void CreateCamera(int width, int height, vector3df position, vector3df target) { //Build camera ISceneManager* sm = g_GameGraph->GetSceneManager(); WorldState* worldState = static_cast<WorldState*> (g_GameGraph->GetWorldState()); HexMap* hm = worldState->GetCurrentMap(); if (NULL != sm) { if (NULL != hm) { ICameraSceneNode* orthoCam = sm->addCameraSceneNode( sm->getRootSceneNode(), position, target); matrix4 projMat; projMat.buildProjectionMatrixOrthoLH(width, height, -5, 5); orthoCam->setProjectionMatrix(projMat, true); orthoCam->bindTargetAndRotation(true); if (orthoCam->isOrthogonal()) { CameraAnimator* cameraAnim = new CameraAnimator(position, width, height, hm->GetMapDimensions().Height, hm->GetMapDimensions().Width, worldState->GetHero(), hm->GetCoordinateTranslator()); orthoCam->addAnimator(cameraAnim); cameraAnim->drop(); cameraAnim = NULL; if (width > height) { LOGI("Creating a landscape camera."); landscapeCamera = orthoCam; } else { LOGI("Creating a portrait camera"); portraitCamera = orthoCam; } } else { LOGE("The created camera is not orthoganol, something is wrong with the perspective matrix."); } } else { LOGE("The hex map created in the WorldState is NULL."); } } else { LOGE("The scene manager cannot be loaded from the device."); } }
int main() { // create device EventHandler receiver; Init(); Output(); ISceneNode* objects [MAX_OBJECTS]; IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<u32>(ResX, ResY), 32, fullscreen, false, vsync, &receiver); receiver.device = device; if (!device) return 1; IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); HMDDescriptor HMD; // Parameters from the Oculus Rift DK1 HMD.hResolution = ResX; HMD.vResolution = ResY; HMD.hScreenSize = 0.14976; HMD.vScreenSize = 0.0936; HMD.interpupillaryDistance = 0.064; HMD.lensSeparationDistance = 0.064; HMD.eyeToScreenDistance = 0.041; HMD.distortionK[0] = 1.0; HMD.distortionK[1] = 0.22; HMD.distortionK[2] = 0.24; HMD.distortionK[3] = 0.0; HMDStereoRender renderer(device, HMD, 10); #ifdef OCCULUS ICameraSceneNode* camera = smgr->addCameraSceneNode(); camera->bindTargetAndRotation(false); camera->setTarget(vector3df(1,0,0)); #else ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(); #endif device->getCursorControl()->setVisible(false); // load a faerie IAnimatedMesh* faerie = smgr->getMesh("media/faerie.md2"); IAnimatedMeshSceneNode* faerieNode = smgr->addAnimatedMeshSceneNode(faerie); faerieNode->setMaterialTexture(0, driver->getTexture("media/faerie2.bmp")); faerieNode->setMaterialFlag(EMF_LIGHTING, false); faerieNode->setPosition(vector3df(40,190,-1030)); faerieNode->setRotation(vector3df(0,-90,0)); faerieNode->setMD2Animation(EMAT_SALUTE); // load a dwarf IAnimatedMesh* dwarf = smgr->getMesh("media/dwarf.x"); IAnimatedMeshSceneNode* dwarfNode = smgr->addAnimatedMeshSceneNode(dwarf); dwarfNode->setPosition(vector3df(40,-25,20)); Level currentLevel(device); currentLevel.makeLevel(0); smgr->setAmbientLight(video::SColorf(0.1,0.1,0.1,1)); ILightSceneNode* light1 = smgr->addLightSceneNode( camera , vector3df(0,0,0), video::SColorf(0.3f,0.4f,0.4f), 80.0f, 1 ); vector3df pos = vector3df(0,0,0); //naplníme tunel pøekážkama srand (time(NULL)); /* generate secret number between 1 and 10: */ for(int i = 0; i < MAX_OBJECTS; i++){ objects[i] = smgr->addCubeSceneNode(2); objects[i]->setMaterialFlag(EMF_LIGHTING, false); objects[i]->setPosition( vector3df( (rand() % 30) - 5, (rand() % 30) - 5, rand() % 80) ); } //device->setInputReceivingSceneManager(smgr); //použivane pro vector3df tempRot; irr::core::quaternion tempQ; irr::core::matrix4 tempM; float round = 0; while(device->run()) { round += 0.01; driver->beginScene(true, true, SColor(255,100,101,140)); for(int i = 0; i < MAX_OBJECTS; i++){ vector3df tmpPos = objects[i]->getPosition(); if(tmpPos.Z > pos.Z) continue; objects[i]->setPosition( vector3df( (rand() % 30) - 15, (rand() % 30) - 15, rand() % 80 + pos.Z) ); } #ifndef OCCULUS tempM.setRotationDegrees(vector3df(sin(round*0.5)*360-180, sin(round)*360-180, cos(round*0.8)*360-180)); // transform forward vector of camera irr::core::vector3df frv = irr::core::vector3df (0.0f, 0.0f, 1.0f); tempM.transformVect(frv); // transform upvector of camera irr::core::vector3df upv = irr::core::vector3df (0.0f, 1.0f, 0.0f); tempM.transformVect(upv); camera->setUpVector(upv); //set up vector of camera camera->setTarget(frv); //set target of camera (look at point) (thx Zeuss for correcting it) #endif if(pSensor){ Quatf quaternion = FusionResult.GetOrientation(); ICameraSceneNode* camera = smgr->getActiveCamera(); tempQ.set(-quaternion.z,quaternion.y,-quaternion.x, quaternion.w); tempQ.normalize(); tempQ.toEuler(tempRot); tempM.setRotationDegrees(tempRot); // transform forward vector of camera irr::core::vector3df frv = irr::core::vector3df (0.0f, 0.0f, 1.0f); tempM.transformVect(frv); // transform upvector of camera irr::core::vector3df upv = irr::core::vector3df (0.0f, 1.0f, 0.0f); tempM.transformVect(upv); camera->setUpVector(upv); //set up vector of camera camera->setTarget(frv); //set target of camera (look at point) (thx Zeuss for correcting it) // update absolute position camera->updateAbsolutePosition(); float yaw, pitch, roll; quaternion.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(&yaw, &pitch, &roll); camera->getParent()->setRotation( vector3df(RadToDegree(pitch),RadToDegree(yaw),RadToDegree(roll))); //camera->setRotation( vector3df(RadToDegree(-pitch),RadToDegree(-yaw),RadToDegree(roll))); //camera->setProjectionMatrix(ToMatrix(quaternion)); cout << " Yaw: " << RadToDegree(yaw) << ", Pitch: " << RadToDegree(pitch) << ", Roll: " << RadToDegree(roll) << endl; if (_kbhit()) exit(0); } #ifdef OCCULUS renderer.drawAll(smgr); #else smgr->drawAll(); #endif guienv->drawAll(); driver->endScene(); } device->drop(); Clear(); return 0; }