Modify examples

This commit is contained in:
Daniel Chappuis 2014-07-03 23:09:08 +02:00
parent a983026094
commit 4f141b87fb
5 changed files with 18 additions and 11 deletions

View File

@ -46,7 +46,7 @@ Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath, const std::str
mViewer->setScenePosition(center, radiusScene);
// Gravity vector in the dynamics world
rp3d::Vector3 gravity(0, rp3d::decimal(-9.81), 0);
rp3d::Vector3 gravity(0, -9.81, 0);
// Time step for the physics simulation
rp3d::decimal timeStep = 1.0f / 60.0f;
@ -67,7 +67,7 @@ Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath, const std::str
// Position
float angle = i * 30.0f;
openglframework::Vector3 position(radius * cos(angle),
80 + i * (DUMBBELL_HEIGHT + 0.3f),
100 + i * (DUMBBELL_HEIGHT + 0.3f),
radius * sin(angle));
// Create a convex mesh and a corresponding rigid in the dynamics world

View File

@ -41,12 +41,12 @@
// Constants
const int NB_BOXES = 2;
const int NB_SPHERES = 3;
const int NB_CONES = 1;
const int NB_SPHERES = 1;
const int NB_CONES = 3;
const int NB_CYLINDERS = 2;
const int NB_CAPSULES = 1;
const int NB_MESHES = 3;
const int NB_COMPOUND_SHAPES = 1;
const int NB_MESHES = 2;
const int NB_COMPOUND_SHAPES = 2;
const openglframework::Vector3 BOX_SIZE(2, 2, 2);
const float SPHERE_RADIUS = 1.5f;
const float CONE_RADIUS = 2.0f;

View File

@ -61,7 +61,7 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
// Initial position and orientation of the rigid body
rp3d::Vector3 initPosition(position.x, position.y, position.z);
rp3d::decimal angleAroundX = rp3d::PI / 4;
rp3d::decimal angleAroundX = 0;//rp3d::PI / 2;
rp3d::Quaternion initOrientation(angleAroundX, 0, 0);
rp3d::Transform transformBody(initPosition, initOrientation);
@ -78,8 +78,8 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
mRigidBody = dynamicsWorld->createRigidBody(transformBody);
// Add the three collision shapes to the body and specify the mass and transform of the shapes
mRigidBody->addCollisionShape(sphereCollisionShape, 1, transformSphereShape1);
mRigidBody->addCollisionShape(sphereCollisionShape, 4, transformSphereShape2);
mRigidBody->addCollisionShape(sphereCollisionShape, massSphere, transformSphereShape1);
mRigidBody->addCollisionShape(sphereCollisionShape, massSphere, transformSphereShape2);
mRigidBody->addCollisionShape(cylinderCollisionShape, massCylinder, transformCylinderShape);
}

View File

@ -46,7 +46,7 @@ Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath)
mViewer->setScenePosition(center, radiusScene);
// Gravity vector in the dynamics world
rp3d::Vector3 gravity(0, rp3d::decimal(-9.81), 0);
rp3d::Vector3 gravity(0, rp3d::decimal(-5.81), 0);
// Time step for the physics simulation
rp3d::decimal timeStep = 1.0f / 60.0f;
@ -92,6 +92,8 @@ Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath)
// Start the simulation
startSimulation();
counter=0;
}
// Destructor
@ -129,6 +131,9 @@ void Scene::simulate() {
// If the physics simulation is running
if (mIsRunning) {
counter++;
if (counter == 800) mIsRunning = false;
// Take a simulation step
mDynamicsWorld->update();

View File

@ -33,7 +33,7 @@
#include "Viewer.h"
// Constants
const int NB_SPHERES = 20; // Number of boxes in the scene
const int NB_SPHERES = 200; // Number of boxes in the scene
const openglframework::Vector3 BOX_SIZE(2, 2, 2); // Box dimensions in meters
const openglframework::Vector3 FLOOR_SIZE(50, 0.5f, 50); // Floor dimensions in meters
const float BOX_MASS = 1.0f; // Box mass in kilograms
@ -46,6 +46,8 @@ class Scene {
// -------------------- Attributes -------------------- //
int counter;
/// Pointer to the viewer
Viewer* mViewer;