Jump to content

  • Log In with Google      Sign In   
  • Create Account


FPS Weapon Positioning


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 mynameisnafe   Members   -  Reputation: 242

Like
0Likes
Like

Posted 08 April 2013 - 05:18 AM

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.



Sponsor:

#2 Tordin   Members   -  Reputation: 604

Like
0Likes
Like

Posted 08 April 2013 - 05:52 AM

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


"There will be major features. none to be thought of yet"

#3 mynameisnafe   Members   -  Reputation: 242

Like
0Likes
Like

Posted 08 April 2013 - 07:10 AM

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, 08 April 2013 - 07:11 AM.


#4 Norman Barrows   Crossbones+   -  Reputation: 1849

Like
0Likes
Like

Posted 08 April 2013 - 06:14 PM

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.


Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS