Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MagTDK

Advanced Quake 2 question

This topic is 5717 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I doubt anyone can answer this but I'll ask it anyways since I've been stuck on this for 2 days. I've asked this question on several quake 2 source forums but no one seems to have the answer to it. My question is, I'm looking for the source code (function or line of code) responsible for interpolating quake 2's gun kick back effects after firing the weapon. This is the effect were the gun smoothly goes up then down. This interpolation also affects things like smoothing the damage effect after falling from a ledge, smooth view bobbing, ect. From what I can tell, they are all tied together which is why I'm interested in figuring out how it works. It appears quake 2 has an elegant solution for view interpolation on all camera effects. This is what I have found so far: Lets say the user fires the rail gun. In the file p_weapon.c under the function weapon_railgun_fire, there is a line of code that sets the kick back value to -3 like so: ent->client->kick_angles[0] = -3. I know this is the peek up value for the kick back of the gun before it should interpolate back to it's original state. I know that same value shows up again in the cl_ents.c file under the variable ps->kick_angles. If you look at the function CL_CalcViewValues, you'll see a for statement that says: for (i=0 ; i<3 ; i++) c1.refdef.viewangles += LerpAngle (ops->kick_angles[ i], ps->kick_angles[i], lerp); This appears to do the interpolation but not like the way I thought it would which tells me that there has to be another section of code responsible for it. Because during this same frame of animation, that the player fires the rail gun, the ps->kick_angles[0] will have -3 (the peek up amount) as it's value and ops->kick_angles[0] will have 0 as it's value. ops stands for old player state from the previous frame. Now the part that's confusing me is the very next frame of animation were ps->kick_angles[0] know has it's value set to zero. Shouldn't this still be -3 until the interpolation is finished? I don't see were the actual interpolation from 0 to -3 and then back to 0 takes place for the smooth kick back motion. And I know the kick_angles vector is cleared each frame by looking at the p_view.c file under the ClientEndServerFrame function. I know if I change the for statement from the function CL_CalcViewValues to this: for (i=0 ; i<3 ; i++) c1.refdef.viewangles[i] += ps->kick_angles[i]; then no interpolation will take place on all the things I mentioned. You could check for yourself to see what I mean (things will look jerky). Just another side note, viewangles is the orientation of the players view before adding the kick back angles. If anyone can add any insight to this, please do. [edited by - MagTDK on April 19, 2003 2:38:01 PM]

Share this post


Link to post
Share on other sites
Advertisement
What does the code for LerpAngles actually do? (I''ve got the Q2 source lying around but can''t be arsed to look for it). Is it possible that it stores the angle in ops->kick_angles?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i believe LerpAngle just interpolates between two angles:

float LerpAngle (float a2, float a1, float frac)
{
if (a1 - a2 > 180)
a1 -= 360;
if (a1 - a2 < -180)
a1 += 360;
return a2 + frac * (a1 - a2);
}

as far as how the view interpolation for the kickback etc. works, i''m still poking around the q2 code...

Share this post


Link to post
Share on other sites

Yes, the LerpAngle function just interpolates between two angles. But that''s only part of the equation.

kick_angles stores information for things like shaking the camera, view bobbing and gun kick backs. This is a one time event each frame that is reset back to zero for the next frame.

viewangles holds the current camera orientation that gets it''s input from the mouse movement and is carried over each frame.

The final camera orientation is a result of adding the kick_angles with the viewangles vector.

But were does the actual interpolation take place? If you run quake through the debugger and check the sections I pointed out, you''ll see why I''m confused about this line of code:

for (i=0 ; i<3 ; i++) c1.refdef.viewangles += LerpAngle (ops->kick_angles, ps->kick_angles[i], lerp);

It doesn''t make sense the next frame of animation.

Very frustrating

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!