HomeHome  CalendarCalendar  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log inLog in  

Share | 
 

 Rotating a system in irrlicht

View previous topic View next topic Go down 
AuthorMessage
Skreamz



Messages : 9
Date d'inscription : 2011-01-27

PostSubject: Rotating a system in irrlicht   Thu Feb 10, 2011 9:30 pm

I'm having trouble rotating a system to at the end of my missile (2D btw).
am hoping if someone could tell me what I'm doing wrong, I'll probably end up face palming myself lol.

here is the creating of the system id.

Code:

      // trail renderer
   IRRQuadRenderer* trailRenderer = IRRQuadRenderer::create(device);
   trailRenderer->setTexturingMode(TEXTURE_2D);
   trailRenderer->setTexture(device->getVideoDriver()->getTexture("point.png"));
   trailRenderer->setBlending(BLENDING_ADD);
   trailRenderer->setScale(10.0f, 10.0f);
   trailRenderer->enableRenderingHint(DEPTH_WRITE,false);
   trailRenderer->setShared(true);

   // trail model
   Model* trailModel = Model::create(FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA | FLAG_SIZE | FLAG_ANGLE | FLAG_TEXTURE_INDEX,
                                     FLAG_ANGLE | FLAG_RED | FLAG_GREEN | FLAG_BLUE,
                                     FLAG_ANGLE | FLAG_TEXTURE_INDEX,
                                     FLAG_ALPHA | FLAG_RED);
   trailModel->setParam(PARAM_BLUE,1.0f,0.2f);
   trailModel->setParam(PARAM_GREEN,0.5f,0.2f);
   trailModel->setParam(PARAM_RED,0.2f,0.2f);
   trailModel->setParam(PARAM_TEXTURE_INDEX,0.0f,4.0f);
   trailModel->setParam(PARAM_ANGLE,0.0f,PI * 0.5f,0.0f,PI * 0.5f);
   trailModel->setLifeTime(0.15f, 0.3f);
   trailModel->setShared(true);

   interpolator = trailModel->getInterpolator(PARAM_ALPHA);
   interpolator->addEntry(0.7f,1.0f);
   interpolator->addEntry(1.0f,0.0f);
   
   interpolator = trailModel->getInterpolator(PARAM_RED);
   interpolator->addEntry(0.0f,1.0f);

   Point *trailzone = Point::create();
   
   // trail emitter
   StraightEmitter* trailEmitter = StraightEmitter::create(Vector3D(0.0f, 0.0f, 1.0f));
   trailEmitter->setZone(trailzone);
   trailEmitter->setFlow(10);
   trailEmitter->setTank(50);
   trailEmitter->setForce(0.1f, 0.5f);


   // trail group
   Group* trailGroup = Group::create(trailModel,20);
   trailGroup->addEmitter(trailEmitter);
   trailGroup->setRenderer(trailRenderer);

   system = IRRSystem::create(NULL, device->getSceneManager());
   system->addGroup(trailGroup);

   basemissiletrailparticle = ((SPK::Registerable *)system)->getID();

in my missile code i create a missile trail, and set the position to the backside of my missile (unrotated), as if the missile was at point 0.0.0

Code:

   systemtrail = (IRRSystem *)SPK_Copy(System, trailid);
   systemtrail->setParent(device->getSceneManager()->getRootSceneNode());

   Point *zone = (Point *)systemtrail->getGroup(0)->getEmitter(0)->getZone();
   zone->setPosition(Vector3D(0.0f, (MISSILE_SIZE / 2), 0.0f));

and here is the code trying to rotate the system so it stays to the missile's backside.

Code:

      systemtrail->setPosition(irr::core::vector3df(pos.X, pos.Y, 0.0f));

      core::matrix4 m;
      m.setRotationCenter(irr::core::vector3df(0.0f, 0.0f, 0.0f), systemtrail->getPosition());
      m.setRotationDegrees(irr::core::vector3df(0.0f, 0.0f, atan2(targpos.Y - pos.Y, targpos.X - pos.X) * irr::core::RADTODEG));
      core::matrix4 from;
      from.setRotationDegrees(systemtrail->getRotation());
      from.setTranslation(systemtrail->getPosition());
      core::matrix4 newM=m*from;
      systemtrail->setPosition(newM.getTranslation());
      systemtrail->setRotation(newM.getRotationDegrees());

i know its quite a bit to look at, but any help would be grateful.
thanks.
Back to top Go down
View user profile
Juff
Developer


Messages : 539
Date d'inscription : 2009-07-14
Age : 34

PostSubject: Re: Rotating a system in irrlicht   Fri Feb 11, 2011 10:30 am

Hi. Why dont you simply set your IRRsystem node as a child of your missile node ?
Back to top Go down
View user profile http://spark.developpez.com
Skreamz



Messages : 9
Date d'inscription : 2011-01-27

PostSubject: Re: Rotating a system in irrlicht   Fri Feb 11, 2011 12:24 pm

basically i had to write my own 2D drawing functions to be able to rotate my sprites and do other things that is not inbuilt into irrlicht. i guess i could write a 2dsprite scene node. but wasn't sure if this was the best route to take, as the engine itself kept all 2d drawing functions as a member of the IVideoDriver.
Back to top Go down
View user profile
Juff
Developer


Messages : 539
Date d'inscription : 2009-07-14
Age : 34

PostSubject: Re: Rotating a system in irrlicht   Fri Feb 11, 2011 12:39 pm

ok, so basically :

The position of the system is the position of the missile : system->setPosition(missilePos)
The rotation of the system is the rotation of the missile. As we re in 2D, it is a rotation around the z axis. so the vector to pass to system->setRotation will look like this (0.0f,0.0f,angle)
Now you got to find the angle. An arctan is ok if the missile's direction is defined by a vector. Given your equation, it seems that your missile follow a straight line. If it is not the case, dont compute the direction with target - pos but rather with pos - oldPos (the pos at the previous frame).

So what you have to do is only (pseudo code) :

Code:

systemTrail->setPosition(missilePos)
systemTrail->setRotation(vector(0.0f,0.0f,getMissileAngle(missileRot)))

In addition, you can take a look at the SFML demo which renders smoke behind cars in 2D.
Back to top Go down
View user profile http://spark.developpez.com
Skreamz



Messages : 9
Date d'inscription : 2011-01-27

PostSubject: Re: Rotating a system in irrlicht   Fri Feb 11, 2011 7:22 pm

i gave pos - oldPos but im getting the same strange problem.
heres an image, as you can see, the the trail is offset on the right. but if i apply no rotation it is at the bottom where it should be, unless the missile is rotated then it looks weird :p



here is the new code

Code:

      irr::core::vector2df p;
      p.Y = pos.Y + dtime * direction.Y * speed;
      p.X = pos.X + dtime * direction.X * speed;

      systemtrail->setRotation(irr::core::vector3df(0.0f, 0.0f, atan2(p.Y - pos.Y, p.X - pos.X) * irr::core::RADTODEG));
      systemtrail->setPosition(irr::core::vector3df(p.X, p.Y, 0.0f));
      pos = p;
Back to top Go down
View user profile
Skreamz



Messages : 9
Date d'inscription : 2011-01-27

PostSubject: (SOLVED)   Sat Feb 12, 2011 2:10 am

Juff thanks for your help,

i seemed to have forgotton that the atan gives angle based horizontal, so i had to add 90 deg to the answer. (facepalm).

thanks again for you time.
Back to top Go down
View user profile
Sponsored content




PostSubject: Re: Rotating a system in irrlicht   Today at 3:43 am

Back to top Go down
 
Rotating a system in irrlicht
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» [IMPLEMENTED] Registry tweak to disable File System Tunneling
» Latest Topic System v5
» [Solved] how to change text colour of my Latest Topic System v5
» Dell System Recovery Partition Hotkey & Instructions (Dell PC Restore)
» Acer System Recovery Partition Hotkey & Instructions (eRecovery)

Permissions in this forum:You cannot reply to topics in this forum
 :: English Forum :: Questions (en)-
Jump to: