Modifications of the examples
This commit is contained in:
parent
501b0747d3
commit
84d946ac48
|
@ -6,7 +6,7 @@
|
|||
* 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: *
|
||||
|
@ -24,10 +24,10 @@
|
|||
********************************************************************************/
|
||||
|
||||
// Uniform variables
|
||||
uniform vec3 lightPosCameraSpace; // Camera-space position of the light
|
||||
uniform vec3 lightAmbientColor; // Lights ambient color
|
||||
uniform vec3 lightDiffuseColor; // Light diffuse color
|
||||
uniform vec3 lightSpecularColor; // Light specular color
|
||||
uniform vec3 light0PosCameraSpace; // Camera-space position of the light
|
||||
uniform vec3 light0DiffuseColor; // Light 0 diffuse color
|
||||
uniform vec3 light0SpecularColor; // Light 0 specular color
|
||||
uniform float shininess; // Shininess
|
||||
uniform sampler2D texture; // Texture
|
||||
uniform bool isTexture; // True if we need to use the texture
|
||||
|
@ -46,18 +46,20 @@ void main() {
|
|||
vec3 textureColor = vec3(1);
|
||||
if (isTexture) textureColor = texture2D(texture, texCoords).rgb;
|
||||
|
||||
// Compute the diffuse term
|
||||
vec3 L = normalize(lightPosCameraSpace - vertexPosCameraSpace);
|
||||
// Compute the surface normal vector
|
||||
vec3 N = normalize(vertexNormalCameraSpace);
|
||||
float diffuseFactor = max(dot(N, L), 0.0);
|
||||
vec3 diffuse = lightDiffuseColor * diffuseFactor * textureColor;
|
||||
|
||||
// Compute the specular term
|
||||
// Compute the diffuse term of light 0
|
||||
vec3 L0 = normalize(light0PosCameraSpace - vertexPosCameraSpace);
|
||||
float diffuseFactor = max(dot(N, L0), 0.0);
|
||||
vec3 diffuse = light0DiffuseColor * diffuseFactor * textureColor;
|
||||
|
||||
// Compute the specular term of light 0
|
||||
vec3 V = normalize(-vertexPosCameraSpace);
|
||||
vec3 H = normalize(V + L);
|
||||
float specularFactor = pow(max(dot(N, H), 0), shininess);
|
||||
vec3 H0 = normalize(V + L0);
|
||||
float specularFactor = pow(max(dot(N, H0), 0), shininess);
|
||||
if (diffuseFactor < 0) specularFactor = 0.0;
|
||||
vec3 specular = lightSpecularColor * specularFactor;
|
||||
vec3 specular = light0SpecularColor * specularFactor;
|
||||
|
||||
// Compute the final color
|
||||
gl_FragColor = vec4(ambient + diffuse + specular, 1.0);
|
||||
|
|
|
@ -59,7 +59,7 @@ Scene::Scene(GlutViewer* viewer) : mViewer(viewer), mLight0(0),
|
|||
float radius = 2.0f;
|
||||
|
||||
// Create all the cubes of the scene
|
||||
for (int i=0; i<NB_SPHERES; i++) {
|
||||
for (int i=0; i<NB_CUBES; i++) {
|
||||
|
||||
// Position of the cubes
|
||||
float angle = i * 30.0f;
|
||||
|
@ -68,7 +68,7 @@ Scene::Scene(GlutViewer* viewer) : mViewer(viewer), mLight0(0),
|
|||
radius * sin(angle));
|
||||
|
||||
// Create a cube and a corresponding rigid in the dynamics world
|
||||
Box* cube = new Box(BOX_SIZE, position , SPHERE_MASS, mDynamicsWorld);
|
||||
Box* cube = new Box(BOX_SIZE, position , CUBE_MASS, mDynamicsWorld);
|
||||
|
||||
// The box is a moving rigid body
|
||||
cube->getRigidBody()->setIsMotionEnabled(true);
|
||||
|
@ -160,12 +160,12 @@ void Scene::render() {
|
|||
|
||||
// Set the variables of the shader
|
||||
mPhongShader.setMatrix4x4Uniform("projectionMatrix", camera.getProjectionMatrix());
|
||||
mPhongShader.setVector3Uniform("lightPosCameraSpace",worldToCameraMatrix * mLight0.getOrigin());
|
||||
mPhongShader.setVector3Uniform("light0PosCameraSpace",worldToCameraMatrix * mLight0.getOrigin());
|
||||
mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f));
|
||||
Color& diffCol = mLight0.getDiffuseColor();
|
||||
Color& specCol = mLight0.getSpecularColor();
|
||||
mPhongShader.setVector3Uniform("lightDiffuseColor", Vector3(diffCol.r, diffCol.g, diffCol.b));
|
||||
mPhongShader.setVector3Uniform("lightSpecularColor", Vector3(specCol.r, specCol.g, specCol.b));
|
||||
mPhongShader.setVector3Uniform("light0DiffuseColor", Vector3(diffCol.r, diffCol.g, diffCol.b));
|
||||
mPhongShader.setVector3Uniform("light0SpecularColor", Vector3(specCol.r, specCol.g, specCol.b));
|
||||
mPhongShader.setFloatUniform("shininess", 60.0f);
|
||||
|
||||
// Render all the cubes of the scene
|
||||
|
|
|
@ -32,10 +32,10 @@
|
|||
#include "Box.h"
|
||||
|
||||
// Constants
|
||||
const int NB_SPHERES = 20; // Number of boxes in the scene
|
||||
const int NB_CUBES = 20; // Number of boxes in the scene
|
||||
const openglframework::Vector3 BOX_SIZE(2, 2, 2); // Box dimensions in meters
|
||||
const openglframework::Vector3 FLOOR_SIZE(20, 0.5f, 20); // Floor dimensions in meters
|
||||
const float SPHERE_MASS = 1.0f; // Box mass in kilograms
|
||||
const float CUBE_MASS = 1.0f; // Box mass in kilograms
|
||||
const float FLOOR_MASS = 100.0f; // Floor mass in kilograms
|
||||
|
||||
// Class Scene
|
||||
|
|
|
@ -164,14 +164,13 @@ void Scene::render() {
|
|||
mPhongShader.bind();
|
||||
|
||||
// Set the variables of the shader
|
||||
mPhongShader.setVector3Uniform("lightPosCameraSpace",worldToCameraMatrix * mLight0.getOrigin());
|
||||
mPhongShader.setVector3Uniform("light0PosCameraSpace",worldToCameraMatrix * mLight0.getOrigin());
|
||||
mPhongShader.setMatrix4x4Uniform("projectionMatrix", camera.getProjectionMatrix());
|
||||
mPhongShader.setVector3Uniform("lightWorldPosition", mLight0.getOrigin());
|
||||
mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f));
|
||||
Color& diffCol = mLight0.getDiffuseColor();
|
||||
Color& specCol = mLight0.getSpecularColor();
|
||||
mPhongShader.setVector3Uniform("lightDiffuseColor", Vector3(diffCol.r, diffCol.g, diffCol.b));
|
||||
mPhongShader.setVector3Uniform("lightSpecularColor", Vector3(specCol.r, specCol.g, specCol.b));
|
||||
mPhongShader.setVector3Uniform("light0DiffuseColor", Vector3(diffCol.r, diffCol.g, diffCol.b));
|
||||
mPhongShader.setVector3Uniform("light0SpecularColor", Vector3(specCol.r, specCol.g, specCol.b));
|
||||
mPhongShader.setFloatUniform("shininess", 60.0f);
|
||||
|
||||
// Render all the boxes
|
||||
|
@ -244,7 +243,7 @@ void Scene::createSliderJoint() {
|
|||
|
||||
// Create a box and a corresponding rigid in the dynamics world
|
||||
openglframework::Vector3 box1Dimension(2, 4, 2);
|
||||
mSliderJointBottomBox = new Box(box1Dimension, positionBox1 , SPHERE_MASS, mDynamicsWorld);
|
||||
mSliderJointBottomBox = new Box(box1Dimension, positionBox1 , CUBE_MASS, mDynamicsWorld);
|
||||
|
||||
// The fist box cannot move
|
||||
mSliderJointBottomBox->getRigidBody()->setIsMotionEnabled(false);
|
||||
|
@ -259,7 +258,7 @@ void Scene::createSliderJoint() {
|
|||
|
||||
// Create a box and a corresponding rigid in the dynamics world
|
||||
openglframework::Vector3 box2Dimension(1.5, 4, 1.5);
|
||||
mSliderJointTopBox = new Box(box2Dimension, positionBox2 , SPHERE_MASS, mDynamicsWorld);
|
||||
mSliderJointTopBox = new Box(box2Dimension, positionBox2 , CUBE_MASS, mDynamicsWorld);
|
||||
|
||||
// The second box is allowed to move
|
||||
mSliderJointTopBox->getRigidBody()->setIsMotionEnabled(true);
|
||||
|
@ -297,7 +296,7 @@ void Scene::createPropellerHingeJoint() {
|
|||
|
||||
// Create a box and a corresponding rigid in the dynamics world
|
||||
openglframework::Vector3 boxDimension(10, 1, 1);
|
||||
mPropellerBox = new Box(boxDimension, positionBox1 , SPHERE_MASS, mDynamicsWorld);
|
||||
mPropellerBox = new Box(boxDimension, positionBox1 , CUBE_MASS, mDynamicsWorld);
|
||||
|
||||
// The fist box cannot move
|
||||
mPropellerBox->getRigidBody()->setIsMotionEnabled(true);
|
||||
|
@ -334,7 +333,7 @@ void Scene::createFixedJoints() {
|
|||
|
||||
// Create a box and a corresponding rigid in the dynamics world
|
||||
openglframework::Vector3 boxDimension(1.5, 1.5, 1.5);
|
||||
mFixedJointBox1 = new Box(boxDimension, positionBox1 , SPHERE_MASS, mDynamicsWorld);
|
||||
mFixedJointBox1 = new Box(boxDimension, positionBox1 , CUBE_MASS, mDynamicsWorld);
|
||||
|
||||
// The fist box cannot move
|
||||
mFixedJointBox1->getRigidBody()->setIsMotionEnabled(true);
|
||||
|
@ -348,7 +347,7 @@ void Scene::createFixedJoints() {
|
|||
openglframework::Vector3 positionBox2(-5, 7, 0);
|
||||
|
||||
// Create a box and a corresponding rigid in the dynamics world
|
||||
mFixedJointBox2 = new Box(boxDimension, positionBox2 , SPHERE_MASS, mDynamicsWorld);
|
||||
mFixedJointBox2 = new Box(boxDimension, positionBox2 , CUBE_MASS, mDynamicsWorld);
|
||||
|
||||
// The second box is allowed to move
|
||||
mFixedJointBox2->getRigidBody()->setIsMotionEnabled(true);
|
||||
|
@ -363,6 +362,7 @@ void Scene::createFixedJoints() {
|
|||
rp3d::RigidBody* propellerBody = mPropellerBox->getRigidBody();
|
||||
const rp3d::Vector3 anchorPointWorldSpace1(5, 7, 0);
|
||||
rp3d::FixedJointInfo jointInfo1(body1, propellerBody, anchorPointWorldSpace1);
|
||||
jointInfo1.isCollisionEnabled = false;
|
||||
|
||||
// Create the joint in the dynamics world
|
||||
mFixedJoint1 = dynamic_cast<rp3d::FixedJoint*>(mDynamicsWorld->createJoint(jointInfo1));
|
||||
|
@ -373,6 +373,7 @@ void Scene::createFixedJoints() {
|
|||
rp3d::RigidBody* body2 = mFixedJointBox2->getRigidBody();
|
||||
const rp3d::Vector3 anchorPointWorldSpace2(-5, 7, 0);
|
||||
rp3d::FixedJointInfo jointInfo2(body2, propellerBody, anchorPointWorldSpace2);
|
||||
jointInfo2.isCollisionEnabled = false;
|
||||
|
||||
// Create the joint in the dynamics world
|
||||
mFixedJoint2 = dynamic_cast<rp3d::FixedJoint*>(mDynamicsWorld->createJoint(jointInfo2));
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
// Constants
|
||||
const openglframework::Vector3 BOX_SIZE(2, 2, 2); // Box dimensions in meters
|
||||
const openglframework::Vector3 FLOOR_SIZE(20, 0.5f, 20); // Floor dimensions in meters
|
||||
const float SPHERE_MASS = 1.0f; // Box mass in kilograms
|
||||
const float CUBE_MASS = 1.0f; // Box mass in kilograms
|
||||
const float FLOOR_MASS = 100.0f; // Floor mass in kilograms
|
||||
const int NB_BALLSOCKETJOINT_BOXES = 7; // Number of Ball-And-Socket chain boxes
|
||||
const int NB_HINGE_BOXES = 7; // Number of Hinge chain boxes
|
||||
|
|
|
@ -45,12 +45,12 @@ using namespace reactphysics3d;
|
|||
|
||||
// Constructor
|
||||
ConeShape::ConeShape(decimal radius, decimal height)
|
||||
: CollisionShape(CONE), mRadius(radius), mHalfHeight(height / decimal(2.0)) {
|
||||
assert(radius > 0.0);
|
||||
: CollisionShape(CONE), mRadius(radius), mHalfHeight(height * decimal(0.5)) {
|
||||
assert(mRadius > 0.0);
|
||||
assert(mHalfHeight > 0.0);
|
||||
|
||||
// Compute the sine of the semi-angle at the apex point
|
||||
mSinTheta = radius / (sqrt(radius * radius + height * height));
|
||||
mSinTheta = mRadius / (sqrt(mRadius * mRadius + height * height));
|
||||
}
|
||||
|
||||
// Private copy-constructor
|
||||
|
@ -88,7 +88,7 @@ inline Vector3 ConeShape::getLocalSupportPointWithoutMargin(const Vector3& direc
|
|||
decimal sinThetaTimesLengthV = mSinTheta * v.length();
|
||||
Vector3 supportPoint;
|
||||
|
||||
if (v.y >= sinThetaTimesLengthV) {
|
||||
if (v.y > sinThetaTimesLengthV) {
|
||||
supportPoint = Vector3(0.0, mHalfHeight, 0.0);
|
||||
}
|
||||
else {
|
||||
|
@ -98,7 +98,7 @@ inline Vector3 ConeShape::getLocalSupportPointWithoutMargin(const Vector3& direc
|
|||
supportPoint = Vector3(v.x * d, -mHalfHeight, v.z * d);
|
||||
}
|
||||
else {
|
||||
supportPoint = Vector3(mRadius, -mHalfHeight, 0.0);
|
||||
supportPoint = Vector3(0.0, -mHalfHeight, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user