📄 application.cpp
字号:
switch(mSceneDetailIndex)
{
case 0: mCamera->setDetailLevel(SDL_SOLID);
break;
case 1: mCamera->setDetailLevel(SDL_WIREFRAME);
break;
case 2: mCamera->setDetailLevel(SDL_POINTS);
break;
}
// Wait at least 0.25 seconds to perform another action
mTimeUntilNextAction = 0.25;
}
// Key '-' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_MINUS) && mTimeUntilNextAction <= 0.0f)
{
// Decrease bullet mass
if(mBullet->getMass() >= 10.0f)
{
mBullet->setMass(mBullet->getMass() - 5.0f);
}
// Wait at least 0.25 seconds to perform another mode action
mTimeUntilNextAction = 0.25f;
}
// Key '=' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_EQUALS) && mTimeUntilNextAction <= 0.0f)
{
// Increase bullet mass
mBullet->setMass(mBullet->getMass() + 5.0f);
// Wait at least 0.25 seconds to perform another mode action
mTimeUntilNextAction = 0.25f;
}
// Key '[' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_LBRACKET) && mTimeUntilNextAction <= 0.0f)
{
// Decrease the gravity (or increase...)
Vector3 gravity = Simulation::getSingleton().getGravity();
gravity -= Vector3(0.0f, 10.0f, 0.0f);
Simulation::getSingleton().setGravity(gravity);
// Wait at least 0.25 seconds to perform another mode action
mTimeUntilNextAction = 0.25f;
}
// Key ']' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_RBRACKET) && mTimeUntilNextAction <= 0.0f)
{
// Increase the gravity (or decrease...)
Vector3 gravity = Simulation::getSingleton().getGravity();
gravity += Vector3(0.0f, 10.0f, 0.0f);
Simulation::getSingleton().setGravity(gravity);
// Wait at least 0.25 seconds to perform another mode action
mTimeUntilNextAction = 0.25f;
}
// Key ';' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_SEMICOLON) && mTimeUntilNextAction <= 0.0f)
{
// Decrease the speed of the Simulation
if(mPhysicsSpeed >= 0.4)
{
mPhysicsSpeed -= 0.2;
}
// Wait at least 0.25 seconds to perform another mode action
mTimeUntilNextAction = 0.25f;
}
// Key ''' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_APOSTROPHE) && mTimeUntilNextAction <= 0.0f)
{
// Increase the speed of the Simulation
if(mPhysicsSpeed <= 4.8)
{
mPhysicsSpeed += 0.2;
}
// Wait at least 0.25 seconds to perform another mode action
mTimeUntilNextAction = 0.25f;
}
// Key '1' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_1) && mTimeUntilNextAction <= 0.0f)
{
// Setup test sim #1
mBullet = setupTestSim1(mSceneMgr->getRootSceneNode());
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Description")->setCaption("Test Sim #1: A 5 story building and arbitrary obstacles.");
// Never start a Simulation paused
mPhysicsPaused = false;
// Wait at least 0.25 seconds to perform another action
mTimeUntilNextAction = 0.25f;
}
// Key '2' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_2) && mTimeUntilNextAction <= 0.0f)
{
// Setup test sim #2
mBullet = setupTestSim2(mSceneMgr->getRootSceneNode());
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Description")->setCaption("Test Sim #2: A 10 story building and arbitrary obstacles.");
// Never start a Simulation paused
mPhysicsPaused = false;
// Wait at least 0.25 seconds to perform another action
mTimeUntilNextAction = 0.25f;
}
// Key '3' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_3) && mTimeUntilNextAction <= 0.0f)
{
// Setup test sim #3
mBullet = setupTestSim3(mSceneMgr->getRootSceneNode());
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Description")->setCaption("Test Sim #3: An extremely thin 5 story building and arbitrary obstacles.");
// Never start a Simulation paused
mPhysicsPaused = false;
// Wait at least 0.25 seconds to perform another action
mTimeUntilNextAction = 0.25f;
}
// Key '4' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_4) && mTimeUntilNextAction <= 0.0f)
{
// Setup test sim #4
mBullet = setupTestSim4(mSceneMgr->getRootSceneNode());
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Description")->setCaption("Test Sim #4: Four, small 5 story buildings. May lag momentarily. :)");
// Never start a Simulation paused
mPhysicsPaused = false;
// Wait at least 0.25 seconds to perform another action
mTimeUntilNextAction = 0.25f;
}
// Key '5' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_5) && mTimeUntilNextAction <= 0.0f)
{
// Setup test sim #5
mBullet = setupTestSim5(mSceneMgr->getRootSceneNode());
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Description")->setCaption("Test Sim #5: A 10 box, ball and socket, jointed chain.");
// Never start a Simulation paused
mPhysicsPaused = false;
// Wait at least 0.25 seconds to perform another action
mTimeUntilNextAction = 0.25f;
}
// Key '6' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_6) && mTimeUntilNextAction <= 0.0f)
{
// Setup test sim #6
mBullet = setupTestSim6(mSceneMgr->getRootSceneNode());
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Description")->setCaption("Test Sim #6: A 10 box, Hinge jointed chain, with limiters.");
// Never start a Simulation paused
mPhysicsPaused = false;
// Wait at least 0.25 seconds to perform another action
mTimeUntilNextAction = 0.25f;
}
// Key '7' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_7) && mTimeUntilNextAction <= 0.0f)
{
// Setup test sim #7
mBullet = setupTestSim7(mSceneMgr->getRootSceneNode());
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Description")->setCaption("Test Sim #7: A complex static object with numerous breakable elements.");
// Never start a Simulation paused
mPhysicsPaused = false;
// Wait at least 0.25 seconds to perform another action
mTimeUntilNextAction = 0.25f;
}
// Key '8' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_8) && mTimeUntilNextAction <= 0.0f)
{
// Setup test sim #8
mBullet = setupTestSim8(mSceneMgr->getRootSceneNode());
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Description")->setCaption("Test Sim #8: Twenty-five stacks of five blocks each, with a heavy bullet.");
// Never start a Simulation paused
mPhysicsPaused = false;
// Wait at least 0.25 seconds to perform another action
mTimeUntilNextAction = 0.25f;
}
// Key '9' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_9) && mTimeUntilNextAction <= 0.0f)
{
// Setup test sim #9
mBullet = setupTestSim9(mSceneMgr->getRootSceneNode());
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Description")->setCaption("Test Sim #9: TriMesh collision! Two 5000 poly TriMeshes and 25 blocks.");
// Never start a Simulation paused
mPhysicsPaused = false;
// Wait at least 0.25 seconds to perform another action
mTimeUntilNextAction = 0.25f;
}
// Key '0' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_0) && mTimeUntilNextAction <= 0.0f)
{
// Setup test sim #0
mBullet = setupTestSim0(mSceneMgr->getRootSceneNode());
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Description")->setCaption("Test Sim #0: Ragdolls! Based on code by KayNine. :)");
// Never start a Simulation paused
mPhysicsPaused = false;
// Wait at least 0.25 seconds to perform another action
mTimeUntilNextAction = 0.25f;
}
// Key 'P' is down and it has been sufficient time since the last action
if (mInputDevice->isKeyDown(KC_P) && mTimeUntilNextAction <= 0.0f)
{
// action Simulation pause
mPhysicsPaused = !mPhysicsPaused;
// Wait at least 0.25 seconds to perform another action
mTimeUntilNextAction = 0.25f;
}
// Continue rendering
return true;
}
// processUnbufferedMouseInput()
bool Application::processUnbufferedMouseInput(void)
{
// First mouse button is pressed and it has been sufficient time since the last action
if (mInputDevice->getMouseButton(0) && mTimeUntilNextAction <= 0.0f)
{
// Shoot the bullet
mBullet->setPosition(mCamera->getPosition());
mBullet->setVelocity(mCamera->getDirection() * 2000);
// Wait at least 0.25 seconds to perform another action
mTimeUntilNextAction = 0.25f;
}
// Rotate the camera
mRotX = -mInputDevice->getMouseRelativeX() * 0.13;
mRotY = -mInputDevice->getMouseRelativeY() * 0.13;
// Continue program
return true;
}
// updateStats()
void Application::updateStats(void)
{
// Last time the display was updated was updated
static Real lastUpdate = mRoot->getTimer()->getMilliseconds();
// Get current time
int time = mRoot->getTimer()->getMilliseconds();
// Only update five times per second
if(time - lastUpdate > 200)
{
// Update the last update variable
lastUpdate = time;
// Set new values
GuiManager::getSingleton().getGuiElement("OgreTok/DebugPanel/AverageFps")->
setCaption("Average FPS: " + StringConverter::toString(mWindow->getAverageFPS()));
GuiManager::getSingleton().getGuiElement("OgreTok/DebugPanel/CurrFps")->
setCaption("Current FPS: " + StringConverter::toString(mWindow->getLastFPS()));
GuiManager::getSingleton().getGuiElement("OgreTok/DebugPanel/BestFps")->
setCaption("Best FPS: " + StringConverter::toString(mWindow->getBestFPS()) + " (" + StringConverter::toString(mWindow->getBestFrameTime()) + " ms)");
GuiManager::getSingleton().getGuiElement("OgreTok/DebugPanel/WorstFps")->
setCaption("Worst FPS: " + StringConverter::toString(mWindow->getWorstFPS()) + " (" + StringConverter::toString(mWindow->getWorstFrameTime()) + " ms)");
GuiManager::getSingleton().getGuiElement("OgreTok/DebugPanel/NumTris")->
setCaption("Triangle Count: " + StringConverter::toString(mWindow->getTriangleCount()));
// Set new values
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Stat1")->
setCaption("Tokamak Mem Usage: " + StringConverter::toString(Simulation::getSingleton().getTokamakMemoryUsage() / 1024) + "k");
// Only update frame time stats if physics were computed last frame
if(Simulation::getSingleton().getLastFrameTime() > 0)
{
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Stat2")->
setCaption("Tokamak Frame Time: " + StringConverter::toString(Simulation::getSingleton().getLastFrameTime()) + " ms");
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Stat3")->
setCaption("% of Last Frame: " + StringConverter::toString(Simulation::getSingleton().getLastFrameTime() / (1000 / mWindow->getLastFPS()) * 100));
}
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Stat4")->
setCaption("Simulation Speed: " + StringConverter::toString(mPhysicsSpeed) + " (;/')");
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Stat5")->
setCaption("Gravity: " + StringConverter::toString(Simulation::getSingleton().getGravity().y) + " ([/])");
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Stat6")->
setCaption("Bullet Mass: " + StringConverter::toString(mBullet->getMass()) + " (-/+)");
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Stat7")->
setCaption("Static Objects: " + StringConverter::toString(Simulation::getSingleton().getStaticObjectCount()) + " / " + StringConverter::toString(Simulation::getSingleton().getStaticObjectMax()));
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Stat8")->
setCaption("Dynamic Objects : " + StringConverter::toString(Simulation::getSingleton().getDynamicObjectCount()) + " / " + StringConverter::toString(Simulation::getSingleton().getDynamicObjectMax()));
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Stat9")->
setCaption("Joints: " + StringConverter::toString(Simulation::getSingleton().getJointCount()) + " / " + StringConverter::toString(Simulation::getSingleton().getJointMax()));
GuiManager::getSingleton().getGuiElement("OgreTok/StatsPanel/Stat10")->
setCaption("TriMeshes: " + StringConverter::toString(Simulation::getSingleton().getTriMeshCount()));
}
}
// showOverlay()
void Application::showOverlay(const String& name, bool show)
{
// Get the overlay
Overlay* gui = (Overlay*)OverlayManager::getSingleton().getByName(name);
// Overlay not created
if (!gui)
{
// Throw exception
Except(Exception::ERR_ITEM_NOT_FOUND, "Could not find overlay " + name, "Application::showOverlay");
}
// Overlay should be shown
if (show)
{
// Show the overlay
gui->show();
}
else
{
// Hide the overlay
gui->hide();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -