Rotations without matrices

Started by
4 comments, last by JohnBolton 18 years, 7 months ago
How can I work out what the position of a certain object will be after applying a rotation to it? For example, i need the equivalent of the D3DXMatrixRotationYawPitchRoll function but without the use of matrices, as i will be batching these objects into one buffer and hence I cannot change the matrices when drawing each one. Any ideas?
Advertisement
Here is how i do it.

D3DXMATRIX Object;
void YawNoMatrix(float angle)
{
D3DXMatrixIdentity(&Object);
Object._11=cosf(angle);
Object._13=-sinf(angle);
Object._31=sinf(angle);
Object._33=cos(angle);
position.x=Object._11+Object.13;
position.z=Object._31+Object._33;
}
void PitchNoMatrix(float angle)
{
D3DXMatrixIdentity(&Object);
Object._22=cosf(angle);
Object._23=sinf(angle);
Object._32=-sinf(angle);
Object._33=cos(angle);
position.y=Object._22+Object.23;
position.z=Object._32+Object._33;
}
void RollNoMatrix(float angle)
{
D3DXMatrixIdentity(&Object);
Object._11=cosf(angle);
Object._12=sinf(angle);
Object._21=-sinf(angle);
Object._22=cos(angle);
position.y=Object._11+Object.12;
position.z=Object._21+Object._22;
}

PS. try it out and let me know if it works for you. If not i will see if i can come up with something better.
It's not clear to my why you can't use matrices. Computing the position of an object is (or can be) independent of drawing it. Perhaps you are thinking of OpenGL, where functions like glRotate affect drawing. That's not how D3D works.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
The reason I cant use matrices is that I am rendering many objects with the one DrawIndexedPrimitive call, hence I cannot apply transformations on each one.
Thanks for the code BornToCode, but I guess I didnt phrase the question too well. Never mind, I figured out how to rotate a point without matrices.
You do know that transforming in software will likely be slower than rendering each object individually with a Draw...Primitive call, right?
Quote:Original post by barakus
The reason I cant use matrices is that I am rendering many objects with the one DrawIndexedPrimitive call, hence I cannot apply transformations on each one.


The D3DXMatrix*() functions don't "apply transformations". They just create matrices for you. To apply a transformation, you hand the matrix to the renderer or you multiply the vectors by the matrix yourself (perhaps using D3DXVec3Transform or D3DXVec3TransformArray).
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

This topic is closed to new replies.

Advertisement