2 registered members (dr_panther, 7th_zorro),
1,203
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Proper gun positioning
#469793
12/08/17 19:46
12/08/17 19:46
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
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 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:
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.
|
|
|
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
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
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:
{
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!
|
|
|
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
Expert
|
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
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
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:
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.
|
|
|
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
Expert
|
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
Serious User
|
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.
_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
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Wow! Thank you very much for your time and help guys! 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:
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!
|
|
|
|