Rotation Around a Faked Axis

Started by
11 comments, last by NeonWolfTrance 9 years, 6 months ago

As mentioned, I'm not sure what problem you're trying to solve.

How 'bout:


position = rotY * rotation; // perform the Y rotation first

Yea same deal, but sorry missed that part. I'm trying to implement rotation for how a first person camera would rotate. The yaw for a first person camera is unaffected by the previous pitch. Looking up and then rotating wouldn't make your vision go sideways.

If all you want is just a FirstPersonCamera a simple way to do it would be to save yaw and pitch in some variables and update them upon mouse movement.

Then during update/render call we can easily derive the matrix or quaterion from yaw and pitch.

Or You can maintain 3 vectors vecLook, vecUp and vecRight and update them whenever you move camera. These 3 vectors are basically the rows of your rotation matrix. Also you need to normalize them before forming the matrix.

You might find this link useful http://r3dux.org/2012/12/a-c-camera-class-for-simple-opengl-fps-controls/ (even though its for opengl, it can be easily converted for directx)

My Game Development Blog : chetanjags.wordpress.com

Advertisement


These 3 vectors are basically the rows of your rotation matrix.

I think in D3D they are the columns, not the rows. See the formula at the bottom of this page: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205342%28v=vs.85%29.aspx


It ever rotates around an primary axis in the effective space.

Fixed that for you. The distinction between "primary axis", "arbitrary axis" and "primary axis-aligned" is really important here. If your persistent matrix is the identity matrix (no rotation or translation), then the first rotation you apply to it (multiplying either to the left or to the right with a translation matrix) will be a rotation around a primary axis. If you already have translation in the persistent matrix, the rotation becomes rotation around an primary axis-aligned axis (so this rotation will not result in a "look-at" type of transformation). If you also have rotation (in addition to translation) in your initial persistent matrix, and you want to apply new rotation around an axis, independently of the translation or the other axes, then you'd have to somehow remove the rotation around the wanted axis from the persistent matrix (which I think involves at least a matrix inversion), change the rotation, and re-multiply the persistent matrix with the new rotation... this is way too much work than just keeping separate variables for position and rotation.

Anyway, is anything I said not true? I can't handle your math explanations right now, sorry... The reason I know that what I said IS true, is because I had the same problem described in the OP at one time, and it turns out I couldn't just keep a persistent matrix that I could infinitely multiply to the left or right to get yaw and pitch rotations to act independently of each other and independently of the translation (position).

The simple explanation for how matrix concatenation works is that the transformations are applied in the order in which their corresponding matrices are multiplied. Also, each transformation by itself is relative to the origin (translation) or the axes (rotation) of the coordinate system, but when you concatenate transformations together, the origin and the axes of the coordinate system are relative to the previous transformations. So a translation matrix will move the origin of future transformations, and a rotation matrix will rotate the axes of future transofrmations.

So if you have YawRotation * Translation * YawRotation in the persistent matrix, you will obviously not get what you want, because the second rotation will be affected by the previous rotation and translation (which results in a new origin and rotated X,Y,Z axes). Similarly, if you wanted to apply only two transformations (translation and yaw), then you could always multiply the yaw rotation matrix to the right of the persistent matrix, and the translation matrix to the left, and you would get correct results. However, if you also have pitch, which needs to be applied to the right as well, but AFTER the yaw rotation, then your pitch and yaw will end up affecting each other...

Note: My previous recommendation of using Translation * RotationYaw * RotationPitch works for a view matrix, but I think it should work the same for a world matrix, except the angles and position coordinates are negated... In the end, I think it's always best to figure out your own explanation for how matrix concatenation works. Different people will have different ways of explaining it (even though they're explaining the same thing smile.png ). For myself, I found it better to stick to the simple explanation above (third paragraph) than a mathematical one...

You are all sexy people and thank you tonemgub, I do prefer the simple explanation and this worked wonderfully.

Although, I did switch around the multiplications:


D3DXMatrixMultiply(&result, &rotation, &translation);

This way I get rotation in-place instead of an orbiting rotation.

Thanks for the help everyone!

This topic is closed to new replies.

Advertisement