Public Group

# OpenGL matrix rotation/transformation

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

## Recommended Posts

hi, ive been getting to grips with 3d matrix rotations and transformations. im planning to use a 3x4 matrix in an implimentation of opengl for my nintendo ds. at the moment i have an object with x,y and z coords represented by variables: with the rotation matrix do i multiply these coordinates by the rotation matrix or the actual vertices of the said object? ive read that u multiply by the objects coordinates, however if i multiply the 3vector for its position by the matrix, how will it rotate the object? would it just not move the object with unexpected results?

##### Share on other sites
how do i multiply a matrix by the coordinates of the vertices of my model? especially if my model is fairly complex, it will be a long procedure and take up alot of cpu time

##### Share on other sites
can anybody help me?

##### Share on other sites
Hi...

I had a similar problem some time ago, and what I did for example, for implementing Rotation in the Z axis was:

//Z-rotation-"matrix"
new_x = x * cos(angle) - y * sin(angle);
new_y = x * sin(angle) + y * cos(angle);

http://www.gamedev.net/reference/articles/article415.asp

##### Share on other sites
Hey!
You're very right that you can't rotate an object by manipulating it's position - you have no choice but to do it on all vertices. luckily the OpenGL API (and possibly you hardware, but I really don't know about the DS) can handle that for you: you are multiplying all your vertices by the two OpenGL matrices anyways. What is typically done is just manipulating the GL_MODELVIEW matrix with your rotation. Write back if you need further help doing that.

##### Share on other sites
oh right, i think i get it now. how would i implement it? would i somehow put the modelview matrix on the stack and then multiply it with my rotation matrix? cheers guys for the input! :)

##### Share on other sites
you, you could do that, but you don't really need to use the stack :) only if you want a way to undo the change to the modelview matrix

##### Share on other sites
cheers for the help! so after i create my rotation matrix, how do i actually multiply the modelview matrix by it?

##### Share on other sites
glMultMatrix - or you can just have opengl create the matrix for you using glRotate

##### Share on other sites
cheers ill try it out now. the reason im not using glRotate is because i need rotations and translations on my objects local axis (unless im missing a way to do this!). ill get back and post my results :)

• ### What is your GameDev Story?

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

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

• Total Topics
634151
• Total Posts
3015819
×