Add the example scenes to the testbed application
This commit is contained in:
parent
c264356cc6
commit
e31c7abffc
|
@ -16,23 +16,59 @@ ADD_SUBDIRECTORY(glfw/)
|
||||||
# Copy the shaders used for the demo into the build directory
|
# Copy the shaders used for the demo into the build directory
|
||||||
FILE(COPY "shaders/" DESTINATION "${EXECUTABLE_OUTPUT_PATH}/shaders/")
|
FILE(COPY "shaders/" DESTINATION "${EXECUTABLE_OUTPUT_PATH}/shaders/")
|
||||||
|
|
||||||
# Headers
|
# Copy the meshes used for the demo into the build directory
|
||||||
MESSAGE("Test" "${OPENGLFRAMEWORK_DIR}")
|
FILE(COPY "meshes/" DESTINATION "${EXECUTABLE_OUTPUT_PATH}/meshes/")
|
||||||
INCLUDE_DIRECTORIES("opengl-framework/src/" "glfw/include/" "common/")
|
|
||||||
|
|
||||||
# Source files
|
# Headers
|
||||||
|
INCLUDE_DIRECTORIES("src" "opengl-framework/src/" "glfw/include/" "common/" "scenes/")
|
||||||
|
|
||||||
|
# Testbed source files
|
||||||
SET(TESTBED_SOURCES
|
SET(TESTBED_SOURCES
|
||||||
Main.cpp
|
src/Main.cpp
|
||||||
TestbedApplication.h
|
src/TestbedApplication.h
|
||||||
TestbedApplication.cpp
|
src/TestbedApplication.cpp
|
||||||
Gui.h
|
src/Gui.h
|
||||||
Gui.cpp
|
src/Gui.cpp
|
||||||
Scene.h
|
src/Scene.h
|
||||||
Scene.cpp
|
src/Scene.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# Common source files
|
||||||
|
SET(COMMON_SOURCES
|
||||||
|
common/Box.h
|
||||||
|
common/Box.cpp
|
||||||
|
common/Cone.h
|
||||||
|
common/Cone.cpp
|
||||||
|
common/Sphere.h
|
||||||
|
common/Sphere.cpp
|
||||||
|
common/Line.h
|
||||||
|
common/Line.cpp
|
||||||
|
common/Capsule.h
|
||||||
|
common/Capsule.cpp
|
||||||
|
common/ConvexMesh.h
|
||||||
|
common/ConvexMesh.cpp
|
||||||
|
common/Cylinder.h
|
||||||
|
common/Cylinder.cpp
|
||||||
|
common/Dumbbell.h
|
||||||
|
common/Dumbbell.cpp
|
||||||
|
common/VisualContactPoint.h
|
||||||
|
common/VisualContactPoint.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# Examples scenes source files
|
||||||
|
SET(SCENES_SOURCES
|
||||||
|
scenes/cubes/CubesScene.h
|
||||||
|
scenes/cubes/CubesScene.cpp
|
||||||
|
scenes/joints/JointsScene.h
|
||||||
|
scenes/joints/JointsScene.cpp
|
||||||
|
scenes/raycast/RaycastScene.h
|
||||||
|
scenes/raycast/RaycastScene.cpp
|
||||||
|
scenes/collisionshapes/CollisionShapesScene.h
|
||||||
|
scenes/collisionshapes/CollisionShapesScene.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create the executable
|
# Create the executable
|
||||||
ADD_EXECUTABLE(testbed ${TESTBED_SOURCES})
|
ADD_EXECUTABLE(testbed ${TESTBED_SOURCES} ${SCENES_SOURCES} ${COMMON_SOURCES})
|
||||||
|
|
||||||
# Link with libraries
|
# Link with libraries
|
||||||
TARGET_LINK_LIBRARIES(testbed reactphysics3d openglframework glfw ${GLFW_LIBRARIES})
|
TARGET_LINK_LIBRARIES(testbed reactphysics3d openglframework glfw ${GLFW_LIBRARIES})
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
# Minimum cmake version required
|
|
||||||
cmake_minimum_required(VERSION 2.6)
|
|
||||||
|
|
||||||
# Project configuration
|
|
||||||
PROJECT(CollisionShapes)
|
|
||||||
|
|
||||||
# Where to build the executables
|
|
||||||
SET(EXECUTABLE_OUTPUT_PATH "${OUR_EXECUTABLE_OUTPUT_PATH}/collisionshapes")
|
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
|
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${EXECUTABLE_OUTPUT_PATH})
|
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${EXECUTABLE_OUTPUT_PATH})
|
|
||||||
|
|
||||||
# Copy the shaders used for the demo into the build directory
|
|
||||||
FILE(COPY "${OPENGLFRAMEWORK_DIR}/src/shaders/" DESTINATION "${EXECUTABLE_OUTPUT_PATH}/shaders/")
|
|
||||||
|
|
||||||
# Copy the meshes used for the demo into the build directory
|
|
||||||
FILE(COPY "../common/meshes/" DESTINATION "${EXECUTABLE_OUTPUT_PATH}/meshes/")
|
|
||||||
|
|
||||||
# Headers
|
|
||||||
INCLUDE_DIRECTORIES("${OPENGLFRAMEWORK_DIR}/src/" "../common/glfw/include/" "../common/")
|
|
||||||
|
|
||||||
# Source files
|
|
||||||
SET(COLLISION_SHAPES_SOURCES
|
|
||||||
CollisionShapes.cpp
|
|
||||||
Scene.cpp
|
|
||||||
Scene.h
|
|
||||||
"../common/VisualContactPoint.cpp"
|
|
||||||
"../common/ConvexMesh.cpp"
|
|
||||||
"../common/Capsule.cpp"
|
|
||||||
"../common/Sphere.cpp"
|
|
||||||
"../common/Cylinder.cpp"
|
|
||||||
"../common/Cone.cpp"
|
|
||||||
"../common/Dumbbell.cpp"
|
|
||||||
"../common/Box.cpp"
|
|
||||||
"../common/Viewer.cpp"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create the executable
|
|
||||||
ADD_EXECUTABLE(collisionshapes ${COLLISION_SHAPES_SOURCES})
|
|
||||||
|
|
||||||
# Link with libraries
|
|
||||||
TARGET_LINK_LIBRARIES(collisionshapes reactphysics3d openglframework glfw ${GLFW_LIBRARIES})
|
|
|
@ -1,152 +0,0 @@
|
||||||
/********************************************************************************
|
|
||||||
* ReactPhysics3D physics library, http://www.reactphysics3d.com *
|
|
||||||
* Copyright (c) 2010-2015 Daniel Chappuis *
|
|
||||||
*********************************************************************************
|
|
||||||
* *
|
|
||||||
* This software is provided 'as-is', without any express or implied warranty. *
|
|
||||||
* In no event will the authors be held liable for any damages arising from the *
|
|
||||||
* use of this software. *
|
|
||||||
* *
|
|
||||||
* Permission is granted to anyone to use this software for any purpose, *
|
|
||||||
* including commercial applications, and to alter it and redistribute it *
|
|
||||||
* freely, subject to the following restrictions: *
|
|
||||||
* *
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not claim *
|
|
||||||
* that you wrote the original software. If you use this software in a *
|
|
||||||
* product, an acknowledgment in the product documentation would be *
|
|
||||||
* appreciated but is not required. *
|
|
||||||
* *
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be *
|
|
||||||
* misrepresented as being the original software. *
|
|
||||||
* *
|
|
||||||
* 3. This notice may not be removed or altered from any source distribution. *
|
|
||||||
* *
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
// Libraries
|
|
||||||
#include "Scene.h"
|
|
||||||
#include "../common/Viewer.h"
|
|
||||||
|
|
||||||
// Declarations
|
|
||||||
void simulate();
|
|
||||||
void render();
|
|
||||||
void update();
|
|
||||||
void mouseButton(GLFWwindow* window, int button, int action, int mods);
|
|
||||||
void mouseMotion(GLFWwindow* window, double x, double y);
|
|
||||||
void keyboard(GLFWwindow* window, int key, int scancode, int action, int mods);
|
|
||||||
void scroll(GLFWwindow* window, double xAxis, double yAxis);
|
|
||||||
void init();
|
|
||||||
|
|
||||||
// Namespaces
|
|
||||||
using namespace openglframework;
|
|
||||||
|
|
||||||
// Global variables
|
|
||||||
Viewer* viewer;
|
|
||||||
Scene* scene;
|
|
||||||
|
|
||||||
// Main function
|
|
||||||
int main(int argc, char** argv) {
|
|
||||||
|
|
||||||
// Create and initialize the Viewer
|
|
||||||
viewer = new Viewer();
|
|
||||||
Vector2 windowsSize = Vector2(800, 600);
|
|
||||||
Vector2 windowsPosition = Vector2(100, 100);
|
|
||||||
viewer->init(argc, argv, "ReactPhysics3D Examples - Collision Shapes",
|
|
||||||
windowsSize, windowsPosition, true);
|
|
||||||
|
|
||||||
// If the shaders and meshes folders are not specified as an argument
|
|
||||||
if (argc < 3) {
|
|
||||||
std::cerr << "Error : You need to specify the shaders folder as the first argument"
|
|
||||||
<< " and the meshes folder as the second argument" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the path of the shaders folder
|
|
||||||
std::string shaderFolderPath(argv[1]);
|
|
||||||
std::string meshFolderPath(argv[2]);
|
|
||||||
|
|
||||||
// Register callback methods
|
|
||||||
viewer->registerUpdateFunction(update);
|
|
||||||
viewer->registerKeyboardCallback(keyboard);
|
|
||||||
viewer->registerMouseButtonCallback(mouseButton);
|
|
||||||
viewer->registerMouseCursorCallback(mouseMotion);
|
|
||||||
viewer->registerScrollingCallback(scroll);
|
|
||||||
|
|
||||||
// Create the scene
|
|
||||||
scene = new Scene(viewer, shaderFolderPath, meshFolderPath);
|
|
||||||
|
|
||||||
init();
|
|
||||||
|
|
||||||
viewer->startMainLoop();
|
|
||||||
|
|
||||||
delete viewer;
|
|
||||||
delete scene;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update function that is called each frame
|
|
||||||
void update() {
|
|
||||||
|
|
||||||
// Take a simulation step
|
|
||||||
simulate();
|
|
||||||
|
|
||||||
// Render
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simulate function
|
|
||||||
void simulate() {
|
|
||||||
|
|
||||||
// Physics simulation
|
|
||||||
scene->simulate();
|
|
||||||
|
|
||||||
viewer->computeFPS();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialization
|
|
||||||
void init() {
|
|
||||||
|
|
||||||
// Define the background color (black)
|
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback method to receive keyboard events
|
|
||||||
void keyboard(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
|
||||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
|
||||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
|
||||||
}
|
|
||||||
else if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) {
|
|
||||||
scene->pauseContinueSimulation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback method to receive scrolling events
|
|
||||||
void scroll(GLFWwindow* window, double xAxis, double yAxis) {
|
|
||||||
viewer->scrollingEvent(static_cast<float>(yAxis));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when a mouse button event occurs
|
|
||||||
void mouseButton(GLFWwindow* window, int button, int action, int mods) {
|
|
||||||
viewer->mouseButtonEvent(button, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when a mouse motion event occurs
|
|
||||||
void mouseMotion(GLFWwindow* window, double x, double y) {
|
|
||||||
viewer->mouseMotionEvent(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display the scene
|
|
||||||
void render() {
|
|
||||||
|
|
||||||
// Render the scene
|
|
||||||
scene->render();
|
|
||||||
|
|
||||||
// Display the FPS
|
|
||||||
viewer->displayGUI();
|
|
||||||
|
|
||||||
// Check the OpenGL errors
|
|
||||||
Viewer::checkOpenGLErrors();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
# Minimum cmake version required
|
|
||||||
cmake_minimum_required(VERSION 2.6)
|
|
||||||
|
|
||||||
# Project configuration
|
|
||||||
PROJECT(Cubes)
|
|
||||||
|
|
||||||
# Where to build the executables
|
|
||||||
SET(EXECUTABLE_OUTPUT_PATH "${OUR_EXECUTABLE_OUTPUT_PATH}/cubes")
|
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
|
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${EXECUTABLE_OUTPUT_PATH})
|
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${EXECUTABLE_OUTPUT_PATH})
|
|
||||||
|
|
||||||
# Copy the shaders used for the demo into the build directory
|
|
||||||
FILE(COPY "${OPENGLFRAMEWORK_DIR}/src/shaders/" DESTINATION "${EXECUTABLE_OUTPUT_PATH}/shaders/")
|
|
||||||
|
|
||||||
# Headers
|
|
||||||
INCLUDE_DIRECTORIES("${OPENGLFRAMEWORK_DIR}/src/" "../common/glfw/include/" "../common/")
|
|
||||||
|
|
||||||
# Source files
|
|
||||||
SET(CUBES_SOURCES
|
|
||||||
Cubes.cpp
|
|
||||||
Scene.cpp
|
|
||||||
Scene.h
|
|
||||||
"../common/Box.cpp"
|
|
||||||
"../common/Box.h"
|
|
||||||
"../common/Viewer.cpp"
|
|
||||||
"../common/Viewer.h"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create the executable
|
|
||||||
ADD_EXECUTABLE(cubes ${CUBES_SOURCES})
|
|
||||||
|
|
||||||
# Link with libraries
|
|
||||||
TARGET_LINK_LIBRARIES(cubes reactphysics3d openglframework glfw ${GLFW_LIBRARIES})
|
|
|
@ -1,148 +0,0 @@
|
||||||
/********************************************************************************
|
|
||||||
* ReactPhysics3D physics library, http://www.reactphysics3d.com *
|
|
||||||
* Copyright (c) 2010-2015 Daniel Chappuis *
|
|
||||||
*********************************************************************************
|
|
||||||
* *
|
|
||||||
* This software is provided 'as-is', without any express or implied warranty. *
|
|
||||||
* In no event will the authors be held liable for any damages arising from the *
|
|
||||||
* use of this software. *
|
|
||||||
* *
|
|
||||||
* Permission is granted to anyone to use this software for any purpose, *
|
|
||||||
* including commercial applications, and to alter it and redistribute it *
|
|
||||||
* freely, subject to the following restrictions: *
|
|
||||||
* *
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not claim *
|
|
||||||
* that you wrote the original software. If you use this software in a *
|
|
||||||
* product, an acknowledgment in the product documentation would be *
|
|
||||||
* appreciated but is not required. *
|
|
||||||
* *
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be *
|
|
||||||
* misrepresented as being the original software. *
|
|
||||||
* *
|
|
||||||
* 3. This notice may not be removed or altered from any source distribution. *
|
|
||||||
* *
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
// Libraries
|
|
||||||
#include "Scene.h"
|
|
||||||
#include "Viewer.h"
|
|
||||||
|
|
||||||
// Declarations
|
|
||||||
void simulate();
|
|
||||||
void render();
|
|
||||||
void update();
|
|
||||||
void mouseButton(GLFWwindow* window, int button, int action, int mods);
|
|
||||||
void mouseMotion(GLFWwindow* window, double x, double y);
|
|
||||||
void keyboard(GLFWwindow* window, int key, int scancode, int action, int mods);
|
|
||||||
void scroll(GLFWwindow* window, double xAxis, double yAxis);
|
|
||||||
void init();
|
|
||||||
|
|
||||||
// Namespaces
|
|
||||||
using namespace openglframework;
|
|
||||||
|
|
||||||
// Global variables
|
|
||||||
Viewer* viewer;
|
|
||||||
Scene* scene;
|
|
||||||
|
|
||||||
// Main function
|
|
||||||
int main(int argc, char** argv) {
|
|
||||||
|
|
||||||
// Create and initialize the Viewer
|
|
||||||
viewer = new Viewer();
|
|
||||||
Vector2 windowsSize = Vector2(800, 600);
|
|
||||||
Vector2 windowsPosition = Vector2(100, 100);
|
|
||||||
viewer->init(argc, argv, "ReactPhysics3D Examples - Cubes", windowsSize, windowsPosition, true);
|
|
||||||
|
|
||||||
// If the shaders folder is not specified as an argument
|
|
||||||
if (argc < 2) {
|
|
||||||
std::cerr << "Error : You need to specify the shaders folder as argument !" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the path of the shaders folder
|
|
||||||
std::string shaderFolderPath(argv[1]);
|
|
||||||
|
|
||||||
// Register callback methods
|
|
||||||
viewer->registerUpdateFunction(update);
|
|
||||||
viewer->registerKeyboardCallback(keyboard);
|
|
||||||
viewer->registerMouseButtonCallback(mouseButton);
|
|
||||||
viewer->registerMouseCursorCallback(mouseMotion);
|
|
||||||
viewer->registerScrollingCallback(scroll);
|
|
||||||
|
|
||||||
// Create the scene
|
|
||||||
scene = new Scene(viewer, shaderFolderPath);
|
|
||||||
|
|
||||||
init();
|
|
||||||
|
|
||||||
viewer->startMainLoop();
|
|
||||||
|
|
||||||
delete viewer;
|
|
||||||
delete scene;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update function that is called each frame
|
|
||||||
void update() {
|
|
||||||
|
|
||||||
// Take a simulation step
|
|
||||||
simulate();
|
|
||||||
|
|
||||||
// Render
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simulate function
|
|
||||||
void simulate() {
|
|
||||||
|
|
||||||
// Physics simulation
|
|
||||||
scene->simulate();
|
|
||||||
|
|
||||||
// Compute the current framerate
|
|
||||||
viewer->computeFPS();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialization
|
|
||||||
void init() {
|
|
||||||
|
|
||||||
// Define the background color (black)
|
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback method to receive keyboard events
|
|
||||||
void keyboard(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
|
||||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
|
||||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
|
||||||
}
|
|
||||||
else if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) {
|
|
||||||
scene->pauseContinueSimulation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback method to receive scrolling events
|
|
||||||
void scroll(GLFWwindow* window, double xAxis, double yAxis) {
|
|
||||||
viewer->scrollingEvent(static_cast<float>(yAxis));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when a mouse button event occurs
|
|
||||||
void mouseButton(GLFWwindow* window, int button, int action, int mods) {
|
|
||||||
viewer->mouseButtonEvent(button, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when a mouse motion event occurs
|
|
||||||
void mouseMotion(GLFWwindow* window, double x, double y) {
|
|
||||||
viewer->mouseMotionEvent(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display the scene
|
|
||||||
void render() {
|
|
||||||
|
|
||||||
// Render the scene
|
|
||||||
scene->render();
|
|
||||||
|
|
||||||
// Display the FPS
|
|
||||||
viewer->displayGUI();
|
|
||||||
|
|
||||||
// Check the OpenGL errors
|
|
||||||
Viewer::checkOpenGLErrors();
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
# Minimum cmake version required
|
|
||||||
cmake_minimum_required(VERSION 2.6)
|
|
||||||
|
|
||||||
# Project configuration
|
|
||||||
PROJECT(Joints)
|
|
||||||
|
|
||||||
# Where to build the executables
|
|
||||||
SET(EXECUTABLE_OUTPUT_PATH "${OUR_EXECUTABLE_OUTPUT_PATH}/joints")
|
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
|
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${EXECUTABLE_OUTPUT_PATH})
|
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${EXECUTABLE_OUTPUT_PATH})
|
|
||||||
|
|
||||||
# Copy the shaders used for the demo into the build directory
|
|
||||||
FILE(COPY "${OPENGLFRAMEWORK_DIR}/src/shaders/" DESTINATION "${EXECUTABLE_OUTPUT_PATH}/shaders/")
|
|
||||||
|
|
||||||
# Headers
|
|
||||||
INCLUDE_DIRECTORIES("${OPENGLFRAMEWORK_DIR}/src/" "../common/glfw/include/" "../common/")
|
|
||||||
|
|
||||||
# Source files
|
|
||||||
SET(JOINTS_SOURCES
|
|
||||||
Joints.cpp
|
|
||||||
Scene.cpp
|
|
||||||
Scene.h
|
|
||||||
"../common/Box.cpp"
|
|
||||||
"../common/Box.h"
|
|
||||||
"../common/Viewer.cpp"
|
|
||||||
"../common/Viewer.h"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create the executable
|
|
||||||
ADD_EXECUTABLE(joints ${JOINTS_SOURCES})
|
|
||||||
|
|
||||||
# Link with libraries
|
|
||||||
TARGET_LINK_LIBRARIES(joints reactphysics3d openglframework glfw ${GLFW_LIBRARIES})
|
|
|
@ -1,149 +0,0 @@
|
||||||
/********************************************************************************
|
|
||||||
* ReactPhysics3D physics library, http://www.reactphysics3d.com *
|
|
||||||
* Copyright (c) 2010-2015 Daniel Chappuis *
|
|
||||||
*********************************************************************************
|
|
||||||
* *
|
|
||||||
* This software is provided 'as-is', without any express or implied warranty. *
|
|
||||||
* In no event will the authors be held liable for any damages arising from the *
|
|
||||||
* use of this software. *
|
|
||||||
* *
|
|
||||||
* Permission is granted to anyone to use this software for any purpose, *
|
|
||||||
* including commercial applications, and to alter it and redistribute it *
|
|
||||||
* freely, subject to the following restrictions: *
|
|
||||||
* *
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not claim *
|
|
||||||
* that you wrote the original software. If you use this software in a *
|
|
||||||
* product, an acknowledgment in the product documentation would be *
|
|
||||||
* appreciated but is not required. *
|
|
||||||
* *
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be *
|
|
||||||
* misrepresented as being the original software. *
|
|
||||||
* *
|
|
||||||
* 3. This notice may not be removed or altered from any source distribution. *
|
|
||||||
* *
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
// Libraries
|
|
||||||
#include "Scene.h"
|
|
||||||
#include "../common/Viewer.h"
|
|
||||||
|
|
||||||
// Declarations
|
|
||||||
void simulate();
|
|
||||||
void update();
|
|
||||||
void render();
|
|
||||||
void mouseButton(GLFWwindow* window, int button, int action, int mods);
|
|
||||||
void mouseMotion(GLFWwindow* window, double x, double y);
|
|
||||||
void keyboard(GLFWwindow* window, int key, int scancode, int action, int mods);
|
|
||||||
void scroll(GLFWwindow* window, double xAxis, double yAxis);
|
|
||||||
void init();
|
|
||||||
|
|
||||||
// Namespaces
|
|
||||||
using namespace openglframework;
|
|
||||||
|
|
||||||
// Global variables
|
|
||||||
Viewer* viewer;
|
|
||||||
Scene* scene;
|
|
||||||
|
|
||||||
// Main function
|
|
||||||
int main(int argc, char** argv) {
|
|
||||||
|
|
||||||
// Create and initialize the Viewer
|
|
||||||
viewer = new Viewer();
|
|
||||||
Vector2 windowsSize = Vector2(800, 600);
|
|
||||||
Vector2 windowsPosition = Vector2(100, 100);
|
|
||||||
viewer->init(argc, argv, "ReactPhysics3D Examples - Joints", windowsSize, windowsPosition, true);
|
|
||||||
|
|
||||||
// If the shaders folder is not specified as an argument
|
|
||||||
if (argc < 2) {
|
|
||||||
std::cerr << "Error : You need to specify the shaders folder as argument !" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the path of the shaders folder
|
|
||||||
std::string shaderFolderPath(argv[1]);
|
|
||||||
|
|
||||||
// Register callback methods
|
|
||||||
viewer->registerUpdateFunction(update);
|
|
||||||
viewer->registerKeyboardCallback(keyboard);
|
|
||||||
viewer->registerMouseButtonCallback(mouseButton);
|
|
||||||
viewer->registerMouseCursorCallback(mouseMotion);
|
|
||||||
viewer->registerScrollingCallback(scroll);
|
|
||||||
|
|
||||||
// Create the scene
|
|
||||||
scene = new Scene(viewer, shaderFolderPath);
|
|
||||||
|
|
||||||
init();
|
|
||||||
|
|
||||||
viewer->startMainLoop();
|
|
||||||
|
|
||||||
delete viewer;
|
|
||||||
delete scene;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update function that is called each frame
|
|
||||||
void update() {
|
|
||||||
|
|
||||||
// Take a simulation step
|
|
||||||
simulate();
|
|
||||||
|
|
||||||
// Render
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simulate function
|
|
||||||
void simulate() {
|
|
||||||
|
|
||||||
// Physics simulation
|
|
||||||
scene->simulate();
|
|
||||||
|
|
||||||
viewer->computeFPS();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialization
|
|
||||||
void init() {
|
|
||||||
|
|
||||||
// Define the background color (black)
|
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback method to receive keyboard events
|
|
||||||
void keyboard(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
|
||||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
|
||||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
|
||||||
}
|
|
||||||
else if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) {
|
|
||||||
scene->pauseContinueSimulation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback method to receive scrolling events
|
|
||||||
void scroll(GLFWwindow* window, double xAxis, double yAxis) {
|
|
||||||
viewer->scrollingEvent(static_cast<float>(yAxis));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when a mouse button event occurs
|
|
||||||
void mouseButton(GLFWwindow* window, int button, int action, int mods) {
|
|
||||||
viewer->mouseButtonEvent(button, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when a mouse motion event occurs
|
|
||||||
void mouseMotion(GLFWwindow* window, double x, double y) {
|
|
||||||
viewer->mouseMotionEvent(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display the scene
|
|
||||||
void render() {
|
|
||||||
|
|
||||||
// Render the scene
|
|
||||||
scene->render();
|
|
||||||
|
|
||||||
// Display the FPS
|
|
||||||
viewer->displayGUI();
|
|
||||||
|
|
||||||
// Check the OpenGL errors
|
|
||||||
Viewer::checkOpenGLErrors();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
# Minimum cmake version required
|
|
||||||
cmake_minimum_required(VERSION 2.6)
|
|
||||||
|
|
||||||
# Project configuration
|
|
||||||
PROJECT(Raycast)
|
|
||||||
|
|
||||||
# Where to build the executables
|
|
||||||
SET(EXECUTABLE_OUTPUT_PATH "${OUR_EXECUTABLE_OUTPUT_PATH}/raycast")
|
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
|
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${EXECUTABLE_OUTPUT_PATH})
|
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${EXECUTABLE_OUTPUT_PATH})
|
|
||||||
|
|
||||||
# Copy the shaders used for the demo into the build directory
|
|
||||||
FILE(COPY "${OPENGLFRAMEWORK_DIR}/src/shaders/" DESTINATION "${EXECUTABLE_OUTPUT_PATH}/shaders/")
|
|
||||||
|
|
||||||
# Copy the meshes used for the demo into the build directory
|
|
||||||
FILE(COPY "../common/meshes/" DESTINATION "${EXECUTABLE_OUTPUT_PATH}/meshes/")
|
|
||||||
|
|
||||||
# Headers
|
|
||||||
INCLUDE_DIRECTORIES("${OPENGLFRAMEWORK_DIR}/src/" "../common/glfw/include/" "../common/")
|
|
||||||
|
|
||||||
# Source files
|
|
||||||
SET(RAYCAST_SOURCES
|
|
||||||
Raycast.cpp
|
|
||||||
Scene.cpp
|
|
||||||
Scene.h
|
|
||||||
"../common/VisualContactPoint.cpp"
|
|
||||||
"../common/ConvexMesh.cpp"
|
|
||||||
"../common/Capsule.cpp"
|
|
||||||
"../common/Sphere.cpp"
|
|
||||||
"../common/Line.cpp"
|
|
||||||
"../common/Cylinder.cpp"
|
|
||||||
"../common/Cone.cpp"
|
|
||||||
"../common/Dumbbell.cpp"
|
|
||||||
"../common/Box.cpp"
|
|
||||||
"../common/Viewer.cpp"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create the executable
|
|
||||||
ADD_EXECUTABLE(raycast ${RAYCAST_SOURCES})
|
|
||||||
|
|
||||||
# Link with libraries
|
|
||||||
TARGET_LINK_LIBRARIES(raycast reactphysics3d openglframework glfw ${GLFW_LIBRARIES})
|
|
|
@ -1,155 +0,0 @@
|
||||||
/********************************************************************************
|
|
||||||
* ReactPhysics3D physics library, http://www.reactphysics3d.com *
|
|
||||||
* Copyright (c) 2010-2015 Daniel Chappuis *
|
|
||||||
*********************************************************************************
|
|
||||||
* *
|
|
||||||
* This software is provided 'as-is', without any express or implied warranty. *
|
|
||||||
* In no event will the authors be held liable for any damages arising from the *
|
|
||||||
* use of this software. *
|
|
||||||
* *
|
|
||||||
* Permission is granted to anyone to use this software for any purpose, *
|
|
||||||
* including commercial applications, and to alter it and redistribute it *
|
|
||||||
* freely, subject to the following restrictions: *
|
|
||||||
* *
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not claim *
|
|
||||||
* that you wrote the original software. If you use this software in a *
|
|
||||||
* product, an acknowledgment in the product documentation would be *
|
|
||||||
* appreciated but is not required. *
|
|
||||||
* *
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be *
|
|
||||||
* misrepresented as being the original software. *
|
|
||||||
* *
|
|
||||||
* 3. This notice may not be removed or altered from any source distribution. *
|
|
||||||
* *
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
// Libraries
|
|
||||||
#include "Scene.h"
|
|
||||||
#include "../common/Viewer.h"
|
|
||||||
|
|
||||||
// Declarations
|
|
||||||
void simulate();
|
|
||||||
void render();
|
|
||||||
void update();
|
|
||||||
void mouseButton(GLFWwindow* window, int button, int action, int mods);
|
|
||||||
void mouseMotion(GLFWwindow* window, double x, double y);
|
|
||||||
void keyboard(GLFWwindow* window, int key, int scancode, int action, int mods);
|
|
||||||
void scroll(GLFWwindow* window, double xAxis, double yAxis);
|
|
||||||
void init();
|
|
||||||
|
|
||||||
// Namespaces
|
|
||||||
using namespace openglframework;
|
|
||||||
|
|
||||||
// Global variables
|
|
||||||
Viewer* viewer;
|
|
||||||
Scene* scene;
|
|
||||||
|
|
||||||
// Main function
|
|
||||||
int main(int argc, char** argv) {
|
|
||||||
|
|
||||||
// Create and initialize the Viewer
|
|
||||||
viewer = new Viewer();
|
|
||||||
Vector2 windowsSize = Vector2(800, 600);
|
|
||||||
Vector2 windowsPosition = Vector2(100, 100);
|
|
||||||
viewer->init(argc, argv, "ReactPhysics3D Examples - Raycast",
|
|
||||||
windowsSize, windowsPosition, true);
|
|
||||||
|
|
||||||
// If the shaders and meshes folders are not specified as an argument
|
|
||||||
if (argc < 3) {
|
|
||||||
std::cerr << "Error : You need to specify the shaders folder as the first argument"
|
|
||||||
<< " and the meshes folder as the second argument" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the path of the shaders folder
|
|
||||||
std::string shaderFolderPath(argv[1]);
|
|
||||||
std::string meshFolderPath(argv[2]);
|
|
||||||
|
|
||||||
// Register callback methods
|
|
||||||
viewer->registerUpdateFunction(update);
|
|
||||||
viewer->registerKeyboardCallback(keyboard);
|
|
||||||
viewer->registerMouseButtonCallback(mouseButton);
|
|
||||||
viewer->registerMouseCursorCallback(mouseMotion);
|
|
||||||
viewer->registerScrollingCallback(scroll);
|
|
||||||
|
|
||||||
// Create the scene
|
|
||||||
scene = new Scene(viewer, shaderFolderPath, meshFolderPath);
|
|
||||||
|
|
||||||
init();
|
|
||||||
|
|
||||||
viewer->startMainLoop();
|
|
||||||
|
|
||||||
delete viewer;
|
|
||||||
delete scene;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update function that is called each frame
|
|
||||||
void update() {
|
|
||||||
|
|
||||||
// Take a simulation step
|
|
||||||
simulate();
|
|
||||||
|
|
||||||
// Render
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simulate function
|
|
||||||
void simulate() {
|
|
||||||
|
|
||||||
// Physics simulation
|
|
||||||
scene->simulate();
|
|
||||||
|
|
||||||
viewer->computeFPS();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialization
|
|
||||||
void init() {
|
|
||||||
|
|
||||||
// Define the background color (black)
|
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback method to receive keyboard events
|
|
||||||
void keyboard(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
|
||||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
|
||||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
|
||||||
}
|
|
||||||
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) {
|
|
||||||
scene->changeBody();
|
|
||||||
}
|
|
||||||
if (key == GLFW_KEY_N && action == GLFW_PRESS) {
|
|
||||||
scene->showHideNormals();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback method to receive scrolling events
|
|
||||||
void scroll(GLFWwindow* window, double xAxis, double yAxis) {
|
|
||||||
viewer->scrollingEvent(static_cast<float>(yAxis));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when a mouse button event occurs
|
|
||||||
void mouseButton(GLFWwindow* window, int button, int action, int mods) {
|
|
||||||
viewer->mouseButtonEvent(button, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when a mouse motion event occurs
|
|
||||||
void mouseMotion(GLFWwindow* window, double x, double y) {
|
|
||||||
viewer->mouseMotionEvent(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display the scene
|
|
||||||
void render() {
|
|
||||||
|
|
||||||
// Render the scene
|
|
||||||
scene->render();
|
|
||||||
|
|
||||||
// Display the FPS
|
|
||||||
viewer->displayGUI();
|
|
||||||
|
|
||||||
// Check the OpenGL errors
|
|
||||||
Viewer::checkOpenGLErrors();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -24,16 +24,17 @@
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "Scene.h"
|
#include "CollisionShapesScene.h"
|
||||||
|
|
||||||
// Namespaces
|
// Namespaces
|
||||||
using namespace openglframework;
|
using namespace openglframework;
|
||||||
|
using namespace collisionshapesscene;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath, const std::string& meshFolderPath)
|
CollisionShapesScene::CollisionShapesScene(const std::string& name)
|
||||||
: mViewer(viewer), mLight0(0),
|
: Scene(name), mLight0(0), mPhongShader("shaders/phong.vert", "shaders/phong.frag") {
|
||||||
mPhongShader(shaderFolderPath + "phong.vert",
|
|
||||||
shaderFolderPath +"phong.frag"), mIsRunning(false) {
|
std::string meshFolderPath("meshes/");
|
||||||
|
|
||||||
// Move the light 0
|
// Move the light 0
|
||||||
mLight0.translateWorld(Vector3(50, 50, 50));
|
mLight0.translateWorld(Vector3(50, 50, 50));
|
||||||
|
@ -43,7 +44,7 @@ Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath, const std::str
|
||||||
openglframework::Vector3 center(0, 5, 0);
|
openglframework::Vector3 center(0, 5, 0);
|
||||||
|
|
||||||
// Set the center of the scene
|
// Set the center of the scene
|
||||||
mViewer->setScenePosition(center, radiusScene);
|
setScenePosition(center, radiusScene);
|
||||||
|
|
||||||
// Gravity vector in the dynamics world
|
// Gravity vector in the dynamics world
|
||||||
rp3d::Vector3 gravity(0, -9.81, 0);
|
rp3d::Vector3 gravity(0, -9.81, 0);
|
||||||
|
@ -217,14 +218,11 @@ Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath, const std::str
|
||||||
material.setBounciness(rp3d::decimal(0.2));
|
material.setBounciness(rp3d::decimal(0.2));
|
||||||
|
|
||||||
// Start the simulation
|
// Start the simulation
|
||||||
startSimulation();
|
mDynamicsWorld->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Scene::~Scene() {
|
CollisionShapesScene::~CollisionShapesScene() {
|
||||||
|
|
||||||
// Stop the physics simulation
|
|
||||||
stopSimulation();
|
|
||||||
|
|
||||||
// Destroy the shader
|
// Destroy the shader
|
||||||
mPhongShader.destroy();
|
mPhongShader.destroy();
|
||||||
|
@ -312,85 +310,81 @@ Scene::~Scene() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take a step for the simulation
|
// Take a step for the simulation
|
||||||
void Scene::simulate() {
|
void CollisionShapesScene::update() {
|
||||||
|
|
||||||
// If the physics simulation is running
|
|
||||||
if (mIsRunning) {
|
|
||||||
|
|
||||||
// Take a simulation step
|
// Take a simulation step
|
||||||
mDynamicsWorld->update();
|
mDynamicsWorld->update();
|
||||||
|
|
||||||
// Update the position and orientation of the boxes
|
// Update the position and orientation of the boxes
|
||||||
for (std::vector<Box*>::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it) {
|
for (std::vector<Box*>::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it) {
|
||||||
|
|
||||||
// Update the transform used for the rendering
|
// Update the transform used for the rendering
|
||||||
(*it)->updateTransform();
|
(*it)->updateTransform();
|
||||||
}
|
|
||||||
|
|
||||||
// Update the position and orientation of the sphere
|
|
||||||
for (std::vector<Sphere*>::iterator it = mSpheres.begin(); it != mSpheres.end(); ++it) {
|
|
||||||
|
|
||||||
// Update the transform used for the rendering
|
|
||||||
(*it)->updateTransform();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the position and orientation of the cones
|
|
||||||
for (std::vector<Cone*>::iterator it = mCones.begin(); it != mCones.end(); ++it) {
|
|
||||||
|
|
||||||
// Update the transform used for the rendering
|
|
||||||
(*it)->updateTransform();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the position and orientation of the cylinders
|
|
||||||
for (std::vector<Cylinder*>::iterator it = mCylinders.begin(); it != mCylinders.end(); ++it) {
|
|
||||||
|
|
||||||
// Update the transform used for the rendering
|
|
||||||
(*it)->updateTransform();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the position and orientation of the capsules
|
|
||||||
for (std::vector<Capsule*>::iterator it = mCapsules.begin(); it != mCapsules.end(); ++it) {
|
|
||||||
|
|
||||||
// Update the transform used for the rendering
|
|
||||||
(*it)->updateTransform();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the position and orientation of the convex meshes
|
|
||||||
for (std::vector<ConvexMesh*>::iterator it = mConvexMeshes.begin();
|
|
||||||
it != mConvexMeshes.end(); ++it) {
|
|
||||||
|
|
||||||
// Update the transform used for the rendering
|
|
||||||
(*it)->updateTransform();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the position and orientation of the dumbbells
|
|
||||||
for (std::vector<Dumbbell*>::iterator it = mDumbbells.begin();
|
|
||||||
it != mDumbbells.end(); ++it) {
|
|
||||||
|
|
||||||
// Update the transform used for the rendering
|
|
||||||
(*it)->updateTransform();
|
|
||||||
}
|
|
||||||
|
|
||||||
mFloor->updateTransform();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the position and orientation of the sphere
|
||||||
|
for (std::vector<Sphere*>::iterator it = mSpheres.begin(); it != mSpheres.end(); ++it) {
|
||||||
|
|
||||||
|
// Update the transform used for the rendering
|
||||||
|
(*it)->updateTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the position and orientation of the cones
|
||||||
|
for (std::vector<Cone*>::iterator it = mCones.begin(); it != mCones.end(); ++it) {
|
||||||
|
|
||||||
|
// Update the transform used for the rendering
|
||||||
|
(*it)->updateTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the position and orientation of the cylinders
|
||||||
|
for (std::vector<Cylinder*>::iterator it = mCylinders.begin(); it != mCylinders.end(); ++it) {
|
||||||
|
|
||||||
|
// Update the transform used for the rendering
|
||||||
|
(*it)->updateTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the position and orientation of the capsules
|
||||||
|
for (std::vector<Capsule*>::iterator it = mCapsules.begin(); it != mCapsules.end(); ++it) {
|
||||||
|
|
||||||
|
// Update the transform used for the rendering
|
||||||
|
(*it)->updateTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the position and orientation of the convex meshes
|
||||||
|
for (std::vector<ConvexMesh*>::iterator it = mConvexMeshes.begin();
|
||||||
|
it != mConvexMeshes.end(); ++it) {
|
||||||
|
|
||||||
|
// Update the transform used for the rendering
|
||||||
|
(*it)->updateTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the position and orientation of the dumbbells
|
||||||
|
for (std::vector<Dumbbell*>::iterator it = mDumbbells.begin();
|
||||||
|
it != mDumbbells.end(); ++it) {
|
||||||
|
|
||||||
|
// Update the transform used for the rendering
|
||||||
|
(*it)->updateTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
mFloor->updateTransform();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the scene
|
// Render the scene
|
||||||
void Scene::render() {
|
void CollisionShapesScene::render() {
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
// Get the world-space to camera-space matrix
|
// Get the world-space to camera-space matrix
|
||||||
const Camera& camera = mViewer->getCamera();
|
const openglframework::Matrix4 worldToCameraMatrix = mCamera.getTransformMatrix().getInverse();
|
||||||
const openglframework::Matrix4 worldToCameraMatrix = camera.getTransformMatrix().getInverse();
|
|
||||||
|
|
||||||
// Bind the shader
|
// Bind the shader
|
||||||
mPhongShader.bind();
|
mPhongShader.bind();
|
||||||
|
|
||||||
// Set the variables of the shader
|
// Set the variables of the shader
|
||||||
mPhongShader.setMatrix4x4Uniform("projectionMatrix", camera.getProjectionMatrix());
|
mPhongShader.setMatrix4x4Uniform("projectionMatrix", mCamera.getProjectionMatrix());
|
||||||
mPhongShader.setVector3Uniform("light0PosCameraSpace", worldToCameraMatrix * mLight0.getOrigin());
|
mPhongShader.setVector3Uniform("light0PosCameraSpace", worldToCameraMatrix * mLight0.getOrigin());
|
||||||
mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f));
|
mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f));
|
||||||
const Color& diffColLight0 = mLight0.getDiffuseColor();
|
const Color& diffColLight0 = mLight0.getDiffuseColor();
|
||||||
|
@ -442,3 +436,8 @@ void Scene::render() {
|
||||||
// Unbind the shader
|
// Unbind the shader
|
||||||
mPhongShader.unbind();
|
mPhongShader.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reset the scene
|
||||||
|
void CollisionShapesScene::reset() {
|
||||||
|
|
||||||
|
}
|
|
@ -23,12 +23,13 @@
|
||||||
* *
|
* *
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
#ifndef SCENE_H
|
#ifndef COLLISION_SHAPES_SCENE_H
|
||||||
#define SCENE_H
|
#define COLLISION_SHAPES_SCENE_H
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "openglframework.h"
|
#include "openglframework.h"
|
||||||
#include "reactphysics3d.h"
|
#include "reactphysics3d.h"
|
||||||
|
#include "Scene.h"
|
||||||
#include "Sphere.h"
|
#include "Sphere.h"
|
||||||
#include "Box.h"
|
#include "Box.h"
|
||||||
#include "Cone.h"
|
#include "Cone.h"
|
||||||
|
@ -39,6 +40,9 @@
|
||||||
#include "VisualContactPoint.h"
|
#include "VisualContactPoint.h"
|
||||||
#include "../common/Viewer.h"
|
#include "../common/Viewer.h"
|
||||||
|
|
||||||
|
namespace collisionshapesscene {
|
||||||
|
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const int NB_BOXES = 2;
|
const int NB_BOXES = 2;
|
||||||
const int NB_CUBES = 1;
|
const int NB_CUBES = 1;
|
||||||
|
@ -64,16 +68,13 @@ const float CAPSULE_MASS = 1.0f;
|
||||||
const float MESH_MASS = 1.0f;
|
const float MESH_MASS = 1.0f;
|
||||||
const float FLOOR_MASS = 100.0f; // Floor mass in kilograms
|
const float FLOOR_MASS = 100.0f; // Floor mass in kilograms
|
||||||
|
|
||||||
// Class Scene
|
// Class CollisionShapesScene
|
||||||
class Scene {
|
class CollisionShapesScene : public Scene{
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
// -------------------- Attributes -------------------- //
|
// -------------------- Attributes -------------------- //
|
||||||
|
|
||||||
/// Pointer to the viewer
|
|
||||||
Viewer* mViewer;
|
|
||||||
|
|
||||||
/// Light 0
|
/// Light 0
|
||||||
openglframework::Light mLight0;
|
openglframework::Light mLight0;
|
||||||
|
|
||||||
|
@ -103,56 +104,26 @@ class Scene {
|
||||||
/// Dynamics world used for the physics simulation
|
/// Dynamics world used for the physics simulation
|
||||||
rp3d::DynamicsWorld* mDynamicsWorld;
|
rp3d::DynamicsWorld* mDynamicsWorld;
|
||||||
|
|
||||||
/// True if the physics simulation is running
|
|
||||||
bool mIsRunning;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
Scene(Viewer* viewer, const std::string& shaderFolderPath,
|
CollisionShapesScene(const std::string& name);
|
||||||
const std::string& meshFolderPath);
|
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~Scene();
|
virtual ~CollisionShapesScene();
|
||||||
|
|
||||||
/// Take a step for the simulation
|
/// Take a step for the simulation
|
||||||
void simulate();
|
virtual void update();
|
||||||
|
|
||||||
/// Stop the simulation
|
|
||||||
void stopSimulation();
|
|
||||||
|
|
||||||
/// Start the simulation
|
|
||||||
void startSimulation();
|
|
||||||
|
|
||||||
/// Pause or continue simulation
|
|
||||||
void pauseContinueSimulation();
|
|
||||||
|
|
||||||
/// Render the scene
|
/// Render the scene
|
||||||
void render();
|
virtual void render();
|
||||||
|
|
||||||
|
/// Reset the scene
|
||||||
|
virtual void reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Stop the simulation
|
|
||||||
inline void Scene::stopSimulation() {
|
|
||||||
mDynamicsWorld->stop();
|
|
||||||
mIsRunning = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the simulation
|
|
||||||
inline void Scene::startSimulation() {
|
|
||||||
mDynamicsWorld->start();
|
|
||||||
mIsRunning = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pause or continue simulation
|
|
||||||
inline void Scene::pauseContinueSimulation() {
|
|
||||||
if (mIsRunning) {
|
|
||||||
stopSimulation();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
startSimulation();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -24,16 +24,16 @@
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "Scene.h"
|
#include "CubesScene.h"
|
||||||
|
|
||||||
// Namespaces
|
// Namespaces
|
||||||
using namespace openglframework;
|
using namespace openglframework;
|
||||||
|
using namespace cubesscene;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath)
|
CubesScene::CubesScene(const std::string& name)
|
||||||
: mViewer(viewer), mLight0(0),
|
: Scene(name), mLight0(0),
|
||||||
mPhongShader(shaderFolderPath + "phong.vert", shaderFolderPath + "phong.frag"),
|
mPhongShader("shaders/phong.vert", "shaders/phong.frag") {
|
||||||
mIsRunning(false) {
|
|
||||||
|
|
||||||
// Move the light 0
|
// Move the light 0
|
||||||
mLight0.translateWorld(Vector3(7, 15, 15));
|
mLight0.translateWorld(Vector3(7, 15, 15));
|
||||||
|
@ -43,7 +43,7 @@ Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath)
|
||||||
openglframework::Vector3 center(0, 5, 0);
|
openglframework::Vector3 center(0, 5, 0);
|
||||||
|
|
||||||
// Set the center of the scene
|
// Set the center of the scene
|
||||||
mViewer->setScenePosition(center, radiusScene);
|
setScenePosition(center, radiusScene);
|
||||||
|
|
||||||
// Gravity vector in the dynamics world
|
// Gravity vector in the dynamics world
|
||||||
rp3d::Vector3 gravity(0, rp3d::decimal(-5.81), 0);
|
rp3d::Vector3 gravity(0, rp3d::decimal(-5.81), 0);
|
||||||
|
@ -91,16 +91,15 @@ Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath)
|
||||||
material.setBounciness(rp3d::decimal(0.3));
|
material.setBounciness(rp3d::decimal(0.3));
|
||||||
|
|
||||||
// Start the simulation
|
// Start the simulation
|
||||||
startSimulation();
|
mDynamicsWorld->start();
|
||||||
|
|
||||||
counter=0;
|
counter=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Scene::~Scene() {
|
CubesScene::~CubesScene() {
|
||||||
|
|
||||||
// Stop the physics simulation
|
mDynamicsWorld->stop();
|
||||||
stopSimulation();
|
|
||||||
|
|
||||||
// Destroy the shader
|
// Destroy the shader
|
||||||
mPhongShader.destroy();
|
mPhongShader.destroy();
|
||||||
|
@ -126,56 +125,51 @@ Scene::~Scene() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take a step for the simulation
|
// Take a step for the simulation
|
||||||
void Scene::simulate() {
|
void CubesScene::update() {
|
||||||
|
|
||||||
// If the physics simulation is running
|
counter++;
|
||||||
if (mIsRunning) {
|
if (counter == 400) {
|
||||||
|
//mIsRunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
counter++;
|
// Take a simulation step
|
||||||
if (counter == 400) {
|
mDynamicsWorld->update();
|
||||||
//mIsRunning = false;
|
|
||||||
|
// Update the position and orientation of the boxes
|
||||||
|
for (std::vector<Box*>::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it) {
|
||||||
|
|
||||||
|
// Update the transform used for the rendering
|
||||||
|
(*it)->updateTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
mFloor->updateTransform();
|
||||||
|
|
||||||
|
// Set the color of the awake/sleeping bodies
|
||||||
|
for (uint i=0; i<mBoxes.size(); i++) {
|
||||||
|
if (mBoxes[i]->getRigidBody()->isSleeping()) {
|
||||||
|
mBoxes[i]->setColor(Color(1, 0, 0, 1));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
// Take a simulation step
|
mBoxes[i]->setColor(Color(0, 1, 0, 1));
|
||||||
mDynamicsWorld->update();
|
|
||||||
|
|
||||||
// Update the position and orientation of the boxes
|
|
||||||
for (std::vector<Box*>::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it) {
|
|
||||||
|
|
||||||
// Update the transform used for the rendering
|
|
||||||
(*it)->updateTransform();
|
|
||||||
}
|
|
||||||
|
|
||||||
mFloor->updateTransform();
|
|
||||||
|
|
||||||
// Set the color of the awake/sleeping bodies
|
|
||||||
for (uint i=0; i<mBoxes.size(); i++) {
|
|
||||||
if (mBoxes[i]->getRigidBody()->isSleeping()) {
|
|
||||||
mBoxes[i]->setColor(Color(1, 0, 0, 1));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mBoxes[i]->setColor(Color(0, 1, 0, 1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the scene
|
// Render the scene
|
||||||
void Scene::render() {
|
void CubesScene::render() {
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
// Get the world-space to camera-space matrix
|
// Get the world-space to camera-space matrix
|
||||||
const Camera& camera = mViewer->getCamera();
|
const openglframework::Matrix4 worldToCameraMatrix = mCamera.getTransformMatrix().getInverse();
|
||||||
const openglframework::Matrix4 worldToCameraMatrix = camera.getTransformMatrix().getInverse();
|
|
||||||
|
|
||||||
// Bind the shader
|
// Bind the shader
|
||||||
mPhongShader.bind();
|
mPhongShader.bind();
|
||||||
|
|
||||||
// Set the variables of the shader
|
// Set the variables of the shader
|
||||||
mPhongShader.setMatrix4x4Uniform("projectionMatrix", camera.getProjectionMatrix());
|
mPhongShader.setMatrix4x4Uniform("projectionMatrix", mCamera.getProjectionMatrix());
|
||||||
mPhongShader.setVector3Uniform("light0PosCameraSpace",worldToCameraMatrix * mLight0.getOrigin());
|
mPhongShader.setVector3Uniform("light0PosCameraSpace",worldToCameraMatrix * mLight0.getOrigin());
|
||||||
mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f));
|
mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f));
|
||||||
const Color& diffCol = mLight0.getDiffuseColor();
|
const Color& diffCol = mLight0.getDiffuseColor();
|
||||||
|
@ -195,3 +189,8 @@ void Scene::render() {
|
||||||
// Unbind the shader
|
// Unbind the shader
|
||||||
mPhongShader.unbind();
|
mPhongShader.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset the scene
|
||||||
|
void CubesScene::reset() {
|
||||||
|
|
||||||
|
}
|
|
@ -23,14 +23,16 @@
|
||||||
* *
|
* *
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
#ifndef SCENE_H
|
#ifndef CUBES_SCENE_H
|
||||||
#define SCENE_H
|
#define CUBES_SCENE_H
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "openglframework.h"
|
#include "openglframework.h"
|
||||||
#include "reactphysics3d.h"
|
#include "reactphysics3d.h"
|
||||||
#include "Box.h"
|
#include "Box.h"
|
||||||
#include "Viewer.h"
|
#include "Scene.h"
|
||||||
|
|
||||||
|
namespace cubesscene {
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const int NB_CUBES = 200; // Number of boxes in the scene
|
const int NB_CUBES = 200; // Number of boxes in the scene
|
||||||
|
@ -39,18 +41,15 @@ const openglframework::Vector3 FLOOR_SIZE(50, 0.5f, 50); // Floor dimensions i
|
||||||
const float BOX_MASS = 1.0f; // Box mass in kilograms
|
const float BOX_MASS = 1.0f; // Box mass in kilograms
|
||||||
const float FLOOR_MASS = 100.0f; // Floor mass in kilograms
|
const float FLOOR_MASS = 100.0f; // Floor mass in kilograms
|
||||||
|
|
||||||
// Class Scene
|
// Class CubesScene
|
||||||
class Scene {
|
class CubesScene : public Scene {
|
||||||
|
|
||||||
private :
|
protected :
|
||||||
|
|
||||||
// -------------------- Attributes -------------------- //
|
// -------------------- Attributes -------------------- //
|
||||||
|
|
||||||
int counter;
|
int counter;
|
||||||
|
|
||||||
/// Pointer to the viewer
|
|
||||||
Viewer* mViewer;
|
|
||||||
|
|
||||||
/// Light 0
|
/// Light 0
|
||||||
openglframework::Light mLight0;
|
openglframework::Light mLight0;
|
||||||
|
|
||||||
|
@ -66,55 +65,26 @@ class Scene {
|
||||||
/// Dynamics world used for the physics simulation
|
/// Dynamics world used for the physics simulation
|
||||||
rp3d::DynamicsWorld* mDynamicsWorld;
|
rp3d::DynamicsWorld* mDynamicsWorld;
|
||||||
|
|
||||||
/// True if the physics simulation is running
|
|
||||||
bool mIsRunning;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
Scene(Viewer* viewer, const std::string& shaderFolderPath);
|
CubesScene(const std::string& name);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~Scene();
|
virtual ~CubesScene();
|
||||||
|
|
||||||
/// Take a step for the simulation
|
/// Update the scene (take a simulation step)
|
||||||
void simulate();
|
virtual void update();
|
||||||
|
|
||||||
/// Stop the simulation
|
|
||||||
void stopSimulation();
|
|
||||||
|
|
||||||
/// Start the simulation
|
|
||||||
void startSimulation();
|
|
||||||
|
|
||||||
/// Pause or continue simulation
|
|
||||||
void pauseContinueSimulation();
|
|
||||||
|
|
||||||
/// Render the scene
|
/// Render the scene
|
||||||
void render();
|
virtual void render();
|
||||||
|
|
||||||
|
/// Reset the scene
|
||||||
|
virtual void reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Stop the simulation
|
|
||||||
inline void Scene::stopSimulation() {
|
|
||||||
mDynamicsWorld->stop();
|
|
||||||
mIsRunning = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the simulation
|
|
||||||
inline void Scene::startSimulation() {
|
|
||||||
mDynamicsWorld->start();
|
|
||||||
mIsRunning = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pause or continue simulation
|
|
||||||
inline void Scene::pauseContinueSimulation() {
|
|
||||||
if (mIsRunning) {
|
|
||||||
stopSimulation();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
startSimulation();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -24,17 +24,17 @@
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "Scene.h"
|
#include "JointsScene.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
// Namespaces
|
// Namespaces
|
||||||
using namespace openglframework;
|
using namespace openglframework;
|
||||||
|
using namespace jointsscene;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Scene::Scene(Viewer *viewer, const std::string& shaderFolderPath)
|
JointsScene::JointsScene(const std::string& name)
|
||||||
: mViewer(viewer), mLight0(0), mPhongShader(shaderFolderPath + "phong.vert",
|
: Scene(name), mLight0(0), mPhongShader("shaders/phong.vert",
|
||||||
shaderFolderPath + "phong.frag"),
|
"shaders/phong.frag") {
|
||||||
mIsRunning(false) {
|
|
||||||
|
|
||||||
// Move the light 0
|
// Move the light 0
|
||||||
mLight0.translateWorld(Vector3(7, 15, 15));
|
mLight0.translateWorld(Vector3(7, 15, 15));
|
||||||
|
@ -44,7 +44,7 @@ Scene::Scene(Viewer *viewer, const std::string& shaderFolderPath)
|
||||||
openglframework::Vector3 center(0, 5, 0);
|
openglframework::Vector3 center(0, 5, 0);
|
||||||
|
|
||||||
// Set the center of the scene
|
// Set the center of the scene
|
||||||
mViewer->setScenePosition(center, radiusScene);
|
setScenePosition(center, radiusScene);
|
||||||
|
|
||||||
// Gravity vector in the dynamics world
|
// Gravity vector in the dynamics world
|
||||||
rp3d::Vector3 gravity(0, rp3d::decimal(-9.81), 0);
|
rp3d::Vector3 gravity(0, rp3d::decimal(-9.81), 0);
|
||||||
|
@ -74,14 +74,14 @@ Scene::Scene(Viewer *viewer, const std::string& shaderFolderPath)
|
||||||
createFloor();
|
createFloor();
|
||||||
|
|
||||||
// Start the simulation
|
// Start the simulation
|
||||||
startSimulation();
|
mDynamicsWorld->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Scene::~Scene() {
|
JointsScene::~JointsScene() {
|
||||||
|
|
||||||
// Stop the physics simulation
|
// Stop the physics simulation
|
||||||
stopSimulation();
|
mDynamicsWorld->stop();
|
||||||
|
|
||||||
// Destroy the shader
|
// Destroy the shader
|
||||||
mPhongShader.destroy();
|
mPhongShader.destroy();
|
||||||
|
@ -123,50 +123,45 @@ Scene::~Scene() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take a step for the simulation
|
// Take a step for the simulation
|
||||||
void Scene::simulate() {
|
void JointsScene::update() {
|
||||||
|
|
||||||
// If the physics simulation is running
|
// Update the motor speed of the Slider Joint (to move up and down)
|
||||||
if (mIsRunning) {
|
long double motorSpeed = 2 * cos(mDynamicsWorld->getPhysicsTime() * 1.5);
|
||||||
|
mSliderJoint->setMotorSpeed(rp3d::decimal(motorSpeed));
|
||||||
|
|
||||||
// Update the motor speed of the Slider Joint (to move up and down)
|
// Take a simulation step
|
||||||
long double motorSpeed = 2 * cos(mDynamicsWorld->getPhysicsTime() * 1.5);
|
mDynamicsWorld->update();
|
||||||
mSliderJoint->setMotorSpeed(rp3d::decimal(motorSpeed));
|
|
||||||
|
|
||||||
// Take a simulation step
|
// Update the position and orientation of the boxes
|
||||||
mDynamicsWorld->update();
|
mSliderJointBottomBox->updateTransform();
|
||||||
|
mSliderJointTopBox->updateTransform();
|
||||||
// Update the position and orientation of the boxes
|
mPropellerBox->updateTransform();
|
||||||
mSliderJointBottomBox->updateTransform();
|
mFixedJointBox1->updateTransform();
|
||||||
mSliderJointTopBox->updateTransform();
|
mFixedJointBox2->updateTransform();
|
||||||
mPropellerBox->updateTransform();
|
for (int i=0; i<NB_BALLSOCKETJOINT_BOXES; i++) {
|
||||||
mFixedJointBox1->updateTransform();
|
mBallAndSocketJointChainBoxes[i]->updateTransform();
|
||||||
mFixedJointBox2->updateTransform();
|
|
||||||
for (int i=0; i<NB_BALLSOCKETJOINT_BOXES; i++) {
|
|
||||||
mBallAndSocketJointChainBoxes[i]->updateTransform();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the position and orientation of the floor
|
|
||||||
mFloor->updateTransform();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the position and orientation of the floor
|
||||||
|
mFloor->updateTransform();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the scene
|
// Render the scene
|
||||||
void Scene::render() {
|
void JointsScene::render() {
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
// Get the world-space to camera-space matrix
|
// Get the world-space to camera-space matrix
|
||||||
const Camera& camera = mViewer->getCamera();
|
const openglframework::Matrix4 worldToCameraMatrix = mCamera.getTransformMatrix().getInverse();
|
||||||
const openglframework::Matrix4 worldToCameraMatrix = camera.getTransformMatrix().getInverse();
|
|
||||||
|
|
||||||
// Bind the shader
|
// Bind the shader
|
||||||
mPhongShader.bind();
|
mPhongShader.bind();
|
||||||
|
|
||||||
// Set the variables of the shader
|
// Set the variables of the shader
|
||||||
mPhongShader.setVector3Uniform("light0PosCameraSpace",worldToCameraMatrix * mLight0.getOrigin());
|
mPhongShader.setVector3Uniform("light0PosCameraSpace",worldToCameraMatrix * mLight0.getOrigin());
|
||||||
mPhongShader.setMatrix4x4Uniform("projectionMatrix", camera.getProjectionMatrix());
|
mPhongShader.setMatrix4x4Uniform("projectionMatrix", mCamera.getProjectionMatrix());
|
||||||
mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f));
|
mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f));
|
||||||
const Color& diffCol = mLight0.getDiffuseColor();
|
const Color& diffCol = mLight0.getDiffuseColor();
|
||||||
const Color& specCol = mLight0.getSpecularColor();
|
const Color& specCol = mLight0.getSpecularColor();
|
||||||
|
@ -191,8 +186,13 @@ void Scene::render() {
|
||||||
mPhongShader.unbind();
|
mPhongShader.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset the scene
|
||||||
|
void JointsScene::reset() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Create the boxes and joints for the Ball-and-Socket joint example
|
// Create the boxes and joints for the Ball-and-Socket joint example
|
||||||
void Scene::createBallAndSocketJoints() {
|
void JointsScene::createBallAndSocketJoints() {
|
||||||
|
|
||||||
// --------------- Create the boxes --------------- //
|
// --------------- Create the boxes --------------- //
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ void Scene::createBallAndSocketJoints() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create the boxes and joint for the Slider joint example
|
/// Create the boxes and joint for the Slider joint example
|
||||||
void Scene::createSliderJoint() {
|
void JointsScene::createSliderJoint() {
|
||||||
|
|
||||||
// --------------- Create the first box --------------- //
|
// --------------- Create the first box --------------- //
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ void Scene::createSliderJoint() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create the boxes and joint for the Hinge joint example
|
/// Create the boxes and joint for the Hinge joint example
|
||||||
void Scene::createPropellerHingeJoint() {
|
void JointsScene::createPropellerHingeJoint() {
|
||||||
|
|
||||||
// --------------- Create the propeller box --------------- //
|
// --------------- Create the propeller box --------------- //
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ void Scene::createPropellerHingeJoint() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create the boxes and joints for the fixed joints
|
/// Create the boxes and joints for the fixed joints
|
||||||
void Scene::createFixedJoints() {
|
void JointsScene::createFixedJoints() {
|
||||||
|
|
||||||
// --------------- Create the first box --------------- //
|
// --------------- Create the first box --------------- //
|
||||||
|
|
||||||
|
@ -379,7 +379,7 @@ void Scene::createFixedJoints() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the floor
|
// Create the floor
|
||||||
void Scene::createFloor() {
|
void JointsScene::createFloor() {
|
||||||
|
|
||||||
// Create the floor
|
// Create the floor
|
||||||
openglframework::Vector3 floorPosition(0, 0, 0);
|
openglframework::Vector3 floorPosition(0, 0, 0);
|
|
@ -23,14 +23,16 @@
|
||||||
* *
|
* *
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
#ifndef SCENE_H
|
#ifndef JOINTS_SCENE_H
|
||||||
#define SCENE_H
|
#define JOINTS_SCENE_H
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "openglframework.h"
|
#include "openglframework.h"
|
||||||
#include "reactphysics3d.h"
|
#include "reactphysics3d.h"
|
||||||
#include "Box.h"
|
#include "Box.h"
|
||||||
#include "../common/Viewer.h"
|
#include "Scene.h"
|
||||||
|
|
||||||
|
namespace jointsscene {
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const openglframework::Vector3 BOX_SIZE(2, 2, 2); // Box dimensions in meters
|
const openglframework::Vector3 BOX_SIZE(2, 2, 2); // Box dimensions in meters
|
||||||
|
@ -40,16 +42,13 @@ const float FLOOR_MASS = 100.0f; // Floor mass in kil
|
||||||
const int NB_BALLSOCKETJOINT_BOXES = 7; // Number of Ball-And-Socket chain boxes
|
const int NB_BALLSOCKETJOINT_BOXES = 7; // Number of Ball-And-Socket chain boxes
|
||||||
const int NB_HINGE_BOXES = 7; // Number of Hinge chain boxes
|
const int NB_HINGE_BOXES = 7; // Number of Hinge chain boxes
|
||||||
|
|
||||||
// Class Scene
|
// Class JointsScene
|
||||||
class Scene {
|
class JointsScene : public Scene {
|
||||||
|
|
||||||
private :
|
protected :
|
||||||
|
|
||||||
// -------------------- Attributes -------------------- //
|
// -------------------- Attributes -------------------- //
|
||||||
|
|
||||||
/// Pointer to the viewer
|
|
||||||
Viewer* mViewer;
|
|
||||||
|
|
||||||
/// Light 0
|
/// Light 0
|
||||||
openglframework::Light mLight0;
|
openglframework::Light mLight0;
|
||||||
|
|
||||||
|
@ -101,9 +100,6 @@ class Scene {
|
||||||
/// Dynamics world used for the physics simulation
|
/// Dynamics world used for the physics simulation
|
||||||
rp3d::DynamicsWorld* mDynamicsWorld;
|
rp3d::DynamicsWorld* mDynamicsWorld;
|
||||||
|
|
||||||
/// True if the physics simulation is running
|
|
||||||
bool mIsRunning;
|
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Create the boxes and joints for the Ball-and-Socket joint example
|
/// Create the boxes and joints for the Ball-and-Socket joint example
|
||||||
|
@ -126,47 +122,21 @@ class Scene {
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
Scene(Viewer* viewer, const std::string& shaderFolderPath);
|
JointsScene(const std::string& name);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~Scene();
|
virtual ~JointsScene();
|
||||||
|
|
||||||
/// Take a step for the simulation
|
/// Take a step for the simulation
|
||||||
void simulate();
|
virtual void update();
|
||||||
|
|
||||||
/// Stop the simulation
|
|
||||||
void stopSimulation();
|
|
||||||
|
|
||||||
/// Start the simulation
|
|
||||||
void startSimulation();
|
|
||||||
|
|
||||||
/// Pause or continue simulation
|
|
||||||
void pauseContinueSimulation();
|
|
||||||
|
|
||||||
/// Render the scene
|
/// Render the scene
|
||||||
void render();
|
virtual void render();
|
||||||
|
|
||||||
|
/// Reset the scene
|
||||||
|
virtual void reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Stop the simulation
|
|
||||||
inline void Scene::stopSimulation() {
|
|
||||||
mDynamicsWorld->stop();
|
|
||||||
mIsRunning = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the simulation
|
|
||||||
inline void Scene::startSimulation() {
|
|
||||||
mDynamicsWorld->start();
|
|
||||||
mIsRunning = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pause or continue simulation
|
|
||||||
inline void Scene::pauseContinueSimulation() {
|
|
||||||
if (mIsRunning) {
|
|
||||||
stopSimulation();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
startSimulation();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -24,16 +24,18 @@
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "Scene.h"
|
#include "RaycastScene.h"
|
||||||
|
|
||||||
// Namespaces
|
// Namespaces
|
||||||
using namespace openglframework;
|
using namespace openglframework;
|
||||||
|
using namespace raycastscene;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath, const std::string& meshFolderPath)
|
RaycastScene::RaycastScene(const std::string& name)
|
||||||
: mViewer(viewer), mLight0(0), mCurrentBodyIndex(-1), mAreNormalsDisplayed(false),
|
: Scene(name), mLight0(0), mCurrentBodyIndex(-1), mAreNormalsDisplayed(false),
|
||||||
mPhongShader(shaderFolderPath + "phong.vert",
|
mPhongShader("shaders/phong.vert", "shaders/phong.frag") {
|
||||||
shaderFolderPath +"phong.frag") {
|
|
||||||
|
std::string meshFolderPath("meshes/");
|
||||||
|
|
||||||
// Move the light 0
|
// Move the light 0
|
||||||
mLight0.translateWorld(Vector3(50, 50, 50));
|
mLight0.translateWorld(Vector3(50, 50, 50));
|
||||||
|
@ -43,7 +45,7 @@ Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath, const std::str
|
||||||
openglframework::Vector3 center(0, 0, 0);
|
openglframework::Vector3 center(0, 0, 0);
|
||||||
|
|
||||||
// Set the center of the scene
|
// Set the center of the scene
|
||||||
mViewer->setScenePosition(center, radiusScene);
|
setScenePosition(center, radiusScene);
|
||||||
|
|
||||||
// Create the dynamics world for the physics simulation
|
// Create the dynamics world for the physics simulation
|
||||||
mCollisionWorld = new rp3d::CollisionWorld();
|
mCollisionWorld = new rp3d::CollisionWorld();
|
||||||
|
@ -105,7 +107,7 @@ Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath, const std::str
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the raycast lines
|
// Create the raycast lines
|
||||||
void Scene::createLines() {
|
void RaycastScene::createLines() {
|
||||||
|
|
||||||
int nbRaysOneDimension = std::sqrt(float(NB_RAYS));
|
int nbRaysOneDimension = std::sqrt(float(NB_RAYS));
|
||||||
|
|
||||||
|
@ -131,7 +133,7 @@ void Scene::createLines() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change the body to raycast and to display
|
// Change the body to raycast and to display
|
||||||
void Scene::changeBody() {
|
void RaycastScene::changeBody() {
|
||||||
|
|
||||||
mCurrentBodyIndex++;
|
mCurrentBodyIndex++;
|
||||||
if (mCurrentBodyIndex >= NB_BODIES) mCurrentBodyIndex = 0;
|
if (mCurrentBodyIndex >= NB_BODIES) mCurrentBodyIndex = 0;
|
||||||
|
@ -163,8 +165,13 @@ void Scene::changeBody() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset the scene
|
||||||
|
void RaycastScene::reset() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Scene::~Scene() {
|
RaycastScene::~RaycastScene() {
|
||||||
|
|
||||||
// Destroy the shader
|
// Destroy the shader
|
||||||
mPhongShader.destroy();
|
mPhongShader.destroy();
|
||||||
|
@ -221,7 +228,7 @@ Scene::~Scene() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take a step for the simulation
|
// Take a step for the simulation
|
||||||
void Scene::simulate() {
|
void RaycastScene::update() {
|
||||||
|
|
||||||
mRaycastManager.resetPoints();
|
mRaycastManager.resetPoints();
|
||||||
|
|
||||||
|
@ -246,15 +253,14 @@ void Scene::simulate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the scene
|
// Render the scene
|
||||||
void Scene::render() {
|
void RaycastScene::render() {
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
// Get the world-space to camera-space matrix
|
// Get the world-space to camera-space matrix
|
||||||
const Camera& camera = mViewer->getCamera();
|
const openglframework::Matrix4 worldToCameraMatrix = mCamera.getTransformMatrix().getInverse();
|
||||||
const openglframework::Matrix4 worldToCameraMatrix = camera.getTransformMatrix().getInverse();
|
|
||||||
|
|
||||||
// Bind the shader
|
// Bind the shader
|
||||||
mPhongShader.bind();
|
mPhongShader.bind();
|
||||||
|
@ -263,7 +269,7 @@ void Scene::render() {
|
||||||
mPhongShader.setVector4Uniform("vertexColor", grey);
|
mPhongShader.setVector4Uniform("vertexColor", grey);
|
||||||
|
|
||||||
// Set the variables of the shader
|
// Set the variables of the shader
|
||||||
mPhongShader.setMatrix4x4Uniform("projectionMatrix", camera.getProjectionMatrix());
|
mPhongShader.setMatrix4x4Uniform("projectionMatrix", mCamera.getProjectionMatrix());
|
||||||
mPhongShader.setVector3Uniform("light0PosCameraSpace", worldToCameraMatrix * mLight0.getOrigin());
|
mPhongShader.setVector3Uniform("light0PosCameraSpace", worldToCameraMatrix * mLight0.getOrigin());
|
||||||
mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f));
|
mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f));
|
||||||
const Color& diffColLight0 = mLight0.getDiffuseColor();
|
const Color& diffColLight0 = mLight0.getDiffuseColor();
|
|
@ -23,14 +23,15 @@
|
||||||
* *
|
* *
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
#ifndef SCENE_H
|
#ifndef RAYCAST_SCENE_H
|
||||||
#define SCENE_H
|
#define RAYCAST_SCENE_H
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#define _USE_MATH_DEFINES
|
#define _USE_MATH_DEFINES
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "openglframework.h"
|
#include "openglframework.h"
|
||||||
#include "reactphysics3d.h"
|
#include "reactphysics3d.h"
|
||||||
|
#include "Scene.h"
|
||||||
#include "Sphere.h"
|
#include "Sphere.h"
|
||||||
#include "Box.h"
|
#include "Box.h"
|
||||||
#include "Cone.h"
|
#include "Cone.h"
|
||||||
|
@ -42,6 +43,8 @@
|
||||||
#include "VisualContactPoint.h"
|
#include "VisualContactPoint.h"
|
||||||
#include "../common/Viewer.h"
|
#include "../common/Viewer.h"
|
||||||
|
|
||||||
|
namespace raycastscene {
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const openglframework::Vector3 BOX_SIZE(4, 2, 1);
|
const openglframework::Vector3 BOX_SIZE(4, 2, 1);
|
||||||
const float SPHERE_RADIUS = 3.0f;
|
const float SPHERE_RADIUS = 3.0f;
|
||||||
|
@ -122,16 +125,13 @@ class RaycastManager : public rp3d::RaycastCallback {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class Scene
|
// Class RaycastScene
|
||||||
class Scene {
|
class RaycastScene : public Scene {
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
// -------------------- Attributes -------------------- //
|
// -------------------- Attributes -------------------- //
|
||||||
|
|
||||||
/// Pointer to the viewer
|
|
||||||
Viewer* mViewer;
|
|
||||||
|
|
||||||
/// Raycast manager
|
/// Raycast manager
|
||||||
RaycastManager mRaycastManager;
|
RaycastManager mRaycastManager;
|
||||||
|
|
||||||
|
@ -172,17 +172,19 @@ class Scene {
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
Scene(Viewer* viewer, const std::string& shaderFolderPath,
|
RaycastScene(const std::string& name);
|
||||||
const std::string& meshFolderPath);
|
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~Scene();
|
virtual ~RaycastScene();
|
||||||
|
|
||||||
/// Take a step for the simulation
|
/// Take a step for the simulation
|
||||||
void simulate();
|
virtual void update();
|
||||||
|
|
||||||
/// Render the scene
|
/// Render the scene
|
||||||
void render();
|
virtual void render();
|
||||||
|
|
||||||
|
/// Reset the scene
|
||||||
|
virtual void reset();
|
||||||
|
|
||||||
/// Change the body to raycast
|
/// Change the body to raycast
|
||||||
void changeBody();
|
void changeBody();
|
||||||
|
@ -192,9 +194,10 @@ class Scene {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Display or not the surface normals at hit points
|
// Display or not the surface normals at hit points
|
||||||
inline void Scene::showHideNormals() {
|
inline void RaycastScene::showHideNormals() {
|
||||||
mAreNormalsDisplayed = !mAreNormalsDisplayed;
|
mAreNormalsDisplayed = !mAreNormalsDisplayed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -26,6 +26,16 @@
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "Gui.h"
|
#include "Gui.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Gui::Gui() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Gui::~Gui() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Display the GUI
|
// Display the GUI
|
||||||
void Gui::display() {
|
void Gui::display() {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
using namespace openglframework;
|
using namespace openglframework;
|
||||||
|
|
||||||
|
@ -33,6 +34,11 @@ Scene::Scene(const std::string& name) : mName(name) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Scene::~Scene() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Set the scene position (where the camera needs to look at)
|
// Set the scene position (where the camera needs to look at)
|
||||||
void Scene::setScenePosition(const openglframework::Vector3& position, float sceneRadius) {
|
void Scene::setScenePosition(const openglframework::Vector3& position, float sceneRadius) {
|
||||||
|
|
||||||
|
@ -59,15 +65,12 @@ void Scene::resetCameraToViewAll() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map the mouse x,y coordinates to a point on a sphere
|
// Map the mouse x,y coordinates to a point on a sphere
|
||||||
bool Scene::mapMouseCoordinatesToSphere(double xMouse, double yMouse, Vector3& spherePoint) const {
|
bool Scene::mapMouseCoordinatesToSphere(double xMouse, double yMouse,
|
||||||
|
Vector3& spherePoint) const {
|
||||||
|
|
||||||
// Get the window dimension
|
if ((xMouse >= 0) && (xMouse <= mWindowWidth) && (yMouse >= 0) && (yMouse <= mWindowHeight)) {
|
||||||
int width, height;
|
float x = float(xMouse - 0.5f * mWindowWidth) / float(mWindowWidth);
|
||||||
glfwGetWindowSize(mWindow, &width, &height);
|
float y = float(0.5f * mWindowHeight - yMouse) / float(mWindowHeight);
|
||||||
|
|
||||||
if ((xMouse >= 0) && (xMouse <= width) && (yMouse >= 0) && (yMouse <= height)) {
|
|
||||||
float x = float(xMouse - 0.5f * width) / float(width);
|
|
||||||
float y = float(0.5f * height - yMouse) / float(height);
|
|
||||||
float sinx = sin(PI * x * 0.5f);
|
float sinx = sin(PI * x * 0.5f);
|
||||||
float siny = sin(PI * y * 0.5f);
|
float siny = sin(PI * y * 0.5f);
|
||||||
float sinx2siny2 = sinx * sinx + siny * siny;
|
float sinx2siny2 = sinx * sinx + siny * siny;
|
||||||
|
@ -84,17 +87,14 @@ bool Scene::mapMouseCoordinatesToSphere(double xMouse, double yMouse, Vector3& s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when a mouse button event occurs
|
// Called when a mouse button event occurs
|
||||||
void Scene::mouseButtonEvent(int button, int action, int mods) {
|
void Scene::mouseButtonEvent(int button, int action, int mods,
|
||||||
|
double mousePosX, double mousePosY) {
|
||||||
// Get the mouse cursor position
|
|
||||||
double x, y;
|
|
||||||
glfwGetCursorPos(mWindow, &x, &y);
|
|
||||||
|
|
||||||
// If the mouse button is pressed
|
// If the mouse button is pressed
|
||||||
if (action == GLFW_PRESS) {
|
if (action == GLFW_PRESS) {
|
||||||
mLastMouseX = x;
|
mLastMouseX = mousePosX;
|
||||||
mLastMouseY = y;
|
mLastMouseY = mousePosY;
|
||||||
mIsLastPointOnSphereValid = mapMouseCoordinatesToSphere(x, y, mLastPointOnSphere);
|
mIsLastPointOnSphereValid = mapMouseCoordinatesToSphere(mousePosX, mousePosY, mLastPointOnSphere);
|
||||||
}
|
}
|
||||||
else { // If the mouse button is released
|
else { // If the mouse button is released
|
||||||
mIsLastPointOnSphereValid = false;
|
mIsLastPointOnSphereValid = false;
|
||||||
|
@ -102,22 +102,15 @@ void Scene::mouseButtonEvent(int button, int action, int mods) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when a mouse motion event occurs
|
// Called when a mouse motion event occurs
|
||||||
void Scene::mouseMotionEvent(double xMouse, double yMouse) {
|
void Scene::mouseMotionEvent(double xMouse, double yMouse, int leftButtonState,
|
||||||
|
int rightButtonState, int middleButtonState,
|
||||||
int leftButtonState = glfwGetMouseButton(mWindow, GLFW_MOUSE_BUTTON_LEFT);
|
int altKeyState) {
|
||||||
int rightButtonState = glfwGetMouseButton(mWindow, GLFW_MOUSE_BUTTON_RIGHT);
|
|
||||||
int middleButtonState = glfwGetMouseButton(mWindow, GLFW_MOUSE_BUTTON_MIDDLE);
|
|
||||||
int altKeyState = glfwGetKey(mWindow, GLFW_KEY_LEFT_ALT);
|
|
||||||
|
|
||||||
// Zoom
|
// Zoom
|
||||||
if (leftButtonState == GLFW_PRESS && altKeyState == GLFW_PRESS) {
|
if (leftButtonState == GLFW_PRESS && altKeyState == GLFW_PRESS) {
|
||||||
|
|
||||||
// Get the window dimension
|
|
||||||
int width, height;
|
|
||||||
glfwGetWindowSize(mWindow, &width, &height);
|
|
||||||
|
|
||||||
float dy = static_cast<float>(yMouse - mLastMouseY);
|
float dy = static_cast<float>(yMouse - mLastMouseY);
|
||||||
float h = static_cast<float>(height);
|
float h = static_cast<float>(mWindowHeight);
|
||||||
|
|
||||||
// Zoom the camera
|
// Zoom the camera
|
||||||
zoom(-dy / h);
|
zoom(-dy / h);
|
||||||
|
@ -139,8 +132,8 @@ void Scene::mouseMotionEvent(double xMouse, double yMouse) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when a scrolling event occurs
|
// Called when a scrolling event occurs
|
||||||
void Scene::scrollingEvent(float xAxis, float yAxis) {
|
void Scene::scrollingEvent(float xAxis, float yAxis, float scrollSensitivy) {
|
||||||
zoom(yAxis * SCROLL_SENSITIVITY);
|
zoom(yAxis * scrollSensitivy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zoom the camera
|
// Zoom the camera
|
|
@ -49,6 +49,9 @@ class Scene {
|
||||||
/// Last mouse coordinates on the windows
|
/// Last mouse coordinates on the windows
|
||||||
double mLastMouseX, mLastMouseY;
|
double mLastMouseX, mLastMouseY;
|
||||||
|
|
||||||
|
/// Window dimension
|
||||||
|
int mWindowWidth, mWindowHeight;
|
||||||
|
|
||||||
/// Last point computed on a sphere (for camera rotation)
|
/// Last point computed on a sphere (for camera rotation)
|
||||||
openglframework::Vector3 mLastPointOnSphere;
|
openglframework::Vector3 mLastPointOnSphere;
|
||||||
|
|
||||||
|
@ -87,9 +90,6 @@ class Scene {
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~Scene();
|
virtual ~Scene();
|
||||||
|
|
||||||
/// Initialize the scene
|
|
||||||
virtual void init()=0;
|
|
||||||
|
|
||||||
/// Reshape the view
|
/// Reshape the view
|
||||||
virtual void reshape(int width, int height);
|
virtual void reshape(int width, int height);
|
||||||
|
|
||||||
|
@ -106,13 +106,18 @@ class Scene {
|
||||||
virtual void keyboardEvent(int key, int scancode, int action, int mods);
|
virtual void keyboardEvent(int key, int scancode, int action, int mods);
|
||||||
|
|
||||||
/// Called when a mouse button event occurs
|
/// Called when a mouse button event occurs
|
||||||
virtual void mouseButtonEvent(int button, int action, int mods);
|
virtual void mouseButtonEvent(int button, int action, int mods,
|
||||||
|
double mousePosX, double mousePosY);
|
||||||
|
|
||||||
/// Called when a mouse motion event occurs
|
/// Called when a mouse motion event occurs
|
||||||
virtual void mouseMotionEvent(double xMouse, double yMouse);
|
virtual void mouseMotionEvent(double xMouse, double yMouse, int leftButtonState,
|
||||||
|
int rightButtonState, int middleButtonState, int altKeyState);
|
||||||
|
|
||||||
/// Called when a scrolling event occurs
|
/// Called when a scrolling event occurs
|
||||||
virtual void scrollingEvent(float xAxis, float yAxis);
|
virtual void scrollingEvent(float xAxis, float yAxis, float scrollSensitivy);
|
||||||
|
|
||||||
|
/// Set the window dimension
|
||||||
|
void setWindowDimension(int width, int height);
|
||||||
|
|
||||||
/// Return a reference to the camera
|
/// Return a reference to the camera
|
||||||
const openglframework::Camera& getCamera() const;
|
const openglframework::Camera& getCamera() const;
|
||||||
|
@ -133,5 +138,11 @@ inline const openglframework::Camera& Scene::getCamera() const {
|
||||||
return mCamera;
|
return mCamera;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the window dimension
|
||||||
|
inline void Scene::setWindowDimension(int width, int height) {
|
||||||
|
mWindowWidth = width;
|
||||||
|
mWindowHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -29,8 +29,16 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include "cubes/CubesScene.h"
|
||||||
|
#include "joints/JointsScene.h"
|
||||||
|
#include "collisionshapes/CollisionShapesScene.h"
|
||||||
|
#include "raycast/RaycastScene.h"
|
||||||
|
|
||||||
using namespace openglframework;
|
using namespace openglframework;
|
||||||
|
using namespace jointsscene;
|
||||||
|
using namespace cubesscene;
|
||||||
|
using namespace raycastscene;
|
||||||
|
using namespace collisionshapesscene;
|
||||||
|
|
||||||
// Initialization of static variables
|
// Initialization of static variables
|
||||||
const float TestbedApplication::SCROLL_SENSITIVITY = 0.02f;
|
const float TestbedApplication::SCROLL_SENSITIVITY = 0.02f;
|
||||||
|
@ -54,6 +62,9 @@ TestbedApplication::~TestbedApplication() {
|
||||||
|
|
||||||
// TODO : Check that this method is called at the end
|
// TODO : Check that this method is called at the end
|
||||||
|
|
||||||
|
// Destroy all the scenes
|
||||||
|
destroyScenes();
|
||||||
|
|
||||||
// Destroy the window
|
// Destroy the window
|
||||||
glfwDestroyWindow(mWindow);
|
glfwDestroyWindow(mWindow);
|
||||||
|
|
||||||
|
@ -110,6 +121,42 @@ void TestbedApplication::init() {
|
||||||
|
|
||||||
// Define the background color (black)
|
// Define the background color (black)
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||||
|
|
||||||
|
// Create all the scenes
|
||||||
|
createScenes();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create all the scenes
|
||||||
|
void TestbedApplication::createScenes() {
|
||||||
|
|
||||||
|
// Cubes scene
|
||||||
|
CubesScene* cubeScene = new CubesScene("Cubes");
|
||||||
|
mScenes.push_back(cubeScene);
|
||||||
|
|
||||||
|
// Joints scene
|
||||||
|
JointsScene* jointsScene = new JointsScene("Joints");
|
||||||
|
mScenes.push_back(jointsScene);
|
||||||
|
|
||||||
|
// Collision shapes scene
|
||||||
|
CollisionShapesScene* collisionShapesScene = new CollisionShapesScene("Collision Shapes");
|
||||||
|
mScenes.push_back(collisionShapesScene);
|
||||||
|
|
||||||
|
// Raycast scene
|
||||||
|
RaycastScene* raycastScene = new RaycastScene("Raycast");
|
||||||
|
mScenes.push_back(raycastScene);
|
||||||
|
|
||||||
|
assert(mScenes.size() > 0);
|
||||||
|
mCurrentScene = mScenes[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove all the scenes
|
||||||
|
void TestbedApplication::destroyScenes() {
|
||||||
|
|
||||||
|
for (int i=0; i<mScenes.size(); i++) {
|
||||||
|
delete mScenes[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
mCurrentScene = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestbedApplication::update() {
|
void TestbedApplication::update() {
|
||||||
|
@ -141,10 +188,16 @@ void TestbedApplication::reshape() {
|
||||||
int width, height;
|
int width, height;
|
||||||
glfwGetFramebufferSize(mWindow, &width, &height);
|
glfwGetFramebufferSize(mWindow, &width, &height);
|
||||||
|
|
||||||
// Resize the camera viewport of the current scene
|
// Resize the camera viewport
|
||||||
mCurrentScene->reshape(width, height);
|
mCurrentScene->reshape(width, height);
|
||||||
|
|
||||||
|
// Resize the OpenGL viewport
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
|
|
||||||
|
// Update the window size of the scene
|
||||||
|
int windowWidth, windowHeight;
|
||||||
|
glfwGetWindowSize(mWindow, &windowWidth, &windowHeight);
|
||||||
|
mCurrentScene->setWindowDimension(windowWidth, windowHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the main loop where rendering occur
|
// Start the main loop where rendering occur
|
||||||
|
@ -159,6 +212,9 @@ void TestbedApplication::startMainLoop() {
|
||||||
// Call the update function
|
// Call the update function
|
||||||
update();
|
update();
|
||||||
|
|
||||||
|
// Render the application
|
||||||
|
render();
|
||||||
|
|
||||||
// Swap front and back buffers
|
// Swap front and back buffers
|
||||||
glfwSwapBuffers(mWindow);
|
glfwSwapBuffers(mWindow);
|
||||||
|
|
||||||
|
@ -249,15 +305,27 @@ void TestbedApplication::keyboard(GLFWwindow* window, int key, int scancode,
|
||||||
|
|
||||||
// Callback method to receive scrolling events
|
// Callback method to receive scrolling events
|
||||||
void TestbedApplication::scroll(GLFWwindow* window, double xAxis, double yAxis) {
|
void TestbedApplication::scroll(GLFWwindow* window, double xAxis, double yAxis) {
|
||||||
getInstance().mCurrentScene->scrollingEvent(xAxis, yAxis);
|
getInstance().mCurrentScene->scrollingEvent(xAxis, yAxis, SCROLL_SENSITIVITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when a mouse button event occurs
|
// Called when a mouse button event occurs
|
||||||
void TestbedApplication::mouseButton(GLFWwindow* window, int button, int action, int mods) {
|
void TestbedApplication::mouseButton(GLFWwindow* window, int button, int action, int mods) {
|
||||||
getInstance().mCurrentScene->mouseButtonEvent(button, action, mods);
|
|
||||||
|
// Get the mouse cursor position
|
||||||
|
double x, y;
|
||||||
|
glfwGetCursorPos(window, &x, &y);
|
||||||
|
|
||||||
|
getInstance().mCurrentScene->mouseButtonEvent(button, action, mods, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when a mouse motion event occurs
|
// Called when a mouse motion event occurs
|
||||||
void TestbedApplication::mouseMotion(GLFWwindow* window, double x, double y) {
|
void TestbedApplication::mouseMotion(GLFWwindow* window, double x, double y) {
|
||||||
getInstance().mCurrentScene->mouseMotionEvent(x, y);
|
|
||||||
|
int leftButtonState = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT);
|
||||||
|
int rightButtonState = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT);
|
||||||
|
int middleButtonState = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_MIDDLE);
|
||||||
|
int altKeyState = glfwGetKey(window, GLFW_KEY_LEFT_ALT);
|
||||||
|
|
||||||
|
getInstance().mCurrentScene->mouseMotionEvent(x, y, leftButtonState, rightButtonState,
|
||||||
|
middleButtonState, altKeyState);
|
||||||
}
|
}
|
|
@ -121,6 +121,12 @@ class TestbedApplication {
|
||||||
/// Called when a mouse motion event occurs
|
/// Called when a mouse motion event occurs
|
||||||
static void mouseMotion(GLFWwindow* window, double x, double y);
|
static void mouseMotion(GLFWwindow* window, double x, double y);
|
||||||
|
|
||||||
|
/// Initialize all the scenes
|
||||||
|
void createScenes();
|
||||||
|
|
||||||
|
/// Remove all the scenes
|
||||||
|
void destroyScenes() ;
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
@ -131,7 +137,7 @@ class TestbedApplication {
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~TestbedApplication();
|
~TestbedApplication();
|
||||||
|
|
||||||
/// Initialize the viewer
|
/// Initialize the application
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
/// Start the main loop where rendering occur
|
/// Start the main loop where rendering occur
|
Loading…
Reference in New Issue
Block a user