Page 1 of 1

Direction!?

Posted: Sat Nov 11, 2006 5:45 pm
by omar shaaban
How can i change the direction of movement of a node?
i have tried to rotate it but it keep moving in the same direction !!

Posted: Sat Nov 11, 2006 6:23 pm
by Watcher
I thing that a good way is to create a fps camera (it has function seTarget) and set set your node as a child.

Posted: Sat Nov 11, 2006 6:25 pm
by omar shaaban
:shock: :shock: what there is no other way!!!!! every 3d engine has the ability to change the directon!!!! another help plz

Posted: Sat Nov 11, 2006 6:33 pm
by JP
There is another way. You keep a record of the forward vector of the node and then when you update its position you can do node->setPosition(node->getPosition()+forwardVector*amount);

amount being how far you want to go forward. The forward vector would be vector3df(1,0,0) if it was facing straight down the x axis and then you can rotate it using trig or matrices to keep it updated as your node rotates.

I think that would work anyway, my mind isn't in much of a working mood atm!

Posted: Sat Nov 11, 2006 6:57 pm
by omar shaaban
:? u made me depresed of the engine :(

Posted: Sat Nov 11, 2006 8:00 pm
by JP
Any reason? It's really not that hard... I don't have experience of other engines so i don't know if other ones handle it differently. If you know a better one why did you stop using it? ;)

Posted: Sat Nov 11, 2006 8:21 pm
by omar shaaban
:roll: ok ok can any one tells me a code how to do it i have a code but it is for 2d i am trying to make it 3d

Posted: Sat Nov 11, 2006 8:46 pm
by vitek

Code: Select all

  core::vector3df forward(0, 0, 1);

  core::matrix4 m;
  m.setRotationDegrees( node->getRotationDegrees() );

  // rotate the forward vector into parent coords
  m.rotateVect(forward);

  // get the old position
  core::vector3df position(node->getPosition());

  // get the distance moved this time slice
  f32 distance = velocity * time;

  // augment the node position
  position += (forward * distance);
  node->setPosition(position);

Posted: Sat Nov 11, 2006 9:06 pm
by omar shaaban
:x Finally after 3 hours i made this code

Code: Select all

core::vector3df c = ship->getPosition();
         core::vector3df d= ship->getRotation();
float diry = ((d.Y+90)*3.14)/180;
        if (up)
         {

            c.X += speed * cos((d.Y) * 3.14 / 180);
  c.Z -= speed * sin((d.Y) * 3.14 / 180);

         }
         if (down)
         {
                     c.X -= speed * cos((d.Y) * 3.14 / 180);
  c.Z += speed * sin((d.Y) * 3.14 / 180);
         }
         if (left)
         {
            d.Y -= 0.1;
         }
         if (right)
         {
            d.Y += 0.1;
         }
ship->setRotation(d);
core::stringw cy = d.Y;
device->setWindowCaption(cy.c_str());


int xf = (c.X-sin(diry)*125);
int yf =(c.Z-cos(diry)*125);
int zf =100;

ship->setPosition(c);


         camera->setTarget(c);

         c.Y +=200.f;
         c.Z -= 150.f;

         camera->setPosition(vector3df(xf,zf,yf));
      }
      else
      {
         // clear keys when window goes out of focus
         up = down = left = right = false;
      }
   }

   device->drop();

   return 0;
}
thanx every one for your suport and thanx vitek but i will use my way :wink: