# Total amount of revolutions in a rotation

9 replies to this topic

### #1Gorgorath

New Member

• Members
• 12 posts

Posted 10 December 2009 - 07:27 PM

HI all,

i've got a problems which i've been trying to solve for a day now
I'm rotating an object by and arcball based controller, it's been working
great, except all rotations that are clamped in a [0..360] range( after normalizing ). Now i don't want this, because i want to key frame animations, where a range greater than the[0...360] is needed.

But i can't quite figure it out, this is some code i had

//determine amount of full revolutions
//do this only once
//onMouseDown()
m_revX = ((int)m_newRotation.getPitch())/360;
m_revY = ((int)m_newRotation.getRoll())/360;
m_revZ = ((int)m_newRotation.getYaw())/360;

if(m_revX<0)
m_revX--;
if(m_revY<0)
m_revY--;
if(m_revZ<0)
m_revZ--;

//onMouseDrag()

EulerAngle oldRot = m_newRotation;
oldRot.correctRotation();	//clamp in [0...360] range

m_newRotation = dMat.toEulerAngle();	//matrix to eulers
m_newRotation.correctRotation(); //clamp in [0...360] range

int oldPitch = ((int)oldRot.getPitch())%360;
int oldRoll  = ((int)oldRot.getRoll())%360;
int oldYaw   = ((int)oldRot.getYaw())%360;

float newPitch = m_newRotation.getPitch();
float newRoll  = m_newRotation.getRoll();
float newYaw   = m_newRotation.getYaw();

//determine new revolution
if(oldPitch > 315 && newPitch < 45 )
{
m_revX++;
}
else if ( oldPitch < 45 && newPitch> 315)
{
m_revX--;
}
if(oldRoll>315 && newRoll<45)
{
m_revY++;
}
else if ( oldRoll < 45 && newRoll> 315)
{
m_revY--;
}
if(oldYaw>315 &&  newYaw <45)
{
m_revZ++;
}
else if ( oldYaw < 45 &&  newYaw > 315)
{
m_revZ--;
}

m_newRotation.setPitch(m_revX * 360 + m_newRotation.getPitch());
m_newRotation.setRoll(m_revY * 360 + m_newRotation.getRoll());
m_newRotation.setYaw(m_revZ * 360 + m_newRotation.getYaw());

Regards,

Marks

### #2Reedbeta

DevMaster Staff

• 5305 posts
• LocationBellevue, WA

Posted 10 December 2009 - 07:57 PM

Note that you can use [code]...[/code] to post code on the forum.

As for your problem, I would suggest switching to a quaternion representation because it's much easier to work with for things like this than Euler angles. In particular, slerping between two quaternions always follows the shortest path between them, so you don't get the issues with interpolating across the 0-360 boundary that you get with Euler angles.

On the other hand this does also mean that animating a spinning object would require around two keyframes per revolution, which might be a lot of keyframes if it's spinning rapidly.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #3Gorgorath

New Member

• Members
• 12 posts

Posted 10 December 2009 - 09:22 PM

thanks for the reply, but quaternions still dont give me the wanted revolutions( i'm using them btw )

Mark

### #4Gorgorath

New Member

• Members
• 12 posts

Posted 10 December 2009 - 10:07 PM

all i can think of it is more difficult, when first thought of, quaternions are of course also in the range of [-pi, and pi] but for visual feedback( euler angles ) and keyframing the euler angles should be accumulated, 3d max does it perfectly, i can see myy y axis rotation go down and down, and not jumping back from -1 to 359 for example;)

Mark

### #5v71

Valued Member

• Members
• 353 posts

Posted 10 December 2009 - 10:59 PM

Well, if you don't want to use quaternions, you could always divide your variable which holds the rotation value by 360 , so you will know how many rotation your object performed.
You have to remove the checks for clamping the value beetween 0..360 , it won't affect the rotation matrix
its 24.00 here so i may be wrong on something

### #6rouncer

Senior Member

• Members
• 2718 posts

Posted 11 December 2009 - 01:07 AM

Do you wanna make it spin? i just use general(arbitrary) axis rotates.

(ed)
I cant even tell what you want me to say, sorry shouldnt have posted, maybe you could describe a little more?

(ed2)
storing keyframes, nothing is ever past 360...
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.

### #7Gorgorath

New Member

• Members
• 12 posts

Posted 11 December 2009 - 10:40 AM

rouncer said:

Do you wanna make it spin? i just use general(arbitrary) axis rotates.

(ed2)
storing keyframes, nothing is ever past 360...

Key frames surely can go beyond the [0 360] range

### #8geon

Senior Member

• Members
• 939 posts

Posted 11 December 2009 - 11:29 AM

How about using an axis+angle representation?

### #9rouncer

Senior Member

• Members
• 2718 posts

Posted 13 December 2009 - 01:43 AM

well, all i do is give each rotation a number, it can go around any amount of times who gives a shit. less to less, more to more, 3.6 to 6.6 it goes up (right on the circle) if it goes 6.6 5.6 it goes down (left on the circle.)

Theres 2 ways to go in a circle and only 2 ways, more or less.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.

### #10Gorgorath

New Member

• Members
• 12 posts

Posted 14 December 2009 - 04:52 PM

rouncer said:

well, all i do is give each rotation a number, it can go around any amount of times who gives a shit. less to less, more to more, 3.6 to 6.6 it goes up (right on the circle) if it goes 6.6 5.6 it goes down (left on the circle.)

Theres 2 ways to go in a circle and only 2 ways, more or less.

Yes basically that is what i do, works fine for the x and z axis,
but the y-axis, jumps from sometimes to 90 to -90( which is logical since the asin() function ) , and the x and a z values increment by 180.
So to conclude, i should be using some 'if else' statements in order to find the correct amount of revolutions..i was trying to avoid them..

Mark

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users