All pastes #507758 Raw Edit

Anonymous

public cpp v1 · immutable
·published 2007-05-24 18:48 UTC
rendered paste body
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   cam->setPosition(vector3df(0,30,-30)); //so we're behind the plane   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 forward(sin(tn->getRotation().Y*PI/180.0f), 0, cos(tn->getRotation().Y*PI/180.0f));   plane->mesh()->setPosition(plane->mesh()->getPosition() + forward);   cam->setTarget(plane->mesh()->getPosition());   lastMousePos = mousePos;  }};