2015-04-08 18:47:55 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* ReactPhysics3D physics library, http://www.reactphysics3d.com *
|
2016-04-11 18:15:20 +00:00
|
|
|
* Copyright (c) 2010-2016 Daniel Chappuis *
|
2015-04-08 18:47:55 +00:00
|
|
|
*********************************************************************************
|
|
|
|
* *
|
|
|
|
* 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
|
2015-04-15 21:11:27 +00:00
|
|
|
#include "RaycastScene.h"
|
2015-04-08 18:47:55 +00:00
|
|
|
|
|
|
|
// Namespaces
|
|
|
|
using namespace openglframework;
|
2015-04-15 21:11:27 +00:00
|
|
|
using namespace raycastscene;
|
2015-04-08 18:47:55 +00:00
|
|
|
|
|
|
|
// Constructor
|
2017-11-02 21:58:41 +00:00
|
|
|
RaycastScene::RaycastScene(const std::string& name, EngineSettings& settings)
|
|
|
|
: SceneDemo(name, settings, SCENE_RADIUS, false), mMeshFolderPath("meshes/"),
|
2015-12-02 21:25:52 +00:00
|
|
|
mRaycastManager(mPhongShader, mMeshFolderPath), mCurrentBodyIndex(-1),
|
|
|
|
mAreNormalsDisplayed(false), mVBOVertices(GL_ARRAY_BUFFER) {
|
2015-04-08 18:47:55 +00:00
|
|
|
|
2015-08-11 16:32:45 +00:00
|
|
|
mIsContactPointsDisplayed = true;
|
|
|
|
|
2015-04-08 18:47:55 +00:00
|
|
|
// Compute the radius and the center of the scene
|
|
|
|
openglframework::Vector3 center(0, 0, 0);
|
|
|
|
|
|
|
|
// Set the center of the scene
|
2015-07-29 16:15:20 +00:00
|
|
|
setScenePosition(center, SCENE_RADIUS);
|
2015-04-08 18:47:55 +00:00
|
|
|
|
2018-03-15 22:11:26 +00:00
|
|
|
rp3d::WorldSettings worldSettings;
|
|
|
|
worldSettings.worldName = name;
|
|
|
|
|
2015-04-08 18:47:55 +00:00
|
|
|
// Create the dynamics world for the physics simulation
|
2018-03-15 22:11:26 +00:00
|
|
|
mPhysicsWorld = new rp3d::CollisionWorld(worldSettings);
|
2017-11-10 18:57:50 +00:00
|
|
|
|
2015-04-08 18:47:55 +00:00
|
|
|
// ---------- Dumbbell ---------- //
|
|
|
|
|
|
|
|
// Create a convex mesh and a corresponding collision body in the dynamics world
|
2017-11-02 21:58:41 +00:00
|
|
|
mDumbbell = new Dumbbell(mPhysicsWorld, mMeshFolderPath);
|
2015-04-08 18:47:55 +00:00
|
|
|
|
2015-08-08 09:40:37 +00:00
|
|
|
// Set the box color
|
|
|
|
mDumbbell->setColor(mGreyColorDemo);
|
|
|
|
mDumbbell->setSleepingColor(mRedColorDemo);
|
2017-10-19 15:42:21 +00:00
|
|
|
mPhysicsObjects.push_back(mDumbbell);
|
2015-08-08 09:40:37 +00:00
|
|
|
|
2015-04-08 18:47:55 +00:00
|
|
|
// ---------- Box ---------- //
|
|
|
|
|
|
|
|
// Create a box and a corresponding collision body in the dynamics world
|
2017-11-02 21:58:41 +00:00
|
|
|
mBox = new Box(BOX_SIZE, mPhysicsWorld, mMeshFolderPath);
|
2015-04-08 18:47:55 +00:00
|
|
|
mBox->getCollisionBody()->setIsActive(false);
|
|
|
|
|
2015-08-08 09:40:37 +00:00
|
|
|
// Set the box color
|
|
|
|
mBox->setColor(mGreyColorDemo);
|
|
|
|
mBox->setSleepingColor(mRedColorDemo);
|
2017-10-19 15:42:21 +00:00
|
|
|
mPhysicsObjects.push_back(mBox);
|
2015-08-08 09:40:37 +00:00
|
|
|
|
2015-04-08 18:47:55 +00:00
|
|
|
// ---------- Sphere ---------- //
|
|
|
|
|
|
|
|
// Create a sphere and a corresponding collision body in the dynamics world
|
2017-11-02 21:58:41 +00:00
|
|
|
mSphere = new Sphere(SPHERE_RADIUS, mPhysicsWorld, mMeshFolderPath);
|
2015-04-08 18:47:55 +00:00
|
|
|
|
2015-08-08 09:40:37 +00:00
|
|
|
// Set the color
|
|
|
|
mSphere->setColor(mGreyColorDemo);
|
|
|
|
mSphere->setSleepingColor(mRedColorDemo);
|
2017-10-19 15:42:21 +00:00
|
|
|
mPhysicsObjects.push_back(mSphere);
|
2015-08-08 09:40:37 +00:00
|
|
|
|
2015-04-08 18:47:55 +00:00
|
|
|
// ---------- Capsule ---------- //
|
|
|
|
openglframework::Vector3 position6(0, 0, 0);
|
|
|
|
|
|
|
|
// Create a cylinder and a corresponding collision body in the dynamics world
|
2017-11-02 21:58:41 +00:00
|
|
|
mCapsule = new Capsule(CAPSULE_RADIUS, CAPSULE_HEIGHT, mPhysicsWorld, mMeshFolderPath);
|
2015-04-08 18:47:55 +00:00
|
|
|
|
2015-08-08 09:40:37 +00:00
|
|
|
// Set the color
|
|
|
|
mCapsule->setColor(mGreyColorDemo);
|
|
|
|
mCapsule->setSleepingColor(mRedColorDemo);
|
2017-10-19 15:42:21 +00:00
|
|
|
mPhysicsObjects.push_back(mCapsule);
|
2015-08-08 09:40:37 +00:00
|
|
|
|
2015-04-08 18:47:55 +00:00
|
|
|
// ---------- Convex Mesh ---------- //
|
|
|
|
|
|
|
|
// Create a convex mesh and a corresponding collision body in the dynamics world
|
2017-11-02 21:58:41 +00:00
|
|
|
mConvexMesh = new ConvexMesh(mPhysicsWorld, mMeshFolderPath + "convexmesh.obj");
|
2015-04-08 18:47:55 +00:00
|
|
|
|
2015-08-08 09:40:37 +00:00
|
|
|
// Set the color
|
|
|
|
mConvexMesh->setColor(mGreyColorDemo);
|
|
|
|
mConvexMesh->setSleepingColor(mRedColorDemo);
|
2017-10-19 15:42:21 +00:00
|
|
|
mPhysicsObjects.push_back(mConvexMesh);
|
2015-08-08 09:40:37 +00:00
|
|
|
|
2015-12-02 21:25:52 +00:00
|
|
|
// ---------- Concave Mesh ---------- //
|
|
|
|
|
|
|
|
// Create a convex mesh and a corresponding collision body in the dynamics world
|
2017-11-02 21:58:41 +00:00
|
|
|
mConcaveMesh = new ConcaveMesh(mPhysicsWorld, mMeshFolderPath + "city.obj");
|
2015-12-02 21:25:52 +00:00
|
|
|
|
|
|
|
// Set the color
|
|
|
|
mConcaveMesh->setColor(mGreyColorDemo);
|
|
|
|
mConcaveMesh->setSleepingColor(mRedColorDemo);
|
2017-10-19 15:42:21 +00:00
|
|
|
mPhysicsObjects.push_back(mConcaveMesh);
|
2015-12-02 21:25:52 +00:00
|
|
|
|
2016-02-08 21:27:11 +00:00
|
|
|
// ---------- Heightfield ---------- //
|
|
|
|
|
|
|
|
// Create a convex mesh and a corresponding collision body in the dynamics world
|
2017-11-02 21:58:41 +00:00
|
|
|
mHeightField = new HeightField(mPhysicsWorld);
|
2016-02-08 21:27:11 +00:00
|
|
|
|
|
|
|
// Set the color
|
|
|
|
mHeightField->setColor(mGreyColorDemo);
|
|
|
|
mHeightField->setSleepingColor(mRedColorDemo);
|
2017-10-19 15:42:21 +00:00
|
|
|
mPhysicsObjects.push_back(mHeightField);
|
2016-02-08 21:27:11 +00:00
|
|
|
|
2015-04-08 18:47:55 +00:00
|
|
|
// Create the lines that will be used for raycasting
|
|
|
|
createLines();
|
|
|
|
|
2015-06-25 20:28:11 +00:00
|
|
|
// Create the VBO and VAO to render the lines
|
2017-05-17 21:40:17 +00:00
|
|
|
createVBOAndVAO();
|
2015-06-25 20:28:11 +00:00
|
|
|
|
2015-04-08 18:47:55 +00:00
|
|
|
changeBody();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the raycast lines
|
2015-04-15 21:11:27 +00:00
|
|
|
void RaycastScene::createLines() {
|
2015-04-08 18:47:55 +00:00
|
|
|
|
2017-11-02 21:58:41 +00:00
|
|
|
int nbRaysOneDimension = static_cast<int>(std::sqrt(float(NB_RAYS)));
|
2015-04-08 18:47:55 +00:00
|
|
|
|
|
|
|
for (int i=0; i<nbRaysOneDimension; i++) {
|
|
|
|
for (int j=0; j<nbRaysOneDimension; j++) {
|
|
|
|
|
2015-08-13 17:47:29 +00:00
|
|
|
float theta = i * 2.0f * PI / float(nbRaysOneDimension);
|
|
|
|
float phi = j * PI / float(nbRaysOneDimension);
|
2015-04-08 18:47:55 +00:00
|
|
|
|
|
|
|
// Generate a point on a sphere with spherical coordinates
|
|
|
|
float x = RAY_LENGTH * std::sin(phi) * std::cos(theta);
|
|
|
|
float y = RAY_LENGTH * std::sin(phi) * std::sin(theta);
|
|
|
|
float z = RAY_LENGTH * std::cos(phi);
|
|
|
|
|
|
|
|
// Create a line from the point on the sphere to the center of
|
|
|
|
// the scene
|
|
|
|
openglframework::Vector3 point1(x, y, z);
|
|
|
|
openglframework::Vector3 point2(0.0f, 0.0f, 0.0f);
|
|
|
|
Line* line = new Line(point1, point2);
|
|
|
|
mLines.push_back(line);
|
2015-06-25 20:28:11 +00:00
|
|
|
|
|
|
|
mLinePoints.push_back(point1);
|
|
|
|
mLinePoints.push_back(point2);
|
2015-04-08 18:47:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change the body to raycast and to display
|
2015-04-15 21:11:27 +00:00
|
|
|
void RaycastScene::changeBody() {
|
2015-04-08 18:47:55 +00:00
|
|
|
|
|
|
|
mCurrentBodyIndex++;
|
|
|
|
if (mCurrentBodyIndex >= NB_BODIES) mCurrentBodyIndex = 0;
|
|
|
|
|
|
|
|
mSphere->getCollisionBody()->setIsActive(false);
|
|
|
|
mBox->getCollisionBody()->setIsActive(false);
|
|
|
|
mCapsule->getCollisionBody()->setIsActive(false);
|
|
|
|
mConvexMesh->getCollisionBody()->setIsActive(false);
|
|
|
|
mDumbbell->getCollisionBody()->setIsActive(false);
|
2015-12-02 21:25:52 +00:00
|
|
|
mConcaveMesh->getCollisionBody()->setIsActive(false);
|
2016-02-08 21:27:11 +00:00
|
|
|
mHeightField->getCollisionBody()->setIsActive(false);
|
2015-04-08 18:47:55 +00:00
|
|
|
|
|
|
|
switch(mCurrentBodyIndex) {
|
|
|
|
case 0: mSphere->getCollisionBody()->setIsActive(true);
|
|
|
|
break;
|
|
|
|
case 1: mBox->getCollisionBody()->setIsActive(true);
|
|
|
|
break;
|
2017-02-02 21:58:40 +00:00
|
|
|
case 2: mCapsule->getCollisionBody()->setIsActive(true);
|
2015-04-08 18:47:55 +00:00
|
|
|
break;
|
2017-02-02 21:58:40 +00:00
|
|
|
case 3: mConvexMesh->getCollisionBody()->setIsActive(true);
|
2015-04-08 18:47:55 +00:00
|
|
|
break;
|
2017-02-02 21:58:40 +00:00
|
|
|
case 4: mDumbbell->getCollisionBody()->setIsActive(true);
|
2015-04-08 18:47:55 +00:00
|
|
|
break;
|
2017-02-02 21:58:40 +00:00
|
|
|
case 5: mConcaveMesh->getCollisionBody()->setIsActive(true);
|
2015-04-08 18:47:55 +00:00
|
|
|
break;
|
2017-02-02 21:58:40 +00:00
|
|
|
case 6: mHeightField->getCollisionBody()->setIsActive(true);
|
2016-02-08 21:27:11 +00:00
|
|
|
break;
|
2015-04-08 18:47:55 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-15 21:11:27 +00:00
|
|
|
// Reset the scene
|
|
|
|
void RaycastScene::reset() {
|
|
|
|
|
2017-11-02 21:58:41 +00:00
|
|
|
std::vector<PhysicsObject*>::iterator it;
|
|
|
|
for (it = mPhysicsObjects.begin(); it != mPhysicsObjects.end(); ++it) {
|
|
|
|
(*it)->setTransform(rp3d::Transform(rp3d::Vector3::zero(), rp3d::Quaternion::identity()));
|
|
|
|
}
|
2015-04-15 21:11:27 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 18:47:55 +00:00
|
|
|
// Destructor
|
2015-04-15 21:11:27 +00:00
|
|
|
RaycastScene::~RaycastScene() {
|
2015-04-08 18:47:55 +00:00
|
|
|
|
|
|
|
// Destroy the box rigid body from the dynamics world
|
2017-11-02 21:58:41 +00:00
|
|
|
mPhysicsWorld->destroyCollisionBody(mBox->getCollisionBody());
|
2015-04-08 18:47:55 +00:00
|
|
|
delete mBox;
|
|
|
|
|
|
|
|
// Destroy the sphere
|
2017-11-02 21:58:41 +00:00
|
|
|
mPhysicsWorld->destroyCollisionBody(mSphere->getCollisionBody());
|
2015-04-08 18:47:55 +00:00
|
|
|
delete mSphere;
|
|
|
|
|
|
|
|
// Destroy the corresponding rigid body from the dynamics world
|
2017-11-02 21:58:41 +00:00
|
|
|
mPhysicsWorld->destroyCollisionBody(mCapsule->getCollisionBody());
|
2015-04-08 18:47:55 +00:00
|
|
|
|
|
|
|
// Destroy the sphere
|
|
|
|
delete mCapsule;
|
|
|
|
|
|
|
|
// Destroy the corresponding rigid body from the dynamics world
|
2017-11-02 21:58:41 +00:00
|
|
|
mPhysicsWorld->destroyCollisionBody(mConvexMesh->getCollisionBody());
|
2015-04-08 18:47:55 +00:00
|
|
|
|
|
|
|
// Destroy the convex mesh
|
|
|
|
delete mConvexMesh;
|
|
|
|
|
|
|
|
// Destroy the corresponding rigid body from the dynamics world
|
2017-11-02 21:58:41 +00:00
|
|
|
mPhysicsWorld->destroyCollisionBody(mDumbbell->getCollisionBody());
|
2015-04-08 18:47:55 +00:00
|
|
|
|
2015-12-02 21:25:52 +00:00
|
|
|
// Destroy the dumbbell
|
2015-04-08 18:47:55 +00:00
|
|
|
delete mDumbbell;
|
|
|
|
|
2015-12-02 21:25:52 +00:00
|
|
|
// Destroy the corresponding rigid body from the dynamics world
|
2017-11-02 21:58:41 +00:00
|
|
|
mPhysicsWorld->destroyCollisionBody(mConcaveMesh->getCollisionBody());
|
2015-12-02 21:25:52 +00:00
|
|
|
|
|
|
|
// Destroy the convex mesh
|
|
|
|
delete mConcaveMesh;
|
|
|
|
|
2016-02-08 21:27:11 +00:00
|
|
|
// Destroy the corresponding rigid body from the dynamics world
|
2017-11-02 21:58:41 +00:00
|
|
|
mPhysicsWorld->destroyCollisionBody(mHeightField->getCollisionBody());
|
2016-02-08 21:27:11 +00:00
|
|
|
|
|
|
|
// Destroy the convex mesh
|
|
|
|
delete mHeightField;
|
|
|
|
|
2015-04-08 18:47:55 +00:00
|
|
|
mRaycastManager.resetPoints();
|
|
|
|
|
|
|
|
// Destroy the static data for the visual contact points
|
|
|
|
VisualContactPoint::destroyStaticData();
|
|
|
|
|
|
|
|
// Destroy the collision world
|
2017-11-02 21:58:41 +00:00
|
|
|
delete mPhysicsWorld;
|
2015-04-08 18:47:55 +00:00
|
|
|
|
|
|
|
// Destroy the lines
|
|
|
|
for (std::vector<Line*>::iterator it = mLines.begin(); it != mLines.end();
|
|
|
|
++it) {
|
|
|
|
delete (*it);
|
|
|
|
}
|
2015-06-25 20:28:11 +00:00
|
|
|
|
|
|
|
// Destroy the VBOs and VAO
|
|
|
|
mVBOVertices.destroy();
|
|
|
|
mVAO.destroy();
|
2015-04-08 18:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Take a step for the simulation
|
2015-04-15 21:11:27 +00:00
|
|
|
void RaycastScene::update() {
|
2015-04-08 18:47:55 +00:00
|
|
|
|
|
|
|
mRaycastManager.resetPoints();
|
|
|
|
|
|
|
|
// For each line of the scene
|
|
|
|
for (std::vector<Line*>::iterator it = mLines.begin(); it != mLines.end();
|
|
|
|
++it) {
|
|
|
|
|
|
|
|
Line* line = *it;
|
|
|
|
|
|
|
|
// Create a ray corresponding to the line
|
|
|
|
openglframework::Vector3 p1 = line->getPoint1();
|
|
|
|
openglframework::Vector3 p2 = line->getPoint2();
|
|
|
|
|
|
|
|
rp3d::Vector3 point1(p1.x, p1.y, p1.z);
|
|
|
|
rp3d::Vector3 point2(p2.x, p2.y, p2.z);
|
|
|
|
rp3d::Ray ray(point1, point2);
|
|
|
|
|
|
|
|
// Perform a raycast query on the physics world by passing a raycast
|
|
|
|
// callback class in argument.
|
2017-11-02 21:58:41 +00:00
|
|
|
mPhysicsWorld->raycast(ray, &mRaycastManager);
|
2015-04-08 18:47:55 +00:00
|
|
|
}
|
2015-08-11 16:32:45 +00:00
|
|
|
|
|
|
|
SceneDemo::update();
|
2015-04-08 18:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Render the scene
|
2017-05-17 21:40:17 +00:00
|
|
|
void RaycastScene::renderSinglePass(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix) {
|
2015-04-08 18:47:55 +00:00
|
|
|
|
2015-08-11 19:40:07 +00:00
|
|
|
// Bind the VAO
|
|
|
|
mVAO.bind();
|
|
|
|
|
2015-04-08 18:47:55 +00:00
|
|
|
// Bind the shader
|
2017-05-17 21:40:17 +00:00
|
|
|
mColorShader.bind();
|
2015-06-25 20:28:11 +00:00
|
|
|
|
2015-08-11 19:40:07 +00:00
|
|
|
mVBOVertices.bind();
|
|
|
|
|
2015-06-25 20:28:11 +00:00
|
|
|
// Set the model to camera matrix
|
2015-07-29 16:15:20 +00:00
|
|
|
const Matrix4 localToCameraMatrix = Matrix4::identity();
|
2017-05-17 21:40:17 +00:00
|
|
|
mColorShader.setMatrix4x4Uniform("localToWorldMatrix", localToCameraMatrix);
|
|
|
|
mColorShader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
|
2015-06-25 20:28:11 +00:00
|
|
|
|
|
|
|
// Set the vertex color
|
2017-11-02 21:58:41 +00:00
|
|
|
openglframework::Vector4 color(1, 0.55f, 0, 1);
|
2017-05-17 21:40:17 +00:00
|
|
|
mColorShader.setVector4Uniform("vertexColor", color, false);
|
2015-06-25 20:28:11 +00:00
|
|
|
|
2015-08-11 19:40:07 +00:00
|
|
|
// Get the location of shader attribute variables
|
2017-05-17 21:40:17 +00:00
|
|
|
GLint vertexPositionLoc = mColorShader.getAttribLocation("vertexPosition");
|
2015-08-11 19:40:07 +00:00
|
|
|
|
|
|
|
glEnableVertexAttribArray(vertexPositionLoc);
|
|
|
|
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
|
2015-06-25 20:28:11 +00:00
|
|
|
|
|
|
|
// Draw the lines
|
2017-05-17 21:40:17 +00:00
|
|
|
glDrawArrays(GL_LINES, 0, mLinePoints.size() * 2);
|
2015-06-25 20:28:11 +00:00
|
|
|
|
2015-08-11 19:40:07 +00:00
|
|
|
glDisableVertexAttribArray(vertexPositionLoc);
|
|
|
|
|
|
|
|
mVBOVertices.unbind();
|
|
|
|
|
2015-06-25 20:28:11 +00:00
|
|
|
// Unbind the VAO
|
|
|
|
mVAO.unbind();
|
|
|
|
|
2017-05-17 21:40:17 +00:00
|
|
|
mColorShader.unbind();
|
2015-04-08 18:47:55 +00:00
|
|
|
|
2017-10-19 15:42:21 +00:00
|
|
|
// Bind the shader
|
|
|
|
shader.bind();
|
|
|
|
|
|
|
|
// Render all the physics objects of the scene
|
|
|
|
for (std::vector<PhysicsObject*>::iterator it = mPhysicsObjects.begin(); it != mPhysicsObjects.end(); ++it) {
|
|
|
|
if ((*it)->getCollisionBody()->isActive()) {
|
2017-11-02 21:58:41 +00:00
|
|
|
(*it)->render(shader, worldToCameraMatrix);
|
2017-10-19 15:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unbind the shader
|
|
|
|
shader.unbind();
|
2015-04-08 18:47:55 +00:00
|
|
|
}
|
2015-06-25 20:28:11 +00:00
|
|
|
|
|
|
|
// Create the Vertex Buffer Objects used to render with OpenGL.
|
|
|
|
/// We create two VBOs (one for vertices and one for indices)
|
2017-05-17 21:40:17 +00:00
|
|
|
void RaycastScene::createVBOAndVAO() {
|
2015-06-25 20:28:11 +00:00
|
|
|
|
|
|
|
// Create the VBO for the vertices data
|
|
|
|
mVBOVertices.create();
|
|
|
|
mVBOVertices.bind();
|
|
|
|
size_t sizeVertices = mLinePoints.size() * sizeof(openglframework::Vector3);
|
|
|
|
mVBOVertices.copyDataIntoVBO(sizeVertices, &mLinePoints[0], GL_STATIC_DRAW);
|
|
|
|
mVBOVertices.unbind();
|
|
|
|
|
|
|
|
// Create the VAO for both VBOs
|
|
|
|
mVAO.create();
|
|
|
|
mVAO.bind();
|
|
|
|
|
|
|
|
// Bind the VBO of vertices
|
|
|
|
mVBOVertices.bind();
|
|
|
|
|
|
|
|
// Unbind the VAO
|
|
|
|
mVAO.unbind();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called when a keyboard event occurs
|
2016-02-22 17:44:29 +00:00
|
|
|
bool RaycastScene::keyboardEvent(int key, int scancode, int action, int mods) {
|
2015-06-25 20:28:11 +00:00
|
|
|
|
|
|
|
// If the space key has been pressed
|
|
|
|
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) {
|
|
|
|
changeBody();
|
2016-02-22 17:44:29 +00:00
|
|
|
return true;
|
2015-06-25 20:28:11 +00:00
|
|
|
}
|
2016-02-22 17:44:29 +00:00
|
|
|
|
|
|
|
return false;
|
2015-06-25 20:28:11 +00:00
|
|
|
}
|