I am trying to make some basic modifications to the quake engine, in order to understand a little more vectors and aiming, but without any help of other ports.
As you have maybe noticed, when we fire something, the coordinates are always right into the center of the screen, no matter the position of our view.
However, what I am trying to achieve is a little more "difficult" to do...
I am trying to make a Goldeneye64 "aiming system" clone, in order to understand a lot more how vectors are working. To be honest, I am really lost about that, and I know the Wii-QuakeGX port has that system done with the wiimote.
I have made some basic changes in gl_screen.c ( SCR_UpdateScreen(void) ) in order to make the crosshair appear:
Code: Select all
(...)
else if (cl.intermission == 2 && key_dest == key_game)
{
Sbar_FinaleOverlay ();
SCR_CheckDrawCenterString ();
}
else
{
if (bCrosshair)
{
Draw_Character (scr_vrect.x + crossx , scr_vrect.y + crossy, '+');
}
else
{
crossx = vid.width/2;
crossy = vid.height/2;
}
I know, I tried some things before, but I need to seriously clean A LOT OF THINGS on that engine...
Code: Select all
(...)
old_mouse_x = mx;
old_mouse_y = my;
mouse_x *= sensitivity.value;
mouse_y *= sensitivity.value;
if (in_mouselook.value)
{
V_StopPitchDrift ();
bCrosshair=false;
// That SHOULD disable the view!!
// But doesn't work...
// If we are aiming____
if (in_mlook.state & 1)
{
bCrosshair = true;
crossx += mouse_x * aim_sensitivity.value;
crossy += mouse_y * aim_sensitivity.value;
if ( crossx <= 0 ) crossx = 0;
if ( crossx >= vid.width) crossx = vid.width;
if ( crossy <= 0 ) crossy = 0;
if ( crossy >= vid.height) crossy = vid.height;
}
else {
cl.viewangles[YAW] -= m_yaw.value * mouse_x;
cl.viewangles[PITCH] += m_pitch.value * mouse_y;
if (cl.viewangles[PITCH] > 80)
cl.viewangles[PITCH] = 80;
if (cl.viewangles[PITCH] < -70)
cl.viewangles[PITCH] = -70;
}
}
(res: 640*480)
However, now that I can move my crosshair anywhere on my screen, the most difficult thing is to aim to that position.
After some time, I've noticed that I had to check PF_aim (void) [pr_cmds.c] to be able to fire where I wanted to aim...
But that's nearly ununderstandable for me actually...
After the basic changes, I've maybe got an hint, but that drives me crazy :
in PF_aim (void) :
Code: Select all
(insert 90% of PF_aim here ... )
if (bestent)
{
VectorSubtract (bestent->v.origin, ent->v.origin, dir);
dist = DotProduct (dir, pr_global_struct->v_forward);
VectorScale (pr_global_struct->v_forward, dist, end);
end[2] = dir[2];
VectorNormalize (end);
Q_DPrint("HIT!!!!!!!!!!!"); // How does that part of code work?
VectorCopy (end, G_VECTOR(OFS_RETURN));
}
else
{
if (bCrosshair) // bCrosshair is the bool to check if we are aiming with the crosshair coordinates
{
crossaim[0]= crossx; // CrosshairX coord
crossaim[1]= crossy; // CrosshairY coord
crossaim[2]= dir[2]; // Direction of the player?
VectorNormalize (crossaim); // Make crossaim a vector
VectorSubtract(pr_global_struct->v_forward,crossaim,crossaim); // substract our current view with our coodinates?
VectorCopy (crossaim, G_VECTOR(OFS_RETURN)); // Returns the vector where to shoot
}
else
VectorCopy (bestdir, G_VECTOR(OFS_RETURN));
}
(res: 640*480)
thanks in advance for the help...