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

Started by
3 comments, last by Trashcann 20 years, 9 months ago
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!
ermokwww.truevision3d.com
Advertisement
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!
im using TV3D and visual basic- i dont know how i just know there is some sin cos and atn shit
ermokwww.truevision3d.com
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 weaponDrawEverythingElse( );//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 dirDrawSomething( Weapon, 1, 0, 0, 1, 0, 0 ); //Restore the cameraSetCamera( PreviousValues );//Display this frame and move on to the next one


ToohrVyk

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)
delete this;

This topic is closed to new replies.

Advertisement