#### Archived

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

# Calc the front of a camera rotatin matrix

This topic is 6055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I was wondering if you could tell me how to calculate the front of a rotation matrix. In other words, if I knew that an unrotated object''s front was at (0,0,1) in object space, then I applied a rotation matrix to it, how would I calculate where the front moved to? I tried doing it like this: Public Sub RotateRel(ByVal yaw As Single, ByVal pitch As Single, ByVal roll As Single) Dim tmpRotMatrix As D3DMATRIX ''Create an update matrix D3DXMatrixIdentity tmpRotMatrix D3DXMatrixRotationYawPitchRoll tmpRotMatrix, yaw * RAD, pitch * RAD, roll * RAD ''Apply it to the rot matrix D3DXMatrixMultiply mvarRotationMatrix, mvarRotationMatrix, tmpRotMatrix vTop = MultVecByMatrix(D3DVECTOR(0, 1, 0), mvarRotationMatrix) ''*** This is the line I''m having trouble with *** vFront = MultVecByMatrix(D3DVECTOR(0, 0, 1), mvarRotationMatrix) End Sub Private Function MultVecByMatrix(vec As D3DVECTOR, mat As D3DMATRIX) As D3DVECTOR MultVecByMatrix.x = vec.x * mat.M11 + vec.y * mat.M21 + vec.z * mat.M31 + mat.M41 MultVecByMatrix.y = vec.x * mat.M12 + vec.y * mat.M22 + vec.z * mat.M32 + mat.M42 MultVecByMatrix.z = vec.x * mat.M13 + vec.y * mat.M23 + vec.z * mat.M33 + mat.M43 End Function This works as long as pitch = 0 or yaw = 0. But, if both of them are non-zero, it doesn''t work. Also, when RotateRel() is called, the matrix mvarRotationMatrix already has rotations applied to it. The yaw, pitch, and roll are relative to rotations it already contains. I tested the program by setting the camera''s matrix mvarRotationMatrix and placing a sphere at the coordinates in vFront. I would have expected the sphere to remain directly in front of the camera as I rotated it. The camera rotated as I expected. But, the sphere didn''t the result was as if the camera was inside of a globe. If I set the pitch to 60 degrees and the yaw to 0 degrees, the camera would point to the 80 degrees north latitude and 0 degrees longitude. The sphere appeared directly in front, as it should. But, if I yaw the camera around to 180 degrees, the camera pointed to 80 degrees south latitude 180 longitude while the sphere stayed on 80 degree latitude line and moved to 180 degrees longitude. What am I doing wrong? How can I calculated the point in front of the camera? Thanks in advance, Mike

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632959
• Total Posts
3009461
• ### Who's Online (See full list)

There are no registered users currently online

×