From 5f03b039a5a46a6dcbfbe7f2c59c648e8d72e8df Mon Sep 17 00:00:00 2001 From: Benjamin Ellenberger Date: Mon, 11 Jul 2016 23:22:17 +0200 Subject: [PATCH] Change btVector3/btQuaternion to const btVector3&/btQuaternion&. ------------------------------------------------------------------ Parameters such as btVector3/btQuaternion need to be passed as const reference, not by value (it causes SIMD alignnment errors on Windows). --- examples/ExtendedTutorials/MultiPendulum.cpp | 21 +++++++------------ examples/ExtendedTutorials/NewtonsCradle.cpp | 4 ++-- .../ExtendedTutorials/NewtonsRopeCradle.cpp | 4 ++-- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/examples/ExtendedTutorials/MultiPendulum.cpp b/examples/ExtendedTutorials/MultiPendulum.cpp index 5e1fa59e1..038aab3ec 100644 --- a/examples/ExtendedTutorials/MultiPendulum.cpp +++ b/examples/ExtendedTutorials/MultiPendulum.cpp @@ -50,7 +50,7 @@ struct MultiPendulumExample: public CommonRigidBodyBase { virtual void initPhysics(); // build a multi pendulum virtual void renderScene(); // render the scene to screen - virtual void createMultiPendulum(btSphereShape* colShape, btScalar pendulaQty, btScalar xPosition, btScalar yPosition,btScalar zPosition, btScalar length, btScalar mass); // create a multi pendulum at the indicated x and y position, the specified number of pendula formed into a chain, each with indicated length and mass + virtual void createMultiPendulum(btSphereShape* colShape, btScalar pendulaQty, const btVector3& position, btScalar length, btScalar mass); // create a multi pendulum at the indicated x and y position, the specified number of pendula formed into a chain, each with indicated length and mass virtual void changePendulaLength(btScalar length); // change the pendulum length virtual void changePendulaRestitution(btScalar restitution); // change the pendula restitution virtual void stepSimulation(float deltaTime); // step the simulation @@ -155,16 +155,14 @@ void MultiPendulumExample::initPhysics() { // Setup your physics scene { // create the multipendulum starting at the indicated position below and where each pendulum has the following mass btScalar pendulumMass(1.f); - btScalar xPosition(0.0f); // initial top-most pendulum position - btScalar yPosition(15.0f); - btScalar zPosition(0.0f); + btVector3 position(0.0f,15.0f,0.0f); // initial top-most pendulum position // Re-using the same collision is better for memory usage and performance btSphereShape* pendulumShape = new btSphereShape(gSphereRadius); m_collisionShapes.push_back(pendulumShape); // create multi-pendulum - createMultiPendulum(pendulumShape, floor(gPendulaQty), xPosition, yPosition,zPosition, + createMultiPendulum(pendulumShape, floor(gPendulaQty), position, gInitialPendulumLength, pendulumMass); } @@ -181,7 +179,7 @@ void MultiPendulumExample::stepSimulation(float deltaTime) { } void MultiPendulumExample::createMultiPendulum(btSphereShape* colShape, - btScalar pendulaQty, btScalar xPosition, btScalar yPosition, btScalar zPosition, + btScalar pendulaQty, const btVector3& position, btScalar length, btScalar mass) { // The multi-pendulum looks like this (names when built): @@ -200,8 +198,7 @@ void MultiPendulumExample::createMultiPendulum(btSphereShape* colShape, startTransform.setIdentity(); // position the top sphere - startTransform.setOrigin( - btVector3(btScalar(xPosition), btScalar(yPosition), btScalar(zPosition))); + startTransform.setOrigin(position); startTransform.setRotation(btQuaternion(0, 0, 0, 1)); // zero rotation @@ -228,9 +225,7 @@ void MultiPendulumExample::createMultiPendulum(btSphereShape* colShape, // create joint element to make the pendulum rotate it // position the joint sphere at the same position as the top sphere - startTransform.setOrigin( - btVector3(btScalar(xPosition), btScalar(yPosition - length*(i)), - btScalar(0))); + startTransform.setOrigin(position - btVector3(0,length*(i),0)); startTransform.setRotation(btQuaternion(0, 0, 0, 1)); // zero rotation @@ -269,9 +264,7 @@ void MultiPendulumExample::createMultiPendulum(btSphereShape* colShape, startTransform.setIdentity(); // reset start transform // position the child sphere below the joint sphere - startTransform.setOrigin( - btVector3(btScalar(xPosition), btScalar(yPosition - length*(i+1)), - btScalar(0))); + startTransform.setOrigin(position - btVector3(0,length*(i+1),0)); startTransform.setRotation(btQuaternion(0, 0, 0, 1)); // zero rotation diff --git a/examples/ExtendedTutorials/NewtonsCradle.cpp b/examples/ExtendedTutorials/NewtonsCradle.cpp index baa7536fc..0d4c52095 100644 --- a/examples/ExtendedTutorials/NewtonsCradle.cpp +++ b/examples/ExtendedTutorials/NewtonsCradle.cpp @@ -50,7 +50,7 @@ struct NewtonsCradleExample: public CommonRigidBodyBase { } virtual void initPhysics(); virtual void renderScene(); - virtual void createPendulum(btSphereShape* colShape, btVector3 position, btScalar length, btScalar mass); + virtual void createPendulum(btSphereShape* colShape, const btVector3& position, btScalar length, btScalar mass); virtual void changePendulaLength(btScalar length); virtual void changePendulaRestitution(btScalar restitution); virtual void stepSimulation(float deltaTime); @@ -184,7 +184,7 @@ void NewtonsCradleExample::stepSimulation(float deltaTime) { } } -void NewtonsCradleExample::createPendulum(btSphereShape* colShape,btVector3 position, btScalar length, btScalar mass) { +void NewtonsCradleExample::createPendulum(btSphereShape* colShape, const btVector3& position, btScalar length, btScalar mass) { // The pendulum looks like this (names when built): // O topSphere diff --git a/examples/ExtendedTutorials/NewtonsRopeCradle.cpp b/examples/ExtendedTutorials/NewtonsRopeCradle.cpp index 7d8a289de..94c96a71f 100644 --- a/examples/ExtendedTutorials/NewtonsRopeCradle.cpp +++ b/examples/ExtendedTutorials/NewtonsRopeCradle.cpp @@ -76,7 +76,7 @@ struct NewtonsRopeCradleExample : public CommonRigidBodyBase { } virtual void createRopePendulum(btSphereShape* colShape, - btVector3 position, btQuaternion pendulumOrientation, btScalar width, btScalar height, btScalar mass); + const btVector3& position, const btQuaternion& pendulumOrientation, btScalar width, btScalar height, btScalar mass); virtual void changePendulaRestitution(btScalar restitution); virtual void connectWithRope(btRigidBody* body1, btRigidBody* body2); virtual bool keyboardCallback(int key, int state); @@ -254,7 +254,7 @@ void NewtonsRopeCradleExample::stepSimulation(float deltaTime) { } void NewtonsRopeCradleExample::createRopePendulum(btSphereShape* colShape, - btVector3 position, btQuaternion pendulumOrientation, btScalar width, btScalar height, btScalar mass) { + const btVector3& position, const btQuaternion& pendulumOrientation, btScalar width, btScalar height, btScalar mass) { // The pendulum looks like this (names when built): // O O topSphere1 topSphere2