Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (TipmyPip, AndrewAMD, Quad, aliswee, degenerate_762), 970 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 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
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