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)
|
Gui::Gui(TestbedApplication* app)
|
||||||
: mApp(app), mSimulationPanel(nullptr), mSettingsPanel(nullptr), mPhysicsPanel(nullptr),
|
: mApp(app), mSimulationPanel(nullptr), mSettingsPanel(nullptr), mPhysicsPanel(nullptr),
|
||||||
mRenderingPanel(nullptr), mFPSLabel(nullptr), mFrameTimeLabel(nullptr), mTotalPhysicsTimeLabel(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() {
|
void Gui::draw() {
|
||||||
|
|
||||||
mScreen->draw_setup();
|
if (mIsDisplayed) {
|
||||||
mScreen->clear();
|
mScreen->draw_setup();
|
||||||
mScreen->draw_contents();
|
mScreen->draw_contents();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gui::drawTearDown() {
|
void Gui::drawTearDown() {
|
||||||
|
|
||||||
mScreen->draw_widgets();
|
if (mIsDisplayed) {
|
||||||
|
mScreen->draw_widgets();
|
||||||
|
}
|
||||||
|
|
||||||
mScreen->draw_teardown();
|
mScreen->draw_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,9 @@ class Gui {
|
||||||
std::vector<CheckBox*> mCheckboxesScenes;
|
std::vector<CheckBox*> mCheckboxesScenes;
|
||||||
ComboBox* mComboBoxScenes;
|
ComboBox* mComboBoxScenes;
|
||||||
|
|
||||||
|
/// True if the GUI is displayed
|
||||||
|
bool mIsDisplayed;
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
static void resetScroll();
|
static void resetScroll();
|
||||||
|
@ -158,6 +161,10 @@ class Gui {
|
||||||
void onMouseButtonEvent(int button, int action, int modifiers);
|
void onMouseButtonEvent(int button, int action, int modifiers);
|
||||||
|
|
||||||
void onKeyboardEvent(int key, int scancode, 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() {
|
inline void Gui::resetScroll() {
|
||||||
|
@ -176,4 +183,12 @@ inline std::string Gui::floatToString(float value, int precision) {
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool Gui::getIsDisplayed() const {
|
||||||
|
return mIsDisplayed;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Gui::setIsDisplayed(bool isDisplayed) {
|
||||||
|
mIsDisplayed = isDisplayed;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -38,7 +38,7 @@ Scene::Scene(const std::string& name, EngineSettings& engineSettings, bool isSha
|
||||||
mViewportWidth(0), mViewportHeight(0), mIsShadowMappingEnabled(isShadowMappingEnabled),
|
mViewportWidth(0), mViewportHeight(0), mIsShadowMappingEnabled(isShadowMappingEnabled),
|
||||||
mAreContactPointsDisplayed(true), mAreContactNormalsDisplayed(false), mAreBroadPhaseAABBsDisplayed(false),
|
mAreContactPointsDisplayed(true), mAreContactNormalsDisplayed(false), mAreBroadPhaseAABBsDisplayed(false),
|
||||||
mAreCollidersAABBsDisplayed(false), mAreCollisionShapesDisplayed(false), mIsWireframeEnabled(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
|
/// Initial zoom factor
|
||||||
float mInitZoom;
|
float mInitZoom;
|
||||||
|
|
||||||
|
/// True if the automatic camera rotation animation is enabled
|
||||||
|
bool mIsCameraRotationAnimationEnabled;
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Set the scene position (where the camera needs to look at)
|
/// 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
|
/// Return a reference to the engine settings of the scene
|
||||||
EngineSettings& getEngineSettings();
|
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
|
// Called when a keyboard event occurs
|
||||||
|
@ -381,4 +391,14 @@ inline EngineSettings& Scene::getEngineSettings() {
|
||||||
return mEngineSettings;
|
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
|
#endif
|
||||||
|
|
|
@ -49,7 +49,7 @@ SceneDemo::SceneDemo(const std::string& name, EngineSettings& settings, reactphy
|
||||||
mQuadShader("shaders/quad.vert", "shaders/quad.frag"),
|
mQuadShader("shaders/quad.vert", "shaders/quad.frag"),
|
||||||
mVBOQuad(GL_ARRAY_BUFFER), mDebugVBOLinesVertices(GL_ARRAY_BUFFER), mDebugVBOTrianglesVertices(GL_ARRAY_BUFFER),
|
mVBOQuad(GL_ARRAY_BUFFER), mDebugVBOLinesVertices(GL_ARRAY_BUFFER), mDebugVBOTrianglesVertices(GL_ARRAY_BUFFER),
|
||||||
mMeshFolderPath("meshes/"), mPhysicsCommon(physicsCommon), mPhysicsWorld(nullptr), mIsPhysicsWorldSimulated(isPhysicsWorldSimulated),
|
mMeshFolderPath("meshes/"), mPhysicsCommon(physicsCommon), mPhysicsWorld(nullptr), mIsPhysicsWorldSimulated(isPhysicsWorldSimulated),
|
||||||
mIsMovingBody(false), mMovingBody(nullptr) {
|
mIsMovingBody(false), mMovingBody(nullptr), mCameraRotationAngle(0) {
|
||||||
|
|
||||||
shadowMapTextureLevel++;
|
shadowMapTextureLevel++;
|
||||||
|
|
||||||
|
@ -143,6 +143,16 @@ void SceneDemo::update() {
|
||||||
// Update the transform used for the rendering
|
// Update the transform used for the rendering
|
||||||
(*it)->updateTransform(mInterpolationFactor);
|
(*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)
|
// 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
|
/// Pointer to the body that is currently moved with the mouse by the user
|
||||||
rp3d::RigidBody* mMovingBody;
|
rp3d::RigidBody* mMovingBody;
|
||||||
|
|
||||||
|
float mCameraRotationAngle;
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Create the Shadow map FBO and texture
|
/// 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)
|
/// Called when a raycast hit occurs (used to move a body with the mouse)
|
||||||
virtual rp3d::decimal notifyRaycastHit(const rp3d::RaycastInfo& raycastInfo) override;
|
virtual rp3d::decimal notifyRaycastHit(const rp3d::RaycastInfo& raycastInfo) override;
|
||||||
|
|
||||||
|
void rotateCameraAnimation();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Enabled/Disable the shadow mapping
|
// Enabled/Disable the shadow mapping
|
||||||
|
|
|
@ -604,7 +604,19 @@ void TestbedApplication::keyboard_event(int key, int scancode, int action, int m
|
||||||
return;
|
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 (key == GLFW_KEY_P && action == GLFW_PRESS) {
|
||||||
|
|
||||||
if (mTimer.isRunning()) {
|
if (mTimer.isRunning()) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user