void HMDStereoRender::drawAll(ISceneManager* smgr) { ICameraSceneNode* camera = smgr->getActiveCamera(); camera->OnAnimate(_timer->getTime()); // Render Left _driver->setRenderTarget(_renderTexture, true, true, video::SColor(0,0,0,0)); _pCamera->setProjectionMatrix(_projectionLeft); vector3df r = camera->getRotation(); vector3df tx(-_eyeSeparation, 0.0,0.0); tx.rotateXZBy(-r.Y); tx.rotateYZBy(-r.X); tx.rotateXYBy(-r.Z); _pCamera->setPosition(camera->getPosition() + tx); _pCamera->setTarget(camera->getTarget() + tx); smgr->setActiveCamera(_pCamera); smgr->drawAll(); _driver->setRenderTarget(0, false, false, video::SColor(0,100,100,100)); _driver->setViewPort(_viewportLeft); _distortionCB.lensCenter[0] = _lensShift; _driver->setMaterial(_renderMaterial); _driver->drawIndexedTriangleList(_planeVertices, 4, _planeIndices, 2); // Render Right _driver->setRenderTarget(_renderTexture, true, true, video::SColor(0,0,0,0)); _pCamera->setProjectionMatrix(_projectionRight); vector3df r2 = camera->getRotation(); vector3df tx2(-_eyeSeparation, 0.0,0.0); tx.rotateXZBy(-r2.Y); tx.rotateYZBy(-r2.X); tx.rotateXYBy(-r2.Z); _pCamera->setPosition(camera->getPosition() + tx2); _pCamera->setTarget(camera->getTarget() + tx2); smgr->drawAll(); _driver->setRenderTarget(0, false, false, video::SColor(0,100,100,100)); _driver->setViewPort(_viewportRight); _distortionCB.lensCenter[0] = -_lensShift; _driver->setMaterial(_renderMaterial); _driver->drawIndexedTriangleList(_planeVertices, 4, _planeIndices, 2); smgr->setActiveCamera(camera); }
//------------------------------------------------------------------------- // p r e R e n d e r //------------------------------------------------------------------------- void CApplication::preRender(u32 delta) { static u32 elapsed=0; elapsed += delta; if(elapsed > 100) { elapsed = 0; // update debug info if visible if(m_debugPanel->getVisible()) { char buf[128]; u32 tris = m_videoDriver->getPrimitiveCountDrawn(); ICameraSceneNode* camera = m_sceneManager->getActiveCamera(); vector3df pos = camera->getPosition(); vector3df rot = camera->getRotation(); vector3df dir = camera->getTarget(); stringc nname = camera->getName(); sprintf(buf,"%s: Pos(%.1f,%.1f,%.1f) Rot(%.1f,%.1f,%.1f) Dir(%.1f,%.1f,%.1f)", nname.c_str(),pos.X,pos.Y,pos.Z,rot.Y,rot.X,rot.Z,dir.X,dir.Y,dir.Z); m_debugPanel->updateItem(0,buf); sprintf(buf,"Frame: Avg(%d) Min(%d) Max(%d), Tris(%d)", m_fpsAvg, m_fpsMin, m_fpsMax, tris); m_debugPanel->updateItem(1,buf); array<stringc> debugStrings; addCustomDebug(debugStrings); if(debugStrings.size() > 0) { while((debugStrings.size()+2) > m_debugPanel->getItemCount()) { m_debugPanel->addItem(" " ,EGUIA_CENTER); } for(u32 i=0;i<debugStrings.size();i++) { m_debugPanel->updateItem(i+2,debugStrings[i]); } } } } }
int main(int argc, char* argv[]) { stringc sceneDirectory, saveDir; irr::io::path sceneFileName; UserDataSerializer serializer; if(argc < 2) { printf("error scene file name missing:\n"); printf(" irrbPhysics <input scene filename>\n"); return -1; } // initialize Irrlicht m_device = _createDevice(); if(!m_device) return -1; m_fileSystem = m_device->getFileSystem(); m_videoDriver = m_device->getVideoDriver(); m_sceneManager = m_device->getSceneManager(); m_gui = m_device->getGUIEnvironment(); m_debugNode = new CDebugNode(m_sceneManager); // create debug panel (text area) core::dimension2du screen = m_videoDriver->getScreenSize(); m_debugPanel = m_gui->addStaticText(L"",rect<s32>(screen.Width-202,0,screen.Width-2,100)); m_debugPanel->setBackgroundColor(SColor(128, 30, 30, 30)); m_debugPanel->setDrawBorder(true); IGUIFont* font=m_debugPanel->getOverrideFont(); if(!font) font = m_gui->getSkin()->getFont(); m_charHeight = font->getDimension(L"Ay").Height; s32 idx=0; m_charHeight += font->getKerningHeight(); // create help panel (text area) m_helpPanel = m_gui->addStaticText(L"",rect<s32>(2,0,202,200)); m_helpPanel->setBackgroundColor(SColor(128, 30, 30, 30)); m_helpPanel->setDrawBorder(true); _addHelpText("F1 - Toggle Help"); _addHelpText("F3 - Cycle Wire, Points, Solid"); _addHelpText("F4 - Toggle Physics Debug"); _addHelpText("F5 - Warp To Start Position"); _addHelpText("F9 - Detach Camera"); // turn hardware cursor off m_device->getCursorControl()->setVisible(false); #if defined(USE_BULLET) m_device->setWindowCaption(L"irrb Collision/Physics example - Using Bullet"); #elif defined(USE_IRRPHYSX) m_device->setWindowCaption(L"irrb Collision/Physics example - Using IrrPhysx"); #else m_device->setWindowCaption(L"irrb Collision/Physics example - Using Irrlicht"); #endif m_camera = m_sceneManager->addCameraSceneNodeFPS(0, 100.0f, m_moveSpeed, -1, keyMap, 5, true, m_jumpSpeed); m_camera->setPosition(vector3df(0,10,0)); m_camera->setFOV(core::PI / 2.5f); m_camera->setNearValue(.1f); m_camera->setFarValue(1000.f); // save off animator core::list<ISceneNodeAnimator*>::ConstIterator anims=m_camera->getAnimators().begin(); while(anims != m_camera->getAnimators().end()) { if ((*anims)->getType() == ESNAT_CAMERA_FPS) { m_fpsAnimator = (ISceneNodeAnimatorCameraFPS*)*anims; break; } ++anims; } // init physics library _initPhysicsLibrary(); m_displayPhysicsDebug = true; _enablePhysicsDebug(true); m_debugNode->setVisible(true); // load scene sceneFileName = argv[1]; sceneDirectory = m_fileSystem->getFileDir(sceneFileName); saveDir = m_fileSystem->getWorkingDirectory(); m_fileSystem->changeWorkingDirectoryTo(sceneDirectory); m_sceneManager->loadScene(sceneFileName.c_str(), &serializer); m_fileSystem->changeWorkingDirectoryTo(saveDir); // if the scene also contained a camera, set the active // camera to our fps camera and update the fps pos/rot. if(m_camera && (m_camera != m_sceneManager->getActiveCamera())) { ICameraSceneNode* anode = m_sceneManager->getActiveCamera(); m_camera->setPosition(anode->getPosition()); m_camera->setRotation(anode->getRotation()); m_sceneManager->setActiveCamera(m_camera); m_startPos = m_camera->getPosition(); _warp(m_startPos); } ITimer* timer = m_device->getTimer(); u32 current, last = timer->getRealTime(); u32 delta = 0; while(m_device->run() && m_running) { _clearDebugText(); m_videoDriver->beginScene(true, true, SColor(255,100,101,140)); // calc milliseconds since last frame current = timer->getRealTime(); delta = current-last; last = current; // update collision/physics simulation _stepSimulation(delta); m_sceneManager->drawAll(); static char buf[64]; sprintf(buf, "FPS: %d", m_videoDriver->getFPS()); _updateDebugText(0, buf); m_gui->drawAll(); m_videoDriver->endScene(); } m_device->drop(); delete m_eventReceiver; return 0; }
WxIrrMainWindow::WxIrrMainWindow(const wxString& title, void (*draw)(WxIrrViewportManager*), void (*update)(void), bool (*irrlichtLeftMouseDown)(bool controlDown, bool shiftDown, int x, int y), bool (*irrlichtLeftMouseUp)(bool controlDown, bool shiftDown, int x, int y), bool (*irrlichtLeftMouseDoubleClick)(bool controlDown, bool shiftDown, int x, int y), bool (*irrlichtMouseMove)(bool controlDown, bool shiftDown, int x, int y, int moveX, int moveY), void (*irrlichtCameraMouseMove)(int moveX, int moveY, WxIrrViewport* selectedViewport), void (*irrlichtCameraKeyDown)(int id, WxIrrViewport* selectedViewport), void (*irrlichtCameraKeyUp)(int id), void (*irrlichtCameraKeyboardReset)(void), void (*simulationMouseMove)(wxPoint mousePos, bool isShiftDown, WxIrrViewport* mouseOverViewport), bool (*simulationMouseClick)(bool isShiftDown, bool isControlDown), bool (*simulationMouseDoubleClick)(void), void (*SimulationStartMouseChecking)(void), void (*onSimulationShowAxesFunctionPointer)(bool), void (*onSimulationShowObjectNameFunctionPointer)(bool), SColor (*onSimulationXAxisGetColorFunctionPointer)(void), SColor (*onSimulationYAxisGetColorFunctionPointer)(void), SColor (*onSimulationZAxisGetColorFunctionPointer)(void), void (*onSimulationXAxisChangeColorFunctionPointer)(wxColour& color), void (*onSimulationYAxisChangeColorFunctionPointer)(wxColour& color), void (*onSimulationZAxisChangeColorFunctionPointer)(wxColour& color), void (*onSimulationShowXYGridFunctionPointer)(bool), void (*onSimulationShowXZGridFunctionPointer)(bool), void (*onSimulationShowYZGridFunctionPointer)(bool)) : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600)) { OnSimulationShowAxesFunctionPointer = onSimulationShowAxesFunctionPointer; OnSimulationShowObjectNameFunctionPointer = onSimulationShowObjectNameFunctionPointer; OnSimulationXAxisGetColorFunctionPointer = onSimulationXAxisGetColorFunctionPointer; OnSimulationYAxisGetColorFunctionPointer = onSimulationYAxisGetColorFunctionPointer; OnSimulationZAxisGetColorFunctionPointer = onSimulationZAxisGetColorFunctionPointer; OnSimulationXAxisChangeColorFunctionPointer = onSimulationXAxisChangeColorFunctionPointer; OnSimulationYAxisChangeColorFunctionPointer = onSimulationYAxisChangeColorFunctionPointer; OnSimulationZAxisChangeColorFunctionPointer = onSimulationZAxisChangeColorFunctionPointer; OnSimulationShowXYGridFunctionPointer = onSimulationShowXYGridFunctionPointer; OnSimulationShowXZGridFunctionPointer = onSimulationShowXZGridFunctionPointer; OnSimulationShowYZGridFunctionPointer = onSimulationShowYZGridFunctionPointer; leftPanel = new WxIrrViewportWindow(this, 1000); leftPanel->SetBackgroundColour(wxColour(wxT("Black"))); irr::SIrrlichtCreationParameters param; #if defined _WX_IRR_WINDOWS param.DriverType = EDT_DIRECT3D9; param.AntiAlias = false; param.WindowId = reinterpret_cast<void*>(GetLeftPanelHandle()); #elif defined _WX_IRR_LINUX param.DriverType = EDT_OPENGL; param.AntiAlias = false; GtkWidget* handle = (GtkWidget*)GetLeftPanelHandle(); gtk_widget_realize(handle); Window xHandle = GDK_WINDOW_XWINDOW(handle->window); param.WindowId = (void*)(xHandle); #elif defined _WX_IRR_MACOS //param.DriverType = EDT_OPENGL; #else //return false; Close(); #endif leftPanel->InitalizeViewportManager(); SetupDevice(param, draw, update, irrlichtLeftMouseDown, irrlichtLeftMouseUp, irrlichtLeftMouseDoubleClick, irrlichtMouseMove, irrlichtCameraMouseMove, irrlichtCameraKeyDown, irrlichtCameraKeyUp, irrlichtCameraKeyboardReset, simulationMouseMove, simulationMouseClick, simulationMouseDoubleClick, SimulationStartMouseChecking); //Main camera ICameraSceneNode* camera = GetDevice()->getSceneManager()->addCameraSceneNode(); camera->setPosition(Vector3(30,-10,30)); //camera->bindTargetAndRotation(true); //camera->setTarget(Vector3(0,0,0)); Vector3 currentCameraRot = camera->getRotation(); Vector3 rot = currentCameraRot.rotationToDirection(); Vector3 pos = camera->getPosition(); camera->setTarget(rot + pos); camera->setFarValue(100000); SetCamera(camera); rightPanel = new SimulationPanel(this, 1001, wxDefaultPosition, wxDefaultSize); rightPanel->SetBackgroundColour(wxColour(wxT("Black"))); m_mgr.SetManagedWindow(this); //Create Main Menu menuBar = new wxMenuBar(); menuBarManager = new PhysicsHelperMenuBar(menuBar); SetMenuBar( menuBar ); //Status bar CreateStatusBar(); SetStatusText( wxT("PhysicsHelper") ); statusBarText = wxT("PhysicsHelper"); toolBarsManager = new PhysicsHelperToolbars(this, m_mgr); //add the normal panes m_mgr.AddPane(leftPanel, wxAuiPaneInfo().CenterPane().Name(wxT("leftPanel"))); m_mgr.AddPane(rightPanel, wxAuiPaneInfo().CloseButton(false).Right().PinButton(true).MinimizeButton(true).Name(wxT("rightPanel"))); m_mgr.Update(); //Centre(); }