Sign in to follow this  

FPS Weapon Positioning

This topic is 1714 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

Hi there,

 

I've got a first person camera. Yay me! I've also got a sweet model of a Mac11 that I position on the lookAt vector of my camera. Its always in front of the camera. Trouble is, I can't figure out how to get it to always be facing 'forward'.

How do I do this? I've done getting the cameras current rotation values and multiplying by that, but then what I get is a wildly spinning Mac11.. no use to anyone lol

 

I read something [on here] about setting the view matrix to the identity, or to the world matrix, so that the camera and gun are in the same space, so to speak. Can someone clear this idea up for me please?


Please help, many thanks in advance.

Share this post


Link to post
Share on other sites

Try multiplying the models worldmatrix with the cameras viewmatrix every frame. this should result in "childing" the model to the camera.

Share this post


Link to post
Share on other sites

Try multiplying the models worldmatrix with the cameras viewmatrix every frame. this should result in "childing" the model to the camera.

 

Sounds sweet..

 

m_mainCam->GetViewMatrix( view );        // actual view matrix

gunPos = m_mainCam->GetLookAt();         // is just in front of the camera
gunMat = playerGun->GetModelMatrix();    //.. model, view, proj sent to shader

D3DXMatrixTranslation( &gunMat, gunPos.x, gunPos.y, gunPos.z );
                
playerGun->SetModelMatrix( gunMat * view ); // on render we use the private m_modelMatrix, and pass in view and proj
 

It almost works.. it's not spinning so  wildly.. the rotation looks like it's definitely relative to the camera now,

but now it's not placed in front of my camera anymore.

Can you give me another nudge kind sir?

Thanks smile.png

Edited by mynameisnafe

Share this post


Link to post
Share on other sites

if you're trying to draw it like you're holding it in front of you aiming it, you need to first transform it out to where it should be in relation to the player, and then transform it out to the player's location and orientation in the world. so first you turn it so its pointing away from you, then you move it up to where your hand is. then you apply the player's orientation, so it turns with the player, then you apply the players translation, to move it out where it should be in the world. do a search on "nested frames of reference" for more info.

Share this post


Link to post
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this