How to realize rotation with constant angular speed

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
Morganolla
Posts: 44
Joined: Tue Nov 17, 2009 9:56 am
Location: Rus

How to realize rotation with constant angular speed

Post 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... :(
nespa
Posts: 167
Joined: Wed Feb 24, 2010 12:02 pm

Post 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 

Morganolla
Posts: 44
Joined: Tue Nov 17, 2009 9:56 am
Location: Rus

Post by Morganolla »

Thanks a lot!
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post 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
Morganolla
Posts: 44
Joined: Tue Nov 17, 2009 9:56 am
Location: Rus

Post by Morganolla »

2Radikalizm -
Sorry, do you mean - createRotationAnimator ()?
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

Morganolla wrote:2Radikalizm -
Sorry, do you mean - createRotationAnimator ()?
Yes, that's the one ;)
Morganolla
Posts: 44
Joined: Tue Nov 17, 2009 9:56 am
Location: Rus

Post 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. :)
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post 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
Morganolla
Posts: 44
Joined: Tue Nov 17, 2009 9:56 am
Location: Rus

Post 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... ;)
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post 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
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post 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.
ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
Morganolla
Posts: 44
Joined: Tue Nov 17, 2009 9:56 am
Location: Rus

Post 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...
nespa
Posts: 167
Joined: Wed Feb 24, 2010 12:02 pm

Post 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)
Morganolla
Posts: 44
Joined: Tue Nov 17, 2009 9:56 am
Location: Rus

Post 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?
Post Reply