Total amount of revolutions in a rotation

Caa4db5b4f1ea9c1f2ae59ddd0bb5cb6
0
Gorgorath 101 Dec 10, 2009 at 19:27

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

9 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 10, 2009 at 19:57

Note that you can use …[/code[b][/b]] 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. [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.

Caa4db5b4f1ea9c1f2ae59ddd0bb5cb6
0
Gorgorath 101 Dec 10, 2009 at 21:22

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

Mark

Caa4db5b4f1ea9c1f2ae59ddd0bb5cb6
0
Gorgorath 101 Dec 10, 2009 at 22:07

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

Ceee4d1295c32a0c1c08a9eae8c9459d
0
v71 105 Dec 10, 2009 at 22:59

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

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 103 Dec 11, 2009 at 01:07

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…

Caa4db5b4f1ea9c1f2ae59ddd0bb5cb6
0
Gorgorath 101 Dec 11, 2009 at 10:40

@rouncer

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

820ce9018b365a6aeba6e23847f17eda
0
geon 101 Dec 11, 2009 at 11:29

How about using an axis+angle representation?

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 103 Dec 13, 2009 at 01:43

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.

Caa4db5b4f1ea9c1f2ae59ddd0bb5cb6
0
Gorgorath 101 Dec 14, 2009 at 16:52

@rouncer

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