Jump to content
• Advertisement

# Rotations without matrices

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

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 this post

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

#### Share this post

##### 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 this post

##### 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 this post

##### 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 this post

##### 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).

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5
• Advertisement

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633303
• Total Posts
3011277
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!