From 3dd759c46385ec80af60109532540d26ca1063a8 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Mon, 19 May 2014 14:53:11 -0700 Subject: [PATCH] fix BT_USE_DOUBLE_PRECISION build, address Issue 177 https://github.com/bulletphysics/bullet3/issues/177 --- Demos3/bullet2/BasicDemo/BasicDemo.cpp | 6 ++-- Demos3/bullet2/BasicDemo/MyDebugDrawer.h | 5 ++- Demos3/bullet2/ChainDemo/ChainDemo.cpp | 6 ++-- .../BulletMultiBodyDemos.cpp | 22 ++++++------ btgui/OpenGLWindow/GLInstancingRenderer.cpp | 9 +++++ btgui/OpenGLWindow/GLInstancingRenderer.h | 36 +++++++++++++++++++ 6 files changed, 66 insertions(+), 18 deletions(-) diff --git a/Demos3/bullet2/BasicDemo/BasicDemo.cpp b/Demos3/bullet2/BasicDemo/BasicDemo.cpp index 92147c16d..59980667a 100644 --- a/Demos3/bullet2/BasicDemo/BasicDemo.cpp +++ b/Demos3/bullet2/BasicDemo/BasicDemo.cpp @@ -26,8 +26,8 @@ BasicDemo::~BasicDemo() void BasicDemo::createGround(int cubeShapeId) { { - float color[]={0.3,0.3,1,1}; - float halfExtents[]={50,50,50,1}; + btVector4 color(0.3,0.3,1,1); + btVector4 halfExtents(50,50,50,1); btTransform groundTransform; groundTransform.setIdentity(); groundTransform.setOrigin(btVector3(0,-50,0)); @@ -71,7 +71,7 @@ void BasicDemo::initPhysics() { - float halfExtents[]={scaling,scaling,scaling,1}; + btVector4 halfExtents(scaling,scaling,scaling,1); btVector4 colors[4] = { btVector4(1,0,0,1), diff --git a/Demos3/bullet2/BasicDemo/MyDebugDrawer.h b/Demos3/bullet2/BasicDemo/MyDebugDrawer.h index 411815452..81f9a536c 100644 --- a/Demos3/bullet2/BasicDemo/MyDebugDrawer.h +++ b/Demos3/bullet2/BasicDemo/MyDebugDrawer.h @@ -15,8 +15,11 @@ public: { } - virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color) + virtual void drawLine(const btVector3& from1,const btVector3& to1,const btVector3& color1) { + float from[4] = {from1[0],from1[1],from1[2],from1[3]}; + float to[4] = {to1[0],to1[1],to1[2],to1[3]}; + float color[4] = {color1[0],color1[1],color1[2],color1[3]}; m_glApp->m_instancingRenderer->drawLine(from,to,color); } diff --git a/Demos3/bullet2/ChainDemo/ChainDemo.cpp b/Demos3/bullet2/ChainDemo/ChainDemo.cpp index 4c353a01b..71032cb7c 100644 --- a/Demos3/bullet2/ChainDemo/ChainDemo.cpp +++ b/Demos3/bullet2/ChainDemo/ChainDemo.cpp @@ -26,8 +26,8 @@ ChainDemo::~ChainDemo() void ChainDemo::createGround(int cubeShapeId) { { - float color[]={0.3,0.3,1,1}; - float halfExtents[]={50,1,50,1}; + btVector4 color(0.3,0.3,1,1); + btVector4 halfExtents(50,1,50,1); btTransform groundTransform; groundTransform.setIdentity(); groundTransform.setOrigin(btVector3(0,-5,0)); @@ -85,7 +85,7 @@ void ChainDemo::initPhysics() int sphereShapeId = m_glApp->registerGraphicsSphereShape(radius,false); { - float halfExtents[]={scaling,scaling,scaling,1}; + btVector4 halfExtents(scaling,scaling,scaling,1); btVector4 colors[4] = { btVector4(1,0,0,1), diff --git a/Demos3/bullet2/FeatherstoneMultiBodyDemo/BulletMultiBodyDemos.cpp b/Demos3/bullet2/FeatherstoneMultiBodyDemo/BulletMultiBodyDemos.cpp index e03afcdd9..80dced6bb 100644 --- a/Demos3/bullet2/FeatherstoneMultiBodyDemo/BulletMultiBodyDemos.cpp +++ b/Demos3/bullet2/FeatherstoneMultiBodyDemo/BulletMultiBodyDemos.cpp @@ -38,12 +38,12 @@ struct GraphicsVertex float texcoord[2]; }; -static b3Vector4 colors[4] = +static btVector4 colors[4] = { - b3MakeVector4(1,0,0,1), - b3MakeVector4(0,1,0,1), - b3MakeVector4(0,1,1,1), - b3MakeVector4(1,1,0,1), + btVector4(1,0,0,1), + btVector4(0,1,0,1), + btVector4(0,1,1,1), + btVector4(1,1,0,1), }; @@ -435,8 +435,8 @@ btMultiBody* FeatherstoneDemo1::createFeatherstoneMultiBody(class btMultiBodyDyn world_to_local[0] = bod->getWorldToBaseRot(); local_origin[0] = bod->getBasePos(); //float halfExtents[3]={7.5,0.05,4.5}; - float halfExtents[3]={7.5,0.45,4.5}; - { + btVector4 halfExtents(7.5,0.45,4.5,1); + { float pos[4]={local_origin[0].x(),local_origin[0].y(),local_origin[0].z(),1}; float quat[4]={-world_to_local[0].x(),-world_to_local[0].y(),-world_to_local[0].z(),world_to_local[0].w()}; @@ -455,7 +455,7 @@ btMultiBody* FeatherstoneDemo1::createFeatherstoneMultiBody(class btMultiBodyDyn tr.setRotation(btQuaternion(quat[0],quat[1],quat[2],quat[3])); col->setWorldTransform(tr); - b3Vector4 color = colors[curColor++]; + btVector4 color = colors[curColor++]; curColor&=3; int index = m_glApp->m_instancingRenderer->registerGraphicsInstance(cubeShapeId,tr.getOrigin(),tr.getRotation(),color,halfExtents); @@ -500,7 +500,7 @@ btMultiBody* FeatherstoneDemo1::createFeatherstoneMultiBody(class btMultiBodyDyn col->setFriction(friction); - b3Vector4 color = colors[curColor++]; + btVector4 color = colors[curColor++]; curColor&=3; int index = m_glApp->m_instancingRenderer->registerGraphicsInstance(cubeShapeId,tr.getOrigin(),tr.getRotation(),color,halfExtents); @@ -536,8 +536,8 @@ void FeatherstoneDemo1::createGround() { - float color[]={0.3,0.3,1,1}; - float halfExtents[]={50,50,50,1}; + btVector4 color(0.3,0.3,1,1); + btVector4 halfExtents(50,50,50,1); btTransform groundTransform; groundTransform.setIdentity(); groundTransform.setOrigin(btVector3(0,-50,0)); diff --git a/btgui/OpenGLWindow/GLInstancingRenderer.cpp b/btgui/OpenGLWindow/GLInstancingRenderer.cpp index e214c3220..a81fa19e3 100644 --- a/btgui/OpenGLWindow/GLInstancingRenderer.cpp +++ b/btgui/OpenGLWindow/GLInstancingRenderer.cpp @@ -582,6 +582,15 @@ void GLInstancingRenderer::writeTransforms() } +int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const double* pos1, const double* orn1, const double* color1, const double* scaling1) +{ + float pos[4] = {pos1[0],pos1[1],pos1[2],pos1[3]}; + float orn[4] = {orn1[0],orn1[1],orn1[2],orn1[3]}; + float color[4] = {color1[0],color1[1],color1[2],color1[3]}; + float scaling[4] = {scaling1[0],scaling1[1],scaling1[2],scaling1[3]}; + return registerGraphicsInstance(shapeIndex,pos,orn,color,scaling); +} + int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling) { diff --git a/btgui/OpenGLWindow/GLInstancingRenderer.h b/btgui/OpenGLWindow/GLInstancingRenderer.h index fd64a57e7..2325006e7 100644 --- a/btgui/OpenGLWindow/GLInstancingRenderer.h +++ b/btgui/OpenGLWindow/GLInstancingRenderer.h @@ -77,10 +77,26 @@ public: ///position x,y,z, quaternion x,y,z,w, color r,g,b,a, scaling x,y,z int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling); + int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling); void writeTransforms(); void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex); + void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex) + { + float pos[4]; + float orn[4]; + pos[0] = position[0]; + pos[1] = position[1]; + pos[2] = position[2]; + pos[3] = position[3]; + orn[0] =orientation[0]; + orn[1] =orientation[1]; + orn[2] =orientation[2]; + orn[3] =orientation[3]; + writeSingleInstanceTransformToCPU(pos,orn,srcIndex); + + } void writeSingleInstanceTransformToGPU(float* position, float* orientation, int srcIndex); @@ -97,12 +113,32 @@ public: void updateCamera(); void getCameraPosition(float cameraPos[4]); + void getCameraPosition(double cameraPos[4]) + { + float campos[4]; + getCameraPosition(campos); + cameraPos[0] = campos[0]; + cameraPos[1] = campos[1]; + cameraPos[2] = campos[2]; + cameraPos[3] = campos[3]; + } + void setCameraDistance(float dist); float getCameraDistance() const; //set the camera 'target' void setCameraTargetPosition(float cameraPos[4]); void getCameraTargetPosition(float cameraPos[4]) const; + void getCameraTargetPosition(double cameraPos[4]) const + { + float campos[4]; + getCameraTargetPosition(campos); + cameraPos[0] = campos[0]; + cameraPos[1] = campos[1]; + cameraPos[2] = campos[2]; + cameraPos[3] = campos[3]; + + } void setCameraYaw(float yaw); void setCameraPitch(float pitch);