View Full Version : 3D Model Rotation abt Screen Coords based on mouse movement

dan81

10-10-2005, 10:13 AM

Hi guys,

I need some help regarding rotation in a 3D world space:

glRotated(m_AngleX, 1, 0, 0);

glRotated(m_AngleY, 0, 1, 0);

glRotated(m_AngleZ, 0, 0, 1);

where, m_AngleX, Y, Z are the calculated parameters for angle turned abt the respective axes, based on user mouse movement.

I am using the above code to rotate my 3D model about these axes. But then, these are the object's local coordinates. I am required instead to rotate my model about the view coordinates, or shud i say the screen coordinates or the world coordinates.. I have researched and thought thru this for very long, but still cannot get any insights..

Can someone help me out here? I really do appreciate it!! Thanks!

Ojama

10-10-2005, 01:54 PM

Originally posted by dan81:

Hi guys,

I need some help regarding rotation in a 3D world space:

glRotated(m_AngleX, 1, 0, 0);

glRotated(m_AngleY, 0, 1, 0);

glRotated(m_AngleZ, 0, 0, 1);

where, m_AngleX, Y, Z are the calculated parameters for angle turned abt the respective axes, based on user mouse movement.

I am using the above code to rotate my 3D model about these axes. But then, these are the object's local coordinates. I am required instead to rotate my model about the view coordinates, or shud i say the screen coordinates or the world coordinates.. I have researched and thought thru this for very long, but still cannot get any insights..

Can someone help me out here? I really do appreciate it!! Thanks!Try calculating the rotation necessary based on a distance value for the mouse. Keep in mind that the mouse simulates a flat surface, whereas you are rotating an invisible sphere with the object attached some distance inside.

One way to get results with arbitrary metrics is to divide by your screen resolution(mice measure DPI, the OS usually is set up for a one-to-one relationship with pixles), divide that by your screen resolution, and multiply by the fraction your screen is over how many "screens" is one rotation.

Or, if I misunderstand your problem, you are trying to rotate your entire scene, and that is causing problems. Try a buffer. Put everthing in a second set of values, (I think arrays or whatnot work) then rotate that array.

Supposedly, you should have three versions of each object, with 3 corresponding xyz values for each vertex.

1. Each model

2. "worldspace"

3. the view, which it looks like you have.

That's a rotation and move followed by another rotation, if you're counting.

ummmm....is that close?

dan81

10-11-2005, 05:43 AM

yup, I have already implemented the mouse movements and translated into rotating factors by which my model should rotate. Anyway, i have solved the problem, and this is my solution:

for rotation about object coordinates, the matrix order shud be MTV, where M is the saved current modelview matrix, T is the rotation matrix, and v is the vertex.

for rotation about absolute coordinates, the matrix order instead shud be TMV. just reverse the order.

There is no need for euler angles, quaternions and all that stuff. Hope this will help someone out there facin the same prob.

Thanks for replyin anyway!

=)

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.