Problem with node->SetRotation
Problem with node->SetRotation
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
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
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
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
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
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
Hardware - play with it long enough.. it BREAKS
Software - play with it long enough.. it WORKS
I just use:
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
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)
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
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
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
Hardware - play with it long enough.. it BREAKS
Software - play with it long enough.. it WORKS
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
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
Hardware - play with it long enough.. it BREAKS
Software - play with it long enough.. it WORKS
I think this shows what i mean:
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
Code: Select all
while (device->run())
{
node->setrotation(vector3df(180,0,0)-node->getrotation());
}
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
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:
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.
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());
}
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.