Modifications in testbed for setScaling() method on objects

This commit is contained in:
Daniel Chappuis 2015-11-24 07:03:02 +01:00
parent 22b214fb91
commit 3ebb00fd68
6 changed files with 42 additions and 11 deletions

View File

@ -55,7 +55,7 @@ class ProxyShape {
CollisionShape* mCollisionShape;
/// Local-space to parent body-space transform (does not change over time)
const Transform mLocalToBodyTransform;
Transform mLocalToBodyTransform;
/// Mass (in kilogramms) of the corresponding collision shape
decimal mMass;
@ -122,6 +122,9 @@ class ProxyShape {
/// Return the local to parent body transform
const Transform& getLocalToBodyTransform() const;
/// Set the local to parent body transform
void setLocalToBodyTransform(const Transform& transform);
/// Return the local to world transform
const Transform getLocalToWorldTransform() const;
@ -227,6 +230,17 @@ inline const Transform& ProxyShape::getLocalToBodyTransform() const {
return mLocalToBodyTransform;
}
// Set the local to parent body transform
inline void ProxyShape::setLocalToBodyTransform(const Transform& transform) {
mLocalToBodyTransform = transform;
mBody->setIsSleeping(false);
// Notify the body that the proxy shape has to be updated in the broad-phase
mBody->updateProxyShapeInBroadPhase(this, true);
}
// Return the local to world transform
/**
* @return The transformation that transforms the local-space of the collision
@ -316,6 +330,8 @@ inline void ProxyShape::setLocalScaling(const Vector3& scaling) {
// Set the local scaling of the collision shape
mCollisionShape->setLocalScaling(scaling);
mBody->setIsSleeping(false);
// Notify the body that the proxy shape has to be updated in the broad-phase
mBody->updateProxyShapeInBroadPhase(this, true);
}

View File

@ -128,7 +128,7 @@ inline decimal CapsuleShape::getHeight() const {
return mHalfHeight + mHalfHeight;
}
/// Set the scaling vector of the collision shape
// Set the scaling vector of the collision shape
inline void CapsuleShape::setLocalScaling(const Vector3& scaling) {
mHalfHeight = (mHalfHeight / mScaling.y) * scaling.y;

View File

@ -47,7 +47,7 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos
// Compute the scaling matrix
mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0,
0, (mHeight + 2.0f * mRadius) / 3.0f, 0,0,
0, (mHeight + 2.0f * mRadius) / 3, 0,0,
0, 0, mRadius, 0,
0, 0, 0, 1.0f);
@ -290,7 +290,7 @@ void Capsule::setScaling(const openglframework::Vector3& scaling) {
// Scale the graphics object
mScalingMatrix = openglframework::Matrix4(mRadius * scaling.x, 0, 0, 0,
0, (mHeight + 2.0f * mRadius) / 3.0f * scaling.y, 0,0,
0, 0, mRadius * scaling.z, 0,
0, (mHeight * scaling.y + 2.0f * mRadius * scaling.x) / 3, 0,0,
0, 0, mRadius * scaling.x, 0,
0, 0, 0, 1.0f);
}

View File

@ -47,6 +47,8 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
// Identity scaling matrix
mScalingMatrix.setToIdentity();
mDistanceBetweenSphere = 8.0f;
// Initialize the position where the sphere will be rendered
translateWorld(position);
@ -74,10 +76,10 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
mPreviousTransform = transformBody;
// Initial transform of the first sphere collision shape of the dumbbell (in local-space)
rp3d::Transform transformSphereShape1(rp3d::Vector3(0, 4.0, 0), rp3d::Quaternion::identity());
rp3d::Transform transformSphereShape1(rp3d::Vector3(0, mDistanceBetweenSphere / 2.0f, 0), rp3d::Quaternion::identity());
// Initial transform of the second sphere collision shape of the dumbell (in local-space)
rp3d::Transform transformSphereShape2(rp3d::Vector3(0, -4.0, 0), rp3d::Quaternion::identity());
rp3d::Transform transformSphereShape2(rp3d::Vector3(0, -mDistanceBetweenSphere / 2.0f, 0), rp3d::Quaternion::identity());
// Initial transform of the cylinder collision shape of the dumbell (in local-space)
rp3d::Transform transformCylinderShape(rp3d::Vector3(0, 0, 0), rp3d::Quaternion::identity());
@ -116,6 +118,8 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
// Identity scaling matrix
mScalingMatrix.setToIdentity();
mDistanceBetweenSphere = 8.0f;
// Initialize the position where the sphere will be rendered
translateWorld(position);
@ -139,10 +143,10 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
rp3d::Transform transformBody(initPosition, initOrientation);
// Initial transform of the first sphere collision shape of the dumbbell (in local-space)
rp3d::Transform transformSphereShape1(rp3d::Vector3(0, 4.0, 0), rp3d::Quaternion::identity());
rp3d::Transform transformSphereShape1(rp3d::Vector3(0, mDistanceBetweenSphere / 2.0f, 0), rp3d::Quaternion::identity());
// Initial transform of the second sphere collision shape of the dumbell (in local-space)
rp3d::Transform transformSphereShape2(rp3d::Vector3(0, -4.0, 0), rp3d::Quaternion::identity());
rp3d::Transform transformSphereShape2(rp3d::Vector3(0, -mDistanceBetweenSphere / 2.0f, 0), rp3d::Quaternion::identity());
// Initial transform of the cylinder collision shape of the dumbell (in local-space)
rp3d::Transform transformCylinderShape(rp3d::Vector3(0, 0, 0), rp3d::Quaternion::identity());
@ -325,6 +329,17 @@ void Dumbbell::setScaling(const openglframework::Vector3& scaling) {
mProxyShapeSphere1->setLocalScaling(newScaling);
mProxyShapeSphere2->setLocalScaling(newScaling);
mDistanceBetweenSphere = (mDistanceBetweenSphere / mScalingMatrix.getValue(1, 1)) * scaling.y;
// Initial transform of the first sphere collision shape of the dumbbell (in local-space)
rp3d::Transform transformSphereShape1(rp3d::Vector3(0, mDistanceBetweenSphere / 2.0f, 0), rp3d::Quaternion::identity());
// Initial transform of the second sphere collision shape of the dumbell (in local-space)
rp3d::Transform transformSphereShape2(rp3d::Vector3(0, -mDistanceBetweenSphere / 2.0f, 0), rp3d::Quaternion::identity());
mProxyShapeSphere1->setLocalToBodyTransform(transformSphereShape1);
mProxyShapeSphere2->setLocalToBodyTransform(transformSphereShape2);
// Scale the graphics object
mScalingMatrix = openglframework::Matrix4(scaling.x, 0, 0, 0,
0, scaling.y, 0, 0,

View File

@ -39,7 +39,7 @@ class Dumbbell : public openglframework::Mesh, public PhysicsObject {
// -------------------- Attributes -------------------- //
/// Radius of the spheres
float mRadius;
float mDistanceBetweenSphere;
/// Collision shapes
rp3d::CylinderShape* mCylinderShape;

View File

@ -47,7 +47,7 @@ struct EngineSettings {
public:
float elapsedTime; // Elapsed time (in seconds)
long double elapsedTime; // Elapsed time (in seconds)
float timeStep; // Current time step (in seconds)
int nbVelocitySolverIterations; // Nb of velocity solver iterations
int nbPositionSolverIterations; // Nb of position solver iterations