Add camera rotation animation and possibility to show/hide GUI in testbed application
This commit is contained in:
parent
b9e363fe87
commit
2b0b4ea5fd
|
@ -43,7 +43,7 @@ double Gui::mCachedPhysicsStepTime = 0;
|
|||
Gui::Gui(TestbedApplication* app)
|
||||
: mApp(app), mSimulationPanel(nullptr), mSettingsPanel(nullptr), mPhysicsPanel(nullptr),
|
||||
mRenderingPanel(nullptr), mFPSLabel(nullptr), mFrameTimeLabel(nullptr), mTotalPhysicsTimeLabel(nullptr),
|
||||
mPhysicsStepTimeLabel(nullptr)
|
||||
mPhysicsStepTimeLabel(nullptr), mIsDisplayed(true)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -84,14 +84,18 @@ void Gui::drawAll() {
|
|||
|
||||
void Gui::draw() {
|
||||
|
||||
mScreen->draw_setup();
|
||||
mScreen->clear();
|
||||
mScreen->draw_contents();
|
||||
if (mIsDisplayed) {
|
||||
mScreen->draw_setup();
|
||||
mScreen->draw_contents();
|
||||
}
|
||||
}
|
||||
|
||||
void Gui::drawTearDown() {
|
||||
|
||||
mScreen->draw_widgets();
|
||||
if (mIsDisplayed) {
|
||||
mScreen->draw_widgets();
|
||||
}
|
||||
|
||||
mScreen->draw_teardown();
|
||||
}
|
||||
|
||||
|
|
|
@ -92,6 +92,9 @@ class Gui {
|
|||
std::vector<CheckBox*> mCheckboxesScenes;
|
||||
ComboBox* mComboBoxScenes;
|
||||
|
||||
/// True if the GUI is displayed
|
||||
bool mIsDisplayed;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
static void resetScroll();
|
||||
|
@ -158,6 +161,10 @@ class Gui {
|
|||
void onMouseButtonEvent(int button, int action, int modifiers);
|
||||
|
||||
void onKeyboardEvent(int key, int scancode, int action, int modifiers);
|
||||
|
||||
bool getIsDisplayed() const;
|
||||
|
||||
void setIsDisplayed(bool isDisplayed);
|
||||
};
|
||||
|
||||
inline void Gui::resetScroll() {
|
||||
|
@ -176,4 +183,12 @@ inline std::string Gui::floatToString(float value, int precision) {
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
inline bool Gui::getIsDisplayed() const {
|
||||
return mIsDisplayed;
|
||||
}
|
||||
|
||||
inline void Gui::setIsDisplayed(bool isDisplayed) {
|
||||
mIsDisplayed = isDisplayed;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -38,7 +38,7 @@ Scene::Scene(const std::string& name, EngineSettings& engineSettings, bool isSha
|
|||
mViewportWidth(0), mViewportHeight(0), mIsShadowMappingEnabled(isShadowMappingEnabled),
|
||||
mAreContactPointsDisplayed(true), mAreContactNormalsDisplayed(false), mAreBroadPhaseAABBsDisplayed(false),
|
||||
mAreCollidersAABBsDisplayed(false), mAreCollisionShapesDisplayed(false), mIsWireframeEnabled(false),
|
||||
mInitZoom(2.0f) {
|
||||
mInitZoom(2.0f), mIsCameraRotationAnimationEnabled(false) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -158,6 +158,9 @@ class Scene : public rp3d::EventListener {
|
|||
/// Initial zoom factor
|
||||
float mInitZoom;
|
||||
|
||||
/// True if the automatic camera rotation animation is enabled
|
||||
bool mIsCameraRotationAnimationEnabled;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Set the scene position (where the camera needs to look at)
|
||||
|
@ -274,6 +277,13 @@ class Scene : public rp3d::EventListener {
|
|||
|
||||
/// Return a reference to the engine settings of the scene
|
||||
EngineSettings& getEngineSettings();
|
||||
|
||||
/// Return true if the camera rotation animation is enabled
|
||||
bool getIsCameraRotationAnimationEnabled() const;
|
||||
|
||||
/// Set whether the camera rotation animation is enabled or not
|
||||
void setIsCameraRotationAnimationEnabled(bool isRotationEnabled);
|
||||
|
||||
};
|
||||
|
||||
// Called when a keyboard event occurs
|
||||
|
@ -381,4 +391,14 @@ inline EngineSettings& Scene::getEngineSettings() {
|
|||
return mEngineSettings;
|
||||
}
|
||||
|
||||
// Return true if the scene rotation is enabled
|
||||
inline bool Scene::getIsCameraRotationAnimationEnabled() const {
|
||||
return mIsCameraRotationAnimationEnabled;
|
||||
}
|
||||
|
||||
// Set whether the scene rotation is enabled or no
|
||||
inline void Scene::setIsCameraRotationAnimationEnabled(bool isRotationEnabled) {
|
||||
mIsCameraRotationAnimationEnabled = isRotationEnabled;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -49,7 +49,7 @@ SceneDemo::SceneDemo(const std::string& name, EngineSettings& settings, reactphy
|
|||
mQuadShader("shaders/quad.vert", "shaders/quad.frag"),
|
||||
mVBOQuad(GL_ARRAY_BUFFER), mDebugVBOLinesVertices(GL_ARRAY_BUFFER), mDebugVBOTrianglesVertices(GL_ARRAY_BUFFER),
|
||||
mMeshFolderPath("meshes/"), mPhysicsCommon(physicsCommon), mPhysicsWorld(nullptr), mIsPhysicsWorldSimulated(isPhysicsWorldSimulated),
|
||||
mIsMovingBody(false), mMovingBody(nullptr) {
|
||||
mIsMovingBody(false), mMovingBody(nullptr), mCameraRotationAngle(0) {
|
||||
|
||||
shadowMapTextureLevel++;
|
||||
|
||||
|
@ -143,6 +143,16 @@ void SceneDemo::update() {
|
|||
// Update the transform used for the rendering
|
||||
(*it)->updateTransform(mInterpolationFactor);
|
||||
}
|
||||
|
||||
if (mIsCameraRotationAnimationEnabled) {
|
||||
rotateCameraAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
void SceneDemo::rotateCameraAnimation() {
|
||||
|
||||
const float angle = 0.1f * (PI / 180.0);
|
||||
mCamera.rotateAroundWorldPoint(Vector3(0, 1, 0), angle, mCenterScene);
|
||||
}
|
||||
|
||||
// Update the physics world (take a simulation step)
|
||||
|
|
|
@ -135,6 +135,8 @@ class SceneDemo : public Scene, rp3d::RaycastCallback {
|
|||
/// Pointer to the body that is currently moved with the mouse by the user
|
||||
rp3d::RigidBody* mMovingBody;
|
||||
|
||||
float mCameraRotationAngle;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Create the Shadow map FBO and texture
|
||||
|
@ -208,6 +210,8 @@ class SceneDemo : public Scene, rp3d::RaycastCallback {
|
|||
|
||||
/// Called when a raycast hit occurs (used to move a body with the mouse)
|
||||
virtual rp3d::decimal notifyRaycastHit(const rp3d::RaycastInfo& raycastInfo) override;
|
||||
|
||||
void rotateCameraAnimation();
|
||||
};
|
||||
|
||||
// Enabled/Disable the shadow mapping
|
||||
|
|
|
@ -604,7 +604,19 @@ void TestbedApplication::keyboard_event(int key, int scancode, int action, int m
|
|||
return;
|
||||
}
|
||||
|
||||
// Close application on escape key
|
||||
// Show/hide the GUI with "i" key
|
||||
if (key == GLFW_KEY_I && action == GLFW_PRESS) {
|
||||
mGui.setIsDisplayed(!mGui.getIsDisplayed());
|
||||
return;
|
||||
}
|
||||
|
||||
// Start/Stop camera rotation animation with "r" key
|
||||
if (key == GLFW_KEY_R && action == GLFW_PRESS) {
|
||||
mCurrentScene->setIsCameraRotationAnimationEnabled(!mCurrentScene->getIsCameraRotationAnimationEnabled());
|
||||
return;
|
||||
}
|
||||
|
||||
// Pause the application on "p" key
|
||||
if (key == GLFW_KEY_P && action == GLFW_PRESS) {
|
||||
|
||||
if (mTimer.isRunning()) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user