#include "graphics.cpp" #define PI 3.14159 using namespace irr; using namespace scene; using namespace core; using namespace io; /** Map class * holds the map * mesh and collision * detection stuff for * the map */ class CMap { protected: CMesh *map; public: CMap() { map = new CMesh("map.obj"); map->setScale(400,400,400); } CMesh *getMesh() { return map; } }; /** Player class * holds the camera * and stuff about the * player. */ class CPlayer { protected: ICameraSceneNode* cam; CMesh *plane; position2d 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 mousePos = position2d((s32)0,(s32)0); lastMousePos = position2d((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(cam->getRotation().Y*PI/180.0f), 0, cos(cam->getRotation().Y*PI/180.0f)); plane->mesh()->setPosition((cam->getPosition() + Forwards) * 15.0f); // move to there cam->setPosition(plane->mesh()->getPosition + vector3df(0,30,-30)); //adjust that to be as close/far away to the plane as needed cam->setTarget(plane->mesh()->getPosition()); lastMousePos = mousePos; } }; /*TODO! CTurret & CBullet class*/ /**Globals of the player, the map, and the turrets*/ CPlayer *p; CMap *m; // the event reciever #include "event.cpp" int main() { MyEventReceiver rv; device = createDevice(video::EDT_OPENGL, core::dimension2d(640, 480)); driver = device->getVideoDriver(); smgr = device->getSceneManager(); colmgr = smgr->getSceneCollisionManager(); device->setEventReceiver(&rv); p = new CPlayer(); m = new CMap(); while(device->run() && device) { p->go(); render(); stringw title = "[zP] "; title += driver->getFPS(); title += " [zP]"; device->setWindowCaption(title.c_str()); } };