Problem with node->SetRotation

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Scarabol
Posts: 167
Joined: Sat Jan 03, 2009 5:26 pm
Location: Aachen, Germany

Problem with node->SetRotation

Post by Scarabol »

Hi,

i have a node, which is rotated to vector3df(360,0,0).

The problem is, when i call setRotation(vector3df(0,0,0), the node rotates 1 time around himself, which looks very ugly and crazy too if the rotations is not 360 but 720 or more...

How can i make vector3df(360,0,0) and vector3df(0,0,0) equal, that the user does not see any difference?

Greetings
Scarabol
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

I dont understand your question. 360 and 0 degrees rotations ARE equal. 720 degree rotation does not exist at all. Rotations can exist only between 0-360 degrees.
Scarabol
Posts: 167
Joined: Sat Jan 03, 2009 5:26 pm
Location: Aachen, Germany

Post by Scarabol »

Well, i know that they are equal, but Irrlicht doesn't know this...

So if i call node->setRotation(0,0,0);
and then node->setRotation(360,0,0); Irrlicht Rotates the node one the Screen...

Or if the node->getRotation() is (720,0,0) (<< it is possible to make this) and i call node->setRotation(0,0,0) Irrlicht rotates the node twice around his axis :-((

Greetings
Scarabol
vipergc
Posts: 27
Joined: Mon Mar 02, 2009 3:33 am
Location: Louisville, KY
Contact:

Post by vipergc »

setrotation first converts the degrees to radians by multiplying the angle by DEGTORAD64 and then calculating the sine and cosine in order to apply the rotation...

THEORY:
the trig value of sin(0) = sin(360) = 0
and cos(0) = cos(360) = 1

PRACTICAL:
sin(0) = 0
sin(360) = sin(360 * pi/180) = sin(.0174) = .000303 (not zero)
this is due to floating point limitations on a computing device and the fact that pi is an irrational number. I would suggest that you limit the values to 0-360 from within your code because rotations beyond 360 are essentially wrapped to fit within 0-360 anyway by the trig functions. you cant force the function to do two rotations by passing 720 degrees.

are you hard coding the values you are passing or are they calculated values? if they are calculated, then you may be experiencing errors due to floating point limitations (jitter is a common problem here)
for example sin(360.1) = 0.00174, not zero
Last edited by vipergc on Sat Apr 18, 2009 1:00 pm, edited 1 time in total.
Co-Inventor of ZIP files.

Hardware - play with it long enough.. it BREAKS
Software - play with it long enough.. it WORKS
Scarabol
Posts: 167
Joined: Sat Jan 03, 2009 5:26 pm
Location: Aachen, Germany

Post by Scarabol »

I just use:

Code: Select all

node->setRotation(node->getRotation() + vector3df(-((receiver.mouseY()-device->getVideoDriver()->getScreenSize().Height/2))*0.01f*mainplayer.turnspeed*masterspeed, ((receiver.mouseX()-device->getVideoDriver()->getScreenSize().Width/2))*0.01f*mainplayer.turnspeed*masterspeed, 0)
So it is possible that the node rotates all the time left and in my debug view node->getRotation increase equal to this, also over 360 degree...

Im just looking for a way that the node is just set to the Rotation not rotated to...
So node->setRotation() seems not to do what it should do :-(

Greetings
Scarabol
vipergc
Posts: 27
Joined: Mon Mar 02, 2009 3:33 am
Location: Louisville, KY
Contact:

Post by vipergc »

rememeber, setrotation is a RELATIVE rotation and if your calculations are off even by a slight bit, and the function is called numerous times.. it will appear to be showing a slight rotation...

computers are stupid,
they do what we tell them to do,
not what we want them to do
Co-Inventor of ZIP files.

Hardware - play with it long enough.. it BREAKS
Software - play with it long enough.. it WORKS
Scarabol
Posts: 167
Joined: Sat Jan 03, 2009 5:26 pm
Location: Aachen, Germany

Post by Scarabol »

Is there a function for absolute rotation?

The problem is that the node is rotated and not set to the rotation...

Greetings
Scarabol
vipergc
Posts: 27
Joined: Mon Mar 02, 2009 3:33 am
Location: Louisville, KY
Contact:

Post by vipergc »

Are you looking for something that will actually animate the rotation?
The setrotation() function will simply perform rotation in the 3D sense, that is the object will be rotated into a particular position..
if you are looking to spin an object, then you can either use an animated mesh object or program the rotation angle as a varying quantity and then call the setrotation() within that loop
Co-Inventor of ZIP files.

Hardware - play with it long enough.. it BREAKS
Software - play with it long enough.. it WORKS
Scarabol
Posts: 167
Joined: Sat Jan 03, 2009 5:26 pm
Location: Aachen, Germany

Post by Scarabol »

I think this shows what i mean:

Code: Select all

while (device->run())
{
node->setrotation(vector3df(180,0,0)-node->getrotation());
}
Well first, i know there is some code missing, but not necessary ;-)

I think the node should only have 2 states on screen, one with xangle = 0 and one with xangle = 180, but as u can see the node has some interstates which make him flip around, like a gyroscope...

Greetings
Scarabol
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

I think either we misunderstand your question or you misunderstand rotations in Irrlicht.

If you call setRotation on node, it will change nodes rotation relative to its parent node. If node does not have parent, than relative to global space which means it will be absolute rotation.

If you want to rotate node relative to its own rotation, not rotation of its parent, than you have to use different approach.

If you execute code:

Code: Select all

while (device->run())
{
node->setrotation(vector3df(180,0,0)-node->getrotation());
} 
and your node flips like a gyroscope, then thats perfectly fine. You ordered it to do so:

Say original rotation is 0
1th loop: 180 - 0 = 180
2nd loop: 180 - 180 = 0
3rd loop: 180 - 0 = 180
4th loop: 180 - 180 = 0

As you see you turn your node 180 degrees each frame.
Scarabol
Posts: 167
Joined: Sat Jan 03, 2009 5:26 pm
Location: Aachen, Germany

Post by Scarabol »

I'm have to say sorry to everyone, who helped me in this case, it was my mistake, i'm sorry :-)

[CLOSED]

Greetings
Scarabol
vipergc
Posts: 27
Joined: Mon Mar 02, 2009 3:33 am
Location: Louisville, KY
Contact:

Post by vipergc »

Not a problem... kudos to you... there are those.. who will never admit having screwed up...
Co-Inventor of ZIP files.

Hardware - play with it long enough.. it BREAKS
Software - play with it long enough.. it WORKS
Post Reply