Archived

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

Trashcann

Trig- placing a gun in front and to the right of a camera

Recommended Posts

I want to put a gun in front and down to the right like a normal FPS so it stays there and stays rotated properly- can someone help me with the math? please, any help would be greatly appreciated!

Share this post


Link to post
Share on other sites
If im reading this correctly, you want a gun to stick out of the screen and stay static, no matter how you render your screen, kinda like halflife guns or bf1942 ones. I dont see any intensive math thats really involved, if your using open gl, the code would look something like this...

RenderInterface()
RenderScene()
glPushMatrix()
glRotate(...) //rotate however far the character has rotated
//from your axis of orgin
DrawGun()
glPopMatrix()

So say your character faces down the negative z axis. He then rotates towards the x axis 30 degrees. When you want to draw the gun, rotate back -30 degrees on the x axis then draw the gun. If im not mistaken this should be how you draw your gun.



come visit me at www.worldofwc.org!

Share this post


Link to post
Share on other sites
First, your API must provide two things :

-> How do you draw something on the screen at position (X,Y,Z) facing (X'',Y'',Z'') ?

Call this DrawSomething( Object, X, Y, Z, X'',Y'',Z'')

-> How do you set the camera position to X,Y,Z facing (X'',Y'',Z'')?

Call this SetCamera( X, Y, Z, X'', Y'', Z'' )

Then, to draw an object in front of the camera :


//Draw everything except the weapon

DrawEverythingElse( );
//move camera to 0, 0, 0, looking down the x axis.

SetCamera( 0, 0, 0, 1, 0, 0 );
//Draw the weapon in front of the camera, looking in the same dir

DrawSomething( Weapon, 1, 0, 0, 1, 0, 0 );
//Restore the camera

SetCamera( PreviousValues );
//Display this frame and move on to the next one



ToohrVyk

Share this post


Link to post
Share on other sites
1. Render scene, HUD etc.
2. Reset matrix
3. Clear depth buffer
4. Draw gun without any rotation or transformation applied(assuming it is placed in the correct way in the model)

Share this post


Link to post
Share on other sites