int main() { // we'll use the OGL driver IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2du(640, 480), 16, false, false, false, 0); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); // load sydney IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2"); // squash her! CSquashingMeshSceneNode* node = new CSquashingMeshSceneNode( mesh->getMesh(0), 0, smgr, 0 ); if (node) { node->setMaterialFlag(EMF_LIGHTING, false); node->setPosition( vector3df(0,0,50)); node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") ); } smgr->addCameraSceneNodeFPS(); int lastFPS = -1; while(device->run()) { driver->beginScene(true, true, SColor(255,100,101,140)); node->render(); node->OnPostRender(device->getTimer()->getTime()); smgr->drawAll(); guienv->drawAll(); driver->endScene(); int fps = driver->getFPS(); if (lastFPS != fps) { core::stringw str = L"Irrlicht Mesh Deformation Contest ["; str += driver->getName(); str += "] FPS:"; str += fps; device->setWindowCaption(str.c_str()); lastFPS = fps; } } device->drop(); return 0; }
int main() { int rows = 10, colums = 10; printf("Number of stack rows: "); cin >> rows; printf("\nNumber of stack colums: "); cin >> colums; CReceiver receiver; IrrlichtDevice *device = createDevice(EDT_DIRECT3D9, dimension2d<u32>(640, 480), 16, false, false, false, &receiver); IVideoDriver *driver = device->getVideoDriver(); ISceneManager *smgr = device->getSceneManager(); IGUIEnvironment *guienv = device->getGUIEnvironment(); device->setWindowCaption(L"HelloWorld"); irrBulletWorld * world = createIrrBulletWorld(device, true, true); world->setDebugMode(EPDM_DrawAabb | EPDM_DrawContactPoints); world->setGravity(core::vector3df(0, -10, 0)); createWorld(rows, colums, device, world); scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(); camera->setPosition(core::vector3df(50, 15, 200)); u32 then = device->getTimer()->getTime(); while (device->run()) { const u32 now = device->getTimer()->getTime(); const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // в секундах then = now; if (receiver.isMouseDown(EMIE_RMOUSE_PRESSED_DOWN)) { core::vector3df pos(camera->getPosition().X, camera->getPosition().Y, camera->getPosition().Z); scene::ISceneNode *Node = smgr->addCubeSceneNode(); Node->setScale(core::vector3df(0.2, 0.2, 0.2)); Node->setPosition(pos); Node->setMaterialFlag(video::EMF_LIGHTING, false); Node->setMaterialTexture(0, driver->getTexture("../rockwall.jpg")); ICollisionShape *shape = new IBoxShape(Node, 1, true); IRigidBody *body = world->addRigidBody(shape); body->setDamping(0.2, 0.2); body->setFriction(0.4f); body->setGravity(core::vector3df(0, -10, 0)); core::vector3df rot = camera->getRotation(); core::matrix4 mat; mat.setRotationDegrees(rot); core::vector3df forwardDir(core::vector3df(mat[8], mat[9], mat[10]) * 120); body->setLinearVelocity(forwardDir); } driver->beginScene(true, true, video::SColor(255, 100, 101, 140)); world->stepSimulation(frameDeltaTime, 120); world->debugDrawWorld(true); world->debugDrawProperties(true); smgr->drawAll(); guienv->drawAll(); driver->endScene(); if (world) delete world; device->drop(); return 0; } }
void Player::Init(UnitObject* pUnit,ITriangleSelector* pTerrain) { Irrdevice* pDevice = Irrdevice::GetInstance(); m_pUnitObject = pUnit; ISceneManager* pSmgr = pDevice->GetSceneManager(); SKeyMap aKeyMap[5]; aKeyMap[0].Action = EKA_MOVE_FORWARD; aKeyMap[0].KeyCode = KEY_KEY_W; aKeyMap[1].Action = EKA_MOVE_BACKWARD; aKeyMap[1].KeyCode = KEY_KEY_S; aKeyMap[2].Action = EKA_STRAFE_LEFT; aKeyMap[2].KeyCode = KEY_KEY_A; aKeyMap[3].Action = EKA_STRAFE_RIGHT; aKeyMap[3].KeyCode = KEY_KEY_D; aKeyMap[4].Action = EKA_JUMP_UP; aKeyMap[4].KeyCode = KEY_SPACE; //각 유닛마다 카메라 생성 m_pCamera = pSmgr->addCameraSceneNodeFPS(0,100.0f,0.5f,-1,aKeyMap,9,false,0,false,false); m_pCollisionAnimator = static_cast<ISceneNodeAnimatorCameraFPS*>(*(m_pCamera->getAnimators().begin())); //카메라가 가지고 있는 FPS 카메라 애니메이션 을 가지온다. 이것은 줌 확대 기능 등!! //카메라 따라댕기는 유닉 오브젝트... 방향에 대한것도 설정해줘야함... 이것은 일단 나중에 테스트를 위하여 m_pUnitObject->GetAnimatedNode()->setParent(m_pCamera); IMeshSceneNode* pNode = pSmgr->addCubeSceneNode(10,m_pCamera); m_pCamera->addChild(pUnit->GetAnimatedNode()); pNode->setVisible(true); m_pMyTriangle = pSmgr->createTriangleSelector(pNode->getMesh(),pNode); m_pMetaTriangle = pSmgr->createMetaTriangleSelector(); m_pMetaTriangle->addTriangleSelector(pTerrain); //역시 스크립트 적용 안할 수가 없다... 파일을 읽어와서 적용하던지.... 아우 ISceneNodeAnimatorCollisionResponse * pani = pSmgr->createCollisionResponseAnimator(m_pMetaTriangle,m_pCamera); m_pCamera->addAnimator(pani); pani->drop(); }
CIrr3DCamera(_string &name, _TRANSFORM & t, _CAMERA_PARAM ¶m) { static bool firstCam = true; m_camNode = NULL; ISceneManager* smgr = irrDevice->getSceneManager(); //m_camNode = smgr->addCameraSceneNodeFPS(0, 40.0f, 0.01f, -1, 0, 0, false, // 0, false, firstCam); m_camNode = smgr->addCameraSceneNodeFPS(0,40.0f, 0.005); if (firstCam) { firstCam = false; } if (m_camNode == NULL) { printf("CIrr3DCamera, failed to create camera\n"); return; } // irrDevice->getCursorControl()->setVisible(false); m_camNode->setPosition(t.position); vector3df euler; t.quaternion.toEuler(euler); euler = euler*core::RADTODEG; euler.X += 89.8; m_camNode->setRotation(euler); // printf("rotate:(%f,%f,%f)\n",(euler.X), (euler.Y), (euler.Z)); // rotate(t.quaternion); setFov(param.fov); setNear(param.nearDist); setFar(param.farDist); m_camNode->setName(name); }
/* Ok, now the main-function: First, we initialize the device, get the SourceManager and VideoDriver, load an animated mesh from .md2 and a map from .pk3. Because that's old stuff, I won't explain every step. Just take care of the maps position. */ int main() { // ask user for driver video::E_DRIVER_TYPE driverType=driverChoiceConsole(); if (driverType==video::EDT_COUNT) return 1; //Instance of the EventReceiver MyEventReceiver receiver; //Initialise the engine IrrlichtDevice *device = createDevice(driverType, dimension2du(ResX,ResY), 32, fullScreen, false, false, &receiver); if (!device) return 1; ISceneManager *smgr = device->getSceneManager(); IVideoDriver *driver = device->getVideoDriver(); //Load model IAnimatedMesh *model = smgr->getMesh("../../media/sydney.md2"); if (!model) return 1; IAnimatedMeshSceneNode *model_node = smgr->addAnimatedMeshSceneNode(model); //Load texture if (model_node) { ITexture *texture = driver->getTexture("../../media/sydney.bmp"); model_node->setMaterialTexture(0,texture); model_node->setMD2Animation(scene::EMAT_RUN); //Disable lighting (we've got no light) model_node->setMaterialFlag(EMF_LIGHTING,false); } //Load map device->getFileSystem()->addFileArchive("../../media/map-20kdm2.pk3"); IAnimatedMesh *map = smgr->getMesh("20kdm2.bsp"); if (map) { ISceneNode *map_node = smgr->addOctreeSceneNode(map->getMesh(0)); //Set position map_node->setPosition(vector3df(-850,-220,-850)); } /* Now we create our four cameras. One is looking at the model from the front, one from the top and one from the side. In addition there's a FPS-camera which can be controlled by the user. */ // Create 3 fixed and one user-controlled cameras //Front camera[0] = smgr->addCameraSceneNode(0, vector3df(50,0,0), vector3df(0,0,0)); //Top camera[1] = smgr->addCameraSceneNode(0, vector3df(0,50,0), vector3df(0,0,0)); //Left camera[2] = smgr->addCameraSceneNode(0, vector3df(0,0,50), vector3df(0,0,0)); //User-controlled camera[3] = smgr->addCameraSceneNodeFPS(); // don't start at sydney's position if (camera[3]) camera[3]->setPosition(core::vector3df(-50,0,-50)); /* Create a variable for counting the fps and hide the mouse: */ //Hide mouse device->getCursorControl()->setVisible(false); //We want to count the fps int lastFPS = -1; /* There wasn't much new stuff - till now! Only by defining four cameras, the game won't be splitscreen. To do this you need several steps: - Set the viewport to the whole screen - Begin a new scene (Clear screen) - The following 3 steps are repeated for every viewport in the splitscreen - Set the viewport to the area you wish - Activate the camera which should be "linked" with the viewport - Render all objects - If you have a GUI: - Set the viewport the whole screen - Display the GUI - End scene Sounds a little complicated, but you'll see it isn't: */ while(device->run()) { //Set the viewpoint to the whole screen and begin scene driver->setViewPort(rect<s32>(0,0,ResX,ResY)); driver->beginScene(true,true,SColor(255,100,100,100)); //If SplitScreen is used if (SplitScreen) { //Activate camera1 smgr->setActiveCamera(camera[0]); //Set viewpoint to the first quarter (left top) driver->setViewPort(rect<s32>(0,0,ResX/2,ResY/2)); //Draw scene smgr->drawAll(); //Activate camera2 smgr->setActiveCamera(camera[1]); //Set viewpoint to the second quarter (right top) driver->setViewPort(rect<s32>(ResX/2,0,ResX,ResY/2)); //Draw scene smgr->drawAll(); //Activate camera3 smgr->setActiveCamera(camera[2]); //Set viewpoint to the third quarter (left bottom) driver->setViewPort(rect<s32>(0,ResY/2,ResX/2,ResY)); //Draw scene smgr->drawAll(); //Set viewport the last quarter (right bottom) driver->setViewPort(rect<s32>(ResX/2,ResY/2,ResX,ResY)); } //Activate camera4 smgr->setActiveCamera(camera[3]); //Draw scene smgr->drawAll(); driver->endScene(); /* As you can probably see, the image is rendered for every viewport seperately. That means, that you'll loose much performance. Ok, if you're aksing "How do I have to set the viewport to get this or that screen?", don't panic. It's really easy: In the rect-function you define 4 coordinates: - X-coordinate of the corner left top - Y-coordinate of the corner left top - X-coordinate of the corner right bottom - Y-coordinate of the corner right bottom That means, if you want to split the screen into 2 viewports you would give the following coordinates: - 1st viewport: 0,0,ResX/2,ResY - 2nd viewport: ResX/2,0,ResX,ResY If you didn't fully understand, just play arround with the example to check out what happens. Now we just view the current fps and shut down the engine, when the user wants to: */ //Get and show fps if (driver->getFPS() != lastFPS) { lastFPS = driver->getFPS(); core::stringw tmp = L"Irrlicht SplitScreen-Example (FPS: "; tmp += lastFPS; tmp += ")"; device->setWindowCaption(tmp.c_str()); } } //Delete device device->drop(); return 0; }
int main(int argc, char **argv) { BSPdungeon dun(50,50,5); IrrlichtDevice *device =createDevice( video::EDT_OPENGL, dimension2d<u32>(1280,720), 16,false, false, false, 0); if (!device) return 1; device->setWindowCaption(L"Pangolin Kwest"); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); smgr->setAmbientLight(video::SColorf(0.1,0.1,0.1,1)); ILightSceneNode* mylight1 = smgr->addLightSceneNode( 0, core::vector3df(00,00,00), video::SColorf(0.3f,0.3f,0.3f), 30.0f, 1 ); //IGUIFont* myfont=guienv->getFont("./myfont.xml"); //if(myfont==0)exit(93); //guienv->addMessageBox(L"Alertz!",L"You pangolin are been createrized. You totalleh ready to bash monstaz etc.!"); mylight1->enableCastShadow(true); //guienv->addStaticText(L"Pangolin Kwest 3D",rect<s32>(10,10,260,22), true); //------------------------------------------- int x,y,z; for(x=0;x<50;x++){ for(y=0;y<50;y++){ if(dun.map[x][y]==NIL){ for(z=0;z<3;z++){ ISceneNode* cueb=smgr->addCubeSceneNode(10); cueb->setMaterialFlag(EMF_LIGHTING, true); cueb->setMaterialTexture( 0, driver->getTexture("media/stdwall.jpg") ); // cueb->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.25,0.5); // cueb->getMaterial(0).getTextureMatrix(0).setTextureScale(0.0625,0.0625); cueb->setPosition(vector3df(x*10,z*10,y*10)); } } // ISceneNode* cueb=smgr->addCubeSceneNode(10); // cueb->setMaterialFlag(EMF_LIGHTING, true); // cueb->setMaterialTexture( 0, driver->getTexture("media/stdfloor.jpg") ); // cueb->setPosition(vector3df(x*10,-10,y*10)); ISceneNode* cueb=smgr->addCubeSceneNode(10); cueb->setMaterialFlag(EMF_LIGHTING, true); cueb->setMaterialTexture( 0, driver->getTexture("media/stdup.jpg") ); cueb->setPosition(vector3df(x*10,30,y*10)); } } ISceneNode* cueb=smgr->addCubeSceneNode(500); cueb->setMaterialFlag(EMF_LIGHTING, true); cueb->setMaterialTexture( 0, driver->getTexture("media/stdfloor.jpg") ); cueb->setPosition(vector3df(250,-255,250)); //cueb->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.25,0.5); cueb->getMaterial(0).getTextureMatrix(0).setTextureScale(50,50); //cueb->setScale(vector3df(0,-5,0)); //cueb->addshadowVolumeSceneNode(); //------------------------------------------- int lastFPS; //smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0)); ICameraSceneNode* mycam; mycam=smgr->addCameraSceneNodeFPS(0,100.0f,0.025f); mycam->setFOV(45); mylight1->setParent(mycam); while(device->run()) { //mylight1->setPosition(); //mylight1-> driver->beginScene(true, true, SColor(255,100,101,140)); smgr->drawAll(); guienv->drawAll(); driver->endScene(); int fps = driver->getFPS(); if (lastFPS != fps) { core::stringw str = L"Pangolin Kwest 3D ["; str += driver->getName(); str += "] FPS:"; str += fps; device->setWindowCaption(str.c_str()); lastFPS = fps; } } device->drop(); return 0; }
int main(int argc, char* argv[]) { // ask user for driver video::E_DRIVER_TYPE driverType=driverChoiceConsole(); if (driverType==video::EDT_COUNT) return 1; MyEventReceiver receiver; IrrlichtDevice* device = createDevice(driverType, core::dimension2du(800, 600), 32, false, false, false, &receiver); if(device == 0) return 1; IVideoDriver *driver = device->getVideoDriver(); ISceneManager *smgr = device->getSceneManager(); device->setWindowCaption(L"Irrlicht Example for SMesh usage."); /* Create the custom mesh and initialize with a heightmap */ TMesh mesh; HeightMap hm = HeightMap(255, 255); hm.generate(eggbox); mesh.init(hm, 50.f, grey, driver); // Add the mesh to the scene graph IMeshSceneNode* meshnode = smgr -> addMeshSceneNode(mesh.Mesh); meshnode->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false); // light is just for nice effects ILightSceneNode *node = smgr->addLightSceneNode(0, vector3df(0,100,0), SColorf(1.0f, 0.6f, 0.7f, 1.0f), 500.0f); if (node) { node->getLightData().Attenuation.set(0.f, 1.f/500.f, 0.f); ISceneNodeAnimator* anim = smgr->createFlyCircleAnimator(vector3df(0,150,0),250.0f); if (anim) { node->addAnimator(anim); anim->drop(); } } ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(); if (camera) { camera->setPosition(vector3df(-20.f, 150.f, -20.f)); camera->setTarget(vector3df(200.f, -80.f, 150.f)); camera->setFarValue(20000.0f); } /* Just a usual render loop with event handling. The custom mesh is a usual part of the scene graph which gets rendered by drawAll. */ while(device->run()) { if(!device->isWindowActive()) { device->sleep(100); continue; } if(receiver.IsKeyDown(irr::KEY_KEY_W)) { meshnode->setMaterialFlag(video::EMF_WIREFRAME, !meshnode->getMaterial(0).Wireframe); } else if(receiver.IsKeyDown(irr::KEY_KEY_1)) { hm.generate(eggbox); mesh.init(hm, 50.f, grey, driver); } else if(receiver.IsKeyDown(irr::KEY_KEY_2)) { hm.generate(moresine); mesh.init(hm, 50.f, yellow, driver); } else if(receiver.IsKeyDown(irr::KEY_KEY_3)) { hm.generate(justexp); mesh.init(hm, 50.f, yellow, driver); } driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0xff000000)); smgr->drawAll(); driver->endScene(); } device->drop(); return 0; }
int main() { int idCenario = 0; int quadId; vector3df p1, p2, p3, p4; SMatrix mtxCenario; CArquivoMatrizes *_fileMtx = new CArquivoMatrizes(); CSampleSceneNode *myQuad[2500]; CGerEventos eventos; IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>(800, 600), 16, false,false,false, &eventos); device->setWindowCaption(L"Editor de matrizes - Warbugs"); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); smgr->addCameraSceneNodeFPS(); //smgr->addCameraSceneNode(0, vector3df(0,100,0), vector3df(0,0,0)); smgr->loadScene(pathCenario[idCenario]); mtxCenario = _fileMtx->getMatrix(idCenario); ITerrainSceneNode *sceneTerrain = (ITerrainSceneNode*)smgr->getSceneNodeFromType(ESNT_TERRAIN, 0); ITriangleSelector *sceneTris = smgr->createTerrainTriangleSelector(sceneTerrain, 0); sceneTerrain->setTriangleSelector(sceneTris); for(int i=0; i<50; i++) // z { for(int j=0; j<50;j++) // x { //if( //{ p1.X = 10.0; p1.Y = 1.0; p1.Z = 0.0; p2.X = 10.0; p2.Y = 1.0; p2.Z = 500.0; p3.X = 0.0; p3.Y = 1.0; p3.Z = 500.0; p4.X = 0.0; p4.Y = 1.0; p4.Z = 0.0; quadId = j + (i * 10); myQuad[quadId] = new CSampleSceneNode(smgr->getRootSceneNode(), smgr, quadId, p1, p2, p3, p4); //} } } while(device->run()) { driver->beginScene(true, true, SColor(0,100,100,100)); smgr->drawAll(); driver->endScene(); } device->drop(); return 0; }
int main() { IrrlichtDevice *device = createDevice( video::EDT_OPENGL, dimension2d<u32>(1024, 768), 32, false, false, true, 0); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); smgr->addCameraSceneNodeFPS(); const s32 randLength = 1024; srand(device->getTimer()->getRealTime()); //Creating the grid for unit measure, etc u32 tileNumber = 128; IAnimatedMesh* groundMesh = smgr->addHillPlaneMesh("", dimension2d<float>(8,8),dimension2d<u32>(tileNumber,tileNumber),0,0.0f,dimension2df(0,0),dimension2df(tileNumber,tileNumber)); IAnimatedMeshSceneNode * groundNode = smgr->addAnimatedMeshSceneNode(groundMesh); groundNode->setMaterialTexture(0,driver->getTexture("../media/grid2.png")); groundNode->setMaterialFlag(EMF_LIGHTING,false); groundNode->setPosition(vector3df(0,-2,0)); //obstacles for stuff EntityGroup obstacles; for(int i = 0; i < 20; i++) { ISceneNode* s = smgr->addSphereSceneNode(20); IrrlichtBaseEntity * e = new IrrlichtBaseEntity(s); s->setPosition(vector3df(rand()%randLength - (randLength/2),0,rand()%randLength - (randLength/2))); obstacles.push_back(e); } //Nodes for vehicles ISceneNode * cube = smgr->addCubeSceneNode(4); ISceneNode * cube2 = smgr->addCubeSceneNode(4); cube->setMaterialFlag(EMF_LIGHTING,false); cube->setMaterialTexture(0,driver->getTexture("../media/v1-solid.png")); cube2->setMaterialFlag(EMF_LIGHTING,false); cube2->setMaterialTexture(0,driver->getTexture("../media/v2-solid.png")); //Creating the actual vehicles IrrlichtMobileEntity * Entity1 = new IrrlichtMobileEntity(cube ,vector3df(0,0,0), 1, 90, 40); IrrlichtMobileEntity * Entity2 = new IrrlichtMobileEntity(cube2,vector3df(0,0,300), 1, 100, 50); //Creating the steering conrollers, constructor also sets steering on entity SimpleSteeringController* Entity1Steering = new SimpleSteeringController(Entity1); SimpleSteeringController * Entity2Steering = new SimpleSteeringController(Entity2); //Setting up other params for behaviors Entity1Steering->SetObstacles(obstacles); Entity1Steering->SetHideTarget(Entity2); Entity1Steering->SetBehaviorFlag(EBF_HIDE,true); Entity1Steering->SetBehaviorFlag(EBF_AVOID,true); Entity2Steering->SetObstacles(obstacles); Entity2Steering->SetPursuitTarget(Entity1); Entity2Steering->SetBehaviorFlag(EBF_PURSUIT,true); Entity2Steering->SetBehaviorFlag(EBF_AVOID,true); //vars for tracking time between frames. This allows framerate independent motion state updates. u32 then = device->getTimer()->getTime(); float timeUpdate = 0; while(device->run()) { const u32 now = device->getTimer()->getTime(); const float frameDeltaTime = (float)(now - then) / 1000.f; // Time in seconds then = now; timeUpdate += frameDeltaTime; if(timeUpdate > 1) { core::stringw str = L"desteer v0.0.1 FPS: "; str += (s32)driver->getFPS(); device->setWindowCaption(str.c_str()); timeUpdate = 0; } //Do behavior updates before the rendering. Entity1->Update(frameDeltaTime); Entity2->Update(frameDeltaTime); driver->beginScene(true, true, SColor(255,100,101,140)); smgr->drawAll(); driver->endScene(); } //Clean up irrlicht. device->drop(); return 0; }
int main() { IrrlichtDevice* device = createDevice( video::EDT_OPENGL, core::dimension2d<s32>(640, 480), 16, false, false, false); if (device == 0) return 1; ISceneManager *smgr = device->getSceneManager(); IVideoDriver *driver= device->getVideoDriver(); IMesh* mesh = smgr->getMesh("media/cube.obj")->getMesh(0); mesh->getMeshBuffer(0)->getMaterial().setTexture(0, driver->getTexture("media/grass.png")); CBatchingMesh* BatchingMesh = new CBatchingMesh(); s32 x,y,z; // let's add a grassy floor, 20x20 for (x=-10; x<11; ++x) for (z=-10; z<11; ++z) if ( abs(x) > 5 || abs(z) > 5) BatchingMesh->addMesh(mesh, core::vector3df(x*2,-4,z*2)); mesh->getMeshBuffer(0)->getMaterial().setTexture(0, driver->getTexture("media/stone.png")); // add some walls for (y=-1; y<7; ++y) for (x=-5; x<6; ++x) for (z=-5; z<6; ++z) if (((abs(z) == 5 || abs(x) == 5) && (abs(x)>1 || y > 3 )) || y==6) BatchingMesh->addMesh(mesh, core::vector3df(x*2,y*2-2,z*2)); mesh->getMeshBuffer(0)->getMaterial().setTexture(0, driver->getTexture("media/tile.png")); // a nice tiled interior for (x=-5; x<6; ++x) for (z=-5; z<6; ++z) BatchingMesh->addMesh(mesh, core::vector3df(x*2,-4,z*2)); BatchingMesh->update(); BatchingMesh->setMaterialFlag(EMF_LIGHTING, false); ISceneNode *node = smgr->addMeshSceneNode(BatchingMesh); node->setScale(core::vector3df(10,10,10)); node->setDebugDataVisible(EDS_BBOX_BUFFERS); BatchingMesh->drop(); /* To be able to look at and move around in this scene, we create a first person shooter style camera and make the mouse cursor invisible. */ smgr->addCameraSceneNodeFPS(0, 100.0f, 0.1f); device->getCursorControl()->setVisible(false); int lastFPS = -1; while(device->run()) if (device->isWindowActive()) { driver->beginScene(true, true, video::SColor(255,113,113,133)); smgr->drawAll(); driver->endScene(); int fps = driver->getFPS(); if (lastFPS != fps) { core::stringw tmp(L"CBatchingMesh ["); tmp += driver->getName(); tmp += L"] fps: "; tmp += fps; tmp += L", mesh count: "; tmp += BatchingMesh->getSourceBufferCount(); device->setWindowCaption(tmp.c_str()); lastFPS = fps; } device->sleep(5,0); } /* In the end, delete the Irrlicht device. */ device->drop(); return 0; }
int main() { MyEventReceiver receiver; IrrlichtDevice *device = createDevice( video::EDT_OPENGL, dimension2d<u32>(1280, 800), 16, false, false, false, &receiver); if (!device) return 1; IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); scene::ISceneNode* o = smgr->addSphereSceneNode(20); //o->setMaterialFlag(video::EMF_LIGHTING, false); o->setPosition(core::vector3df(0,0,0)); SMaterial &m = o->getMaterial(0); m.EmissiveColor = SColor(255, 255, 0, 0); vector3df sssPos(0, 60, 0); scene::ISceneNode* sss = smgr->addCubeSceneNode(30); sss->setMaterialFlag(video::EMF_LIGHTING, true); //sss->setMaterialTexture(0, driver->getTexture("wall.bmp")); sss->setPosition(sssPos); SMaterial &sssm = sss->getMaterial(0); sssm.EmissiveColor = SColor(100, 255, 255, 255); scene::ISceneNode* hp = smgr->addSphereSceneNode(10); SMaterial &hpm = hp->getMaterial(0); hpm.EmissiveColor = SColor(255, 0, 0, 255); scene::ISceneNode* hd = smgr->addSphereSceneNode(10); SMaterial &hdm = hd->getMaterial(0); hdm.EmissiveColor = SColor(255, 0, 0, 100); scene::ISceneNode* node[10]; for (int i = 0; i < 10; ++i) { node[i] = smgr->addSphereSceneNode(5); //node[i]->setMaterialFlag(video::EMF_LIGHTING, false); node[i]->setVisible(false); SMaterial &m = node[i]->getMaterial(0); m.EmissiveColor = SColor(255, 255, 0, 0); } scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(); vector3df camPos(0,0,200); vector3df camshift(0,0,0); cam->setPosition(camPos); cam->setTarget(core::vector3df(0,0,0)); u32 then = device->getTimer()->getTime(); const f32 MOVEMENT_SPEED = 50.f; irr::video::S3DVertex m_cPlaneVertices[4]; irr::u16 m_iPlaneIndices[6]; m_cPlaneVertices[0] = irr::video::S3DVertex(-100.0f, -100.0f, -100.0f,1,1,0, irr::video::SColor(255,255,255,255), 0.0f, 0.0f); m_cPlaneVertices[1] = irr::video::S3DVertex(-100.0f, 100.0f, -100.0f,1,1,0, irr::video::SColor(255,255,255,255), 0.0f, 1.0f); m_cPlaneVertices[2] = irr::video::S3DVertex( 100.0f, 100.0f, -100.0f,1,1,0, irr::video::SColor(255,255,255,255), 1.0f, 1.0f); m_cPlaneVertices[3] = irr::video::S3DVertex( 100.0f, -100.0f, -100.0f,1,1,0, irr::video::SColor(255,255,255,255), 1.0f, 0.0f); m_iPlaneIndices[0] = 0; m_iPlaneIndices[1] = 2; m_iPlaneIndices[2] = 1; m_iPlaneIndices[3] = 0; m_iPlaneIndices[4] = 3; m_iPlaneIndices[5] = 2; SMaterial m_cRenderMaterial; m_cRenderMaterial.Wireframe = false; m_cRenderMaterial.Lighting = false; m_cRenderMaterial.TextureLayer[0].TextureWrapU = irr::video::ETC_CLAMP; m_cRenderMaterial.TextureLayer[0].TextureWrapV = irr::video::ETC_CLAMP; ITexture *m_pRenderTexture = 0; CvCapture *capture; IplImage *frame; char AviFileName[]="Accel World.mp4"; capture = cvCaptureFromAVI(AviFileName); if (driver->queryFeature(irr::video::EVDF_RENDER_TO_TARGET)) { m_pRenderTexture = driver->addRenderTargetTexture(irr::core::dimension2d<irr::u32>((irr::u32)(720), (irr::u32)(480))); m_cRenderMaterial.setTexture(0, m_pRenderTexture); } // m_pRenderTexture = driver->getTexture("wall.bmp"); // m_cRenderMaterial.setTexture(0, m_pRenderTexture); while(device->run()) { const u32 now = device->getTimer()->getTime(); const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds then = now; if(receiver.IsKeyDown(irr::KEY_KEY_W)) camshift.Z -= MOVEMENT_SPEED * frameDeltaTime; else if(receiver.IsKeyDown(irr::KEY_KEY_S)) camshift.Z += MOVEMENT_SPEED * frameDeltaTime; if(receiver.IsKeyDown(irr::KEY_KEY_A)) camshift.X -= MOVEMENT_SPEED * frameDeltaTime; else if(receiver.IsKeyDown(irr::KEY_KEY_D)) camshift.X += MOVEMENT_SPEED * frameDeltaTime; if(receiver.IsKeyDown(irr::KEY_KEY_X)) camshift.Y -= MOVEMENT_SPEED * frameDeltaTime; else if(receiver.IsKeyDown(irr::KEY_SPACE)) camshift.Y += MOVEMENT_SPEED * frameDeltaTime; cam->setPosition(camPos + camshift); driver->beginScene(true, true, SColor(255,0,0,0)); driver->setRenderTarget(m_pRenderTexture, true, true, irr::video::SColor(0,0,0,0)); if(cvGrabFrame(capture)) { frame=cvRetrieveFrame(capture); void* pBits = m_pRenderTexture->lock(); u32 Pitch = m_pRenderTexture->getPitch(); int wmin= Pitch; // for(int h=0; h< 100; h++) // memcpy((char*)pBits+((h)*wmin),(char*)frame->imageDataOrigin + h * wmin, wmin); char* tmp = new char[frame->imageSize + 720 * 480]; for (int i = 0; i < 480; ++i) { for (int j = 0; j < 720; ++j) { tmp[(i * 720 + j) * 4] = frame->imageDataOrigin[(i * 720 + j) * 3]; tmp[(i * 720 + j) * 4 + 1] = frame->imageDataOrigin[(i * 720 + j) * 3 + 1]; tmp[(i * 720 + j) * 4 + 2] = frame->imageDataOrigin[(i * 720 + j) * 3 + 2]; tmp[(i * 720 + j) * 4 + 3] = 255; } } memcpy(pBits,tmp, frame->imageSize + 720 * 480); delete []tmp; m_pRenderTexture->unlock(); } driver->setRenderTarget(0, false, false, irr::video::SColor(0,100,100,100)); //driver->setTransform(video::ETS_VIEW, core::matrix4()); driver->setTransform(video::ETS_WORLD, core::matrix4()); //driver->setTransform(video::ETS_PROJECTION, core::matrix4()); driver->setMaterial(m_cRenderMaterial); driver->drawIndexedTriangleList(m_cPlaneVertices, 4, m_iPlaneIndices, 2); smgr->drawAll(); driver->endScene(); } //controller.removeListener(listener); device->drop(); return 0; }
//When our engine is called up int main(int argc, char* argv[]) { //This is all that's needed to initialize the engine ... blahaha irrEngineManager *Manager = new irrEngineManager(); IrrlichtDevice *Device = Manager->getDevice(); ISceneManager *Smgr = Device->getSceneManager(); IVideoDriver *Video = Device->getVideoDriver(); irrBulletWorld *World = Manager->getBulletWorld(); ISoundEngine *Sound = Manager->getSoundEngine(); IGUIEnvironment *Gui = Device->getGUIEnvironment(); ICursorControl *cursor = Device->getCursorControl(); World->setGravity(vector3df(0,-100,0)); Manager->setWindowCaption(L"irrEngine"); Device->getFileSystem()->addZipFileArchive("map-20kdm2.pk3"); //Scene Begin CStaticProp *prop = new CStaticProp(Device, World, Smgr->getMesh("20kdm2.bsp")->getMesh(0)); // CGUIButton *button = new CGUIButton(Device); // button->setRelativePosition(vector2df(720, 450)); // button->setPosition(vector2df(720, 450)); // button->setScale(vector2df(2,2)); // Manager->registerStaticProp(prop); CGUIImage *image = new CGUIImage(Device); // image->setImage(Video->getTexture("draakan.png")); // image->setRelativePosition(vector2df(720, 450)); // image->setRelativeScale(vector2df(1,1)); CRigidBox *box = new CRigidBox(Device, World); box->setScale(vector3df(5,5,5)); box->setPosition(vector3df(715,1200,500)); box->setMaterialFlag(EMF_LIGHTING, false); box->setMaterialTexture(0, Video->getTexture("textures/crate.jpg")); Manager->registerRigidBox(box); // CRenderTarget *rt = new CRenderTarget(Device, box->getNode()); // rt->getCamera()->setPosition(vector3df(0,500,0)); ICameraSceneNode *Camera = Smgr->addCameraSceneNodeFPS(0, 100.f, 0.0f, -1, 0, 0, true, 0.0, false, true); // ICameraSceneNode*Camera = Smgr->addCameraSceneNodeFPS(); Smgr->addAnimatedMeshSceneNode(Smgr->getMesh("dwarf.x")); CIrrKlangSceneNode *Nodes = new CIrrKlangSceneNode(Sound, Smgr->getRootSceneNode(), Smgr, 666); Nodes->setMinMaxSoundDistance(); Nodes->setSoundFileName("Menu.mp3"); CFPSController *controller = new CFPSController(Device, World, Smgr->getMesh("dwarf.x")); Manager->registerFPSController(controller); Manager->setActivePlayer(controller); // controller->setCameraOffset(vector3df(0,50,0)); controller->setNodeOffset(vector3df(0,-10,0)); // rt->setFollowMode(true, Camera); // rt->setTrailMode(true, Camera, true, true); // box->setMaterialTexture(0, rt->getTexture()); // Manager->registerRenderTarget(rt); // // CRagdoll *doll = new CRagdoll(Device, World, Smgr->getMesh("dwarf.x")); //Continue using Irrlicht as normal u32 TimeStamp = Device->getTimer()->getTime(); u32 DeltaTime = 0; while (Manager->run()) { //The Manager handles everything inside of this drawAll call DeltaTime = Device->getTimer()->getTime() - TimeStamp; TimeStamp = Device->getTimer()->getTime(); World->stepSimulation(DeltaTime*0.001f, 120); Manager->drawAll(); } //When the device is closed, delete the irrEngine manager to cause a "domino" effect of deletion :) delete Manager; if (Device) Device->drop(); }
int main() { order_map<S3DVertex, int> map; S3DVertex s = S3DVertex(Vector3(23, 12, 14), Vector3(231, 33, 22), ColourValue::getColourValue(255,255,255,255), Vector2(12, 34)); map.insert(s, 1); order_map<S3DVertex, int>::Node* nofe = map.find(s); int i = nofe->getValue(); /* The most important function of the engine is the createDevice() function. The IrrlichtDevice is created by it, which is the root object for doing anything with the engine. createDevice() has 7 parameters: - deviceType: Type of the device. This can currently be the Null-device, one of the two software renderers, D3D8, D3D9, or OpenGL. In this example we use EDT_SOFTWARE, but to try out, you might want to change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8, EDT_DIRECT3D9, or EDT_OPENGL. - windowSize: Size of the Window or screen in FullScreenMode to be created. In this example we use 640x480. - bits: Amount of color bits per pixel. This should be 16 or 32. The parameter is often ignored when running in windowed mode. - fullscreen: Specifies if we want the device to run in fullscreen mode or not. - stencilbuffer: Specifies if we want to use the stencil buffer (for drawing shadows). - vsync: Specifies if we want to have vsync enabled, this is only useful in fullscreen mode. - eventReceiver: An object to receive events. We do not want to use this parameter here, and set it to 0. Always check the return value to cope with unsupported drivers, dimensions, etc. */ Device *device = createDevice(EDT_OPENGL, dimension2d<Sapphire::UINT32>(1920, 1080), 32, false, false, false, 0); if (!device) return 1; /* Set the caption of the window to some nice text. Note that there is an 'L' in front of the string. The Irrlicht Engine uses wide character strings when displaying text. */ device->setWindowCaption(L"HELLO WORLD!"); /* Get a pointer to the VideoDriver, the SceneManager and the graphical user interface environment, so that we do not always have to write device->getVideoDriver(), device->getSceneManager(), or device->getGUIEnvironment(). */ IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); /* We add a hello world label to the window, using the GUI environment. The text is placed at the position (10,10) as top left corner and (260,22) as lower right corner. */ guienv->addStaticText(L"Hello World!", rect<SINT32>(10, 10, 260, 22), true); /* To show something interesting, we load a Quake 2 model and display it. We only have to get the Mesh from the Scene Manager with getMesh() and add a SceneNode to display the mesh with addAnimatedMeshSceneNode(). We check the return value of getMesh() to become aware of loading problems and other errors. Instead of writing the filename sydney.md2, it would also be possible to load a Maya object file (.obj), a complete Quake3 map (.bsp) or any other supported file format. By the way, that cool Quake 2 model called sydney was modelled by Brian Collins. */ //IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2"); //IAnimatedMesh* mesh = smgr->getMesh("media/q2mdl-wham/tris.md2"); //IAnimatedMesh* mesh = smgr->getMesh("media/sydney.md2"); IAnimatedMesh* mesh = smgr->getMesh("media/kokoro/kokoro.obj"); if (!mesh) { device->drop(); return 1; } IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh); //node->setDebugDataVisible(EDS_BBOX ); /* To let the mesh look a little bit nicer, we change its material. We disable lighting because we do not have a dynamic light in here, and the mesh would be totally black otherwise. Then we set the frame loop, such that the predefined STAND animation is used. And last, we apply a texture to the mesh. Without it the mesh would be drawn using only a color. */ if (node) { node->setMaterialFlag(EMF_LIGHTING, false); // node->setMD2Animation(EMAT_STAND); //node->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp")); //node->setMaterialTexture(0, driver->getTexture("media/sydney.bmp")); // node->setMaterialTexture(0, driver->getTexture("media/q2mdl-wham/tundra.bmp")); //node->setMaterialTexture(0, driver->getTexture("media/kokoro/kok_face_d.tga")); //node->setMaterialTexture(0, driver->getTexture("media/kokoro/kok_acc1_d.tga")); //node->setMaterialTexture(0, driver->getTexture("media/kokoro/kok_body_d.tga")); //node->setMaterialTexture(0, driver->getTexture("media/kokoro/kok_body_d.tga")); //node->setMaterialTexture(0, driver->getTexture("media/kokoro/kok_hairback_s.tga")); node->setPosition(Vector3(1, 29, -39)); node->setRotation(Vector3(Math::DegreesToRadians(45), 0, 0)); node->setRotation(Vector3(0, Math::DegreesToRadians(180), 0)); } /* To look at the mesh, we place a camera into 3d space at the position (0, 30, -40). The camera looks from there to (0,5,0), which is approximately the place where our md2 model is. */ //smgr->addCameraSceneNode(0, Vector3(0, 30, -40), Vector3(0, 5, 0)); ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 50.0f, 0.01f); camera->setTarget(Vector3(5, 10, 0)); camera->setPosition(Vector3(0, 30, -40)); /* Ok, now we have set up the scene, lets draw everything: We run the device in a while() loop, until the device does not want to run any more. This would be when the user closes the window or presses ALT+F4 (or whatever keycode closes a window). */ while (device->run()) { /* Anything can be drawn between a beginScene() and an endScene() call. The beginScene() call clears the screen with a color and the depth buffer, if desired. Then we let the Scene Manager and the GUI Environment draw their content. With the endScene() call everything is presented on the screen. */ driver->beginScene(true, true, ColourValue::getColourValue(255, 100, 101, 140)); smgr->drawAll(); guienv->drawAll(); driver->endScene(); } /* After we are done with the render loop, we have to delete the Irrlicht Device created before with createDevice(). In the Irrlicht Engine, you have to delete all objects you created with a method or function which starts with 'create'. The object is simply deleted by calling ->drop(). See the documentation at irr::IReferenceCounted::drop() for more information. */ device->drop(); return 0; return 0; }
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; }
/** Tests that the geometry creator does what it says it does. */ bool testGeometryCreator(void) { IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, core::dimension2du(160,120), 32); if (!device) return false; IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); (void)smgr->addCameraSceneNode(0, vector3df(0, 0, -50)); const IGeometryCreator * geom = smgr->getGeometryCreator(); ITexture * wall = driver->getTexture("../media/wall.bmp"); SMaterial material; material.Lighting = false; material.TextureLayer[0].Texture = wall; irr::scene::IMesh * meshHill = geom->createHillPlaneMesh(dimension2df(10, 5), dimension2du(5, 5), &material, 10, dimension2df(2, 2), dimension2df(3, 3) ); IMeshSceneNode * node = smgr->addMeshSceneNode(meshHill, 0, -1, vector3df(0, 10, 0), vector3df(-60, 0, 0)); meshHill->drop(); irr::scene::IMesh * meshArrow = geom->createArrowMesh(4, 8, 10, 6, 3, 6, SColor(255, 255, 0, 0), SColor(255, 0, 255, 0)); node = smgr->addMeshSceneNode(meshArrow, 0, -1, vector3df(-10, -20, 0)); node->setMaterialFlag(video::EMF_LIGHTING, false); meshArrow->drop(); irr::scene::IMesh * meshCone = geom->createConeMesh(5.f, 10.f, 16); node = smgr->addMeshSceneNode(meshCone, 0, -1, vector3df(-35, -20, 0)); node->setMaterialFlag(video::EMF_LIGHTING, false); node->setMaterialTexture(0, wall); meshCone->drop(); irr::scene::IMesh * meshCube = geom->createCubeMesh(); node = smgr->addMeshSceneNode(meshCube, 0, -1, vector3df(-20, -20, 0)); node->setMaterialFlag(video::EMF_LIGHTING, false); node->setMaterialTexture(0, wall); meshCube->drop(); irr::scene::IMesh * meshCylinder = geom->createCylinderMesh(3, 10, 16); node = smgr->addMeshSceneNode(meshCylinder, 0, -1, vector3df(0, -20, 10), core::vector3df(45,0,0)); node->setMaterialFlag(video::EMF_LIGHTING, false); node->setMaterialTexture(0, wall); meshCylinder->drop(); irr::scene::IMesh * meshSphere = geom->createSphereMesh(); node = smgr->addMeshSceneNode(meshSphere, 0, -1, vector3df(10, -15, 0)); node->setMaterialFlag(video::EMF_LIGHTING, false); node->setMaterialTexture(0, wall); meshSphere->drop(); irr::scene::IMesh * meshVolumeLight = geom->createVolumeLightMesh(); node = smgr->addMeshSceneNode(meshVolumeLight, 0, -1, vector3df(20, -20, -10)); node->setMaterialFlag(video::EMF_LIGHTING, false); node->setMaterialTexture(0, wall); node->setScale(core::vector3df(4.f,4.f,4.f)); meshVolumeLight->drop(); bool result = false; device->run(); if (driver->beginScene(true, true, video::SColor(0, 80, 80, 80))) { smgr->drawAll(); driver->endScene(); result = takeScreenshotAndCompareAgainstReference(driver, "-testGeometryCreator.png", 99.994f); } smgr->clear(); driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true); // add camera scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0,100.0f,2.0f); camera->setPosition(core::vector3df(2000.0f,5000.f,0.0f)); camera->setTarget(core::vector3df(0.0f,0.0f,0.0f)); camera->setFarValue(20000.0f); device->getCursorControl()->setVisible(false); // disable mouse cursor video::IImage* colorMapImage = driver->createImageFromFile("../media/terrain-texture.jpg"); video::IImage* heightMapImage = driver->createImageFromFile("../media/terrain-heightmap.bmp"); scene::IAnimatedMesh* terrain = smgr->addTerrainMesh("TerrainMeshName", colorMapImage, heightMapImage, core::dimension2d<f32>(40, 40), // size of a pixel 8*40); // maximum height colorMapImage->drop(); colorMapImage = 0; heightMapImage->drop(); heightMapImage = 0; scene::IAnimatedMeshSceneNode* anode = smgr->addAnimatedMeshSceneNode(terrain); if (anode) { anode->setMaterialFlag(video::EMF_LIGHTING, false); anode->setPosition(core::vector3df(-5000,0,-5000)); } driver->beginScene(); smgr->drawAll(); driver->endScene(); // This screenshot shows some mipmap problems, but this seems to be // no fault of the mesh result = takeScreenshotAndCompareAgainstReference(driver, "-testTerrainMesh.png", 99.989f); device->closeDevice(); device->run(); device->drop(); return result; }
int main() { /* shadowDimen = dimension2du(1024,1024); shadowDimen = dimension2du(2048,2048); shadowDimen = dimension2du(4096,4096); shadowDimen = dimension2du(2048,2048); filterType = EFT_NONE; filterType = EFT_4PCF; filterType = EFT_8PCF; filterType = EFT_4PCF; */ dimension2du shadowDimen = dimension2du(1024,1024); E_FILTER_TYPE filterType = EFT_4PCF; filterType = EFT_NONE; //// IrrlichtDevice* device = createDevice(EDT_OPENGL,dimension2du(800,600),32); ISceneManager* smgr = device->getSceneManager(); IVideoDriver* driver = device->getVideoDriver(); ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0,100,.5); cam->setPosition(vector3df(0,10,0)); // Create the effect handler, passing the device and RTT size (as a dimension2d) . effectHandler* effect = new effectHandler(device,shadowDimen); ITerrainSceneNode* terrain = smgr->addTerrainSceneNode("media/terrain.bmp",0,-1,vector3df(0,0,0),vector3df(0,0,0),vector3df(1,1,1),SColor(255,255,255,255),1,ETPS_33); terrain->setMaterialTexture(0,driver->getTexture("media/terrain.jpg")); terrain->setMaterialTexture(1, driver->getTexture("media/detailmap.jpg")); terrain->scaleTexture(1,10); terrain->setScale(core::vector3df(4, 0.01f, 4)); terrain->setPosition(vector3df(-120,-1.5f,-120)); terrain->setMaterialType(EMT_DETAIL_MAP); // Make the terrain recieve a shadow with the specified filter type. // (NOTE: 12PCF is only available in Direct3D9, all others work with OpenGL) effect->addShadowToNode(terrain,filterType); IAnimatedMeshSceneNode* sydney; IAnimatedMesh* sydneymesh = smgr->getMesh("media/dwarf.x"); for(int g = 0;g < 1;g++) { for(int v = 0;v < 3;v++) { sydney = smgr->addAnimatedMeshSceneNode(sydneymesh); sydney->setScale(vector3df(0.05f,0.05f,0.05f)); sydney->setPosition(vector3df(g * 4,0.5f,v * 4)); sydney->setMaterialFlag(EMF_NORMALIZE_NORMALS,true); sydney->setAutomaticCulling(EAC_FRUSTUM_BOX); sydney->setMaterialType(EMT_SOLID); // Add the nodes to the depth pass so that they cast a shadow. effect->addNodeToDepthPass(sydney); } } effect->getLightCamera()->addAnimator(smgr->createFlyCircleAnimator(sydney->getPosition() + vector3df(0,15,0),25,0.0002f)); effect->getLightCamera()->setNearValue(5); effect->setMaxShadowDistanceFromLight(120); smgr->addLightSceneNode(effect->getLightCamera()); MyEventReceiver receiver(cam); device->setEventReceiver(&receiver); // Parent a sphere to the light camera so we can see its position. smgr->addSphereSceneNode(1,8,effect->getLightCamera())->setMaterialFlag(EMF_LIGHTING,false); while(device->run()) { wchar_t tmp[255]; swprintf(tmp,255,L"Shadow Map Demo (FPS: %d)",driver->getFPS()); device->setWindowCaption(tmp); driver->beginScene(true,true,SColor(0,0,0,0)); // Point the light camera at one of the nodes as it rotates around them. effect->setLightTarget(sydney->getPosition()); // Update the effect handler, remember to always do this BEFORE smgr->drawAll and AFTER beginscene! effect->update(); smgr->drawAll(); // If user wishes we can display the shadow map to the screen. (May not work in OpenGL) if(disp2d) driver->draw2DImage(effect->getShadowMapTexture(),position2d<s32>(0,0)); driver->endScene(); // device->sleep(5); } device->drop(); return 0; }