Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, VoroneTZ), 396 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Proper gun positioning #469793
12/08/17 19:46
12/08/17 19:46
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
I'm trying to position weapon correctly on the screen, so changing resolution won't actually affect it's appearance. I remember MasterQ32 recommended me to use rel_for_screen, but after I've struggled for a while (I couldn't get it working) he helped me out and made an example, and it worked like a charm! But back then I didn't really get/find any differences to my original code that didn't work grin Unfortunately I lost some data from my laptop which I was using back then, so I have to make things from scratch.

Idea (if I got it correctly) is to find center of the X coordinates on the screen (screen_size.x / 2) and the lowest Y coordinate of the screen (screen_size.y) and then convert it into the world XYZ coordinates (that's what rel_for_screen does, right? same as vec_for_screen but without views angle and position, for my purpose it's probably even better to use vec_for_screen, cause it's not a view entity but a world one).

Here is how I do that:
Code:
VECTOR pos;
vec_set(&pos, vector(screen_size.x / 2, screen_size.y, 4)); // 4
vec_for_screen(&pos, camera);


But the tricky part here is to position the weapon sprite (yes, I use sprites) correctly. The one I use has it's size 256x256. How do I place it correctly, can any one give me a hint, please?


Best regards.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Proper gun positioning [Re: 3run] #469795
12/08/17 20:57
12/08/17 20:57
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
scale it down and displace it like a normal weapon model. also you need to set DECAL and disable auto-rotation, then set the model rotation to camera.pan


Visit my site: www.masterq32.de
Re: Proper gun positioning [Re: MasterQ32] #469796
12/08/17 21:04
12/08/17 21:04
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: MasterQ32
scale it down and displace it like a normal weapon model.
That's what I did, but it doesn't work, take a look:



Code:
Code:
{
	my = ent_create("v_supershotgun+12.tga", nullvector, NULL);
	set(my, PASSABLE | NOFILTER | ZNEAR);
	vec_fill(&my->scale_x, 0.0625); // 0.0625
	my->ambient = 100;
	
	while(my){
		
		camera->arc = 90;		
		camera->pan = cycle(camera->pan - mickey.x / 6.5 * 1, 0, 360);
		camera->tilt = clamp(camera->tilt - mickey.y / 6.5 * 1, -90, 90);		
		camera->roll = 0;		
		
		VECTOR pos;
		vec_set(&pos, vector(screen_size.x / 2, screen_size.y, 4));
		vec_for_screen(&pos, camera);
		
		draw_point3d(&pos, COLOR_RED, 100, 0.1);
		
		VECTOR off;
		vec_set(&off, vector(4, 0, 4.5));
		vec_rotate(&off, &camera->pan);
		vec_add(&off, &pos);
		
		vec_set(&my->x, &off);
		vec_set(&my->pan, &camera->pan);
		
		wait(1);
	}
	
}



Greets!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Proper gun positioning [Re: 3run] #469797
12/08/17 22:05
12/08/17 22:05
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Shouldn't positioning the gun based on the camera's fov & aspect ratio work for all resolutions?


POTATO-MAN saves the day! - Random
Re: Proper gun positioning [Re: Kartoffel] #469798
12/08/17 22:17
12/08/17 22:17
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: Kartoffel
Shouldn't positioning the gun based on the camera's fov & aspect ratio work for all resolutions?
Well, I used to use something like this before:
Code:
VECTOR pos;
vec_set(&pos, vector(16, 0, 8));
vec_rotate(&pos, &camera->pan);
vec_add(&pos, &camera->x);

vec_set(&weapon->x, &pos);

But this won't work correctly, it will give same results as in pictures above, and I don't really know how to position weapon based on camera's fov and aspect ratio. Any ideas are welcome.

Greets.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Proper gun positioning [Re: 3run] #469799
12/08/17 23:25
12/08/17 23:25
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
well for example use

vec_set(&pos, vector(16, 0, some_value * (screen_height / screen_width)));


POTATO-MAN saves the day! - Random
Re: Proper gun positioning [Re: Kartoffel] #469801
12/09/17 01:47
12/09/17 01:47
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
the bottom of the screen has a trigonometric relation with the camera arc. It may be computed only once when view arc or screen resolution changes.

Code:
_ent->skill20 = fcos(0.5 * camera->arc, _distance);
_ent->skill21 = 0;
_ent->skill22 = _sizeY - fsin(0.5 * camera->arc, _distance) * screen_size.y / screen_size.x;
...
vec_set(&_ent->x, &_ent->skill20);
vec_rotate(&_ent->x, &camera->pan);
vec_add(&_ent->x, &camera->x);
_ent->pan = ang(camera->pan - 180);
_ent->tilt = -camera->tilt;
_ent->roll = -camera->roll;



_distance is the distance to the camera and _sizeY is the sprites max_y value (0.5 * bmap_height * scale_y).

Salud!

Re: Proper gun positioning [Re: txesmi] #469809
12/09/17 09:21
12/09/17 09:21
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Wow! Thank you very much for your time and help guys! laugh

Kartoffel@ thank you man! but unfortunately couldn't get it working, still when resolution changes weapon is not placed at the same spot.

txesmi@ thank you man, it works like a charm! yet the math part is a little bit above of my head, I'm not good at trigonometric.


Here is current code (with weapon bobbing effect) for those who might need it:
Code:
my = ent_create("v_supershotgun+12.tga", nullvector, NULL);
set(my, PASSABLE | NOFILTER | ZNEAR);
vec_fill(&my->scale_x, 0.0625); // cause original size was 256x256, I scale it down to 16x16
my->ambient = 100;

var weapon_bob_move = 0, weapon_bob = 0, weapon_bob_y = 0, weapon_bob_z = 0;

while(my){
	
	camera->arc = 90;		
	camera->pan = cycle(camera->pan - mickey.x / 6.5 * 1, 0, 360);
	camera->tilt = clamp(camera->tilt - mickey.y / 6.5 * 1, -90, 90);		
	camera->roll = 0;
	
	if(key_w){ weapon_bob_move = (weapon_bob_move + 30 * time_step) % 360; }
	weapon_bob = clamp(weapon_bob + 4 * time_step * 0.1 - weapon_bob / 3 * time_step, 0, 2);
	weapon_bob_y = sin(weapon_bob_move) * weapon_bob * 0.5;						
	weapon_bob_z = cos(weapon_bob_move * 2) * weapon_bob * 0.25;
	
	var x_distance = 16, z_distance = 17;		
	my->skill20 = fcos(0.5 * camera->arc, x_distance);
	my->skill21 = -weapon_bob_y;
	my->skill22 = 8 - fsin(0.5 * camera->arc, z_distance) * screen_size.y / screen_size.x + weapon_bob_z;
	
	vec_set(&my->x, &my->skill20);
	vec_rotate(&my->x, &camera->pan);
	vec_add(&my->x, &camera->x);
	
	ANGLE temp_angle;
	vec_set(&temp_angle, vector(180, 0, 0));
	ang_add(&temp_angle, &camera->pan);
	vec_set(&my->pan, &temp_angle);
	
	wait(1);
}




Best regards!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Proper gun positioning [Re: 3run] #469816
12/09/17 17:10
12/09/17 17:10
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Glad of been of help laugh

Here are the concepts behind the solution, if insterested.


Re: Proper gun positioning [Re: txesmi] #469817
12/09/17 17:19
12/09/17 17:19
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Thank you for your time for making that concept! laugh

Best regards!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Proper gun positioning [Re: 3run] #469846
12/11/17 12:35
12/11/17 12:35
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
You are welcome laugh

I realized/remembered there is a better trigonometric relation between cathetus and angles... the tangent! blush cry



Salud!

Re: Proper gun positioning [Re: txesmi] #469847
12/11/17 12:48
12/11/17 12:48
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Thank you very much bro! laugh


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Proper gun positioning [Re: 3run] #472199
04/16/18 00:01
04/16/18 00:01
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Hi!

Faced some troubles with your solution, txesmi!
Fullscreen mode messes everything up..

Take a look at this code
Code:
void main(){
	
	fps_max = 60;
	level_load("");
	wait(3);
	
	camera->arc = 90;
	
	my = ent_create("test.png", nullvector, NULL);
	set(my, PASSABLE | NOFILTER | ZNEAR);
	vec_fill(&my->scale_x, 1);
	my->ambient = 100;

	var distance = 16, size_z = 8;

	while(my){
		
		my->skill20 = fcos(0.5 * camera->arc, distance);
		my->skill21 = 0;
		my->skill22 = size_z - fsin(0.5 * camera->arc, distance) * screen_size.y / screen_size.x;
		
		vec_set(&my->x, &my->skill20);
		vec_rotate(&my->x, &camera->pan);
		vec_add(&my->x, &camera->x);
		
		my->pan = ang(camera->pan - 180);
		my->tilt = -camera->tilt;
		my->roll = -camera->roll;
		
		wait(1);
	}
	
}


And a small bmap to test it, here it goes (right click and save, it's 16x16):


As far as I understood it should work correctly, but it does not :<

Screen examples (notice that resolution is the same!)
Quote:
Windowed mode

Fullscreen mode


Greets!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Proper gun positioning [Re: 3run] #472202
04/16/18 08:45
04/16/18 08:45
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
looks like the image is scaled along the screen y axis (which is weird)

maybe check if screen_size really contains the correct resolution?

Edit: another thing that might mess things up is the billboard rotation that the engine does for sprites (I think this is done when the sprite rotation is (0,0,0)).

Last edited by Kartoffel; 04/16/18 08:46.

POTATO-MAN saves the day! - Random
Re: Proper gun positioning [Re: Kartoffel] #472204
04/16/18 10:28
04/16/18 10:28
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: Kartoffel
maybe check if screen_size really contains the correct resolution?
Checked that, and it's correct (720x480 in both modes).

As for rotation, as far as I know, when you manually change rotation of the sprite, engine won't rotate it by itself.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Proper gun positioning [Re: 3run] #472207
04/16/18 12:38
04/16/18 12:38
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
I noticed that the proportion of the projection area in full screen is always real screen sized. That is strange because while it computes the projection matrix by 'screen_size', it shows a rectangle with the real proportion of the screen, so it cuts part of the projection depending on the proportion difference. And at the end it renders in 'screen_size' resolution! It sounds like a bug for me. The good thing is that it is easy to work around xP

Code:
#include <acknex.h>

var distance = 16;
var cameraProp = 1;
var screenProp = 1;

void safe_video_switch (var _mode) {
	video_mode = video_switch(_mode, 32, video_screen);
	if(!video_mode)
		video_mode = video_switch(7, 32, video_screen);
	if (video_screen == 1)
		cameraProp = distance * screenProp / camera->aspect;
	else
		cameraProp = distance * screen_size.y / (screen_size.x * camera->aspect);
}

void onQ () {
	safe_video_switch(video_mode + 1);
}

void onW () {
	video_screen = 1 + video_screen % 2;
	safe_video_switch(video_mode);
}

void weaponLocate (ENTITY *_ent) {
	var size_z = 8 * _ent->scale_z;
	_ent->x = distance;
	_ent->y = 0;
	_ent->z = size_z - tanv(0.5 * camera->arc) * cameraProp;
	vec_rotate(&_ent->x, &camera->pan);
	vec_add(&_ent->x, &camera->x);
	_ent->pan = ang(camera->pan - 180);
	_ent->tilt = -camera->tilt;
	_ent->roll = -camera->roll;
}

void main () {
	screenProp = sys_metrics(1) / sys_metrics(0);
	fps_max = 60;
	video_mode = 7;
	video_screen = 1;
	wait(1);
	
	on_q = onQ;
	on_w = onW;
	
	level_load("");
	camera->arc = 90;
	camera->aspect = 1;
	
	safe_video_switch(7);
	
	ENTITY *_ent = ent_create("sprite2.tga", nullvector, NULL);
	set(_ent, PASSABLE | NOFILTER | ZNEAR | DECAL);
	vec_fill(&_ent->scale_x, 1);
	_ent->ambient = 100;

	while (!key_esc) {
		camera->pan = ang(camera->pan - mickey.x * 0.2);
		camera->tilt = clamp(camera->tilt - mickey.y * 0.2, -90, 90);
		weaponLocate(_ent);
		wait(1);
	}
	
	sys_exit(NULL);
}



added 'camera->aspect' as it has full relevance on the computations.

Originally Posted By: 3run
As for rotation, as far as I know, when you manually change rotation of the sprite, engine won't rotate it by itself.

Remember the DECAL flag

Salud!

Re: Proper gun positioning [Re: txesmi] #472209
04/16/18 12:50
04/16/18 12:50
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Thank you very much, man! I'll dive in to the code laugh

Best regards!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Proper gun positioning [Re: 3run] #472210
04/16/18 13:46
04/16/18 13:46
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
A little bump, what size is your "sprite2.tga" ?

Edit: got it working, size was 16x16 if I understood correctly.
Thank you one more time man! laugh


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Proper gun positioning [Re: 3run] #472217
04/16/18 19:35
04/16/18 19:35
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
glad of been of help wink

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1