I use left and right arrows to rotate the character arround the Y axis. The up and down arrows are used to move the character forwards and backwards respectivelly.
The handling of left and right arrows is pretty simple:
Code: Select all
if(receiver->IsKeyDown(KEY_LEFT)){
vector3df r = box->getRotation();
float speed = 2;
vector3df inc = vector3df(0,-1,0) * speed;
r = r+inc;
box->setRotation(r);
}
Code: Select all
if(receiver->IsKeyDown(KEY_UP)){
vector3df v = box->getPosition();
vector3df r = -box->getRotation();
r *= DEGTORAD;
quaternion q(r);
float speed = 0.1;
vector3df inc = (vector3df(0,0,1));
quaternion resq(inc.X, inc.Y, inc.Z, 0);
resq = q * resq;
q.makeInverse(); // q * resq * q^(-1)
resq = resq*q;
box->setPosition( v + vector3df(resq.X, resq.Y, resq.Z)*speed );
}
Code: Select all
vector3df r = -box->getRotation();
I will attach the full code(still do not know how).
http://tuket.webcindario.com/follow.zip
Thanks in advance.