# Rotations without matrices

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

## Recommended Posts

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?

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
You do know that transforming in software will likely be slower than rendering each object individually with a Draw...Primitive call, right?

##### Share on other sites
Quote:
 Original post by barakusThe 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).

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 11
• 15
• 11
• 11
• ### Forum Statistics

• Total Topics
634149
• Total Posts
3015834
×