Modifications in testbed for setScaling() method on objects
This commit is contained in:
parent
22b214fb91
commit
3ebb00fd68
|
@ -55,7 +55,7 @@ class ProxyShape {
|
||||||
CollisionShape* mCollisionShape;
|
CollisionShape* mCollisionShape;
|
||||||
|
|
||||||
/// Local-space to parent body-space transform (does not change over time)
|
/// 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
|
/// Mass (in kilogramms) of the corresponding collision shape
|
||||||
decimal mMass;
|
decimal mMass;
|
||||||
|
@ -122,6 +122,9 @@ class ProxyShape {
|
||||||
/// Return the local to parent body transform
|
/// Return the local to parent body transform
|
||||||
const Transform& getLocalToBodyTransform() const;
|
const Transform& getLocalToBodyTransform() const;
|
||||||
|
|
||||||
|
/// Set the local to parent body transform
|
||||||
|
void setLocalToBodyTransform(const Transform& transform);
|
||||||
|
|
||||||
/// Return the local to world transform
|
/// Return the local to world transform
|
||||||
const Transform getLocalToWorldTransform() const;
|
const Transform getLocalToWorldTransform() const;
|
||||||
|
|
||||||
|
@ -227,6 +230,17 @@ inline const Transform& ProxyShape::getLocalToBodyTransform() const {
|
||||||
return mLocalToBodyTransform;
|
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 local to world transform
|
||||||
/**
|
/**
|
||||||
* @return The transformation that transforms the local-space of the collision
|
* @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
|
// Set the local scaling of the collision shape
|
||||||
mCollisionShape->setLocalScaling(scaling);
|
mCollisionShape->setLocalScaling(scaling);
|
||||||
|
|
||||||
|
mBody->setIsSleeping(false);
|
||||||
|
|
||||||
// Notify the body that the proxy shape has to be updated in the broad-phase
|
// Notify the body that the proxy shape has to be updated in the broad-phase
|
||||||
mBody->updateProxyShapeInBroadPhase(this, true);
|
mBody->updateProxyShapeInBroadPhase(this, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ inline decimal CapsuleShape::getHeight() const {
|
||||||
return mHalfHeight + mHalfHeight;
|
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) {
|
inline void CapsuleShape::setLocalScaling(const Vector3& scaling) {
|
||||||
|
|
||||||
mHalfHeight = (mHalfHeight / mScaling.y) * scaling.y;
|
mHalfHeight = (mHalfHeight / mScaling.y) * scaling.y;
|
||||||
|
|
|
@ -47,7 +47,7 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos
|
||||||
|
|
||||||
// Compute the scaling matrix
|
// Compute the scaling matrix
|
||||||
mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0,
|
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, mRadius, 0,
|
||||||
0, 0, 0, 1.0f);
|
0, 0, 0, 1.0f);
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ void Capsule::setScaling(const openglframework::Vector3& scaling) {
|
||||||
|
|
||||||
// Scale the graphics object
|
// Scale the graphics object
|
||||||
mScalingMatrix = openglframework::Matrix4(mRadius * scaling.x, 0, 0, 0,
|
mScalingMatrix = openglframework::Matrix4(mRadius * scaling.x, 0, 0, 0,
|
||||||
0, (mHeight + 2.0f * mRadius) / 3.0f * scaling.y, 0,0,
|
0, (mHeight * scaling.y + 2.0f * mRadius * scaling.x) / 3, 0,0,
|
||||||
0, 0, mRadius * scaling.z, 0,
|
0, 0, mRadius * scaling.x, 0,
|
||||||
0, 0, 0, 1.0f);
|
0, 0, 0, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,8 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
|
||||||
// Identity scaling matrix
|
// Identity scaling matrix
|
||||||
mScalingMatrix.setToIdentity();
|
mScalingMatrix.setToIdentity();
|
||||||
|
|
||||||
|
mDistanceBetweenSphere = 8.0f;
|
||||||
|
|
||||||
// Initialize the position where the sphere will be rendered
|
// Initialize the position where the sphere will be rendered
|
||||||
translateWorld(position);
|
translateWorld(position);
|
||||||
|
|
||||||
|
@ -74,10 +76,10 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
|
||||||
mPreviousTransform = transformBody;
|
mPreviousTransform = transformBody;
|
||||||
|
|
||||||
// Initial transform of the first sphere collision shape of the dumbbell (in local-space)
|
// 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)
|
// 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)
|
// Initial transform of the cylinder collision shape of the dumbell (in local-space)
|
||||||
rp3d::Transform transformCylinderShape(rp3d::Vector3(0, 0, 0), rp3d::Quaternion::identity());
|
rp3d::Transform transformCylinderShape(rp3d::Vector3(0, 0, 0), rp3d::Quaternion::identity());
|
||||||
|
@ -116,6 +118,8 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
|
||||||
// Identity scaling matrix
|
// Identity scaling matrix
|
||||||
mScalingMatrix.setToIdentity();
|
mScalingMatrix.setToIdentity();
|
||||||
|
|
||||||
|
mDistanceBetweenSphere = 8.0f;
|
||||||
|
|
||||||
// Initialize the position where the sphere will be rendered
|
// Initialize the position where the sphere will be rendered
|
||||||
translateWorld(position);
|
translateWorld(position);
|
||||||
|
|
||||||
|
@ -139,10 +143,10 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
|
||||||
rp3d::Transform transformBody(initPosition, initOrientation);
|
rp3d::Transform transformBody(initPosition, initOrientation);
|
||||||
|
|
||||||
// Initial transform of the first sphere collision shape of the dumbbell (in local-space)
|
// 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)
|
// 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)
|
// Initial transform of the cylinder collision shape of the dumbell (in local-space)
|
||||||
rp3d::Transform transformCylinderShape(rp3d::Vector3(0, 0, 0), rp3d::Quaternion::identity());
|
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);
|
mProxyShapeSphere1->setLocalScaling(newScaling);
|
||||||
mProxyShapeSphere2->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
|
// Scale the graphics object
|
||||||
mScalingMatrix = openglframework::Matrix4(scaling.x, 0, 0, 0,
|
mScalingMatrix = openglframework::Matrix4(scaling.x, 0, 0, 0,
|
||||||
0, scaling.y, 0, 0,
|
0, scaling.y, 0, 0,
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Dumbbell : public openglframework::Mesh, public PhysicsObject {
|
||||||
// -------------------- Attributes -------------------- //
|
// -------------------- Attributes -------------------- //
|
||||||
|
|
||||||
/// Radius of the spheres
|
/// Radius of the spheres
|
||||||
float mRadius;
|
float mDistanceBetweenSphere;
|
||||||
|
|
||||||
/// Collision shapes
|
/// Collision shapes
|
||||||
rp3d::CylinderShape* mCylinderShape;
|
rp3d::CylinderShape* mCylinderShape;
|
||||||
|
|
|
@ -47,7 +47,7 @@ struct EngineSettings {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
float elapsedTime; // Elapsed time (in seconds)
|
long double elapsedTime; // Elapsed time (in seconds)
|
||||||
float timeStep; // Current time step (in seconds)
|
float timeStep; // Current time step (in seconds)
|
||||||
int nbVelocitySolverIterations; // Nb of velocity solver iterations
|
int nbVelocitySolverIterations; // Nb of velocity solver iterations
|
||||||
int nbPositionSolverIterations; // Nb of position solver iterations
|
int nbPositionSolverIterations; // Nb of position solver iterations
|
||||||
|
|
Loading…
Reference in New Issue
Block a user