Page 1 of 1

How to realize rotation with constant angular speed

Posted: Sun Apr 03, 2011 5:42 am
by Morganolla
Hi guys. Well, I have a 3D vector of angular speed (for example core::vector3df W). How to realize rotation of a body (node) with constant vector of angular speed (vector W)? I try method Rotation(), but it's not correct in this case... :(

Posted: Sun Apr 03, 2011 7:14 am
by nespa
this will rotate an object around its local axees with X,Y,Z speed each frame:

Code: Select all

    ISceneNode* Spaceship;
      vector3df rp(X,Y,Z);
      vector3df r = Spaceship->getRotation(); //get current rotation (euler)

      matrix4 m;
      matrix4 mp;
      m.setRotationDegrees(r); //set matrix to current rotation
      mp.setRotationDegrees(rp); //set second matrix to rotation to add
      m *= mp; //multipy them

      r = m.getRotationDegrees(); //get rotation vector from matrix (euler)
      
      Spaceship->setRotation(r); //rotate node 


Posted: Sun Apr 03, 2011 8:40 am
by Morganolla
Thanks a lot!

Posted: Sun Apr 03, 2011 11:37 am
by Radikalizm
Why don't you just use a rotation animator? How I see it this does exactly what you want to achieve

I don't get why some people on these forums have such a hard time using and writing animators, it produces very clean code (perfectly following an OOP design), doesn't require you to clog up your drawing loop and is just very easy to use and will probably make your project more manageable

Posted: Sun Apr 03, 2011 12:41 pm
by Morganolla
2Radikalizm -
Sorry, do you mean - createRotationAnimator ()?

Posted: Sun Apr 03, 2011 12:44 pm
by Radikalizm
Morganolla wrote:2Radikalizm -
Sorry, do you mean - createRotationAnimator ()?
Yes, that's the one ;)

Posted: Sun Apr 03, 2011 1:56 pm
by Morganolla
Dear friend, this animator (RotationAnimator ) at all doesn't correspond to my physical problem - to realize free rotation of a body in 3D space. I wrote my own animator.
PS . From this point of view the Irrlicht engine structure not so corresponds to a problem of modeling of kinematics unlike game developing. :)

Posted: Sun Apr 03, 2011 2:33 pm
by Radikalizm
Morganolla wrote:Dear friend, this animator (RotationAnimator ) at all doesn't correspond to my physical problem - to realize free rotation of a body in 3D space. I wrote my own animator.
PS . From this point of view the Irrlicht engine structure not so corresponds to a problem of modeling of kinematics unlike game developing. :)
In what way does your animator differ from the regular rotation animator? The rotation animator provides free 360° rotation around the local axes of the body, so I don't really understand what you're actually looking for

Also, if you want accurate physics simulation you should use a physics engine, irrlicht on its own is just a rendering engine and is not meant to accurately handle physical phenomena
With a physics engine you can actually define rotations in terms of angular velocities

Posted: Sun Apr 03, 2011 7:54 pm
by Morganolla
...The rotation animator provides free 360° rotation around the local axes of the body....

Sorry, guy, not exactly local axis.(z angel -seems be global...)

Also, if you want accurate physics simulation you should use a physics engine, irrlicht on its own is just a rendering engine and is not meant to accurately handle physical phenomena

Thanks, I think so too, but while I won't take complex physics engine... ;)

Posted: Sun Apr 03, 2011 9:16 pm
by Radikalizm
Morganolla wrote:...The rotation animator provides free 360° rotation around the local axes of the body....

Sorry, guy, not exactly local axis.(z angel -seems be global...)

Also, if you want accurate physics simulation you should use a physics engine, irrlicht on its own is just a rendering engine and is not meant to accurately handle physical phenomena

Thanks, I think so too, but while I won't take complex physics engine... ;)
Of course, there's always the case of gimbal lock which takes away a degree of freedom when using euler angles, but what exactly are you trying to rotate? It's very unlikely that 2 rotation angles are local and that the other one is global, it doesn't really work that way, so maybe the problem lies somewhere else?

And physics engines don't have to be complex in usage, there are a lot of wrappers available on these forums which are rather easy to add and to use

Posted: Sun Apr 03, 2011 9:24 pm
by ChaiRuiPeng
i would not exactly say bullet is complex... it might seem like a scary task taking that it IS a big library and has a lot of neat features, but what is great about bullet is its modular design, so you can just pick and choose which parts you want to use.

Posted: Mon Apr 11, 2011 5:19 pm
by Morganolla
Hi again. I realise rotation of space ship ( in my simulator game) like "nespa" wrote earlier (by multiply matrix). But now I have a little bug :(. When i rotate ship around Y axis very slowly at angel +90 degree or -90 degree - the ship stop and disappear from screen :) . It seems to me somewhere is division by zero (or Cos(90 degree)) . How can I resolve this problem ?
PS I can give my demo (.exe), or code (.cpp) of my ship animator if its necessary...

Posted: Mon Apr 11, 2011 6:45 pm
by nespa
if (angle==90)
{
angle=90.01;
}

something like that....., depends of the sens of rotation...


or try this:

if(r.Y == 0.0f)
{
r.Y = 0.001f;
}
if(r.Y == 180.0f)
{
r.Y = 180.001f;
}


ohh, no, at very small angular steps, it happened;

try to work with angular step greater or equal with 1.0f (>=1.0f)

Posted: Mon Apr 11, 2011 7:05 pm
by Morganolla
thanks, It's works, I tried already. But I think this partial corrections is not good way. May be exist correct general approach?