Jump to content
  • Advertisement

Archived

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

b612

first person weapon movement/rotation

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

can anyone briefly tell me how this is done? haven''t gotten it working 100% yet...i''m translating to the camera''s position, so placement is correct, but rotation is off. thank you.

Share this post


Link to post
Share on other sites
Advertisement
Well, without seeing your code its hard to tell you what isn't working but here is what I do (this is using the mouse). I also have keyboard code too, but it works exactly the same.

Public Function ReadMouse( _
ByVal bImmediate As Boolean _
) As Boolean
Try
If m_Mouse Is Nothing Then
Return True
End If

Dim mtxRot As Matrix = New Matrix

Dim mState As MouseState
Try
mState = m_Mouse.CurrentMouseState
Catch ex As Exception
Try
If Not Me.AcquireMouse Then
Return False
End If

mState = m_Mouse.CurrentMouseState
Catch exc As Exception
Return False
End Try
End Try

Dim mArray() As Byte = mState.GetMouseButtons

If 0 <> mArray(0) Then
'down
If mState.Y <> 0 Then
mtxRot = Matrix.RotationAxis(m_Right, (mState.Y * m_Speed))
m_Look = Vector3.TransformCoordinate(m_Look, mtxRot)
m_Up = Vector3.TransformCoordinate(m_Up, mtxRot)
Else
End If

If mState.X <> 0 Then
mtxRot = Matrix.RotationAxis(New Vector3(0.0, 1.0, 0.0), (mState.X * m_Speed))
m_Look = Vector3.TransformCoordinate(m_Look, mtxRot)
m_Up = Vector3.TransformCoordinate(m_Up, mtxRot)
Else
End If
Else
'up
End If
If 0 <> mArray(1) Then
m_Position = Vector3.Add( _
m_Position, _
Vector3.Multiply(Vector3.Multiply(m_Look, m_Speed), _
m_Speed))
Else
End If
If 0 <> mArray(2) Then
m_Position = Vector3.Subtract( _
m_Position, _
Vector3.Multiply(Vector3.Multiply(m_Look, m_Speed), _
m_Speed))
Else
End If

Return True
Catch ex As Exception
Return False
End Try
End Function

Hope that helps... works great for me :-)

Of course if your matrices are different or not correct ATM then possibly it might not work.

Also, I do NOT use LookAt functions I calculate the matrix everytime.

P.S. I can "speed up" my move ment hence the m_speed variable, however you can set it to whatever. Usually (i found imho) that you DO not want your "movement" speed to be the same as your rotate speed. When I do... I rotate so darn fast lol its nuts.

[edited by - 3dxd on June 10, 2004 12:53:44 PM]

Share this post


Link to post
Share on other sites
thanks for the reply!

however, my camera is working great...i was looking for help on moving/rotating a weapon model with the camera.

Share this post


Link to post
Share on other sites
Can you post the code that you use to transform the camera and weapon?

If you think about it, it''s very simple - just translate the weapon by the camera matrix plus some vector offset.

// playerPosition is a structure that holds self-explanatory D3DXVECTOR3''s
// Update player position
playerPosition.yaw += playerPosition.yawVel;
playerPosition.pitch += playerPosition.pitchVel;

// Normalize and add
D3DXVECTOR3 cameraVel;
D3DXVec3TransformNormal( &cameraVel, &playerPosition.vel, &matOrientation );
playerPosition.pos += cameraVel;

// Use quaternions to rotate the camera
D3DXQUATERNION quat;
D3DXMATRIX matView;
D3DXQuaternionRotationYawPitchRoll( &quat, playerPosition.yaw, playerPosition.pitch, playerPosition.roll );
D3DXMatrixAffineTransformation( &matOrientation, 1.25f, NULL, &quat, &playerPosition.pos );
D3DXMatrixInverse( &matView, NULL, &matOrientation );
d3dDevice->SetTransform( D3DTS_VIEW, &matView );

// Find the gun position
D3DXVECTOR3 gunPos;
D3DXMATRIX gunMatrix, matGunOrientation;
D3DXVECTOR3 offset = D3DXVECTOR3( 5.0f, 0.0f, 2.0f ); // Offset X by 5, Z by 2
gunPos = playerPosition.pos + offset;
D3DXMatrixAffineTransformation( &matGunOrientation, 1.25f, NULL, &quat, &gunPos );
D3DXMatrixInverse( &gunMatrix, NULL, &matGunOrientation );
I think that''s right...if anything, offset will need to be normalized first.


Dustin Franklin
Mircrosoft DirectX MVP

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!