Jump to content
  • Advertisement


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


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

This topic is 5562 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 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...

glRotate(...) //rotate however far the character has rotated
//from your axis of orgin

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


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

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!