Jump to content
  • Advertisement
Sign in to follow this  
Rajveer

OpenGL matrix rotation/transformation

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

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


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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);

(Please correct me if I had any mistake in that formula)

This article really helped me when I had that problem, I think it may help you too. =)

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

Share this post


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


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


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


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


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

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!