I am trying to get my gun to follow my first-person shooter cam in DX9. First, I'll explain what's happening and then next I'll show some code. Well, what's going on is that the gun follows the camera rotating fine, _but_ I only see the barrel of the gun and nothing else. Here's the code:
Here I'm setting eye point to player's position and then lookat to the rotation angle of the player. This works fine....
D3DXVECTOR3 eyePt = m_player.GetPos();
D3DXVECTOR3 lookatPt = D3DXVECTOR3( sinf( m_player.GetAngle() ) + eyePt.x, eyePt.y, cosf( m_player.GetAngle() ) + eyePt.z );
D3DXVECTOR3 upVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
Now, to have the gun follow I am doing this:
m_weapon.SetAngle( m_player.GetAngle() );
D3DXVECTOR3 gunPos = lookatPt;
gunPos.y -= 0.5f; // y offset
// gunPos.z += 1.0f; // z offset to bring gun into view...eek! gun no longer follows player rotating the camera
m_weapon.SetPos( gunPos );
m_weapon.Render();
With this code, the gun follows along as I rotate the camera, _however_ I can only see the beginning of the gun and nothing else. So I thought I would put a gunPos.z += 1.0f; in there to move the gun more into sight. NOW I see all of the gun but it no longer follows when I rotate.
Maybe it's getting late and I'm tired, but I can't figure this out :) Any help is appreciated. Thanks!
PS -- If you need more info, let me know or if you have a completely easier way to do this, I'd be glad. Also, setting gunPos = lookatPt is something I really didn't think about too much, but I think it's right...