Smooth rotation - question

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
newbi

Smooth rotation - question

Post by newbi »

Maybe my question is silly but can anyone tell me how to do smooth rotation of node ?
I have node ( ship ) and I face it to direction where it has to be moved

Code: Select all

vector3df currentPos = Node->getPosition();

vector3df angle = currentPos - newPos;

Node->setRotation(angle.getHorizontalAngle());
This code rotate node into good direction but node jumps, teleports. I hope you know what I mean and forgive my crooked English :D

And one more question, how can I make ships going in formation, not going through itself :?:
FrSl
Posts: 19
Joined: Thu Jan 19, 2006 5:03 pm

Post by FrSl »

You need to code a smooth rotation yourself i think, something like this:

Code: Select all

while(device->run()) //main loop
{
   rotationDone = false;
   while( ship->getRotation()->getX() < angleYouWant && !rotationDone)
   {
      core::vector3df smoothRotation = core::vector3df(0.01*3.14, 0, 0);
      ship->setRotation(ship->getRotation() + smoothRotation); 
      rotationDone = true;
   }
}
For the second formation part i would use a array with a couple of vectors(positions) and set the ships in place with a for loop like this:

Code: Select all

k=0;
for (int x=0;x<=ships;x++)
{   
   ship[x]->setPosition(shipPositions[k]);
   k++;
   if (k > 2)
      k = 0;
}
Good luck with it! 8)
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

What's best is to do time based movement, so it's independent of the frame rate. To do that you work out the time elapsed since the last frame was rendered, and then you rotate the ship based on that amount, using a distance = speed * time approach. So each frame you check the ship to see if it currenly wants to rotate and if so you update its rotation using the elapsed time since the last frame. When your ship wants to rotate it simply sets its wantToRotate flag to true and then sets its desired rotation, so then you can tell when you've rotated far enough.

Hope that makes sense!
Image Image Image
newbi

Post by newbi »

Ok, I manage to do rotation and some kind of formation movement. Here comes another problem, explosion. I made nice looking particle box emitter, and I add delete animator to it. What should I do if I want explosion slowly disappearing :?:
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I nicked something of dhenton9000's from his game which was a load of png images of an explosion at various stages which can be loaded into irrlicht and displayed as an animation, looks quite nice and may well be suitable for you too. I think he links to the game in his signature, or you can search through the memberlist for him. I'd upload it for you myself but i feel his knowledge of your using it might be better, i'm not even sure if he knows i nicked it for my project either :oops: But he did get an acknowledgement in my dissertation for it :wink:
Image Image Image
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Here's the thread he made it available in when i got it:
http://irrlicht.sourceforge.net/phpBB2/ ... sion#64280
Image Image Image
Post Reply