class CPlayer {
protected:
ICameraSceneNode* cam;
CMesh *plane;
position2d<s32> mousePos, lastMousePos;
public:
CPlayer() {
plane = new CMesh("plane.x");
plane->setPosition(0,0,5); // set it to right infront of us
plane->setRotation(0,180,0); // its facing twards us, make it face away
cam = smgr->addCameraSceneNode(); // add our camera
//cam->setParent(plane->mesh());
plane->mesh()->setParent(cam); // make the plane a child of the camera
mousePos = position2d<s32>((s32)0,(s32)0);
lastMousePos = position2d<s32>((s32)0,(s32)0);
}
ICameraSceneNode* getCam() {
return cam;
}
/*Go function to update the camera*/
void go() {
mousePos = device->getCursorControl()->getPosition();
if(mousePos.X > lastMousePos.X) { // moved to the right
// move camera
vector3df p = cam->getRotation();
p.Y += 1;
cam->setRotation(p);
// tilt plane
vector3df z = plane->getRotation();
z.Z += 1;
plane->mesh()->setRotation(z);
}
if(mousePos.X < lastMousePos.X) { // moved to the left
// move camera
vector3df p = cam->getRotation();
p.Y -= 1;
cam->setRotation(p);
// tilt plane
vector3df z = plane->getRotation();
z.Z -= 1;
plane->mesh()->setRotation(z);
}
if(mousePos.Y > lastMousePos.Y) { // moved down
vector3df p = cam->getRotation();
p.X += 1;
cam->setRotation(p);
}
if(mousePos.Y < lastMousePos.Y) { // moved up
vector3df p = cam->getRotation();
p.X -= 1;
cam->setRotation(p);
}
//vector3df Forwards = (cam->getTarget() - cam->getPosition()).normalize(); // wheres infront of us?
vector3df Forwards = cam->getTarget().normalize();
cam->setPosition(cam->getPosition() + Forwards); // move to there
plane->mesh()->setParent(cam); // set the plane to the child of the camera, AGAIN
lastMousePos = mousePos;
}
};