more bt* to b3*

This commit is contained in:
erwin coumans
2013-04-16 17:08:59 -07:00
parent faabffc23d
commit e646754228
116 changed files with 2466 additions and 3034 deletions

View File

@@ -41,9 +41,9 @@
"../../../../bullet2/LinearMath/btConvexHullComputer.h", "../../../../bullet2/LinearMath/btConvexHullComputer.h",
"../../../../bullet2/LinearMath/btSerializer.cpp", "../../../../bullet2/LinearMath/btSerializer.cpp",
"../../../../bullet2/LinearMath/btSerializer.h", "../../../../bullet2/LinearMath/btSerializer.h",
"../../../../bullet2/LinearMath/btAlignedAllocator.cpp", "../../../../bullet2/LinearMath/b3AlignedAllocator.cpp",
"../../../../bullet2/LinearMath/btQuickprof.cpp", "../../../../bullet2/LinearMath/b3Quickprof.cpp",
"../../../../bullet2/LinearMath/btQuickprof.h", "../../../../bullet2/LinearMath/b3Quickprof.h",
"../**.cpp", "../**.cpp",
"../**.h", "../**.h",
} }

View File

@@ -39,9 +39,9 @@
"../OpenGLTrueTypeFont/opengl_fontstashcallbacks.h", "../OpenGLTrueTypeFont/opengl_fontstashcallbacks.h",
"../../src/BulletGeometry/btConvexHullComputer.cpp", "../../src/BulletGeometry/btConvexHullComputer.cpp",
"../../src/BulletGeometry/btConvexHullComputer.h", "../../src/BulletGeometry/btConvexHullComputer.h",
"../../src/BulletCommon/btAlignedAllocator.cpp", "../../src/BulletCommon/b3AlignedAllocator.cpp",
"../../src/BulletCommon/btQuickprof.cpp", "../../src/BulletCommon/b3Quickprof.cpp",
"../../src/BulletCommon/btQuickprof.h", "../../src/BulletCommon/b3Quickprof.h",
"**.cpp", "**.cpp",
"**.h", "**.h",
} }

View File

@@ -32,9 +32,9 @@ subject to the following restrictions:
#include "opengl_fontstashcallbacks.h" #include "opengl_fontstashcallbacks.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "BulletCommon/btQuaternion.h" #include "BulletCommon/b3Quaternion.h"
#include "BulletCommon/CommandLineArgs.h" #include "BulletCommon/b3CommandLineArgs.h"
#include "../OpenGLWindow/LoadShader.h" #include "../OpenGLWindow/LoadShader.h"
extern char OpenSansData[]; extern char OpenSansData[];
bool printStats = false; bool printStats = false;
@@ -295,7 +295,7 @@ void Usage()
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
GLint err; GLint err;
CommandLineArgs args(argc,argv); b3CommandLineArgs args(argc,argv);
if (args.CheckCmdLineFlag("help")) if (args.CheckCmdLineFlag("help"))
{ {

View File

@@ -23,9 +23,9 @@
"../FontFiles/OpenSans.cpp", "../FontFiles/OpenSans.cpp",
"../OpenGLWindow/LoadShader.cpp", "../OpenGLWindow/LoadShader.cpp",
"../OpenGLWindow/LoadShader.h", "../OpenGLWindow/LoadShader.h",
"../../src/BulletCommon/btAlignedAllocator.cpp", "../../src/BulletCommon/b3AlignedAllocator.cpp",
"../../src/BulletCommon/btQuickprof.cpp", "../../src/BulletCommon/b3Quickprof.cpp",
"../../src/BulletCommon/btQuickprof.h" , "../../src/BulletCommon/b3Quickprof.h" ,
"fontstash.cpp", "fontstash.cpp",
"fontstash.h", "fontstash.h",
"opengl_fontstashcallbacks.cpp", "opengl_fontstashcallbacks.cpp",

View File

@@ -1,7 +1,7 @@
#ifndef GL_INSTANCE_GRAPHICS_SHAPE_H #ifndef GL_INSTANCE_GRAPHICS_SHAPE_H
#define GL_INSTANCE_GRAPHICS_SHAPE_H #define GL_INSTANCE_GRAPHICS_SHAPE_H
#include "BulletCommon/btAlignedObjectArray.h" #include "BulletCommon/b3AlignedObjectArray.h"
struct GLInstanceVertex struct GLInstanceVertex
{ {
@@ -11,9 +11,9 @@ struct GLInstanceVertex
}; };
struct GLInstanceGraphicsShape struct GLInstanceGraphicsShape
{ {
btAlignedObjectArray<GLInstanceVertex>* m_vertices; b3AlignedObjectArray<GLInstanceVertex>* m_vertices;
int m_numvertices; int m_numvertices;
btAlignedObjectArray<int>* m_indices; b3AlignedObjectArray<int>* m_indices;
int m_numIndices; int m_numIndices;
float m_scaling[4]; float m_scaling[4];
}; };

View File

@@ -2,15 +2,15 @@
#define GL_INSTANCE_RENDERER_INTERNAL_DATA_H #define GL_INSTANCE_RENDERER_INTERNAL_DATA_H
#include "OpenGLInclude.h" #include "OpenGLInclude.h"
#include "BulletCommon/btAlignedObjectArray.h" #include "BulletCommon/b3AlignedObjectArray.h"
struct GLInstanceRendererInternalData struct GLInstanceRendererInternalData
{ {
btAlignedObjectArray<GLfloat> m_instance_positions_ptr; b3AlignedObjectArray<GLfloat> m_instance_positions_ptr;
btAlignedObjectArray<GLfloat> m_instance_quaternion_ptr; b3AlignedObjectArray<GLfloat> m_instance_quaternion_ptr;
btAlignedObjectArray<GLfloat> m_instance_colors_ptr; b3AlignedObjectArray<GLfloat> m_instance_colors_ptr;
btAlignedObjectArray<GLfloat> m_instance_scale_ptr; b3AlignedObjectArray<GLfloat> m_instance_scale_ptr;
int m_vboSize; int m_vboSize;
GLuint m_vbo; GLuint m_vbo;

View File

@@ -22,10 +22,10 @@ subject to the following restrictions:
//#include "DemoSettings.h" //#include "DemoSettings.h"
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
#include "BulletCommon/btQuaternion.h" #include "BulletCommon/b3Quaternion.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "BulletCommon/btMatrix3x3.h" #include "BulletCommon/b3Matrix3x3.h"
#include "LoadShader.h" #include "LoadShader.h"
@@ -91,10 +91,10 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
{ {
btVector3 m_cameraPosition; b3Vector3 m_cameraPosition;
btVector3 m_cameraTargetPosition; b3Vector3 m_cameraTargetPosition;
float m_cameraDistance; float m_cameraDistance;
btVector3 m_cameraUp; b3Vector3 m_cameraUp;
float m_azi; float m_azi;
float m_ele; float m_ele;
@@ -106,8 +106,8 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
GLuint m_defaultTexturehandle; GLuint m_defaultTexturehandle;
InternalDataRenderer() : InternalDataRenderer() :
m_cameraPosition(btVector3(0,0,0)), m_cameraPosition(b3Vector3(0,0,0)),
m_cameraTargetPosition(btVector3(15,2,-24)), m_cameraTargetPosition(b3Vector3(15,2,-24)),
m_cameraDistance(150), m_cameraDistance(150),
m_cameraUp(0,1,0), m_cameraUp(0,1,0),
m_azi(100.f),//135.f), m_azi(100.f),//135.f),
@@ -131,7 +131,7 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
} else } else
{ {
m_cameraDistance -= deltay*0.1; m_cameraDistance -= deltay*0.1;
//btVector3 fwd = m_cameraTargetPosition-m_cameraPosition; //b3Vector3 fwd = m_cameraTargetPosition-m_cameraPosition;
//fwd.normalize(); //fwd.normalize();
//m_cameraTargetPosition += fwd*deltay*0.1; //m_cameraTargetPosition += fwd*deltay*0.1;
} }
@@ -139,8 +139,8 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
{ {
if (btFabs(deltax)>btFabs(deltay)) if (btFabs(deltax)>btFabs(deltay))
{ {
btVector3 fwd = m_cameraTargetPosition-m_cameraPosition; b3Vector3 fwd = m_cameraTargetPosition-m_cameraPosition;
btVector3 side = m_cameraUp.cross(fwd); b3Vector3 side = m_cameraUp.cross(fwd);
side.normalize(); side.normalize();
m_cameraTargetPosition += side * deltax*0.1; m_cameraTargetPosition += side * deltax*0.1;
@@ -952,11 +952,11 @@ void btCreateFrustum(
void btCreateLookAt(const btVector3& eye, const btVector3& center,const btVector3& up, GLfloat result[16]) void btCreateLookAt(const b3Vector3& eye, const b3Vector3& center,const b3Vector3& up, GLfloat result[16])
{ {
btVector3 f = (center - eye).normalized(); b3Vector3 f = (center - eye).normalized();
btVector3 u = up.normalized(); b3Vector3 u = up.normalized();
btVector3 s = (f.cross(u)).normalized(); b3Vector3 s = (f.cross(u)).normalized();
u = s.cross(f); u = s.cross(f);
result[0*4+0] = s.getX(); result[0*4+0] = s.getX();
@@ -996,25 +996,25 @@ void GLInstancingRenderer::updateCamera()
// m_azi=m_azi+0.01; // m_azi=m_azi+0.01;
btScalar rele = m_data->m_ele * btScalar(0.01745329251994329547);// rads per deg b3Scalar rele = m_data->m_ele * b3Scalar(0.01745329251994329547);// rads per deg
btScalar razi = m_data->m_azi * btScalar(0.01745329251994329547);// rads per deg b3Scalar razi = m_data->m_azi * b3Scalar(0.01745329251994329547);// rads per deg
btQuaternion rot(m_data->m_cameraUp,razi); b3Quaternion rot(m_data->m_cameraUp,razi);
btVector3 eyePos(0,0,0); b3Vector3 eyePos(0,0,0);
eyePos[m_forwardAxis] = -m_data->m_cameraDistance; eyePos[m_forwardAxis] = -m_data->m_cameraDistance;
btVector3 forward(eyePos[0],eyePos[1],eyePos[2]); b3Vector3 forward(eyePos[0],eyePos[1],eyePos[2]);
if (forward.length2() < SIMD_EPSILON) if (forward.length2() < SIMD_EPSILON)
{ {
forward.setValue(1.f,0.f,0.f); forward.setValue(1.f,0.f,0.f);
} }
btVector3 right = m_data->m_cameraUp.cross(forward); b3Vector3 right = m_data->m_cameraUp.cross(forward);
btQuaternion roll(right,-rele); b3Quaternion roll(right,-rele);
eyePos = btMatrix3x3(rot) * btMatrix3x3(roll) * eyePos; eyePos = b3Matrix3x3(rot) * b3Matrix3x3(roll) * eyePos;
m_data->m_cameraPosition[0] = eyePos.getX(); m_data->m_cameraPosition[0] = eyePos.getX();
m_data->m_cameraPosition[1] = eyePos.getY(); m_data->m_cameraPosition[1] = eyePos.getY();
@@ -1024,10 +1024,10 @@ void GLInstancingRenderer::updateCamera()
if (m_glutScreenWidth == 0 && m_glutScreenHeight == 0) if (m_glutScreenWidth == 0 && m_glutScreenHeight == 0)
return; return;
btScalar aspect; b3Scalar aspect;
btVector3 extents; b3Vector3 extents;
aspect = m_glutScreenWidth / (btScalar)m_glutScreenHeight; aspect = m_glutScreenWidth / (b3Scalar)m_glutScreenHeight;
extents.setValue(aspect * 1.0f, 1.0f,0); extents.setValue(aspect * 1.0f, 1.0f,0);
@@ -1037,8 +1037,8 @@ void GLInstancingRenderer::updateCamera()
extents *= m_data->m_cameraDistance; extents *= m_data->m_cameraDistance;
//btVector3 lower = m_data->m_cameraTargetPosition - extents; //b3Vector3 lower = m_data->m_cameraTargetPosition - extents;
//btVector3 upper = m_data->m_cameraTargetPosition + extents; //b3Vector3 upper = m_data->m_cameraTargetPosition + extents;
//gluOrtho2D(lower.x, upper.x, lower.y, upper.y); //gluOrtho2D(lower.x, upper.x, lower.y, upper.y);
//glTranslatef(100,210,0); //glTranslatef(100,210,0);
} else } else
@@ -1085,7 +1085,7 @@ void GLInstancingRenderer::setCameraPitch(float pitch)
void GLInstancingRenderer::setCameraTargetPosition(float cameraPos[4]) void GLInstancingRenderer::setCameraTargetPosition(float cameraPos[4])
{ {
m_data->m_cameraTargetPosition = btVector3(cameraPos[0],cameraPos[1],cameraPos[2]); m_data->m_cameraTargetPosition = b3Vector3(cameraPos[0],cameraPos[1],cameraPos[2]);
} }
void GLInstancingRenderer::getCameraTargetPosition(float cameraPos[4]) const void GLInstancingRenderer::getCameraTargetPosition(float cameraPos[4]) const
@@ -1108,18 +1108,18 @@ void GLInstancingRenderer::getMouseDirection(float* dir, int x, int y)
float bottom = -1.f; float bottom = -1.f;
float nearPlane = 1.f; float nearPlane = 1.f;
float tanFov = (top-bottom)*0.5f / nearPlane; float tanFov = (top-bottom)*0.5f / nearPlane;
float fov = btScalar(2.0) * btAtan(tanFov); float fov = b3Scalar(2.0) * btAtan(tanFov);
btVector3 rayFrom = m_data->m_cameraPosition; b3Vector3 rayFrom = m_data->m_cameraPosition;
btVector3 rayForward = (m_data->m_cameraTargetPosition-m_data->m_cameraPosition); b3Vector3 rayForward = (m_data->m_cameraTargetPosition-m_data->m_cameraPosition);
rayForward.normalize(); rayForward.normalize();
float farPlane = 10000.f; float farPlane = 10000.f;
rayForward*= farPlane; rayForward*= farPlane;
btVector3 rightOffset; b3Vector3 rightOffset;
btVector3 vertical = m_data->m_cameraUp; b3Vector3 vertical = m_data->m_cameraUp;
btVector3 hor; b3Vector3 hor;
hor = rayForward.cross(vertical); hor = rayForward.cross(vertical);
hor.normalize(); hor.normalize();
vertical = hor.cross(rayForward); vertical = hor.cross(rayForward);
@@ -1131,21 +1131,21 @@ void GLInstancingRenderer::getMouseDirection(float* dir, int x, int y)
hor *= 2.f * farPlane * tanfov; hor *= 2.f * farPlane * tanfov;
vertical *= 2.f * farPlane * tanfov; vertical *= 2.f * farPlane * tanfov;
btScalar aspect; b3Scalar aspect;
aspect = m_glutScreenWidth / (btScalar)m_glutScreenHeight; aspect = m_glutScreenWidth / (b3Scalar)m_glutScreenHeight;
hor*=aspect; hor*=aspect;
btVector3 rayToCenter = rayFrom + rayForward; b3Vector3 rayToCenter = rayFrom + rayForward;
btVector3 dHor = hor * 1.f/float(m_glutScreenWidth); b3Vector3 dHor = hor * 1.f/float(m_glutScreenWidth);
btVector3 dVert = vertical * 1.f/float(m_glutScreenHeight); b3Vector3 dVert = vertical * 1.f/float(m_glutScreenHeight);
btVector3 rayTo = rayToCenter - 0.5f * hor + 0.5f * vertical; b3Vector3 rayTo = rayToCenter - 0.5f * hor + 0.5f * vertical;
rayTo += btScalar(x) * dHor; rayTo += b3Scalar(x) * dHor;
rayTo -= btScalar(y) * dVert; rayTo -= b3Scalar(y) * dVert;
dir[0] = rayTo[0]; dir[0] = rayTo[0];
dir[1] = rayTo[1]; dir[1] = rayTo[1];

View File

@@ -16,7 +16,7 @@ subject to the following restrictions:
#ifndef GL_INSTANCING_RENDERER_H #ifndef GL_INSTANCING_RENDERER_H
#define GL_INSTANCING_RENDERER_H #define GL_INSTANCING_RENDERER_H
#include "BulletCommon/btAlignedObjectArray.h" #include "BulletCommon/b3AlignedObjectArray.h"
void btDefaultMouseButtonCallback( int button, int state, float x, float y); void btDefaultMouseButtonCallback( int button, int state, float x, float y);
void btDefaultMouseMoveCallback( float x, float y); void btDefaultMouseMoveCallback( float x, float y);
@@ -32,7 +32,7 @@ enum
class GLInstancingRenderer class GLInstancingRenderer
{ {
btAlignedObjectArray<struct btGraphicsInstance*> m_graphicsInstances; b3AlignedObjectArray<struct btGraphicsInstance*> m_graphicsInstances;
int m_maxNumObjectCapacity; int m_maxNumObjectCapacity;
int m_maxShapeCapacityInBytes; int m_maxShapeCapacityInBytes;

View File

@@ -18,7 +18,7 @@ subject to the following restrictions:
#include "OpenGLInclude.h" #include "OpenGLInclude.h"
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
#include "Win32InternalWindowData.h" #include "Win32InternalWindowData.h"
#include <stdio.h> #include <stdio.h>

View File

@@ -17,7 +17,7 @@ subject to the following restrictions:
#include "Win32Window.h" #include "Win32Window.h"
#include "OpenGLInclude.h" #include "OpenGLInclude.h"
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
#include <wchar.h> #include <wchar.h>
static InternalData2* sData = 0; static InternalData2* sData = 0;

View File

@@ -19,7 +19,7 @@
#include "Gwen/Controls/TabControl.h" #include "Gwen/Controls/TabControl.h"
#include "Gwen/Controls/ListBox.h" #include "Gwen/Controls/ListBox.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "GwenOpenGL3CoreRenderer.h" #include "GwenOpenGL3CoreRenderer.h"
#include "GLPrimitiveRenderer.h" #include "GLPrimitiveRenderer.h"

View File

@@ -37,10 +37,10 @@ extern char OpenSansData[];
#include "renderscene.h" #include "renderscene.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "BulletCommon/btQuaternion.h" #include "BulletCommon/b3Quaternion.h"
#include "BulletCommon/CommandLineArgs.h" #include "BulletCommon/b3CommandLineArgs.h"
#include "../OpenGLTrueTypeFont/fontstash.h" #include "../OpenGLTrueTypeFont/fontstash.h"
#include "../OpenGLTrueTypeFont/opengl_fontstashcallbacks.h" #include "../OpenGLTrueTypeFont/opengl_fontstashcallbacks.h"
@@ -240,7 +240,7 @@ sth_stash* initFont(GLPrimitiveRenderer* primRender)
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
CommandLineArgs args(argc,argv); b3CommandLineArgs args(argc,argv);
if (args.CheckCmdLineFlag("help")) if (args.CheckCmdLineFlag("help"))
{ {

View File

@@ -43,9 +43,9 @@
"../OpenGLTrueTypeFont/opengl_fontstashcallbacks.h", "../OpenGLTrueTypeFont/opengl_fontstashcallbacks.h",
"../../src/BulletGeometry/btConvexHullComputer.cpp", "../../src/BulletGeometry/btConvexHullComputer.cpp",
"../../src/BulletGeometry/btConvexHullComputer.h", "../../src/BulletGeometry/btConvexHullComputer.h",
"../../src/BulletCommon/btAlignedAllocator.cpp", "../../src/BulletCommon/b3AlignedAllocator.cpp",
"../../src/BulletCommon/btQuickprof.cpp", "../../src/BulletCommon/b3Quickprof.cpp",
"../../src/BulletCommon/btQuickprof.h" "../../src/BulletCommon/b3Quickprof.h"
} }
if os.is("Windows") then if os.is("Windows") then

View File

@@ -15,9 +15,9 @@ bool keepStaticObjects = false;
#include "renderscene.h" #include "renderscene.h"
#include "GLInstancingRenderer.h" #include "GLInstancingRenderer.h"
//#include "LinearMath/btQuickprof.h" //#include "LinearMath/b3Quickprof.h"
#include "BulletCommon/btQuaternion.h" #include "BulletCommon/b3Quaternion.h"
#include "BulletCommon/btMatrix3x3.h" #include "BulletCommon/b3Matrix3x3.h"
//#include "../opencl/gpu_rigidbody_pipeline/b3ConvexUtility.h" //#include "../opencl/gpu_rigidbody_pipeline/b3ConvexUtility.h"
#include "ShapeData.h" #include "ShapeData.h"
///work-in-progress ///work-in-progress
@@ -49,7 +49,7 @@ struct InstanceGroup
// Bullet::btCollisionShapeData* m_shape; // Bullet::btCollisionShapeData* m_shape;
int m_collisionShapeIndex; int m_collisionShapeIndex;
// btAlignedObjectArray<bParse::bStructHandle*> m_rigidBodies; // b3AlignedObjectArray<bParse::bStructHandle*> m_rigidBodies;
}; };
@@ -57,50 +57,50 @@ struct InstanceGroup
#define MY_UNITSPHERE_POINTS 42 #define MY_UNITSPHERE_POINTS 42
static btVector3 sUnitSpherePoints[MY_UNITSPHERE_POINTS] = static b3Vector3 sUnitSpherePoints[MY_UNITSPHERE_POINTS] =
{ {
btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)), b3Vector3(b3Scalar(0.000000) , b3Scalar(-0.000000),b3Scalar(-1.000000)),
btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)), b3Vector3(b3Scalar(0.723608) , b3Scalar(-0.525725),b3Scalar(-0.447219)),
btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)), b3Vector3(b3Scalar(-0.276388) , b3Scalar(-0.850649),b3Scalar(-0.447219)),
btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)), b3Vector3(b3Scalar(-0.894426) , b3Scalar(-0.000000),b3Scalar(-0.447216)),
btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)), b3Vector3(b3Scalar(-0.276388) , b3Scalar(0.850649),b3Scalar(-0.447220)),
btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)), b3Vector3(b3Scalar(0.723608) , b3Scalar(0.525725),b3Scalar(-0.447219)),
btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)), b3Vector3(b3Scalar(0.276388) , b3Scalar(-0.850649),b3Scalar(0.447220)),
btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)), b3Vector3(b3Scalar(-0.723608) , b3Scalar(-0.525725),b3Scalar(0.447219)),
btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)), b3Vector3(b3Scalar(-0.723608) , b3Scalar(0.525725),b3Scalar(0.447219)),
btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)), b3Vector3(b3Scalar(0.276388) , b3Scalar(0.850649),b3Scalar(0.447219)),
btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)), b3Vector3(b3Scalar(0.894426) , b3Scalar(0.000000),b3Scalar(0.447216)),
btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)), b3Vector3(b3Scalar(-0.000000) , b3Scalar(0.000000),b3Scalar(1.000000)),
btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)), b3Vector3(b3Scalar(0.425323) , b3Scalar(-0.309011),b3Scalar(-0.850654)),
btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)), b3Vector3(b3Scalar(-0.162456) , b3Scalar(-0.499995),b3Scalar(-0.850654)),
btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)), b3Vector3(b3Scalar(0.262869) , b3Scalar(-0.809012),b3Scalar(-0.525738)),
btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)), b3Vector3(b3Scalar(0.425323) , b3Scalar(0.309011),b3Scalar(-0.850654)),
btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)), b3Vector3(b3Scalar(0.850648) , b3Scalar(-0.000000),b3Scalar(-0.525736)),
btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)), b3Vector3(b3Scalar(-0.525730) , b3Scalar(-0.000000),b3Scalar(-0.850652)),
btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)), b3Vector3(b3Scalar(-0.688190) , b3Scalar(-0.499997),b3Scalar(-0.525736)),
btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)), b3Vector3(b3Scalar(-0.162456) , b3Scalar(0.499995),b3Scalar(-0.850654)),
btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)), b3Vector3(b3Scalar(-0.688190) , b3Scalar(0.499997),b3Scalar(-0.525736)),
btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)), b3Vector3(b3Scalar(0.262869) , b3Scalar(0.809012),b3Scalar(-0.525738)),
btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)), b3Vector3(b3Scalar(0.951058) , b3Scalar(0.309013),b3Scalar(0.000000)),
btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)), b3Vector3(b3Scalar(0.951058) , b3Scalar(-0.309013),b3Scalar(0.000000)),
btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)), b3Vector3(b3Scalar(0.587786) , b3Scalar(-0.809017),b3Scalar(0.000000)),
btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)), b3Vector3(b3Scalar(0.000000) , b3Scalar(-1.000000),b3Scalar(0.000000)),
btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)), b3Vector3(b3Scalar(-0.587786) , b3Scalar(-0.809017),b3Scalar(0.000000)),
btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)), b3Vector3(b3Scalar(-0.951058) , b3Scalar(-0.309013),b3Scalar(-0.000000)),
btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)), b3Vector3(b3Scalar(-0.951058) , b3Scalar(0.309013),b3Scalar(-0.000000)),
btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)), b3Vector3(b3Scalar(-0.587786) , b3Scalar(0.809017),b3Scalar(-0.000000)),
btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)), b3Vector3(b3Scalar(-0.000000) , b3Scalar(1.000000),b3Scalar(-0.000000)),
btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)), b3Vector3(b3Scalar(0.587786) , b3Scalar(0.809017),b3Scalar(-0.000000)),
btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)), b3Vector3(b3Scalar(0.688190) , b3Scalar(-0.499997),b3Scalar(0.525736)),
btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)), b3Vector3(b3Scalar(-0.262869) , b3Scalar(-0.809012),b3Scalar(0.525738)),
btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)), b3Vector3(b3Scalar(-0.850648) , b3Scalar(0.000000),b3Scalar(0.525736)),
btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)), b3Vector3(b3Scalar(-0.262869) , b3Scalar(0.809012),b3Scalar(0.525738)),
btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)), b3Vector3(b3Scalar(0.688190) , b3Scalar(0.499997),b3Scalar(0.525736)),
btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)), b3Vector3(b3Scalar(0.525730) , b3Scalar(0.000000),b3Scalar(0.850652)),
btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)), b3Vector3(b3Scalar(0.162456) , b3Scalar(-0.499995),b3Scalar(0.850654)),
btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)), b3Vector3(b3Scalar(-0.425323) , b3Scalar(-0.309011),b3Scalar(0.850654)),
btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)), b3Vector3(b3Scalar(-0.425323) , b3Scalar(0.309011),b3Scalar(0.850654)),
btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654)) b3Vector3(b3Scalar(0.162456) , b3Scalar(0.499995),b3Scalar(0.850654))
}; };
@@ -114,7 +114,7 @@ void createSceneProgrammatically(GLInstancingRenderer& renderer)
int tetraShapeIndex = -1; int tetraShapeIndex = -1;
float position[4]={0,0,0,0}; float position[4]={0,0,0,0};
btQuaternion born(btVector3(1,0,0),SIMD_PI*0.25*0.5); b3Quaternion born(b3Vector3(1,0,0),SIMD_PI*0.25*0.5);
float orn[4] = {0,0,0,1}; float orn[4] = {0,0,0,1};
// float rotOrn[4] = {born.getX(),born.getY(),born.getZ(),born.getW()};// // float rotOrn[4] = {born.getX(),born.getY(),born.getZ(),born.getW()};//

View File

@@ -23,7 +23,7 @@ subject to the following restrictions:
#define START_POS_Y 10 #define START_POS_Y 10
#define START_POS_Z -3 #define START_POS_Z -3
#include "LinearMath/btVector3.h" #include "LinearMath/b3Vector3.h"
#include "GpuDemo.h" #include "GpuDemo.h"
//#include "GlutStuff.h" //#include "GlutStuff.h"
@@ -41,7 +41,7 @@ subject to the following restrictions:
#include "BulletDynamics/Dynamics/btRigidBody.h" #include "BulletDynamics/Dynamics/btRigidBody.h"
#include "LinearMath/btDefaultMotionState.h" #include "LinearMath/btDefaultMotionState.h"
#include "LinearMath/btQuickprof.h" #include "LinearMath/b3Quickprof.h"
#include <stdio.h> //printf debugging #include <stdio.h> //printf debugging
@@ -90,7 +90,7 @@ void GpuDemo::clientMoveAndDisplay()
btAlignedObjectArray<btVector3> vertices; b3AlignedObjectArray<b3Vector3> vertices;
void EmptyDemo::setupScene(const ConstructionInfo& ci) void EmptyDemo::setupScene(const ConstructionInfo& ci)
{ {
@@ -107,7 +107,7 @@ void SpheresDemo::setupScene(const ConstructionInfo& ci)
m_collisionShapes.push_back(sphere); m_collisionShapes.push_back(sphere);
/// Create Dynamic Objects /// Create Dynamic Objects
btTransform startTransform; b3Transform startTransform;
startTransform.setIdentity(); startTransform.setIdentity();
@@ -134,21 +134,21 @@ void SpheresDemo::setupScene(const ConstructionInfo& ci)
btCollisionShape* shape = sphere; btCollisionShape* shape = sphere;
btScalar mass = 1; b3Scalar mass = 1;
if (!ci.m_useConcaveMesh && k==0) if (!ci.m_useConcaveMesh && k==0)
mass = k==0? 0.f : 1.f; mass = k==0? 0.f : 1.f;
//rigidbody is dynamic if and only if mass is non zero, otherwise static //rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f); bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0); b3Vector3 localInertia(0,0,0);
if (isDynamic) if (isDynamic)
shape->calculateLocalInertia(mass,localInertia); shape->calculateLocalInertia(mass,localInertia);
startTransform.setOrigin(SCALING*btVector3( startTransform.setOrigin(SCALING*b3Vector3(
btScalar(gapX*i + start_x), b3Scalar(gapX*i + start_x),
btScalar(ci.gapY*k + start_y), b3Scalar(ci.gapY*k + start_y),
btScalar(gapZ*j + start_z))); b3Scalar(gapZ*j + start_z)));
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
@@ -164,24 +164,24 @@ void SpheresDemo::setupScene(const ConstructionInfo& ci)
} }
{ {
btVector3 planeNormal(0,1,0); b3Vector3 planeNormal(0,1,0);
btScalar planeConstant=0; b3Scalar planeConstant=0;
btCollisionShape* shape = new btStaticPlaneShape(planeNormal,planeConstant); btCollisionShape* shape = new btStaticPlaneShape(planeNormal,planeConstant);
//btBoxShape* plane = new btBoxShape(btVector3(100,1,100)); //btBoxShape* plane = new btBoxShape(b3Vector3(100,1,100));
//plane->initializePolyhedralFeatures(); //plane->initializePolyhedralFeatures();
//btSphereShape* shape = new btSphereShape(1000); //btSphereShape* shape = new btSphereShape(1000);
btScalar mass(0.); b3Scalar mass(0.);
//rigidbody is dynamic if and only if mass is non zero, otherwise static //rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f); bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0); b3Vector3 localInertia(0,0,0);
btTransform groundTransform; b3Transform groundTransform;
groundTransform.setIdentity(); groundTransform.setIdentity();
groundTransform.setRotation(btQuaternion(btVector3(1,0,0),0.3)); groundTransform.setRotation(b3Quaternion(b3Vector3(1,0,0),0.3));
groundTransform.setOrigin(btVector3(0,0,0)); groundTransform.setOrigin(b3Vector3(0,0,0));
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform); btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
@@ -198,18 +198,18 @@ void SpheresDemo::setupScene(const ConstructionInfo& ci)
void GpuCompoundDemo::setupScene(const ConstructionInfo& ci) void GpuCompoundDemo::setupScene(const ConstructionInfo& ci)
{ {
btCollisionShape* groundShape =0; btCollisionShape* groundShape =0;
// btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50); // btCollisionShape* groundShape = new btStaticPlaneShape(b3Vector3(0,1,0),50);
if (ci.m_useConcaveMesh) if (ci.m_useConcaveMesh)
{ {
btTriangleMesh* meshInterface = new btTriangleMesh(); btTriangleMesh* meshInterface = new btTriangleMesh();
btAlignedObjectArray<btVector3> concaveVertices; b3AlignedObjectArray<b3Vector3> concaveVertices;
concaveVertices.push_back(btVector3(0,-20,0)); concaveVertices.push_back(b3Vector3(0,-20,0));
concaveVertices.push_back(btVector3(80,10,80)); concaveVertices.push_back(b3Vector3(80,10,80));
concaveVertices.push_back(btVector3(80,10,-80)); concaveVertices.push_back(b3Vector3(80,10,-80));
concaveVertices.push_back(btVector3(-80,10,-80)); concaveVertices.push_back(b3Vector3(-80,10,-80));
concaveVertices.push_back(btVector3(-80,10,80)); concaveVertices.push_back(b3Vector3(-80,10,80));
meshInterface->addTriangle(concaveVertices[0],concaveVertices[1],concaveVertices[2],true); meshInterface->addTriangle(concaveVertices[0],concaveVertices[1],concaveVertices[2],true);
meshInterface->addTriangle(concaveVertices[0],concaveVertices[2],concaveVertices[3],true); meshInterface->addTriangle(concaveVertices[0],concaveVertices[2],concaveVertices[3],true);
@@ -217,33 +217,33 @@ void GpuCompoundDemo::setupScene(const ConstructionInfo& ci)
meshInterface->addTriangle(concaveVertices[0],concaveVertices[4],concaveVertices[1],true); meshInterface->addTriangle(concaveVertices[0],concaveVertices[4],concaveVertices[1],true);
#if 0 #if 0
groundShape = new btBvhTriangleMeshShape(meshInterface,true);//btStaticPlaneShape(btVector3(0,1,0),50); groundShape = new btBvhTriangleMeshShape(meshInterface,true);//btStaticPlaneShape(b3Vector3(0,1,0),50);
#else #else
btBoxShape* shape =new btBoxShape(btVector3(btScalar(250.),btScalar(10.),btScalar(250.))); btBoxShape* shape =new btBoxShape(b3Vector3(b3Scalar(250.),b3Scalar(10.),b3Scalar(250.)));
shape->initializePolyhedralFeatures(); shape->initializePolyhedralFeatures();
groundShape = shape; groundShape = shape;
#endif #endif
} else } else
{ {
groundShape = new btBoxShape(btVector3(btScalar(250.),btScalar(50.),btScalar(250.))); groundShape = new btBoxShape(b3Vector3(b3Scalar(250.),b3Scalar(50.),b3Scalar(250.)));
} }
m_collisionShapes.push_back(groundShape); m_collisionShapes.push_back(groundShape);
btTransform groundTransform; b3Transform groundTransform;
groundTransform.setIdentity(); groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0,0,0)); groundTransform.setOrigin(b3Vector3(0,0,0));
//We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here: //We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
if (ci.m_useConcaveMesh) if (ci.m_useConcaveMesh)
{ {
btScalar mass(0.); b3Scalar mass(0.);
//rigidbody is dynamic if and only if mass is non zero, otherwise static //rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f); bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0); b3Vector3 localInertia(0,0,0);
if (isDynamic) if (isDynamic)
groundShape->calculateLocalInertia(mass,localInertia); groundShape->calculateLocalInertia(mass,localInertia);
@@ -261,15 +261,15 @@ void GpuCompoundDemo::setupScene(const ConstructionInfo& ci)
//create a few dynamic rigidbodies //create a few dynamic rigidbodies
// Re-using the same collision is better for memory usage and performance // Re-using the same collision is better for memory usage and performance
//vertices.push_back(btVector3(0,1,0)); //vertices.push_back(b3Vector3(0,1,0));
vertices.push_back(btVector3(1,1,1)); vertices.push_back(b3Vector3(1,1,1));
vertices.push_back(btVector3(1,1,-1)); vertices.push_back(b3Vector3(1,1,-1));
vertices.push_back(btVector3(-1,1,-1)); vertices.push_back(b3Vector3(-1,1,-1));
vertices.push_back(btVector3(-1,1,1)); vertices.push_back(b3Vector3(-1,1,1));
vertices.push_back(btVector3(1,-1,1)); vertices.push_back(b3Vector3(1,-1,1));
vertices.push_back(btVector3(1,-1,-1)); vertices.push_back(b3Vector3(1,-1,-1));
vertices.push_back(btVector3(-1,-1,-1)); vertices.push_back(b3Vector3(-1,-1,-1));
vertices.push_back(btVector3(-1,-1,1)); vertices.push_back(b3Vector3(-1,-1,1));
#if 0 #if 0
btPolyhedralConvexShape* colShape = new btConvexHullShape(&vertices[0].getX(),vertices.size()); btPolyhedralConvexShape* colShape = new btConvexHullShape(&vertices[0].getX(),vertices.size());
@@ -280,13 +280,13 @@ void GpuCompoundDemo::setupScene(const ConstructionInfo& ci)
btPolyhedralConvexShape* colShape = new btConvexHullShape(&vertices[0].getX(),vertices.size()); btPolyhedralConvexShape* colShape = new btConvexHullShape(&vertices[0].getX(),vertices.size());
colShape->initializePolyhedralFeatures(); colShape->initializePolyhedralFeatures();
compoundShape = new btCompoundShape(); compoundShape = new btCompoundShape();
btTransform tr; b3Transform tr;
tr.setIdentity(); tr.setIdentity();
tr.setOrigin(btVector3(0,-1,0)); tr.setOrigin(b3Vector3(0,-1,0));
compoundShape->addChildShape(tr,colShape); compoundShape->addChildShape(tr,colShape);
tr.setOrigin(btVector3(0,0,2)); tr.setOrigin(b3Vector3(0,0,2));
compoundShape->addChildShape(tr,colShape); compoundShape->addChildShape(tr,colShape);
tr.setOrigin(btVector3(2,0,0)); tr.setOrigin(b3Vector3(2,0,0));
compoundShape->addChildShape(tr,colShape); compoundShape->addChildShape(tr,colShape);
} }
btCollisionShape* colShape = compoundShape; btCollisionShape* colShape = compoundShape;
@@ -294,18 +294,18 @@ void GpuCompoundDemo::setupScene(const ConstructionInfo& ci)
btPolyhedralConvexShape* boxShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,SCALING*1)); btPolyhedralConvexShape* boxShape = new btBoxShape(b3Vector3(SCALING*1,SCALING*1,SCALING*1));
boxShape->initializePolyhedralFeatures(); boxShape->initializePolyhedralFeatures();
//btCollisionShape* colShape = new btSphereShape(btScalar(1.)); //btCollisionShape* colShape = new btSphereShape(b3Scalar(1.));
m_collisionShapes.push_back(colShape); m_collisionShapes.push_back(colShape);
m_collisionShapes.push_back(boxShape); m_collisionShapes.push_back(boxShape);
/// Create Dynamic Objects /// Create Dynamic Objects
btTransform startTransform; b3Transform startTransform;
startTransform.setIdentity(); startTransform.setIdentity();
@@ -334,21 +334,21 @@ void GpuCompoundDemo::setupScene(const ConstructionInfo& ci)
btCollisionShape* shape = colShape; btCollisionShape* shape = colShape;
btScalar mass = 1; b3Scalar mass = 1;
if (!ci.m_useConcaveMesh && k==0) if (!ci.m_useConcaveMesh && k==0)
mass = k==0? 0.f : 1.f; mass = k==0? 0.f : 1.f;
//rigidbody is dynamic if and only if mass is non zero, otherwise static //rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f); bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0); b3Vector3 localInertia(0,0,0);
if (isDynamic) if (isDynamic)
shape->calculateLocalInertia(mass,localInertia); shape->calculateLocalInertia(mass,localInertia);
startTransform.setOrigin(SCALING*btVector3( startTransform.setOrigin(SCALING*b3Vector3(
btScalar(startX+gapX*i + start_x), b3Scalar(startX+gapX*i + start_x),
btScalar(20+ci.gapY*k + start_y), b3Scalar(20+ci.gapY*k + start_y),
btScalar(startZ+gapZ*j + start_z))); b3Scalar(startZ+gapZ*j + start_z)));
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
@@ -369,18 +369,18 @@ void GpuCompoundDemo::setupScene(const ConstructionInfo& ci)
void GpuBoxDemo::setupScene(const ConstructionInfo& ci) void GpuBoxDemo::setupScene(const ConstructionInfo& ci)
{ {
btCollisionShape* groundShape =0; btCollisionShape* groundShape =0;
// btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50); // btCollisionShape* groundShape = new btStaticPlaneShape(b3Vector3(0,1,0),50);
if (ci.m_useConcaveMesh) if (ci.m_useConcaveMesh)
{ {
btTriangleMesh* meshInterface = new btTriangleMesh(); btTriangleMesh* meshInterface = new btTriangleMesh();
btAlignedObjectArray<btVector3> concaveVertices; b3AlignedObjectArray<b3Vector3> concaveVertices;
concaveVertices.push_back(btVector3(0,-20,0)); concaveVertices.push_back(b3Vector3(0,-20,0));
concaveVertices.push_back(btVector3(80,10,80)); concaveVertices.push_back(b3Vector3(80,10,80));
concaveVertices.push_back(btVector3(80,10,-80)); concaveVertices.push_back(b3Vector3(80,10,-80));
concaveVertices.push_back(btVector3(-80,10,-80)); concaveVertices.push_back(b3Vector3(-80,10,-80));
concaveVertices.push_back(btVector3(-80,10,80)); concaveVertices.push_back(b3Vector3(-80,10,80));
meshInterface->addTriangle(concaveVertices[0],concaveVertices[1],concaveVertices[2],true); meshInterface->addTriangle(concaveVertices[0],concaveVertices[1],concaveVertices[2],true);
meshInterface->addTriangle(concaveVertices[0],concaveVertices[2],concaveVertices[3],true); meshInterface->addTriangle(concaveVertices[0],concaveVertices[2],concaveVertices[3],true);
@@ -388,33 +388,33 @@ void GpuBoxDemo::setupScene(const ConstructionInfo& ci)
meshInterface->addTriangle(concaveVertices[0],concaveVertices[4],concaveVertices[1],true); meshInterface->addTriangle(concaveVertices[0],concaveVertices[4],concaveVertices[1],true);
#if 0 #if 0
groundShape = new btBvhTriangleMeshShape(meshInterface,true);//btStaticPlaneShape(btVector3(0,1,0),50); groundShape = new btBvhTriangleMeshShape(meshInterface,true);//btStaticPlaneShape(b3Vector3(0,1,0),50);
#else #else
btBoxShape* shape =new btBoxShape(btVector3(btScalar(250.),btScalar(10.),btScalar(250.))); btBoxShape* shape =new btBoxShape(b3Vector3(b3Scalar(250.),b3Scalar(10.),b3Scalar(250.)));
shape->initializePolyhedralFeatures(); shape->initializePolyhedralFeatures();
groundShape = shape; groundShape = shape;
#endif #endif
} else } else
{ {
groundShape = new btBoxShape(btVector3(btScalar(250.),btScalar(50.),btScalar(250.))); groundShape = new btBoxShape(b3Vector3(b3Scalar(250.),b3Scalar(50.),b3Scalar(250.)));
} }
m_collisionShapes.push_back(groundShape); m_collisionShapes.push_back(groundShape);
btTransform groundTransform; b3Transform groundTransform;
groundTransform.setIdentity(); groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0,0,0)); groundTransform.setOrigin(b3Vector3(0,0,0));
//We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here: //We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
if (ci.m_useConcaveMesh) if (ci.m_useConcaveMesh)
{ {
btScalar mass(0.); b3Scalar mass(0.);
//rigidbody is dynamic if and only if mass is non zero, otherwise static //rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f); bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0); b3Vector3 localInertia(0,0,0);
if (isDynamic) if (isDynamic)
groundShape->calculateLocalInertia(mass,localInertia); groundShape->calculateLocalInertia(mass,localInertia);
@@ -432,15 +432,15 @@ void GpuBoxDemo::setupScene(const ConstructionInfo& ci)
//create a few dynamic rigidbodies //create a few dynamic rigidbodies
// Re-using the same collision is better for memory usage and performance // Re-using the same collision is better for memory usage and performance
//vertices.push_back(btVector3(0,1,0)); //vertices.push_back(b3Vector3(0,1,0));
vertices.push_back(btVector3(1,1,1)); vertices.push_back(b3Vector3(1,1,1));
vertices.push_back(btVector3(1,1,-1)); vertices.push_back(b3Vector3(1,1,-1));
vertices.push_back(btVector3(-1,1,-1)); vertices.push_back(b3Vector3(-1,1,-1));
vertices.push_back(btVector3(-1,1,1)); vertices.push_back(b3Vector3(-1,1,1));
vertices.push_back(btVector3(1,-1,1)); vertices.push_back(b3Vector3(1,-1,1));
vertices.push_back(btVector3(1,-1,-1)); vertices.push_back(b3Vector3(1,-1,-1));
vertices.push_back(btVector3(-1,-1,-1)); vertices.push_back(b3Vector3(-1,-1,-1));
vertices.push_back(btVector3(-1,-1,1)); vertices.push_back(b3Vector3(-1,-1,1));
#if 1 #if 1
btPolyhedralConvexShape* colShape = new btConvexHullShape(&vertices[0].getX(),vertices.size()); btPolyhedralConvexShape* colShape = new btConvexHullShape(&vertices[0].getX(),vertices.size());
@@ -451,13 +451,13 @@ void GpuBoxDemo::setupScene(const ConstructionInfo& ci)
btPolyhedralConvexShape* colShape = new btConvexHullShape(&vertices[0].getX(),vertices.size()); btPolyhedralConvexShape* colShape = new btConvexHullShape(&vertices[0].getX(),vertices.size());
colShape->initializePolyhedralFeatures(); colShape->initializePolyhedralFeatures();
compoundShape = new btCompoundShape(); compoundShape = new btCompoundShape();
btTransform tr; b3Transform tr;
tr.setIdentity(); tr.setIdentity();
tr.setOrigin(btVector3(0,-1,0)); tr.setOrigin(b3Vector3(0,-1,0));
compoundShape->addChildShape(tr,colShape); compoundShape->addChildShape(tr,colShape);
tr.setOrigin(btVector3(0,0,2)); tr.setOrigin(b3Vector3(0,0,2));
compoundShape->addChildShape(tr,colShape); compoundShape->addChildShape(tr,colShape);
tr.setOrigin(btVector3(2,0,0)); tr.setOrigin(b3Vector3(2,0,0));
compoundShape->addChildShape(tr,colShape); compoundShape->addChildShape(tr,colShape);
} }
btCollisionShape* colShape = compoundShape; btCollisionShape* colShape = compoundShape;
@@ -465,18 +465,18 @@ void GpuBoxDemo::setupScene(const ConstructionInfo& ci)
btPolyhedralConvexShape* boxShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,SCALING*1)); btPolyhedralConvexShape* boxShape = new btBoxShape(b3Vector3(SCALING*1,SCALING*1,SCALING*1));
boxShape->initializePolyhedralFeatures(); boxShape->initializePolyhedralFeatures();
//btCollisionShape* colShape = new btSphereShape(btScalar(1.)); //btCollisionShape* colShape = new btSphereShape(b3Scalar(1.));
m_collisionShapes.push_back(colShape); m_collisionShapes.push_back(colShape);
m_collisionShapes.push_back(boxShape); m_collisionShapes.push_back(boxShape);
/// Create Dynamic Objects /// Create Dynamic Objects
btTransform startTransform; b3Transform startTransform;
startTransform.setIdentity(); startTransform.setIdentity();
@@ -505,21 +505,21 @@ void GpuBoxDemo::setupScene(const ConstructionInfo& ci)
btCollisionShape* shape = colShape; btCollisionShape* shape = colShape;
btScalar mass = 1; b3Scalar mass = 1;
if (!ci.m_useConcaveMesh && k==0) if (!ci.m_useConcaveMesh && k==0)
mass = k==0? 0.f : 1.f; mass = k==0? 0.f : 1.f;
//rigidbody is dynamic if and only if mass is non zero, otherwise static //rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f); bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0); b3Vector3 localInertia(0,0,0);
if (isDynamic) if (isDynamic)
shape->calculateLocalInertia(mass,localInertia); shape->calculateLocalInertia(mass,localInertia);
startTransform.setOrigin(SCALING*btVector3( startTransform.setOrigin(SCALING*b3Vector3(
btScalar(startX+gapX*i + start_x), b3Scalar(startX+gapX*i + start_x),
btScalar(ci.gapY*(k+0.5) + start_y), b3Scalar(ci.gapY*(k+0.5) + start_y),
btScalar(startZ+gapZ*j + start_z))); b3Scalar(startZ+gapZ*j + start_z)));
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
@@ -541,7 +541,7 @@ void GpuDemo::initPhysics(const ConstructionInfo& ci)
// setTexturing(true); // setTexturing(true);
//setShadows(false); //setShadows(false);
// setCameraDistance(btScalar(SCALING*250.)); // setCameraDistance(b3Scalar(SCALING*250.));
///collision configuration contains default setup for memory, collision setup ///collision configuration contains default setup for memory, collision setup
if (ci.useOpenCL) if (ci.useOpenCL)
@@ -553,7 +553,7 @@ void GpuDemo::initPhysics(const ConstructionInfo& ci)
} }
m_dynamicsWorld->setGravity(btVector3(0,-10,0)); m_dynamicsWorld->setGravity(b3Vector3(0,-10,0));
///create a few basic rigid bodies ///create a few basic rigid bodies

View File

@@ -16,7 +16,7 @@ subject to the following restrictions:
#define GPU_DEMO_H #define GPU_DEMO_H
#include "BulletCommon/btAlignedObjectArray.h" #include "BulletCommon/b3AlignedObjectArray.h"
class btBroadphaseInterface; class btBroadphaseInterface;
@@ -41,7 +41,7 @@ protected:
btDynamicsWorld* m_dynamicsWorld; btDynamicsWorld* m_dynamicsWorld;
//keep the collision shapes, for deletion/cleanup //keep the collision shapes, for deletion/cleanup
btAlignedObjectArray<btCollisionShape*> m_collisionShapes; b3AlignedObjectArray<btCollisionShape*> m_collisionShapes;
float getDeltaTimeInSeconds() float getDeltaTimeInSeconds()
{ {

View File

@@ -4,7 +4,7 @@
#include "OpenGLWindow/ShapeData.h" #include "OpenGLWindow/ShapeData.h"
//#include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h" //#include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h"
//#include "BulletCollision/CollisionDispatch/btCollisionObject.h" //#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
/*#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" /*#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
#include "BulletCollision/CollisionShapes/btConvexPolyhedron.h" #include "BulletCollision/CollisionShapes/btConvexPolyhedron.h"
@@ -64,20 +64,20 @@ struct GraphicsShape
GraphicsShape* createGraphicsShapeFromConvexHull(const btConvexPolyhedron* utilPtr) GraphicsShape* createGraphicsShapeFromConvexHull(const btConvexPolyhedron* utilPtr)
{ {
btAlignedObjectArray<GraphicsVertex>* vertices = new btAlignedObjectArray<GraphicsVertex>; b3AlignedObjectArray<GraphicsVertex>* vertices = new b3AlignedObjectArray<GraphicsVertex>;
{ {
int numVertices = utilPtr->m_vertices.size(); int numVertices = utilPtr->m_vertices.size();
int numIndices = 0; int numIndices = 0;
btAlignedObjectArray<int>* indicesPtr = new btAlignedObjectArray<int>; b3AlignedObjectArray<int>* indicesPtr = new b3AlignedObjectArray<int>;
for (int f=0;f<utilPtr->m_faces.size();f++) for (int f=0;f<utilPtr->m_faces.size();f++)
{ {
const btFace& face = utilPtr->m_faces[f]; const btFace& face = utilPtr->m_faces[f];
btVector3 normal(face.m_plane[0],face.m_plane[1],face.m_plane[2]); b3Vector3 normal(face.m_plane[0],face.m_plane[1],face.m_plane[2]);
if (face.m_indices.size()>2) if (face.m_indices.size()>2)
{ {
GraphicsVertex vtx; GraphicsVertex vtx;
const btVector3& orgVertex = utilPtr->m_vertices[face.m_indices[0]]; const b3Vector3& orgVertex = utilPtr->m_vertices[face.m_indices[0]];
vtx.xyzw[0] = orgVertex[0];vtx.xyzw[1] = orgVertex[1];vtx.xyzw[2] = orgVertex[2];vtx.xyzw[3] = 0.f; vtx.xyzw[0] = orgVertex[0];vtx.xyzw[1] = orgVertex[1];vtx.xyzw[2] = orgVertex[2];vtx.xyzw[3] = 0.f;
vtx.normal[0] = normal[0];vtx.normal[1] = normal[1];vtx.normal[2] = normal[2]; vtx.normal[0] = normal[0];vtx.normal[1] = normal[1];vtx.normal[2] = normal[2];
vtx.uv[0] = 0.5f;vtx.uv[1] = 0.5f; vtx.uv[0] = 0.5f;vtx.uv[1] = 0.5f;
@@ -89,7 +89,7 @@ GraphicsShape* createGraphicsShapeFromConvexHull(const btConvexPolyhedron* utilP
indicesPtr->push_back(newvtxindex0); indicesPtr->push_back(newvtxindex0);
{ {
GraphicsVertex vtx; GraphicsVertex vtx;
const btVector3& orgVertex = utilPtr->m_vertices[face.m_indices[j]]; const b3Vector3& orgVertex = utilPtr->m_vertices[face.m_indices[j]];
vtx.xyzw[0] = orgVertex[0];vtx.xyzw[1] = orgVertex[1];vtx.xyzw[2] = orgVertex[2];vtx.xyzw[3] = 0.f; vtx.xyzw[0] = orgVertex[0];vtx.xyzw[1] = orgVertex[1];vtx.xyzw[2] = orgVertex[2];vtx.xyzw[3] = 0.f;
vtx.normal[0] = normal[0];vtx.normal[1] = normal[1];vtx.normal[2] = normal[2]; vtx.normal[0] = normal[0];vtx.normal[1] = normal[1];vtx.normal[2] = normal[2];
vtx.uv[0] = 0.5f;vtx.uv[1] = 0.5f; vtx.uv[0] = 0.5f;vtx.uv[1] = 0.5f;
@@ -100,7 +100,7 @@ GraphicsShape* createGraphicsShapeFromConvexHull(const btConvexPolyhedron* utilP
{ {
GraphicsVertex vtx; GraphicsVertex vtx;
const btVector3& orgVertex = utilPtr->m_vertices[face.m_indices[j+1]]; const b3Vector3& orgVertex = utilPtr->m_vertices[face.m_indices[j+1]];
vtx.xyzw[0] = orgVertex[0];vtx.xyzw[1] = orgVertex[1];vtx.xyzw[2] = orgVertex[2];vtx.xyzw[3] = 0.f; vtx.xyzw[0] = orgVertex[0];vtx.xyzw[1] = orgVertex[1];vtx.xyzw[2] = orgVertex[2];vtx.xyzw[3] = 0.f;
vtx.normal[0] = normal[0];vtx.normal[1] = normal[1];vtx.normal[2] = normal[2]; vtx.normal[0] = normal[0];vtx.normal[1] = normal[1];vtx.normal[2] = normal[2];
vtx.uv[0] = 0.5f;vtx.uv[1] = 0.5f; vtx.uv[0] = 0.5f;vtx.uv[1] = 0.5f;
@@ -127,8 +127,8 @@ GraphicsShape* createGraphicsShapeFromConvexHull(const btConvexPolyhedron* utilP
GraphicsShape* createGraphicsShapeFromCompoundShape(btCompoundShape* compound) GraphicsShape* createGraphicsShapeFromCompoundShape(btCompoundShape* compound)
{ {
GraphicsShape* gfxShape = new GraphicsShape(); GraphicsShape* gfxShape = new GraphicsShape();
btAlignedObjectArray<GraphicsVertex>* vertexArray = new btAlignedObjectArray<GraphicsVertex>; b3AlignedObjectArray<GraphicsVertex>* vertexArray = new b3AlignedObjectArray<GraphicsVertex>;
btAlignedObjectArray<int>* indexArray = new btAlignedObjectArray<int>; b3AlignedObjectArray<int>* indexArray = new b3AlignedObjectArray<int>;
@@ -139,7 +139,7 @@ GraphicsShape* createGraphicsShapeFromCompoundShape(btCompoundShape* compound)
if (compound->getChildShape(i)->isPolyhedral()) if (compound->getChildShape(i)->isPolyhedral())
{ {
btPolyhedralConvexShape* convexHull = (btPolyhedralConvexShape*) compound->getChildShape(i); btPolyhedralConvexShape* convexHull = (btPolyhedralConvexShape*) compound->getChildShape(i);
btTransform tr = compound->getChildTransform(i); b3Transform tr = compound->getChildTransform(i);
const btConvexPolyhedron* polyhedron = convexHull->getConvexPolyhedron(); const btConvexPolyhedron* polyhedron = convexHull->getConvexPolyhedron();
GraphicsShape* childGfxShape = createGraphicsShapeFromConvexHull(polyhedron); GraphicsShape* childGfxShape = createGraphicsShapeFromConvexHull(polyhedron);
@@ -153,7 +153,7 @@ GraphicsShape* createGraphicsShapeFromCompoundShape(btCompoundShape* compound)
for (int j=0;j<childGfxShape->m_numvertices;j++) for (int j=0;j<childGfxShape->m_numvertices;j++)
{ {
GraphicsVertex vtx; GraphicsVertex vtx;
btVector3 pos(orgVerts[j].xyzw[0],orgVerts[j].xyzw[1],orgVerts[j].xyzw[2]); b3Vector3 pos(orgVerts[j].xyzw[0],orgVerts[j].xyzw[1],orgVerts[j].xyzw[2]);
pos = tr*pos; pos = tr*pos;
vtx.xyzw[0] = childGfxShape->m_scaling[0]*pos.getX(); vtx.xyzw[0] = childGfxShape->m_scaling[0]*pos.getX();
vtx.xyzw[1] = childGfxShape->m_scaling[1]*pos.getY(); vtx.xyzw[1] = childGfxShape->m_scaling[1]*pos.getY();
@@ -163,7 +163,7 @@ GraphicsShape* createGraphicsShapeFromCompoundShape(btCompoundShape* compound)
vtx.uv[0] = 0.5f; vtx.uv[0] = 0.5f;
vtx.uv[1] = 0.5f; vtx.uv[1] = 0.5f;
btVector3 normal(orgVerts[j].normal[0],orgVerts[j].normal[1],orgVerts[j].normal[2]); b3Vector3 normal(orgVerts[j].normal[0],orgVerts[j].normal[1],orgVerts[j].normal[2]);
normal = tr.getBasis()*normal; normal = tr.getBasis()*normal;
vtx.normal[0] = normal.getX(); vtx.normal[0] = normal.getX();
vtx.normal[1] = normal.getY(); vtx.normal[1] = normal.getY();
@@ -192,12 +192,12 @@ GraphicsShape* createGraphicsShapeFromCompoundShape(btCompoundShape* compound)
GraphicsShape* createGraphicsShapeFromConcaveMesh(const btBvhTriangleMeshShape* trimesh) GraphicsShape* createGraphicsShapeFromConcaveMesh(const btBvhTriangleMeshShape* trimesh)
{ {
btAlignedObjectArray<GraphicsVertex>* vertices = new btAlignedObjectArray<GraphicsVertex>; b3AlignedObjectArray<GraphicsVertex>* vertices = new b3AlignedObjectArray<GraphicsVertex>;
btAlignedObjectArray<int>* indicesPtr = new btAlignedObjectArray<int>; b3AlignedObjectArray<int>* indicesPtr = new b3AlignedObjectArray<int>;
const b3StridingMeshInterface* meshInterface = trimesh->getMeshInterface(); const b3StridingMeshInterface* meshInterface = trimesh->getMeshInterface();
btVector3 trimeshScaling(1,1,1); b3Vector3 trimeshScaling(1,1,1);
for (int partId=0;partId<meshInterface->getNumSubParts();partId++) for (int partId=0;partId<meshInterface->getNumSubParts();partId++)
{ {
@@ -211,9 +211,9 @@ GraphicsShape* createGraphicsShapeFromConcaveMesh(const btBvhTriangleMeshShape*
PHY_ScalarType indicestype = PHY_INTEGER; PHY_ScalarType indicestype = PHY_INTEGER;
//PHY_ScalarType indexType=0; //PHY_ScalarType indexType=0;
btVector3 triangleVerts[3]; b3Vector3 triangleVerts[3];
meshInterface->getLockedReadOnlyVertexIndexBase(&vertexbase,numverts, type,stride,&indexbase,indexstride,numfaces,indicestype,partId); meshInterface->getLockedReadOnlyVertexIndexBase(&vertexbase,numverts, type,stride,&indexbase,indexstride,numfaces,indicestype,partId);
btVector3 aabbMin,aabbMax; b3Vector3 aabbMin,aabbMax;
for (int triangleIndex = 0 ; triangleIndex < numfaces;triangleIndex++) for (int triangleIndex = 0 ; triangleIndex < numfaces;triangleIndex++)
{ {
@@ -226,7 +226,7 @@ GraphicsShape* createGraphicsShapeFromConcaveMesh(const btBvhTriangleMeshShape*
if (type == PHY_FLOAT) if (type == PHY_FLOAT)
{ {
float* graphicsbase = (float*)(vertexbase+graphicsindex*stride); float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
triangleVerts[j] = btVector3( triangleVerts[j] = b3Vector3(
graphicsbase[0]*trimeshScaling.getX(), graphicsbase[0]*trimeshScaling.getX(),
graphicsbase[1]*trimeshScaling.getY(), graphicsbase[1]*trimeshScaling.getY(),
graphicsbase[2]*trimeshScaling.getZ()); graphicsbase[2]*trimeshScaling.getZ());
@@ -234,12 +234,12 @@ GraphicsShape* createGraphicsShapeFromConcaveMesh(const btBvhTriangleMeshShape*
else else
{ {
double* graphicsbase = (double*)(vertexbase+graphicsindex*stride); double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
triangleVerts[j] = btVector3( btScalar(graphicsbase[0]*trimeshScaling.getX()), triangleVerts[j] = b3Vector3( b3Scalar(graphicsbase[0]*trimeshScaling.getX()),
btScalar(graphicsbase[1]*trimeshScaling.getY()), b3Scalar(graphicsbase[1]*trimeshScaling.getY()),
btScalar(graphicsbase[2]*trimeshScaling.getZ())); b3Scalar(graphicsbase[2]*trimeshScaling.getZ()));
} }
} }
btVector3 normal = (triangleVerts[2]-triangleVerts[0]).cross(triangleVerts[1]-triangleVerts[0]); b3Vector3 normal = (triangleVerts[2]-triangleVerts[0]).cross(triangleVerts[1]-triangleVerts[0]);
normal.normalize(); normal.normalize();
GraphicsVertex vtx0,vtx1,vtx2; GraphicsVertex vtx0,vtx1,vtx2;
@@ -299,18 +299,18 @@ GraphicsShape* createGraphicsShapeFromConcaveMesh(const btBvhTriangleMeshShape*
GraphicsShape* createGraphicsShapeFromWavefrontObj(objLoader* obj) GraphicsShape* createGraphicsShapeFromWavefrontObj(objLoader* obj)
{ {
btAlignedObjectArray<GraphicsVertex>* vertices = new btAlignedObjectArray<GraphicsVertex>; b3AlignedObjectArray<GraphicsVertex>* vertices = new b3AlignedObjectArray<GraphicsVertex>;
{ {
// int numVertices = obj->vertexCount; // int numVertices = obj->vertexCount;
// int numIndices = 0; // int numIndices = 0;
btAlignedObjectArray<int>* indicesPtr = new btAlignedObjectArray<int>; b3AlignedObjectArray<int>* indicesPtr = new b3AlignedObjectArray<int>;
/* /*
for (int v=0;v<obj->vertexCount;v++) for (int v=0;v<obj->vertexCount;v++)
{ {
vtx.xyzw[0] = obj->vertexList[v]->e[0]; vtx.xyzw[0] = obj->vertexList[v]->e[0];
vtx.xyzw[1] = obj->vertexList[v]->e[1]; vtx.xyzw[1] = obj->vertexList[v]->e[1];
vtx.xyzw[2] = obj->vertexList[v]->e[2]; vtx.xyzw[2] = obj->vertexList[v]->e[2];
btVector3 n(vtx.xyzw[0],vtx.xyzw[1],vtx.xyzw[2]); b3Vector3 n(vtx.xyzw[0],vtx.xyzw[1],vtx.xyzw[2]);
if (n.length2()>SIMD_EPSILON) if (n.length2()>SIMD_EPSILON)
{ {
n.normalize(); n.normalize();
@@ -332,10 +332,10 @@ GraphicsShape* createGraphicsShapeFromWavefrontObj(objLoader* obj)
for (int f=0;f<obj->faceCount;f++) for (int f=0;f<obj->faceCount;f++)
{ {
obj_face* face = obj->faceList[f]; obj_face* face = obj->faceList[f];
//btVector3 normal(face.m_plane[0],face.m_plane[1],face.m_plane[2]); //b3Vector3 normal(face.m_plane[0],face.m_plane[1],face.m_plane[2]);
if (face->vertex_count>=3) if (face->vertex_count>=3)
{ {
btVector3 normal(0,1,0); b3Vector3 normal(0,1,0);
int vtxBaseIndex = vertices->size(); int vtxBaseIndex = vertices->size();
if (face->vertex_count<=4) if (face->vertex_count<=4)
@@ -366,9 +366,9 @@ GraphicsShape* createGraphicsShapeFromWavefrontObj(objLoader* obj)
vtx2.uv[1] = obj->textureList[face->vertex_index[2]]->e[1]; vtx2.uv[1] = obj->textureList[face->vertex_index[2]]->e[1];
btVector3 v0(vtx0.xyzw[0],vtx0.xyzw[1],vtx0.xyzw[2]); b3Vector3 v0(vtx0.xyzw[0],vtx0.xyzw[1],vtx0.xyzw[2]);
btVector3 v1(vtx1.xyzw[0],vtx1.xyzw[1],vtx1.xyzw[2]); b3Vector3 v1(vtx1.xyzw[0],vtx1.xyzw[1],vtx1.xyzw[2]);
btVector3 v2(vtx2.xyzw[0],vtx2.xyzw[1],vtx2.xyzw[2]); b3Vector3 v2(vtx2.xyzw[0],vtx2.xyzw[1],vtx2.xyzw[2]);
normal = (v1-v0).cross(v2-v0); normal = (v1-v0).cross(v2-v0);
normal.normalize(); normal.normalize();
@@ -446,13 +446,13 @@ void graphics_from_physics(GLInstancingRenderer& renderer, bool syncTransformsOn
{ {
btCollisionObject* colObj = colObjArray[i]; btCollisionObject* colObj = colObjArray[i];
btVector3 pos = colObj->getWorldTransform().getOrigin(); b3Vector3 pos = colObj->getWorldTransform().getOrigin();
btQuaternion orn = colObj->getWorldTransform().getRotation(); b3Quaternion orn = colObj->getWorldTransform().getRotation();
float position[4] = {pos.getX(),pos.getY(),pos.getZ(),0.f}; float position[4] = {pos.getX(),pos.getY(),pos.getZ(),0.f};
float orientation[4] = {orn.getX(),orn.getY(),orn.getZ(),orn.getW()}; float orientation[4] = {orn.getX(),orn.getY(),orn.getZ(),orn.getW()};
float color[4] = {0,0,0,1}; float color[4] = {0,0,0,1};
btVector3 localScaling = colObj->getCollisionShape()->getLocalScaling(); b3Vector3 localScaling = colObj->getCollisionShape()->getLocalScaling();
if (colObj->isStaticOrKinematicObject()) if (colObj->isStaticOrKinematicObject())
@@ -476,7 +476,7 @@ void graphics_from_physics(GLInstancingRenderer& renderer, bool syncTransformsOn
prevGraphicsShapeIndex = renderer.registerShape(&gfxShape->m_vertices[0],gfxShape->m_numvertices,gfxShape->m_indices,gfxShape->m_numIndices); prevGraphicsShapeIndex = renderer.registerShape(&gfxShape->m_vertices[0],gfxShape->m_numvertices,gfxShape->m_indices,gfxShape->m_numIndices);
prevShape = colObj->getCollisionShape(); prevShape = colObj->getCollisionShape();
const btVector3& scaling = prevShape->getLocalScaling(); const b3Vector3& scaling = prevShape->getLocalScaling();
localScaling[0] = scaling.getX();localScaling[1] = scaling.getY();localScaling[2] = scaling.getZ(); localScaling[0] = scaling.getX();localScaling[1] = scaling.getY();localScaling[2] = scaling.getZ();
} else } else
{ {
@@ -486,7 +486,7 @@ void graphics_from_physics(GLInstancingRenderer& renderer, bool syncTransformsOn
GraphicsShape* gfxShape = createGraphicsShapeFromConcaveMesh(trimesh); GraphicsShape* gfxShape = createGraphicsShapeFromConcaveMesh(trimesh);
prevGraphicsShapeIndex = renderer.registerShape(&gfxShape->m_vertices[0],gfxShape->m_numvertices,gfxShape->m_indices,gfxShape->m_numIndices); prevGraphicsShapeIndex = renderer.registerShape(&gfxShape->m_vertices[0],gfxShape->m_numvertices,gfxShape->m_indices,gfxShape->m_numIndices);
prevShape = colObj->getCollisionShape(); prevShape = colObj->getCollisionShape();
const btVector3& scaling = prevShape->getLocalScaling(); const b3Vector3& scaling = prevShape->getLocalScaling();
localScaling[0] = scaling.getX();localScaling[1] = scaling.getY();localScaling[2] = scaling.getZ(); localScaling[0] = scaling.getX();localScaling[1] = scaling.getY();localScaling[2] = scaling.getZ();
} else } else
{ {
@@ -498,7 +498,7 @@ void graphics_from_physics(GLInstancingRenderer& renderer, bool syncTransformsOn
{ {
prevGraphicsShapeIndex = renderer.registerShape(&gfxShape->m_vertices[0],gfxShape->m_numvertices,gfxShape->m_indices,gfxShape->m_numIndices); prevGraphicsShapeIndex = renderer.registerShape(&gfxShape->m_vertices[0],gfxShape->m_numvertices,gfxShape->m_indices,gfxShape->m_numIndices);
prevShape = colObj->getCollisionShape(); prevShape = colObj->getCollisionShape();
const btVector3& scaling = prevShape->getLocalScaling(); const b3Vector3& scaling = prevShape->getLocalScaling();
localScaling[0] = scaling.getX();localScaling[1] = scaling.getY();localScaling[2] = scaling.getZ(); localScaling[0] = scaling.getX();localScaling[1] = scaling.getY();localScaling[2] = scaling.getZ();
} else } else
{ {
@@ -509,7 +509,7 @@ void graphics_from_physics(GLInstancingRenderer& renderer, bool syncTransformsOn
if (colObj->getCollisionShape()->getShapeType()==SPHERE_SHAPE_PROXYTYPE) if (colObj->getCollisionShape()->getShapeType()==SPHERE_SHAPE_PROXYTYPE)
{ {
btSphereShape* sphere = (btSphereShape*) colObj->getCollisionShape(); btSphereShape* sphere = (btSphereShape*) colObj->getCollisionShape();
btScalar radius = sphere->getRadius(); b3Scalar radius = sphere->getRadius();
//btConvexHullShape* spherePoly = new btConvexHullShape( //btConvexHullShape* spherePoly = new btConvexHullShape(
//const btConvexPolyhedron* pol = polyShape->getConvexPolyhedron(); //const btConvexPolyhedron* pol = polyShape->getConvexPolyhedron();
@@ -589,7 +589,7 @@ void graphics_from_physics(GLInstancingRenderer& renderer, bool syncTransformsOn
} }
} }
prevShape = sphere; prevShape = sphere;
const btVector3& scaling = prevShape->getLocalScaling(); const b3Vector3& scaling = prevShape->getLocalScaling();
//assume uniform scaling, using X component //assume uniform scaling, using X component
float sphereScale = radius*scaling.getX(); float sphereScale = radius*scaling.getX();
localScaling[0] = sphereScale; localScaling[0] = sphereScale;

View File

@@ -9,7 +9,7 @@
#include "BulletCollision/CollisionShapes/btSphereShape.h" #include "BulletCollision/CollisionShapes/btSphereShape.h"
#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h" #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
#include "LinearMath/btQuickprof.h" #include "LinearMath/b3Quickprof.h"
#ifdef _WIN32 #ifdef _WIN32
@@ -43,7 +43,7 @@ void btGpuDynamicsWorld::exitOpenCL()
int btGpuDynamicsWorld::stepSimulation( btScalar timeStep,int maxSubSteps, btScalar fixedTimeStep) int btGpuDynamicsWorld::stepSimulation( b3Scalar timeStep,int maxSubSteps, b3Scalar fixedTimeStep)
{ {
#ifndef BT_NO_PROFILE #ifndef BT_NO_PROFILE
// CProfileManager::Reset(); // CProfileManager::Reset();
@@ -73,10 +73,10 @@ int btGpuDynamicsWorld::stepSimulation( btScalar timeStep,int maxSubSteps, btSc
BT_PROFILE("scatter transforms into rigidbody (CPU)"); BT_PROFILE("scatter transforms into rigidbody (CPU)");
for (int i=0;i<this->m_collisionObjects.size();i++) for (int i=0;i<this->m_collisionObjects.size();i++)
{ {
btVector3 pos; b3Vector3 pos;
btQuaternion orn; b3Quaternion orn;
m_gpuPhysics->getObjectTransformFromCpu(&pos[0],&orn[0],i); m_gpuPhysics->getObjectTransformFromCpu(&pos[0],&orn[0],i);
btTransform newTrans; b3Transform newTrans;
newTrans.setOrigin(pos); newTrans.setOrigin(pos);
newTrans.setRotation(orn); newTrans.setRotation(orn);
this->m_collisionObjects[i]->setWorldTransform(newTrans); this->m_collisionObjects[i]->setWorldTransform(newTrans);
@@ -94,7 +94,7 @@ int btGpuDynamicsWorld::stepSimulation( btScalar timeStep,int maxSubSteps, btSc
} }
void btGpuDynamicsWorld::setGravity(const btVector3& gravity) void btGpuDynamicsWorld::setGravity(const b3Vector3& gravity)
{ {
} }
@@ -110,8 +110,8 @@ int btGpuDynamicsWorld::findOrRegisterCollisionShape(const btCollisionShape* col
btPolyhedralConvexShape* convex = (btPolyhedralConvexShape*)colShape; btPolyhedralConvexShape* convex = (btPolyhedralConvexShape*)colShape;
int numVertices=convex->getNumVertices(); int numVertices=convex->getNumVertices();
int strideInBytes=sizeof(btVector3); int strideInBytes=sizeof(b3Vector3);
btAlignedObjectArray<btVector3> tmpVertices; b3AlignedObjectArray<b3Vector3> tmpVertices;
tmpVertices.resize(numVertices); tmpVertices.resize(numVertices);
for (int i=0;i<numVertices;i++) for (int i=0;i<numVertices;i++)
convex->getVertex(i,tmpVertices[i]); convex->getVertex(i,tmpVertices[i]);
@@ -128,10 +128,10 @@ int btGpuDynamicsWorld::findOrRegisterCollisionShape(const btCollisionShape* col
btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*) colShape; btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*) colShape;
b3StridingMeshInterface* meshInterface = trimesh->getMeshInterface(); b3StridingMeshInterface* meshInterface = trimesh->getMeshInterface();
btAlignedObjectArray<btVector3> vertices; b3AlignedObjectArray<b3Vector3> vertices;
btAlignedObjectArray<int> indices; b3AlignedObjectArray<int> indices;
btVector3 trimeshScaling(1,1,1); b3Vector3 trimeshScaling(1,1,1);
for (int partId=0;partId<meshInterface->getNumSubParts();partId++) for (int partId=0;partId<meshInterface->getNumSubParts();partId++)
{ {
@@ -145,9 +145,9 @@ int btGpuDynamicsWorld::findOrRegisterCollisionShape(const btCollisionShape* col
PHY_ScalarType indicestype = PHY_INTEGER; PHY_ScalarType indicestype = PHY_INTEGER;
//PHY_ScalarType indexType=0; //PHY_ScalarType indexType=0;
btVector3 triangleVerts[3]; b3Vector3 triangleVerts[3];
meshInterface->getLockedReadOnlyVertexIndexBase(&vertexbase,numverts, type,stride,&indexbase,indexstride,numfaces,indicestype,partId); meshInterface->getLockedReadOnlyVertexIndexBase(&vertexbase,numverts, type,stride,&indexbase,indexstride,numfaces,indicestype,partId);
btVector3 aabbMin,aabbMax; b3Vector3 aabbMin,aabbMax;
for (int triangleIndex = 0 ; triangleIndex < numfaces;triangleIndex++) for (int triangleIndex = 0 ; triangleIndex < numfaces;triangleIndex++)
{ {
@@ -160,7 +160,7 @@ int btGpuDynamicsWorld::findOrRegisterCollisionShape(const btCollisionShape* col
if (type == PHY_FLOAT) if (type == PHY_FLOAT)
{ {
float* graphicsbase = (float*)(vertexbase+graphicsindex*stride); float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
triangleVerts[j] = btVector3( triangleVerts[j] = b3Vector3(
graphicsbase[0]*trimeshScaling.getX(), graphicsbase[0]*trimeshScaling.getX(),
graphicsbase[1]*trimeshScaling.getY(), graphicsbase[1]*trimeshScaling.getY(),
graphicsbase[2]*trimeshScaling.getZ()); graphicsbase[2]*trimeshScaling.getZ());
@@ -168,9 +168,9 @@ int btGpuDynamicsWorld::findOrRegisterCollisionShape(const btCollisionShape* col
else else
{ {
double* graphicsbase = (double*)(vertexbase+graphicsindex*stride); double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
triangleVerts[j] = btVector3( btScalar(graphicsbase[0]*trimeshScaling.getX()), triangleVerts[j] = b3Vector3( b3Scalar(graphicsbase[0]*trimeshScaling.getX()),
btScalar(graphicsbase[1]*trimeshScaling.getY()), b3Scalar(graphicsbase[1]*trimeshScaling.getY()),
btScalar(graphicsbase[2]*trimeshScaling.getZ())); b3Scalar(graphicsbase[2]*trimeshScaling.getZ()));
} }
} }
vertices.push_back(triangleVerts[0]); vertices.push_back(triangleVerts[0]);
@@ -207,7 +207,7 @@ int btGpuDynamicsWorld::findOrRegisterCollisionShape(const btCollisionShape* col
{ {
btCompoundShape* compound = (btCompoundShape*) colShape; btCompoundShape* compound = (btCompoundShape*) colShape;
btAlignedObjectArray<btGpuChildShape> childShapes; b3AlignedObjectArray<btGpuChildShape> childShapes;
for (int i=0;i<compound->getNumChildShapes();i++) for (int i=0;i<compound->getNumChildShapes();i++)
{ {
@@ -215,8 +215,8 @@ int btGpuDynamicsWorld::findOrRegisterCollisionShape(const btCollisionShape* col
btAssert(compound->getChildShape(i)->isPolyhedral()); btAssert(compound->getChildShape(i)->isPolyhedral());
btGpuChildShape child; btGpuChildShape child;
child.m_shapeIndex = findOrRegisterCollisionShape(compound->getChildShape(i)); child.m_shapeIndex = findOrRegisterCollisionShape(compound->getChildShape(i));
btVector3 pos = compound->getChildTransform(i).getOrigin(); b3Vector3 pos = compound->getChildTransform(i).getOrigin();
btQuaternion orn = compound->getChildTransform(i).getRotation(); b3Quaternion orn = compound->getChildTransform(i).getRotation();
for (int v=0;v<4;v++) for (int v=0;v<4;v++)
{ {
child.m_childPosition[v] = pos[v]; child.m_childPosition[v] = pos[v];
@@ -283,8 +283,8 @@ void btGpuDynamicsWorld::addRigidBody(btRigidBody* body)
{ {
int gpuShapeIndex= m_uniqueShapeMapping[index]; int gpuShapeIndex= m_uniqueShapeMapping[index];
float mass = body->getInvMass() ? 1.f/body->getInvMass() : 0.f; float mass = body->getInvMass() ? 1.f/body->getInvMass() : 0.f;
btVector3 pos = body->getWorldTransform().getOrigin(); b3Vector3 pos = body->getWorldTransform().getOrigin();
btQuaternion orn = body->getWorldTransform().getRotation(); b3Quaternion orn = body->getWorldTransform().getRotation();
m_gpuPhysics->registerPhysicsInstance(mass,&pos.getX(),&orn.getX(),gpuShapeIndex,m_collisionObjects.size()); m_gpuPhysics->registerPhysicsInstance(mass,&pos.getX(),&orn.getX(),gpuShapeIndex,m_collisionObjects.size());

View File

@@ -1,25 +1,25 @@
#ifndef BT_GPU_DYNAMICS_WORLD_H #ifndef BT_GPU_DYNAMICS_WORLD_H
#define BT_GPU_DYNAMICS_WORLD_H #define BT_GPU_DYNAMICS_WORLD_H
class btVector3; class b3Vector3;
class btRigidBody; class btRigidBody;
class btCollisionObject; class btCollisionObject;
struct btGpuInternalData;//use this struct to avoid 'leaking' all OpenCL headers into clients code base struct btGpuInternalData;//use this struct to avoid 'leaking' all OpenCL headers into clients code base
class CLPhysicsDemo; class CLPhysicsDemo;
#include "BulletCommon/btAlignedObjectArray.h" #include "BulletCommon/b3AlignedObjectArray.h"
//#include "BulletDynamics/Dynamics/btDynamicsWorld.h" //#include "BulletDynamics/Dynamics/btDynamicsWorld.h"
class btGpuDynamicsWorld //: public btDynamicsWorld class btGpuDynamicsWorld //: public btDynamicsWorld
{ {
btAlignedObjectArray<const class btCollisionShape*> m_uniqueShapes; b3AlignedObjectArray<const class btCollisionShape*> m_uniqueShapes;
btAlignedObjectArray<int> m_uniqueShapeMapping; b3AlignedObjectArray<int> m_uniqueShapeMapping;
CLPhysicsDemo* m_gpuPhysics; CLPhysicsDemo* m_gpuPhysics;
btVector3 m_gravity; b3Vector3 m_gravity;
bool m_once; bool m_once;
bool initOpenCL(int preferredDeviceIndex, int preferredPlatformIndex, bool useInterop); bool initOpenCL(int preferredDeviceIndex, int preferredPlatformIndex, bool useInterop);
@@ -33,7 +33,7 @@ public:
virtual ~btGpuDynamicsWorld(); virtual ~btGpuDynamicsWorld();
virtual int stepSimulation( btScalar timeStep,int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.)); virtual int stepSimulation( b3Scalar timeStep,int maxSubSteps=1, b3Scalar fixedTimeStep=b3Scalar(1.)/b3Scalar(60.));
virtual void synchronizeMotionStates() virtual void synchronizeMotionStates()
{ {
@@ -42,7 +42,7 @@ public:
void debugDrawWorld() {} void debugDrawWorld() {}
void setGravity(const btVector3& gravity); void setGravity(const b3Vector3& gravity);
void addRigidBody(btRigidBody* body); void addRigidBody(btRigidBody* body);
@@ -50,9 +50,9 @@ public:
btAlignedObjectArray<class btCollisionObject*>& getCollisionObjectArray(); b3AlignedObjectArray<class btCollisionObject*>& getCollisionObjectArray();
const btAlignedObjectArray<class btCollisionObject*>& getCollisionObjectArray() const; const b3AlignedObjectArray<class btCollisionObject*>& getCollisionObjectArray() const;
virtual void addAction(btActionInterface* action) virtual void addAction(btActionInterface* action)
{ {
@@ -65,7 +65,7 @@ public:
} }
btVector3 getGravity () const b3Vector3 getGravity () const
{ {
return m_gravity; return m_gravity;
} }

View File

@@ -1,6 +1,6 @@
#include "GpuDemo.h" #include "GpuDemo.h"
#include "GpuDemoInternalData.h" #include "GpuDemoInternalData.h"
#include "BulletCommon/btScalar.h" #include "BulletCommon/b3Scalar.h"
#include "basic_initialize/b3OpenCLUtils.h" #include "basic_initialize/b3OpenCLUtils.h"
#include "OpenGLWindow/ShapeData.h" #include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h" #include "OpenGLWindow/GLInstancingRenderer.h"

View File

@@ -38,9 +38,9 @@ public:
:useOpenCL(true), :useOpenCL(true),
preferredOpenCLPlatformIndex(-1), preferredOpenCLPlatformIndex(-1),
preferredOpenCLDeviceIndex(-1), preferredOpenCLDeviceIndex(-1),
arraySizeX(10), arraySizeX(30),
arraySizeY(30), arraySizeY(30),
arraySizeZ(10), arraySizeZ(30),
m_useConcaveMesh(false), m_useConcaveMesh(false),
gapX(14.3), gapX(14.3),
gapY(14.0), gapY(14.0),

View File

@@ -9,7 +9,7 @@ static char* particleKernelsString =
#include "ParticleKernels.cl" #include "ParticleKernels.cl"
#define INTEROPKERNEL_SRC_PATH "demo/gpudemo/ParticleKernels.cl" #define INTEROPKERNEL_SRC_PATH "demo/gpudemo/ParticleKernels.cl"
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
#include "OpenGLWindow/OpenGLInclude.h" #include "OpenGLWindow/OpenGLInclude.h"
#include "OpenGLWindow/GLInstanceRendererInternalData.h" #include "OpenGLWindow/GLInstanceRendererInternalData.h"
#include "parallel_primitives/host/btLauncherCL.h" #include "parallel_primitives/host/btLauncherCL.h"
@@ -19,7 +19,7 @@ static char* particleKernelsString =
#include "GpuDemoInternalData.h" #include "GpuDemoInternalData.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
//1000000 particles //1000000 particles
//#define NUM_PARTICLES_X 100 //#define NUM_PARTICLES_X 100
@@ -46,7 +46,7 @@ static char* particleKernelsString =
ATTRIBUTE_ALIGNED16(struct) btSimParams ATTRIBUTE_ALIGNED16(struct) btSimParams
{ {
BT_DECLARE_ALIGNED_ALLOCATOR(); BT_DECLARE_ALIGNED_ALLOCATOR();
btVector3 m_gravity; b3Vector3 m_gravity;
float m_worldMin[4]; float m_worldMin[4];
float m_worldMax[4]; float m_worldMax[4];
@@ -97,10 +97,10 @@ struct ParticleInternalData
cl_mem m_clPositionBuffer; cl_mem m_clPositionBuffer;
btAlignedObjectArray<btVector3> m_velocitiesCPU; b3AlignedObjectArray<b3Vector3> m_velocitiesCPU;
btOpenCLArray<btVector3>* m_velocitiesGPU; btOpenCLArray<b3Vector3>* m_velocitiesGPU;
btAlignedObjectArray<btSimParams> m_simParamCPU; b3AlignedObjectArray<btSimParams> m_simParamCPU;
btOpenCLArray<btSimParams>* m_simParamGPU; btOpenCLArray<btSimParams>* m_simParamGPU;
@@ -168,14 +168,14 @@ void ParticleDemo::setupScene(const ConstructionInfo& ci)
int maxPairsSmallProxy = 32; int maxPairsSmallProxy = 32;
float radius = 3.f*m_data->m_simParamCPU[0].m_particleRad; float radius = 3.f*m_data->m_simParamCPU[0].m_particleRad;
m_data->m_broadphaseGPU = new b3GpuSapBroadphase(m_clData->m_clContext ,m_clData->m_clDevice,m_clData->m_clQueue);//overlappingPairCache,btVector3(4.f, 4.f, 4.f), 128, 128, 128,maxObjects, maxObjects, maxPairsSmallProxy, 100.f, 128, m_data->m_broadphaseGPU = new b3GpuSapBroadphase(m_clData->m_clContext ,m_clData->m_clDevice,m_clData->m_clQueue);//overlappingPairCache,b3Vector3(4.f, 4.f, 4.f), 128, 128, 128,maxObjects, maxObjects, maxPairsSmallProxy, 100.f, 128,
/*m_data->m_broadphaseGPU = new btGridBroadphaseCl(overlappingPairCache,btVector3(radius,radius,radius), 128, 128, 128, /*m_data->m_broadphaseGPU = new btGridBroadphaseCl(overlappingPairCache,b3Vector3(radius,radius,radius), 128, 128, 128,
maxObjects, maxObjects, maxPairsSmallProxy, 100.f, 128, maxObjects, maxObjects, maxPairsSmallProxy, 100.f, 128,
m_clData->m_clContext ,m_clData->m_clDevice,m_clData->m_clQueue); m_clData->m_clContext ,m_clData->m_clDevice,m_clData->m_clQueue);
*/ */
m_data->m_velocitiesGPU = new btOpenCLArray<btVector3>(m_clData->m_clContext,m_clData->m_clQueue,numParticles); m_data->m_velocitiesGPU = new btOpenCLArray<b3Vector3>(m_clData->m_clContext,m_clData->m_clQueue,numParticles);
m_data->m_velocitiesCPU.resize(numParticles); m_data->m_velocitiesCPU.resize(numParticles);
for (int i=0;i<numParticles;i++) for (int i=0;i<numParticles;i++)
{ {
@@ -243,11 +243,11 @@ void ParticleDemo::setupScene(const ConstructionInfo& ci)
void* userPtr = (void*)userIndex; void* userPtr = (void*)userIndex;
int collidableIndex = userIndex; int collidableIndex = userIndex;
btVector3 aabbMin,aabbMax; b3Vector3 aabbMin,aabbMax;
btVector3 particleRadius(rad,rad,rad); b3Vector3 particleRadius(rad,rad,rad);
aabbMin = btVector3(position[0],position[1],position[2])-particleRadius; aabbMin = b3Vector3(position[0],position[1],position[2])-particleRadius;
aabbMax = btVector3(position[0],position[1],position[2])+particleRadius; aabbMax = b3Vector3(position[0],position[1],position[2])+particleRadius;
m_data->m_broadphaseGPU->createProxy(aabbMin,aabbMax,collidableIndex,1,1); m_data->m_broadphaseGPU->createProxy(aabbMin,aabbMax,collidableIndex,1,1);
userIndex++; userIndex++;

View File

@@ -1,8 +1,8 @@
#include "PairBench.h" #include "PairBench.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "OpenGLWindow/ShapeData.h" #include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h" #include "OpenGLWindow/GLInstancingRenderer.h"
#include "BulletCommon/btQuaternion.h" #include "BulletCommon/b3Quaternion.h"
#include "OpenGLWindow/btgWindowInterface.h" #include "OpenGLWindow/btgWindowInterface.h"
#include "gpu_broadphase/host/b3GpuSapBroadphase.h" #include "gpu_broadphase/host/b3GpuSapBroadphase.h"
#include "../GpuDemoInternalData.h" #include "../GpuDemoInternalData.h"
@@ -187,16 +187,16 @@ void PairBench::initPhysics(const ConstructionInfo& ci)
{ {
for (int k=0;k<ci.arraySizeZ;k++) for (int k=0;k<ci.arraySizeZ;k++)
{ {
btVector3 position(k*3,i*3,j*3); b3Vector3 position(k*3,i*3,j*3);
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
btVector4 color(0,1,0,1); btVector4 color(0,1,0,1);
btVector4 scaling(1,1,1,1); btVector4 scaling(1,1,1,1);
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
btVector3 aabbHalfExtents(1,1,1); b3Vector3 aabbHalfExtents(1,1,1);
btVector3 aabbMin = position-aabbHalfExtents; b3Vector3 aabbMin = position-aabbHalfExtents;
btVector3 aabbMax = position+aabbHalfExtents; b3Vector3 aabbMax = position+aabbHalfExtents;
m_data->m_broadphaseGPU->createProxy(aabbMin,aabbMax,index,group,mask); m_data->m_broadphaseGPU->createProxy(aabbMin,aabbMax,index,group,mask);
@@ -264,7 +264,7 @@ void PairBench::clientMoveAndDisplay()
m_data->m_instancePosOrnColor->copyFromHostPointer(positions,3*numObjects,0); m_data->m_instancePosOrnColor->copyFromHostPointer(positions,3*numObjects,0);
m_data->m_bodyTimes = new btOpenCLArray<float>(m_clData->m_clContext,m_clData->m_clQueue); m_data->m_bodyTimes = new btOpenCLArray<float>(m_clData->m_clContext,m_clData->m_clQueue);
m_data->m_bodyTimes ->resize(numObjects); m_data->m_bodyTimes ->resize(numObjects);
btAlignedObjectArray<float> tmp; b3AlignedObjectArray<float> tmp;
tmp.resize(numObjects); tmp.resize(numObjects);
for (int i=0;i<numObjects;i++) for (int i=0;i<numObjects;i++)
{ {

View File

@@ -15,7 +15,7 @@
#include "Gwen/Controls/MenuStrip.h" #include "Gwen/Controls/MenuStrip.h"
#include "Gwen/Controls/Property/Text.h" #include "Gwen/Controls/Property/Text.h"
#include "Gwen/Controls/SplitterBar.h" #include "Gwen/Controls/SplitterBar.h"
#include "BulletCommon/btAlignedObjectArray.h" #include "BulletCommon/b3AlignedObjectArray.h"
#include "Gwen/Gwen.h" #include "Gwen/Gwen.h"
#include "Gwen/Align.h" #include "Gwen/Align.h"
#include "Gwen/Utility.h" #include "Gwen/Utility.h"
@@ -38,7 +38,7 @@ struct GwenInternalData
Gwen::Controls::Label* m_rightStatusBar; Gwen::Controls::Label* m_rightStatusBar;
Gwen::Controls::Label* m_leftStatusBar; Gwen::Controls::Label* m_leftStatusBar;
btAlignedObjectArray<struct Gwen::Event::Handler*> m_handlers; b3AlignedObjectArray<struct Gwen::Event::Handler*> m_handlers;
btToggleButtonCallback m_toggleButtonCallback; btToggleButtonCallback m_toggleButtonCallback;
btComboBoxCallback m_comboBoxCallback; btComboBoxCallback m_comboBoxCallback;

View File

@@ -16,7 +16,7 @@
#include "OpenGLWindow/GLPrimitiveRenderer.h" #include "OpenGLWindow/GLPrimitiveRenderer.h"
#include "OpenGLWindow/GLInstancingRenderer.h" #include "OpenGLWindow/GLInstancingRenderer.h"
//#include "OpenGL3CoreRenderer.h" //#include "OpenGL3CoreRenderer.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
//#include "btGpuDynamicsWorld.h" //#include "btGpuDynamicsWorld.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
@@ -61,7 +61,7 @@ enum
MYCOMBOBOX1 = 1, MYCOMBOBOX1 = 1,
}; };
btAlignedObjectArray<const char*> demoNames; b3AlignedObjectArray<const char*> demoNames;
int selectedDemo = 0; int selectedDemo = 0;
GpuDemo::CreateFunc* allDemos[]= GpuDemo::CreateFunc* allDemos[]=
{ {
@@ -313,7 +313,7 @@ sth_stash* initFont(GLPrimitiveRenderer* primRender)
#include "OpenGLWindow/OpenGLInclude.h" #include "OpenGLWindow/OpenGLInclude.h"
#include "BulletCommon/CommandLineArgs.h" #include "BulletCommon/b3CommandLineArgs.h"
void Usage() void Usage()
{ {
@@ -383,18 +383,18 @@ void DumpSimulationTime(FILE* f)
///extern const char* g_deviceName; ///extern const char* g_deviceName;
const char* g_deviceName = "blaat"; const char* g_deviceName = "blaat";
extern bool useNewBatchingKernel; extern bool useNewBatchingKernel;
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
btVector3 test(1,2,3); b3Vector3 test(1,2,3);
test.x = 1; test.x = 1;
test.y = 4; test.y = 4;
printf("main start"); printf("main start");
CommandLineArgs args(argc,argv); b3CommandLineArgs args(argc,argv);
ParticleDemo::ConstructionInfo ci; ParticleDemo::ConstructionInfo ci;
if (args.CheckCmdLineFlag("help")) if (args.CheckCmdLineFlag("help"))
@@ -670,7 +670,7 @@ int main(int argc, char* argv[])
/*if (demo->getDynamicsWorld() && demo->getDynamicsWorld()->getNumCollisionObjects()) /*if (demo->getDynamicsWorld() && demo->getDynamicsWorld()->getNumCollisionObjects())
{ {
BT_PROFILE("renderPhysicsWorld"); BT_PROFILE("renderPhysicsWorld");
btAlignedObjectArray<btCollisionObject*> arr = demo->getDynamicsWorld()->getCollisionObjectArray(); b3AlignedObjectArray<btCollisionObject*> arr = demo->getDynamicsWorld()->getCollisionObjectArray();
btCollisionObject** colObjArray = &arr[0]; btCollisionObject** colObjArray = &arr[0];
render.renderPhysicsWorld(demo->getDynamicsWorld()->getNumCollisionObjects(),colObjArray, syncOnly); render.renderPhysicsWorld(demo->getDynamicsWorld()->getNumCollisionObjects(),colObjArray, syncOnly);

View File

@@ -41,10 +41,10 @@ function createProject(vendor)
"../ObjLoader/list.cpp", "../ObjLoader/list.cpp",
"../ObjLoader/list.h", "../ObjLoader/list.h",
"../../src/BulletCommon/btAlignedAllocator.cpp", "../../src/BulletCommon/b3AlignedAllocator.cpp",
"../../src/BulletCommon/btAlignedAllocator.h", "../../src/BulletCommon/b3AlignedAllocator.h",
"../../src/BulletCommon/btQuickprof.cpp", "../../src/BulletCommon/b3Quickprof.cpp",
"../../src/BulletCommon/btQuickprof.h", "../../src/BulletCommon/b3Quickprof.h",
"../../src/BulletGeometry/btConvexHullComputer.cpp", "../../src/BulletGeometry/btConvexHullComputer.cpp",
"../../src/BulletGeometry/btConvexHullComputer.h", "../../src/BulletGeometry/btConvexHullComputer.h",

View File

@@ -1,10 +1,10 @@
#include "ConcaveScene.h" #include "ConcaveScene.h"
#include "GpuRigidBodyDemo.h" #include "GpuRigidBodyDemo.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "OpenGLWindow/ShapeData.h" #include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h" #include "OpenGLWindow/GLInstancingRenderer.h"
#include "BulletCommon/btQuaternion.h" #include "BulletCommon/b3Quaternion.h"
#include "OpenGLWindow/btgWindowInterface.h" #include "OpenGLWindow/btgWindowInterface.h"
#include "gpu_broadphase/host/b3GpuSapBroadphase.h" #include "gpu_broadphase/host/b3GpuSapBroadphase.h"
#include "../GpuDemoInternalData.h" #include "../GpuDemoInternalData.h"
@@ -17,7 +17,7 @@
#include "gpu_rigidbody/host/b3Config.h" #include "gpu_rigidbody/host/b3Config.h"
#include "GpuRigidBodyDemoInternalData.h" #include "GpuRigidBodyDemoInternalData.h"
#include"../../ObjLoader/objLoader.h" #include"../../ObjLoader/objLoader.h"
#include "BulletCommon/btTransform.h" #include "BulletCommon/b3Transform.h"
#include "OpenGLWindow/GLInstanceGraphicsShape.h" #include "OpenGLWindow/GLInstanceGraphicsShape.h"
#define CONCAVE_GAPX 16 #define CONCAVE_GAPX 16
@@ -27,18 +27,18 @@
GLInstanceGraphicsShape* createGraphicsShapeFromWavefrontObj(objLoader* obj) GLInstanceGraphicsShape* createGraphicsShapeFromWavefrontObj(objLoader* obj)
{ {
btAlignedObjectArray<GLInstanceVertex>* vertices = new btAlignedObjectArray<GLInstanceVertex>; b3AlignedObjectArray<GLInstanceVertex>* vertices = new b3AlignedObjectArray<GLInstanceVertex>;
{ {
// int numVertices = obj->vertexCount; // int numVertices = obj->vertexCount;
// int numIndices = 0; // int numIndices = 0;
btAlignedObjectArray<int>* indicesPtr = new btAlignedObjectArray<int>; b3AlignedObjectArray<int>* indicesPtr = new b3AlignedObjectArray<int>;
/* /*
for (int v=0;v<obj->vertexCount;v++) for (int v=0;v<obj->vertexCount;v++)
{ {
vtx.xyzw[0] = obj->vertexList[v]->e[0]; vtx.xyzw[0] = obj->vertexList[v]->e[0];
vtx.xyzw[1] = obj->vertexList[v]->e[1]; vtx.xyzw[1] = obj->vertexList[v]->e[1];
vtx.xyzw[2] = obj->vertexList[v]->e[2]; vtx.xyzw[2] = obj->vertexList[v]->e[2];
btVector3 n(vtx.xyzw[0],vtx.xyzw[1],vtx.xyzw[2]); b3Vector3 n(vtx.xyzw[0],vtx.xyzw[1],vtx.xyzw[2]);
if (n.length2()>SIMD_EPSILON) if (n.length2()>SIMD_EPSILON)
{ {
n.normalize(); n.normalize();
@@ -60,10 +60,10 @@ GLInstanceGraphicsShape* createGraphicsShapeFromWavefrontObj(objLoader* obj)
for (int f=0;f<obj->faceCount;f++) for (int f=0;f<obj->faceCount;f++)
{ {
obj_face* face = obj->faceList[f]; obj_face* face = obj->faceList[f];
//btVector3 normal(face.m_plane[0],face.m_plane[1],face.m_plane[2]); //b3Vector3 normal(face.m_plane[0],face.m_plane[1],face.m_plane[2]);
if (face->vertex_count>=3) if (face->vertex_count>=3)
{ {
btVector3 normal(0,1,0); b3Vector3 normal(0,1,0);
int vtxBaseIndex = vertices->size(); int vtxBaseIndex = vertices->size();
if (face->vertex_count<=4) if (face->vertex_count<=4)
@@ -98,9 +98,9 @@ GLInstanceGraphicsShape* createGraphicsShapeFromWavefrontObj(objLoader* obj)
vtx2.uv[1] = 0.5f;obj->textureList[face->vertex_index[2]]->e[1]; vtx2.uv[1] = 0.5f;obj->textureList[face->vertex_index[2]]->e[1];
btVector3 v0(vtx0.xyzw[0],vtx0.xyzw[1],vtx0.xyzw[2]); b3Vector3 v0(vtx0.xyzw[0],vtx0.xyzw[1],vtx0.xyzw[2]);
btVector3 v1(vtx1.xyzw[0],vtx1.xyzw[1],vtx1.xyzw[2]); b3Vector3 v1(vtx1.xyzw[0],vtx1.xyzw[1],vtx1.xyzw[2]);
btVector3 v2(vtx2.xyzw[0],vtx2.xyzw[1],vtx2.xyzw[2]); b3Vector3 v2(vtx2.xyzw[0],vtx2.xyzw[1],vtx2.xyzw[2]);
normal = (v1-v0).cross(v2-v0); normal = (v1-v0).cross(v2-v0);
normal.normalize(); normal.normalize();
@@ -168,7 +168,7 @@ void ConcaveScene::createConcaveMesh(const ConstructionInfo& ci)
char* fileName = "data/samurai_monastry.obj"; char* fileName = "data/samurai_monastry.obj";
// char* fileName = "data/teddy2_VHACD_CHs.obj"; // char* fileName = "data/teddy2_VHACD_CHs.obj";
btVector3 shift(0,0,0);//0,230,80);//150,-100,-120); b3Vector3 shift(0,0,0);//0,230,80);//150,-100,-120);
btVector4 scaling(4,4,4,1); btVector4 scaling(4,4,4,1);
FILE* f = 0; FILE* f = 0;
@@ -202,19 +202,19 @@ void ConcaveScene::createConcaveMesh(const ConstructionInfo& ci)
GLInstanceGraphicsShape* shape = createGraphicsShapeFromWavefrontObj(objData); GLInstanceGraphicsShape* shape = createGraphicsShapeFromWavefrontObj(objData);
btAlignedObjectArray<btVector3> verts; b3AlignedObjectArray<b3Vector3> verts;
for (int i=0;i<shape->m_numvertices;i++) for (int i=0;i<shape->m_numvertices;i++)
{ {
for (int j=0;j<3;j++) for (int j=0;j<3;j++)
shape->m_vertices->at(i).xyzw[j] += shift[j]; shape->m_vertices->at(i).xyzw[j] += shift[j];
btVector3 vtx(shape->m_vertices->at(i).xyzw[0], b3Vector3 vtx(shape->m_vertices->at(i).xyzw[0],
shape->m_vertices->at(i).xyzw[1], shape->m_vertices->at(i).xyzw[1],
shape->m_vertices->at(i).xyzw[2]); shape->m_vertices->at(i).xyzw[2]);
verts.push_back(vtx*scaling); verts.push_back(vtx*scaling);
} }
int colIndex = m_data->m_np->registerConcaveMesh(&verts,shape->m_indices,btVector3(1,1,1)); int colIndex = m_data->m_np->registerConcaveMesh(&verts,shape->m_indices,b3Vector3(1,1,1));
{ {
int strideInBytes = 9*sizeof(float); int strideInBytes = 9*sizeof(float);
@@ -225,14 +225,14 @@ void ConcaveScene::createConcaveMesh(const ConstructionInfo& ci)
int shapeId = ci.m_instancingRenderer->registerShape(&shape->m_vertices->at(0).xyzw[0], shape->m_numvertices, &shape->m_indices->at(0), shape->m_numIndices); int shapeId = ci.m_instancingRenderer->registerShape(&shape->m_vertices->at(0).xyzw[0], shape->m_numvertices, &shape->m_indices->at(0), shape->m_numIndices);
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
btVector4 color(0.3,0.3,1,1.f);//0.5);//1.f btVector4 color(0.3,0.3,1,1.f);//0.5);//1.f
{ {
float mass = 0.f; float mass = 0.f;
btVector3 position(0,0,0); b3Vector3 position(0,0,0);
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index); int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index);
index++; index++;
@@ -267,8 +267,8 @@ void ConcaveScene::setupScene(const ConstructionInfo& ci)
{ {
btVector4 scaling(400,0.001,400,1); btVector4 scaling(400,0.001,400,1);
int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
btVector3 position(0,-2,0); b3Vector3 position(0,-2,0);
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
btVector4 color(0,0,1,1); btVector4 color(0,0,1,1);
@@ -323,9 +323,9 @@ void ConcaveScene::createDynamicObjects(const ConstructionInfo& ci)
{ {
float mass = 1; float mass = 1;
//btVector3 position(-2*ci.gapX+i*ci.gapX,25+j*ci.gapY,-2*ci.gapZ+k*ci.gapZ); //b3Vector3 position(-2*ci.gapX+i*ci.gapX,25+j*ci.gapY,-2*ci.gapZ+k*ci.gapZ);
btVector3 position(-(ci.arraySizeX/2)*CONCAVE_GAPX+i*CONCAVE_GAPX,150+j*CONCAVE_GAPY,-(ci.arraySizeZ/2)*CONCAVE_GAPZ+k*CONCAVE_GAPZ); b3Vector3 position(-(ci.arraySizeX/2)*CONCAVE_GAPX+i*CONCAVE_GAPX,150+j*CONCAVE_GAPY,-(ci.arraySizeZ/2)*CONCAVE_GAPZ+k*CONCAVE_GAPZ);
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
btVector4 color = colors[curColor]; btVector4 color = colors[curColor];
curColor++; curColor++;
@@ -363,7 +363,7 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
//char* fileName = "data/cube_offset.obj"; //char* fileName = "data/cube_offset.obj";
btVector3 shift(0,0,0);//0,230,80);//150,-100,-120); b3Vector3 shift(0,0,0);//0,230,80);//150,-100,-120);
btVector4 scaling(1,1,1,1); btVector4 scaling(1,1,1,1);
FILE* f = 0; FILE* f = 0;
@@ -398,8 +398,8 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
int strideInBytes = 9*sizeof(float); int strideInBytes = 9*sizeof(float);
btAlignedObjectArray<GLInstanceVertex> vertexArray; b3AlignedObjectArray<GLInstanceVertex> vertexArray;
btAlignedObjectArray<int> indexArray; b3AlignedObjectArray<int> indexArray;
@@ -410,14 +410,14 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
int index=0; int index=0;
int colIndex = 0; int colIndex = 0;
btAlignedObjectArray<GLInstanceVertex> vertices; b3AlignedObjectArray<GLInstanceVertex> vertices;
int stride2 = sizeof(GLInstanceVertex); int stride2 = sizeof(GLInstanceVertex);
btAssert(stride2 == strideInBytes); btAssert(stride2 == strideInBytes);
{ {
btAlignedObjectArray<btGpuChildShape> childShapes; b3AlignedObjectArray<btGpuChildShape> childShapes;
int numChildShapes = objData->objectCount; int numChildShapes = objData->objectCount;
@@ -435,15 +435,15 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
//for now, only support polyhedral child shapes //for now, only support polyhedral child shapes
btGpuChildShape child; btGpuChildShape child;
btVector3 pos(0,0,0); b3Vector3 pos(0,0,0);
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
for (int v=0;v<4;v++) for (int v=0;v<4;v++)
{ {
child.m_childPosition[v] = pos[v]; child.m_childPosition[v] = pos[v];
child.m_childOrientation[v] = orn[v]; child.m_childOrientation[v] = orn[v];
} }
btTransform tr; b3Transform tr;
tr.setIdentity(); tr.setIdentity();
tr.setOrigin(pos); tr.setOrigin(pos);
tr.setRotation(orn); tr.setRotation(orn);
@@ -465,11 +465,11 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
} }
} }
btVector3 center(0,0,0); b3Vector3 center(0,0,0);
btAlignedObjectArray<GLInstanceVertex> tmpVertices; b3AlignedObjectArray<GLInstanceVertex> tmpVertices;
//add transformed graphics vertices and indices //add transformed graphics vertices and indices
btVector3 myScaling(1,1,1);//50,50,50);//300,300,300); b3Vector3 myScaling(1,1,1);//50,50,50);//300,300,300);
for (int v=0;v<numVertices;v++) for (int v=0;v<numVertices;v++)
{ {
GLInstanceVertex vert; GLInstanceVertex vert;
@@ -479,7 +479,7 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
vert.normal[0]=0.f; vert.normal[0]=0.f;
vert.normal[1]=1.f; vert.normal[1]=1.f;
vert.normal[2]=0.f; vert.normal[2]=0.f;
btVector3 vertPos; b3Vector3 vertPos;
vertPos[0] = orgVert->e[0]*myScaling[0]; vertPos[0] = orgVert->e[0]*myScaling[0];
vertPos[1] = orgVert->e[1]*myScaling[1]; vertPos[1] = orgVert->e[1]*myScaling[1];
vertPos[2] = orgVert->e[2]*myScaling[2]; vertPos[2] = orgVert->e[2]*myScaling[2];
@@ -498,7 +498,7 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
vert.normal[0]=0.f; vert.normal[0]=0.f;
vert.normal[1]=1.f; vert.normal[1]=1.f;
vert.normal[2]=0.f; vert.normal[2]=0.f;
btVector3 vertPos; b3Vector3 vertPos;
vertPos[0] = orgVert->e[0]*myScaling[0]; vertPos[0] = orgVert->e[0]*myScaling[0];
vertPos[1] = orgVert->e[1]*myScaling[1]; vertPos[1] = orgVert->e[1]*myScaling[1];
vertPos[2] = orgVert->e[2]*myScaling[2]; vertPos[2] = orgVert->e[2]*myScaling[2];
@@ -509,7 +509,7 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
vert.xyzw[2] = vertPos[2]; vert.xyzw[2] = vertPos[2];
tmpVertices.push_back(vert); tmpVertices.push_back(vert);
btVector3 newPos = tr*vertPos; b3Vector3 newPos = tr*vertPos;
vert.xyzw[0] = newPos[0]; vert.xyzw[0] = newPos[0];
vert.xyzw[1] = newPos[1]; vert.xyzw[1] = newPos[1];
vert.xyzw[2] = newPos[2]; vert.xyzw[2] = newPos[2];
@@ -548,11 +548,11 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
{ {
float mass = 1;//j==0? 0.f : 1.f; float mass = 1;//j==0? 0.f : 1.f;
//btVector3 position(i*10*ci.gapX,j*ci.gapY,k*10*ci.gapZ); //b3Vector3 position(i*10*ci.gapX,j*ci.gapY,k*10*ci.gapZ);
btVector3 position(i*10*ci.gapX,50+j*ci.gapY,k*10*ci.gapZ); b3Vector3 position(i*10*ci.gapX,50+j*ci.gapY,k*10*ci.gapZ);
// btQuaternion orn(0,0,0,1); // b3Quaternion orn(0,0,0,1);
btQuaternion orn(btVector3(0,0,1),1.8); b3Quaternion orn(b3Vector3(0,0,1),1.8);
btVector4 color = colors[curColor]; btVector4 color = colors[curColor];
curColor++; curColor++;
@@ -577,8 +577,8 @@ void ConcaveCompoundScene::createDynamicObjects(const ConstructionInfo& ci)
int numVertices = sizeof(cube_vertices)/strideInBytes; int numVertices = sizeof(cube_vertices)/strideInBytes;
int numIndices = sizeof(cube_indices)/sizeof(int); int numIndices = sizeof(cube_indices)/sizeof(int);
btAlignedObjectArray<GLInstanceVertex> vertexArray; b3AlignedObjectArray<GLInstanceVertex> vertexArray;
btAlignedObjectArray<int> indexArray; b3AlignedObjectArray<int> indexArray;
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); //int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
@@ -596,28 +596,28 @@ void ConcaveCompoundScene::createDynamicObjects(const ConstructionInfo& ci)
int childColIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); int childColIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
btVector3 childPositions[3] = { b3Vector3 childPositions[3] = {
btVector3(0,-2,0), b3Vector3(0,-2,0),
btVector3(0,0,0), b3Vector3(0,0,0),
btVector3(0,0,2) b3Vector3(0,0,2)
}; };
btAlignedObjectArray<btGpuChildShape> childShapes; b3AlignedObjectArray<btGpuChildShape> childShapes;
int numChildShapes = 3; int numChildShapes = 3;
for (int i=0;i<numChildShapes;i++) for (int i=0;i<numChildShapes;i++)
{ {
//for now, only support polyhedral child shapes //for now, only support polyhedral child shapes
btGpuChildShape child; btGpuChildShape child;
child.m_shapeIndex = childColIndex; child.m_shapeIndex = childColIndex;
btVector3 pos = childPositions[i]; b3Vector3 pos = childPositions[i];
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
for (int v=0;v<4;v++) for (int v=0;v<4;v++)
{ {
child.m_childPosition[v] = pos[v]; child.m_childPosition[v] = pos[v];
child.m_childOrientation[v] = orn[v]; child.m_childOrientation[v] = orn[v];
} }
childShapes.push_back(child); childShapes.push_back(child);
btTransform tr; b3Transform tr;
tr.setIdentity(); tr.setIdentity();
tr.setOrigin(pos); tr.setOrigin(pos);
tr.setRotation(orn); tr.setRotation(orn);
@@ -630,8 +630,8 @@ btVector3 childPositions[3] = {
for (int v=0;v<numVertices;v++) for (int v=0;v<numVertices;v++)
{ {
GLInstanceVertex vert = cubeVerts[v]; GLInstanceVertex vert = cubeVerts[v];
btVector3 vertPos(vert.xyzw[0],vert.xyzw[1],vert.xyzw[2]); b3Vector3 vertPos(vert.xyzw[0],vert.xyzw[1],vert.xyzw[2]);
btVector3 newPos = tr*vertPos; b3Vector3 newPos = tr*vertPos;
vert.xyzw[0] = newPos[0]; vert.xyzw[0] = newPos[0];
vert.xyzw[1] = newPos[1]; vert.xyzw[1] = newPos[1];
vert.xyzw[2] = newPos[2]; vert.xyzw[2] = newPos[2];
@@ -665,9 +665,9 @@ btVector3 childPositions[3] = {
{ {
float mass = 1;//j==0? 0.f : 1.f; float mass = 1;//j==0? 0.f : 1.f;
btVector3 position(i*ci.gapX,150+j*ci.gapY,k*ci.gapZ); b3Vector3 position(i*ci.gapX,150+j*ci.gapY,k*ci.gapZ);
//btQuaternion orn(0,0,0,1); //b3Quaternion orn(0,0,0,1);
btQuaternion orn(btVector3(1,0,0),0.7); b3Quaternion orn(b3Vector3(1,0,0),0.7);
btVector4 color = colors[curColor]; btVector4 color = colors[curColor];
curColor++; curColor++;
@@ -722,11 +722,11 @@ void ConcaveSphereScene::createDynamicObjects(const ConstructionInfo& ci)
float mass = 1.f; float mass = 1.f;
btVector3 position(-(ci.arraySizeX/2)*8+i*8,50+j*8,-(ci.arraySizeZ/2)*8+k*8); b3Vector3 position(-(ci.arraySizeX/2)*8+i*8,50+j*8,-(ci.arraySizeZ/2)*8+k*8);
//btVector3 position(0,-41,0);//0,0,0);//i*radius*3,-41+j*radius*3,k*radius*3); //b3Vector3 position(0,-41,0);//0,0,0);//i*radius*3,-41+j*radius*3,k*radius*3);
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
btVector4 color = colors[curColor]; btVector4 color = colors[curColor];
curColor++; curColor++;

View File

@@ -1,10 +1,10 @@
#include "GpuCompoundScene.h" #include "GpuCompoundScene.h"
#include "GpuRigidBodyDemo.h" #include "GpuRigidBodyDemo.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "OpenGLWindow/ShapeData.h" #include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h" #include "OpenGLWindow/GLInstancingRenderer.h"
#include "BulletCommon/btQuaternion.h" #include "BulletCommon/b3Quaternion.h"
#include "OpenGLWindow/btgWindowInterface.h" #include "OpenGLWindow/btgWindowInterface.h"
#include "gpu_broadphase/host/b3GpuSapBroadphase.h" #include "gpu_broadphase/host/b3GpuSapBroadphase.h"
#include "../GpuDemoInternalData.h" #include "../GpuDemoInternalData.h"
@@ -16,7 +16,7 @@
#include "gpu_rigidbody/host/b3GpuNarrowPhase.h" #include "gpu_rigidbody/host/b3GpuNarrowPhase.h"
#include "gpu_rigidbody/host/b3Config.h" #include "gpu_rigidbody/host/b3Config.h"
#include "GpuRigidBodyDemoInternalData.h" #include "GpuRigidBodyDemoInternalData.h"
#include "BulletCommon/btTransform.h" #include "BulletCommon/b3Transform.h"
#include "OpenGLWindow/GLInstanceGraphicsShape.h" #include "OpenGLWindow/GLInstanceGraphicsShape.h"
@@ -37,35 +37,35 @@ void GpuCompoundScene::setupScene(const ConstructionInfo& ci)
btAssert(stride2 == strideInBytes); btAssert(stride2 == strideInBytes);
int index=0; int index=0;
int colIndex = -1; int colIndex = -1;
btAlignedObjectArray<GLInstanceVertex> vertexArray; b3AlignedObjectArray<GLInstanceVertex> vertexArray;
btAlignedObjectArray<int> indexArray; b3AlignedObjectArray<int> indexArray;
{ {
int childColIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); int childColIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
btVector3 childPositions[3] = { b3Vector3 childPositions[3] = {
btVector3(0,-2,0), b3Vector3(0,-2,0),
btVector3(0,0,0), b3Vector3(0,0,0),
btVector3(0,0,2) b3Vector3(0,0,2)
}; };
btAlignedObjectArray<btGpuChildShape> childShapes; b3AlignedObjectArray<btGpuChildShape> childShapes;
int numChildShapes = 3; int numChildShapes = 3;
for (int i=0;i<numChildShapes;i++) for (int i=0;i<numChildShapes;i++)
{ {
//for now, only support polyhedral child shapes //for now, only support polyhedral child shapes
btGpuChildShape child; btGpuChildShape child;
child.m_shapeIndex = childColIndex; child.m_shapeIndex = childColIndex;
btVector3 pos = childPositions[i]; b3Vector3 pos = childPositions[i];
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
for (int v=0;v<4;v++) for (int v=0;v<4;v++)
{ {
child.m_childPosition[v] = pos[v]; child.m_childPosition[v] = pos[v];
child.m_childOrientation[v] = orn[v]; child.m_childOrientation[v] = orn[v];
} }
childShapes.push_back(child); childShapes.push_back(child);
btTransform tr; b3Transform tr;
tr.setIdentity(); tr.setIdentity();
tr.setOrigin(pos); tr.setOrigin(pos);
tr.setRotation(orn); tr.setRotation(orn);
@@ -78,8 +78,8 @@ void GpuCompoundScene::setupScene(const ConstructionInfo& ci)
for (int v=0;v<numVertices;v++) for (int v=0;v<numVertices;v++)
{ {
GLInstanceVertex vert = cubeVerts[v]; GLInstanceVertex vert = cubeVerts[v];
btVector3 vertPos(vert.xyzw[0],vert.xyzw[1],vert.xyzw[2]); b3Vector3 vertPos(vert.xyzw[0],vert.xyzw[1],vert.xyzw[2]);
btVector3 newPos = tr*vertPos; b3Vector3 newPos = tr*vertPos;
vert.xyzw[0] = newPos[0]; vert.xyzw[0] = newPos[0];
vert.xyzw[1] = newPos[1]; vert.xyzw[1] = newPos[1];
vert.xyzw[2] = newPos[2]; vert.xyzw[2] = newPos[2];
@@ -113,9 +113,9 @@ void GpuCompoundScene::setupScene(const ConstructionInfo& ci)
{ {
float mass = 1;//j==0? 0.f : 1.f; float mass = 1;//j==0? 0.f : 1.f;
btVector3 position(i*ci.gapX,10+j*ci.gapY,k*ci.gapZ); b3Vector3 position(i*ci.gapX,10+j*ci.gapY,k*ci.gapZ);
//btQuaternion orn(0,0,0,1); //b3Quaternion orn(0,0,0,1);
btQuaternion orn(btVector3(1,0,0),0.7); b3Quaternion orn(b3Vector3(1,0,0),0.7);
btVector4 color = colors[curColor]; btVector4 color = colors[curColor];
curColor++; curColor++;
@@ -208,11 +208,11 @@ void GpuCompoundScene::createStaticEnvironment(const ConstructionInfo& ci)
int colIndex = m_data->m_np->registerSphereShape(radius);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); int colIndex = m_data->m_np->registerSphereShape(radius);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
float mass = 0.f; float mass = 0.f;
//btVector3 position((j&1)+i*2.2,1+j*2.,(j&1)+k*2.2); //b3Vector3 position((j&1)+i*2.2,1+j*2.,(j&1)+k*2.2);
btVector3 position(0,-41,0); b3Vector3 position(0,-41,0);
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
btVector4 color = colors[curColor]; btVector4 color = colors[curColor];
curColor++; curColor++;
@@ -232,12 +232,12 @@ void GpuCompoundPlaneScene::createStaticEnvironment(const ConstructionInfo& ci)
{ {
int index=0; int index=0;
btVector3 normal(0,1,0); b3Vector3 normal(0,1,0);
float constant=0.f; float constant=0.f;
int colIndex = m_data->m_np->registerPlaneShape(normal,constant);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); int colIndex = m_data->m_np->registerPlaneShape(normal,constant);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
btVector3 position(0,0,0); b3Vector3 position(0,0,0);
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
// btQuaternion orn(btVector3(1,0,0),0.3); // b3Quaternion orn(b3Vector3(1,0,0),0.3);
btVector4 color(0,0,1,1); btVector4 color(0,0,1,1);
btVector4 scaling(100,0.01,100,1); btVector4 scaling(100,0.01,100,1);
int strideInBytes = 9*sizeof(float); int strideInBytes = 9*sizeof(float);

View File

@@ -1,10 +1,10 @@
#include "GpuConvexScene.h" #include "GpuConvexScene.h"
#include "GpuRigidBodyDemo.h" #include "GpuRigidBodyDemo.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "OpenGLWindow/ShapeData.h" #include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h" #include "OpenGLWindow/GLInstancingRenderer.h"
#include "BulletCommon/btQuaternion.h" #include "BulletCommon/b3Quaternion.h"
#include "OpenGLWindow/btgWindowInterface.h" #include "OpenGLWindow/btgWindowInterface.h"
#include "gpu_broadphase/host/b3GpuSapBroadphase.h" #include "gpu_broadphase/host/b3GpuSapBroadphase.h"
#include "../GpuDemoInternalData.h" #include "../GpuDemoInternalData.h"
@@ -91,10 +91,10 @@ int GpuConvexScene::createDynamicsObjects2(const ConstructionInfo& ci, const flo
{ {
float mass = 1.f; float mass = 1.f;
btVector3 position((j&1)+i*2.2,1+j*2.,(j&1)+k*2.2); b3Vector3 position((j&1)+i*2.2,1+j*2.,(j&1)+k*2.2);
//btVector3 position(i*2.2,1+j*2.,k*2.2); //b3Vector3 position(i*2.2,1+j*2.,k*2.2);
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
btVector4 color = colors[curColor]; btVector4 color = colors[curColor];
curColor++; curColor++;
@@ -126,8 +126,8 @@ void GpuConvexScene::createStaticEnvironment(const ConstructionInfo& ci)
{ {
btVector4 scaling(400,1,400,1); btVector4 scaling(400,1,400,1);
int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
btVector3 position(0,0,0); b3Vector3 position(0,0,0);
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
btVector4 color(0,0,1,1); btVector4 color(0,0,1,1);
@@ -140,12 +140,12 @@ void GpuConvexScene::createStaticEnvironment(const ConstructionInfo& ci)
void GpuConvexPlaneScene::createStaticEnvironment(const ConstructionInfo& ci) void GpuConvexPlaneScene::createStaticEnvironment(const ConstructionInfo& ci)
{ {
int index=0; int index=0;
btVector3 normal(0,1,0); b3Vector3 normal(0,1,0);
float constant=0.f; float constant=0.f;
int colIndex = m_data->m_np->registerPlaneShape(normal,constant);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); int colIndex = m_data->m_np->registerPlaneShape(normal,constant);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
btVector3 position(0,0,0); b3Vector3 position(0,0,0);
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
// btQuaternion orn(btVector3(1,0,0),0.3); // b3Quaternion orn(b3Vector3(1,0,0),0.3);
btVector4 color(0,0,1,1); btVector4 color(0,0,1,1);
btVector4 scaling(100,0.001,100,1); btVector4 scaling(100,0.001,100,1);
int strideInBytes = 9*sizeof(float); int strideInBytes = 9*sizeof(float);

View File

@@ -1,8 +1,8 @@
#include "GpuRigidBodyDemo.h" #include "GpuRigidBodyDemo.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "OpenGLWindow/ShapeData.h" #include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h" #include "OpenGLWindow/GLInstancingRenderer.h"
#include "BulletCommon/btQuaternion.h" #include "BulletCommon/b3Quaternion.h"
#include "OpenGLWindow/btgWindowInterface.h" #include "OpenGLWindow/btgWindowInterface.h"
#include "gpu_broadphase/host/b3GpuSapBroadphase.h" #include "gpu_broadphase/host/b3GpuSapBroadphase.h"
#include "../GpuDemoInternalData.h" #include "../GpuDemoInternalData.h"

View File

@@ -3,7 +3,7 @@
#include "basic_initialize/b3OpenCLUtils.h" #include "basic_initialize/b3OpenCLUtils.h"
#include "parallel_primitives/host/btOpenCLArray.h" #include "parallel_primitives/host/btOpenCLArray.h"
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
struct GpuRigidBodyDemoInternalData struct GpuRigidBodyDemoInternalData
{ {

View File

@@ -1,10 +1,10 @@
#include "GpuSphereScene.h" #include "GpuSphereScene.h"
#include "GpuRigidBodyDemo.h" #include "GpuRigidBodyDemo.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "OpenGLWindow/ShapeData.h" #include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h" #include "OpenGLWindow/GLInstancingRenderer.h"
#include "BulletCommon/btQuaternion.h" #include "BulletCommon/b3Quaternion.h"
#include "OpenGLWindow/btgWindowInterface.h" #include "OpenGLWindow/btgWindowInterface.h"
#include "gpu_broadphase/host/b3GpuSapBroadphase.h" #include "gpu_broadphase/host/b3GpuSapBroadphase.h"
#include "../GpuDemoInternalData.h" #include "../GpuDemoInternalData.h"
@@ -85,10 +85,10 @@ void GpuSphereScene::setupScene(const ConstructionInfo& ci)
int colIndex = m_data->m_np->registerSphereShape(radius);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); int colIndex = m_data->m_np->registerSphereShape(radius);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
float mass = 0.f; float mass = 0.f;
//btVector3 position((j&1)+i*2.2,1+j*2.,(j&1)+k*2.2); //b3Vector3 position((j&1)+i*2.2,1+j*2.,(j&1)+k*2.2);
btVector3 position(0,0,0); b3Vector3 position(0,0,0);
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
btVector4 color = colors[curColor]; btVector4 color = colors[curColor];
curColor++; curColor++;
@@ -141,11 +141,11 @@ void GpuSphereScene::setupScene(const ConstructionInfo& ci)
int i=0,j=0,k=0; int i=0,j=0,k=0;
float mass = 0.f; float mass = 0.f;
btVector3 position(0,0,0); b3Vector3 position(0,0,0);
//btVector3 position((j&1)+i*142.2,-51+j*142.,(j&1)+k*142.2); //b3Vector3 position((j&1)+i*142.2,-51+j*142.,(j&1)+k*142.2);
//btVector3 position(0,-41,0);//0,0,0);//i*radius*3,-41+j*radius*3,k*radius*3); //b3Vector3 position(0,-41,0);//0,0,0);//i*radius*3,-41+j*radius*3,k*radius*3);
btQuaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
btVector4 color = colors[curColor]; btVector4 color = colors[curColor];
curColor++; curColor++;
@@ -165,7 +165,7 @@ void GpuSphereScene::setupScene(const ConstructionInfo& ci)
int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
btVector4 scaling(0.5,0.5,0.5,1);//1,1,1,1);//0.1,0.1,0.1,1); btVector4 scaling(0.5,0.5,0.5,1);//1,1,1,1);//0.1,0.1,0.1,1);
int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
btVector3 normal(0,-1,0); b3Vector3 normal(0,-1,0);
float constant=2; float constant=2;
@@ -176,8 +176,8 @@ void GpuSphereScene::setupScene(const ConstructionInfo& ci)
{ {
//int colIndex = m_data->m_np->registerPlaneShape(normal,constant);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); //int colIndex = m_data->m_np->registerPlaneShape(normal,constant);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
btVector4 position(2*i,70+k*2,2*j+8,0); btVector4 position(2*i,70+k*2,2*j+8,0);
//btQuaternion orn(0,0,0,1); //b3Quaternion orn(0,0,0,1);
btQuaternion orn(btVector3(1,0,0),0.3); b3Quaternion orn(b3Vector3(1,0,0),0.3);
btVector4 color(0,0,1,1); btVector4 color(0,0,1,1);

View File

@@ -1,14 +1,14 @@
#include "b3GpuSapBroadphase.h" #include "b3GpuSapBroadphase.h"
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
#include "parallel_primitives/host/btLauncherCL.h" #include "parallel_primitives/host/btLauncherCL.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "basic_initialize/b3OpenCLUtils.h" #include "basic_initialize/b3OpenCLUtils.h"
#include "../kernels/sapKernels.h" #include "../kernels/sapKernels.h"
#include "../kernels/sapFastKernels.h" #include "../kernels/sapFastKernels.h"
#include "BulletCommon/btMinMax.h" #include "BulletCommon/b3MinMax.h"
b3GpuSapBroadphase::b3GpuSapBroadphase(cl_context ctx,cl_device_id device, cl_command_queue q ) b3GpuSapBroadphase::b3GpuSapBroadphase(cl_context ctx,cl_device_id device, cl_command_queue q )
@@ -77,8 +77,8 @@ b3GpuSapBroadphase::~b3GpuSapBroadphase()
} }
/// conservative test for overlap between two aabbs /// conservative test for overlap between two aabbs
static bool TestAabbAgainstAabb2(const btVector3 &aabbMin1, const btVector3 &aabbMax1, static bool TestAabbAgainstAabb2(const b3Vector3 &aabbMin1, const b3Vector3 &aabbMax1,
const btVector3 &aabbMin2, const btVector3 &aabbMax2) const b3Vector3 &aabbMin2, const b3Vector3 &aabbMax2)
{ {
bool overlap = true; bool overlap = true;
overlap = (aabbMin1.getX() > aabbMax2.getX() || aabbMax1.getX() < aabbMin2.getX()) ? false : overlap; overlap = (aabbMin1.getX() > aabbMax2.getX() || aabbMax1.getX() < aabbMin2.getX()) ? false : overlap;
@@ -192,7 +192,7 @@ void b3GpuSapBroadphase::calculateOverlappingPairsHost()
} }
} }
btAlignedObjectArray<btInt2> hostPairs; b3AlignedObjectArray<btInt2> hostPairs;
{ {
int numSmallAabbs = m_smallAabbsCPU.size(); int numSmallAabbs = m_smallAabbsCPU.size();
@@ -202,8 +202,8 @@ void b3GpuSapBroadphase::calculateOverlappingPairsHost()
for (int j=i+1;j<numSmallAabbs;j++) for (int j=i+1;j<numSmallAabbs;j++)
{ {
if (TestAabbAgainstAabb2((btVector3&)m_smallAabbsCPU[i].m_min, (btVector3&)m_smallAabbsCPU[i].m_max, if (TestAabbAgainstAabb2((b3Vector3&)m_smallAabbsCPU[i].m_min, (b3Vector3&)m_smallAabbsCPU[i].m_max,
(btVector3&)m_smallAabbsCPU[j].m_min,(btVector3&)m_smallAabbsCPU[j].m_max)) (b3Vector3&)m_smallAabbsCPU[j].m_min,(b3Vector3&)m_smallAabbsCPU[j].m_max))
{ {
btInt2 pair; btInt2 pair;
pair.x = m_smallAabbsCPU[i].m_minIndices[3];//store the original index in the unsorted aabb array pair.x = m_smallAabbsCPU[i].m_minIndices[3];//store the original index in the unsorted aabb array
@@ -224,8 +224,8 @@ void b3GpuSapBroadphase::calculateOverlappingPairsHost()
for (int j=0;j<numLargeAabbs;j++) for (int j=0;j<numLargeAabbs;j++)
{ {
if (TestAabbAgainstAabb2((btVector3&)m_smallAabbsCPU[i].m_min, (btVector3&)m_smallAabbsCPU[i].m_max, if (TestAabbAgainstAabb2((b3Vector3&)m_smallAabbsCPU[i].m_min, (b3Vector3&)m_smallAabbsCPU[i].m_max,
(btVector3&)m_largeAabbsCPU[j].m_min,(btVector3&)m_largeAabbsCPU[j].m_max)) (b3Vector3&)m_largeAabbsCPU[j].m_min,(b3Vector3&)m_largeAabbsCPU[j].m_max))
{ {
btInt2 pair; btInt2 pair;
pair.x = m_largeAabbsCPU[j].m_minIndices[3]; pair.x = m_largeAabbsCPU[j].m_minIndices[3];
@@ -485,7 +485,7 @@ void b3GpuSapBroadphase::calculateOverlappingPairs()
pairCount.setFromOpenCLBuffer(launcher.m_arrays[2]->getBufferCL(),numElements); pairCount.setFromOpenCLBuffer(launcher.m_arrays[2]->getBufferCL(),numElements);
numPairs = pairCount.at(0); numPairs = pairCount.at(0);
//printf("overlapping pairs = %d\n",numPairs); //printf("overlapping pairs = %d\n",numPairs);
btAlignedObjectArray<btInt2> hostOoverlappingPairs; b3AlignedObjectArray<btInt2> hostOoverlappingPairs;
btOpenCLArray<btInt2> tmpGpuPairs(m_context,m_queue); btOpenCLArray<btInt2> tmpGpuPairs(m_context,m_queue);
tmpGpuPairs.setFromOpenCLBuffer(launcher.m_arrays[1]->getBufferCL(),numPairs ); tmpGpuPairs.setFromOpenCLBuffer(launcher.m_arrays[1]->getBufferCL(),numPairs );
@@ -520,7 +520,7 @@ void b3GpuSapBroadphase::writeAabbsToGpu()
} }
void b3GpuSapBroadphase::createLargeProxy(const btVector3& aabbMin, const btVector3& aabbMax, int userPtr ,short int collisionFilterGroup,short int collisionFilterMask) void b3GpuSapBroadphase::createLargeProxy(const b3Vector3& aabbMin, const b3Vector3& aabbMax, int userPtr ,short int collisionFilterGroup,short int collisionFilterMask)
{ {
int index = userPtr; int index = userPtr;
b3SapAabb aabb; b3SapAabb aabb;
@@ -535,7 +535,7 @@ void b3GpuSapBroadphase::createLargeProxy(const btVector3& aabbMin, const btVec
m_allAabbsCPU.push_back(aabb); m_allAabbsCPU.push_back(aabb);
} }
void b3GpuSapBroadphase::createProxy(const btVector3& aabbMin, const btVector3& aabbMax, int userPtr ,short int collisionFilterGroup,short int collisionFilterMask) void b3GpuSapBroadphase::createProxy(const b3Vector3& aabbMin, const b3Vector3& aabbMax, int userPtr ,short int collisionFilterGroup,short int collisionFilterMask)
{ {
int index = userPtr; int index = userPtr;
b3SapAabb aabb; b3SapAabb aabb;

View File

@@ -3,7 +3,7 @@
#include "parallel_primitives/host/btOpenCLArray.h" #include "parallel_primitives/host/btOpenCLArray.h"
#include "parallel_primitives/host/btFillCL.h" //btInt2 #include "parallel_primitives/host/btFillCL.h" //btInt2
class btVector3; class b3Vector3;
#include "parallel_primitives/host/btRadixSort32CL.h" #include "parallel_primitives/host/btRadixSort32CL.h"
#include "b3SapAabb.h" #include "b3SapAabb.h"
@@ -25,19 +25,19 @@ class b3GpuSapBroadphase
class btRadixSort32CL* m_sorter; class btRadixSort32CL* m_sorter;
///test for 3d SAP ///test for 3d SAP
btAlignedObjectArray<btSortData> m_sortedAxisCPU[3][2]; b3AlignedObjectArray<btSortData> m_sortedAxisCPU[3][2];
int m_currentBuffer; int m_currentBuffer;
public: public:
btOpenCLArray<b3SapAabb> m_allAabbsGPU; btOpenCLArray<b3SapAabb> m_allAabbsGPU;
btAlignedObjectArray<b3SapAabb> m_allAabbsCPU; b3AlignedObjectArray<b3SapAabb> m_allAabbsCPU;
btOpenCLArray<b3SapAabb> m_smallAabbsGPU; btOpenCLArray<b3SapAabb> m_smallAabbsGPU;
btAlignedObjectArray<b3SapAabb> m_smallAabbsCPU; b3AlignedObjectArray<b3SapAabb> m_smallAabbsCPU;
btOpenCLArray<b3SapAabb> m_largeAabbsGPU; btOpenCLArray<b3SapAabb> m_largeAabbsGPU;
btAlignedObjectArray<b3SapAabb> m_largeAabbsCPU; b3AlignedObjectArray<b3SapAabb> m_largeAabbsCPU;
btOpenCLArray<btInt2> m_overlappingPairs; btOpenCLArray<btInt2> m_overlappingPairs;
@@ -55,8 +55,8 @@ class b3GpuSapBroadphase
void init3dSap(); void init3dSap();
void calculateOverlappingPairsHostIncremental3Sap(); void calculateOverlappingPairsHostIncremental3Sap();
void createProxy(const btVector3& aabbMin, const btVector3& aabbMax, int userPtr ,short int collisionFilterGroup,short int collisionFilterMask); void createProxy(const b3Vector3& aabbMin, const b3Vector3& aabbMax, int userPtr ,short int collisionFilterGroup,short int collisionFilterMask);
void createLargeProxy(const btVector3& aabbMin, const btVector3& aabbMax, int userPtr ,short int collisionFilterGroup,short int collisionFilterMask); void createLargeProxy(const b3Vector3& aabbMin, const b3Vector3& aabbMax, int userPtr ,short int collisionFilterGroup,short int collisionFilterMask);
//call writeAabbsToGpu after done making all changes (createProxy etc) //call writeAabbsToGpu after done making all changes (createProxy etc)
void writeAabbsToGpu(); void writeAabbsToGpu();

View File

@@ -16,13 +16,13 @@ subject to the following restrictions:
#include <stdio.h> #include <stdio.h>
#include "../basic_initialize/b3OpenCLUtils.h" #include "../basic_initialize/b3OpenCLUtils.h"
#include "../host/b3GpuSapBroadphase.h" #include "../host/b3GpuSapBroadphase.h"
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
#include "parallel_primitives/host/btFillCL.h" #include "parallel_primitives/host/btFillCL.h"
#include "parallel_primitives/host/btBoundSearchCL.h" #include "parallel_primitives/host/btBoundSearchCL.h"
#include "parallel_primitives/host/btRadixSort32CL.h" #include "parallel_primitives/host/btRadixSort32CL.h"
#include "parallel_primitives/host/btPrefixScanCL.h" #include "parallel_primitives/host/btPrefixScanCL.h"
#include "BulletCommon/CommandLineArgs.h" #include "BulletCommon/b3CommandLineArgs.h"
#include "BulletCommon/btMinMax.h" #include "BulletCommon/b3MinMax.h"
int g_nPassed = 0; int g_nPassed = 0;
int g_nFailed = 0; int g_nFailed = 0;
@@ -76,8 +76,8 @@ inline void broadphaseTest()
b3GpuSapBroadphase* sap = new b3GpuSapBroadphase(g_context,g_device,g_queue); b3GpuSapBroadphase* sap = new b3GpuSapBroadphase(g_context,g_device,g_queue);
int group=1; int group=1;
int mask=1; int mask=1;
btVector3 aabbMin(0,0,0); b3Vector3 aabbMin(0,0,0);
btVector3 aabbMax(1,1,1); b3Vector3 aabbMax(1,1,1);
int usrPtr = 1; int usrPtr = 1;
sap->createProxy(aabbMin,aabbMax,usrPtr,group,mask); sap->createProxy(aabbMin,aabbMax,usrPtr,group,mask);
@@ -105,7 +105,7 @@ int main(int argc, char** argv)
int preferredDeviceIndex = -1; int preferredDeviceIndex = -1;
int preferredPlatformIndex = -1; int preferredPlatformIndex = -1;
CommandLineArgs args(argc, argv); b3CommandLineArgs args(argc, argv);
args.GetCmdLineArgument("deviceId", preferredDeviceIndex); args.GetCmdLineArgument("deviceId", preferredDeviceIndex);
args.GetCmdLineArgument("platformId", preferredPlatformIndex); args.GetCmdLineArgument("platformId", preferredPlatformIndex);

View File

@@ -29,11 +29,11 @@ function createProject(vendor)
"../../parallel_primitives/host/btPrefixScanCL.h", "../../parallel_primitives/host/btPrefixScanCL.h",
"../../parallel_primitives/host/btRadixSort32CL.cpp", "../../parallel_primitives/host/btRadixSort32CL.cpp",
"../../parallel_primitives/host/btRadixSort32CL.h", "../../parallel_primitives/host/btRadixSort32CL.h",
"../../../src/BulletCommon/btAlignedAllocator.cpp", "../../../src/BulletCommon/b3AlignedAllocator.cpp",
"../../../src/BulletCommon/btAlignedAllocator.h", "../../../src/BulletCommon/b3AlignedAllocator.h",
"../../../src/BulletCommon/btAlignedObjectArray.h", "../../../src/BulletCommon/b3AlignedObjectArray.h",
"../../../src/BulletCommon/btQuickprof.cpp", "../../../src/BulletCommon/b3Quickprof.cpp",
"../../../src/BulletCommon/btQuickprof.h", "../../../src/BulletCommon/b3Quickprof.h",
} }

View File

@@ -1,15 +1,15 @@
#ifndef BT_CONTACT4_H #ifndef BT_CONTACT4_H
#define BT_CONTACT4_H #define BT_CONTACT4_H
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
ATTRIBUTE_ALIGNED16(struct) b3Contact4 ATTRIBUTE_ALIGNED16(struct) b3Contact4
{ {
BT_DECLARE_ALIGNED_ALLOCATOR(); BT_DECLARE_ALIGNED_ALLOCATOR();
btVector3 m_worldPos[4]; b3Vector3 m_worldPos[4];
btVector3 m_worldNormal; b3Vector3 m_worldNormal;
// float m_restituitionCoeff; // float m_restituitionCoeff;
// float m_frictionCoeff; // float m_frictionCoeff;
unsigned short m_restituitionCoeffCmp; unsigned short m_restituitionCoeffCmp;

View File

@@ -25,8 +25,8 @@ subject to the following restrictions:
#include "b3ConvexPolyhedronCL.h" #include "b3ConvexPolyhedronCL.h"
typedef btAlignedObjectArray<btVector3> btVertexArray; typedef b3AlignedObjectArray<b3Vector3> btVertexArray;
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include <float.h> //for FLT_MAX #include <float.h> //for FLT_MAX
#include "basic_initialize/b3OpenCLUtils.h" #include "basic_initialize/b3OpenCLUtils.h"
@@ -219,7 +219,7 @@ struct MyTriangleCallback : public btNodeOverlapCallback
}; };
#define float4 btVector3 #define float4 b3Vector3
#define make_float4(x,y,z,w) btVector4(x,y,z,w) #define make_float4(x,y,z,w) btVector4(x,y,z,w)
float signedDistanceFromPointToPlane(const float4& point, const float4& planeEqn, float4* closestPointOnFace) float signedDistanceFromPointToPlane(const float4& point, const float4& planeEqn, float4* closestPointOnFace)
@@ -234,14 +234,14 @@ float signedDistanceFromPointToPlane(const float4& point, const float4& planeEqn
#define cross3(a,b) (a.cross(b)) #define cross3(a,b) (a.cross(b))
btVector3 transform(btVector3* v, const btVector3* pos, const btVector3* orn) b3Vector3 transform(b3Vector3* v, const b3Vector3* pos, const b3Vector3* orn)
{ {
btTransform tr; b3Transform tr;
tr.setIdentity(); tr.setIdentity();
tr.setOrigin(*pos); tr.setOrigin(*pos);
btQuaternion* o = (btQuaternion*) orn; b3Quaternion* o = (b3Quaternion*) orn;
tr.setRotation(*o); tr.setRotation(*o);
btVector3 res = tr(*v); b3Vector3 res = tr(*v);
return res; return res;
} }
@@ -411,7 +411,7 @@ void computeContactPlaneConvex(int pairIndex,
const b3RigidBodyCL* rigidBodies, const b3RigidBodyCL* rigidBodies,
const b3Collidable* collidables, const b3Collidable* collidables,
const b3ConvexPolyhedronCL* convexShapes, const b3ConvexPolyhedronCL* convexShapes,
const btVector3* convexVertices, const b3Vector3* convexVertices,
const int* convexIndices, const int* convexIndices,
const btGpuFace* faces, const btGpuFace* faces,
b3Contact4* globalContactsOut, b3Contact4* globalContactsOut,
@@ -422,40 +422,40 @@ void computeContactPlaneConvex(int pairIndex,
int shapeIndex = collidables[collidableIndexB].m_shapeIndex; int shapeIndex = collidables[collidableIndexB].m_shapeIndex;
const b3ConvexPolyhedronCL* hullB = &convexShapes[shapeIndex]; const b3ConvexPolyhedronCL* hullB = &convexShapes[shapeIndex];
btVector3 posB = rigidBodies[bodyIndexB].m_pos; b3Vector3 posB = rigidBodies[bodyIndexB].m_pos;
btQuaternion ornB = rigidBodies[bodyIndexB].m_quat; b3Quaternion ornB = rigidBodies[bodyIndexB].m_quat;
btVector3 posA = rigidBodies[bodyIndexA].m_pos; b3Vector3 posA = rigidBodies[bodyIndexA].m_pos;
btQuaternion ornA = rigidBodies[bodyIndexA].m_quat; b3Quaternion ornA = rigidBodies[bodyIndexA].m_quat;
int numContactsOut = 0; int numContactsOut = 0;
int numWorldVertsB1= 0; int numWorldVertsB1= 0;
btVector3 planeEq = faces[collidables[collidableIndexA].m_shapeIndex].m_plane; b3Vector3 planeEq = faces[collidables[collidableIndexA].m_shapeIndex].m_plane;
btVector3 planeNormal(planeEq.x,planeEq.y,planeEq.z); b3Vector3 planeNormal(planeEq.x,planeEq.y,planeEq.z);
btVector3 planeNormalWorld = quatRotate(ornA,planeNormal); b3Vector3 planeNormalWorld = quatRotate(ornA,planeNormal);
float planeConstant = planeEq.w; float planeConstant = planeEq.w;
btTransform convexWorldTransform; b3Transform convexWorldTransform;
convexWorldTransform.setIdentity(); convexWorldTransform.setIdentity();
convexWorldTransform.setOrigin(posB); convexWorldTransform.setOrigin(posB);
convexWorldTransform.setRotation(ornB); convexWorldTransform.setRotation(ornB);
btTransform planeTransform; b3Transform planeTransform;
planeTransform.setIdentity(); planeTransform.setIdentity();
planeTransform.setOrigin(posA); planeTransform.setOrigin(posA);
planeTransform.setRotation(ornA); planeTransform.setRotation(ornA);
btTransform planeInConvex; b3Transform planeInConvex;
planeInConvex= convexWorldTransform.inverse() * planeTransform; planeInConvex= convexWorldTransform.inverse() * planeTransform;
btTransform convexInPlane; b3Transform convexInPlane;
convexInPlane = planeTransform.inverse() * convexWorldTransform; convexInPlane = planeTransform.inverse() * convexWorldTransform;
btVector3 planeNormalInConvex = planeInConvex.getBasis()*-planeNormal; b3Vector3 planeNormalInConvex = planeInConvex.getBasis()*-planeNormal;
float maxDot = -1e30; float maxDot = -1e30;
int hitVertex=-1; int hitVertex=-1;
btVector3 hitVtx; b3Vector3 hitVtx;
#define MAX_PLANE_CONVEX_POINTS 64 #define MAX_PLANE_CONVEX_POINTS 64
btVector3 contactPoints[MAX_PLANE_CONVEX_POINTS]; b3Vector3 contactPoints[MAX_PLANE_CONVEX_POINTS];
int numPoints = 0; int numPoints = 0;
btInt4 contactIdx; btInt4 contactIdx;
@@ -466,7 +466,7 @@ void computeContactPlaneConvex(int pairIndex,
for (int i=0;i<hullB->m_numVertices;i++) for (int i=0;i<hullB->m_numVertices;i++)
{ {
btVector3 vtx = convexVertices[hullB->m_vertexOffset+i]; b3Vector3 vtx = convexVertices[hullB->m_vertexOffset+i];
float curDot = vtx.dot(planeNormalInConvex); float curDot = vtx.dot(planeNormalInConvex);
@@ -482,8 +482,8 @@ void computeContactPlaneConvex(int pairIndex,
if (numPoints<MAX_PLANE_CONVEX_POINTS) if (numPoints<MAX_PLANE_CONVEX_POINTS)
{ {
btVector3 vtxWorld = convexWorldTransform*vtx; b3Vector3 vtxWorld = convexWorldTransform*vtx;
btVector3 vtxInPlane = planeTransform.inverse()*vtxWorld; b3Vector3 vtxInPlane = planeTransform.inverse()*vtxWorld;
float dist = planeNormal.dot(vtxInPlane)-planeConstant; float dist = planeNormal.dot(vtxInPlane)-planeConstant;
if (dist<0.f) if (dist<0.f)
{ {
@@ -523,7 +523,7 @@ void computeContactPlaneConvex(int pairIndex,
c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB; c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB;
for (int i=0;i<numReducedPoints;i++) for (int i=0;i<numReducedPoints;i++)
{ {
btVector3 pOnB1 = contactPoints[contactIdx.s[i]]; b3Vector3 pOnB1 = contactPoints[contactIdx.s[i]];
c->m_worldPos[i] = pOnB1; c->m_worldPos[i] = pOnB1;
} }
c->m_worldNormal[3] = numReducedPoints; c->m_worldNormal[3] = numReducedPoints;
@@ -544,7 +544,7 @@ void computeContactPlaneCompound(int pairIndex,
const b3RigidBodyCL* rigidBodies, const b3RigidBodyCL* rigidBodies,
const b3Collidable* collidables, const b3Collidable* collidables,
const b3ConvexPolyhedronCL* convexShapes, const b3ConvexPolyhedronCL* convexShapes,
const btVector3* convexVertices, const b3Vector3* convexVertices,
const int* convexIndices, const int* convexIndices,
const btGpuFace* faces, const btGpuFace* faces,
b3Contact4* globalContactsOut, b3Contact4* globalContactsOut,
@@ -560,40 +560,40 @@ void computeContactPlaneCompound(int pairIndex,
int shapeIndex = collidables[collidableIndexB].m_shapeIndex; int shapeIndex = collidables[collidableIndexB].m_shapeIndex;
const b3ConvexPolyhedronCL* hullB = &convexShapes[shapeIndex]; const b3ConvexPolyhedronCL* hullB = &convexShapes[shapeIndex];
btVector3 posB = rigidBodies[bodyIndexB].m_pos; b3Vector3 posB = rigidBodies[bodyIndexB].m_pos;
btQuaternion ornB = rigidBodies[bodyIndexB].m_quat; b3Quaternion ornB = rigidBodies[bodyIndexB].m_quat;
btVector3 posA = rigidBodies[bodyIndexA].m_pos; b3Vector3 posA = rigidBodies[bodyIndexA].m_pos;
btQuaternion ornA = rigidBodies[bodyIndexA].m_quat; b3Quaternion ornA = rigidBodies[bodyIndexA].m_quat;
int numContactsOut = 0; int numContactsOut = 0;
int numWorldVertsB1= 0; int numWorldVertsB1= 0;
btVector3 planeEq = faces[collidables[collidableIndexA].m_shapeIndex].m_plane; b3Vector3 planeEq = faces[collidables[collidableIndexA].m_shapeIndex].m_plane;
btVector3 planeNormal(planeEq.x,planeEq.y,planeEq.z); b3Vector3 planeNormal(planeEq.x,planeEq.y,planeEq.z);
btVector3 planeNormalWorld = quatRotate(ornA,planeNormal); b3Vector3 planeNormalWorld = quatRotate(ornA,planeNormal);
float planeConstant = planeEq.w; float planeConstant = planeEq.w;
btTransform convexWorldTransform; b3Transform convexWorldTransform;
convexWorldTransform.setIdentity(); convexWorldTransform.setIdentity();
convexWorldTransform.setOrigin(posB); convexWorldTransform.setOrigin(posB);
convexWorldTransform.setRotation(ornB); convexWorldTransform.setRotation(ornB);
btTransform planeTransform; b3Transform planeTransform;
planeTransform.setIdentity(); planeTransform.setIdentity();
planeTransform.setOrigin(posA); planeTransform.setOrigin(posA);
planeTransform.setRotation(ornA); planeTransform.setRotation(ornA);
btTransform planeInConvex; b3Transform planeInConvex;
planeInConvex= convexWorldTransform.inverse() * planeTransform; planeInConvex= convexWorldTransform.inverse() * planeTransform;
btTransform convexInPlane; b3Transform convexInPlane;
convexInPlane = planeTransform.inverse() * convexWorldTransform; convexInPlane = planeTransform.inverse() * convexWorldTransform;
btVector3 planeNormalInConvex = planeInConvex.getBasis()*-planeNormal; b3Vector3 planeNormalInConvex = planeInConvex.getBasis()*-planeNormal;
float maxDot = -1e30; float maxDot = -1e30;
int hitVertex=-1; int hitVertex=-1;
btVector3 hitVtx; b3Vector3 hitVtx;
#define MAX_PLANE_CONVEX_POINTS 64 #define MAX_PLANE_CONVEX_POINTS 64
btVector3 contactPoints[MAX_PLANE_CONVEX_POINTS]; b3Vector3 contactPoints[MAX_PLANE_CONVEX_POINTS];
int numPoints = 0; int numPoints = 0;
btInt4 contactIdx; btInt4 contactIdx;
@@ -604,7 +604,7 @@ void computeContactPlaneCompound(int pairIndex,
for (int i=0;i<hullB->m_numVertices;i++) for (int i=0;i<hullB->m_numVertices;i++)
{ {
btVector3 vtx = convexVertices[hullB->m_vertexOffset+i]; b3Vector3 vtx = convexVertices[hullB->m_vertexOffset+i];
float curDot = vtx.dot(planeNormalInConvex); float curDot = vtx.dot(planeNormalInConvex);
@@ -620,8 +620,8 @@ void computeContactPlaneCompound(int pairIndex,
if (numPoints<MAX_PLANE_CONVEX_POINTS) if (numPoints<MAX_PLANE_CONVEX_POINTS)
{ {
btVector3 vtxWorld = convexWorldTransform*vtx; b3Vector3 vtxWorld = convexWorldTransform*vtx;
btVector3 vtxInPlane = planeTransform.inverse()*vtxWorld; b3Vector3 vtxInPlane = planeTransform.inverse()*vtxWorld;
float dist = planeNormal.dot(vtxInPlane)-planeConstant; float dist = planeNormal.dot(vtxInPlane)-planeConstant;
if (dist<0.f) if (dist<0.f)
{ {
@@ -661,7 +661,7 @@ void computeContactPlaneCompound(int pairIndex,
c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB; c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB;
for (int i=0;i<numReducedPoints;i++) for (int i=0;i<numReducedPoints;i++)
{ {
btVector3 pOnB1 = contactPoints[contactIdx.s[i]]; b3Vector3 pOnB1 = contactPoints[contactIdx.s[i]];
c->m_worldPos[i] = pOnB1; c->m_worldPos[i] = pOnB1;
} }
c->m_worldNormal[3] = numReducedPoints; c->m_worldNormal[3] = numReducedPoints;
@@ -683,7 +683,7 @@ void computeContactSphereConvex(int pairIndex,
const b3RigidBodyCL* rigidBodies, const b3RigidBodyCL* rigidBodies,
const b3Collidable* collidables, const b3Collidable* collidables,
const b3ConvexPolyhedronCL* convexShapes, const b3ConvexPolyhedronCL* convexShapes,
const btVector3* convexVertices, const b3Vector3* convexVertices,
const int* convexIndices, const int* convexIndices,
const btGpuFace* faces, const btGpuFace* faces,
b3Contact4* globalContactsOut, b3Contact4* globalContactsOut,
@@ -693,20 +693,20 @@ void computeContactSphereConvex(int pairIndex,
float radius = collidables[collidableIndexA].m_radius; float radius = collidables[collidableIndexA].m_radius;
float4 spherePos1 = rigidBodies[bodyIndexA].m_pos; float4 spherePos1 = rigidBodies[bodyIndexA].m_pos;
btQuaternion sphereOrn = rigidBodies[bodyIndexA].m_quat; b3Quaternion sphereOrn = rigidBodies[bodyIndexA].m_quat;
float4 pos = rigidBodies[bodyIndexB].m_pos; float4 pos = rigidBodies[bodyIndexB].m_pos;
btQuaternion quat = rigidBodies[bodyIndexB].m_quat; b3Quaternion quat = rigidBodies[bodyIndexB].m_quat;
btTransform tr; b3Transform tr;
tr.setIdentity(); tr.setIdentity();
tr.setOrigin(pos); tr.setOrigin(pos);
tr.setRotation(quat); tr.setRotation(quat);
btTransform trInv = tr.inverse(); b3Transform trInv = tr.inverse();
float4 spherePos = trInv(spherePos1); float4 spherePos = trInv(spherePos1);
@@ -740,7 +740,7 @@ void computeContactSphereConvex(int pairIndex,
if ( dist > 0 ) if ( dist > 0 )
{ {
//might hit an edge or vertex //might hit an edge or vertex
btVector3 out; b3Vector3 out;
bool isInPoly = IsPointInPolygon(spherePos, bool isInPoly = IsPointInPolygon(spherePos,
&face, &face,
@@ -758,8 +758,8 @@ void computeContactSphereConvex(int pairIndex,
} }
} else } else
{ {
btVector3 tmp = spherePos-out; b3Vector3 tmp = spherePos-out;
btScalar l2 = tmp.length2(); b3Scalar l2 = tmp.length2();
if (l2<radius*radius) if (l2<radius*radius)
{ {
dist = btSqrt(l2); dist = btSqrt(l2);
@@ -837,20 +837,20 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray<btI
btOpenCLArray<b3Contact4>* contactOut, int& nContacts, btOpenCLArray<b3Contact4>* contactOut, int& nContacts,
int maxContactCapacity, int maxContactCapacity,
const btOpenCLArray<b3ConvexPolyhedronCL>& convexData, const btOpenCLArray<b3ConvexPolyhedronCL>& convexData,
const btOpenCLArray<btVector3>& gpuVertices, const btOpenCLArray<b3Vector3>& gpuVertices,
const btOpenCLArray<btVector3>& gpuUniqueEdges, const btOpenCLArray<b3Vector3>& gpuUniqueEdges,
const btOpenCLArray<btGpuFace>& gpuFaces, const btOpenCLArray<btGpuFace>& gpuFaces,
const btOpenCLArray<int>& gpuIndices, const btOpenCLArray<int>& gpuIndices,
const btOpenCLArray<b3Collidable>& gpuCollidables, const btOpenCLArray<b3Collidable>& gpuCollidables,
const btOpenCLArray<btGpuChildShape>& gpuChildShapes, const btOpenCLArray<btGpuChildShape>& gpuChildShapes,
const btOpenCLArray<btYetAnotherAabb>& clAabbsWS, const btOpenCLArray<btYetAnotherAabb>& clAabbsWS,
btOpenCLArray<btVector3>& worldVertsB1GPU, btOpenCLArray<b3Vector3>& worldVertsB1GPU,
btOpenCLArray<btInt4>& clippingFacesOutGPU, btOpenCLArray<btInt4>& clippingFacesOutGPU,
btOpenCLArray<btVector3>& worldNormalsAGPU, btOpenCLArray<b3Vector3>& worldNormalsAGPU,
btOpenCLArray<btVector3>& worldVertsA1GPU, btOpenCLArray<b3Vector3>& worldVertsA1GPU,
btOpenCLArray<btVector3>& worldVertsB2GPU, btOpenCLArray<b3Vector3>& worldVertsB2GPU,
btAlignedObjectArray<class b3OptimizedBvh*>& bvhData, b3AlignedObjectArray<class b3OptimizedBvh*>& bvhData,
btOpenCLArray<btQuantizedBvhNode>* treeNodesGPU, btOpenCLArray<btQuantizedBvhNode>* treeNodesGPU,
btOpenCLArray<btBvhSubtreeInfo>* subTreesGPU, btOpenCLArray<btBvhSubtreeInfo>* subTreesGPU,
int numObjects, int numObjects,
@@ -865,38 +865,38 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray<btI
//#define CHECK_ON_HOST //#define CHECK_ON_HOST
#ifdef CHECK_ON_HOST #ifdef CHECK_ON_HOST
btAlignedObjectArray<btYetAnotherAabb> hostAabbs; b3AlignedObjectArray<btYetAnotherAabb> hostAabbs;
clAabbsWS.copyToHost(hostAabbs); clAabbsWS.copyToHost(hostAabbs);
btAlignedObjectArray<btInt2> hostPairs; b3AlignedObjectArray<btInt2> hostPairs;
pairs->copyToHost(hostPairs); pairs->copyToHost(hostPairs);
btAlignedObjectArray<b3RigidBodyCL> hostBodyBuf; b3AlignedObjectArray<b3RigidBodyCL> hostBodyBuf;
bodyBuf->copyToHost(hostBodyBuf); bodyBuf->copyToHost(hostBodyBuf);
btAlignedObjectArray<b3ConvexPolyhedronCL> hostConvexData; b3AlignedObjectArray<b3ConvexPolyhedronCL> hostConvexData;
convexData.copyToHost(hostConvexData); convexData.copyToHost(hostConvexData);
btAlignedObjectArray<btVector3> hostVertices; b3AlignedObjectArray<b3Vector3> hostVertices;
gpuVertices.copyToHost(hostVertices); gpuVertices.copyToHost(hostVertices);
btAlignedObjectArray<btVector3> hostUniqueEdges; b3AlignedObjectArray<b3Vector3> hostUniqueEdges;
gpuUniqueEdges.copyToHost(hostUniqueEdges); gpuUniqueEdges.copyToHost(hostUniqueEdges);
btAlignedObjectArray<btGpuFace> hostFaces; b3AlignedObjectArray<btGpuFace> hostFaces;
gpuFaces.copyToHost(hostFaces); gpuFaces.copyToHost(hostFaces);
btAlignedObjectArray<int> hostIndices; b3AlignedObjectArray<int> hostIndices;
gpuIndices.copyToHost(hostIndices); gpuIndices.copyToHost(hostIndices);
btAlignedObjectArray<b3Collidable> hostCollidables; b3AlignedObjectArray<b3Collidable> hostCollidables;
gpuCollidables.copyToHost(hostCollidables); gpuCollidables.copyToHost(hostCollidables);
btAlignedObjectArray<btGpuChildShape> cpuChildShapes; b3AlignedObjectArray<btGpuChildShape> cpuChildShapes;
gpuChildShapes.copyToHost(cpuChildShapes); gpuChildShapes.copyToHost(cpuChildShapes);
btAlignedObjectArray<btInt4> hostTriangleConvexPairs; b3AlignedObjectArray<btInt4> hostTriangleConvexPairs;
btAlignedObjectArray<b3Contact4> hostContacts; b3AlignedObjectArray<b3Contact4> hostContacts;
if (nContacts) if (nContacts)
{ {
contactOut->copyToHost(hostContacts); contactOut->copyToHost(hostContacts);
@@ -1013,13 +1013,13 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray<btI
BT_PROFILE("computeConvexConvexContactsGPUSAT"); BT_PROFILE("computeConvexConvexContactsGPUSAT");
// printf("nContacts = %d\n",nContacts); // printf("nContacts = %d\n",nContacts);
btOpenCLArray<btVector3> sepNormals(m_context,m_queue); btOpenCLArray<b3Vector3> sepNormals(m_context,m_queue);
sepNormals.resize(nPairs); sepNormals.resize(nPairs);
btOpenCLArray<int> hasSeparatingNormals(m_context,m_queue); btOpenCLArray<int> hasSeparatingNormals(m_context,m_queue);
hasSeparatingNormals.resize(nPairs); hasSeparatingNormals.resize(nPairs);
int concaveCapacity=maxTriConvexPairCapacity; int concaveCapacity=maxTriConvexPairCapacity;
btOpenCLArray<btVector3> concaveSepNormals(m_context,m_queue); btOpenCLArray<b3Vector3> concaveSepNormals(m_context,m_queue);
concaveSepNormals.resize(concaveCapacity); concaveSepNormals.resize(concaveCapacity);
btOpenCLArray<int> numConcavePairsOut(m_context,m_queue); btOpenCLArray<int> numConcavePairsOut(m_context,m_queue);
@@ -1029,7 +1029,7 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray<btI
btOpenCLArray<btCompoundOverlappingPair> gpuCompoundPairs(m_context,m_queue); btOpenCLArray<btCompoundOverlappingPair> gpuCompoundPairs(m_context,m_queue);
gpuCompoundPairs.resize(compoundPairCapacity); gpuCompoundPairs.resize(compoundPairCapacity);
btOpenCLArray<btVector3> gpuCompoundSepNormals(m_context,m_queue); btOpenCLArray<b3Vector3> gpuCompoundSepNormals(m_context,m_queue);
gpuCompoundSepNormals.resize(compoundPairCapacity); gpuCompoundSepNormals.resize(compoundPairCapacity);
@@ -1081,9 +1081,9 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray<btI
if (numNodes) if (numNodes)
{ {
int numSubTrees = subTreesGPU->size(); int numSubTrees = subTreesGPU->size();
btVector3 bvhAabbMin = bvhData[0]->m_bvhAabbMin; b3Vector3 bvhAabbMin = bvhData[0]->m_bvhAabbMin;
btVector3 bvhAabbMax = bvhData[0]->m_bvhAabbMax; b3Vector3 bvhAabbMax = bvhData[0]->m_bvhAabbMax;
btVector3 bvhQuantization = bvhData[0]->m_bvhQuantization; b3Vector3 bvhQuantization = bvhData[0]->m_bvhQuantization;
{ {
BT_PROFILE("m_bvhTraversalKernel"); BT_PROFILE("m_bvhTraversalKernel");
numConcavePairs = numConcavePairsOut.at(0); numConcavePairs = numConcavePairsOut.at(0);
@@ -1142,9 +1142,9 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray<btI
launcher.launch1D( num); launcher.launch1D( num);
clFinish(m_queue); clFinish(m_queue);
// btAlignedObjectArray<btVector3> cpuCompoundSepNormals; // b3AlignedObjectArray<b3Vector3> cpuCompoundSepNormals;
// concaveSepNormals.copyToHost(cpuCompoundSepNormals); // concaveSepNormals.copyToHost(cpuCompoundSepNormals);
// btAlignedObjectArray<btInt4> cpuConcavePairs; // b3AlignedObjectArray<btInt4> cpuConcavePairs;
// triangleConvexPairsOut.copyToHost(cpuConcavePairs); // triangleConvexPairsOut.copyToHost(cpuConcavePairs);
@@ -1355,7 +1355,7 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray<btI
clFinish(m_queue); clFinish(m_queue);
nContacts = m_totalContactsOut.at(0); nContacts = m_totalContactsOut.at(0);
contactOut->resize(nContacts); contactOut->resize(nContacts);
btAlignedObjectArray<b3Contact4> cpuContacts; b3AlignedObjectArray<b3Contact4> cpuContacts;
contactOut->copyToHost(cpuContacts); contactOut->copyToHost(cpuContacts);
// printf("nContacts after = %d\n", nContacts); // printf("nContacts after = %d\n", nContacts);
} }

View File

@@ -4,7 +4,7 @@
#include "parallel_primitives/host/btOpenCLArray.h" #include "parallel_primitives/host/btOpenCLArray.h"
#include "b3RigidBodyCL.h" #include "b3RigidBodyCL.h"
#include "BulletCommon/btAlignedObjectArray.h" #include "BulletCommon/b3AlignedObjectArray.h"
#include "b3ConvexUtility.h" #include "b3ConvexUtility.h"
#include "b3ConvexPolyhedronCL.h" #include "b3ConvexPolyhedronCL.h"
#include "b3Collidable.h" #include "b3Collidable.h"
@@ -69,20 +69,20 @@ struct GpuSatCollision
btOpenCLArray<b3Contact4>* contactOut, int& nContacts, btOpenCLArray<b3Contact4>* contactOut, int& nContacts,
int maxContactCapacity, int maxContactCapacity,
const btOpenCLArray<b3ConvexPolyhedronCL>& hostConvexData, const btOpenCLArray<b3ConvexPolyhedronCL>& hostConvexData,
const btOpenCLArray<btVector3>& vertices, const btOpenCLArray<b3Vector3>& vertices,
const btOpenCLArray<btVector3>& uniqueEdges, const btOpenCLArray<b3Vector3>& uniqueEdges,
const btOpenCLArray<btGpuFace>& faces, const btOpenCLArray<btGpuFace>& faces,
const btOpenCLArray<int>& indices, const btOpenCLArray<int>& indices,
const btOpenCLArray<b3Collidable>& gpuCollidables, const btOpenCLArray<b3Collidable>& gpuCollidables,
const btOpenCLArray<btGpuChildShape>& gpuChildShapes, const btOpenCLArray<btGpuChildShape>& gpuChildShapes,
const btOpenCLArray<btYetAnotherAabb>& clAabbs, const btOpenCLArray<btYetAnotherAabb>& clAabbs,
btOpenCLArray<btVector3>& worldVertsB1GPU, btOpenCLArray<b3Vector3>& worldVertsB1GPU,
btOpenCLArray<btInt4>& clippingFacesOutGPU, btOpenCLArray<btInt4>& clippingFacesOutGPU,
btOpenCLArray<btVector3>& worldNormalsAGPU, btOpenCLArray<b3Vector3>& worldNormalsAGPU,
btOpenCLArray<btVector3>& worldVertsA1GPU, btOpenCLArray<b3Vector3>& worldVertsA1GPU,
btOpenCLArray<btVector3>& worldVertsB2GPU, btOpenCLArray<b3Vector3>& worldVertsB2GPU,
btAlignedObjectArray<class b3OptimizedBvh*>& bvhData, b3AlignedObjectArray<class b3OptimizedBvh*>& bvhData,
btOpenCLArray<btQuantizedBvhNode>* treeNodesGPU, btOpenCLArray<btQuantizedBvhNode>* treeNodesGPU,
btOpenCLArray<btBvhSubtreeInfo>* subTreesGPU, btOpenCLArray<btBvhSubtreeInfo>* subTreesGPU,
int numObjects, int numObjects,

View File

@@ -1,7 +1,7 @@
#ifndef CONVEX_POLYHEDRON_CL #ifndef CONVEX_POLYHEDRON_CL
#define CONVEX_POLYHEDRON_CL #define CONVEX_POLYHEDRON_CL
#include "BulletCommon/btTransform.h" #include "BulletCommon/b3Transform.h"
struct btGpuFace struct btGpuFace
{ {
@@ -12,12 +12,12 @@ struct btGpuFace
ATTRIBUTE_ALIGNED16(struct) b3ConvexPolyhedronCL ATTRIBUTE_ALIGNED16(struct) b3ConvexPolyhedronCL
{ {
btVector3 m_localCenter; b3Vector3 m_localCenter;
btVector3 m_extents; b3Vector3 m_extents;
btVector3 mC; b3Vector3 mC;
btVector3 mE; b3Vector3 mE;
btScalar m_radius; b3Scalar m_radius;
int m_faceOffset; int m_faceOffset;
int m_numFaces; int m_numFaces;
int m_numVertices; int m_numVertices;
@@ -29,29 +29,29 @@ ATTRIBUTE_ALIGNED16(struct) b3ConvexPolyhedronCL
inline void project(const btTransform& trans, const btVector3& dir, const btAlignedObjectArray<btVector3>& vertices, btScalar& min, btScalar& max) const inline void project(const b3Transform& trans, const b3Vector3& dir, const b3AlignedObjectArray<b3Vector3>& vertices, b3Scalar& min, b3Scalar& max) const
{ {
min = FLT_MAX; min = FLT_MAX;
max = -FLT_MAX; max = -FLT_MAX;
int numVerts = m_numVertices; int numVerts = m_numVertices;
const btVector3 localDir = trans.getBasis().transpose()*dir; const b3Vector3 localDir = trans.getBasis().transpose()*dir;
const btVector3 localDi2 = quatRotate(trans.getRotation().inverse(),dir); const b3Vector3 localDi2 = quatRotate(trans.getRotation().inverse(),dir);
btScalar offset = trans.getOrigin().dot(dir); b3Scalar offset = trans.getOrigin().dot(dir);
for(int i=0;i<numVerts;i++) for(int i=0;i<numVerts;i++)
{ {
//btVector3 pt = trans * vertices[m_vertexOffset+i]; //b3Vector3 pt = trans * vertices[m_vertexOffset+i];
//btScalar dp = pt.dot(dir); //b3Scalar dp = pt.dot(dir);
btScalar dp = vertices[m_vertexOffset+i].dot(localDir); b3Scalar dp = vertices[m_vertexOffset+i].dot(localDir);
//btAssert(dp==dpL); //btAssert(dp==dpL);
if(dp < min) min = dp; if(dp < min) min = dp;
if(dp > max) max = dp; if(dp > max) max = dp;
} }
if(min>max) if(min>max)
{ {
btScalar tmp = min; b3Scalar tmp = min;
min = max; min = max;
max = tmp; max = tmp;
} }

View File

@@ -17,8 +17,8 @@ subject to the following restrictions:
#include "b3ConvexUtility.h" #include "b3ConvexUtility.h"
#include "BulletGeometry/btConvexHullComputer.h" #include "BulletGeometry/btConvexHullComputer.h"
#include "BulletGeometry/btGrahamScan2dConvexHull.h" #include "BulletGeometry/btGrahamScan2dConvexHull.h"
#include "BulletCommon/btQuaternion.h" #include "BulletCommon/b3Quaternion.h"
#include "BulletCommon/btHashMap.h" #include "BulletCommon/b3HashMap.h"
#include "b3ConvexPolyhedronCL.h" #include "b3ConvexPolyhedronCL.h"
@@ -28,21 +28,21 @@ b3ConvexUtility::~b3ConvexUtility()
{ {
} }
bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices, int numPoints, bool mergeCoplanarTriangles) bool b3ConvexUtility::initializePolyhedralFeatures(const b3Vector3* orgVertices, int numPoints, bool mergeCoplanarTriangles)
{ {
btConvexHullComputer conv; btConvexHullComputer conv;
conv.compute(&orgVertices[0].getX(), sizeof(btVector3),numPoints,0.f,0.f); conv.compute(&orgVertices[0].getX(), sizeof(b3Vector3),numPoints,0.f,0.f);
btAlignedObjectArray<btVector3> faceNormals; b3AlignedObjectArray<b3Vector3> faceNormals;
int numFaces = conv.faces.size(); int numFaces = conv.faces.size();
faceNormals.resize(numFaces); faceNormals.resize(numFaces);
btConvexHullComputer* convexUtil = &conv; btConvexHullComputer* convexUtil = &conv;
btAlignedObjectArray<btMyFace> tmpFaces; b3AlignedObjectArray<btMyFace> tmpFaces;
tmpFaces.resize(numFaces); tmpFaces.resize(numFaces);
int numVertices = convexUtil->vertices.size(); int numVertices = convexUtil->vertices.size();
@@ -60,7 +60,7 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
const btConvexHullComputer::Edge* firstEdge = &convexUtil->edges[face]; const btConvexHullComputer::Edge* firstEdge = &convexUtil->edges[face];
const btConvexHullComputer::Edge* edge = firstEdge; const btConvexHullComputer::Edge* edge = firstEdge;
btVector3 edges[3]; b3Vector3 edges[3];
int numEdges = 0; int numEdges = 0;
//compute face normals //compute face normals
@@ -70,10 +70,10 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
int src = edge->getSourceVertex(); int src = edge->getSourceVertex();
tmpFaces[i].m_indices.push_back(src); tmpFaces[i].m_indices.push_back(src);
int targ = edge->getTargetVertex(); int targ = edge->getTargetVertex();
btVector3 wa = convexUtil->vertices[src]; b3Vector3 wa = convexUtil->vertices[src];
btVector3 wb = convexUtil->vertices[targ]; b3Vector3 wb = convexUtil->vertices[targ];
btVector3 newEdge = wb-wa; b3Vector3 newEdge = wb-wa;
newEdge.normalize(); newEdge.normalize();
if (numEdges<2) if (numEdges<2)
edges[numEdges++] = newEdge; edges[numEdges++] = newEdge;
@@ -81,7 +81,7 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
edge = edge->getNextEdgeOfFace(); edge = edge->getNextEdgeOfFace();
} while (edge!=firstEdge); } while (edge!=firstEdge);
btScalar planeEq = 1e30f; b3Scalar planeEq = 1e30f;
if (numEdges==2) if (numEdges==2)
@@ -102,7 +102,7 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
for (int v=0;v<tmpFaces[i].m_indices.size();v++) for (int v=0;v<tmpFaces[i].m_indices.size();v++)
{ {
btScalar eq = m_vertices[tmpFaces[i].m_indices[v]].dot(faceNormals[i]); b3Scalar eq = m_vertices[tmpFaces[i].m_indices[v]].dot(faceNormals[i]);
if (planeEq>eq) if (planeEq>eq)
{ {
planeEq=eq; planeEq=eq;
@@ -113,26 +113,26 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
//merge coplanar faces and copy them to m_polyhedron //merge coplanar faces and copy them to m_polyhedron
btScalar faceWeldThreshold= 0.999f; b3Scalar faceWeldThreshold= 0.999f;
btAlignedObjectArray<int> todoFaces; b3AlignedObjectArray<int> todoFaces;
for (int i=0;i<tmpFaces.size();i++) for (int i=0;i<tmpFaces.size();i++)
todoFaces.push_back(i); todoFaces.push_back(i);
while (todoFaces.size()) while (todoFaces.size())
{ {
btAlignedObjectArray<int> coplanarFaceGroup; b3AlignedObjectArray<int> coplanarFaceGroup;
int refFace = todoFaces[todoFaces.size()-1]; int refFace = todoFaces[todoFaces.size()-1];
coplanarFaceGroup.push_back(refFace); coplanarFaceGroup.push_back(refFace);
btMyFace& faceA = tmpFaces[refFace]; btMyFace& faceA = tmpFaces[refFace];
todoFaces.pop_back(); todoFaces.pop_back();
btVector3 faceNormalA(faceA.m_plane[0],faceA.m_plane[1],faceA.m_plane[2]); b3Vector3 faceNormalA(faceA.m_plane[0],faceA.m_plane[1],faceA.m_plane[2]);
for (int j=todoFaces.size()-1;j>=0;j--) for (int j=todoFaces.size()-1;j>=0;j--)
{ {
int i = todoFaces[j]; int i = todoFaces[j];
btMyFace& faceB = tmpFaces[i]; btMyFace& faceB = tmpFaces[i];
btVector3 faceNormalB(faceB.m_plane[0],faceB.m_plane[1],faceB.m_plane[2]); b3Vector3 faceNormalB(faceB.m_plane[0],faceB.m_plane[1],faceB.m_plane[2]);
if (faceNormalA.dot(faceNormalB)>faceWeldThreshold) if (faceNormalA.dot(faceNormalB)>faceWeldThreshold)
{ {
coplanarFaceGroup.push_back(i); coplanarFaceGroup.push_back(i);
@@ -146,20 +146,20 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
{ {
//do the merge: use Graham Scan 2d convex hull //do the merge: use Graham Scan 2d convex hull
btAlignedObjectArray<GrahamVector3> orgpoints; b3AlignedObjectArray<GrahamVector3> orgpoints;
btVector3 averageFaceNormal(0,0,0); b3Vector3 averageFaceNormal(0,0,0);
for (int i=0;i<coplanarFaceGroup.size();i++) for (int i=0;i<coplanarFaceGroup.size();i++)
{ {
// m_polyhedron->m_faces.push_back(tmpFaces[coplanarFaceGroup[i]]); // m_polyhedron->m_faces.push_back(tmpFaces[coplanarFaceGroup[i]]);
btMyFace& face = tmpFaces[coplanarFaceGroup[i]]; btMyFace& face = tmpFaces[coplanarFaceGroup[i]];
btVector3 faceNormal(face.m_plane[0],face.m_plane[1],face.m_plane[2]); b3Vector3 faceNormal(face.m_plane[0],face.m_plane[1],face.m_plane[2]);
averageFaceNormal+=faceNormal; averageFaceNormal+=faceNormal;
for (int f=0;f<face.m_indices.size();f++) for (int f=0;f<face.m_indices.size();f++)
{ {
int orgIndex = face.m_indices[f]; int orgIndex = face.m_indices[f];
btVector3 pt = m_vertices[orgIndex]; b3Vector3 pt = m_vertices[orgIndex];
bool found = false; bool found = false;
@@ -183,7 +183,7 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
for (int i=0;i<4;i++) for (int i=0;i<4;i++)
combinedFace.m_plane[i] = tmpFaces[coplanarFaceGroup[0]].m_plane[i]; combinedFace.m_plane[i] = tmpFaces[coplanarFaceGroup[0]].m_plane[i];
btAlignedObjectArray<GrahamVector3> hull; b3AlignedObjectArray<GrahamVector3> hull;
averageFaceNormal.normalize(); averageFaceNormal.normalize();
GrahamScanConvexHull2D(orgpoints,hull,averageFaceNormal); GrahamScanConvexHull2D(orgpoints,hull,averageFaceNormal);
@@ -269,7 +269,7 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const btVector3* orgVertices,
inline bool IsAlmostZero(const btVector3& v) inline bool IsAlmostZero(const b3Vector3& v)
{ {
if(fabsf(v.getX())>1e-6 || fabsf(v.getY())>1e-6 || fabsf(v.getZ())>1e-6) return false; if(fabsf(v.getX())>1e-6 || fabsf(v.getY())>1e-6 || fabsf(v.getZ())>1e-6) return false;
return true; return true;
@@ -314,20 +314,20 @@ bool b3ConvexUtility::testContainment() const
{ {
for(int p=0;p<8;p++) for(int p=0;p<8;p++)
{ {
btVector3 LocalPt; b3Vector3 LocalPt;
if(p==0) LocalPt = m_localCenter + btVector3(m_extents[0], m_extents[1], m_extents[2]); if(p==0) LocalPt = m_localCenter + b3Vector3(m_extents[0], m_extents[1], m_extents[2]);
else if(p==1) LocalPt = m_localCenter + btVector3(m_extents[0], m_extents[1], -m_extents[2]); else if(p==1) LocalPt = m_localCenter + b3Vector3(m_extents[0], m_extents[1], -m_extents[2]);
else if(p==2) LocalPt = m_localCenter + btVector3(m_extents[0], -m_extents[1], m_extents[2]); else if(p==2) LocalPt = m_localCenter + b3Vector3(m_extents[0], -m_extents[1], m_extents[2]);
else if(p==3) LocalPt = m_localCenter + btVector3(m_extents[0], -m_extents[1], -m_extents[2]); else if(p==3) LocalPt = m_localCenter + b3Vector3(m_extents[0], -m_extents[1], -m_extents[2]);
else if(p==4) LocalPt = m_localCenter + btVector3(-m_extents[0], m_extents[1], m_extents[2]); else if(p==4) LocalPt = m_localCenter + b3Vector3(-m_extents[0], m_extents[1], m_extents[2]);
else if(p==5) LocalPt = m_localCenter + btVector3(-m_extents[0], m_extents[1], -m_extents[2]); else if(p==5) LocalPt = m_localCenter + b3Vector3(-m_extents[0], m_extents[1], -m_extents[2]);
else if(p==6) LocalPt = m_localCenter + btVector3(-m_extents[0], -m_extents[1], m_extents[2]); else if(p==6) LocalPt = m_localCenter + b3Vector3(-m_extents[0], -m_extents[1], m_extents[2]);
else if(p==7) LocalPt = m_localCenter + btVector3(-m_extents[0], -m_extents[1], -m_extents[2]); else if(p==7) LocalPt = m_localCenter + b3Vector3(-m_extents[0], -m_extents[1], -m_extents[2]);
for(int i=0;i<m_faces.size();i++) for(int i=0;i<m_faces.size();i++)
{ {
const btVector3 Normal(m_faces[i].m_plane[0], m_faces[i].m_plane[1], m_faces[i].m_plane[2]); const b3Vector3 Normal(m_faces[i].m_plane[0], m_faces[i].m_plane[1], m_faces[i].m_plane[2]);
const btScalar d = LocalPt.dot(Normal) + m_faces[i].m_plane[3]; const b3Scalar d = LocalPt.dot(Normal) + m_faces[i].m_plane[3];
if(d>0.0f) if(d>0.0f)
return false; return false;
} }
@@ -339,9 +339,9 @@ bool b3ConvexUtility::testContainment() const
void b3ConvexUtility::initialize() void b3ConvexUtility::initialize()
{ {
btHashMap<btInternalVertexPair,btInternalEdge> edges; b3HashMap<btInternalVertexPair,btInternalEdge> edges;
btScalar TotalArea = 0.0f; b3Scalar TotalArea = 0.0f;
m_localCenter.setValue(0, 0, 0); m_localCenter.setValue(0, 0, 0);
for(int i=0;i<m_faces.size();i++) for(int i=0;i<m_faces.size();i++)
@@ -353,11 +353,11 @@ void b3ConvexUtility::initialize()
int k = (j+1)%numVertices; int k = (j+1)%numVertices;
btInternalVertexPair vp(m_faces[i].m_indices[j],m_faces[i].m_indices[k]); btInternalVertexPair vp(m_faces[i].m_indices[j],m_faces[i].m_indices[k]);
btInternalEdge* edptr = edges.find(vp); btInternalEdge* edptr = edges.find(vp);
btVector3 edge = m_vertices[vp.m_v1]-m_vertices[vp.m_v0]; b3Vector3 edge = m_vertices[vp.m_v1]-m_vertices[vp.m_v0];
edge.normalize(); edge.normalize();
bool found = false; bool found = false;
btVector3 diff,diff2; b3Vector3 diff,diff2;
for (int p=0;p<m_uniqueEdges.size();p++) for (int p=0;p<m_uniqueEdges.size();p++)
{ {
@@ -421,14 +421,14 @@ void b3ConvexUtility::initialize()
int numVertices = m_faces[i].m_indices.size(); int numVertices = m_faces[i].m_indices.size();
int NbTris = numVertices-2; int NbTris = numVertices-2;
const btVector3& p0 = m_vertices[m_faces[i].m_indices[0]]; const b3Vector3& p0 = m_vertices[m_faces[i].m_indices[0]];
for(int j=1;j<=NbTris;j++) for(int j=1;j<=NbTris;j++)
{ {
int k = (j+1)%numVertices; int k = (j+1)%numVertices;
const btVector3& p1 = m_vertices[m_faces[i].m_indices[j]]; const b3Vector3& p1 = m_vertices[m_faces[i].m_indices[j]];
const btVector3& p2 = m_vertices[m_faces[i].m_indices[k]]; const b3Vector3& p2 = m_vertices[m_faces[i].m_indices[k]];
btScalar Area = ((p0 - p1).cross(p0 - p2)).length() * 0.5f; b3Scalar Area = ((p0 - p1).cross(p0 - p2)).length() * 0.5f;
btVector3 Center = (p0+p1+p2)/3.0f; b3Vector3 Center = (p0+p1+p2)/3.0f;
m_localCenter += Area * Center; m_localCenter += Area * Center;
TotalArea += Area; TotalArea += Area;
} }
@@ -444,22 +444,22 @@ void b3ConvexUtility::initialize()
m_radius = FLT_MAX; m_radius = FLT_MAX;
for(int i=0;i<m_faces.size();i++) for(int i=0;i<m_faces.size();i++)
{ {
const btVector3 Normal(m_faces[i].m_plane[0], m_faces[i].m_plane[1], m_faces[i].m_plane[2]); const b3Vector3 Normal(m_faces[i].m_plane[0], m_faces[i].m_plane[1], m_faces[i].m_plane[2]);
const btScalar dist = btFabs(m_localCenter.dot(Normal) + m_faces[i].m_plane[3]); const b3Scalar dist = btFabs(m_localCenter.dot(Normal) + m_faces[i].m_plane[3]);
if(dist<m_radius) if(dist<m_radius)
m_radius = dist; m_radius = dist;
} }
btScalar MinX = FLT_MAX; b3Scalar MinX = FLT_MAX;
btScalar MinY = FLT_MAX; b3Scalar MinY = FLT_MAX;
btScalar MinZ = FLT_MAX; b3Scalar MinZ = FLT_MAX;
btScalar MaxX = -FLT_MAX; b3Scalar MaxX = -FLT_MAX;
btScalar MaxY = -FLT_MAX; b3Scalar MaxY = -FLT_MAX;
btScalar MaxZ = -FLT_MAX; b3Scalar MaxZ = -FLT_MAX;
for(int i=0; i<m_vertices.size(); i++) for(int i=0; i<m_vertices.size(); i++)
{ {
const btVector3& pt = m_vertices[i]; const b3Vector3& pt = m_vertices[i];
if(pt.getX()<MinX) MinX = pt.getX(); if(pt.getX()<MinX) MinX = pt.getX();
if(pt.getX()>MaxX) MaxX = pt.getX(); if(pt.getX()>MaxX) MaxX = pt.getX();
if(pt.getY()<MinY) MinY = pt.getY(); if(pt.getY()<MinY) MinY = pt.getY();
@@ -472,10 +472,10 @@ void b3ConvexUtility::initialize()
// const btScalar r = m_radius / sqrtf(2.0f); // const b3Scalar r = m_radius / sqrtf(2.0f);
const btScalar r = m_radius / sqrtf(3.0f); const b3Scalar r = m_radius / sqrtf(3.0f);
const int LargestExtent = mE.maxAxis(); const int LargestExtent = mE.maxAxis();
const btScalar Step = (mE[LargestExtent]*0.5f - r)/1024.0f; const b3Scalar Step = (mE[LargestExtent]*0.5f - r)/1024.0f;
m_extents[0] = m_extents[1] = m_extents[2] = r; m_extents[0] = m_extents[1] = m_extents[2] = r;
m_extents[LargestExtent] = mE[LargestExtent]*0.5f; m_extents[LargestExtent] = mE[LargestExtent]*0.5f;
bool FoundBox = false; bool FoundBox = false;
@@ -496,14 +496,14 @@ void b3ConvexUtility::initialize()
else else
{ {
// Refine the box // Refine the box
const btScalar Step = (m_radius - r)/1024.0f; const b3Scalar Step = (m_radius - r)/1024.0f;
const int e0 = (1<<LargestExtent) & 3; const int e0 = (1<<LargestExtent) & 3;
const int e1 = (1<<e0) & 3; const int e1 = (1<<e0) & 3;
for(int j=0;j<1024;j++) for(int j=0;j<1024;j++)
{ {
const btScalar Saved0 = m_extents[e0]; const b3Scalar Saved0 = m_extents[e0];
const btScalar Saved1 = m_extents[e1]; const b3Scalar Saved1 = m_extents[e1];
m_extents[e0] += Step; m_extents[e0] += Step;
m_extents[e1] += Step; m_extents[e1] += Step;

View File

@@ -17,16 +17,16 @@ subject to the following restrictions:
#ifndef _BT_CONVEX_UTILITY_H #ifndef _BT_CONVEX_UTILITY_H
#define _BT_CONVEX_UTILITY_H #define _BT_CONVEX_UTILITY_H
#include "BulletCommon/btAlignedObjectArray.h" #include "BulletCommon/b3AlignedObjectArray.h"
#include "BulletCommon/btTransform.h" #include "BulletCommon/b3Transform.h"
#include "b3ConvexPolyhedronCL.h" #include "b3ConvexPolyhedronCL.h"
struct btMyFace struct btMyFace
{ {
btAlignedObjectArray<int> m_indices; b3AlignedObjectArray<int> m_indices;
btScalar m_plane[4]; b3Scalar m_plane[4];
}; };
ATTRIBUTE_ALIGNED16(class) b3ConvexUtility ATTRIBUTE_ALIGNED16(class) b3ConvexUtility
@@ -34,15 +34,15 @@ ATTRIBUTE_ALIGNED16(class) b3ConvexUtility
public: public:
BT_DECLARE_ALIGNED_ALLOCATOR(); BT_DECLARE_ALIGNED_ALLOCATOR();
btVector3 m_localCenter; b3Vector3 m_localCenter;
btVector3 m_extents; b3Vector3 m_extents;
btVector3 mC; b3Vector3 mC;
btVector3 mE; b3Vector3 mE;
btScalar m_radius; b3Scalar m_radius;
btAlignedObjectArray<btVector3> m_vertices; b3AlignedObjectArray<b3Vector3> m_vertices;
btAlignedObjectArray<btMyFace> m_faces; b3AlignedObjectArray<btMyFace> m_faces;
btAlignedObjectArray<btVector3> m_uniqueEdges; b3AlignedObjectArray<b3Vector3> m_uniqueEdges;
b3ConvexUtility() b3ConvexUtility()
@@ -50,7 +50,7 @@ ATTRIBUTE_ALIGNED16(class) b3ConvexUtility
} }
virtual ~b3ConvexUtility(); virtual ~b3ConvexUtility();
bool initializePolyhedralFeatures(const btVector3* orgVertices, int numVertices, bool mergeCoplanarTriangles=true); bool initializePolyhedralFeatures(const b3Vector3* orgVertices, int numVertices, bool mergeCoplanarTriangles=true);
void initialize(); void initialize();
bool testContainment() const; bool testContainment() const;

View File

@@ -17,7 +17,6 @@ subject to the following restrictions:
#include "b3OptimizedBvh.h" #include "b3OptimizedBvh.h"
#include "b3StridingMeshInterface.h" #include "b3StridingMeshInterface.h"
#include "BulletGeometry/btAabbUtil2.h" #include "BulletGeometry/btAabbUtil2.h"
#include "BulletCommon/btIDebugDraw.h"
b3OptimizedBvh::b3OptimizedBvh() b3OptimizedBvh::b3OptimizedBvh()
@@ -29,7 +28,7 @@ b3OptimizedBvh::~b3OptimizedBvh()
} }
void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantizedAabbCompression, const btVector3& bvhAabbMin, const btVector3& bvhAabbMax) void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantizedAabbCompression, const b3Vector3& bvhAabbMin, const b3Vector3& bvhAabbMax)
{ {
m_useQuantization = useQuantizedAabbCompression; m_useQuantization = useQuantizedAabbCompression;
@@ -52,12 +51,12 @@ void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantized
{ {
} }
virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex) virtual void internalProcessTriangleIndex(b3Vector3* triangle,int partId,int triangleIndex)
{ {
btOptimizedBvhNode node; btOptimizedBvhNode node;
btVector3 aabbMin,aabbMax; b3Vector3 aabbMin,aabbMax;
aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); aabbMin.setValue(b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT));
aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); aabbMax.setValue(b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT));
aabbMin.setMin(triangle[0]); aabbMin.setMin(triangle[0]);
aabbMax.setMax(triangle[0]); aabbMax.setMax(triangle[0]);
aabbMin.setMin(triangle[1]); aabbMin.setMin(triangle[1]);
@@ -94,7 +93,7 @@ void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantized
{ {
} }
virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex) virtual void internalProcessTriangleIndex(b3Vector3* triangle,int partId,int triangleIndex)
{ {
// The partId and triangle index must fit in the same (positive) integer // The partId and triangle index must fit in the same (positive) integer
btAssert(partId < (1<<MAX_NUM_PARTS_IN_BITS)); btAssert(partId < (1<<MAX_NUM_PARTS_IN_BITS));
@@ -103,9 +102,9 @@ void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantized
btAssert(triangleIndex>=0); btAssert(triangleIndex>=0);
btQuantizedBvhNode node; btQuantizedBvhNode node;
btVector3 aabbMin,aabbMax; b3Vector3 aabbMin,aabbMax;
aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); aabbMin.setValue(b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT));
aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); aabbMax.setValue(b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT));
aabbMin.setMin(triangle[0]); aabbMin.setMin(triangle[0]);
aabbMax.setMax(triangle[0]); aabbMax.setMax(triangle[0]);
aabbMin.setMin(triangle[1]); aabbMin.setMin(triangle[1]);
@@ -114,8 +113,8 @@ void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantized
aabbMax.setMax(triangle[2]); aabbMax.setMax(triangle[2]);
//PCK: add these checks for zero dimensions of aabb //PCK: add these checks for zero dimensions of aabb
const btScalar MIN_AABB_DIMENSION = btScalar(0.002); const b3Scalar MIN_AABB_DIMENSION = b3Scalar(0.002);
const btScalar MIN_AABB_HALF_DIMENSION = btScalar(0.001); const b3Scalar MIN_AABB_HALF_DIMENSION = b3Scalar(0.001);
if (aabbMax.getX() - aabbMin.getX() < MIN_AABB_DIMENSION) if (aabbMax.getX() - aabbMin.getX() < MIN_AABB_DIMENSION)
{ {
aabbMax.setX(aabbMax.getX() + MIN_AABB_HALF_DIMENSION); aabbMax.setX(aabbMax.getX() + MIN_AABB_HALF_DIMENSION);
@@ -168,8 +167,8 @@ void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantized
{ {
NodeTriangleCallback callback(m_leafNodes); NodeTriangleCallback callback(m_leafNodes);
btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); b3Vector3 aabbMin(b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT));
btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); b3Vector3 aabbMax(b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT));
triangles->InternalProcessAllTriangles(&callback,aabbMin,aabbMax); triangles->InternalProcessAllTriangles(&callback,aabbMin,aabbMax);
@@ -203,7 +202,7 @@ void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantized
void b3OptimizedBvh::refit(b3StridingMeshInterface* meshInterface,const btVector3& aabbMin,const btVector3& aabbMax) void b3OptimizedBvh::refit(b3StridingMeshInterface* meshInterface,const b3Vector3& aabbMin,const b3Vector3& aabbMax)
{ {
if (m_useQuantization) if (m_useQuantization)
{ {
@@ -230,7 +229,7 @@ void b3OptimizedBvh::refit(b3StridingMeshInterface* meshInterface,const btVector
void b3OptimizedBvh::refitPartial(b3StridingMeshInterface* meshInterface,const btVector3& aabbMin,const btVector3& aabbMax) void b3OptimizedBvh::refitPartial(b3StridingMeshInterface* meshInterface,const b3Vector3& aabbMin,const b3Vector3& aabbMax)
{ {
//incrementally initialize quantization values //incrementally initialize quantization values
btAssert(m_useQuantization); btAssert(m_useQuantization);
@@ -287,9 +286,9 @@ void b3OptimizedBvh::updateBvhNodes(b3StridingMeshInterface* meshInterface,int f
int numfaces = 0; int numfaces = 0;
PHY_ScalarType indicestype = PHY_INTEGER; PHY_ScalarType indicestype = PHY_INTEGER;
btVector3 triangleVerts[3]; b3Vector3 triangleVerts[3];
btVector3 aabbMin,aabbMax; b3Vector3 aabbMin,aabbMax;
const btVector3& meshScaling = meshInterface->getScaling(); const b3Vector3& meshScaling = meshInterface->getScaling();
int i; int i;
for (i=endNode-1;i>=firstNode;i--) for (i=endNode-1;i>=firstNode;i--)
@@ -323,7 +322,7 @@ void b3OptimizedBvh::updateBvhNodes(b3StridingMeshInterface* meshInterface,int f
if (type == PHY_FLOAT) if (type == PHY_FLOAT)
{ {
float* graphicsbase = (float*)(vertexbase+graphicsindex*stride); float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
triangleVerts[j] = btVector3( triangleVerts[j] = b3Vector3(
graphicsbase[0]*meshScaling.getX(), graphicsbase[0]*meshScaling.getX(),
graphicsbase[1]*meshScaling.getY(), graphicsbase[1]*meshScaling.getY(),
graphicsbase[2]*meshScaling.getZ()); graphicsbase[2]*meshScaling.getZ());
@@ -331,14 +330,14 @@ void b3OptimizedBvh::updateBvhNodes(b3StridingMeshInterface* meshInterface,int f
else else
{ {
double* graphicsbase = (double*)(vertexbase+graphicsindex*stride); double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
triangleVerts[j] = btVector3( btScalar(graphicsbase[0]*meshScaling.getX()), btScalar(graphicsbase[1]*meshScaling.getY()), btScalar(graphicsbase[2]*meshScaling.getZ())); triangleVerts[j] = b3Vector3( b3Scalar(graphicsbase[0]*meshScaling.getX()), b3Scalar(graphicsbase[1]*meshScaling.getY()), b3Scalar(graphicsbase[2]*meshScaling.getZ()));
} }
} }
aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); aabbMin.setValue(b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT));
aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); aabbMax.setValue(b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT));
aabbMin.setMin(triangleVerts[0]); aabbMin.setMin(triangleVerts[0]);
aabbMax.setMax(triangleVerts[0]); aabbMax.setMax(triangleVerts[0]);
aabbMin.setMin(triangleVerts[1]); aabbMin.setMin(triangleVerts[1]);

View File

@@ -38,11 +38,11 @@ public:
virtual ~b3OptimizedBvh(); virtual ~b3OptimizedBvh();
void build(b3StridingMeshInterface* triangles,bool useQuantizedAabbCompression, const btVector3& bvhAabbMin, const btVector3& bvhAabbMax); void build(b3StridingMeshInterface* triangles,bool useQuantizedAabbCompression, const b3Vector3& bvhAabbMin, const b3Vector3& bvhAabbMax);
void refit(b3StridingMeshInterface* triangles,const btVector3& aabbMin,const btVector3& aabbMax); void refit(b3StridingMeshInterface* triangles,const b3Vector3& aabbMin,const b3Vector3& aabbMax);
void refitPartial(b3StridingMeshInterface* triangles,const btVector3& aabbMin, const btVector3& aabbMax); void refitPartial(b3StridingMeshInterface* triangles,const b3Vector3& aabbMin, const b3Vector3& aabbMax);
void updateBvhNodes(b3StridingMeshInterface* meshInterface,int firstNode,int endNode,int index); void updateBvhNodes(b3StridingMeshInterface* meshInterface,int firstNode,int endNode,int index);

View File

@@ -16,7 +16,6 @@ subject to the following restrictions:
#include "b3QuantizedBvh.h" #include "b3QuantizedBvh.h"
#include "BulletGeometry/btAabbUtil2.h" #include "BulletGeometry/btAabbUtil2.h"
#include "BulletCommon/btIDebugDraw.h"
#define RAYAABB2 #define RAYAABB2
@@ -77,25 +76,25 @@ void b3QuantizedBvh::buildInternal()
///just for debugging, to visualize the individual patches/subtrees ///just for debugging, to visualize the individual patches/subtrees
#ifdef DEBUG_PATCH_COLORS #ifdef DEBUG_PATCH_COLORS
btVector3 color[4]= b3Vector3 color[4]=
{ {
btVector3(1,0,0), b3Vector3(1,0,0),
btVector3(0,1,0), b3Vector3(0,1,0),
btVector3(0,0,1), b3Vector3(0,0,1),
btVector3(0,1,1) b3Vector3(0,1,1)
}; };
#endif //DEBUG_PATCH_COLORS #endif //DEBUG_PATCH_COLORS
void b3QuantizedBvh::setQuantizationValues(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,btScalar quantizationMargin) void b3QuantizedBvh::setQuantizationValues(const b3Vector3& bvhAabbMin,const b3Vector3& bvhAabbMax,b3Scalar quantizationMargin)
{ {
//enlarge the AABB to avoid division by zero when initializing the quantization values //enlarge the AABB to avoid division by zero when initializing the quantization values
btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin); b3Vector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin);
m_bvhAabbMin = bvhAabbMin - clampValue; m_bvhAabbMin = bvhAabbMin - clampValue;
m_bvhAabbMax = bvhAabbMax + clampValue; m_bvhAabbMax = bvhAabbMax + clampValue;
btVector3 aabbSize = m_bvhAabbMax - m_bvhAabbMin; b3Vector3 aabbSize = m_bvhAabbMax - m_bvhAabbMin;
m_bvhQuantization = btVector3(btScalar(65533.0),btScalar(65533.0),btScalar(65533.0)) / aabbSize; m_bvhQuantization = b3Vector3(b3Scalar(65533.0),b3Scalar(65533.0),b3Scalar(65533.0)) / aabbSize;
m_useQuantization = true; m_useQuantization = true;
} }
@@ -147,8 +146,8 @@ void b3QuantizedBvh::buildTree (int startIndex,int endIndex)
//set the min aabb to 'inf' or a max value, and set the max aabb to a -inf/minimum value. //set the min aabb to 'inf' or a max value, and set the max aabb to a -inf/minimum value.
//the aabb will be expanded during buildTree/mergeInternalNodeAabb with actual node values //the aabb will be expanded during buildTree/mergeInternalNodeAabb with actual node values
setInternalNodeAabbMin(m_curNodeIndex,m_bvhAabbMax);//can't use btVector3(SIMD_INFINITY,SIMD_INFINITY,SIMD_INFINITY)) because of quantization setInternalNodeAabbMin(m_curNodeIndex,m_bvhAabbMax);//can't use b3Vector3(SIMD_INFINITY,SIMD_INFINITY,SIMD_INFINITY)) because of quantization
setInternalNodeAabbMax(m_curNodeIndex,m_bvhAabbMin);//can't use btVector3(-SIMD_INFINITY,-SIMD_INFINITY,-SIMD_INFINITY)) because of quantization setInternalNodeAabbMax(m_curNodeIndex,m_bvhAabbMin);//can't use b3Vector3(-SIMD_INFINITY,-SIMD_INFINITY,-SIMD_INFINITY)) because of quantization
for (i=startIndex;i<endIndex;i++) for (i=startIndex;i<endIndex;i++)
@@ -232,22 +231,22 @@ int b3QuantizedBvh::sortAndCalcSplittingIndex(int startIndex,int endIndex,int sp
int i; int i;
int splitIndex =startIndex; int splitIndex =startIndex;
int numIndices = endIndex - startIndex; int numIndices = endIndex - startIndex;
btScalar splitValue; b3Scalar splitValue;
btVector3 means(btScalar(0.),btScalar(0.),btScalar(0.)); b3Vector3 means(b3Scalar(0.),b3Scalar(0.),b3Scalar(0.));
for (i=startIndex;i<endIndex;i++) for (i=startIndex;i<endIndex;i++)
{ {
btVector3 center = btScalar(0.5)*(getAabbMax(i)+getAabbMin(i)); b3Vector3 center = b3Scalar(0.5)*(getAabbMax(i)+getAabbMin(i));
means+=center; means+=center;
} }
means *= (btScalar(1.)/(btScalar)numIndices); means *= (b3Scalar(1.)/(b3Scalar)numIndices);
splitValue = means[splitAxis]; splitValue = means[splitAxis];
//sort leafNodes so all values larger then splitValue comes first, and smaller values start from 'splitIndex'. //sort leafNodes so all values larger then splitValue comes first, and smaller values start from 'splitIndex'.
for (i=startIndex;i<endIndex;i++) for (i=startIndex;i<endIndex;i++)
{ {
btVector3 center = btScalar(0.5)*(getAabbMax(i)+getAabbMin(i)); b3Vector3 center = b3Scalar(0.5)*(getAabbMax(i)+getAabbMin(i));
if (center[splitAxis] > splitValue) if (center[splitAxis] > splitValue)
{ {
//swap //swap
@@ -285,32 +284,32 @@ int b3QuantizedBvh::calcSplittingAxis(int startIndex,int endIndex)
{ {
int i; int i;
btVector3 means(btScalar(0.),btScalar(0.),btScalar(0.)); b3Vector3 means(b3Scalar(0.),b3Scalar(0.),b3Scalar(0.));
btVector3 variance(btScalar(0.),btScalar(0.),btScalar(0.)); b3Vector3 variance(b3Scalar(0.),b3Scalar(0.),b3Scalar(0.));
int numIndices = endIndex-startIndex; int numIndices = endIndex-startIndex;
for (i=startIndex;i<endIndex;i++) for (i=startIndex;i<endIndex;i++)
{ {
btVector3 center = btScalar(0.5)*(getAabbMax(i)+getAabbMin(i)); b3Vector3 center = b3Scalar(0.5)*(getAabbMax(i)+getAabbMin(i));
means+=center; means+=center;
} }
means *= (btScalar(1.)/(btScalar)numIndices); means *= (b3Scalar(1.)/(b3Scalar)numIndices);
for (i=startIndex;i<endIndex;i++) for (i=startIndex;i<endIndex;i++)
{ {
btVector3 center = btScalar(0.5)*(getAabbMax(i)+getAabbMin(i)); b3Vector3 center = b3Scalar(0.5)*(getAabbMax(i)+getAabbMin(i));
btVector3 diff2 = center-means; b3Vector3 diff2 = center-means;
diff2 = diff2 * diff2; diff2 = diff2 * diff2;
variance += diff2; variance += diff2;
} }
variance *= (btScalar(1.)/ ((btScalar)numIndices-1) ); variance *= (b3Scalar(1.)/ ((b3Scalar)numIndices-1) );
return variance.maxAxis(); return variance.maxAxis();
} }
void b3QuantizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const void b3QuantizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallback,const b3Vector3& aabbMin,const b3Vector3& aabbMax) const
{ {
//either choose recursive traversal (walkTree) or stackless (walkStacklessTree) //either choose recursive traversal (walkTree) or stackless (walkStacklessTree)
@@ -350,7 +349,7 @@ void b3QuantizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallb
int maxIterations = 0; int maxIterations = 0;
void b3QuantizedBvh::walkStacklessTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const void b3QuantizedBvh::walkStacklessTree(btNodeOverlapCallback* nodeCallback,const b3Vector3& aabbMin,const b3Vector3& aabbMax) const
{ {
btAssert(!m_useQuantization); btAssert(!m_useQuantization);
@@ -395,7 +394,7 @@ void b3QuantizedBvh::walkStacklessTree(btNodeOverlapCallback* nodeCallback,const
/* /*
///this was the original recursive traversal, before we optimized towards stackless traversal ///this was the original recursive traversal, before we optimized towards stackless traversal
void b3QuantizedBvh::walkTree(btOptimizedBvhNode* rootNode,btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const void b3QuantizedBvh::walkTree(btOptimizedBvhNode* rootNode,btNodeOverlapCallback* nodeCallback,const b3Vector3& aabbMin,const b3Vector3& aabbMax) const
{ {
bool isLeafNode, aabbOverlap = TestAabbAgainstAabb2(aabbMin,aabbMax,rootNode->m_aabbMin,rootNode->m_aabbMax); bool isLeafNode, aabbOverlap = TestAabbAgainstAabb2(aabbMin,aabbMax,rootNode->m_aabbMin,rootNode->m_aabbMax);
if (aabbOverlap) if (aabbOverlap)
@@ -446,7 +445,7 @@ void b3QuantizedBvh::walkRecursiveQuantizedTreeAgainstQueryAabb(const btQuantize
void b3QuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const void b3QuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget, const b3Vector3& aabbMin, const b3Vector3& aabbMax, int startNodeIndex,int endNodeIndex) const
{ {
btAssert(!m_useQuantization); btAssert(!m_useQuantization);
@@ -457,11 +456,11 @@ void b3QuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCall
//PCK: unsigned instead of bool //PCK: unsigned instead of bool
unsigned aabbOverlap=0; unsigned aabbOverlap=0;
unsigned rayBoxOverlap=0; unsigned rayBoxOverlap=0;
btScalar lambda_max = 1.0; b3Scalar lambda_max = 1.0;
/* Quick pruning by quantized box */ /* Quick pruning by quantized box */
btVector3 rayAabbMin = raySource; b3Vector3 rayAabbMin = raySource;
btVector3 rayAabbMax = raySource; b3Vector3 rayAabbMax = raySource;
rayAabbMin.setMin(rayTarget); rayAabbMin.setMin(rayTarget);
rayAabbMax.setMax(rayTarget); rayAabbMax.setMax(rayTarget);
@@ -470,22 +469,22 @@ void b3QuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCall
rayAabbMax += aabbMax; rayAabbMax += aabbMax;
#ifdef RAYAABB2 #ifdef RAYAABB2
btVector3 rayDir = (rayTarget-raySource); b3Vector3 rayDir = (rayTarget-raySource);
rayDir.normalize (); rayDir.normalize ();
lambda_max = rayDir.dot(rayTarget-raySource); lambda_max = rayDir.dot(rayTarget-raySource);
///what about division by zero? --> just set rayDirection[i] to 1.0 ///what about division by zero? --> just set rayDirection[i] to 1.0
btVector3 rayDirectionInverse; b3Vector3 rayDirectionInverse;
rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0]; rayDirectionInverse[0] = rayDir[0] == b3Scalar(0.0) ? b3Scalar(BT_LARGE_FLOAT) : b3Scalar(1.0) / rayDir[0];
rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1]; rayDirectionInverse[1] = rayDir[1] == b3Scalar(0.0) ? b3Scalar(BT_LARGE_FLOAT) : b3Scalar(1.0) / rayDir[1];
rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2]; rayDirectionInverse[2] = rayDir[2] == b3Scalar(0.0) ? b3Scalar(BT_LARGE_FLOAT) : b3Scalar(1.0) / rayDir[2];
unsigned int sign[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0}; unsigned int sign[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0};
#endif #endif
btVector3 bounds[2]; b3Vector3 bounds[2];
while (curIndex < m_curNodeIndex) while (curIndex < m_curNodeIndex)
{ {
btScalar param = 1.0; b3Scalar param = 1.0;
//catch bugs in tree data //catch bugs in tree data
btAssert (walkIterations < m_curNodeIndex); btAssert (walkIterations < m_curNodeIndex);
@@ -507,7 +506,7 @@ void b3QuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCall
rayBoxOverlap = aabbOverlap ? btRayAabb2 (raySource, rayDirectionInverse, sign, bounds, param, 0.0f, lambda_max) : false; rayBoxOverlap = aabbOverlap ? btRayAabb2 (raySource, rayDirectionInverse, sign, bounds, param, 0.0f, lambda_max) : false;
#else #else
btVector3 normal; b3Vector3 normal;
rayBoxOverlap = btRayAabb(raySource, rayTarget,bounds[0],bounds[1],param, normal); rayBoxOverlap = btRayAabb(raySource, rayTarget,bounds[0],bounds[1],param, normal);
#endif #endif
@@ -538,7 +537,7 @@ void b3QuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCall
void b3QuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const void b3QuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget, const b3Vector3& aabbMin, const b3Vector3& aabbMax, int startNodeIndex,int endNodeIndex) const
{ {
btAssert(m_useQuantization); btAssert(m_useQuantization);
@@ -555,22 +554,22 @@ void b3QuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*
unsigned boxBoxOverlap = 0; unsigned boxBoxOverlap = 0;
unsigned rayBoxOverlap = 0; unsigned rayBoxOverlap = 0;
btScalar lambda_max = 1.0; b3Scalar lambda_max = 1.0;
#ifdef RAYAABB2 #ifdef RAYAABB2
btVector3 rayDirection = (rayTarget-raySource); b3Vector3 rayDirection = (rayTarget-raySource);
rayDirection.normalize (); rayDirection.normalize ();
lambda_max = rayDirection.dot(rayTarget-raySource); lambda_max = rayDirection.dot(rayTarget-raySource);
///what about division by zero? --> just set rayDirection[i] to 1.0 ///what about division by zero? --> just set rayDirection[i] to 1.0
rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[0]; rayDirection[0] = rayDirection[0] == b3Scalar(0.0) ? b3Scalar(BT_LARGE_FLOAT) : b3Scalar(1.0) / rayDirection[0];
rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[1]; rayDirection[1] = rayDirection[1] == b3Scalar(0.0) ? b3Scalar(BT_LARGE_FLOAT) : b3Scalar(1.0) / rayDirection[1];
rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[2]; rayDirection[2] = rayDirection[2] == b3Scalar(0.0) ? b3Scalar(BT_LARGE_FLOAT) : b3Scalar(1.0) / rayDirection[2];
unsigned int sign[3] = { rayDirection[0] < 0.0, rayDirection[1] < 0.0, rayDirection[2] < 0.0}; unsigned int sign[3] = { rayDirection[0] < 0.0, rayDirection[1] < 0.0, rayDirection[2] < 0.0};
#endif #endif
/* Quick pruning by quantized box */ /* Quick pruning by quantized box */
btVector3 rayAabbMin = raySource; b3Vector3 rayAabbMin = raySource;
btVector3 rayAabbMax = raySource; b3Vector3 rayAabbMax = raySource;
rayAabbMin.setMin(rayTarget); rayAabbMin.setMin(rayTarget);
rayAabbMax.setMax(rayTarget); rayAabbMax.setMax(rayTarget);
@@ -594,10 +593,10 @@ void b3QuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*
extern btIDebugDraw* debugDrawerPtr; extern btIDebugDraw* debugDrawerPtr;
if (curIndex==drawPatch) if (curIndex==drawPatch)
{ {
btVector3 aabbMin,aabbMax; b3Vector3 aabbMin,aabbMax;
aabbMin = unQuantize(rootNode->m_quantizedAabbMin); aabbMin = unQuantize(rootNode->m_quantizedAabbMin);
aabbMax = unQuantize(rootNode->m_quantizedAabbMax); aabbMax = unQuantize(rootNode->m_quantizedAabbMax);
btVector3 color(1,0,0); b3Vector3 color(1,0,0);
debugDrawerPtr->drawAabb(aabbMin,aabbMax,color); debugDrawerPtr->drawAabb(aabbMin,aabbMax,color);
} }
#endif//VISUALLY_ANALYZE_BVH #endif//VISUALLY_ANALYZE_BVH
@@ -608,19 +607,19 @@ void b3QuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*
walkIterations++; walkIterations++;
//PCK: unsigned instead of bool //PCK: unsigned instead of bool
// only interested if this is closer than any previous hit // only interested if this is closer than any previous hit
btScalar param = 1.0; b3Scalar param = 1.0;
rayBoxOverlap = 0; rayBoxOverlap = 0;
boxBoxOverlap = testQuantizedAabbAgainstQuantizedAabb(quantizedQueryAabbMin,quantizedQueryAabbMax,rootNode->m_quantizedAabbMin,rootNode->m_quantizedAabbMax); boxBoxOverlap = testQuantizedAabbAgainstQuantizedAabb(quantizedQueryAabbMin,quantizedQueryAabbMax,rootNode->m_quantizedAabbMin,rootNode->m_quantizedAabbMax);
isLeafNode = rootNode->isLeafNode(); isLeafNode = rootNode->isLeafNode();
if (boxBoxOverlap) if (boxBoxOverlap)
{ {
btVector3 bounds[2]; b3Vector3 bounds[2];
bounds[0] = unQuantize(rootNode->m_quantizedAabbMin); bounds[0] = unQuantize(rootNode->m_quantizedAabbMin);
bounds[1] = unQuantize(rootNode->m_quantizedAabbMax); bounds[1] = unQuantize(rootNode->m_quantizedAabbMax);
/* Add box cast extents */ /* Add box cast extents */
bounds[0] -= aabbMax; bounds[0] -= aabbMax;
bounds[1] -= aabbMin; bounds[1] -= aabbMin;
btVector3 normal; b3Vector3 normal;
#if 0 #if 0
bool ra2 = btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0, lambda_max); bool ra2 = btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0, lambda_max);
bool ra = btRayAabb (raySource, rayTarget, bounds[0], bounds[1], param, normal); bool ra = btRayAabb (raySource, rayTarget, bounds[0], bounds[1], param, normal);
@@ -691,10 +690,10 @@ void b3QuantizedBvh::walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallb
extern btIDebugDraw* debugDrawerPtr; extern btIDebugDraw* debugDrawerPtr;
if (curIndex==drawPatch) if (curIndex==drawPatch)
{ {
btVector3 aabbMin,aabbMax; b3Vector3 aabbMin,aabbMax;
aabbMin = unQuantize(rootNode->m_quantizedAabbMin); aabbMin = unQuantize(rootNode->m_quantizedAabbMin);
aabbMax = unQuantize(rootNode->m_quantizedAabbMax); aabbMax = unQuantize(rootNode->m_quantizedAabbMax);
btVector3 color(1,0,0); b3Vector3 color(1,0,0);
debugDrawerPtr->drawAabb(aabbMin,aabbMax,color); debugDrawerPtr->drawAabb(aabbMin,aabbMax,color);
} }
#endif//VISUALLY_ANALYZE_BVH #endif//VISUALLY_ANALYZE_BVH
@@ -753,13 +752,13 @@ void b3QuantizedBvh::walkStacklessQuantizedTreeCacheFriendly(btNodeOverlapCallba
} }
void b3QuantizedBvh::reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget) const void b3QuantizedBvh::reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget) const
{ {
reportBoxCastOverlappingNodex(nodeCallback,raySource,rayTarget,btVector3(0,0,0),btVector3(0,0,0)); reportBoxCastOverlappingNodex(nodeCallback,raySource,rayTarget,b3Vector3(0,0,0),b3Vector3(0,0,0));
} }
void b3QuantizedBvh::reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin,const btVector3& aabbMax) const void b3QuantizedBvh::reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget, const b3Vector3& aabbMin,const b3Vector3& aabbMax) const
{ {
//always use stackless //always use stackless
@@ -774,8 +773,8 @@ void b3QuantizedBvh::reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCa
/* /*
{ {
//recursive traversal //recursive traversal
btVector3 qaabbMin = raySource; b3Vector3 qaabbMin = raySource;
btVector3 qaabbMax = raySource; b3Vector3 qaabbMax = raySource;
qaabbMin.setMin(rayTarget); qaabbMin.setMin(rayTarget);
qaabbMax.setMax(rayTarget); qaabbMax.setMax(rayTarget);
qaabbMin += aabbMin; qaabbMin += aabbMin;
@@ -1134,7 +1133,7 @@ b3QuantizedBvh *b3QuantizedBvh::deSerializeInPlace(void *i_alignedDataBuffer, un
return bvh; return bvh;
} }
// Constructor that prevents btVector3's default constructor from being called // Constructor that prevents b3Vector3's default constructor from being called
b3QuantizedBvh::b3QuantizedBvh(b3QuantizedBvh &self, bool /* ownsMemory */) : b3QuantizedBvh::b3QuantizedBvh(b3QuantizedBvh &self, bool /* ownsMemory */) :
m_bvhAabbMin(self.m_bvhAabbMin), m_bvhAabbMin(self.m_bvhAabbMin),
m_bvhAabbMax(self.m_bvhAabbMax), m_bvhAabbMax(self.m_bvhAabbMax),

View File

@@ -28,8 +28,8 @@ class btSerializer;
#include <stdlib.h> #include <stdlib.h>
#endif //DEBUG_CHECK_DEQUANTIZATION #endif //DEBUG_CHECK_DEQUANTIZATION
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
#include "BulletCommon/btAlignedAllocator.h" #include "BulletCommon/b3AlignedAllocator.h"
#ifdef BT_USE_DOUBLE_PRECISION #ifdef BT_USE_DOUBLE_PRECISION
#define btQuantizedBvhData btQuantizedBvhDoubleData #define btQuantizedBvhData btQuantizedBvhDoubleData
@@ -99,8 +99,8 @@ ATTRIBUTE_ALIGNED16 (struct) btOptimizedBvhNode
BT_DECLARE_ALIGNED_ALLOCATOR(); BT_DECLARE_ALIGNED_ALLOCATOR();
//32 bytes //32 bytes
btVector3 m_aabbMinOrg; b3Vector3 m_aabbMinOrg;
btVector3 m_aabbMaxOrg; b3Vector3 m_aabbMaxOrg;
//4 //4
int m_escapeIndex; int m_escapeIndex;
@@ -157,15 +157,15 @@ public:
virtual void processNode(int subPart, int triangleIndex) = 0; virtual void processNode(int subPart, int triangleIndex) = 0;
}; };
#include "BulletCommon/btAlignedAllocator.h" #include "BulletCommon/b3AlignedAllocator.h"
#include "BulletCommon/btAlignedObjectArray.h" #include "BulletCommon/b3AlignedObjectArray.h"
///for code readability: ///for code readability:
typedef btAlignedObjectArray<btOptimizedBvhNode> NodeArray; typedef b3AlignedObjectArray<btOptimizedBvhNode> NodeArray;
typedef btAlignedObjectArray<btQuantizedBvhNode> QuantizedNodeArray; typedef b3AlignedObjectArray<btQuantizedBvhNode> QuantizedNodeArray;
typedef btAlignedObjectArray<btBvhSubtreeInfo> BvhSubtreeInfoArray; typedef b3AlignedObjectArray<btBvhSubtreeInfo> BvhSubtreeInfoArray;
///The b3QuantizedBvh class stores an AABB tree that can be quickly traversed on CPU and Cell SPU. ///The b3QuantizedBvh class stores an AABB tree that can be quickly traversed on CPU and Cell SPU.
@@ -184,9 +184,9 @@ public:
btVector3 m_bvhAabbMin; b3Vector3 m_bvhAabbMin;
btVector3 m_bvhAabbMax; b3Vector3 m_bvhAabbMax;
btVector3 m_bvhQuantization; b3Vector3 m_bvhQuantization;
protected: protected:
int m_bulletVersion; //for serialization versioning. It could also be used to detect endianess. int m_bulletVersion; //for serialization versioning. It could also be used to detect endianess.
@@ -205,7 +205,7 @@ protected:
btTraversalMode m_traversalMode; btTraversalMode m_traversalMode;
BvhSubtreeInfoArray m_SubtreeHeaders; BvhSubtreeInfoArray m_SubtreeHeaders;
//This is only used for serialization so we don't have to add serialization directly to btAlignedObjectArray //This is only used for serialization so we don't have to add serialization directly to b3AlignedObjectArray
mutable int m_subtreeHeaderCount; mutable int m_subtreeHeaderCount;
@@ -214,7 +214,7 @@ protected:
///two versions, one for quantized and normal nodes. This allows code-reuse while maintaining readability (no template/macro!) ///two versions, one for quantized and normal nodes. This allows code-reuse while maintaining readability (no template/macro!)
///this might be refactored into a virtual, it is usually not calculated at run-time ///this might be refactored into a virtual, it is usually not calculated at run-time
void setInternalNodeAabbMin(int nodeIndex, const btVector3& aabbMin) void setInternalNodeAabbMin(int nodeIndex, const b3Vector3& aabbMin)
{ {
if (m_useQuantization) if (m_useQuantization)
{ {
@@ -225,7 +225,7 @@ protected:
} }
} }
void setInternalNodeAabbMax(int nodeIndex,const btVector3& aabbMax) void setInternalNodeAabbMax(int nodeIndex,const b3Vector3& aabbMax)
{ {
if (m_useQuantization) if (m_useQuantization)
{ {
@@ -236,7 +236,7 @@ protected:
} }
} }
btVector3 getAabbMin(int nodeIndex) const b3Vector3 getAabbMin(int nodeIndex) const
{ {
if (m_useQuantization) if (m_useQuantization)
{ {
@@ -246,7 +246,7 @@ protected:
return m_leafNodes[nodeIndex].m_aabbMinOrg; return m_leafNodes[nodeIndex].m_aabbMinOrg;
} }
btVector3 getAabbMax(int nodeIndex) const b3Vector3 getAabbMax(int nodeIndex) const
{ {
if (m_useQuantization) if (m_useQuantization)
{ {
@@ -271,7 +271,7 @@ protected:
} }
void mergeInternalNodeAabb(int nodeIndex,const btVector3& newAabbMin,const btVector3& newAabbMax) void mergeInternalNodeAabb(int nodeIndex,const b3Vector3& newAabbMin,const b3Vector3& newAabbMax)
{ {
if (m_useQuantization) if (m_useQuantization)
{ {
@@ -310,11 +310,11 @@ protected:
int sortAndCalcSplittingIndex(int startIndex,int endIndex,int splitAxis); int sortAndCalcSplittingIndex(int startIndex,int endIndex,int splitAxis);
void walkStacklessTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const; void walkStacklessTree(btNodeOverlapCallback* nodeCallback,const b3Vector3& aabbMin,const b3Vector3& aabbMax) const;
void walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const; void walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget, const b3Vector3& aabbMin, const b3Vector3& aabbMax, int startNodeIndex,int endNodeIndex) const;
void walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax,int startNodeIndex,int endNodeIndex) const; void walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax,int startNodeIndex,int endNodeIndex) const;
void walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const; void walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget, const b3Vector3& aabbMin, const b3Vector3& aabbMax, int startNodeIndex,int endNodeIndex) const;
///tree traversal designed for small-memory processors like PS3 SPU ///tree traversal designed for small-memory processors like PS3 SPU
void walkStacklessQuantizedTreeCacheFriendly(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax) const; void walkStacklessQuantizedTreeCacheFriendly(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax) const;
@@ -340,17 +340,17 @@ public:
///***************************************** expert/internal use only ************************* ///***************************************** expert/internal use only *************************
void setQuantizationValues(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,btScalar quantizationMargin=btScalar(1.0)); void setQuantizationValues(const b3Vector3& bvhAabbMin,const b3Vector3& bvhAabbMax,b3Scalar quantizationMargin=b3Scalar(1.0));
QuantizedNodeArray& getLeafNodeArray() { return m_quantizedLeafNodes; } QuantizedNodeArray& getLeafNodeArray() { return m_quantizedLeafNodes; }
///buildInternal is expert use only: assumes that setQuantizationValues and LeafNodeArray are initialized ///buildInternal is expert use only: assumes that setQuantizationValues and LeafNodeArray are initialized
void buildInternal(); void buildInternal();
///***************************************** expert/internal use only ************************* ///***************************************** expert/internal use only *************************
void reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const; void reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallback,const b3Vector3& aabbMin,const b3Vector3& aabbMax) const;
void reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget) const; void reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget) const;
void reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin,const btVector3& aabbMax) const; void reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const b3Vector3& raySource, const b3Vector3& rayTarget, const b3Vector3& aabbMin,const b3Vector3& aabbMax) const;
SIMD_FORCE_INLINE void quantize(unsigned short* out, const btVector3& point,int isMax) const SIMD_FORCE_INLINE void quantize(unsigned short* out, const b3Vector3& point,int isMax) const
{ {
btAssert(m_useQuantization); btAssert(m_useQuantization);
@@ -363,15 +363,15 @@ public:
btAssert(point.getY() >= m_bvhAabbMin.getY()); btAssert(point.getY() >= m_bvhAabbMin.getY());
btAssert(point.getZ() >= m_bvhAabbMin.getZ()); btAssert(point.getZ() >= m_bvhAabbMin.getZ());
btVector3 v = (point - m_bvhAabbMin) * m_bvhQuantization; b3Vector3 v = (point - m_bvhAabbMin) * m_bvhQuantization;
///Make sure rounding is done in a way that unQuantize(quantizeWithClamp(...)) is conservative ///Make sure rounding is done in a way that unQuantize(quantizeWithClamp(...)) is conservative
///end-points always set the first bit, so that they are sorted properly (so that neighbouring AABBs overlap properly) ///end-points always set the first bit, so that they are sorted properly (so that neighbouring AABBs overlap properly)
///@todo: double-check this ///@todo: double-check this
if (isMax) if (isMax)
{ {
out[0] = (unsigned short) (((unsigned short)(v.getX()+btScalar(1.)) | 1)); out[0] = (unsigned short) (((unsigned short)(v.getX()+b3Scalar(1.)) | 1));
out[1] = (unsigned short) (((unsigned short)(v.getY()+btScalar(1.)) | 1)); out[1] = (unsigned short) (((unsigned short)(v.getY()+b3Scalar(1.)) | 1));
out[2] = (unsigned short) (((unsigned short)(v.getZ()+btScalar(1.)) | 1)); out[2] = (unsigned short) (((unsigned short)(v.getZ()+b3Scalar(1.)) | 1));
} else } else
{ {
out[0] = (unsigned short) (((unsigned short)(v.getX()) & 0xfffe)); out[0] = (unsigned short) (((unsigned short)(v.getX()) & 0xfffe));
@@ -381,7 +381,7 @@ public:
#ifdef DEBUG_CHECK_DEQUANTIZATION #ifdef DEBUG_CHECK_DEQUANTIZATION
btVector3 newPoint = unQuantize(out); b3Vector3 newPoint = unQuantize(out);
if (isMax) if (isMax)
{ {
if (newPoint.getX() < point.getX()) if (newPoint.getX() < point.getX())
@@ -417,12 +417,12 @@ public:
} }
SIMD_FORCE_INLINE void quantizeWithClamp(unsigned short* out, const btVector3& point2,int isMax) const SIMD_FORCE_INLINE void quantizeWithClamp(unsigned short* out, const b3Vector3& point2,int isMax) const
{ {
btAssert(m_useQuantization); btAssert(m_useQuantization);
btVector3 clampedPoint(point2); b3Vector3 clampedPoint(point2);
clampedPoint.setMax(m_bvhAabbMin); clampedPoint.setMax(m_bvhAabbMin);
clampedPoint.setMin(m_bvhAabbMax); clampedPoint.setMin(m_bvhAabbMax);
@@ -430,13 +430,13 @@ public:
} }
SIMD_FORCE_INLINE btVector3 unQuantize(const unsigned short* vecIn) const SIMD_FORCE_INLINE b3Vector3 unQuantize(const unsigned short* vecIn) const
{ {
btVector3 vecOut; b3Vector3 vecOut;
vecOut.setValue( vecOut.setValue(
(btScalar)(vecIn[0]) / (m_bvhQuantization.getX()), (b3Scalar)(vecIn[0]) / (m_bvhQuantization.getX()),
(btScalar)(vecIn[1]) / (m_bvhQuantization.getY()), (b3Scalar)(vecIn[1]) / (m_bvhQuantization.getY()),
(btScalar)(vecIn[2]) / (m_bvhQuantization.getZ())); (b3Scalar)(vecIn[2]) / (m_bvhQuantization.getZ()));
vecOut += m_bvhAabbMin; vecOut += m_bvhAabbMin;
return vecOut; return vecOut;
} }
@@ -493,7 +493,7 @@ public:
private: private:
// Special "copy" constructor that allows for in-place deserialization // Special "copy" constructor that allows for in-place deserialization
// Prevents btVector3's default constructor from being called, but doesn't inialize much else // Prevents b3Vector3's default constructor from being called, but doesn't inialize much else
// ownsMemory should most likely be false if deserializing, and if you are not, don't call this (it also changes the function signature, which we need) // ownsMemory should most likely be false if deserializing, and if you are not, don't call this (it also changes the function signature, which we need)
b3QuantizedBvh(b3QuantizedBvh &other, bool ownsMemory); b3QuantizedBvh(b3QuantizedBvh &other, bool ownsMemory);

View File

@@ -1,17 +1,17 @@
#ifndef BT_RIGID_BODY_CL #ifndef BT_RIGID_BODY_CL
#define BT_RIGID_BODY_CL #define BT_RIGID_BODY_CL
#include "BulletCommon/btScalar.h" #include "BulletCommon/b3Scalar.h"
#include "BulletCommon/btMatrix3x3.h" #include "BulletCommon/b3Matrix3x3.h"
ATTRIBUTE_ALIGNED16(struct) b3RigidBodyCL ATTRIBUTE_ALIGNED16(struct) b3RigidBodyCL
{ {
BT_DECLARE_ALIGNED_ALLOCATOR(); BT_DECLARE_ALIGNED_ALLOCATOR();
btVector3 m_pos; b3Vector3 m_pos;
btQuaternion m_quat; b3Quaternion m_quat;
btVector3 m_linVel; b3Vector3 m_linVel;
btVector3 m_angVel; b3Vector3 m_angVel;
int m_collidableIdx; int m_collidableIdx;
float m_invMass; float m_invMass;
@@ -27,8 +27,8 @@ ATTRIBUTE_ALIGNED16(struct) b3RigidBodyCL
struct btInertiaCL struct btInertiaCL
{ {
btMatrix3x3 m_invInertiaWorld; b3Matrix3x3 m_invInertiaWorld;
btMatrix3x3 m_initInvInertia; b3Matrix3x3 m_initInvInertia;
}; };

View File

@@ -22,7 +22,7 @@ b3StridingMeshInterface::~b3StridingMeshInterface()
} }
void b3StridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const void b3StridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const b3Vector3& aabbMin,const b3Vector3& aabbMax) const
{ {
(void)aabbMin; (void)aabbMin;
(void)aabbMax; (void)aabbMax;
@@ -35,9 +35,9 @@ void b3StridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
PHY_ScalarType gfxindextype; PHY_ScalarType gfxindextype;
int stride,numverts,numtriangles; int stride,numverts,numtriangles;
int gfxindex; int gfxindex;
btVector3 triangle[3]; b3Vector3 triangle[3];
btVector3 meshScaling = getScaling(); b3Vector3 meshScaling = getScaling();
///if the number of parts is big, the performance might drop due to the innerloop switch on indextype ///if the number of parts is big, the performance might drop due to the innerloop switch on indextype
for (part=0;part<graphicssubparts ;part++) for (part=0;part<graphicssubparts ;part++)
@@ -121,11 +121,11 @@ void b3StridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
{ {
unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride); unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
graphicsbase = (double*)(vertexbase+tri_indices[0]*stride); graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ()); triangle[0].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(),(b3Scalar)graphicsbase[2]*meshScaling.getZ());
graphicsbase = (double*)(vertexbase+tri_indices[1]*stride); graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ()); triangle[1].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(), (b3Scalar)graphicsbase[2]*meshScaling.getZ());
graphicsbase = (double*)(vertexbase+tri_indices[2]*stride); graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ()); triangle[2].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(), (b3Scalar)graphicsbase[2]*meshScaling.getZ());
callback->internalProcessTriangleIndex(triangle,part,gfxindex); callback->internalProcessTriangleIndex(triangle,part,gfxindex);
} }
break; break;
@@ -136,11 +136,11 @@ void b3StridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
{ {
unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride); unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
graphicsbase = (double*)(vertexbase+tri_indices[0]*stride); graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ()); triangle[0].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(),(b3Scalar)graphicsbase[2]*meshScaling.getZ());
graphicsbase = (double*)(vertexbase+tri_indices[1]*stride); graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ()); triangle[1].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(), (b3Scalar)graphicsbase[2]*meshScaling.getZ());
graphicsbase = (double*)(vertexbase+tri_indices[2]*stride); graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ()); triangle[2].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(), (b3Scalar)graphicsbase[2]*meshScaling.getZ());
callback->internalProcessTriangleIndex(triangle,part,gfxindex); callback->internalProcessTriangleIndex(triangle,part,gfxindex);
} }
break; break;
@@ -151,11 +151,11 @@ void b3StridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
{ {
unsigned char* tri_indices= (unsigned char*)(indexbase+gfxindex*indexstride); unsigned char* tri_indices= (unsigned char*)(indexbase+gfxindex*indexstride);
graphicsbase = (double*)(vertexbase+tri_indices[0]*stride); graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ()); triangle[0].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(),(b3Scalar)graphicsbase[2]*meshScaling.getZ());
graphicsbase = (double*)(vertexbase+tri_indices[1]*stride); graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ()); triangle[1].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(), (b3Scalar)graphicsbase[2]*meshScaling.getZ());
graphicsbase = (double*)(vertexbase+tri_indices[2]*stride); graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ()); triangle[2].setValue((b3Scalar)graphicsbase[0]*meshScaling.getX(),(b3Scalar)graphicsbase[1]*meshScaling.getY(), (b3Scalar)graphicsbase[2]*meshScaling.getZ());
callback->internalProcessTriangleIndex(triangle,part,gfxindex); callback->internalProcessTriangleIndex(triangle,part,gfxindex);
} }
break; break;
@@ -173,21 +173,21 @@ void b3StridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
} }
} }
void b3StridingMeshInterface::calculateAabbBruteForce(btVector3& aabbMin,btVector3& aabbMax) void b3StridingMeshInterface::calculateAabbBruteForce(b3Vector3& aabbMin,b3Vector3& aabbMax)
{ {
struct AabbCalculationCallback : public btInternalTriangleIndexCallback struct AabbCalculationCallback : public btInternalTriangleIndexCallback
{ {
btVector3 m_aabbMin; b3Vector3 m_aabbMin;
btVector3 m_aabbMax; b3Vector3 m_aabbMax;
AabbCalculationCallback() AabbCalculationCallback()
{ {
m_aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); m_aabbMin.setValue(b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT));
m_aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); m_aabbMax.setValue(b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT));
} }
virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex) virtual void internalProcessTriangleIndex(b3Vector3* triangle,int partId,int triangleIndex)
{ {
(void)partId; (void)partId;
(void)triangleIndex; (void)triangleIndex;
@@ -203,8 +203,8 @@ void b3StridingMeshInterface::calculateAabbBruteForce(btVector3& aabbMin,btVecto
//first calculate the total aabb for all triangles //first calculate the total aabb for all triangles
AabbCalculationCallback aabbCallback; AabbCalculationCallback aabbCallback;
aabbMin.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); aabbMin.setValue(b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT),b3Scalar(-BT_LARGE_FLOAT));
aabbMax.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); aabbMax.setValue(b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT),b3Scalar(BT_LARGE_FLOAT));
InternalProcessAllTriangles(&aabbCallback,aabbMin,aabbMax); InternalProcessAllTriangles(&aabbCallback,aabbMin,aabbMax);
aabbMin = aabbCallback.m_aabbMin; aabbMin = aabbCallback.m_aabbMin;

View File

@@ -16,7 +16,7 @@ subject to the following restrictions:
#ifndef BT_STRIDING_MESHINTERFACE_H #ifndef BT_STRIDING_MESHINTERFACE_H
#define BT_STRIDING_MESHINTERFACE_H #define BT_STRIDING_MESHINTERFACE_H
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
#include "b3TriangleCallback.h" #include "b3TriangleCallback.h"
//#include "btConcaveShape.h" //#include "btConcaveShape.h"
@@ -34,12 +34,12 @@ ATTRIBUTE_ALIGNED16(class ) b3StridingMeshInterface
{ {
protected: protected:
btVector3 m_scaling; b3Vector3 m_scaling;
public: public:
BT_DECLARE_ALIGNED_ALLOCATOR(); BT_DECLARE_ALIGNED_ALLOCATOR();
b3StridingMeshInterface() :m_scaling(btScalar(1.),btScalar(1.),btScalar(1.)) b3StridingMeshInterface() :m_scaling(b3Scalar(1.),b3Scalar(1.),b3Scalar(1.))
{ {
} }
@@ -48,10 +48,10 @@ ATTRIBUTE_ALIGNED16(class ) b3StridingMeshInterface
virtual void InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const; virtual void InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const b3Vector3& aabbMin,const b3Vector3& aabbMax) const;
///brute force method to calculate aabb ///brute force method to calculate aabb
void calculateAabbBruteForce(btVector3& aabbMin,btVector3& aabbMax); void calculateAabbBruteForce(b3Vector3& aabbMin,b3Vector3& aabbMax);
/// get read and write access to a subpart of a triangle mesh /// get read and write access to a subpart of a triangle mesh
/// this subpart has a continuous array of vertices and indices /// this subpart has a continuous array of vertices and indices
@@ -77,21 +77,21 @@ ATTRIBUTE_ALIGNED16(class ) b3StridingMeshInterface
virtual void preallocateIndices(int numindices)=0; virtual void preallocateIndices(int numindices)=0;
virtual bool hasPremadeAabb() const { return false; } virtual bool hasPremadeAabb() const { return false; }
virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const virtual void setPremadeAabb(const b3Vector3& aabbMin, const b3Vector3& aabbMax ) const
{ {
(void) aabbMin; (void) aabbMin;
(void) aabbMax; (void) aabbMax;
} }
virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const virtual void getPremadeAabb(b3Vector3* aabbMin, b3Vector3* aabbMax ) const
{ {
(void) aabbMin; (void) aabbMin;
(void) aabbMax; (void) aabbMax;
} }
const btVector3& getScaling() const { const b3Vector3& getScaling() const {
return m_scaling; return m_scaling;
} }
void setScaling(const btVector3& scaling) void setScaling(const b3Vector3& scaling)
{ {
m_scaling = scaling; m_scaling = scaling;
} }

View File

@@ -16,7 +16,7 @@ subject to the following restrictions:
#ifndef BT_TRIANGLE_CALLBACK_H #ifndef BT_TRIANGLE_CALLBACK_H
#define BT_TRIANGLE_CALLBACK_H #define BT_TRIANGLE_CALLBACK_H
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
///The b3TriangleCallback provides a callback for each overlapping triangle when calling processAllTriangles. ///The b3TriangleCallback provides a callback for each overlapping triangle when calling processAllTriangles.
@@ -26,7 +26,7 @@ class b3TriangleCallback
public: public:
virtual ~b3TriangleCallback(); virtual ~b3TriangleCallback();
virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex) = 0; virtual void processTriangle(b3Vector3* triangle, int partId, int triangleIndex) = 0;
}; };
class btInternalTriangleIndexCallback class btInternalTriangleIndexCallback
@@ -34,7 +34,7 @@ class btInternalTriangleIndexCallback
public: public:
virtual ~btInternalTriangleIndexCallback(); virtual ~btInternalTriangleIndexCallback();
virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex) = 0; virtual void internalProcessTriangleIndex(b3Vector3* triangle,int partId,int triangleIndex) = 0;
}; };

View File

@@ -15,7 +15,7 @@ subject to the following restrictions:
#include "b3TriangleIndexVertexArray.h" #include "b3TriangleIndexVertexArray.h"
b3TriangleIndexVertexArray::b3TriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,btScalar* vertexBase,int vertexStride) b3TriangleIndexVertexArray::b3TriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,b3Scalar* vertexBase,int vertexStride)
: m_hasAabb(0) : m_hasAabb(0)
{ {
btIndexedMesh mesh; btIndexedMesh mesh;
@@ -79,14 +79,14 @@ bool b3TriangleIndexVertexArray::hasPremadeAabb() const
} }
void b3TriangleIndexVertexArray::setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const void b3TriangleIndexVertexArray::setPremadeAabb(const b3Vector3& aabbMin, const b3Vector3& aabbMax ) const
{ {
m_aabbMin = aabbMin; m_aabbMin = aabbMin;
m_aabbMax = aabbMax; m_aabbMax = aabbMax;
m_hasAabb = 1; // this is intentionally an int see notes in header m_hasAabb = 1; // this is intentionally an int see notes in header
} }
void b3TriangleIndexVertexArray::getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const void b3TriangleIndexVertexArray::getPremadeAabb(b3Vector3* aabbMin, b3Vector3* aabbMax ) const
{ {
*aabbMin = m_aabbMin; *aabbMin = m_aabbMin;
*aabbMax = m_aabbMax; *aabbMax = m_aabbMax;

View File

@@ -17,8 +17,8 @@ subject to the following restrictions:
#define BT_TRIANGLE_INDEX_VERTEX_ARRAY_H #define BT_TRIANGLE_INDEX_VERTEX_ARRAY_H
#include "b3StridingMeshInterface.h" #include "b3StridingMeshInterface.h"
#include "BulletCommon/btAlignedObjectArray.h" #include "BulletCommon/b3AlignedObjectArray.h"
#include "BulletCommon/btScalar.h" #include "BulletCommon/b3Scalar.h"
///The btIndexedMesh indexes a single vertex and index array. Multiple btIndexedMesh objects can be passed into a b3TriangleIndexVertexArray using addIndexedMesh. ///The btIndexedMesh indexes a single vertex and index array. Multiple btIndexedMesh objects can be passed into a b3TriangleIndexVertexArray using addIndexedMesh.
@@ -59,7 +59,7 @@ ATTRIBUTE_ALIGNED16( struct) btIndexedMesh
; ;
typedef btAlignedObjectArray<btIndexedMesh> IndexedMeshArray; typedef b3AlignedObjectArray<btIndexedMesh> IndexedMeshArray;
///The b3TriangleIndexVertexArray allows to access multiple triangle meshes, by indexing into existing triangle/index arrays. ///The b3TriangleIndexVertexArray allows to access multiple triangle meshes, by indexing into existing triangle/index arrays.
///Additional meshes can be added using addIndexedMesh ///Additional meshes can be added using addIndexedMesh
@@ -71,8 +71,8 @@ protected:
IndexedMeshArray m_indexedMeshes; IndexedMeshArray m_indexedMeshes;
int m_pad[2]; int m_pad[2];
mutable int m_hasAabb; // using int instead of bool to maintain alignment mutable int m_hasAabb; // using int instead of bool to maintain alignment
mutable btVector3 m_aabbMin; mutable b3Vector3 m_aabbMin;
mutable btVector3 m_aabbMax; mutable b3Vector3 m_aabbMax;
public: public:
@@ -85,7 +85,7 @@ public:
virtual ~b3TriangleIndexVertexArray(); virtual ~b3TriangleIndexVertexArray();
//just to be backwards compatible //just to be backwards compatible
b3TriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,btScalar* vertexBase,int vertexStride); b3TriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,b3Scalar* vertexBase,int vertexStride);
void addIndexedMesh(const btIndexedMesh& mesh, PHY_ScalarType indexType = PHY_INTEGER) void addIndexedMesh(const btIndexedMesh& mesh, PHY_ScalarType indexType = PHY_INTEGER)
{ {
@@ -124,8 +124,8 @@ public:
virtual void preallocateIndices(int numindices){(void) numindices;} virtual void preallocateIndices(int numindices){(void) numindices;}
virtual bool hasPremadeAabb() const; virtual bool hasPremadeAabb() const;
virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const; virtual void setPremadeAabb(const b3Vector3& aabbMin, const b3Vector3& aabbMax ) const;
virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const; virtual void getPremadeAabb(b3Vector3* aabbMin, b3Vector3* aabbMax ) const;
} }
; ;

View File

@@ -17,15 +17,15 @@ subject to the following restrictions:
#include "../basic_initialize/b3OpenCLUtils.h" #include "../basic_initialize/b3OpenCLUtils.h"
#include "../host/b3ConvexHullContact.h" #include "../host/b3ConvexHullContact.h"
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
#include "parallel_primitives/host/btFillCL.h" #include "parallel_primitives/host/btFillCL.h"
#include "parallel_primitives/host/btBoundSearchCL.h" #include "parallel_primitives/host/btBoundSearchCL.h"
#include "parallel_primitives/host/btRadixSort32CL.h" #include "parallel_primitives/host/btRadixSort32CL.h"
#include "parallel_primitives/host/btPrefixScanCL.h" #include "parallel_primitives/host/btPrefixScanCL.h"
#include "BulletCommon/CommandLineArgs.h" #include "BulletCommon/b3CommandLineArgs.h"
#include "../host/b3ConvexHullContact.h" #include "../host/b3ConvexHullContact.h"
#include "BulletCommon/btMinMax.h" #include "BulletCommon/b3MinMax.h"
int g_nPassed = 0; int g_nPassed = 0;
int g_nFailed = 0; int g_nFailed = 0;
bool g_testFailed = 0; bool g_testFailed = 0;
@@ -88,7 +88,7 @@ int main(int argc, char** argv)
{ {
int preferredDeviceIndex = -1; int preferredPlatformIndex = -1; int preferredDeviceIndex = -1; int preferredPlatformIndex = -1;
CommandLineArgs args(argc, argv); b3CommandLineArgs args(argc, argv);
args.GetCmdLineArgument("deviceId", preferredDeviceIndex); args.GetCmdLineArgument("deviceId", preferredDeviceIndex);
args.GetCmdLineArgument("platformId", preferredPlatformIndex); args.GetCmdLineArgument("platformId", preferredPlatformIndex);

View File

@@ -29,11 +29,11 @@ function createProject(vendor)
"../../parallel_primitives/host/btPrefixScanCL.h", "../../parallel_primitives/host/btPrefixScanCL.h",
"../../parallel_primitives/host/btRadixSort32CL.cpp", "../../parallel_primitives/host/btRadixSort32CL.cpp",
"../../parallel_primitives/host/btRadixSort32CL.h", "../../parallel_primitives/host/btRadixSort32CL.h",
"../../../src/BulletCommon/btAlignedAllocator.cpp", "../../../src/BulletCommon/b3AlignedAllocator.cpp",
"../../../src/BulletCommon/btAlignedAllocator.h", "../../../src/BulletCommon/b3AlignedAllocator.h",
"../../../src/BulletCommon/btAlignedObjectArray.h", "../../../src/BulletCommon/b3AlignedObjectArray.h",
"../../../src/BulletCommon/btQuickprof.cpp", "../../../src/BulletCommon/b3Quickprof.cpp",
"../../../src/BulletCommon/btQuickprof.h", "../../../src/BulletCommon/b3Quickprof.h",
"../../../src/BulletGeometry/**.cpp", "../../../src/BulletGeometry/**.cpp",
"../../../src/BulletGeometry/**.h", "../../../src/BulletGeometry/**.h",

View File

@@ -2,7 +2,7 @@
#include "b3GpuBatchingPgsSolver.h" #include "b3GpuBatchingPgsSolver.h"
#include "../../parallel_primitives/host/btRadixSort32CL.h" #include "../../parallel_primitives/host/btRadixSort32CL.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "../../parallel_primitives/host/btLauncherCL.h" #include "../../parallel_primitives/host/btLauncherCL.h"
#include "../../parallel_primitives/host/btBoundSearchCL.h" #include "../../parallel_primitives/host/btBoundSearchCL.h"
#include "../../parallel_primitives/host/btPrefixScanCL.h" #include "../../parallel_primitives/host/btPrefixScanCL.h"
@@ -76,9 +76,9 @@ struct btGpuBatchingPgsSolverInternalData
btOpenCLArray<b3Contact4>* m_pBufContactOutGPU; btOpenCLArray<b3Contact4>* m_pBufContactOutGPU;
btAlignedObjectArray<unsigned int> m_idxBuffer; b3AlignedObjectArray<unsigned int> m_idxBuffer;
btAlignedObjectArray<btSortData> m_sortData; b3AlignedObjectArray<btSortData> m_sortData;
btAlignedObjectArray<b3Contact4> m_old; b3AlignedObjectArray<b3Contact4> m_old;
}; };
@@ -519,7 +519,7 @@ void b3GpuBatchingPgsSolver::solveContacts(int numBodies, cl_mem bodyBuf, cl_mem
btOpenCLArray<btSortData>& keyValuesInOut = *(m_data->m_solverGPU->m_sortDataBuffer); btOpenCLArray<btSortData>& keyValuesInOut = *(m_data->m_solverGPU->m_sortDataBuffer);
this->m_data->m_solverGPU->m_sort32->execute(keyValuesInOut); this->m_data->m_solverGPU->m_sort32->execute(keyValuesInOut);
/*btAlignedObjectArray<btSortData> hostValues; /*b3AlignedObjectArray<btSortData> hostValues;
keyValuesInOut.copyToHost(hostValues); keyValuesInOut.copyToHost(hostValues);
printf("hostValues.size=%d\n",hostValues.size()); printf("hostValues.size=%d\n",hostValues.size());
*/ */
@@ -596,15 +596,15 @@ void b3GpuBatchingPgsSolver::solveContacts(int numBodies, cl_mem bodyBuf, cl_mem
} else } else
{ {
BT_PROFILE("cpu batchContacts"); BT_PROFILE("cpu batchContacts");
btAlignedObjectArray<b3Contact4> cpuContacts; b3AlignedObjectArray<b3Contact4> cpuContacts;
btOpenCLArray<b3Contact4>* contactsIn = m_data->m_solverGPU->m_contactBuffer2; btOpenCLArray<b3Contact4>* contactsIn = m_data->m_solverGPU->m_contactBuffer2;
contactsIn->copyToHost(cpuContacts); contactsIn->copyToHost(cpuContacts);
btOpenCLArray<unsigned int>* countsNative = m_data->m_solverGPU->m_numConstraints; btOpenCLArray<unsigned int>* countsNative = m_data->m_solverGPU->m_numConstraints;
btOpenCLArray<unsigned int>* offsetsNative = m_data->m_solverGPU->m_offsets; btOpenCLArray<unsigned int>* offsetsNative = m_data->m_solverGPU->m_offsets;
btAlignedObjectArray<unsigned int> nNativeHost; b3AlignedObjectArray<unsigned int> nNativeHost;
btAlignedObjectArray<unsigned int> offsetsNativeHost; b3AlignedObjectArray<unsigned int> offsetsNativeHost;
{ {
BT_PROFILE("countsNative/offsetsNative copyToHost"); BT_PROFILE("countsNative/offsetsNative copyToHost");
@@ -641,7 +641,7 @@ void b3GpuBatchingPgsSolver::solveContacts(int numBodies, cl_mem bodyBuf, cl_mem
} }
{ {
BT_PROFILE("m_contactBuffer->copyFromHost"); BT_PROFILE("m_contactBuffer->copyFromHost");
m_data->m_solverGPU->m_contactBuffer2->copyFromHost((btAlignedObjectArray<b3Contact4>&)cpuContacts); m_data->m_solverGPU->m_contactBuffer2->copyFromHost((b3AlignedObjectArray<b3Contact4>&)cpuContacts);
} }
} }
@@ -724,19 +724,19 @@ static bool sortfnc(const btSortData& a,const btSortData& b)
btAlignedObjectArray<int> bodyUsed; b3AlignedObjectArray<int> bodyUsed;
btAlignedObjectArray<unsigned int> idxBuffer; b3AlignedObjectArray<unsigned int> idxBuffer;
btAlignedObjectArray<btSortData> sortData; b3AlignedObjectArray<btSortData> sortData;
btAlignedObjectArray<b3Contact4> old; b3AlignedObjectArray<b3Contact4> old;
inline int b3GpuBatchingPgsSolver::sortConstraintByBatch( b3Contact4* cs, int n, int simdWidth , int staticIdx, int numBodies) inline int b3GpuBatchingPgsSolver::sortConstraintByBatch( b3Contact4* cs, int n, int simdWidth , int staticIdx, int numBodies)
{ {
btAlignedObjectArray<int> bodyUsed; b3AlignedObjectArray<int> bodyUsed;
bodyUsed.resize(numBodies); bodyUsed.resize(numBodies);
for (int q=0;q<numBodies;q++) for (int q=0;q<numBodies;q++)
bodyUsed[q]=0; bodyUsed[q]=0;

View File

@@ -1,15 +1,15 @@
#ifndef BT_CONSTRAINT4_h #ifndef BT_CONSTRAINT4_h
#define BT_CONSTRAINT4_h #define BT_CONSTRAINT4_h
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
ATTRIBUTE_ALIGNED16(struct) b3GpuConstraint4 ATTRIBUTE_ALIGNED16(struct) b3GpuConstraint4
{ {
BT_DECLARE_ALIGNED_ALLOCATOR(); BT_DECLARE_ALIGNED_ALLOCATOR();
btVector3 m_linear;//normal? b3Vector3 m_linear;//normal?
btVector3 m_worldPos[4]; b3Vector3 m_worldPos[4];
btVector3 m_center; // friction b3Vector3 m_center; // friction
float m_jacCoeffInv[4]; float m_jacCoeffInv[4];
float m_b[4]; float m_b[4];
float m_appliedRambdaDt[4]; float m_appliedRambdaDt[4];

View File

@@ -13,57 +13,57 @@
struct btGpuNarrowPhaseInternalData struct btGpuNarrowPhaseInternalData
{ {
btAlignedObjectArray<b3ConvexUtility*>* m_convexData; b3AlignedObjectArray<b3ConvexUtility*>* m_convexData;
btAlignedObjectArray<b3ConvexPolyhedronCL> m_convexPolyhedra; b3AlignedObjectArray<b3ConvexPolyhedronCL> m_convexPolyhedra;
btAlignedObjectArray<btVector3> m_uniqueEdges; b3AlignedObjectArray<b3Vector3> m_uniqueEdges;
btAlignedObjectArray<btVector3> m_convexVertices; b3AlignedObjectArray<b3Vector3> m_convexVertices;
btAlignedObjectArray<int> m_convexIndices; b3AlignedObjectArray<int> m_convexIndices;
btOpenCLArray<b3ConvexPolyhedronCL>* m_convexPolyhedraGPU; btOpenCLArray<b3ConvexPolyhedronCL>* m_convexPolyhedraGPU;
btOpenCLArray<btVector3>* m_uniqueEdgesGPU; btOpenCLArray<b3Vector3>* m_uniqueEdgesGPU;
btOpenCLArray<btVector3>* m_convexVerticesGPU; btOpenCLArray<b3Vector3>* m_convexVerticesGPU;
btOpenCLArray<int>* m_convexIndicesGPU; btOpenCLArray<int>* m_convexIndicesGPU;
btOpenCLArray<btVector3>* m_worldVertsB1GPU; btOpenCLArray<b3Vector3>* m_worldVertsB1GPU;
btOpenCLArray<btInt4>* m_clippingFacesOutGPU; btOpenCLArray<btInt4>* m_clippingFacesOutGPU;
btOpenCLArray<btVector3>* m_worldNormalsAGPU; btOpenCLArray<b3Vector3>* m_worldNormalsAGPU;
btOpenCLArray<btVector3>* m_worldVertsA1GPU; btOpenCLArray<b3Vector3>* m_worldVertsA1GPU;
btOpenCLArray<btVector3>* m_worldVertsB2GPU; btOpenCLArray<b3Vector3>* m_worldVertsB2GPU;
btAlignedObjectArray<btGpuChildShape> m_cpuChildShapes; b3AlignedObjectArray<btGpuChildShape> m_cpuChildShapes;
btOpenCLArray<btGpuChildShape>* m_gpuChildShapes; btOpenCLArray<btGpuChildShape>* m_gpuChildShapes;
btAlignedObjectArray<btGpuFace> m_convexFaces; b3AlignedObjectArray<btGpuFace> m_convexFaces;
btOpenCLArray<btGpuFace>* m_convexFacesGPU; btOpenCLArray<btGpuFace>* m_convexFacesGPU;
GpuSatCollision* m_gpuSatCollision; GpuSatCollision* m_gpuSatCollision;
btAlignedObjectArray<btInt2>* m_pBufPairsCPU; b3AlignedObjectArray<btInt2>* m_pBufPairsCPU;
btOpenCLArray<btInt2>* m_convexPairsOutGPU; btOpenCLArray<btInt2>* m_convexPairsOutGPU;
btOpenCLArray<btInt2>* m_planePairs; btOpenCLArray<btInt2>* m_planePairs;
btOpenCLArray<b3Contact4>* m_pBufContactOutGPU; btOpenCLArray<b3Contact4>* m_pBufContactOutGPU;
btAlignedObjectArray<b3Contact4>* m_pBufContactOutCPU; b3AlignedObjectArray<b3Contact4>* m_pBufContactOutCPU;
btAlignedObjectArray<b3RigidBodyCL>* m_bodyBufferCPU; b3AlignedObjectArray<b3RigidBodyCL>* m_bodyBufferCPU;
btOpenCLArray<b3RigidBodyCL>* m_bodyBufferGPU; btOpenCLArray<b3RigidBodyCL>* m_bodyBufferGPU;
btAlignedObjectArray<btInertiaCL>* m_inertiaBufferCPU; b3AlignedObjectArray<btInertiaCL>* m_inertiaBufferCPU;
btOpenCLArray<btInertiaCL>* m_inertiaBufferGPU; btOpenCLArray<btInertiaCL>* m_inertiaBufferGPU;
int m_numAcceleratedShapes; int m_numAcceleratedShapes;
int m_numAcceleratedRigidBodies; int m_numAcceleratedRigidBodies;
btAlignedObjectArray<b3Collidable> m_collidablesCPU; b3AlignedObjectArray<b3Collidable> m_collidablesCPU;
btOpenCLArray<b3Collidable>* m_collidablesGPU; btOpenCLArray<b3Collidable>* m_collidablesGPU;
btOpenCLArray<b3SapAabb>* m_localShapeAABBGPU; btOpenCLArray<b3SapAabb>* m_localShapeAABBGPU;
btAlignedObjectArray<b3SapAabb>* m_localShapeAABBCPU; b3AlignedObjectArray<b3SapAabb>* m_localShapeAABBCPU;
btAlignedObjectArray<class b3OptimizedBvh*> m_bvhData; b3AlignedObjectArray<class b3OptimizedBvh*> m_bvhData;
btOpenCLArray<btQuantizedBvhNode>* m_treeNodesGPU; btOpenCLArray<btQuantizedBvhNode>* m_treeNodesGPU;
btOpenCLArray<btBvhSubtreeInfo>* m_subTreesGPU; btOpenCLArray<btBvhSubtreeInfo>* m_subTreesGPU;
@@ -89,18 +89,18 @@ m_queue(queue)
m_data->m_config = config; m_data->m_config = config;
m_data->m_gpuSatCollision = new GpuSatCollision(ctx,device,queue); m_data->m_gpuSatCollision = new GpuSatCollision(ctx,device,queue);
m_data->m_pBufPairsCPU = new btAlignedObjectArray<btInt2>; m_data->m_pBufPairsCPU = new b3AlignedObjectArray<btInt2>;
m_data->m_pBufPairsCPU->resize(config.m_maxBroadphasePairs); m_data->m_pBufPairsCPU->resize(config.m_maxBroadphasePairs);
m_data->m_convexPairsOutGPU = new btOpenCLArray<btInt2>(ctx,queue,config.m_maxBroadphasePairs,false); m_data->m_convexPairsOutGPU = new btOpenCLArray<btInt2>(ctx,queue,config.m_maxBroadphasePairs,false);
m_data->m_planePairs = new btOpenCLArray<btInt2>(ctx,queue,config.m_maxBroadphasePairs,false); m_data->m_planePairs = new btOpenCLArray<btInt2>(ctx,queue,config.m_maxBroadphasePairs,false);
m_data->m_pBufContactOutCPU = new btAlignedObjectArray<b3Contact4>(); m_data->m_pBufContactOutCPU = new b3AlignedObjectArray<b3Contact4>();
m_data->m_pBufContactOutCPU->resize(config.m_maxBroadphasePairs); m_data->m_pBufContactOutCPU->resize(config.m_maxBroadphasePairs);
m_data->m_bodyBufferCPU = new btAlignedObjectArray<b3RigidBodyCL>(); m_data->m_bodyBufferCPU = new b3AlignedObjectArray<b3RigidBodyCL>();
m_data->m_bodyBufferCPU->resize(config.m_maxConvexBodies); m_data->m_bodyBufferCPU->resize(config.m_maxConvexBodies);
m_data->m_inertiaBufferCPU = new btAlignedObjectArray<btInertiaCL>(); m_data->m_inertiaBufferCPU = new b3AlignedObjectArray<btInertiaCL>();
m_data->m_inertiaBufferCPU->resize(config.m_maxConvexBodies); m_data->m_inertiaBufferCPU->resize(config.m_maxConvexBodies);
m_data->m_pBufContactOutGPU = new btOpenCLArray<b3Contact4>(ctx,queue, config.m_maxContactCapacity,true); m_data->m_pBufContactOutGPU = new btOpenCLArray<b3Contact4>(ctx,queue, config.m_maxContactCapacity,true);
@@ -108,7 +108,7 @@ m_queue(queue)
m_data->m_inertiaBufferGPU = new btOpenCLArray<btInertiaCL>(ctx,queue,config.m_maxConvexBodies,false); m_data->m_inertiaBufferGPU = new btOpenCLArray<btInertiaCL>(ctx,queue,config.m_maxConvexBodies,false);
m_data->m_collidablesGPU = new btOpenCLArray<b3Collidable>(ctx,queue,config.m_maxConvexShapes); m_data->m_collidablesGPU = new btOpenCLArray<b3Collidable>(ctx,queue,config.m_maxConvexShapes);
m_data->m_localShapeAABBCPU = new btAlignedObjectArray<b3SapAabb>; m_data->m_localShapeAABBCPU = new b3AlignedObjectArray<b3SapAabb>;
m_data->m_localShapeAABBGPU = new btOpenCLArray<b3SapAabb>(ctx,queue,config.m_maxConvexShapes); m_data->m_localShapeAABBGPU = new btOpenCLArray<b3SapAabb>(ctx,queue,config.m_maxConvexShapes);
@@ -119,20 +119,20 @@ m_queue(queue)
m_data->m_gpuChildShapes = new btOpenCLArray<btGpuChildShape>(ctx,queue,config.m_maxCompoundChildShapes,false); m_data->m_gpuChildShapes = new btOpenCLArray<btGpuChildShape>(ctx,queue,config.m_maxCompoundChildShapes,false);
m_data->m_convexPolyhedraGPU = new btOpenCLArray<b3ConvexPolyhedronCL>(ctx,queue,config.m_maxConvexShapes,false); m_data->m_convexPolyhedraGPU = new btOpenCLArray<b3ConvexPolyhedronCL>(ctx,queue,config.m_maxConvexShapes,false);
m_data->m_uniqueEdgesGPU = new btOpenCLArray<btVector3>(ctx,queue,config.m_maxConvexUniqueEdges,true); m_data->m_uniqueEdgesGPU = new btOpenCLArray<b3Vector3>(ctx,queue,config.m_maxConvexUniqueEdges,true);
m_data->m_convexVerticesGPU = new btOpenCLArray<btVector3>(ctx,queue,config.m_maxConvexVertices,true); m_data->m_convexVerticesGPU = new btOpenCLArray<b3Vector3>(ctx,queue,config.m_maxConvexVertices,true);
m_data->m_convexIndicesGPU = new btOpenCLArray<int>(ctx,queue,config.m_maxConvexIndices,true); m_data->m_convexIndicesGPU = new btOpenCLArray<int>(ctx,queue,config.m_maxConvexIndices,true);
m_data->m_worldVertsB1GPU = new btOpenCLArray<btVector3>(ctx,queue,config.m_maxConvexBodies*config.m_maxVerticesPerFace); m_data->m_worldVertsB1GPU = new btOpenCLArray<b3Vector3>(ctx,queue,config.m_maxConvexBodies*config.m_maxVerticesPerFace);
m_data->m_clippingFacesOutGPU = new btOpenCLArray<btInt4>(ctx,queue,config.m_maxConvexBodies); m_data->m_clippingFacesOutGPU = new btOpenCLArray<btInt4>(ctx,queue,config.m_maxConvexBodies);
m_data->m_worldNormalsAGPU = new btOpenCLArray<btVector3>(ctx,queue,config.m_maxConvexBodies); m_data->m_worldNormalsAGPU = new btOpenCLArray<b3Vector3>(ctx,queue,config.m_maxConvexBodies);
m_data->m_worldVertsA1GPU = new btOpenCLArray<btVector3>(ctx,queue,config.m_maxConvexBodies*config.m_maxVerticesPerFace); m_data->m_worldVertsA1GPU = new btOpenCLArray<b3Vector3>(ctx,queue,config.m_maxConvexBodies*config.m_maxVerticesPerFace);
m_data->m_worldVertsB2GPU = new btOpenCLArray<btVector3>(ctx,queue,config.m_maxConvexBodies*config.m_maxVerticesPerFace); m_data->m_worldVertsB2GPU = new btOpenCLArray<b3Vector3>(ctx,queue,config.m_maxConvexBodies*config.m_maxVerticesPerFace);
m_data->m_convexData = new btAlignedObjectArray<b3ConvexUtility* >(); m_data->m_convexData = new b3AlignedObjectArray<b3ConvexUtility* >();
m_data->m_convexData->resize(config.m_maxConvexShapes); m_data->m_convexData->resize(config.m_maxConvexShapes);
@@ -209,8 +209,8 @@ int b3GpuNarrowPhase::registerSphereShape(float radius)
if (col.m_shapeIndex>=0) if (col.m_shapeIndex>=0)
{ {
b3SapAabb aabb; b3SapAabb aabb;
btVector3 myAabbMin(-radius,-radius,-radius); b3Vector3 myAabbMin(-radius,-radius,-radius);
btVector3 myAabbMax(radius,radius,radius); b3Vector3 myAabbMax(radius,radius,radius);
aabb.m_min[0] = myAabbMin[0];//s_convexHeightField->m_aabb.m_min.x; aabb.m_min[0] = myAabbMin[0];//s_convexHeightField->m_aabb.m_min.x;
aabb.m_min[1] = myAabbMin[1];//s_convexHeightField->m_aabb.m_min.y; aabb.m_min[1] = myAabbMin[1];//s_convexHeightField->m_aabb.m_min.y;
@@ -231,7 +231,7 @@ int b3GpuNarrowPhase::registerSphereShape(float radius)
} }
int b3GpuNarrowPhase::registerFace(const btVector3& faceNormal, float faceConstant) int b3GpuNarrowPhase::registerFace(const b3Vector3& faceNormal, float faceConstant)
{ {
int faceOffset = m_data->m_convexFaces.size(); int faceOffset = m_data->m_convexFaces.size();
btGpuFace& face = m_data->m_convexFaces.expand(); btGpuFace& face = m_data->m_convexFaces.expand();
@@ -243,7 +243,7 @@ int b3GpuNarrowPhase::registerFace(const btVector3& faceNormal, float faceConsta
return faceOffset; return faceOffset;
} }
int b3GpuNarrowPhase::registerPlaneShape(const btVector3& planeNormal, float planeConstant) int b3GpuNarrowPhase::registerPlaneShape(const b3Vector3& planeNormal, float planeConstant)
{ {
int collidableIndex = allocateCollidable(); int collidableIndex = allocateCollidable();
@@ -346,13 +346,13 @@ int b3GpuNarrowPhase::registerConvexHullShape(b3ConvexUtility* convexPtr,b3Colli
int b3GpuNarrowPhase::registerConvexHullShape(const float* vertices, int strideInBytes, int numVertices, const float* scaling) int b3GpuNarrowPhase::registerConvexHullShape(const float* vertices, int strideInBytes, int numVertices, const float* scaling)
{ {
btAlignedObjectArray<btVector3> verts; b3AlignedObjectArray<b3Vector3> verts;
unsigned char* vts = (unsigned char*) vertices; unsigned char* vts = (unsigned char*) vertices;
for (int i=0;i<numVertices;i++) for (int i=0;i<numVertices;i++)
{ {
float* vertex = (float*) &vts[i*strideInBytes]; float* vertex = (float*) &vts[i*strideInBytes];
verts.push_back(btVector3(vertex[0]*scaling[0],vertex[1]*scaling[1],vertex[2]*scaling[2])); verts.push_back(b3Vector3(vertex[0]*scaling[0],vertex[1]*scaling[1],vertex[2]*scaling[2]));
} }
b3ConvexUtility* utilPtr = new b3ConvexUtility(); b3ConvexUtility* utilPtr = new b3ConvexUtility();
@@ -375,7 +375,7 @@ int b3GpuNarrowPhase::registerConvexHullShape(b3ConvexUtility* utilPtr)
{ {
btVector3 localCenter(0,0,0); b3Vector3 localCenter(0,0,0);
for (int i=0;i<utilPtr->m_vertices.size();i++) for (int i=0;i<utilPtr->m_vertices.size();i++)
localCenter+=utilPtr->m_vertices[i]; localCenter+=utilPtr->m_vertices[i];
localCenter*= (1.f/utilPtr->m_vertices.size()); localCenter*= (1.f/utilPtr->m_vertices.size());
@@ -388,8 +388,8 @@ int b3GpuNarrowPhase::registerConvexHullShape(b3ConvexUtility* utilPtr)
{ {
b3SapAabb aabb; b3SapAabb aabb;
btVector3 myAabbMin(1e30f,1e30f,1e30f); b3Vector3 myAabbMin(1e30f,1e30f,1e30f);
btVector3 myAabbMax(-1e30f,-1e30f,-1e30f); b3Vector3 myAabbMax(-1e30f,-1e30f,-1e30f);
for (int i=0;i<utilPtr->m_vertices.size();i++) for (int i=0;i<utilPtr->m_vertices.size();i++)
{ {
@@ -414,7 +414,7 @@ int b3GpuNarrowPhase::registerConvexHullShape(b3ConvexUtility* utilPtr)
} }
int b3GpuNarrowPhase::registerCompoundShape(btAlignedObjectArray<btGpuChildShape>* childShapes) int b3GpuNarrowPhase::registerCompoundShape(b3AlignedObjectArray<btGpuChildShape>* childShapes)
{ {
int collidableIndex = allocateCollidable(); int collidableIndex = allocateCollidable();
@@ -438,8 +438,8 @@ int b3GpuNarrowPhase::registerCompoundShape(btAlignedObjectArray<btGpuChildShap
b3SapAabb aabbWS; b3SapAabb aabbWS;
btVector3 myAabbMin(1e30f,1e30f,1e30f); b3Vector3 myAabbMin(1e30f,1e30f,1e30f);
btVector3 myAabbMax(-1e30f,-1e30f,-1e30f); b3Vector3 myAabbMax(-1e30f,-1e30f,-1e30f);
//compute local AABB of the compound of all children //compute local AABB of the compound of all children
for (int i=0;i<childShapes->size();i++) for (int i=0;i<childShapes->size();i++)
@@ -448,17 +448,17 @@ int b3GpuNarrowPhase::registerCompoundShape(btAlignedObjectArray<btGpuChildShap
b3Collidable& childCol = getCollidableCpu(childColIndex); b3Collidable& childCol = getCollidableCpu(childColIndex);
b3SapAabb aabbLoc =m_data->m_localShapeAABBCPU->at(childColIndex); b3SapAabb aabbLoc =m_data->m_localShapeAABBCPU->at(childColIndex);
btVector3 childLocalAabbMin(aabbLoc.m_min[0],aabbLoc.m_min[1],aabbLoc.m_min[2]); b3Vector3 childLocalAabbMin(aabbLoc.m_min[0],aabbLoc.m_min[1],aabbLoc.m_min[2]);
btVector3 childLocalAabbMax(aabbLoc.m_max[0],aabbLoc.m_max[1],aabbLoc.m_max[2]); b3Vector3 childLocalAabbMax(aabbLoc.m_max[0],aabbLoc.m_max[1],aabbLoc.m_max[2]);
btVector3 aMin,aMax; b3Vector3 aMin,aMax;
btScalar margin(0.f); b3Scalar margin(0.f);
btTransform childTr; b3Transform childTr;
childTr.setIdentity(); childTr.setIdentity();
childTr.setOrigin(btVector3(childShapes->at(i).m_childPosition[0], childTr.setOrigin(b3Vector3(childShapes->at(i).m_childPosition[0],
childShapes->at(i).m_childPosition[1], childShapes->at(i).m_childPosition[1],
childShapes->at(i).m_childPosition[2])); childShapes->at(i).m_childPosition[2]));
childTr.setRotation(btQuaternion(childShapes->at(i).m_childOrientation[0], childTr.setRotation(b3Quaternion(childShapes->at(i).m_childOrientation[0],
childShapes->at(i).m_childOrientation[1], childShapes->at(i).m_childOrientation[1],
childShapes->at(i).m_childOrientation[2], childShapes->at(i).m_childOrientation[2],
childShapes->at(i).m_childOrientation[3])); childShapes->at(i).m_childOrientation[3]));
@@ -485,7 +485,7 @@ int b3GpuNarrowPhase::registerCompoundShape(btAlignedObjectArray<btGpuChildShap
} }
int b3GpuNarrowPhase::registerConcaveMesh(btAlignedObjectArray<btVector3>* vertices, btAlignedObjectArray<int>* indices,const float* scaling1) int b3GpuNarrowPhase::registerConcaveMesh(b3AlignedObjectArray<b3Vector3>* vertices, b3AlignedObjectArray<int>* indices,const float* scaling1)
{ {
//right now we only support one single mesh, it is on the todo to merge all mesh data etc //right now we only support one single mesh, it is on the todo to merge all mesh data etc
btAssert(m_data->m_treeNodesGPU ==0); btAssert(m_data->m_treeNodesGPU ==0);
@@ -496,7 +496,7 @@ int b3GpuNarrowPhase::registerConcaveMesh(btAlignedObjectArray<btVector3>* vert
exit (0); exit (0);
} }
btVector3 scaling(scaling1[0],scaling1[1],scaling1[2]); b3Vector3 scaling(scaling1[0],scaling1[1],scaling1[2]);
int collidableIndex = allocateCollidable(); int collidableIndex = allocateCollidable();
b3Collidable& col = getCollidableCpu(collidableIndex); b3Collidable& col = getCollidableCpu(collidableIndex);
@@ -507,12 +507,12 @@ int b3GpuNarrowPhase::registerConcaveMesh(btAlignedObjectArray<btVector3>* vert
b3SapAabb aabb; b3SapAabb aabb;
btVector3 myAabbMin(1e30f,1e30f,1e30f); b3Vector3 myAabbMin(1e30f,1e30f,1e30f);
btVector3 myAabbMax(-1e30f,-1e30f,-1e30f); b3Vector3 myAabbMax(-1e30f,-1e30f,-1e30f);
for (int i=0;i<vertices->size();i++) for (int i=0;i<vertices->size();i++)
{ {
btVector3 vtx(vertices->at(i)*scaling); b3Vector3 vtx(vertices->at(i)*scaling);
myAabbMin.setMin(vtx); myAabbMin.setMin(vtx);
myAabbMax.setMax(vtx); myAabbMax.setMax(vtx);
} }
@@ -530,7 +530,7 @@ int b3GpuNarrowPhase::registerConcaveMesh(btAlignedObjectArray<btVector3>* vert
m_data->m_localShapeAABBGPU->push_back(aabb); m_data->m_localShapeAABBGPU->push_back(aabb);
b3OptimizedBvh* bvh = new b3OptimizedBvh(); b3OptimizedBvh* bvh = new b3OptimizedBvh();
//void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantizedAabbCompression, const btVector3& bvhAabbMin, const btVector3& bvhAabbMax) //void b3OptimizedBvh::build(b3StridingMeshInterface* triangles, bool useQuantizedAabbCompression, const b3Vector3& bvhAabbMin, const b3Vector3& bvhAabbMax)
bool useQuantizedAabbCompression = true; bool useQuantizedAabbCompression = true;
b3TriangleIndexVertexArray* meshInterface=new b3TriangleIndexVertexArray(); b3TriangleIndexVertexArray* meshInterface=new b3TriangleIndexVertexArray();
@@ -538,12 +538,12 @@ int b3GpuNarrowPhase::registerConcaveMesh(btAlignedObjectArray<btVector3>* vert
mesh.m_numTriangles = indices->size()/3; mesh.m_numTriangles = indices->size()/3;
mesh.m_numVertices = vertices->size(); mesh.m_numVertices = vertices->size();
mesh.m_vertexBase = (const unsigned char *)&vertices->at(0).getX(); mesh.m_vertexBase = (const unsigned char *)&vertices->at(0).getX();
mesh.m_vertexStride = sizeof(btVector3); mesh.m_vertexStride = sizeof(b3Vector3);
mesh.m_triangleIndexStride = 3 * sizeof(int);// or sizeof(int) mesh.m_triangleIndexStride = 3 * sizeof(int);// or sizeof(int)
mesh.m_triangleIndexBase = (const unsigned char *)&indices->at(0); mesh.m_triangleIndexBase = (const unsigned char *)&indices->at(0);
meshInterface->addIndexedMesh(mesh); meshInterface->addIndexedMesh(mesh);
bvh->build(meshInterface, useQuantizedAabbCompression, (btVector3&)aabb.m_min, (btVector3&)aabb.m_max); bvh->build(meshInterface, useQuantizedAabbCompression, (b3Vector3&)aabb.m_min, (b3Vector3&)aabb.m_max);
m_data->m_bvhData.push_back(bvh); m_data->m_bvhData.push_back(bvh);
int numNodes = bvh->getQuantizedNodeArray().size(); int numNodes = bvh->getQuantizedNodeArray().size();
btOpenCLArray<btQuantizedBvhNode>* treeNodesGPU = new btOpenCLArray<btQuantizedBvhNode>(this->m_context,this->m_queue,numNodes); btOpenCLArray<btQuantizedBvhNode>* treeNodesGPU = new btOpenCLArray<btQuantizedBvhNode>(this->m_context,this->m_queue,numNodes);
@@ -560,21 +560,21 @@ int b3GpuNarrowPhase::registerConcaveMesh(btAlignedObjectArray<btVector3>* vert
return collidableIndex; return collidableIndex;
} }
int b3GpuNarrowPhase::registerConcaveMeshShape(btAlignedObjectArray<btVector3>* vertices, btAlignedObjectArray<int>* indices,b3Collidable& col, const float* scaling1) int b3GpuNarrowPhase::registerConcaveMeshShape(b3AlignedObjectArray<b3Vector3>* vertices, b3AlignedObjectArray<int>* indices,b3Collidable& col, const float* scaling1)
{ {
btVector3 scaling(scaling1[0],scaling1[1],scaling1[2]); b3Vector3 scaling(scaling1[0],scaling1[1],scaling1[2]);
m_data->m_convexData->resize(m_data->m_numAcceleratedShapes+1); m_data->m_convexData->resize(m_data->m_numAcceleratedShapes+1);
m_data->m_convexPolyhedra.resize(m_data->m_numAcceleratedShapes+1); m_data->m_convexPolyhedra.resize(m_data->m_numAcceleratedShapes+1);
b3ConvexPolyhedronCL& convex = m_data->m_convexPolyhedra.at(m_data->m_convexPolyhedra.size()-1); b3ConvexPolyhedronCL& convex = m_data->m_convexPolyhedra.at(m_data->m_convexPolyhedra.size()-1);
convex.mC = btVector3(0,0,0); convex.mC = b3Vector3(0,0,0);
convex.mE = btVector3(0,0,0); convex.mE = b3Vector3(0,0,0);
convex.m_extents= btVector3(0,0,0); convex.m_extents= b3Vector3(0,0,0);
convex.m_localCenter = btVector3(0,0,0); convex.m_localCenter = b3Vector3(0,0,0);
convex.m_radius = 0.f; convex.m_radius = 0.f;
convex.m_numUniqueEdges = 0; convex.m_numUniqueEdges = 0;
@@ -593,12 +593,12 @@ int b3GpuNarrowPhase::registerConcaveMeshShape(btAlignedObjectArray<btVector3>*
{ {
//printf("i=%d out of %d", i,convex.m_numFaces); //printf("i=%d out of %d", i,convex.m_numFaces);
} }
btVector3 vert0(vertices->at(indices->at(i*3))*scaling); b3Vector3 vert0(vertices->at(indices->at(i*3))*scaling);
btVector3 vert1(vertices->at(indices->at(i*3+1))*scaling); b3Vector3 vert1(vertices->at(indices->at(i*3+1))*scaling);
btVector3 vert2(vertices->at(indices->at(i*3+2))*scaling); b3Vector3 vert2(vertices->at(indices->at(i*3+2))*scaling);
btVector3 normal = ((vert1-vert0).cross(vert2-vert0)).normalize(); b3Vector3 normal = ((vert1-vert0).cross(vert2-vert0)).normalize();
btScalar c = -(normal.dot(vert0)); b3Scalar c = -(normal.dot(vert0));
m_data->m_convexFaces[convex.m_faceOffset+i].m_plane[0] = normal.getX(); m_data->m_convexFaces[convex.m_faceOffset+i].m_plane[0] = normal.getX();
m_data->m_convexFaces[convex.m_faceOffset+i].m_plane[1] = normal.getY(); m_data->m_convexFaces[convex.m_faceOffset+i].m_plane[1] = normal.getY();
@@ -753,8 +753,8 @@ const b3SapAabb& b3GpuNarrowPhase::getLocalSpaceAabb(int collidableIndex) const
int b3GpuNarrowPhase::registerRigidBody(int collidableIndex, float mass, const float* position, const float* orientation , const float* aabbMinPtr, const float* aabbMaxPtr,bool writeToGpu) int b3GpuNarrowPhase::registerRigidBody(int collidableIndex, float mass, const float* position, const float* orientation , const float* aabbMinPtr, const float* aabbMaxPtr,bool writeToGpu)
{ {
btVector3 aabbMin(aabbMinPtr[0],aabbMinPtr[1],aabbMinPtr[2]); b3Vector3 aabbMin(aabbMinPtr[0],aabbMinPtr[1],aabbMinPtr[2]);
btVector3 aabbMax (aabbMaxPtr[0],aabbMaxPtr[1],aabbMaxPtr[2]); b3Vector3 aabbMax (aabbMaxPtr[0],aabbMaxPtr[1],aabbMaxPtr[2]);
btAssert(m_data->m_numAcceleratedRigidBodies< (m_data->m_config.m_maxConvexBodies-1)); btAssert(m_data->m_numAcceleratedRigidBodies< (m_data->m_config.m_maxConvexBodies-1));
@@ -807,9 +807,9 @@ int b3GpuNarrowPhase::registerRigidBody(int collidableIndex, float mass, const f
//approximate using the aabb of the shape //approximate using the aabb of the shape
//Aabb aabb = (*m_data->m_shapePointers)[shapeIndex]->m_aabb; //Aabb aabb = (*m_data->m_shapePointers)[shapeIndex]->m_aabb;
btVector3 halfExtents = (aabbMax-aabbMin);//*0.5f;//fake larger inertia makes demos more stable ;-) b3Vector3 halfExtents = (aabbMax-aabbMin);//*0.5f;//fake larger inertia makes demos more stable ;-)
btVector3 localInertia; b3Vector3 localInertia;
float lx=2.f*halfExtents[0]; float lx=2.f*halfExtents[0];
float ly=2.f*halfExtents[1]; float ly=2.f*halfExtents[1];
@@ -819,7 +819,7 @@ int b3GpuNarrowPhase::registerRigidBody(int collidableIndex, float mass, const f
(mass/12.0f) * (lx*lx + lz*lz), (mass/12.0f) * (lx*lx + lz*lz),
(mass/12.0f) * (lx*lx + ly*ly)); (mass/12.0f) * (lx*lx + ly*ly));
btVector3 invLocalInertia; b3Vector3 invLocalInertia;
invLocalInertia[0] = 1.f/localInertia[0]; invLocalInertia[0] = 1.f/localInertia[0];
invLocalInertia[1] = 1.f/localInertia[1]; invLocalInertia[1] = 1.f/localInertia[1];
invLocalInertia[2] = 1.f/localInertia[2]; invLocalInertia[2] = 1.f/localInertia[2];
@@ -830,7 +830,7 @@ int b3GpuNarrowPhase::registerRigidBody(int collidableIndex, float mass, const f
0, invLocalInertia[1], 0, 0, invLocalInertia[1], 0,
0, 0, invLocalInertia[2]); 0, 0, invLocalInertia[2]);
btMatrix3x3 m (body.m_quat); b3Matrix3x3 m (body.m_quat);
shapeInfo.m_invInertiaWorld = m.scaled(invLocalInertia) * m.transpose(); shapeInfo.m_invInertiaWorld = m.scaled(invLocalInertia) * m.transpose();

View File

@@ -3,8 +3,8 @@
#include "../../gpu_narrowphase/host/b3Collidable.h" #include "../../gpu_narrowphase/host/b3Collidable.h"
#include "basic_initialize/b3OpenCLInclude.h" #include "basic_initialize/b3OpenCLInclude.h"
#include "BulletCommon/btAlignedObjectArray.h" #include "BulletCommon/b3AlignedObjectArray.h"
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
class b3GpuNarrowPhase class b3GpuNarrowPhase
{ {
@@ -20,7 +20,7 @@ protected:
cl_command_queue m_queue; cl_command_queue m_queue;
int registerConvexHullShape(class b3ConvexUtility* convexPtr, b3Collidable& col); int registerConvexHullShape(class b3ConvexUtility* convexPtr, b3Collidable& col);
int registerConcaveMeshShape(btAlignedObjectArray<btVector3>* vertices, btAlignedObjectArray<int>* indices, b3Collidable& col, const float* scaling); int registerConcaveMeshShape(b3AlignedObjectArray<b3Vector3>* vertices, b3AlignedObjectArray<int>* indices, b3Collidable& col, const float* scaling);
public: public:
@@ -32,12 +32,12 @@ public:
virtual ~b3GpuNarrowPhase(void); virtual ~b3GpuNarrowPhase(void);
int registerSphereShape(float radius); int registerSphereShape(float radius);
int registerPlaneShape(const btVector3& planeNormal, float planeConstant); int registerPlaneShape(const b3Vector3& planeNormal, float planeConstant);
int registerCompoundShape(btAlignedObjectArray<btGpuChildShape>* childShapes); int registerCompoundShape(b3AlignedObjectArray<btGpuChildShape>* childShapes);
int registerFace(const btVector3& faceNormal, float faceConstant); int registerFace(const b3Vector3& faceNormal, float faceConstant);
int registerConcaveMesh(btAlignedObjectArray<btVector3>* vertices, btAlignedObjectArray<int>* indices,const float* scaling); int registerConcaveMesh(b3AlignedObjectArray<b3Vector3>* vertices, b3AlignedObjectArray<int>* indices,const float* scaling);
//do they need to be merged? //do they need to be merged?

View File

@@ -20,7 +20,7 @@
#include "b3GpuBatchingPgsSolver.h" #include "b3GpuBatchingPgsSolver.h"
#include "b3Solver.h" #include "b3Solver.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "b3Config.h" #include "b3Config.h"
b3GpuRigidBodyPipeline::b3GpuRigidBodyPipeline(cl_context ctx,cl_device_id device, cl_command_queue q,class b3GpuNarrowPhase* narrowphase, class b3GpuSapBroadphase* broadphaseSap ) b3GpuRigidBodyPipeline::b3GpuRigidBodyPipeline(cl_context ctx,cl_device_id device, cl_command_queue q,class b3GpuNarrowPhase* narrowphase, class b3GpuSapBroadphase* broadphaseSap )
@@ -133,9 +133,9 @@ void b3GpuRigidBodyPipeline::stepSimulation(float deltaTime)
bool forceHost = false; bool forceHost = false;
if (forceHost) if (forceHost)
{ {
btAlignedObjectArray<b3RigidBodyCL> hostBodies; b3AlignedObjectArray<b3RigidBodyCL> hostBodies;
btAlignedObjectArray<btInertiaCL> hostInertias; b3AlignedObjectArray<btInertiaCL> hostInertias;
btAlignedObjectArray<b3Contact4> hostContacts; b3AlignedObjectArray<b3Contact4> hostContacts;
{ {
BT_PROFILE("copyToHost"); BT_PROFILE("copyToHost");
@@ -161,11 +161,11 @@ void b3GpuRigidBodyPipeline::stepSimulation(float deltaTime)
} }
} else } else
{ {
btAlignedObjectArray<b3RigidBodyCL> hostBodies; b3AlignedObjectArray<b3RigidBodyCL> hostBodies;
gpuBodies.copyToHost(hostBodies); gpuBodies.copyToHost(hostBodies);
btAlignedObjectArray<btInertiaCL> hostInertias; b3AlignedObjectArray<btInertiaCL> hostInertias;
gpuInertias.copyToHost(hostInertias); gpuInertias.copyToHost(hostInertias);
btAlignedObjectArray<b3Contact4> hostContacts; b3AlignedObjectArray<b3Contact4> hostContacts;
gpuContacts.copyToHost(hostContacts); gpuContacts.copyToHost(hostContacts);
{ {
m_data->m_solver->solveContacts(m_data->m_narrowphase->getNumBodiesGpu(),&hostBodies[0],&hostInertias[0],numContacts,&hostContacts[0]); m_data->m_solver->solveContacts(m_data->m_narrowphase->getNumBodiesGpu(),&hostBodies[0],&hostInertias[0],numContacts,&hostContacts[0]);
@@ -207,7 +207,7 @@ void b3GpuRigidBodyPipeline::integrate(float timeStep)
float angularDamp = 0.99f; float angularDamp = 0.99f;
launcher.setConst(angularDamp); launcher.setConst(angularDamp);
btVector3 gravity(0.f,-9.8f,0.f); b3Vector3 gravity(0.f,-9.8f,0.f);
launcher.setConst(gravity); launcher.setConst(gravity);
launcher.launch1D(numBodies); launcher.launch1D(numBodies);
@@ -256,18 +256,18 @@ int b3GpuRigidBodyPipeline::getNumBodies() const
int b3GpuRigidBodyPipeline::registerPhysicsInstance(float mass, const float* position, const float* orientation, int collidableIndex, int userIndex) int b3GpuRigidBodyPipeline::registerPhysicsInstance(float mass, const float* position, const float* orientation, int collidableIndex, int userIndex)
{ {
btVector3 aabbMin(0,0,0),aabbMax(0,0,0); b3Vector3 aabbMin(0,0,0),aabbMax(0,0,0);
if (collidableIndex>=0) if (collidableIndex>=0)
{ {
b3SapAabb localAabb = m_data->m_narrowphase->getLocalSpaceAabb(collidableIndex); b3SapAabb localAabb = m_data->m_narrowphase->getLocalSpaceAabb(collidableIndex);
btVector3 localAabbMin(localAabb.m_min[0],localAabb.m_min[1],localAabb.m_min[2]); b3Vector3 localAabbMin(localAabb.m_min[0],localAabb.m_min[1],localAabb.m_min[2]);
btVector3 localAabbMax(localAabb.m_max[0],localAabb.m_max[1],localAabb.m_max[2]); b3Vector3 localAabbMax(localAabb.m_max[0],localAabb.m_max[1],localAabb.m_max[2]);
btScalar margin = 0.01f; b3Scalar margin = 0.01f;
btTransform t; b3Transform t;
t.setIdentity(); t.setIdentity();
t.setOrigin(btVector3(position[0],position[1],position[2])); t.setOrigin(b3Vector3(position[0],position[1],position[2]));
t.setRotation(btQuaternion(orientation[0],orientation[1],orientation[2],orientation[3])); t.setRotation(b3Quaternion(orientation[0],orientation[1],orientation[2],orientation[3]));
btTransformAabb(localAabbMin,localAabbMax, margin,t,aabbMin,aabbMax); btTransformAabb(localAabbMin,localAabbMax, margin,t,aabbMin,aabbMax);
if (mass) if (mass)
{ {

View File

@@ -23,10 +23,10 @@ public:
//int registerConvexPolyhedron(const float* vertices, int strideInBytes, int numVertices, const float* scaling); //int registerConvexPolyhedron(const float* vertices, int strideInBytes, int numVertices, const float* scaling);
//int registerSphereShape(float radius); //int registerSphereShape(float radius);
//int registerPlaneShape(const btVector3& planeNormal, float planeConstant); //int registerPlaneShape(const b3Vector3& planeNormal, float planeConstant);
//int registerConcaveMesh(btAlignedObjectArray<btVector3>* vertices, btAlignedObjectArray<int>* indices, const float* scaling); //int registerConcaveMesh(b3AlignedObjectArray<b3Vector3>* vertices, b3AlignedObjectArray<int>* indices, const float* scaling);
//int registerCompoundShape(btAlignedObjectArray<btGpuChildShape>* childShapes); //int registerCompoundShape(b3AlignedObjectArray<btGpuChildShape>* childShapes);
int registerPhysicsInstance(float mass, const float* position, const float* orientation, int collisionShapeIndex, int userData); int registerPhysicsInstance(float mass, const float* position, const float* orientation, int collisionShapeIndex, int userData);

View File

@@ -2,7 +2,7 @@
#define BT_GPU_RIGIDBODY_PIPELINE_INTERNAL_DATA_H #define BT_GPU_RIGIDBODY_PIPELINE_INTERNAL_DATA_H
#include "../../basic_initialize/b3OpenCLInclude.h" #include "../../basic_initialize/b3OpenCLInclude.h"
#include "BulletCommon/btAlignedObjectArray.h" #include "BulletCommon/b3AlignedObjectArray.h"
#include "../../parallel_primitives/host/btOpenCLArray.h" #include "../../parallel_primitives/host/btOpenCLArray.h"
#include "../../gpu_narrowphase/host/b3Collidable.h" #include "../../gpu_narrowphase/host/b3Collidable.h"

View File

@@ -39,9 +39,9 @@ bool useNewBatchingKernel = false;
#include "../kernels/batchingKernelsNew.h" #include "../kernels/batchingKernelsNew.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "../../parallel_primitives/host/btLauncherCL.h" #include "../../parallel_primitives/host/btLauncherCL.h"
#include "BulletCommon/btVector3.h" #include "BulletCommon/b3Vector3.h"
struct SolverDebugInfo struct SolverDebugInfo
{ {
@@ -282,8 +282,8 @@ b3Solver::~b3Solver()
static static
inline inline
float calcRelVel(const btVector3& l0, const btVector3& l1, const btVector3& a0, const btVector3& a1, float calcRelVel(const b3Vector3& l0, const b3Vector3& l1, const b3Vector3& a0, const b3Vector3& a1,
const btVector3& linVel0, const btVector3& angVel0, const btVector3& linVel1, const btVector3& angVel1) const b3Vector3& linVel0, const b3Vector3& angVel0, const b3Vector3& linVel1, const b3Vector3& angVel1)
{ {
return btDot(l0, linVel0) + btDot(a0, angVel0) + btDot(l1, linVel1) + btDot(a1, angVel1); return btDot(l0, linVel0) + btDot(a0, angVel0) + btDot(l1, linVel1) + btDot(a1, angVel1);
} }
@@ -291,8 +291,8 @@ b3Solver::~b3Solver()
static static
inline inline
void setLinearAndAngular(const btVector3& n, const btVector3& r0, const btVector3& r1, void setLinearAndAngular(const b3Vector3& n, const b3Vector3& r0, const b3Vector3& r1,
btVector3& linear, btVector3& angular0, btVector3& angular1) b3Vector3& linear, b3Vector3& angular0, b3Vector3& angular1)
{ {
linear = -n; linear = -n;
angular0 = -btCross(r0, n); angular0 = -btCross(r0, n);
@@ -304,15 +304,15 @@ template<bool JACOBI>
static static
__inline __inline
void solveContact(b3GpuConstraint4& cs, void solveContact(b3GpuConstraint4& cs,
const btVector3& posA, btVector3& linVelA, btVector3& angVelA, float invMassA, const btMatrix3x3& invInertiaA, const b3Vector3& posA, b3Vector3& linVelA, b3Vector3& angVelA, float invMassA, const b3Matrix3x3& invInertiaA,
const btVector3& posB, btVector3& linVelB, btVector3& angVelB, float invMassB, const btMatrix3x3& invInertiaB, const b3Vector3& posB, b3Vector3& linVelB, b3Vector3& angVelB, float invMassB, const b3Matrix3x3& invInertiaB,
float maxRambdaDt[4], float minRambdaDt[4]) float maxRambdaDt[4], float minRambdaDt[4])
{ {
btVector3 dLinVelA; dLinVelA.setZero(); b3Vector3 dLinVelA; dLinVelA.setZero();
btVector3 dAngVelA; dAngVelA.setZero(); b3Vector3 dAngVelA; dAngVelA.setZero();
btVector3 dLinVelB; dLinVelB.setZero(); b3Vector3 dLinVelB; dLinVelB.setZero();
btVector3 dAngVelB; dAngVelB.setZero(); b3Vector3 dAngVelB; dAngVelB.setZero();
for(int ic=0; ic<4; ic++) for(int ic=0; ic<4; ic++)
{ {
@@ -320,12 +320,12 @@ void solveContact(b3GpuConstraint4& cs,
if( cs.m_jacCoeffInv[ic] == 0.f ) continue; if( cs.m_jacCoeffInv[ic] == 0.f ) continue;
{ {
btVector3 angular0, angular1, linear; b3Vector3 angular0, angular1, linear;
btVector3 r0 = cs.m_worldPos[ic] - (btVector3&)posA; b3Vector3 r0 = cs.m_worldPos[ic] - (b3Vector3&)posA;
btVector3 r1 = cs.m_worldPos[ic] - (btVector3&)posB; b3Vector3 r1 = cs.m_worldPos[ic] - (b3Vector3&)posB;
setLinearAndAngular( (const btVector3 &)-cs.m_linear, (const btVector3 &)r0, (const btVector3 &)r1, linear, angular0, angular1 ); setLinearAndAngular( (const b3Vector3 &)-cs.m_linear, (const b3Vector3 &)r0, (const b3Vector3 &)r1, linear, angular0, angular1 );
float rambdaDt = calcRelVel((const btVector3 &)cs.m_linear,(const btVector3 &) -cs.m_linear, angular0, angular1, float rambdaDt = calcRelVel((const b3Vector3 &)cs.m_linear,(const b3Vector3 &) -cs.m_linear, angular0, angular1,
linVelA, angVelA, linVelB, angVelB ) + cs.m_b[ic]; linVelA, angVelA, linVelB, angVelB ) + cs.m_b[ic];
rambdaDt *= cs.m_jacCoeffInv[ic]; rambdaDt *= cs.m_jacCoeffInv[ic];
@@ -339,10 +339,10 @@ void solveContact(b3GpuConstraint4& cs,
cs.m_appliedRambdaDt[ic] = updated; cs.m_appliedRambdaDt[ic] = updated;
} }
btVector3 linImp0 = invMassA*linear*rambdaDt; b3Vector3 linImp0 = invMassA*linear*rambdaDt;
btVector3 linImp1 = invMassB*(-linear)*rambdaDt; b3Vector3 linImp1 = invMassB*(-linear)*rambdaDt;
btVector3 angImp0 = (invInertiaA* angular0)*rambdaDt; b3Vector3 angImp0 = (invInertiaA* angular0)*rambdaDt;
btVector3 angImp1 = (invInertiaB* angular1)*rambdaDt; b3Vector3 angImp1 = (invInertiaB* angular1)*rambdaDt;
#ifdef _WIN32 #ifdef _WIN32
btAssert(_finite(linImp0.getX())); btAssert(_finite(linImp0.getX()));
btAssert(_finite(linImp1.getX())); btAssert(_finite(linImp1.getX()));
@@ -381,30 +381,30 @@ void solveContact(b3GpuConstraint4& cs,
static static
__inline __inline
void solveFriction(b3GpuConstraint4& cs, void solveFriction(b3GpuConstraint4& cs,
const btVector3& posA, btVector3& linVelA, btVector3& angVelA, float invMassA, const btMatrix3x3& invInertiaA, const b3Vector3& posA, b3Vector3& linVelA, b3Vector3& angVelA, float invMassA, const b3Matrix3x3& invInertiaA,
const btVector3& posB, btVector3& linVelB, btVector3& angVelB, float invMassB, const btMatrix3x3& invInertiaB, const b3Vector3& posB, b3Vector3& linVelB, b3Vector3& angVelB, float invMassB, const b3Matrix3x3& invInertiaB,
float maxRambdaDt[4], float minRambdaDt[4]) float maxRambdaDt[4], float minRambdaDt[4])
{ {
if( cs.m_fJacCoeffInv[0] == 0 && cs.m_fJacCoeffInv[0] == 0 ) return; if( cs.m_fJacCoeffInv[0] == 0 && cs.m_fJacCoeffInv[0] == 0 ) return;
const btVector3& center = (const btVector3&)cs.m_center; const b3Vector3& center = (const b3Vector3&)cs.m_center;
btVector3 n = -(const btVector3&)cs.m_linear; b3Vector3 n = -(const b3Vector3&)cs.m_linear;
btVector3 tangent[2]; b3Vector3 tangent[2];
#if 1 #if 1
btPlaneSpace1 (n, tangent[0],tangent[1]); btPlaneSpace1 (n, tangent[0],tangent[1]);
#else #else
btVector3 r = cs.m_worldPos[0]-center; b3Vector3 r = cs.m_worldPos[0]-center;
tangent[0] = cross3( n, r ); tangent[0] = cross3( n, r );
tangent[1] = cross3( tangent[0], n ); tangent[1] = cross3( tangent[0], n );
tangent[0] = normalize3( tangent[0] ); tangent[0] = normalize3( tangent[0] );
tangent[1] = normalize3( tangent[1] ); tangent[1] = normalize3( tangent[1] );
#endif #endif
btVector3 angular0, angular1, linear; b3Vector3 angular0, angular1, linear;
btVector3 r0 = center - posA; b3Vector3 r0 = center - posA;
btVector3 r1 = center - posB; b3Vector3 r1 = center - posB;
for(int i=0; i<2; i++) for(int i=0; i<2; i++)
{ {
setLinearAndAngular( tangent[i], r0, r1, linear, angular0, angular1 ); setLinearAndAngular( tangent[i], r0, r1, linear, angular0, angular1 );
@@ -422,10 +422,10 @@ void solveContact(b3GpuConstraint4& cs,
cs.m_fAppliedRambdaDt[i] = updated; cs.m_fAppliedRambdaDt[i] = updated;
} }
btVector3 linImp0 = invMassA*linear*rambdaDt; b3Vector3 linImp0 = invMassA*linear*rambdaDt;
btVector3 linImp1 = invMassB*(-linear)*rambdaDt; b3Vector3 linImp1 = invMassB*(-linear)*rambdaDt;
btVector3 angImp0 = (invInertiaA* angular0)*rambdaDt; b3Vector3 angImp0 = (invInertiaA* angular0)*rambdaDt;
btVector3 angImp1 = (invInertiaB* angular1)*rambdaDt; b3Vector3 angImp1 = (invInertiaB* angular1)*rambdaDt;
#ifdef _WIN32 #ifdef _WIN32
btAssert(_finite(linImp0.getX())); btAssert(_finite(linImp0.getX()));
btAssert(_finite(linImp1.getX())); btAssert(_finite(linImp1.getX()));
@@ -437,8 +437,8 @@ void solveContact(b3GpuConstraint4& cs,
} }
{ // angular damping for point constraint { // angular damping for point constraint
btVector3 ab = ( posB - posA ).normalized(); b3Vector3 ab = ( posB - posA ).normalized();
btVector3 ac = ( center - posA ).normalized(); b3Vector3 ac = ( center - posA ).normalized();
if( btDot( ab, ac ) > 0.95f || (invMassA == 0.f || invMassB == 0.f)) if( btDot( ab, ac ) > 0.95f || (invMassA == 0.f || invMassB == 0.f))
{ {
float angNA = btDot( n, angVelA ); float angNA = btDot( n, angVelA );
@@ -454,7 +454,7 @@ void solveContact(b3GpuConstraint4& cs,
struct SolveTask// : public ThreadPool::Task struct SolveTask// : public ThreadPool::Task
{ {
SolveTask(btAlignedObjectArray<b3RigidBodyCL>& bodies, btAlignedObjectArray<btInertiaCL>& shapes, btAlignedObjectArray<b3GpuConstraint4>& constraints, SolveTask(b3AlignedObjectArray<b3RigidBodyCL>& bodies, b3AlignedObjectArray<btInertiaCL>& shapes, b3AlignedObjectArray<b3GpuConstraint4>& constraints,
int start, int nConstraints) int start, int nConstraints)
: m_bodies( bodies ), m_shapes( shapes ), m_constraints( constraints ), m_start( start ), m_nConstraints( nConstraints ), : m_bodies( bodies ), m_shapes( shapes ), m_constraints( constraints ), m_start( start ), m_nConstraints( nConstraints ),
m_solveFriction( true ){} m_solveFriction( true ){}
@@ -480,8 +480,8 @@ struct SolveTask// : public ThreadPool::Task
float maxRambdaDt[4] = {FLT_MAX,FLT_MAX,FLT_MAX,FLT_MAX}; float maxRambdaDt[4] = {FLT_MAX,FLT_MAX,FLT_MAX,FLT_MAX};
float minRambdaDt[4] = {0.f,0.f,0.f,0.f}; float minRambdaDt[4] = {0.f,0.f,0.f,0.f};
solveContact<false>( m_constraints[i], (btVector3&)bodyA.m_pos, (btVector3&)bodyA.m_linVel, (btVector3&)bodyA.m_angVel, bodyA.m_invMass, (const btMatrix3x3 &)m_shapes[aIdx].m_invInertiaWorld, solveContact<false>( m_constraints[i], (b3Vector3&)bodyA.m_pos, (b3Vector3&)bodyA.m_linVel, (b3Vector3&)bodyA.m_angVel, bodyA.m_invMass, (const b3Matrix3x3 &)m_shapes[aIdx].m_invInertiaWorld,
(btVector3&)bodyB.m_pos, (btVector3&)bodyB.m_linVel, (btVector3&)bodyB.m_angVel, bodyB.m_invMass, (const btMatrix3x3 &)m_shapes[bIdx].m_invInertiaWorld, (b3Vector3&)bodyB.m_pos, (b3Vector3&)bodyB.m_linVel, (b3Vector3&)bodyB.m_angVel, bodyB.m_invMass, (const b3Matrix3x3 &)m_shapes[bIdx].m_invInertiaWorld,
maxRambdaDt, minRambdaDt ); maxRambdaDt, minRambdaDt );
} }
@@ -502,8 +502,8 @@ struct SolveTask// : public ThreadPool::Task
minRambdaDt[j] = -maxRambdaDt[j]; minRambdaDt[j] = -maxRambdaDt[j];
} }
solveFriction( m_constraints[i], (btVector3&)bodyA.m_pos, (btVector3&)bodyA.m_linVel, (btVector3&)bodyA.m_angVel, bodyA.m_invMass,(const btMatrix3x3 &) m_shapes[aIdx].m_invInertiaWorld, solveFriction( m_constraints[i], (b3Vector3&)bodyA.m_pos, (b3Vector3&)bodyA.m_linVel, (b3Vector3&)bodyA.m_angVel, bodyA.m_invMass,(const b3Matrix3x3 &) m_shapes[aIdx].m_invInertiaWorld,
(btVector3&)bodyB.m_pos, (btVector3&)bodyB.m_linVel, (btVector3&)bodyB.m_angVel, bodyB.m_invMass,(const btMatrix3x3 &) m_shapes[bIdx].m_invInertiaWorld, (b3Vector3&)bodyB.m_pos, (b3Vector3&)bodyB.m_linVel, (b3Vector3&)bodyB.m_angVel, bodyB.m_invMass,(const b3Matrix3x3 &) m_shapes[bIdx].m_invInertiaWorld,
maxRambdaDt, minRambdaDt ); maxRambdaDt, minRambdaDt );
} }
@@ -512,9 +512,9 @@ struct SolveTask// : public ThreadPool::Task
} }
btAlignedObjectArray<b3RigidBodyCL>& m_bodies; b3AlignedObjectArray<b3RigidBodyCL>& m_bodies;
btAlignedObjectArray<btInertiaCL>& m_shapes; b3AlignedObjectArray<btInertiaCL>& m_shapes;
btAlignedObjectArray<b3GpuConstraint4>& m_constraints; b3AlignedObjectArray<b3GpuConstraint4>& m_constraints;
int m_start; int m_start;
int m_nConstraints; int m_nConstraints;
bool m_solveFriction; bool m_solveFriction;
@@ -525,11 +525,11 @@ void b3Solver::solveContactConstraintHost( btOpenCLArray<b3RigidBodyCL>* bodyBu
btOpenCLArray<b3GpuConstraint4>* constraint, void* additionalData, int n ,int maxNumBatches) btOpenCLArray<b3GpuConstraint4>* constraint, void* additionalData, int n ,int maxNumBatches)
{ {
btAlignedObjectArray<b3RigidBodyCL> bodyNative; b3AlignedObjectArray<b3RigidBodyCL> bodyNative;
bodyBuf->copyToHost(bodyNative); bodyBuf->copyToHost(bodyNative);
btAlignedObjectArray<btInertiaCL> shapeNative; b3AlignedObjectArray<btInertiaCL> shapeNative;
shapeBuf->copyToHost(shapeNative); shapeBuf->copyToHost(shapeNative);
btAlignedObjectArray<b3GpuConstraint4> constraintNative; b3AlignedObjectArray<b3GpuConstraint4> constraintNative;
constraint->copyToHost(constraintNative); constraint->copyToHost(constraintNative);
for(int iter=0; iter<m_nIterations; iter++) for(int iter=0; iter<m_nIterations; iter++)

View File

@@ -19,9 +19,9 @@
#include "b3OpenCLUtils.h" #include "b3OpenCLUtils.h"
#include "../parallel_primitives/host/btOpenCLArray.h" #include "../parallel_primitives/host/btOpenCLArray.h"
#include "../parallel_primitives/host/btLauncherCL.h" #include "../parallel_primitives/host/btLauncherCL.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
#include "../parallel_primitives/host/btFillCL.h" #include "../parallel_primitives/host/btFillCL.h"
#include "BulletCommon/CommandLineArgs.h" #include "BulletCommon/b3CommandLineArgs.h"
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@@ -86,7 +86,7 @@ char* loadProgSource(const char* cFilename, const char* cPreamble, size_t* szFin
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
printf("Use --deviceId=<id> or --platformId=<id> to override OpenCL device\n"); printf("Use --deviceId=<id> or --platformId=<id> to override OpenCL device\n");
CommandLineArgs args(argc,argv); b3CommandLineArgs args(argc,argv);
const int nx = 1024; const int nx = 1024;
const int ny = 1024; const int ny = 1024;

View File

@@ -27,11 +27,11 @@ function createProject (vendor)
"main.cpp", "main.cpp",
"../basic_initialize/b3OpenCLUtils.cpp", "../basic_initialize/b3OpenCLUtils.cpp",
"../basic_initialize/b3OpenCLUtils.h", "../basic_initialize/b3OpenCLUtils.h",
"../../src/BulletCommon/btAlignedAllocator.cpp", "../../src/BulletCommon/b3AlignedAllocator.cpp",
"../../src/BulletCommon/btAlignedAllocator.h", "../../src/BulletCommon/b3AlignedAllocator.h",
"../../src/BulletCommon/btAlignedObjectArray.h", "../../src/BulletCommon/b3AlignedObjectArray.h",
"../../src/BulletCommon/btQuickprof.cpp", "../../src/BulletCommon/b3Quickprof.cpp",
"../../src/BulletCommon/btQuickprof.h", "../../src/BulletCommon/b3Quickprof.h",
} }
end end

View File

@@ -24,11 +24,11 @@ function createProject(vendor)
"../host/btFillCL.cpp", "../host/btFillCL.cpp",
"../host/btPrefixScanCL.cpp", "../host/btPrefixScanCL.cpp",
"../host/btRadixSort32CL.cpp", "../host/btRadixSort32CL.cpp",
"../../../src/BulletCommon/btAlignedAllocator.cpp", "../../../src/BulletCommon/b3AlignedAllocator.cpp",
"../../../src/BulletCommon/btAlignedAllocator.h", "../../../src/BulletCommon/b3AlignedAllocator.h",
"../../../src/BulletCommon/btAlignedObjectArray.h", "../../../src/BulletCommon/b3AlignedObjectArray.h",
"../../../src/BulletCommon/btQuickprof.cpp", "../../../src/BulletCommon/b3Quickprof.cpp",
"../../../src/BulletCommon/btQuickprof.h", "../../../src/BulletCommon/b3Quickprof.h",
} }
end end

View File

@@ -66,7 +66,7 @@
#include "../host/btRadixSort32CL.h" #include "../host/btRadixSort32CL.h"
#include "../../basic_initialize/b3OpenCLUtils.h" #include "../../basic_initialize/b3OpenCLUtils.h"
#include "BulletCommon/btQuickprof.h" #include "BulletCommon/b3Quickprof.h"
cl_context g_cxMainContext; cl_context g_cxMainContext;
cl_device_id g_device; cl_device_id g_device;
@@ -112,7 +112,7 @@ void TimedSort(
printf("Keys only, %d iterations, %d elements\n", iterations, num_elements); printf("Keys only, %d iterations, %d elements\n", iterations, num_elements);
int max_elements = num_elements; int max_elements = num_elements;
btAlignedObjectArray<unsigned int> hostData; b3AlignedObjectArray<unsigned int> hostData;
hostData.resize(num_elements); hostData.resize(num_elements);
for (int i=0;i<num_elements;i++) for (int i=0;i<num_elements;i++)
{ {
@@ -126,7 +126,7 @@ void TimedSort(
//sorter.executeHost(gpuData); //sorter.executeHost(gpuData);
sorter.execute(gpuData); sorter.execute(gpuData);
btAlignedObjectArray<unsigned int> hostDataSorted; b3AlignedObjectArray<unsigned int> hostDataSorted;
gpuData.copyToHost(hostDataSorted); gpuData.copyToHost(hostDataSorted);
clFinish(g_cqCommandQueue); clFinish(g_cqCommandQueue);
@@ -218,7 +218,7 @@ void TimedSort(
printf("Key-values, %d iterations, %d elements\n", iterations, num_elements); printf("Key-values, %d iterations, %d elements\n", iterations, num_elements);
int max_elements = num_elements; int max_elements = num_elements;
btAlignedObjectArray<btSortData> hostData; b3AlignedObjectArray<btSortData> hostData;
hostData.resize(num_elements); hostData.resize(num_elements);
for (int i=0;i<num_elements;i++) for (int i=0;i<num_elements;i++)
{ {
@@ -233,7 +233,7 @@ void TimedSort(
//sorter.executeHost(gpuData); //sorter.executeHost(gpuData);
sorter.execute(gpuData); sorter.execute(gpuData);
btAlignedObjectArray<btSortData> hostDataSorted; b3AlignedObjectArray<btSortData> hostDataSorted;
gpuData.copyToHost(hostDataSorted); gpuData.copyToHost(hostDataSorted);
#if 0 #if 0
for (int i=0;i<num_elements;i++) for (int i=0;i<num_elements;i++)
@@ -549,7 +549,7 @@ void Usage()
#include <algorithm> #include <algorithm>
#include <string> #include <string>
class CommandLineArgs class b3CommandLineArgs
{ {
protected: protected:
@@ -558,7 +558,7 @@ protected:
public: public:
// Constructor // Constructor
CommandLineArgs(int argc, char **argv) b3CommandLineArgs(int argc, char **argv)
{ {
using namespace std; using namespace std;
@@ -603,7 +603,7 @@ public:
}; };
template <typename T> template <typename T>
void CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val) void b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val)
{ {
using namespace std; using namespace std;
map<string, string>::iterator itr; map<string, string>::iterator itr;
@@ -614,7 +614,7 @@ void CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val)
} }
template <> template <>
void CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &val) void b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &val)
{ {
using namespace std; using namespace std;
map<string, string>::iterator itr; map<string, string>::iterator itr;
@@ -644,7 +644,7 @@ int main( int argc, char** argv)
gDebugSkipLoadingBinary = true; gDebugSkipLoadingBinary = true;
cl_int ciErrNum; cl_int ciErrNum;
CommandLineArgs args(argc,argv); b3CommandLineArgs args(argc,argv);
args.GetCmdLineArgument("deviceId", gPreferredDeviceId); args.GetCmdLineArgument("deviceId", gPreferredDeviceId);
args.GetCmdLineArgument("platformId", gPreferredPlatformId); args.GetCmdLineArgument("platformId", gPreferredPlatformId);

View File

@@ -138,8 +138,8 @@ void btBoundSearchCL::execute(btOpenCLArray<btSortData>& src, int nSrc, btOpenCL
} }
void btBoundSearchCL::executeHost( btAlignedObjectArray<btSortData>& src, int nSrc, void btBoundSearchCL::executeHost( b3AlignedObjectArray<btSortData>& src, int nSrc,
btAlignedObjectArray<unsigned int>& dst, int nDst, Option option ) b3AlignedObjectArray<unsigned int>& dst, int nDst, Option option )
{ {
@@ -188,9 +188,9 @@ void btBoundSearchCL::executeHost( btAlignedObjectArray<btSortData>& src, int nS
} }
else if( option == COUNT ) else if( option == COUNT )
{ {
btAlignedObjectArray<unsigned int> lower; b3AlignedObjectArray<unsigned int> lower;
lower.resize(nDst ); lower.resize(nDst );
btAlignedObjectArray<unsigned int> upper; b3AlignedObjectArray<unsigned int> upper;
upper.resize(nDst ); upper.resize(nDst );
for(int i=0; i<nDst; i++) for(int i=0; i<nDst; i++)

View File

@@ -60,7 +60,7 @@ class btBoundSearchCL
// src has to be src[i].m_key <= src[i+1].m_key // src has to be src[i].m_key <= src[i+1].m_key
void execute( btOpenCLArray<btSortData>& src, int nSrc, btOpenCLArray<unsigned int>& dst, int nDst, Option option = BOUND_LOWER ); void execute( btOpenCLArray<btSortData>& src, int nSrc, btOpenCLArray<unsigned int>& dst, int nDst, Option option = BOUND_LOWER );
void executeHost( btAlignedObjectArray<btSortData>& src, int nSrc, btAlignedObjectArray<unsigned int>& dst, int nDst, Option option = BOUND_LOWER); void executeHost( b3AlignedObjectArray<btSortData>& src, int nSrc, b3AlignedObjectArray<unsigned int>& dst, int nDst, Option option = BOUND_LOWER);
}; };

View File

@@ -90,7 +90,7 @@ void btFillCL::execute(btOpenCLArray<unsigned int>& src, const unsigned int valu
} }
} }
void btFillCL::executeHost(btAlignedObjectArray<btInt2> &src, const btInt2 &value, int n, int offset) void btFillCL::executeHost(b3AlignedObjectArray<btInt2> &src, const btInt2 &value, int n, int offset)
{ {
for (int i=0;i<n;i++) for (int i=0;i<n;i++)
{ {
@@ -98,7 +98,7 @@ void btFillCL::executeHost(btAlignedObjectArray<btInt2> &src, const btInt2 &valu
} }
} }
void btFillCL::executeHost(btAlignedObjectArray<int> &src, const int value, int n, int offset) void btFillCL::executeHost(b3AlignedObjectArray<int> &src, const int value, int n, int offset)
{ {
for (int i=0;i<n;i++) for (int i=0;i<n;i++)
{ {

View File

@@ -2,7 +2,7 @@
#define BT_FILL_CL_H #define BT_FILL_CL_H
#include "btOpenCLArray.h" #include "btOpenCLArray.h"
#include "BulletCommon/btScalar.h" #include "BulletCommon/b3Scalar.h"
#include "btInt2.h" #include "btInt2.h"
#include "btInt4.h" #include "btInt4.h"
@@ -48,9 +48,9 @@ public:
void execute(btOpenCLArray<btInt2>& src, const btInt2& value, int n, int offset = 0); void execute(btOpenCLArray<btInt2>& src, const btInt2& value, int n, int offset = 0);
void executeHost(btAlignedObjectArray<btInt2> &src, const btInt2 &value, int n, int offset); void executeHost(b3AlignedObjectArray<btInt2> &src, const btInt2 &value, int n, int offset);
void executeHost(btAlignedObjectArray<int> &src, const int value, int n, int offset); void executeHost(b3AlignedObjectArray<int> &src, const int value, int n, int offset);
// void execute(btOpenCLArray<btInt4>& src, const btInt4& value, int n, int offset = 0); // void execute(btOpenCLArray<btInt4>& src, const btInt4& value, int n, int offset = 0);

View File

@@ -1,7 +1,7 @@
#ifndef BT_INT4_H #ifndef BT_INT4_H
#define BT_INT4_H #define BT_INT4_H
#include "BulletCommon/btScalar.h" #include "BulletCommon/b3Scalar.h"
ATTRIBUTE_ALIGNED16(struct) btUnsignedInt4 ATTRIBUTE_ALIGNED16(struct) btUnsignedInt4
{ {

View File

@@ -3,7 +3,7 @@
#define BT_LAUNCHER_CL_H #define BT_LAUNCHER_CL_H
#include "btBufferInfoCL.h" #include "btBufferInfoCL.h"
#include "BulletCommon/btMinMax.h" #include "BulletCommon/b3MinMax.h"
#include "btOpenCLArray.h" #include "btOpenCLArray.h"
#include <stdio.h> #include <stdio.h>
@@ -31,14 +31,14 @@ class btLauncherCL
cl_kernel m_kernel; cl_kernel m_kernel;
int m_idx; int m_idx;
btAlignedObjectArray<btKernelArgData> m_kernelArguments; b3AlignedObjectArray<btKernelArgData> m_kernelArguments;
int m_serializationSizeInBytes; int m_serializationSizeInBytes;
public: public:
btAlignedObjectArray<btOpenCLArray<unsigned char>* > m_arrays; b3AlignedObjectArray<btOpenCLArray<unsigned char>* > m_arrays;
btLauncherCL(cl_command_queue queue, cl_kernel kernel) btLauncherCL(cl_command_queue queue, cl_kernel kernel)
:m_commandQueue(queue), :m_commandQueue(queue),

View File

@@ -1,7 +1,7 @@
#ifndef BT_OPENCL_ARRAY_H #ifndef BT_OPENCL_ARRAY_H
#define BT_OPENCL_ARRAY_H #define BT_OPENCL_ARRAY_H
#include "BulletCommon/btAlignedObjectArray.h" #include "BulletCommon/b3AlignedObjectArray.h"
#include "../../basic_initialize/b3OpenCLInclude.h" #include "../../basic_initialize/b3OpenCLInclude.h"
template <typename T> template <typename T>
@@ -61,7 +61,7 @@ public:
} }
// we could enable this assignment, but need to make sure to avoid accidental deep copies // we could enable this assignment, but need to make sure to avoid accidental deep copies
// btOpenCLArray<T>& operator=(const btAlignedObjectArray<T>& src) // btOpenCLArray<T>& operator=(const b3AlignedObjectArray<T>& src)
// { // {
// copyFromArray(src); // copyFromArray(src);
// return *this; // return *this;
@@ -212,7 +212,7 @@ public:
btAssert( status == CL_SUCCESS ); btAssert( status == CL_SUCCESS );
} }
void copyFromHost(const btAlignedObjectArray<T>& srcArray, bool waitForCompletion=true) void copyFromHost(const b3AlignedObjectArray<T>& srcArray, bool waitForCompletion=true)
{ {
int newSize = srcArray.size(); int newSize = srcArray.size();
@@ -238,7 +238,7 @@ public:
} }
void copyToHost(btAlignedObjectArray<T>& destArray, bool waitForCompletion=true) const void copyToHost(b3AlignedObjectArray<T>& destArray, bool waitForCompletion=true) const
{ {
destArray.resize(this->size()); destArray.resize(this->size());
if (size()) if (size())

View File

@@ -98,7 +98,7 @@ void btPrefixScanCL::execute(btOpenCLArray<unsigned int>& src, btOpenCLArray<uns
} }
void btPrefixScanCL::executeHost(btAlignedObjectArray<unsigned int>& src, btAlignedObjectArray<unsigned int>& dst, int n, unsigned int* sum) void btPrefixScanCL::executeHost(b3AlignedObjectArray<unsigned int>& src, b3AlignedObjectArray<unsigned int>& dst, int n, unsigned int* sum)
{ {
unsigned int s = 0; unsigned int s = 0;
//if( data->m_option == EXCLUSIVE ) //if( data->m_option == EXCLUSIVE )

View File

@@ -4,7 +4,7 @@
#include "btOpenCLArray.h" #include "btOpenCLArray.h"
#include "btBufferInfoCL.h" #include "btBufferInfoCL.h"
#include "BulletCommon/btAlignedObjectArray.h" #include "BulletCommon/b3AlignedObjectArray.h"
class btPrefixScanCL class btPrefixScanCL
{ {
@@ -31,7 +31,7 @@ class btPrefixScanCL
virtual ~btPrefixScanCL(); virtual ~btPrefixScanCL();
void execute(btOpenCLArray<unsigned int>& src, btOpenCLArray<unsigned int>& dst, int n, unsigned int* sum = 0); void execute(btOpenCLArray<unsigned int>& src, btOpenCLArray<unsigned int>& dst, int n, unsigned int* sum = 0);
void executeHost(btAlignedObjectArray<unsigned int>& src, btAlignedObjectArray<unsigned int>& dst, int n, unsigned int* sum); void executeHost(b3AlignedObjectArray<unsigned int>& src, b3AlignedObjectArray<unsigned int>& dst, int n, unsigned int* sum);
}; };
#endif //BT_PREFIX_SCAN_CL_H #endif //BT_PREFIX_SCAN_CL_H

View File

@@ -93,7 +93,7 @@ btRadixSort32CL::~btRadixSort32CL()
clReleaseKernel(m_prefixScanKernel); clReleaseKernel(m_prefixScanKernel);
} }
void btRadixSort32CL::executeHost(btAlignedObjectArray<btSortData>& inout, int sortBits /* = 32 */) void btRadixSort32CL::executeHost(b3AlignedObjectArray<btSortData>& inout, int sortBits /* = 32 */)
{ {
int n = inout.size(); int n = inout.size();
const int BITS_PER_PASS = 8; const int BITS_PER_PASS = 8;
@@ -104,7 +104,7 @@ void btRadixSort32CL::executeHost(btAlignedObjectArray<btSortData>& inout, int s
int counter[NUM_TABLES]; int counter[NUM_TABLES];
btSortData* src = &inout[0]; btSortData* src = &inout[0];
btAlignedObjectArray<btSortData> workbuffer; b3AlignedObjectArray<btSortData> workbuffer;
workbuffer.resize(inout.size()); workbuffer.resize(inout.size());
btSortData* dst = &workbuffer[0]; btSortData* dst = &workbuffer[0];
@@ -166,7 +166,7 @@ void btRadixSort32CL::executeHost(btAlignedObjectArray<btSortData>& inout, int s
void btRadixSort32CL::executeHost(btOpenCLArray<btSortData>& keyValuesInOut, int sortBits /* = 32 */) void btRadixSort32CL::executeHost(btOpenCLArray<btSortData>& keyValuesInOut, int sortBits /* = 32 */)
{ {
btAlignedObjectArray<btSortData> inout; b3AlignedObjectArray<btSortData> inout;
keyValuesInOut.copyToHost(inout); keyValuesInOut.copyToHost(inout);
executeHost(inout,sortBits); executeHost(inout,sortBits);
@@ -194,7 +194,7 @@ void btRadixSort32CL::execute(btOpenCLArray<btSortData>& keyValuesInOut, int sor
int dataAlignment = DATA_ALIGNMENT; int dataAlignment = DATA_ALIGNMENT;
#ifdef DEBUG_RADIXSORT2 #ifdef DEBUG_RADIXSORT2
btAlignedObjectArray<btSortData> test2; b3AlignedObjectArray<btSortData> test2;
keyValuesInOut.copyToHost(test2); keyValuesInOut.copyToHost(test2);
printf("numElem = %d\n",test2.size()); printf("numElem = %d\n",test2.size());
for (int i=0;i<test2.size();i++) for (int i=0;i<test2.size();i++)
@@ -307,7 +307,7 @@ void btRadixSort32CL::execute(btOpenCLArray<btSortData>& keyValuesInOut, int sor
#ifdef DEBUG_RADIXSORT #ifdef DEBUG_RADIXSORT
btAlignedObjectArray<unsigned int> testHist; b3AlignedObjectArray<unsigned int> testHist;
srcHisto->copyToHost(testHist); srcHisto->copyToHost(testHist);
printf("ib = %d, testHist size = %d, non zero elements:\n",ib, testHist.size()); printf("ib = %d, testHist size = %d, non zero elements:\n",ib, testHist.size());
for (int i=0;i<testHist.size();i++) for (int i=0;i<testHist.size();i++)
@@ -379,8 +379,8 @@ void btRadixSort32CL::execute(btOpenCLArray<btSortData>& keyValuesInOut, int sor
int startBit = ib; int startBit = ib;
destHisto->copyToHost(testHist); destHisto->copyToHost(testHist);
btAlignedObjectArray<btSortData> srcHost; b3AlignedObjectArray<btSortData> srcHost;
btAlignedObjectArray<btSortData> dstHost; b3AlignedObjectArray<btSortData> dstHost;
dstHost.resize(src->size()); dstHost.resize(src->size());
src->copyToHost(srcHost); src->copyToHost(srcHost);
@@ -405,11 +405,11 @@ void btRadixSort32CL::execute(btOpenCLArray<btSortData>& keyValuesInOut, int sor
int counter2[NUM_TABLES]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int counter2[NUM_TABLES]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int tables[NUM_TABLES]; int tables[NUM_TABLES];
btAlignedObjectArray<btSortData> dstHostOK; b3AlignedObjectArray<btSortData> dstHostOK;
dstHostOK.resize(src->size()); dstHostOK.resize(src->size());
destHisto->copyToHost(testHist); destHisto->copyToHost(testHist);
btAlignedObjectArray<btSortData> srcHost; b3AlignedObjectArray<btSortData> srcHost;
src->copyToHost(srcHost); src->copyToHost(srcHost);
int blockSize = 256; int blockSize = 256;
@@ -435,7 +435,7 @@ void btRadixSort32CL::execute(btOpenCLArray<btSortData>& keyValuesInOut, int sor
} }
btAlignedObjectArray<btSortData> dstHost; b3AlignedObjectArray<btSortData> dstHost;
dstHost.resize(src->size()); dstHost.resize(src->size());

View File

@@ -78,7 +78,7 @@ public:
void execute(btOpenCLArray<btSortData>& keyValuesInOut, int sortBits = 32 ); void execute(btOpenCLArray<btSortData>& keyValuesInOut, int sortBits = 32 );
void executeHost(btOpenCLArray<btSortData>& keyValuesInOut, int sortBits = 32); void executeHost(btOpenCLArray<btSortData>& keyValuesInOut, int sortBits = 32);
void executeHost(btAlignedObjectArray<btSortData>& keyValuesInOut, int sortBits = 32); void executeHost(b3AlignedObjectArray<btSortData>& keyValuesInOut, int sortBits = 32);
}; };
#endif //BT_RADIXSORT32_H #endif //BT_RADIXSORT32_H

View File

@@ -19,8 +19,8 @@ subject to the following restrictions:
#include "../host/btBoundSearchCL.h" #include "../host/btBoundSearchCL.h"
#include "../host/btRadixSort32CL.h" #include "../host/btRadixSort32CL.h"
#include "../host/btPrefixScanCL.h" #include "../host/btPrefixScanCL.h"
#include "BulletCommon/CommandLineArgs.h" #include "BulletCommon/b3CommandLineArgs.h"
#include "BulletCommon/btMinMax.h" #include "BulletCommon/b3MinMax.h"
int g_nPassed = 0; int g_nPassed = 0;
int g_nFailed = 0; int g_nFailed = 0;
@@ -89,11 +89,11 @@ inline void fillIntTest()
int offset=0; int offset=0;
fillCL->execute(intBuffer,value,size,offset); fillCL->execute(intBuffer,value,size,offset);
btAlignedObjectArray<int> hostBuf2; b3AlignedObjectArray<int> hostBuf2;
hostBuf2.resize(size); hostBuf2.resize(size);
fillCL->executeHost(hostBuf2,value,size,offset); fillCL->executeHost(hostBuf2,value,size,offset);
btAlignedObjectArray<int> hostBuf; b3AlignedObjectArray<int> hostBuf;
intBuffer.copyToHost(hostBuf); intBuffer.copyToHost(hostBuf);
for(int i=0; i<size; i++) for(int i=0; i<size; i++)
@@ -146,11 +146,11 @@ void boundSearchTest( )
btOpenCLArray<unsigned int> upperCL(g_context,g_queue,maxSize); btOpenCLArray<unsigned int> upperCL(g_context,g_queue,maxSize);
btOpenCLArray<unsigned int> lowerCL(g_context,g_queue,maxSize); btOpenCLArray<unsigned int> lowerCL(g_context,g_queue,maxSize);
btAlignedObjectArray<btSortData> srcHost; b3AlignedObjectArray<btSortData> srcHost;
btAlignedObjectArray<unsigned int> upperHost; b3AlignedObjectArray<unsigned int> upperHost;
btAlignedObjectArray<unsigned int> lowerHost; b3AlignedObjectArray<unsigned int> lowerHost;
btAlignedObjectArray<unsigned int> upperHostCompare; b3AlignedObjectArray<unsigned int> upperHostCompare;
btAlignedObjectArray<unsigned int> lowerHostCompare; b3AlignedObjectArray<unsigned int> lowerHostCompare;
btBoundSearchCL* search = new btBoundSearchCL(g_context,g_device,g_queue, maxSize); btBoundSearchCL* search = new btBoundSearchCL(g_context,g_device,g_queue, maxSize);
@@ -260,8 +260,8 @@ void prefixScanTest()
int maxSize = 1024*256; int maxSize = 1024*256;
btAlignedObjectArray<unsigned int> buf0Host; b3AlignedObjectArray<unsigned int> buf0Host;
btAlignedObjectArray<unsigned int> buf1Host; b3AlignedObjectArray<unsigned int> buf1Host;
btOpenCLArray<unsigned int> buf2CL(g_context,g_queue,maxSize); btOpenCLArray<unsigned int> buf2CL(g_context,g_queue,maxSize);
btOpenCLArray<unsigned int> buf3CL(g_context,g_queue,maxSize); btOpenCLArray<unsigned int> buf3CL(g_context,g_queue,maxSize);
@@ -305,9 +305,9 @@ bool radixSortTest()
int maxSize = 1024*256; int maxSize = 1024*256;
btAlignedObjectArray<btSortData> buf0Host; b3AlignedObjectArray<btSortData> buf0Host;
buf0Host.resize(maxSize); buf0Host.resize(maxSize);
btAlignedObjectArray<btSortData> buf1Host; b3AlignedObjectArray<btSortData> buf1Host;
buf1Host.resize(maxSize ); buf1Host.resize(maxSize );
btOpenCLArray<btSortData> buf2CL(g_context,g_queue,maxSize); btOpenCLArray<btSortData> buf2CL(g_context,g_queue,maxSize);
@@ -356,7 +356,7 @@ int main(int argc, char** argv)
int preferredDeviceIndex = -1; int preferredDeviceIndex = -1;
int preferredPlatformIndex = -1; int preferredPlatformIndex = -1;
CommandLineArgs args(argc, argv); b3CommandLineArgs args(argc, argv);
args.GetCmdLineArgument("deviceId", preferredDeviceIndex); args.GetCmdLineArgument("deviceId", preferredDeviceIndex);
args.GetCmdLineArgument("platformId", preferredPlatformIndex); args.GetCmdLineArgument("platformId", preferredPlatformIndex);

View File

@@ -27,9 +27,9 @@ function createProject(vendor)
"../host/btPrefixScanCL.h", "../host/btPrefixScanCL.h",
"../host/btRadixSort32CL.cpp", "../host/btRadixSort32CL.cpp",
"../host/btRadixSort32CL.h", "../host/btRadixSort32CL.h",
"../../../src/BulletCommon/btAlignedAllocator.cpp", "../../../src/BulletCommon/b3AlignedAllocator.cpp",
"../../../src/BulletCommon/btAlignedAllocator.h", "../../../src/BulletCommon/b3AlignedAllocator.h",
"../../../src/BulletCommon/btAlignedObjectArray.h", "../../../src/BulletCommon/b3AlignedObjectArray.h",
} }
end end

View File

@@ -60,8 +60,8 @@ int main(int argc, char* argv[])
int numElements = 1024*1024; int numElements = 1024*1024;
btOpenCLArray<int> a(ctx,queue); btOpenCLArray<int> a(ctx,queue);
btOpenCLArray<int> b(ctx,queue); btOpenCLArray<int> b(ctx,queue);
btAlignedObjectArray<int> hostA; b3AlignedObjectArray<int> hostA;
btAlignedObjectArray<int> hostB; b3AlignedObjectArray<int> hostB;
for (int i=0;i<numElements;i++) for (int i=0;i<numElements;i++)
{ {

View File

@@ -27,9 +27,9 @@ function createProject (vendor)
"main.cpp", "main.cpp",
"../basic_initialize/b3OpenCLUtils.cpp", "../basic_initialize/b3OpenCLUtils.cpp",
"../basic_initialize/b3OpenCLUtils.h", "../basic_initialize/b3OpenCLUtils.h",
"../../src/BulletCommon/btAlignedAllocator.cpp", "../../src/BulletCommon/b3AlignedAllocator.cpp",
"../../src/BulletCommon/btAlignedAllocator.h", "../../src/BulletCommon/b3AlignedAllocator.h",
"../../src/BulletCommon/btAlignedObjectArray.h", "../../src/BulletCommon/b3AlignedObjectArray.h",
} }
end end

View File

@@ -27,9 +27,9 @@ function createProject (vendor)
"main.cpp", "main.cpp",
"../basic_initialize/b3OpenCLUtils.cpp", "../basic_initialize/b3OpenCLUtils.cpp",
"../basic_initialize/b3OpenCLUtils.h", "../basic_initialize/b3OpenCLUtils.h",
"../../src/BulletCommon/btAlignedAllocator.cpp", "../../src/BulletCommon/b3AlignedAllocator.cpp",
"../../src/BulletCommon/btAlignedAllocator.h", "../../src/BulletCommon/b3AlignedAllocator.h",
"../../src/BulletCommon/btAlignedObjectArray.h", "../../src/BulletCommon/b3AlignedObjectArray.h",
} }
end end

View File

@@ -13,7 +13,7 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "btAlignedAllocator.h" #include "b3AlignedAllocator.h"
int gNumAlignedAllocs = 0; int gNumAlignedAllocs = 0;
int gNumAlignedFree = 0; int gNumAlignedFree = 0;

View File

@@ -20,7 +20,7 @@ subject to the following restrictions:
///so we replace _aligned_malloc and _aligned_free with our own ///so we replace _aligned_malloc and _aligned_free with our own
///that is better portable and more predictable ///that is better portable and more predictable
#include "btScalar.h" #include "b3Scalar.h"
//#define BT_DEBUG_MEMORY_ALLOCATIONS 1 //#define BT_DEBUG_MEMORY_ALLOCATIONS 1
#ifdef BT_DEBUG_MEMORY_ALLOCATIONS #ifdef BT_DEBUG_MEMORY_ALLOCATIONS
@@ -55,23 +55,23 @@ void btAlignedAllocSetCustom(btAllocFunc *allocFunc, btFreeFunc *freeFunc);
void btAlignedAllocSetCustomAligned(btAlignedAllocFunc *allocFunc, btAlignedFreeFunc *freeFunc); void btAlignedAllocSetCustomAligned(btAlignedAllocFunc *allocFunc, btAlignedFreeFunc *freeFunc);
///The btAlignedAllocator is a portable class for aligned memory allocations. ///The b3AlignedAllocator is a portable class for aligned memory allocations.
///Default implementations for unaligned and aligned allocations can be overridden by a custom allocator using btAlignedAllocSetCustom and btAlignedAllocSetCustomAligned. ///Default implementations for unaligned and aligned allocations can be overridden by a custom allocator using btAlignedAllocSetCustom and btAlignedAllocSetCustomAligned.
template < typename T , unsigned Alignment > template < typename T , unsigned Alignment >
class btAlignedAllocator { class b3AlignedAllocator {
typedef btAlignedAllocator< T , Alignment > self_type; typedef b3AlignedAllocator< T , Alignment > self_type;
public: public:
//just going down a list: //just going down a list:
btAlignedAllocator() {} b3AlignedAllocator() {}
/* /*
btAlignedAllocator( const self_type & ) {} b3AlignedAllocator( const self_type & ) {}
*/ */
template < typename Other > template < typename Other >
btAlignedAllocator( const btAlignedAllocator< Other , Alignment > & ) {} b3AlignedAllocator( const b3AlignedAllocator< Other , Alignment > & ) {}
typedef const T* const_pointer; typedef const T* const_pointer;
typedef const T& const_reference; typedef const T& const_reference;
@@ -93,10 +93,10 @@ public:
template < typename O > struct rebind { template < typename O > struct rebind {
typedef btAlignedAllocator< O , Alignment > other; typedef b3AlignedAllocator< O , Alignment > other;
}; };
template < typename O > template < typename O >
self_type & operator=( const btAlignedAllocator< O , Alignment > & ) { return *this; } self_type & operator=( const b3AlignedAllocator< O , Alignment > & ) { return *this; }
friend bool operator==( const self_type & , const self_type & ) { return true; } friend bool operator==( const self_type & , const self_type & ) { return true; }
}; };

View File

@@ -17,11 +17,11 @@ subject to the following restrictions:
#ifndef BT_OBJECT_ARRAY__ #ifndef BT_OBJECT_ARRAY__
#define BT_OBJECT_ARRAY__ #define BT_OBJECT_ARRAY__
#include "btScalar.h" // has definitions like SIMD_FORCE_INLINE #include "b3Scalar.h" // has definitions like SIMD_FORCE_INLINE
#include "btAlignedAllocator.h" #include "b3AlignedAllocator.h"
///If the platform doesn't support placement new, you can disable BT_USE_PLACEMENT_NEW ///If the platform doesn't support placement new, you can disable BT_USE_PLACEMENT_NEW
///then the btAlignedObjectArray doesn't support objects with virtual methods, and non-trivial constructors/destructors ///then the b3AlignedObjectArray doesn't support objects with virtual methods, and non-trivial constructors/destructors
///You can enable BT_USE_MEMCPY, then swapping elements in the array will use memcpy instead of operator= ///You can enable BT_USE_MEMCPY, then swapping elements in the array will use memcpy instead of operator=
///see discussion here: http://continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1231 and ///see discussion here: http://continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1231 and
///http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1240 ///http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1240
@@ -40,13 +40,13 @@ subject to the following restrictions:
#endif //BT_USE_PLACEMENT_NEW #endif //BT_USE_PLACEMENT_NEW
///The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods ///The b3AlignedObjectArray template class uses a subset of the stl::vector interface for its methods
///It is developed to replace stl::vector to avoid portability issues, including STL alignment issues to add SIMD/SSE data ///It is developed to replace stl::vector to avoid portability issues, including STL alignment issues to add SIMD/SSE data
template <typename T> template <typename T>
//template <class T> //template <class T>
class btAlignedObjectArray class b3AlignedObjectArray
{ {
btAlignedAllocator<T , 16> m_allocator; b3AlignedAllocator<T , 16> m_allocator;
int m_size; int m_size;
int m_capacity; int m_capacity;
@@ -56,14 +56,14 @@ class btAlignedObjectArray
#ifdef BT_ALLOW_ARRAY_COPY_OPERATOR #ifdef BT_ALLOW_ARRAY_COPY_OPERATOR
public: public:
SIMD_FORCE_INLINE btAlignedObjectArray<T>& operator=(const btAlignedObjectArray<T> &other) SIMD_FORCE_INLINE b3AlignedObjectArray<T>& operator=(const b3AlignedObjectArray<T> &other)
{ {
copyFromArray(other); copyFromArray(other);
return *this; return *this;
} }
#else//BT_ALLOW_ARRAY_COPY_OPERATOR #else//BT_ALLOW_ARRAY_COPY_OPERATOR
private: private:
SIMD_FORCE_INLINE btAlignedObjectArray<T>& operator=(const btAlignedObjectArray<T> &other); SIMD_FORCE_INLINE b3AlignedObjectArray<T>& operator=(const b3AlignedObjectArray<T> &other);
#endif//BT_ALLOW_ARRAY_COPY_OPERATOR #endif//BT_ALLOW_ARRAY_COPY_OPERATOR
protected: protected:
@@ -123,18 +123,18 @@ protected:
public: public:
btAlignedObjectArray() b3AlignedObjectArray()
{ {
init(); init();
} }
~btAlignedObjectArray() ~b3AlignedObjectArray()
{ {
clear(); clear();
} }
///Generally it is best to avoid using the copy constructor of an btAlignedObjectArray, and use a (const) reference to the array instead. ///Generally it is best to avoid using the copy constructor of an b3AlignedObjectArray, and use a (const) reference to the array instead.
btAlignedObjectArray(const btAlignedObjectArray& otherArray) b3AlignedObjectArray(const b3AlignedObjectArray& otherArray)
{ {
init(); init();
@@ -500,7 +500,7 @@ protected:
m_capacity = capacity; m_capacity = capacity;
} }
void copyFromArray(const btAlignedObjectArray& otherArray) void copyFromArray(const b3AlignedObjectArray& otherArray)
{ {
int otherSize = otherArray.size(); int otherSize = otherArray.size();
resize (otherSize); resize (otherSize);

View File

@@ -9,7 +9,7 @@
#include <string> #include <string>
#include <cstring> #include <cstring>
#include <sstream> #include <sstream>
class CommandLineArgs class b3CommandLineArgs
{ {
protected: protected:
@@ -18,7 +18,7 @@ protected:
public: public:
// Constructor // Constructor
CommandLineArgs(int argc, char **argv) b3CommandLineArgs(int argc, char **argv)
{ {
using namespace std; using namespace std;
@@ -63,7 +63,7 @@ public:
}; };
template <typename T> template <typename T>
void CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val) void b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val)
{ {
using namespace std; using namespace std;
map<string, string>::iterator itr; map<string, string>::iterator itr;
@@ -74,7 +74,7 @@ void CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val)
} }
template <> template <>
void CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &val) void b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &val)
{ {
using namespace std; using namespace std;
map<string, string>::iterator itr; map<string, string>::iterator itr;

View File

@@ -17,9 +17,9 @@ subject to the following restrictions:
#ifndef BT_HASH_MAP_H #ifndef BT_HASH_MAP_H
#define BT_HASH_MAP_H #define BT_HASH_MAP_H
#include "btAlignedObjectArray.h" #include "b3AlignedObjectArray.h"
///very basic hashable string implementation, compatible with btHashMap ///very basic hashable string implementation, compatible with b3HashMap
struct btHashString struct btHashString
{ {
const char* m_string; const char* m_string;
@@ -214,18 +214,18 @@ public:
}; };
///The btHashMap template class implements a generic and lightweight hashmap. ///The b3HashMap template class implements a generic and lightweight hashmap.
///A basic sample of how to use btHashMap is located in Demos\BasicDemo\main.cpp ///A basic sample of how to use b3HashMap is located in Demos\BasicDemo\main.cpp
template <class Key, class Value> template <class Key, class Value>
class btHashMap class b3HashMap
{ {
protected: protected:
btAlignedObjectArray<int> m_hashTable; b3AlignedObjectArray<int> m_hashTable;
btAlignedObjectArray<int> m_next; b3AlignedObjectArray<int> m_next;
btAlignedObjectArray<Value> m_valueArray; b3AlignedObjectArray<Value> m_valueArray;
btAlignedObjectArray<Key> m_keyArray; b3AlignedObjectArray<Key> m_keyArray;
void growTables(const Key& /*key*/) void growTables(const Key& /*key*/)
{ {

View File

@@ -16,8 +16,8 @@ subject to the following restrictions:
#ifndef BT_MATRIX3x3_H #ifndef BT_MATRIX3x3_H
#define BT_MATRIX3x3_H #define BT_MATRIX3x3_H
#include "btVector3.h" #include "b3Vector3.h"
#include "btQuaternion.h" #include "b3Quaternion.h"
#include <stdio.h> #include <stdio.h>
#ifdef BT_USE_SSE #ifdef BT_USE_SSE
@@ -38,32 +38,32 @@ const btSimdFloat4 ATTRIBUTE_ALIGNED16(v0010) = {0.0f, 0.0f, 1.0f, 0.0f};
#endif //BT_USE_DOUBLE_PRECISION #endif //BT_USE_DOUBLE_PRECISION
/**@brief The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with btQuaternion, btTransform and btVector3. /**@brief The b3Matrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with b3Quaternion, b3Transform and b3Vector3.
* Make sure to only include a pure orthogonal matrix without scaling. */ * Make sure to only include a pure orthogonal matrix without scaling. */
ATTRIBUTE_ALIGNED16(class) btMatrix3x3 { ATTRIBUTE_ALIGNED16(class) b3Matrix3x3 {
///Data storage for the matrix, each vector is a row of the matrix ///Data storage for the matrix, each vector is a row of the matrix
btVector3 m_el[3]; b3Vector3 m_el[3];
public: public:
/** @brief No initializaion constructor */ /** @brief No initializaion constructor */
btMatrix3x3 () {} b3Matrix3x3 () {}
// explicit btMatrix3x3(const btScalar *m) { setFromOpenGLSubMatrix(m); } // explicit b3Matrix3x3(const b3Scalar *m) { setFromOpenGLSubMatrix(m); }
/**@brief Constructor from Quaternion */ /**@brief Constructor from Quaternion */
explicit btMatrix3x3(const btQuaternion& q) { setRotation(q); } explicit b3Matrix3x3(const b3Quaternion& q) { setRotation(q); }
/* /*
template <typename btScalar> template <typename b3Scalar>
Matrix3x3(const btScalar& yaw, const btScalar& pitch, const btScalar& roll) Matrix3x3(const b3Scalar& yaw, const b3Scalar& pitch, const b3Scalar& roll)
{ {
setEulerYPR(yaw, pitch, roll); setEulerYPR(yaw, pitch, roll);
} }
*/ */
/** @brief Constructor with row major formatting */ /** @brief Constructor with row major formatting */
btMatrix3x3(const btScalar& xx, const btScalar& xy, const btScalar& xz, b3Matrix3x3(const b3Scalar& xx, const b3Scalar& xy, const b3Scalar& xz,
const btScalar& yx, const btScalar& yy, const btScalar& yz, const b3Scalar& yx, const b3Scalar& yy, const b3Scalar& yz,
const btScalar& zx, const btScalar& zy, const btScalar& zz) const b3Scalar& zx, const b3Scalar& zy, const b3Scalar& zz)
{ {
setValue(xx, xy, xz, setValue(xx, xy, xz,
yx, yy, yz, yx, yy, yz,
@@ -71,14 +71,14 @@ public:
} }
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON)
SIMD_FORCE_INLINE btMatrix3x3 (const btSimdFloat4 v0, const btSimdFloat4 v1, const btSimdFloat4 v2 ) SIMD_FORCE_INLINE b3Matrix3x3 (const btSimdFloat4 v0, const btSimdFloat4 v1, const btSimdFloat4 v2 )
{ {
m_el[0].mVec128 = v0; m_el[0].mVec128 = v0;
m_el[1].mVec128 = v1; m_el[1].mVec128 = v1;
m_el[2].mVec128 = v2; m_el[2].mVec128 = v2;
} }
SIMD_FORCE_INLINE btMatrix3x3 (const btVector3& v0, const btVector3& v1, const btVector3& v2 ) SIMD_FORCE_INLINE b3Matrix3x3 (const b3Vector3& v0, const b3Vector3& v1, const b3Vector3& v2 )
{ {
m_el[0] = v0; m_el[0] = v0;
m_el[1] = v1; m_el[1] = v1;
@@ -86,7 +86,7 @@ public:
} }
// Copy constructor // Copy constructor
SIMD_FORCE_INLINE btMatrix3x3(const btMatrix3x3& rhs) SIMD_FORCE_INLINE b3Matrix3x3(const b3Matrix3x3& rhs)
{ {
m_el[0].mVec128 = rhs.m_el[0].mVec128; m_el[0].mVec128 = rhs.m_el[0].mVec128;
m_el[1].mVec128 = rhs.m_el[1].mVec128; m_el[1].mVec128 = rhs.m_el[1].mVec128;
@@ -94,7 +94,7 @@ public:
} }
// Assignment Operator // Assignment Operator
SIMD_FORCE_INLINE btMatrix3x3& operator=(const btMatrix3x3& m) SIMD_FORCE_INLINE b3Matrix3x3& operator=(const b3Matrix3x3& m)
{ {
m_el[0].mVec128 = m.m_el[0].mVec128; m_el[0].mVec128 = m.m_el[0].mVec128;
m_el[1].mVec128 = m.m_el[1].mVec128; m_el[1].mVec128 = m.m_el[1].mVec128;
@@ -106,7 +106,7 @@ public:
#else #else
/** @brief Copy constructor */ /** @brief Copy constructor */
SIMD_FORCE_INLINE btMatrix3x3 (const btMatrix3x3& other) SIMD_FORCE_INLINE b3Matrix3x3 (const b3Matrix3x3& other)
{ {
m_el[0] = other.m_el[0]; m_el[0] = other.m_el[0];
m_el[1] = other.m_el[1]; m_el[1] = other.m_el[1];
@@ -114,7 +114,7 @@ public:
} }
/** @brief Assignment Operator */ /** @brief Assignment Operator */
SIMD_FORCE_INLINE btMatrix3x3& operator=(const btMatrix3x3& other) SIMD_FORCE_INLINE b3Matrix3x3& operator=(const b3Matrix3x3& other)
{ {
m_el[0] = other.m_el[0]; m_el[0] = other.m_el[0];
m_el[1] = other.m_el[1]; m_el[1] = other.m_el[1];
@@ -126,15 +126,15 @@ public:
/** @brief Get a column of the matrix as a vector /** @brief Get a column of the matrix as a vector
* @param i Column number 0 indexed */ * @param i Column number 0 indexed */
SIMD_FORCE_INLINE btVector3 getColumn(int i) const SIMD_FORCE_INLINE b3Vector3 getColumn(int i) const
{ {
return btVector3(m_el[0][i],m_el[1][i],m_el[2][i]); return b3Vector3(m_el[0][i],m_el[1][i],m_el[2][i]);
} }
/** @brief Get a row of the matrix as a vector /** @brief Get a row of the matrix as a vector
* @param i Row number 0 indexed */ * @param i Row number 0 indexed */
SIMD_FORCE_INLINE const btVector3& getRow(int i) const SIMD_FORCE_INLINE const b3Vector3& getRow(int i) const
{ {
btFullAssert(0 <= i && i < 3); btFullAssert(0 <= i && i < 3);
return m_el[i]; return m_el[i];
@@ -142,7 +142,7 @@ public:
/** @brief Get a mutable reference to a row of the matrix as a vector /** @brief Get a mutable reference to a row of the matrix as a vector
* @param i Row number 0 indexed */ * @param i Row number 0 indexed */
SIMD_FORCE_INLINE btVector3& operator[](int i) SIMD_FORCE_INLINE b3Vector3& operator[](int i)
{ {
btFullAssert(0 <= i && i < 3); btFullAssert(0 <= i && i < 3);
return m_el[i]; return m_el[i];
@@ -150,7 +150,7 @@ public:
/** @brief Get a const reference to a row of the matrix as a vector /** @brief Get a const reference to a row of the matrix as a vector
* @param i Row number 0 indexed */ * @param i Row number 0 indexed */
SIMD_FORCE_INLINE const btVector3& operator[](int i) const SIMD_FORCE_INLINE const b3Vector3& operator[](int i) const
{ {
btFullAssert(0 <= i && i < 3); btFullAssert(0 <= i && i < 3);
return m_el[i]; return m_el[i];
@@ -159,21 +159,21 @@ public:
/** @brief Multiply by the target matrix on the right /** @brief Multiply by the target matrix on the right
* @param m Rotation matrix to be applied * @param m Rotation matrix to be applied
* Equivilant to this = this * m */ * Equivilant to this = this * m */
btMatrix3x3& operator*=(const btMatrix3x3& m); b3Matrix3x3& operator*=(const b3Matrix3x3& m);
/** @brief Adds by the target matrix on the right /** @brief Adds by the target matrix on the right
* @param m matrix to be applied * @param m matrix to be applied
* Equivilant to this = this + m */ * Equivilant to this = this + m */
btMatrix3x3& operator+=(const btMatrix3x3& m); b3Matrix3x3& operator+=(const b3Matrix3x3& m);
/** @brief Substractss by the target matrix on the right /** @brief Substractss by the target matrix on the right
* @param m matrix to be applied * @param m matrix to be applied
* Equivilant to this = this - m */ * Equivilant to this = this - m */
btMatrix3x3& operator-=(const btMatrix3x3& m); b3Matrix3x3& operator-=(const b3Matrix3x3& m);
/** @brief Set from the rotational part of a 4x4 OpenGL matrix /** @brief Set from the rotational part of a 4x4 OpenGL matrix
* @param m A pointer to the beginning of the array of scalars*/ * @param m A pointer to the beginning of the array of scalars*/
void setFromOpenGLSubMatrix(const btScalar *m) void setFromOpenGLSubMatrix(const b3Scalar *m)
{ {
m_el[0].setValue(m[0],m[4],m[8]); m_el[0].setValue(m[0],m[4],m[8]);
m_el[1].setValue(m[1],m[5],m[9]); m_el[1].setValue(m[1],m[5],m[9]);
@@ -190,9 +190,9 @@ public:
* @param zx Bottom Left * @param zx Bottom Left
* @param zy Bottom Middle * @param zy Bottom Middle
* @param zz Bottom Right*/ * @param zz Bottom Right*/
void setValue(const btScalar& xx, const btScalar& xy, const btScalar& xz, void setValue(const b3Scalar& xx, const b3Scalar& xy, const b3Scalar& xz,
const btScalar& yx, const btScalar& yy, const btScalar& yz, const b3Scalar& yx, const b3Scalar& yy, const b3Scalar& yz,
const btScalar& zx, const btScalar& zy, const btScalar& zz) const b3Scalar& zx, const b3Scalar& zy, const b3Scalar& zz)
{ {
m_el[0].setValue(xx,xy,xz); m_el[0].setValue(xx,xy,xz);
m_el[1].setValue(yx,yy,yz); m_el[1].setValue(yx,yy,yz);
@@ -201,11 +201,11 @@ public:
/** @brief Set the matrix from a quaternion /** @brief Set the matrix from a quaternion
* @param q The Quaternion to match */ * @param q The Quaternion to match */
void setRotation(const btQuaternion& q) void setRotation(const b3Quaternion& q)
{ {
btScalar d = q.length2(); b3Scalar d = q.length2();
btFullAssert(d != btScalar(0.0)); btFullAssert(d != b3Scalar(0.0));
btScalar s = btScalar(2.0) / d; b3Scalar s = b3Scalar(2.0) / d;
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 vs, Q = q.get128(); __m128 vs, Q = q.get128();
@@ -259,14 +259,14 @@ public:
m_el[1] = V2; m_el[1] = V2;
m_el[2] = V3; m_el[2] = V3;
#else #else
btScalar xs = q.getX() * s, ys = q.getY() * s, zs = q.getZ() * s; b3Scalar xs = q.getX() * s, ys = q.getY() * s, zs = q.getZ() * s;
btScalar wx = q.getW() * xs, wy = q.getW() * ys, wz = q.getW() * zs; b3Scalar wx = q.getW() * xs, wy = q.getW() * ys, wz = q.getW() * zs;
btScalar xx = q.getX() * xs, xy = q.getX() * ys, xz = q.getX() * zs; b3Scalar xx = q.getX() * xs, xy = q.getX() * ys, xz = q.getX() * zs;
btScalar yy = q.getY() * ys, yz = q.getY() * zs, zz = q.getZ() * zs; b3Scalar yy = q.getY() * ys, yz = q.getY() * zs, zz = q.getZ() * zs;
setValue( setValue(
btScalar(1.0) - (yy + zz), xy - wz, xz + wy, b3Scalar(1.0) - (yy + zz), xy - wz, xz + wy,
xy + wz, btScalar(1.0) - (xx + zz), yz - wx, xy + wz, b3Scalar(1.0) - (xx + zz), yz - wx,
xz - wy, yz + wx, btScalar(1.0) - (xx + yy)); xz - wy, yz + wx, b3Scalar(1.0) - (xx + yy));
#endif #endif
} }
@@ -276,7 +276,7 @@ public:
* @param pitch Pitch about X axis * @param pitch Pitch about X axis
* @param roll Roll about Z axis * @param roll Roll about Z axis
*/ */
void setEulerYPR(const btScalar& yaw, const btScalar& pitch, const btScalar& roll) void setEulerYPR(const b3Scalar& yaw, const b3Scalar& pitch, const b3Scalar& roll)
{ {
setEulerZYX(roll, pitch, yaw); setEulerZYX(roll, pitch, yaw);
} }
@@ -290,18 +290,18 @@ public:
* angles are applied in ZYX order. I.e a vector is first rotated * angles are applied in ZYX order. I.e a vector is first rotated
* about X then Y and then Z * about X then Y and then Z
**/ **/
void setEulerZYX(btScalar eulerX,btScalar eulerY,btScalar eulerZ) { void setEulerZYX(b3Scalar eulerX,b3Scalar eulerY,b3Scalar eulerZ) {
///@todo proposed to reverse this since it's labeled zyx but takes arguments xyz and it will match all other parts of the code ///@todo proposed to reverse this since it's labeled zyx but takes arguments xyz and it will match all other parts of the code
btScalar ci ( btCos(eulerX)); b3Scalar ci ( btCos(eulerX));
btScalar cj ( btCos(eulerY)); b3Scalar cj ( btCos(eulerY));
btScalar ch ( btCos(eulerZ)); b3Scalar ch ( btCos(eulerZ));
btScalar si ( btSin(eulerX)); b3Scalar si ( btSin(eulerX));
btScalar sj ( btSin(eulerY)); b3Scalar sj ( btSin(eulerY));
btScalar sh ( btSin(eulerZ)); b3Scalar sh ( btSin(eulerZ));
btScalar cc = ci * ch; b3Scalar cc = ci * ch;
btScalar cs = ci * sh; b3Scalar cs = ci * sh;
btScalar sc = si * ch; b3Scalar sc = si * ch;
btScalar ss = si * sh; b3Scalar ss = si * sh;
setValue(cj * ch, sj * sc - cs, sj * cc + ss, setValue(cj * ch, sj * sc - cs, sj * cc + ss,
cj * sh, sj * ss + cc, sj * cs - sc, cj * sh, sj * ss + cc, sj * cs - sc,
@@ -316,30 +316,30 @@ public:
m_el[1] = v0100; m_el[1] = v0100;
m_el[2] = v0010; m_el[2] = v0010;
#else #else
setValue(btScalar(1.0), btScalar(0.0), btScalar(0.0), setValue(b3Scalar(1.0), b3Scalar(0.0), b3Scalar(0.0),
btScalar(0.0), btScalar(1.0), btScalar(0.0), b3Scalar(0.0), b3Scalar(1.0), b3Scalar(0.0),
btScalar(0.0), btScalar(0.0), btScalar(1.0)); b3Scalar(0.0), b3Scalar(0.0), b3Scalar(1.0));
#endif #endif
} }
static const btMatrix3x3& getIdentity() static const b3Matrix3x3& getIdentity()
{ {
#if (defined(BT_USE_SSE_IN_API)&& defined (BT_USE_SSE)) || defined(BT_USE_NEON) #if (defined(BT_USE_SSE_IN_API)&& defined (BT_USE_SSE)) || defined(BT_USE_NEON)
static const btMatrix3x3 static const b3Matrix3x3
identityMatrix(v1000, v0100, v0010); identityMatrix(v1000, v0100, v0010);
#else #else
static const btMatrix3x3 static const b3Matrix3x3
identityMatrix( identityMatrix(
btScalar(1.0), btScalar(0.0), btScalar(0.0), b3Scalar(1.0), b3Scalar(0.0), b3Scalar(0.0),
btScalar(0.0), btScalar(1.0), btScalar(0.0), b3Scalar(0.0), b3Scalar(1.0), b3Scalar(0.0),
btScalar(0.0), btScalar(0.0), btScalar(1.0)); b3Scalar(0.0), b3Scalar(0.0), b3Scalar(1.0));
#endif #endif
return identityMatrix; return identityMatrix;
} }
/**@brief Fill the rotational part of an OpenGL matrix and clear the shear/perspective /**@brief Fill the rotational part of an OpenGL matrix and clear the shear/perspective
* @param m The array to be filled */ * @param m The array to be filled */
void getOpenGLSubMatrix(btScalar *m) const void getOpenGLSubMatrix(b3Scalar *m) const
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 v0 = m_el[0].mVec128; __m128 v0 = m_el[0].mVec128;
@@ -375,43 +375,43 @@ public:
vm[1] = v1; vm[1] = v1;
vm[2] = v2; vm[2] = v2;
#else #else
m[0] = btScalar(m_el[0].getX()); m[0] = b3Scalar(m_el[0].getX());
m[1] = btScalar(m_el[1].getX()); m[1] = b3Scalar(m_el[1].getX());
m[2] = btScalar(m_el[2].getX()); m[2] = b3Scalar(m_el[2].getX());
m[3] = btScalar(0.0); m[3] = b3Scalar(0.0);
m[4] = btScalar(m_el[0].getY()); m[4] = b3Scalar(m_el[0].getY());
m[5] = btScalar(m_el[1].getY()); m[5] = b3Scalar(m_el[1].getY());
m[6] = btScalar(m_el[2].getY()); m[6] = b3Scalar(m_el[2].getY());
m[7] = btScalar(0.0); m[7] = b3Scalar(0.0);
m[8] = btScalar(m_el[0].getZ()); m[8] = b3Scalar(m_el[0].getZ());
m[9] = btScalar(m_el[1].getZ()); m[9] = b3Scalar(m_el[1].getZ());
m[10] = btScalar(m_el[2].getZ()); m[10] = b3Scalar(m_el[2].getZ());
m[11] = btScalar(0.0); m[11] = b3Scalar(0.0);
#endif #endif
} }
/**@brief Get the matrix represented as a quaternion /**@brief Get the matrix represented as a quaternion
* @param q The quaternion which will be set */ * @param q The quaternion which will be set */
void getRotation(btQuaternion& q) const void getRotation(b3Quaternion& q) const
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON)
btScalar trace = m_el[0].getX() + m_el[1].getY() + m_el[2].getZ(); b3Scalar trace = m_el[0].getX() + m_el[1].getY() + m_el[2].getZ();
btScalar s, x; b3Scalar s, x;
union { union {
btSimdFloat4 vec; btSimdFloat4 vec;
btScalar f[4]; b3Scalar f[4];
} temp; } temp;
if (trace > btScalar(0.0)) if (trace > b3Scalar(0.0))
{ {
x = trace + btScalar(1.0); x = trace + b3Scalar(1.0);
temp.f[0]=m_el[2].getY() - m_el[1].getZ(); temp.f[0]=m_el[2].getY() - m_el[1].getZ();
temp.f[1]=m_el[0].getZ() - m_el[2].getX(); temp.f[1]=m_el[0].getZ() - m_el[2].getX();
temp.f[2]=m_el[1].getX() - m_el[0].getY(); temp.f[2]=m_el[1].getX() - m_el[0].getY();
temp.f[3]=x; temp.f[3]=x;
//temp.f[3]= s * btScalar(0.5); //temp.f[3]= s * b3Scalar(0.5);
} }
else else
{ {
@@ -431,30 +431,30 @@ public:
{ i = 0; j = 1; k = 2; } { i = 0; j = 1; k = 2; }
} }
x = m_el[i][i] - m_el[j][j] - m_el[k][k] + btScalar(1.0); x = m_el[i][i] - m_el[j][j] - m_el[k][k] + b3Scalar(1.0);
temp.f[3] = (m_el[k][j] - m_el[j][k]); temp.f[3] = (m_el[k][j] - m_el[j][k]);
temp.f[j] = (m_el[j][i] + m_el[i][j]); temp.f[j] = (m_el[j][i] + m_el[i][j]);
temp.f[k] = (m_el[k][i] + m_el[i][k]); temp.f[k] = (m_el[k][i] + m_el[i][k]);
temp.f[i] = x; temp.f[i] = x;
//temp.f[i] = s * btScalar(0.5); //temp.f[i] = s * b3Scalar(0.5);
} }
s = btSqrt(x); s = btSqrt(x);
q.set128(temp.vec); q.set128(temp.vec);
s = btScalar(0.5) / s; s = b3Scalar(0.5) / s;
q *= s; q *= s;
#else #else
btScalar trace = m_el[0].getX() + m_el[1].getY() + m_el[2].getZ(); b3Scalar trace = m_el[0].getX() + m_el[1].getY() + m_el[2].getZ();
btScalar temp[4]; b3Scalar temp[4];
if (trace > btScalar(0.0)) if (trace > b3Scalar(0.0))
{ {
btScalar s = btSqrt(trace + btScalar(1.0)); b3Scalar s = btSqrt(trace + b3Scalar(1.0));
temp[3]=(s * btScalar(0.5)); temp[3]=(s * b3Scalar(0.5));
s = btScalar(0.5) / s; s = b3Scalar(0.5) / s;
temp[0]=((m_el[2].getY() - m_el[1].getZ()) * s); temp[0]=((m_el[2].getY() - m_el[1].getZ()) * s);
temp[1]=((m_el[0].getZ() - m_el[2].getX()) * s); temp[1]=((m_el[0].getZ() - m_el[2].getX()) * s);
@@ -468,9 +468,9 @@ public:
int j = (i + 1) % 3; int j = (i + 1) % 3;
int k = (i + 2) % 3; int k = (i + 2) % 3;
btScalar s = btSqrt(m_el[i][i] - m_el[j][j] - m_el[k][k] + btScalar(1.0)); b3Scalar s = btSqrt(m_el[i][i] - m_el[j][j] - m_el[k][k] + b3Scalar(1.0));
temp[i] = s * btScalar(0.5); temp[i] = s * b3Scalar(0.5);
s = btScalar(0.5) / s; s = b3Scalar(0.5) / s;
temp[3] = (m_el[k][j] - m_el[j][k]) * s; temp[3] = (m_el[k][j] - m_el[j][k]) * s;
temp[j] = (m_el[j][i] + m_el[i][j]) * s; temp[j] = (m_el[j][i] + m_el[i][j]) * s;
@@ -484,13 +484,13 @@ public:
* @param yaw Yaw around Y axis * @param yaw Yaw around Y axis
* @param pitch Pitch around X axis * @param pitch Pitch around X axis
* @param roll around Z axis */ * @param roll around Z axis */
void getEulerYPR(btScalar& yaw, btScalar& pitch, btScalar& roll) const void getEulerYPR(b3Scalar& yaw, b3Scalar& pitch, b3Scalar& roll) const
{ {
// first use the normal calculus // first use the normal calculus
yaw = btScalar(btAtan2(m_el[1].getX(), m_el[0].getX())); yaw = b3Scalar(btAtan2(m_el[1].getX(), m_el[0].getX()));
pitch = btScalar(btAsin(-m_el[2].getX())); pitch = b3Scalar(btAsin(-m_el[2].getX()));
roll = btScalar(btAtan2(m_el[2].getY(), m_el[2].getZ())); roll = b3Scalar(btAtan2(m_el[2].getY(), m_el[2].getZ()));
// on pitch = +/-HalfPI // on pitch = +/-HalfPI
if (btFabs(pitch)==SIMD_HALF_PI) if (btFabs(pitch)==SIMD_HALF_PI)
@@ -513,13 +513,13 @@ public:
* @param pitch Pitch around Y axis * @param pitch Pitch around Y axis
* @param roll around X axis * @param roll around X axis
* @param solution_number Which solution of two possible solutions ( 1 or 2) are possible values*/ * @param solution_number Which solution of two possible solutions ( 1 or 2) are possible values*/
void getEulerZYX(btScalar& yaw, btScalar& pitch, btScalar& roll, unsigned int solution_number = 1) const void getEulerZYX(b3Scalar& yaw, b3Scalar& pitch, b3Scalar& roll, unsigned int solution_number = 1) const
{ {
struct Euler struct Euler
{ {
btScalar yaw; b3Scalar yaw;
btScalar pitch; b3Scalar pitch;
btScalar roll; b3Scalar roll;
}; };
Euler euler_out; Euler euler_out;
@@ -533,18 +533,18 @@ public:
euler_out2.yaw = 0; euler_out2.yaw = 0;
// From difference of angles formula // From difference of angles formula
btScalar delta = btAtan2(m_el[0].getX(),m_el[0].getZ()); b3Scalar delta = btAtan2(m_el[0].getX(),m_el[0].getZ());
if (m_el[2].getX() > 0) //gimbal locked up if (m_el[2].getX() > 0) //gimbal locked up
{ {
euler_out.pitch = SIMD_PI / btScalar(2.0); euler_out.pitch = SIMD_PI / b3Scalar(2.0);
euler_out2.pitch = SIMD_PI / btScalar(2.0); euler_out2.pitch = SIMD_PI / b3Scalar(2.0);
euler_out.roll = euler_out.pitch + delta; euler_out.roll = euler_out.pitch + delta;
euler_out2.roll = euler_out.pitch + delta; euler_out2.roll = euler_out.pitch + delta;
} }
else // gimbal locked down else // gimbal locked down
{ {
euler_out.pitch = -SIMD_PI / btScalar(2.0); euler_out.pitch = -SIMD_PI / b3Scalar(2.0);
euler_out2.pitch = -SIMD_PI / btScalar(2.0); euler_out2.pitch = -SIMD_PI / b3Scalar(2.0);
euler_out.roll = -euler_out.pitch + delta; euler_out.roll = -euler_out.pitch + delta;
euler_out2.roll = -euler_out.pitch + delta; euler_out2.roll = -euler_out.pitch + delta;
} }
@@ -582,12 +582,12 @@ public:
/**@brief Create a scaled copy of the matrix /**@brief Create a scaled copy of the matrix
* @param s Scaling vector The elements of the vector will scale each column */ * @param s Scaling vector The elements of the vector will scale each column */
btMatrix3x3 scaled(const btVector3& s) const b3Matrix3x3 scaled(const b3Vector3& s) const
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON)
return btMatrix3x3(m_el[0] * s, m_el[1] * s, m_el[2] * s); return b3Matrix3x3(m_el[0] * s, m_el[1] * s, m_el[2] * s);
#else #else
return btMatrix3x3( return b3Matrix3x3(
m_el[0].getX() * s.getX(), m_el[0].getY() * s.getY(), m_el[0].getZ() * s.getZ(), m_el[0].getX() * s.getX(), m_el[0].getY() * s.getY(), m_el[0].getZ() * s.getZ(),
m_el[1].getX() * s.getX(), m_el[1].getY() * s.getY(), m_el[1].getZ() * s.getZ(), m_el[1].getX() * s.getX(), m_el[1].getY() * s.getY(), m_el[1].getZ() * s.getZ(),
m_el[2].getX() * s.getX(), m_el[2].getY() * s.getY(), m_el[2].getZ() * s.getZ()); m_el[2].getX() * s.getX(), m_el[2].getY() * s.getY(), m_el[2].getZ() * s.getZ());
@@ -595,28 +595,28 @@ public:
} }
/**@brief Return the determinant of the matrix */ /**@brief Return the determinant of the matrix */
btScalar determinant() const; b3Scalar determinant() const;
/**@brief Return the adjoint of the matrix */ /**@brief Return the adjoint of the matrix */
btMatrix3x3 adjoint() const; b3Matrix3x3 adjoint() const;
/**@brief Return the matrix with all values non negative */ /**@brief Return the matrix with all values non negative */
btMatrix3x3 absolute() const; b3Matrix3x3 absolute() const;
/**@brief Return the transpose of the matrix */ /**@brief Return the transpose of the matrix */
btMatrix3x3 transpose() const; b3Matrix3x3 transpose() const;
/**@brief Return the inverse of the matrix */ /**@brief Return the inverse of the matrix */
btMatrix3x3 inverse() const; b3Matrix3x3 inverse() const;
btMatrix3x3 transposeTimes(const btMatrix3x3& m) const; b3Matrix3x3 transposeTimes(const b3Matrix3x3& m) const;
btMatrix3x3 timesTranspose(const btMatrix3x3& m) const; b3Matrix3x3 timesTranspose(const b3Matrix3x3& m) const;
SIMD_FORCE_INLINE btScalar tdotx(const btVector3& v) const SIMD_FORCE_INLINE b3Scalar tdotx(const b3Vector3& v) const
{ {
return m_el[0].getX() * v.getX() + m_el[1].getX() * v.getY() + m_el[2].getX() * v.getZ(); return m_el[0].getX() * v.getX() + m_el[1].getX() * v.getY() + m_el[2].getX() * v.getZ();
} }
SIMD_FORCE_INLINE btScalar tdoty(const btVector3& v) const SIMD_FORCE_INLINE b3Scalar tdoty(const b3Vector3& v) const
{ {
return m_el[0].getY() * v.getX() + m_el[1].getY() * v.getY() + m_el[2].getY() * v.getZ(); return m_el[0].getY() * v.getX() + m_el[1].getY() * v.getY() + m_el[2].getY() * v.getZ();
} }
SIMD_FORCE_INLINE btScalar tdotz(const btVector3& v) const SIMD_FORCE_INLINE b3Scalar tdotz(const b3Vector3& v) const
{ {
return m_el[0].getZ() * v.getX() + m_el[1].getZ() * v.getY() + m_el[2].getZ() * v.getZ(); return m_el[0].getZ() * v.getX() + m_el[1].getZ() * v.getY() + m_el[2].getZ() * v.getZ();
} }
@@ -631,7 +631,7 @@ public:
* *
* Note that this matrix is assumed to be symmetric. * Note that this matrix is assumed to be symmetric.
*/ */
void diagonalize(btMatrix3x3& rot, btScalar threshold, int maxSteps) void diagonalize(b3Matrix3x3& rot, b3Scalar threshold, int maxSteps)
{ {
rot.setIdentity(); rot.setIdentity();
for (int step = maxSteps; step > 0; step--) for (int step = maxSteps; step > 0; step--)
@@ -640,8 +640,8 @@ public:
int p = 0; int p = 0;
int q = 1; int q = 1;
int r = 2; int r = 2;
btScalar max = btFabs(m_el[0][1]); b3Scalar max = btFabs(m_el[0][1]);
btScalar v = btFabs(m_el[0][2]); b3Scalar v = btFabs(m_el[0][2]);
if (v > max) if (v > max)
{ {
q = 2; q = 2;
@@ -657,7 +657,7 @@ public:
max = v; max = v;
} }
btScalar t = threshold * (btFabs(m_el[0][0]) + btFabs(m_el[1][1]) + btFabs(m_el[2][2])); b3Scalar t = threshold * (btFabs(m_el[0][0]) + btFabs(m_el[1][1]) + btFabs(m_el[2][2]));
if (max <= t) if (max <= t)
{ {
if (max <= SIMD_EPSILON * t) if (max <= SIMD_EPSILON * t)
@@ -668,12 +668,12 @@ public:
} }
// compute Jacobi rotation J which leads to a zero for element [p][q] // compute Jacobi rotation J which leads to a zero for element [p][q]
btScalar mpq = m_el[p][q]; b3Scalar mpq = m_el[p][q];
btScalar theta = (m_el[q][q] - m_el[p][p]) / (2 * mpq); b3Scalar theta = (m_el[q][q] - m_el[p][p]) / (2 * mpq);
btScalar theta2 = theta * theta; b3Scalar theta2 = theta * theta;
btScalar cos; b3Scalar cos;
btScalar sin; b3Scalar sin;
if (theta2 * theta2 < btScalar(10 / SIMD_EPSILON)) if (theta2 * theta2 < b3Scalar(10 / SIMD_EPSILON))
{ {
t = (theta >= 0) ? 1 / (theta + btSqrt(1 + theta2)) t = (theta >= 0) ? 1 / (theta + btSqrt(1 + theta2))
: 1 / (theta - btSqrt(1 + theta2)); : 1 / (theta - btSqrt(1 + theta2));
@@ -683,8 +683,8 @@ public:
else else
{ {
// approximation for large theta-value, i.e., a nearly diagonal matrix // approximation for large theta-value, i.e., a nearly diagonal matrix
t = 1 / (theta * (2 + btScalar(0.5) / theta2)); t = 1 / (theta * (2 + b3Scalar(0.5) / theta2));
cos = 1 - btScalar(0.5) * t * t; cos = 1 - b3Scalar(0.5) * t * t;
sin = cos * t; sin = cos * t;
} }
@@ -692,15 +692,15 @@ public:
m_el[p][q] = m_el[q][p] = 0; m_el[p][q] = m_el[q][p] = 0;
m_el[p][p] -= t * mpq; m_el[p][p] -= t * mpq;
m_el[q][q] += t * mpq; m_el[q][q] += t * mpq;
btScalar mrp = m_el[r][p]; b3Scalar mrp = m_el[r][p];
btScalar mrq = m_el[r][q]; b3Scalar mrq = m_el[r][q];
m_el[r][p] = m_el[p][r] = cos * mrp - sin * mrq; m_el[r][p] = m_el[p][r] = cos * mrp - sin * mrq;
m_el[r][q] = m_el[q][r] = cos * mrq + sin * mrp; m_el[r][q] = m_el[q][r] = cos * mrq + sin * mrp;
// apply rotation to rot (rot = rot * J) // apply rotation to rot (rot = rot * J)
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
btVector3& row = rot[i]; b3Vector3& row = rot[i];
mrp = row[p]; mrp = row[p];
mrq = row[q]; mrq = row[q];
row[p] = cos * mrp - sin * mrq; row[p] = cos * mrp - sin * mrq;
@@ -719,7 +719,7 @@ public:
* @param c1 The second column to use for calculating the cofactor * @param c1 The second column to use for calculating the cofactor
* See http://en.wikipedia.org/wiki/Cofactor_(linear_algebra) for more details * See http://en.wikipedia.org/wiki/Cofactor_(linear_algebra) for more details
*/ */
btScalar cofac(int r1, int c1, int r2, int c2) const b3Scalar cofac(int r1, int c1, int r2, int c2) const
{ {
return m_el[r1][c1] * m_el[r2][c2] - m_el[r1][c2] * m_el[r2][c1]; return m_el[r1][c1] * m_el[r2][c2] - m_el[r1][c2] * m_el[r2][c1];
} }
@@ -737,8 +737,8 @@ public:
}; };
SIMD_FORCE_INLINE btMatrix3x3& SIMD_FORCE_INLINE b3Matrix3x3&
btMatrix3x3::operator*=(const btMatrix3x3& m) b3Matrix3x3::operator*=(const b3Matrix3x3& m)
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 rv00, rv01, rv02; __m128 rv00, rv01, rv02;
@@ -827,8 +827,8 @@ btMatrix3x3::operator*=(const btMatrix3x3& m)
return *this; return *this;
} }
SIMD_FORCE_INLINE btMatrix3x3& SIMD_FORCE_INLINE b3Matrix3x3&
btMatrix3x3::operator+=(const btMatrix3x3& m) b3Matrix3x3::operator+=(const b3Matrix3x3& m)
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON)
m_el[0].mVec128 = m_el[0].mVec128 + m.m_el[0].mVec128; m_el[0].mVec128 = m_el[0].mVec128 + m.m_el[0].mVec128;
@@ -849,38 +849,38 @@ btMatrix3x3::operator+=(const btMatrix3x3& m)
return *this; return *this;
} }
SIMD_FORCE_INLINE btMatrix3x3 SIMD_FORCE_INLINE b3Matrix3x3
operator*(const btMatrix3x3& m, const btScalar & k) operator*(const b3Matrix3x3& m, const b3Scalar & k)
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))
__m128 vk = bt_splat_ps(_mm_load_ss((float *)&k), 0x80); __m128 vk = bt_splat_ps(_mm_load_ss((float *)&k), 0x80);
return btMatrix3x3( return b3Matrix3x3(
_mm_mul_ps(m[0].mVec128, vk), _mm_mul_ps(m[0].mVec128, vk),
_mm_mul_ps(m[1].mVec128, vk), _mm_mul_ps(m[1].mVec128, vk),
_mm_mul_ps(m[2].mVec128, vk)); _mm_mul_ps(m[2].mVec128, vk));
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
return btMatrix3x3( return b3Matrix3x3(
vmulq_n_f32(m[0].mVec128, k), vmulq_n_f32(m[0].mVec128, k),
vmulq_n_f32(m[1].mVec128, k), vmulq_n_f32(m[1].mVec128, k),
vmulq_n_f32(m[2].mVec128, k)); vmulq_n_f32(m[2].mVec128, k));
#else #else
return btMatrix3x3( return b3Matrix3x3(
m[0].getX()*k,m[0].getY()*k,m[0].getZ()*k, m[0].getX()*k,m[0].getY()*k,m[0].getZ()*k,
m[1].getX()*k,m[1].getY()*k,m[1].getZ()*k, m[1].getX()*k,m[1].getY()*k,m[1].getZ()*k,
m[2].getX()*k,m[2].getY()*k,m[2].getZ()*k); m[2].getX()*k,m[2].getY()*k,m[2].getZ()*k);
#endif #endif
} }
SIMD_FORCE_INLINE btMatrix3x3 SIMD_FORCE_INLINE b3Matrix3x3
operator+(const btMatrix3x3& m1, const btMatrix3x3& m2) operator+(const b3Matrix3x3& m1, const b3Matrix3x3& m2)
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON)
return btMatrix3x3( return b3Matrix3x3(
m1[0].mVec128 + m2[0].mVec128, m1[0].mVec128 + m2[0].mVec128,
m1[1].mVec128 + m2[1].mVec128, m1[1].mVec128 + m2[1].mVec128,
m1[2].mVec128 + m2[2].mVec128); m1[2].mVec128 + m2[2].mVec128);
#else #else
return btMatrix3x3( return b3Matrix3x3(
m1[0][0]+m2[0][0], m1[0][0]+m2[0][0],
m1[0][1]+m2[0][1], m1[0][1]+m2[0][1],
m1[0][2]+m2[0][2], m1[0][2]+m2[0][2],
@@ -895,16 +895,16 @@ operator+(const btMatrix3x3& m1, const btMatrix3x3& m2)
#endif #endif
} }
SIMD_FORCE_INLINE btMatrix3x3 SIMD_FORCE_INLINE b3Matrix3x3
operator-(const btMatrix3x3& m1, const btMatrix3x3& m2) operator-(const b3Matrix3x3& m1, const b3Matrix3x3& m2)
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON)
return btMatrix3x3( return b3Matrix3x3(
m1[0].mVec128 - m2[0].mVec128, m1[0].mVec128 - m2[0].mVec128,
m1[1].mVec128 - m2[1].mVec128, m1[1].mVec128 - m2[1].mVec128,
m1[2].mVec128 - m2[2].mVec128); m1[2].mVec128 - m2[2].mVec128);
#else #else
return btMatrix3x3( return b3Matrix3x3(
m1[0][0]-m2[0][0], m1[0][0]-m2[0][0],
m1[0][1]-m2[0][1], m1[0][1]-m2[0][1],
m1[0][2]-m2[0][2], m1[0][2]-m2[0][2],
@@ -920,8 +920,8 @@ operator-(const btMatrix3x3& m1, const btMatrix3x3& m2)
} }
SIMD_FORCE_INLINE btMatrix3x3& SIMD_FORCE_INLINE b3Matrix3x3&
btMatrix3x3::operator-=(const btMatrix3x3& m) b3Matrix3x3::operator-=(const b3Matrix3x3& m)
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON)
m_el[0].mVec128 = m_el[0].mVec128 - m.m_el[0].mVec128; m_el[0].mVec128 = m_el[0].mVec128 - m.m_el[0].mVec128;
@@ -943,36 +943,36 @@ btMatrix3x3::operator-=(const btMatrix3x3& m)
} }
SIMD_FORCE_INLINE btScalar SIMD_FORCE_INLINE b3Scalar
btMatrix3x3::determinant() const b3Matrix3x3::determinant() const
{ {
return btTriple((*this)[0], (*this)[1], (*this)[2]); return btTriple((*this)[0], (*this)[1], (*this)[2]);
} }
SIMD_FORCE_INLINE btMatrix3x3 SIMD_FORCE_INLINE b3Matrix3x3
btMatrix3x3::absolute() const b3Matrix3x3::absolute() const
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))
return btMatrix3x3( return b3Matrix3x3(
_mm_and_ps(m_el[0].mVec128, btvAbsfMask), _mm_and_ps(m_el[0].mVec128, btvAbsfMask),
_mm_and_ps(m_el[1].mVec128, btvAbsfMask), _mm_and_ps(m_el[1].mVec128, btvAbsfMask),
_mm_and_ps(m_el[2].mVec128, btvAbsfMask)); _mm_and_ps(m_el[2].mVec128, btvAbsfMask));
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
return btMatrix3x3( return b3Matrix3x3(
(float32x4_t)vandq_s32((int32x4_t)m_el[0].mVec128, btv3AbsMask), (float32x4_t)vandq_s32((int32x4_t)m_el[0].mVec128, btv3AbsMask),
(float32x4_t)vandq_s32((int32x4_t)m_el[1].mVec128, btv3AbsMask), (float32x4_t)vandq_s32((int32x4_t)m_el[1].mVec128, btv3AbsMask),
(float32x4_t)vandq_s32((int32x4_t)m_el[2].mVec128, btv3AbsMask)); (float32x4_t)vandq_s32((int32x4_t)m_el[2].mVec128, btv3AbsMask));
#else #else
return btMatrix3x3( return b3Matrix3x3(
btFabs(m_el[0].getX()), btFabs(m_el[0].getY()), btFabs(m_el[0].getZ()), btFabs(m_el[0].getX()), btFabs(m_el[0].getY()), btFabs(m_el[0].getZ()),
btFabs(m_el[1].getX()), btFabs(m_el[1].getY()), btFabs(m_el[1].getZ()), btFabs(m_el[1].getX()), btFabs(m_el[1].getY()), btFabs(m_el[1].getZ()),
btFabs(m_el[2].getX()), btFabs(m_el[2].getY()), btFabs(m_el[2].getZ())); btFabs(m_el[2].getX()), btFabs(m_el[2].getY()), btFabs(m_el[2].getZ()));
#endif #endif
} }
SIMD_FORCE_INLINE btMatrix3x3 SIMD_FORCE_INLINE b3Matrix3x3
btMatrix3x3::transpose() const b3Matrix3x3::transpose() const
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))
__m128 v0 = m_el[0].mVec128; __m128 v0 = m_el[0].mVec128;
@@ -990,7 +990,7 @@ btMatrix3x3::transpose() const
v2 = btCastdTo128f(_mm_move_sd(btCastfTo128d(v2), btCastfTo128d(vT))); // z0 z1 z2 0 v2 = btCastdTo128f(_mm_move_sd(btCastfTo128d(v2), btCastfTo128d(vT))); // z0 z1 z2 0
return btMatrix3x3( v0, v1, v2 ); return b3Matrix3x3( v0, v1, v2 );
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
// note: zeros the w channel. We can preserve it at the cost of two more vtrn instructions. // note: zeros the w channel. We can preserve it at the cost of two more vtrn instructions.
static const uint32x2_t zMask = (const uint32x2_t) {-1, 0 }; static const uint32x2_t zMask = (const uint32x2_t) {-1, 0 };
@@ -1000,36 +1000,36 @@ btMatrix3x3::transpose() const
float32x4_t v1 = vcombine_f32( vget_low_f32(top.val[1]), bl.val[1] ); float32x4_t v1 = vcombine_f32( vget_low_f32(top.val[1]), bl.val[1] );
float32x2_t q = (float32x2_t) vand_u32( (uint32x2_t) vget_high_f32( m_el[2].mVec128), zMask ); float32x2_t q = (float32x2_t) vand_u32( (uint32x2_t) vget_high_f32( m_el[2].mVec128), zMask );
float32x4_t v2 = vcombine_f32( vget_high_f32(top.val[0]), q ); // z0 z1 z2 0 float32x4_t v2 = vcombine_f32( vget_high_f32(top.val[0]), q ); // z0 z1 z2 0
return btMatrix3x3( v0, v1, v2 ); return b3Matrix3x3( v0, v1, v2 );
#else #else
return btMatrix3x3( m_el[0].getX(), m_el[1].getX(), m_el[2].getX(), return b3Matrix3x3( m_el[0].getX(), m_el[1].getX(), m_el[2].getX(),
m_el[0].getY(), m_el[1].getY(), m_el[2].getY(), m_el[0].getY(), m_el[1].getY(), m_el[2].getY(),
m_el[0].getZ(), m_el[1].getZ(), m_el[2].getZ()); m_el[0].getZ(), m_el[1].getZ(), m_el[2].getZ());
#endif #endif
} }
SIMD_FORCE_INLINE btMatrix3x3 SIMD_FORCE_INLINE b3Matrix3x3
btMatrix3x3::adjoint() const b3Matrix3x3::adjoint() const
{ {
return btMatrix3x3(cofac(1, 1, 2, 2), cofac(0, 2, 2, 1), cofac(0, 1, 1, 2), return b3Matrix3x3(cofac(1, 1, 2, 2), cofac(0, 2, 2, 1), cofac(0, 1, 1, 2),
cofac(1, 2, 2, 0), cofac(0, 0, 2, 2), cofac(0, 2, 1, 0), cofac(1, 2, 2, 0), cofac(0, 0, 2, 2), cofac(0, 2, 1, 0),
cofac(1, 0, 2, 1), cofac(0, 1, 2, 0), cofac(0, 0, 1, 1)); cofac(1, 0, 2, 1), cofac(0, 1, 2, 0), cofac(0, 0, 1, 1));
} }
SIMD_FORCE_INLINE btMatrix3x3 SIMD_FORCE_INLINE b3Matrix3x3
btMatrix3x3::inverse() const b3Matrix3x3::inverse() const
{ {
btVector3 co(cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1)); b3Vector3 co(cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1));
btScalar det = (*this)[0].dot(co); b3Scalar det = (*this)[0].dot(co);
btFullAssert(det != btScalar(0.0)); btFullAssert(det != b3Scalar(0.0));
btScalar s = btScalar(1.0) / det; b3Scalar s = b3Scalar(1.0) / det;
return btMatrix3x3(co.getX() * s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s, return b3Matrix3x3(co.getX() * s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s,
co.getY() * s, cofac(0, 0, 2, 2) * s, cofac(0, 2, 1, 0) * s, co.getY() * s, cofac(0, 0, 2, 2) * s, cofac(0, 2, 1, 0) * s,
co.getZ() * s, cofac(0, 1, 2, 0) * s, cofac(0, 0, 1, 1) * s); co.getZ() * s, cofac(0, 1, 2, 0) * s, cofac(0, 0, 1, 1) * s);
} }
SIMD_FORCE_INLINE btMatrix3x3 SIMD_FORCE_INLINE b3Matrix3x3
btMatrix3x3::transposeTimes(const btMatrix3x3& m) const b3Matrix3x3::transposeTimes(const b3Matrix3x3& m) const
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))
// zeros w // zeros w
@@ -1049,7 +1049,7 @@ btMatrix3x3::transposeTimes(const btMatrix3x3& m) const
r0 = _mm_add_ps( r0, _mm_mul_ps(m2, _mm_shuffle_ps(row, row, 0))); r0 = _mm_add_ps( r0, _mm_mul_ps(m2, _mm_shuffle_ps(row, row, 0)));
r1 = _mm_add_ps( r1, _mm_mul_ps(m2, _mm_shuffle_ps(row, row, 0x55))); r1 = _mm_add_ps( r1, _mm_mul_ps(m2, _mm_shuffle_ps(row, row, 0x55)));
r2 = _mm_add_ps( r2, _mm_mul_ps(m2, _mm_shuffle_ps(row, row, 0xaa))); r2 = _mm_add_ps( r2, _mm_mul_ps(m2, _mm_shuffle_ps(row, row, 0xaa)));
return btMatrix3x3( r0, r1, r2 ); return b3Matrix3x3( r0, r1, r2 );
#elif defined BT_USE_NEON #elif defined BT_USE_NEON
// zeros w // zeros w
@@ -1069,9 +1069,9 @@ btMatrix3x3::transposeTimes(const btMatrix3x3& m) const
r0 = vmlaq_lane_f32( r0, m2, vget_low_f32(row), 0); r0 = vmlaq_lane_f32( r0, m2, vget_low_f32(row), 0);
r1 = vmlaq_lane_f32( r1, m2, vget_low_f32(row), 1); r1 = vmlaq_lane_f32( r1, m2, vget_low_f32(row), 1);
r2 = vmlaq_lane_f32( r2, m2, vget_high_f32(row), 0); r2 = vmlaq_lane_f32( r2, m2, vget_high_f32(row), 0);
return btMatrix3x3( r0, r1, r2 ); return b3Matrix3x3( r0, r1, r2 );
#else #else
return btMatrix3x3( return b3Matrix3x3(
m_el[0].getX() * m[0].getX() + m_el[1].getX() * m[1].getX() + m_el[2].getX() * m[2].getX(), m_el[0].getX() * m[0].getX() + m_el[1].getX() * m[1].getX() + m_el[2].getX() * m[2].getX(),
m_el[0].getX() * m[0].getY() + m_el[1].getX() * m[1].getY() + m_el[2].getX() * m[2].getY(), m_el[0].getX() * m[0].getY() + m_el[1].getX() * m[1].getY() + m_el[2].getX() * m[2].getY(),
m_el[0].getX() * m[0].getZ() + m_el[1].getX() * m[1].getZ() + m_el[2].getX() * m[2].getZ(), m_el[0].getX() * m[0].getZ() + m_el[1].getX() * m[1].getZ() + m_el[2].getX() * m[2].getZ(),
@@ -1084,15 +1084,15 @@ btMatrix3x3::transposeTimes(const btMatrix3x3& m) const
#endif #endif
} }
SIMD_FORCE_INLINE btMatrix3x3 SIMD_FORCE_INLINE b3Matrix3x3
btMatrix3x3::timesTranspose(const btMatrix3x3& m) const b3Matrix3x3::timesTranspose(const b3Matrix3x3& m) const
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))
__m128 a0 = m_el[0].mVec128; __m128 a0 = m_el[0].mVec128;
__m128 a1 = m_el[1].mVec128; __m128 a1 = m_el[1].mVec128;
__m128 a2 = m_el[2].mVec128; __m128 a2 = m_el[2].mVec128;
btMatrix3x3 mT = m.transpose(); // we rely on transpose() zeroing w channel so that we don't have to do it here b3Matrix3x3 mT = m.transpose(); // we rely on transpose() zeroing w channel so that we don't have to do it here
__m128 mx = mT[0].mVec128; __m128 mx = mT[0].mVec128;
__m128 my = mT[1].mVec128; __m128 my = mT[1].mVec128;
__m128 mz = mT[2].mVec128; __m128 mz = mT[2].mVec128;
@@ -1106,14 +1106,14 @@ btMatrix3x3::timesTranspose(const btMatrix3x3& m) const
r0 = _mm_add_ps(r0, _mm_mul_ps(mz, _mm_shuffle_ps(a0, a0, 0xaa))); r0 = _mm_add_ps(r0, _mm_mul_ps(mz, _mm_shuffle_ps(a0, a0, 0xaa)));
r1 = _mm_add_ps(r1, _mm_mul_ps(mz, _mm_shuffle_ps(a1, a1, 0xaa))); r1 = _mm_add_ps(r1, _mm_mul_ps(mz, _mm_shuffle_ps(a1, a1, 0xaa)));
r2 = _mm_add_ps(r2, _mm_mul_ps(mz, _mm_shuffle_ps(a2, a2, 0xaa))); r2 = _mm_add_ps(r2, _mm_mul_ps(mz, _mm_shuffle_ps(a2, a2, 0xaa)));
return btMatrix3x3( r0, r1, r2); return b3Matrix3x3( r0, r1, r2);
#elif defined BT_USE_NEON #elif defined BT_USE_NEON
float32x4_t a0 = m_el[0].mVec128; float32x4_t a0 = m_el[0].mVec128;
float32x4_t a1 = m_el[1].mVec128; float32x4_t a1 = m_el[1].mVec128;
float32x4_t a2 = m_el[2].mVec128; float32x4_t a2 = m_el[2].mVec128;
btMatrix3x3 mT = m.transpose(); // we rely on transpose() zeroing w channel so that we don't have to do it here b3Matrix3x3 mT = m.transpose(); // we rely on transpose() zeroing w channel so that we don't have to do it here
float32x4_t mx = mT[0].mVec128; float32x4_t mx = mT[0].mVec128;
float32x4_t my = mT[1].mVec128; float32x4_t my = mT[1].mVec128;
float32x4_t mz = mT[2].mVec128; float32x4_t mz = mT[2].mVec128;
@@ -1127,29 +1127,29 @@ btMatrix3x3::timesTranspose(const btMatrix3x3& m) const
r0 = vmlaq_lane_f32( r0, mz, vget_high_f32(a0), 0); r0 = vmlaq_lane_f32( r0, mz, vget_high_f32(a0), 0);
r1 = vmlaq_lane_f32( r1, mz, vget_high_f32(a1), 0); r1 = vmlaq_lane_f32( r1, mz, vget_high_f32(a1), 0);
r2 = vmlaq_lane_f32( r2, mz, vget_high_f32(a2), 0); r2 = vmlaq_lane_f32( r2, mz, vget_high_f32(a2), 0);
return btMatrix3x3( r0, r1, r2 ); return b3Matrix3x3( r0, r1, r2 );
#else #else
return btMatrix3x3( return b3Matrix3x3(
m_el[0].dot(m[0]), m_el[0].dot(m[1]), m_el[0].dot(m[2]), m_el[0].dot(m[0]), m_el[0].dot(m[1]), m_el[0].dot(m[2]),
m_el[1].dot(m[0]), m_el[1].dot(m[1]), m_el[1].dot(m[2]), m_el[1].dot(m[0]), m_el[1].dot(m[1]), m_el[1].dot(m[2]),
m_el[2].dot(m[0]), m_el[2].dot(m[1]), m_el[2].dot(m[2])); m_el[2].dot(m[0]), m_el[2].dot(m[1]), m_el[2].dot(m[2]));
#endif #endif
} }
SIMD_FORCE_INLINE btVector3 SIMD_FORCE_INLINE b3Vector3
operator*(const btMatrix3x3& m, const btVector3& v) operator*(const b3Matrix3x3& m, const b3Vector3& v)
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))|| defined (BT_USE_NEON)
return v.dot3(m[0], m[1], m[2]); return v.dot3(m[0], m[1], m[2]);
#else #else
return btVector3(m[0].dot(v), m[1].dot(v), m[2].dot(v)); return b3Vector3(m[0].dot(v), m[1].dot(v), m[2].dot(v));
#endif #endif
} }
SIMD_FORCE_INLINE btVector3 SIMD_FORCE_INLINE b3Vector3
operator*(const btVector3& v, const btMatrix3x3& m) operator*(const b3Vector3& v, const b3Matrix3x3& m)
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))
@@ -1164,7 +1164,7 @@ operator*(const btVector3& v, const btMatrix3x3& m)
c0 = _mm_add_ps(c0, c1); c0 = _mm_add_ps(c0, c1);
c2 = _mm_mul_ps(c2, _mm_and_ps(m[2].mVec128, btvFFF0fMask) ); c2 = _mm_mul_ps(c2, _mm_and_ps(m[2].mVec128, btvFFF0fMask) );
return btVector3(_mm_add_ps(c0, c2)); return b3Vector3(_mm_add_ps(c0, c2));
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
const float32x4_t vv = v.mVec128; const float32x4_t vv = v.mVec128;
const float32x2_t vlo = vget_low_f32(vv); const float32x2_t vlo = vget_low_f32(vv);
@@ -1182,14 +1182,14 @@ operator*(const btVector3& v, const btMatrix3x3& m)
c0 = vaddq_f32(c0, c1); c0 = vaddq_f32(c0, c1);
c0 = vaddq_f32(c0, c2); c0 = vaddq_f32(c0, c2);
return btVector3(c0); return b3Vector3(c0);
#else #else
return btVector3(m.tdotx(v), m.tdoty(v), m.tdotz(v)); return b3Vector3(m.tdotx(v), m.tdoty(v), m.tdotz(v));
#endif #endif
} }
SIMD_FORCE_INLINE btMatrix3x3 SIMD_FORCE_INLINE b3Matrix3x3
operator*(const btMatrix3x3& m1, const btMatrix3x3& m2) operator*(const b3Matrix3x3& m1, const b3Matrix3x3& m2)
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))
@@ -1235,7 +1235,7 @@ operator*(const btMatrix3x3& m1, const btMatrix3x3& m2)
c1 = _mm_add_ps(c1, m11); c1 = _mm_add_ps(c1, m11);
c2 = _mm_add_ps(c2, m12); c2 = _mm_add_ps(c2, m12);
return btMatrix3x3(c0, c1, c2); return b3Matrix3x3(c0, c1, c2);
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
@@ -1263,10 +1263,10 @@ operator*(const btMatrix3x3& m1, const btMatrix3x3& m2)
rv1 = vmlaq_lane_f32(rv1, mv2, vget_high_f32(v1), 0); rv1 = vmlaq_lane_f32(rv1, mv2, vget_high_f32(v1), 0);
rv2 = vmlaq_lane_f32(rv2, mv2, vget_high_f32(v2), 0); rv2 = vmlaq_lane_f32(rv2, mv2, vget_high_f32(v2), 0);
return btMatrix3x3(rv0, rv1, rv2); return b3Matrix3x3(rv0, rv1, rv2);
#else #else
return btMatrix3x3( return b3Matrix3x3(
m2.tdotx( m1[0]), m2.tdoty( m1[0]), m2.tdotz( m1[0]), m2.tdotx( m1[0]), m2.tdoty( m1[0]), m2.tdotz( m1[0]),
m2.tdotx( m1[1]), m2.tdoty( m1[1]), m2.tdotz( m1[1]), m2.tdotx( m1[1]), m2.tdoty( m1[1]), m2.tdotz( m1[1]),
m2.tdotx( m1[2]), m2.tdoty( m1[2]), m2.tdotz( m1[2])); m2.tdotx( m1[2]), m2.tdoty( m1[2]), m2.tdotz( m1[2]));
@@ -1274,8 +1274,8 @@ operator*(const btMatrix3x3& m1, const btMatrix3x3& m2)
} }
/* /*
SIMD_FORCE_INLINE btMatrix3x3 btMultTransposeLeft(const btMatrix3x3& m1, const btMatrix3x3& m2) { SIMD_FORCE_INLINE b3Matrix3x3 btMultTransposeLeft(const b3Matrix3x3& m1, const b3Matrix3x3& m2) {
return btMatrix3x3( return b3Matrix3x3(
m1[0][0] * m2[0][0] + m1[1][0] * m2[1][0] + m1[2][0] * m2[2][0], m1[0][0] * m2[0][0] + m1[1][0] * m2[1][0] + m1[2][0] * m2[2][0],
m1[0][0] * m2[0][1] + m1[1][0] * m2[1][1] + m1[2][0] * m2[2][1], m1[0][0] * m2[0][1] + m1[1][0] * m2[1][1] + m1[2][0] * m2[2][1],
m1[0][0] * m2[0][2] + m1[1][0] * m2[1][2] + m1[2][0] * m2[2][2], m1[0][0] * m2[0][2] + m1[1][0] * m2[1][2] + m1[2][0] * m2[2][2],
@@ -1290,7 +1290,7 @@ m1[0][2] * m2[0][2] + m1[1][2] * m2[1][2] + m1[2][2] * m2[2][2]);
/**@brief Equality operator between two matrices /**@brief Equality operator between two matrices
* It will test all elements are equal. */ * It will test all elements are equal. */
SIMD_FORCE_INLINE bool operator==(const btMatrix3x3& m1, const btMatrix3x3& m2) SIMD_FORCE_INLINE bool operator==(const b3Matrix3x3& m1, const b3Matrix3x3& m2)
{ {
#if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)) #if (defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE))
@@ -1327,32 +1327,32 @@ struct btMatrix3x3DoubleData
SIMD_FORCE_INLINE void btMatrix3x3::serialize(struct btMatrix3x3Data& dataOut) const SIMD_FORCE_INLINE void b3Matrix3x3::serialize(struct btMatrix3x3Data& dataOut) const
{ {
for (int i=0;i<3;i++) for (int i=0;i<3;i++)
m_el[i].serialize(dataOut.m_el[i]); m_el[i].serialize(dataOut.m_el[i]);
} }
SIMD_FORCE_INLINE void btMatrix3x3::serializeFloat(struct btMatrix3x3FloatData& dataOut) const SIMD_FORCE_INLINE void b3Matrix3x3::serializeFloat(struct btMatrix3x3FloatData& dataOut) const
{ {
for (int i=0;i<3;i++) for (int i=0;i<3;i++)
m_el[i].serializeFloat(dataOut.m_el[i]); m_el[i].serializeFloat(dataOut.m_el[i]);
} }
SIMD_FORCE_INLINE void btMatrix3x3::deSerialize(const struct btMatrix3x3Data& dataIn) SIMD_FORCE_INLINE void b3Matrix3x3::deSerialize(const struct btMatrix3x3Data& dataIn)
{ {
for (int i=0;i<3;i++) for (int i=0;i<3;i++)
m_el[i].deSerialize(dataIn.m_el[i]); m_el[i].deSerialize(dataIn.m_el[i]);
} }
SIMD_FORCE_INLINE void btMatrix3x3::deSerializeFloat(const struct btMatrix3x3FloatData& dataIn) SIMD_FORCE_INLINE void b3Matrix3x3::deSerializeFloat(const struct btMatrix3x3FloatData& dataIn)
{ {
for (int i=0;i<3;i++) for (int i=0;i<3;i++)
m_el[i].deSerializeFloat(dataIn.m_el[i]); m_el[i].deSerializeFloat(dataIn.m_el[i]);
} }
SIMD_FORCE_INLINE void btMatrix3x3::deSerializeDouble(const struct btMatrix3x3DoubleData& dataIn) SIMD_FORCE_INLINE void b3Matrix3x3::deSerializeDouble(const struct btMatrix3x3DoubleData& dataIn)
{ {
for (int i=0;i<3;i++) for (int i=0;i<3;i++)
m_el[i].deSerializeDouble(dataIn.m_el[i]); m_el[i].deSerializeDouble(dataIn.m_el[i]);

View File

@@ -17,7 +17,7 @@ subject to the following restrictions:
#ifndef BT_GEN_MINMAX_H #ifndef BT_GEN_MINMAX_H
#define BT_GEN_MINMAX_H #define BT_GEN_MINMAX_H
#include "btScalar.h" #include "b3Scalar.h"
template <class T> template <class T>
SIMD_FORCE_INLINE const T& btMin(const T& a, const T& b) SIMD_FORCE_INLINE const T& btMin(const T& a, const T& b)

View File

@@ -16,11 +16,11 @@ subject to the following restrictions:
#ifndef _BT_POOL_ALLOCATOR_H #ifndef _BT_POOL_ALLOCATOR_H
#define _BT_POOL_ALLOCATOR_H #define _BT_POOL_ALLOCATOR_H
#include "btScalar.h" #include "b3Scalar.h"
#include "btAlignedAllocator.h" #include "b3AlignedAllocator.h"
///The btPoolAllocator class allows to efficiently allocate a large pool of objects, instead of dynamically allocating them separately. ///The b3PoolAllocator class allows to efficiently allocate a large pool of objects, instead of dynamically allocating them separately.
class btPoolAllocator class b3PoolAllocator
{ {
int m_elemSize; int m_elemSize;
int m_maxElements; int m_maxElements;
@@ -30,7 +30,7 @@ class btPoolAllocator
public: public:
btPoolAllocator(int elemSize, int maxElements) b3PoolAllocator(int elemSize, int maxElements)
:m_elemSize(elemSize), :m_elemSize(elemSize),
m_maxElements(maxElements) m_maxElements(maxElements)
{ {
@@ -47,7 +47,7 @@ public:
*(void**)p = 0; *(void**)p = 0;
} }
~btPoolAllocator() ~b3PoolAllocator()
{ {
btAlignedFree( m_pool); btAlignedFree( m_pool);
} }

View File

@@ -16,8 +16,8 @@ subject to the following restrictions:
#ifndef BT_SIMD_QUADWORD_H #ifndef BT_SIMD_QUADWORD_H
#define BT_SIMD_QUADWORD_H #define BT_SIMD_QUADWORD_H
#include "btScalar.h" #include "b3Scalar.h"
#include "btMinMax.h" #include "b3MinMax.h"
@@ -27,13 +27,13 @@ subject to the following restrictions:
#include <altivec.h> #include <altivec.h>
#endif #endif
/**@brief The btQuadWord class is base class for btVector3 and btQuaternion. /**@brief The b3QuadWord class is base class for b3Vector3 and b3Quaternion.
* Some issues under PS3 Linux with IBM 2.1 SDK, gcc compiler prevent from using aligned quadword. * Some issues under PS3 Linux with IBM 2.1 SDK, gcc compiler prevent from using aligned quadword.
*/ */
#ifndef USE_LIBSPE2 #ifndef USE_LIBSPE2
ATTRIBUTE_ALIGNED16(class) btQuadWord ATTRIBUTE_ALIGNED16(class) b3QuadWord
#else #else
class btQuadWord class b3QuadWord
#endif #endif
{ {
protected: protected:
@@ -41,7 +41,7 @@ protected:
#if defined (__SPU__) && defined (__CELLOS_LV2__) #if defined (__SPU__) && defined (__CELLOS_LV2__)
union { union {
vec_float4 mVec128; vec_float4 mVec128;
btScalar m_floats[4]; b3Scalar m_floats[4];
}; };
public: public:
vec_float4 get128() const vec_float4 get128() const
@@ -54,8 +54,8 @@ public:
#if defined(BT_USE_SSE) || defined(BT_USE_NEON) #if defined(BT_USE_SSE) || defined(BT_USE_NEON)
union { union {
btSimdFloat4 mVec128; btSimdFloat4 mVec128;
btScalar m_floats[4]; b3Scalar m_floats[4];
struct {btScalar x,y,z,w;}; struct {b3Scalar x,y,z,w;};
}; };
public: public:
SIMD_FORCE_INLINE btSimdFloat4 get128() const SIMD_FORCE_INLINE btSimdFloat4 get128() const
@@ -67,7 +67,7 @@ public:
mVec128 = v128; mVec128 = v128;
} }
#else #else
btScalar m_floats[4]; b3Scalar m_floats[4];
#endif // BT_USE_SSE #endif // BT_USE_SSE
#endif //__CELLOS_LV2__ __SPU__ #endif //__CELLOS_LV2__ __SPU__
@@ -77,20 +77,20 @@ public:
#if defined(BT_USE_SSE) || defined(BT_USE_NEON) #if defined(BT_USE_SSE) || defined(BT_USE_NEON)
// Set Vector // Set Vector
SIMD_FORCE_INLINE btQuadWord(const btSimdFloat4 vec) SIMD_FORCE_INLINE b3QuadWord(const btSimdFloat4 vec)
{ {
mVec128 = vec; mVec128 = vec;
} }
// Copy constructor // Copy constructor
SIMD_FORCE_INLINE btQuadWord(const btQuadWord& rhs) SIMD_FORCE_INLINE b3QuadWord(const b3QuadWord& rhs)
{ {
mVec128 = rhs.mVec128; mVec128 = rhs.mVec128;
} }
// Assignment Operator // Assignment Operator
SIMD_FORCE_INLINE btQuadWord& SIMD_FORCE_INLINE b3QuadWord&
operator=(const btQuadWord& v) operator=(const b3QuadWord& v)
{ {
mVec128 = v.mVec128; mVec128 = v.mVec128;
@@ -100,29 +100,29 @@ public:
#endif #endif
/**@brief Return the x value */ /**@brief Return the x value */
SIMD_FORCE_INLINE const btScalar& getX() const { return m_floats[0]; } SIMD_FORCE_INLINE const b3Scalar& getX() const { return m_floats[0]; }
/**@brief Return the y value */ /**@brief Return the y value */
SIMD_FORCE_INLINE const btScalar& getY() const { return m_floats[1]; } SIMD_FORCE_INLINE const b3Scalar& getY() const { return m_floats[1]; }
/**@brief Return the z value */ /**@brief Return the z value */
SIMD_FORCE_INLINE const btScalar& getZ() const { return m_floats[2]; } SIMD_FORCE_INLINE const b3Scalar& getZ() const { return m_floats[2]; }
/**@brief Set the x value */ /**@brief Set the x value */
SIMD_FORCE_INLINE void setX(btScalar _x) { m_floats[0] = _x;}; SIMD_FORCE_INLINE void setX(b3Scalar _x) { m_floats[0] = _x;};
/**@brief Set the y value */ /**@brief Set the y value */
SIMD_FORCE_INLINE void setY(btScalar _y) { m_floats[1] = _y;}; SIMD_FORCE_INLINE void setY(b3Scalar _y) { m_floats[1] = _y;};
/**@brief Set the z value */ /**@brief Set the z value */
SIMD_FORCE_INLINE void setZ(btScalar _z) { m_floats[2] = _z;}; SIMD_FORCE_INLINE void setZ(b3Scalar _z) { m_floats[2] = _z;};
/**@brief Set the w value */ /**@brief Set the w value */
SIMD_FORCE_INLINE void setW(btScalar _w) { m_floats[3] = _w;}; SIMD_FORCE_INLINE void setW(b3Scalar _w) { m_floats[3] = _w;};
/**@brief Return the x value */ /**@brief Return the x value */
//SIMD_FORCE_INLINE btScalar& operator[](int i) { return (&m_floats[0])[i]; } //SIMD_FORCE_INLINE b3Scalar& operator[](int i) { return (&m_floats[0])[i]; }
//SIMD_FORCE_INLINE const btScalar& operator[](int i) const { return (&m_floats[0])[i]; } //SIMD_FORCE_INLINE const b3Scalar& operator[](int i) const { return (&m_floats[0])[i]; }
///operator btScalar*() replaces operator[], using implicit conversion. We added operator != and operator == to avoid pointer comparisons. ///operator b3Scalar*() replaces operator[], using implicit conversion. We added operator != and operator == to avoid pointer comparisons.
SIMD_FORCE_INLINE operator btScalar *() { return &m_floats[0]; } SIMD_FORCE_INLINE operator b3Scalar *() { return &m_floats[0]; }
SIMD_FORCE_INLINE operator const btScalar *() const { return &m_floats[0]; } SIMD_FORCE_INLINE operator const b3Scalar *() const { return &m_floats[0]; }
SIMD_FORCE_INLINE bool operator==(const btQuadWord& other) const SIMD_FORCE_INLINE bool operator==(const b3QuadWord& other) const
{ {
#ifdef BT_USE_SSE #ifdef BT_USE_SSE
return (0xf == _mm_movemask_ps((__m128)_mm_cmpeq_ps(mVec128, other.mVec128))); return (0xf == _mm_movemask_ps((__m128)_mm_cmpeq_ps(mVec128, other.mVec128)));
@@ -134,7 +134,7 @@ public:
#endif #endif
} }
SIMD_FORCE_INLINE bool operator!=(const btQuadWord& other) const SIMD_FORCE_INLINE bool operator!=(const b3QuadWord& other) const
{ {
return !(*this == other); return !(*this == other);
} }
@@ -144,7 +144,7 @@ public:
* @param y Value of y * @param y Value of y
* @param z Value of z * @param z Value of z
*/ */
SIMD_FORCE_INLINE void setValue(const btScalar& _x, const btScalar& _y, const btScalar& _z) SIMD_FORCE_INLINE void setValue(const b3Scalar& _x, const b3Scalar& _y, const b3Scalar& _z)
{ {
m_floats[0]=_x; m_floats[0]=_x;
m_floats[1]=_y; m_floats[1]=_y;
@@ -152,7 +152,7 @@ public:
m_floats[3] = 0.f; m_floats[3] = 0.f;
} }
/* void getValue(btScalar *m) const /* void getValue(b3Scalar *m) const
{ {
m[0] = m_floats[0]; m[0] = m_floats[0];
m[1] = m_floats[1]; m[1] = m_floats[1];
@@ -165,7 +165,7 @@ public:
* @param z Value of z * @param z Value of z
* @param w Value of w * @param w Value of w
*/ */
SIMD_FORCE_INLINE void setValue(const btScalar& _x, const btScalar& _y, const btScalar& _z,const btScalar& _w) SIMD_FORCE_INLINE void setValue(const b3Scalar& _x, const b3Scalar& _y, const b3Scalar& _z,const b3Scalar& _w)
{ {
m_floats[0]=_x; m_floats[0]=_x;
m_floats[1]=_y; m_floats[1]=_y;
@@ -173,8 +173,8 @@ public:
m_floats[3]=_w; m_floats[3]=_w;
} }
/**@brief No initialization constructor */ /**@brief No initialization constructor */
SIMD_FORCE_INLINE btQuadWord() SIMD_FORCE_INLINE b3QuadWord()
// :m_floats[0](btScalar(0.)),m_floats[1](btScalar(0.)),m_floats[2](btScalar(0.)),m_floats[3](btScalar(0.)) // :m_floats[0](b3Scalar(0.)),m_floats[1](b3Scalar(0.)),m_floats[2](b3Scalar(0.)),m_floats[3](b3Scalar(0.))
{ {
} }
@@ -183,7 +183,7 @@ public:
* @param y Value of y * @param y Value of y
* @param z Value of z * @param z Value of z
*/ */
SIMD_FORCE_INLINE btQuadWord(const btScalar& _x, const btScalar& _y, const btScalar& _z) SIMD_FORCE_INLINE b3QuadWord(const b3Scalar& _x, const b3Scalar& _y, const b3Scalar& _z)
{ {
m_floats[0] = _x, m_floats[1] = _y, m_floats[2] = _z, m_floats[3] = 0.0f; m_floats[0] = _x, m_floats[1] = _y, m_floats[2] = _z, m_floats[3] = 0.0f;
} }
@@ -194,15 +194,15 @@ public:
* @param z Value of z * @param z Value of z
* @param w Value of w * @param w Value of w
*/ */
SIMD_FORCE_INLINE btQuadWord(const btScalar& _x, const btScalar& _y, const btScalar& _z,const btScalar& _w) SIMD_FORCE_INLINE b3QuadWord(const b3Scalar& _x, const b3Scalar& _y, const b3Scalar& _z,const b3Scalar& _w)
{ {
m_floats[0] = _x, m_floats[1] = _y, m_floats[2] = _z, m_floats[3] = _w; m_floats[0] = _x, m_floats[1] = _y, m_floats[2] = _z, m_floats[3] = _w;
} }
/**@brief Set each element to the max of the current values and the values of another btQuadWord /**@brief Set each element to the max of the current values and the values of another b3QuadWord
* @param other The other btQuadWord to compare with * @param other The other b3QuadWord to compare with
*/ */
SIMD_FORCE_INLINE void setMax(const btQuadWord& other) SIMD_FORCE_INLINE void setMax(const b3QuadWord& other)
{ {
#ifdef BT_USE_SSE #ifdef BT_USE_SSE
mVec128 = _mm_max_ps(mVec128, other.mVec128); mVec128 = _mm_max_ps(mVec128, other.mVec128);
@@ -215,10 +215,10 @@ public:
btSetMax(m_floats[3], other.m_floats[3]); btSetMax(m_floats[3], other.m_floats[3]);
#endif #endif
} }
/**@brief Set each element to the min of the current values and the values of another btQuadWord /**@brief Set each element to the min of the current values and the values of another b3QuadWord
* @param other The other btQuadWord to compare with * @param other The other b3QuadWord to compare with
*/ */
SIMD_FORCE_INLINE void setMin(const btQuadWord& other) SIMD_FORCE_INLINE void setMin(const b3QuadWord& other)
{ {
#ifdef BT_USE_SSE #ifdef BT_USE_SSE
mVec128 = _mm_min_ps(mVec128, other.mVec128); mVec128 = _mm_min_ps(mVec128, other.mVec128);

View File

@@ -18,8 +18,8 @@ subject to the following restrictions:
#define BT_SIMD__QUATERNION_H_ #define BT_SIMD__QUATERNION_H_
#include "btVector3.h" #include "b3Vector3.h"
#include "btQuadWord.h" #include "b3QuadWord.h"
@@ -38,28 +38,28 @@ const btSimdFloat4 ATTRIBUTE_ALIGNED16(vPPPM) = {+0.0f, +0.0f, +0.0f, -0.0f};
#endif #endif
/**@brief The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatrix3x3, btVector3 and btTransform. */ /**@brief The b3Quaternion implements quaternion to perform linear algebra rotations in combination with b3Matrix3x3, b3Vector3 and b3Transform. */
class btQuaternion : public btQuadWord { class b3Quaternion : public b3QuadWord {
public: public:
/**@brief No initialization constructor */ /**@brief No initialization constructor */
btQuaternion() {} b3Quaternion() {}
#if (defined(BT_USE_SSE_IN_API) && defined(BT_USE_SSE))|| defined(BT_USE_NEON) #if (defined(BT_USE_SSE_IN_API) && defined(BT_USE_SSE))|| defined(BT_USE_NEON)
// Set Vector // Set Vector
SIMD_FORCE_INLINE btQuaternion(const btSimdFloat4 vec) SIMD_FORCE_INLINE b3Quaternion(const btSimdFloat4 vec)
{ {
mVec128 = vec; mVec128 = vec;
} }
// Copy constructor // Copy constructor
SIMD_FORCE_INLINE btQuaternion(const btQuaternion& rhs) SIMD_FORCE_INLINE b3Quaternion(const b3Quaternion& rhs)
{ {
mVec128 = rhs.mVec128; mVec128 = rhs.mVec128;
} }
// Assignment Operator // Assignment Operator
SIMD_FORCE_INLINE btQuaternion& SIMD_FORCE_INLINE b3Quaternion&
operator=(const btQuaternion& v) operator=(const b3Quaternion& v)
{ {
mVec128 = v.mVec128; mVec128 = v.mVec128;
@@ -68,18 +68,18 @@ public:
#endif #endif
// template <typename btScalar> // template <typename b3Scalar>
// explicit Quaternion(const btScalar *v) : Tuple4<btScalar>(v) {} // explicit Quaternion(const b3Scalar *v) : Tuple4<b3Scalar>(v) {}
/**@brief Constructor from scalars */ /**@brief Constructor from scalars */
btQuaternion(const btScalar& _x, const btScalar& _y, const btScalar& _z, const btScalar& _w) b3Quaternion(const b3Scalar& _x, const b3Scalar& _y, const b3Scalar& _z, const b3Scalar& _w)
: btQuadWord(_x, _y, _z, _w) : b3QuadWord(_x, _y, _z, _w)
{ {
btAssert(!((_x==1.f) && (_y==0.f) && (_z==0.f) && (_w==0.f))); btAssert(!((_x==1.f) && (_y==0.f) && (_z==0.f) && (_w==0.f)));
} }
/**@brief Axis angle Constructor /**@brief Axis angle Constructor
* @param axis The axis which the rotation is around * @param axis The axis which the rotation is around
* @param angle The magnitude of the rotation around the angle (Radians) */ * @param angle The magnitude of the rotation around the angle (Radians) */
btQuaternion(const btVector3& _axis, const btScalar& _angle) b3Quaternion(const b3Vector3& _axis, const b3Scalar& _angle)
{ {
setRotation(_axis, _angle); setRotation(_axis, _angle);
} }
@@ -87,7 +87,7 @@ public:
* @param yaw Angle around Y unless BT_EULER_DEFAULT_ZYX defined then Z * @param yaw Angle around Y unless BT_EULER_DEFAULT_ZYX defined then Z
* @param pitch Angle around X unless BT_EULER_DEFAULT_ZYX defined then Y * @param pitch Angle around X unless BT_EULER_DEFAULT_ZYX defined then Y
* @param roll Angle around Z unless BT_EULER_DEFAULT_ZYX defined then X */ * @param roll Angle around Z unless BT_EULER_DEFAULT_ZYX defined then X */
btQuaternion(const btScalar& yaw, const btScalar& pitch, const btScalar& roll) b3Quaternion(const b3Scalar& yaw, const b3Scalar& pitch, const b3Scalar& roll)
{ {
#ifndef BT_EULER_DEFAULT_ZYX #ifndef BT_EULER_DEFAULT_ZYX
setEuler(yaw, pitch, roll); setEuler(yaw, pitch, roll);
@@ -98,29 +98,29 @@ public:
/**@brief Set the rotation using axis angle notation /**@brief Set the rotation using axis angle notation
* @param axis The axis around which to rotate * @param axis The axis around which to rotate
* @param angle The magnitude of the rotation in Radians */ * @param angle The magnitude of the rotation in Radians */
void setRotation(const btVector3& axis, const btScalar& _angle) void setRotation(const b3Vector3& axis, const b3Scalar& _angle)
{ {
btScalar d = axis.length(); b3Scalar d = axis.length();
btAssert(d != btScalar(0.0)); btAssert(d != b3Scalar(0.0));
btScalar s = btSin(_angle * btScalar(0.5)) / d; b3Scalar s = btSin(_angle * b3Scalar(0.5)) / d;
setValue(axis.getX() * s, axis.getY() * s, axis.getZ() * s, setValue(axis.getX() * s, axis.getY() * s, axis.getZ() * s,
btCos(_angle * btScalar(0.5))); btCos(_angle * b3Scalar(0.5)));
} }
/**@brief Set the quaternion using Euler angles /**@brief Set the quaternion using Euler angles
* @param yaw Angle around Y * @param yaw Angle around Y
* @param pitch Angle around X * @param pitch Angle around X
* @param roll Angle around Z */ * @param roll Angle around Z */
void setEuler(const btScalar& yaw, const btScalar& pitch, const btScalar& roll) void setEuler(const b3Scalar& yaw, const b3Scalar& pitch, const b3Scalar& roll)
{ {
btScalar halfYaw = btScalar(yaw) * btScalar(0.5); b3Scalar halfYaw = b3Scalar(yaw) * b3Scalar(0.5);
btScalar halfPitch = btScalar(pitch) * btScalar(0.5); b3Scalar halfPitch = b3Scalar(pitch) * b3Scalar(0.5);
btScalar halfRoll = btScalar(roll) * btScalar(0.5); b3Scalar halfRoll = b3Scalar(roll) * b3Scalar(0.5);
btScalar cosYaw = btCos(halfYaw); b3Scalar cosYaw = btCos(halfYaw);
btScalar sinYaw = btSin(halfYaw); b3Scalar sinYaw = btSin(halfYaw);
btScalar cosPitch = btCos(halfPitch); b3Scalar cosPitch = btCos(halfPitch);
btScalar sinPitch = btSin(halfPitch); b3Scalar sinPitch = btSin(halfPitch);
btScalar cosRoll = btCos(halfRoll); b3Scalar cosRoll = btCos(halfRoll);
btScalar sinRoll = btSin(halfRoll); b3Scalar sinRoll = btSin(halfRoll);
setValue(cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw, setValue(cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw,
cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw, cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw,
sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw, sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw,
@@ -130,17 +130,17 @@ public:
* @param yaw Angle around Z * @param yaw Angle around Z
* @param pitch Angle around Y * @param pitch Angle around Y
* @param roll Angle around X */ * @param roll Angle around X */
void setEulerZYX(const btScalar& yaw, const btScalar& pitch, const btScalar& roll) void setEulerZYX(const b3Scalar& yaw, const b3Scalar& pitch, const b3Scalar& roll)
{ {
btScalar halfYaw = btScalar(yaw) * btScalar(0.5); b3Scalar halfYaw = b3Scalar(yaw) * b3Scalar(0.5);
btScalar halfPitch = btScalar(pitch) * btScalar(0.5); b3Scalar halfPitch = b3Scalar(pitch) * b3Scalar(0.5);
btScalar halfRoll = btScalar(roll) * btScalar(0.5); b3Scalar halfRoll = b3Scalar(roll) * b3Scalar(0.5);
btScalar cosYaw = btCos(halfYaw); b3Scalar cosYaw = btCos(halfYaw);
btScalar sinYaw = btSin(halfYaw); b3Scalar sinYaw = btSin(halfYaw);
btScalar cosPitch = btCos(halfPitch); b3Scalar cosPitch = btCos(halfPitch);
btScalar sinPitch = btSin(halfPitch); b3Scalar sinPitch = btSin(halfPitch);
btScalar cosRoll = btCos(halfRoll); b3Scalar cosRoll = btCos(halfRoll);
btScalar sinRoll = btSin(halfRoll); b3Scalar sinRoll = btSin(halfRoll);
setValue(sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw, //x setValue(sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw, //x
cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw, //y cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw, //y
cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw, //z cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw, //z
@@ -148,7 +148,7 @@ public:
} }
/**@brief Add two quaternions /**@brief Add two quaternions
* @param q The quaternion to add to this one */ * @param q The quaternion to add to this one */
SIMD_FORCE_INLINE btQuaternion& operator+=(const btQuaternion& q) SIMD_FORCE_INLINE b3Quaternion& operator+=(const b3Quaternion& q)
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
mVec128 = _mm_add_ps(mVec128, q.mVec128); mVec128 = _mm_add_ps(mVec128, q.mVec128);
@@ -165,7 +165,7 @@ public:
/**@brief Subtract out a quaternion /**@brief Subtract out a quaternion
* @param q The quaternion to subtract from this one */ * @param q The quaternion to subtract from this one */
btQuaternion& operator-=(const btQuaternion& q) b3Quaternion& operator-=(const b3Quaternion& q)
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
mVec128 = _mm_sub_ps(mVec128, q.mVec128); mVec128 = _mm_sub_ps(mVec128, q.mVec128);
@@ -182,7 +182,7 @@ public:
/**@brief Scale this quaternion /**@brief Scale this quaternion
* @param s The scalar to scale by */ * @param s The scalar to scale by */
btQuaternion& operator*=(const btScalar& s) b3Quaternion& operator*=(const b3Scalar& s)
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 vs = _mm_load_ss(&s); // (S 0 0 0) __m128 vs = _mm_load_ss(&s); // (S 0 0 0)
@@ -202,7 +202,7 @@ public:
/**@brief Multiply this quaternion by q on the right /**@brief Multiply this quaternion by q on the right
* @param q The other quaternion * @param q The other quaternion
* Equivilant to this = this * q */ * Equivilant to this = this * q */
btQuaternion& operator*=(const btQuaternion& q) b3Quaternion& operator*=(const b3Quaternion& q)
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 vQ2 = q.get128(); __m128 vQ2 = q.get128();
@@ -285,7 +285,7 @@ public:
} }
/**@brief Return the dot product between this quaternion and another /**@brief Return the dot product between this quaternion and another
* @param q The other quaternion */ * @param q The other quaternion */
btScalar dot(const btQuaternion& q) const b3Scalar dot(const b3Quaternion& q) const
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 vd; __m128 vd;
@@ -312,20 +312,20 @@ public:
} }
/**@brief Return the length squared of the quaternion */ /**@brief Return the length squared of the quaternion */
btScalar length2() const b3Scalar length2() const
{ {
return dot(*this); return dot(*this);
} }
/**@brief Return the length of the quaternion */ /**@brief Return the length of the quaternion */
btScalar length() const b3Scalar length() const
{ {
return btSqrt(length2()); return btSqrt(length2());
} }
/**@brief Normalize the quaternion /**@brief Normalize the quaternion
* Such that x^2 + y^2 + z^2 +w^2 = 1 */ * Such that x^2 + y^2 + z^2 +w^2 = 1 */
btQuaternion& normalize() b3Quaternion& normalize()
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 vd; __m128 vd;
@@ -350,127 +350,127 @@ public:
/**@brief Return a scaled version of this quaternion /**@brief Return a scaled version of this quaternion
* @param s The scale factor */ * @param s The scale factor */
SIMD_FORCE_INLINE btQuaternion SIMD_FORCE_INLINE b3Quaternion
operator*(const btScalar& s) const operator*(const b3Scalar& s) const
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 vs = _mm_load_ss(&s); // (S 0 0 0) __m128 vs = _mm_load_ss(&s); // (S 0 0 0)
vs = bt_pshufd_ps(vs, 0x00); // (S S S S) vs = bt_pshufd_ps(vs, 0x00); // (S S S S)
return btQuaternion(_mm_mul_ps(mVec128, vs)); return b3Quaternion(_mm_mul_ps(mVec128, vs));
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
return btQuaternion(vmulq_n_f32(mVec128, s)); return b3Quaternion(vmulq_n_f32(mVec128, s));
#else #else
return btQuaternion(getX() * s, getY() * s, getZ() * s, m_floats[3] * s); return b3Quaternion(getX() * s, getY() * s, getZ() * s, m_floats[3] * s);
#endif #endif
} }
/**@brief Return an inversely scaled versionof this quaternion /**@brief Return an inversely scaled versionof this quaternion
* @param s The inverse scale factor */ * @param s The inverse scale factor */
btQuaternion operator/(const btScalar& s) const b3Quaternion operator/(const b3Scalar& s) const
{ {
btAssert(s != btScalar(0.0)); btAssert(s != b3Scalar(0.0));
return *this * (btScalar(1.0) / s); return *this * (b3Scalar(1.0) / s);
} }
/**@brief Inversely scale this quaternion /**@brief Inversely scale this quaternion
* @param s The scale factor */ * @param s The scale factor */
btQuaternion& operator/=(const btScalar& s) b3Quaternion& operator/=(const b3Scalar& s)
{ {
btAssert(s != btScalar(0.0)); btAssert(s != b3Scalar(0.0));
return *this *= btScalar(1.0) / s; return *this *= b3Scalar(1.0) / s;
} }
/**@brief Return a normalized version of this quaternion */ /**@brief Return a normalized version of this quaternion */
btQuaternion normalized() const b3Quaternion normalized() const
{ {
return *this / length(); return *this / length();
} }
/**@brief Return the angle between this quaternion and the other /**@brief Return the angle between this quaternion and the other
* @param q The other quaternion */ * @param q The other quaternion */
btScalar angle(const btQuaternion& q) const b3Scalar angle(const b3Quaternion& q) const
{ {
btScalar s = btSqrt(length2() * q.length2()); b3Scalar s = btSqrt(length2() * q.length2());
btAssert(s != btScalar(0.0)); btAssert(s != b3Scalar(0.0));
return btAcos(dot(q) / s); return btAcos(dot(q) / s);
} }
/**@brief Return the angle of rotation represented by this quaternion */ /**@brief Return the angle of rotation represented by this quaternion */
btScalar getAngle() const b3Scalar getAngle() const
{ {
btScalar s = btScalar(2.) * btAcos(m_floats[3]); b3Scalar s = b3Scalar(2.) * btAcos(m_floats[3]);
return s; return s;
} }
/**@brief Return the axis of the rotation represented by this quaternion */ /**@brief Return the axis of the rotation represented by this quaternion */
btVector3 getAxis() const b3Vector3 getAxis() const
{ {
btScalar s_squared = 1.f-m_floats[3]*m_floats[3]; b3Scalar s_squared = 1.f-m_floats[3]*m_floats[3];
if (s_squared < btScalar(10.) * SIMD_EPSILON) //Check for divide by zero if (s_squared < b3Scalar(10.) * SIMD_EPSILON) //Check for divide by zero
return btVector3(1.0, 0.0, 0.0); // Arbitrary return b3Vector3(1.0, 0.0, 0.0); // Arbitrary
btScalar s = 1.f/btSqrt(s_squared); b3Scalar s = 1.f/btSqrt(s_squared);
return btVector3(m_floats[0] * s, m_floats[1] * s, m_floats[2] * s); return b3Vector3(m_floats[0] * s, m_floats[1] * s, m_floats[2] * s);
} }
/**@brief Return the inverse of this quaternion */ /**@brief Return the inverse of this quaternion */
btQuaternion inverse() const b3Quaternion inverse() const
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
return btQuaternion(_mm_xor_ps(mVec128, vQInv)); return b3Quaternion(_mm_xor_ps(mVec128, vQInv));
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
return btQuaternion((btSimdFloat4)veorq_s32((int32x4_t)mVec128, (int32x4_t)vQInv)); return b3Quaternion((btSimdFloat4)veorq_s32((int32x4_t)mVec128, (int32x4_t)vQInv));
#else #else
return btQuaternion(-m_floats[0], -m_floats[1], -m_floats[2], m_floats[3]); return b3Quaternion(-m_floats[0], -m_floats[1], -m_floats[2], m_floats[3]);
#endif #endif
} }
/**@brief Return the sum of this quaternion and the other /**@brief Return the sum of this quaternion and the other
* @param q2 The other quaternion */ * @param q2 The other quaternion */
SIMD_FORCE_INLINE btQuaternion SIMD_FORCE_INLINE b3Quaternion
operator+(const btQuaternion& q2) const operator+(const b3Quaternion& q2) const
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
return btQuaternion(_mm_add_ps(mVec128, q2.mVec128)); return b3Quaternion(_mm_add_ps(mVec128, q2.mVec128));
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
return btQuaternion(vaddq_f32(mVec128, q2.mVec128)); return b3Quaternion(vaddq_f32(mVec128, q2.mVec128));
#else #else
const btQuaternion& q1 = *this; const b3Quaternion& q1 = *this;
return btQuaternion(q1.getX() + q2.getX(), q1.getY() + q2.getY(), q1.getZ() + q2.getZ(), q1.m_floats[3] + q2.m_floats[3]); return b3Quaternion(q1.getX() + q2.getX(), q1.getY() + q2.getY(), q1.getZ() + q2.getZ(), q1.m_floats[3] + q2.m_floats[3]);
#endif #endif
} }
/**@brief Return the difference between this quaternion and the other /**@brief Return the difference between this quaternion and the other
* @param q2 The other quaternion */ * @param q2 The other quaternion */
SIMD_FORCE_INLINE btQuaternion SIMD_FORCE_INLINE b3Quaternion
operator-(const btQuaternion& q2) const operator-(const b3Quaternion& q2) const
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
return btQuaternion(_mm_sub_ps(mVec128, q2.mVec128)); return b3Quaternion(_mm_sub_ps(mVec128, q2.mVec128));
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
return btQuaternion(vsubq_f32(mVec128, q2.mVec128)); return b3Quaternion(vsubq_f32(mVec128, q2.mVec128));
#else #else
const btQuaternion& q1 = *this; const b3Quaternion& q1 = *this;
return btQuaternion(q1.getX() - q2.getX(), q1.getY() - q2.getY(), q1.getZ() - q2.getZ(), q1.m_floats[3] - q2.m_floats[3]); return b3Quaternion(q1.getX() - q2.getX(), q1.getY() - q2.getY(), q1.getZ() - q2.getZ(), q1.m_floats[3] - q2.m_floats[3]);
#endif #endif
} }
/**@brief Return the negative of this quaternion /**@brief Return the negative of this quaternion
* This simply negates each element */ * This simply negates each element */
SIMD_FORCE_INLINE btQuaternion operator-() const SIMD_FORCE_INLINE b3Quaternion operator-() const
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
return btQuaternion(_mm_xor_ps(mVec128, btvMzeroMask)); return b3Quaternion(_mm_xor_ps(mVec128, btvMzeroMask));
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
return btQuaternion((btSimdFloat4)veorq_s32((int32x4_t)mVec128, (int32x4_t)btvMzeroMask) ); return b3Quaternion((btSimdFloat4)veorq_s32((int32x4_t)mVec128, (int32x4_t)btvMzeroMask) );
#else #else
const btQuaternion& q2 = *this; const b3Quaternion& q2 = *this;
return btQuaternion( - q2.getX(), - q2.getY(), - q2.getZ(), - q2.m_floats[3]); return b3Quaternion( - q2.getX(), - q2.getY(), - q2.getZ(), - q2.m_floats[3]);
#endif #endif
} }
/**@todo document this and it's use */ /**@todo document this and it's use */
SIMD_FORCE_INLINE btQuaternion farthest( const btQuaternion& qd) const SIMD_FORCE_INLINE b3Quaternion farthest( const b3Quaternion& qd) const
{ {
btQuaternion diff,sum; b3Quaternion diff,sum;
diff = *this - qd; diff = *this - qd;
sum = *this + qd; sum = *this + qd;
if( diff.dot(diff) > sum.dot(sum) ) if( diff.dot(diff) > sum.dot(sum) )
@@ -479,9 +479,9 @@ public:
} }
/**@todo document this and it's use */ /**@todo document this and it's use */
SIMD_FORCE_INLINE btQuaternion nearest( const btQuaternion& qd) const SIMD_FORCE_INLINE b3Quaternion nearest( const b3Quaternion& qd) const
{ {
btQuaternion diff,sum; b3Quaternion diff,sum;
diff = *this - qd; diff = *this - qd;
sum = *this + qd; sum = *this + qd;
if( diff.dot(diff) < sum.dot(sum) ) if( diff.dot(diff) < sum.dot(sum) )
@@ -494,23 +494,23 @@ public:
* @param q The other quaternion to interpolate with * @param q The other quaternion to interpolate with
* @param t The ratio between this and q to interpolate. If t = 0 the result is this, if t=1 the result is q. * @param t The ratio between this and q to interpolate. If t = 0 the result is this, if t=1 the result is q.
* Slerp interpolates assuming constant velocity. */ * Slerp interpolates assuming constant velocity. */
btQuaternion slerp(const btQuaternion& q, const btScalar& t) const b3Quaternion slerp(const b3Quaternion& q, const b3Scalar& t) const
{ {
btScalar magnitude = btSqrt(length2() * q.length2()); b3Scalar magnitude = btSqrt(length2() * q.length2());
btAssert(magnitude > btScalar(0)); btAssert(magnitude > b3Scalar(0));
btScalar product = dot(q) / magnitude; b3Scalar product = dot(q) / magnitude;
if (btFabs(product) < btScalar(1)) if (btFabs(product) < b3Scalar(1))
{ {
// Take care of long angle case see http://en.wikipedia.org/wiki/Slerp // Take care of long angle case see http://en.wikipedia.org/wiki/Slerp
const btScalar sign = (product < 0) ? btScalar(-1) : btScalar(1); const b3Scalar sign = (product < 0) ? b3Scalar(-1) : b3Scalar(1);
const btScalar theta = btAcos(sign * product); const b3Scalar theta = btAcos(sign * product);
const btScalar s1 = btSin(sign * t * theta); const b3Scalar s1 = btSin(sign * t * theta);
const btScalar d = btScalar(1.0) / btSin(theta); const b3Scalar d = b3Scalar(1.0) / btSin(theta);
const btScalar s0 = btSin((btScalar(1.0) - t) * theta); const b3Scalar s0 = btSin((b3Scalar(1.0) - t) * theta);
return btQuaternion( return b3Quaternion(
(m_floats[0] * s0 + q.getX() * s1) * d, (m_floats[0] * s0 + q.getX() * s1) * d,
(m_floats[1] * s0 + q.getY() * s1) * d, (m_floats[1] * s0 + q.getY() * s1) * d,
(m_floats[2] * s0 + q.getZ() * s1) * d, (m_floats[2] * s0 + q.getZ() * s1) * d,
@@ -522,13 +522,13 @@ public:
} }
} }
static const btQuaternion& getIdentity() static const b3Quaternion& getIdentity()
{ {
static const btQuaternion identityQuat(btScalar(0.),btScalar(0.),btScalar(0.),btScalar(1.)); static const b3Quaternion identityQuat(b3Scalar(0.),b3Scalar(0.),b3Scalar(0.),b3Scalar(1.));
return identityQuat; return identityQuat;
} }
SIMD_FORCE_INLINE const btScalar& getW() const { return m_floats[3]; } SIMD_FORCE_INLINE const b3Scalar& getW() const { return m_floats[3]; }
}; };
@@ -538,8 +538,8 @@ public:
/**@brief Return the product of two quaternions */ /**@brief Return the product of two quaternions */
SIMD_FORCE_INLINE btQuaternion SIMD_FORCE_INLINE b3Quaternion
operator*(const btQuaternion& q1, const btQuaternion& q2) operator*(const b3Quaternion& q1, const b3Quaternion& q2)
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 vQ1 = q1.get128(); __m128 vQ1 = q1.get128();
@@ -570,7 +570,7 @@ operator*(const btQuaternion& q1, const btQuaternion& q2)
A1 = _mm_xor_ps(A1, vPPPM); // change sign of the last element A1 = _mm_xor_ps(A1, vPPPM); // change sign of the last element
A0 = A0 + A1; // AB03 + AB12 A0 = A0 + A1; // AB03 + AB12
return btQuaternion(A0); return b3Quaternion(A0);
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
@@ -615,10 +615,10 @@ operator*(const btQuaternion& q1, const btQuaternion& q2)
A1 = (btSimdFloat4)veorq_s32((int32x4_t)A1, (int32x4_t)vPPPM); A1 = (btSimdFloat4)veorq_s32((int32x4_t)A1, (int32x4_t)vPPPM);
A0 = vaddq_f32(A0, A1); // AB03 + AB12 A0 = vaddq_f32(A0, A1); // AB03 + AB12
return btQuaternion(A0); return b3Quaternion(A0);
#else #else
return btQuaternion( return b3Quaternion(
q1.getW() * q2.getX() + q1.getX() * q2.getW() + q1.getY() * q2.getZ() - q1.getZ() * q2.getY(), q1.getW() * q2.getX() + q1.getX() * q2.getW() + q1.getY() * q2.getZ() - q1.getZ() * q2.getY(),
q1.getW() * q2.getY() + q1.getY() * q2.getW() + q1.getZ() * q2.getX() - q1.getX() * q2.getZ(), q1.getW() * q2.getY() + q1.getY() * q2.getW() + q1.getZ() * q2.getX() - q1.getX() * q2.getZ(),
q1.getW() * q2.getZ() + q1.getZ() * q2.getW() + q1.getX() * q2.getY() - q1.getY() * q2.getX(), q1.getW() * q2.getZ() + q1.getZ() * q2.getW() + q1.getX() * q2.getY() - q1.getY() * q2.getX(),
@@ -626,8 +626,8 @@ operator*(const btQuaternion& q1, const btQuaternion& q2)
#endif #endif
} }
SIMD_FORCE_INLINE btQuaternion SIMD_FORCE_INLINE b3Quaternion
operator*(const btQuaternion& q, const btVector3& w) operator*(const b3Quaternion& q, const b3Vector3& w)
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 vQ1 = q.get128(); __m128 vQ1 = q.get128();
@@ -653,7 +653,7 @@ operator*(const btQuaternion& q, const btVector3& w)
A1 = _mm_xor_ps(A1, vPPPM); // change sign of the last element A1 = _mm_xor_ps(A1, vPPPM); // change sign of the last element
A1 = A1 - A3; // AB123 = AB12 - AB3 A1 = A1 - A3; // AB123 = AB12 - AB3
return btQuaternion(A1); return b3Quaternion(A1);
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
@@ -698,10 +698,10 @@ operator*(const btQuaternion& q, const btVector3& w)
A1 = vsubq_f32(A1, A3); // AB123 = AB12 - AB3 A1 = vsubq_f32(A1, A3); // AB123 = AB12 - AB3
return btQuaternion(A1); return b3Quaternion(A1);
#else #else
return btQuaternion( return b3Quaternion(
q.getW() * w.getX() + q.getY() * w.getZ() - q.getZ() * w.getY(), q.getW() * w.getX() + q.getY() * w.getZ() - q.getZ() * w.getY(),
q.getW() * w.getY() + q.getZ() * w.getX() - q.getX() * w.getZ(), q.getW() * w.getY() + q.getZ() * w.getX() - q.getX() * w.getZ(),
q.getW() * w.getZ() + q.getX() * w.getY() - q.getY() * w.getX(), q.getW() * w.getZ() + q.getX() * w.getY() - q.getY() * w.getX(),
@@ -709,8 +709,8 @@ operator*(const btQuaternion& q, const btVector3& w)
#endif #endif
} }
SIMD_FORCE_INLINE btQuaternion SIMD_FORCE_INLINE b3Quaternion
operator*(const btVector3& w, const btQuaternion& q) operator*(const b3Vector3& w, const b3Quaternion& q)
{ {
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 vQ1 = w.get128(); __m128 vQ1 = w.get128();
@@ -736,7 +736,7 @@ operator*(const btVector3& w, const btQuaternion& q)
A1 = _mm_xor_ps(A1, vPPPM); // change sign of the last element A1 = _mm_xor_ps(A1, vPPPM); // change sign of the last element
A1 = A1 - A3; // AB123 = AB12 - AB3 A1 = A1 - A3; // AB123 = AB12 - AB3
return btQuaternion(A1); return b3Quaternion(A1);
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
@@ -781,10 +781,10 @@ operator*(const btVector3& w, const btQuaternion& q)
A1 = vsubq_f32(A1, A3); // AB123 = AB12 - AB3 A1 = vsubq_f32(A1, A3); // AB123 = AB12 - AB3
return btQuaternion(A1); return b3Quaternion(A1);
#else #else
return btQuaternion( return b3Quaternion(
+w.getX() * q.getW() + w.getY() * q.getZ() - w.getZ() * q.getY(), +w.getX() * q.getW() + w.getY() * q.getZ() - w.getZ() * q.getY(),
+w.getY() * q.getW() + w.getZ() * q.getX() - w.getX() * q.getZ(), +w.getY() * q.getW() + w.getZ() * q.getX() - w.getX() * q.getZ(),
+w.getZ() * q.getW() + w.getX() * q.getY() - w.getY() * q.getX(), +w.getZ() * q.getW() + w.getX() * q.getY() - w.getY() * q.getX(),
@@ -793,30 +793,30 @@ operator*(const btVector3& w, const btQuaternion& q)
} }
/**@brief Calculate the dot product between two quaternions */ /**@brief Calculate the dot product between two quaternions */
SIMD_FORCE_INLINE btScalar SIMD_FORCE_INLINE b3Scalar
dot(const btQuaternion& q1, const btQuaternion& q2) dot(const b3Quaternion& q1, const b3Quaternion& q2)
{ {
return q1.dot(q2); return q1.dot(q2);
} }
/**@brief Return the length of a quaternion */ /**@brief Return the length of a quaternion */
SIMD_FORCE_INLINE btScalar SIMD_FORCE_INLINE b3Scalar
length(const btQuaternion& q) length(const b3Quaternion& q)
{ {
return q.length(); return q.length();
} }
/**@brief Return the angle between two quaternions*/ /**@brief Return the angle between two quaternions*/
SIMD_FORCE_INLINE btScalar SIMD_FORCE_INLINE b3Scalar
btAngle(const btQuaternion& q1, const btQuaternion& q2) btAngle(const b3Quaternion& q1, const b3Quaternion& q2)
{ {
return q1.angle(q2); return q1.angle(q2);
} }
/**@brief Return the inverse of a quaternion*/ /**@brief Return the inverse of a quaternion*/
SIMD_FORCE_INLINE btQuaternion SIMD_FORCE_INLINE b3Quaternion
inverse(const btQuaternion& q) inverse(const b3Quaternion& q)
{ {
return q.inverse(); return q.inverse();
} }
@@ -826,47 +826,47 @@ inverse(const btQuaternion& q)
* @param q2 The second quaternion * @param q2 The second quaternion
* @param t The ration between q1 and q2. t = 0 return q1, t=1 returns q2 * @param t The ration between q1 and q2. t = 0 return q1, t=1 returns q2
* Slerp assumes constant velocity between positions. */ * Slerp assumes constant velocity between positions. */
SIMD_FORCE_INLINE btQuaternion SIMD_FORCE_INLINE b3Quaternion
slerp(const btQuaternion& q1, const btQuaternion& q2, const btScalar& t) slerp(const b3Quaternion& q1, const b3Quaternion& q2, const b3Scalar& t)
{ {
return q1.slerp(q2, t); return q1.slerp(q2, t);
} }
SIMD_FORCE_INLINE btVector3 SIMD_FORCE_INLINE b3Vector3
quatRotate(const btQuaternion& rotation, const btVector3& v) quatRotate(const b3Quaternion& rotation, const b3Vector3& v)
{ {
btQuaternion q = rotation * v; b3Quaternion q = rotation * v;
q *= rotation.inverse(); q *= rotation.inverse();
#if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
return btVector3(_mm_and_ps(q.get128(), btvFFF0fMask)); return b3Vector3(_mm_and_ps(q.get128(), btvFFF0fMask));
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
return btVector3((float32x4_t)vandq_s32((int32x4_t)q.get128(), btvFFF0Mask)); return b3Vector3((float32x4_t)vandq_s32((int32x4_t)q.get128(), btvFFF0Mask));
#else #else
return btVector3(q.getX(),q.getY(),q.getZ()); return b3Vector3(q.getX(),q.getY(),q.getZ());
#endif #endif
} }
SIMD_FORCE_INLINE btQuaternion SIMD_FORCE_INLINE b3Quaternion
shortestArcQuat(const btVector3& v0, const btVector3& v1) // Game Programming Gems 2.10. make sure v0,v1 are normalized shortestArcQuat(const b3Vector3& v0, const b3Vector3& v1) // Game Programming Gems 2.10. make sure v0,v1 are normalized
{ {
btVector3 c = v0.cross(v1); b3Vector3 c = v0.cross(v1);
btScalar d = v0.dot(v1); b3Scalar d = v0.dot(v1);
if (d < -1.0 + SIMD_EPSILON) if (d < -1.0 + SIMD_EPSILON)
{ {
btVector3 n,unused; b3Vector3 n,unused;
btPlaneSpace1(v0,n,unused); btPlaneSpace1(v0,n,unused);
return btQuaternion(n.getX(),n.getY(),n.getZ(),0.0f); // just pick any vector that is orthogonal to v0 return b3Quaternion(n.getX(),n.getY(),n.getZ(),0.0f); // just pick any vector that is orthogonal to v0
} }
btScalar s = btSqrt((1.0f + d) * 2.0f); b3Scalar s = btSqrt((1.0f + d) * 2.0f);
btScalar rs = 1.0f / s; b3Scalar rs = 1.0f / s;
return btQuaternion(c.getX()*rs,c.getY()*rs,c.getZ()*rs,s * 0.5f); return b3Quaternion(c.getX()*rs,c.getY()*rs,c.getZ()*rs,s * 0.5f);
} }
SIMD_FORCE_INLINE btQuaternion SIMD_FORCE_INLINE b3Quaternion
shortestArcQuatNormalize2(btVector3& v0,btVector3& v1) shortestArcQuatNormalize2(b3Vector3& v0,b3Vector3& v1)
{ {
v0.normalize(); v0.normalize();
v1.normalize(); v1.normalize();

View File

@@ -13,7 +13,7 @@
// Credits: The Clock class was inspired by the Timer classes in // Credits: The Clock class was inspired by the Timer classes in
// Ogre (www.ogre3d.org). // Ogre (www.ogre3d.org).
#include "btQuickprof.h" #include "b3Quickprof.h"
#ifndef BT_NO_PROFILE #ifndef BT_NO_PROFILE

View File

@@ -19,8 +19,8 @@
//#define BT_NO_PROFILE 1 //#define BT_NO_PROFILE 1
#ifndef BT_NO_PROFILE #ifndef BT_NO_PROFILE
#include <stdio.h>//@todo remove this, backwards compatibility #include <stdio.h>//@todo remove this, backwards compatibility
#include "btScalar.h" #include "b3Scalar.h"
#include "btAlignedAllocator.h" #include "b3AlignedAllocator.h"
#include <new> #include <new>

View File

@@ -249,13 +249,13 @@ inline int btGetVersion()
#endif #endif
///The btScalar type abstracts floating point numbers, to easily switch between double and single floating point precision. ///The b3Scalar type abstracts floating point numbers, to easily switch between double and single floating point precision.
#if defined(BT_USE_DOUBLE_PRECISION) #if defined(BT_USE_DOUBLE_PRECISION)
typedef double btScalar; typedef double b3Scalar;
//this number could be bigger in double precision //this number could be bigger in double precision
#define BT_LARGE_FLOAT 1e30 #define BT_LARGE_FLOAT 1e30
#else #else
typedef float btScalar; typedef float b3Scalar;
//keep BT_LARGE_FLOAT*BT_LARGE_FLOAT < FLT_MAX //keep BT_LARGE_FLOAT*BT_LARGE_FLOAT < FLT_MAX
#define BT_LARGE_FLOAT 1e18f #define BT_LARGE_FLOAT 1e18f
#endif #endif
@@ -339,23 +339,23 @@ typedef float32x4_t btSimdFloat4;
#if defined(BT_USE_DOUBLE_PRECISION) || defined(BT_FORCE_DOUBLE_FUNCTIONS) #if defined(BT_USE_DOUBLE_PRECISION) || defined(BT_FORCE_DOUBLE_FUNCTIONS)
SIMD_FORCE_INLINE btScalar btSqrt(btScalar x) { return sqrt(x); } SIMD_FORCE_INLINE b3Scalar btSqrt(b3Scalar x) { return sqrt(x); }
SIMD_FORCE_INLINE btScalar btFabs(btScalar x) { return fabs(x); } SIMD_FORCE_INLINE b3Scalar btFabs(b3Scalar x) { return fabs(x); }
SIMD_FORCE_INLINE btScalar btCos(btScalar x) { return cos(x); } SIMD_FORCE_INLINE b3Scalar btCos(b3Scalar x) { return cos(x); }
SIMD_FORCE_INLINE btScalar btSin(btScalar x) { return sin(x); } SIMD_FORCE_INLINE b3Scalar btSin(b3Scalar x) { return sin(x); }
SIMD_FORCE_INLINE btScalar btTan(btScalar x) { return tan(x); } SIMD_FORCE_INLINE b3Scalar btTan(b3Scalar x) { return tan(x); }
SIMD_FORCE_INLINE btScalar btAcos(btScalar x) { if (x<btScalar(-1)) x=btScalar(-1); if (x>btScalar(1)) x=btScalar(1); return acos(x); } SIMD_FORCE_INLINE b3Scalar btAcos(b3Scalar x) { if (x<b3Scalar(-1)) x=b3Scalar(-1); if (x>b3Scalar(1)) x=b3Scalar(1); return acos(x); }
SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { if (x<btScalar(-1)) x=btScalar(-1); if (x>btScalar(1)) x=btScalar(1); return asin(x); } SIMD_FORCE_INLINE b3Scalar btAsin(b3Scalar x) { if (x<b3Scalar(-1)) x=b3Scalar(-1); if (x>b3Scalar(1)) x=b3Scalar(1); return asin(x); }
SIMD_FORCE_INLINE btScalar btAtan(btScalar x) { return atan(x); } SIMD_FORCE_INLINE b3Scalar btAtan(b3Scalar x) { return atan(x); }
SIMD_FORCE_INLINE btScalar btAtan2(btScalar x, btScalar y) { return atan2(x, y); } SIMD_FORCE_INLINE b3Scalar btAtan2(b3Scalar x, b3Scalar y) { return atan2(x, y); }
SIMD_FORCE_INLINE btScalar btExp(btScalar x) { return exp(x); } SIMD_FORCE_INLINE b3Scalar btExp(b3Scalar x) { return exp(x); }
SIMD_FORCE_INLINE btScalar btLog(btScalar x) { return log(x); } SIMD_FORCE_INLINE b3Scalar btLog(b3Scalar x) { return log(x); }
SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return pow(x,y); } SIMD_FORCE_INLINE b3Scalar btPow(b3Scalar x,b3Scalar y) { return pow(x,y); }
SIMD_FORCE_INLINE btScalar btFmod(btScalar x,btScalar y) { return fmod(x,y); } SIMD_FORCE_INLINE b3Scalar btFmod(b3Scalar x,b3Scalar y) { return fmod(x,y); }
#else #else
SIMD_FORCE_INLINE btScalar btSqrt(btScalar y) SIMD_FORCE_INLINE b3Scalar btSqrt(b3Scalar y)
{ {
#ifdef USE_APPROXIMATION #ifdef USE_APPROXIMATION
double x, z, tempf; double x, z, tempf;
@@ -364,52 +364,52 @@ SIMD_FORCE_INLINE btScalar btSqrt(btScalar y)
tempf = y; tempf = y;
*tfptr = (0xbfcdd90a - *tfptr)>>1; /* estimate of 1/sqrt(y) */ *tfptr = (0xbfcdd90a - *tfptr)>>1; /* estimate of 1/sqrt(y) */
x = tempf; x = tempf;
z = y*btScalar(0.5); z = y*b3Scalar(0.5);
x = (btScalar(1.5)*x)-(x*x)*(x*z); /* iteration formula */ x = (b3Scalar(1.5)*x)-(x*x)*(x*z); /* iteration formula */
x = (btScalar(1.5)*x)-(x*x)*(x*z); x = (b3Scalar(1.5)*x)-(x*x)*(x*z);
x = (btScalar(1.5)*x)-(x*x)*(x*z); x = (b3Scalar(1.5)*x)-(x*x)*(x*z);
x = (btScalar(1.5)*x)-(x*x)*(x*z); x = (b3Scalar(1.5)*x)-(x*x)*(x*z);
x = (btScalar(1.5)*x)-(x*x)*(x*z); x = (b3Scalar(1.5)*x)-(x*x)*(x*z);
return x*y; return x*y;
#else #else
return sqrtf(y); return sqrtf(y);
#endif #endif
} }
SIMD_FORCE_INLINE btScalar btFabs(btScalar x) { return fabsf(x); } SIMD_FORCE_INLINE b3Scalar btFabs(b3Scalar x) { return fabsf(x); }
SIMD_FORCE_INLINE btScalar btCos(btScalar x) { return cosf(x); } SIMD_FORCE_INLINE b3Scalar btCos(b3Scalar x) { return cosf(x); }
SIMD_FORCE_INLINE btScalar btSin(btScalar x) { return sinf(x); } SIMD_FORCE_INLINE b3Scalar btSin(b3Scalar x) { return sinf(x); }
SIMD_FORCE_INLINE btScalar btTan(btScalar x) { return tanf(x); } SIMD_FORCE_INLINE b3Scalar btTan(b3Scalar x) { return tanf(x); }
SIMD_FORCE_INLINE btScalar btAcos(btScalar x) { SIMD_FORCE_INLINE b3Scalar btAcos(b3Scalar x) {
if (x<btScalar(-1)) if (x<b3Scalar(-1))
x=btScalar(-1); x=b3Scalar(-1);
if (x>btScalar(1)) if (x>b3Scalar(1))
x=btScalar(1); x=b3Scalar(1);
return acosf(x); return acosf(x);
} }
SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { SIMD_FORCE_INLINE b3Scalar btAsin(b3Scalar x) {
if (x<btScalar(-1)) if (x<b3Scalar(-1))
x=btScalar(-1); x=b3Scalar(-1);
if (x>btScalar(1)) if (x>b3Scalar(1))
x=btScalar(1); x=b3Scalar(1);
return asinf(x); return asinf(x);
} }
SIMD_FORCE_INLINE btScalar btAtan(btScalar x) { return atanf(x); } SIMD_FORCE_INLINE b3Scalar btAtan(b3Scalar x) { return atanf(x); }
SIMD_FORCE_INLINE btScalar btAtan2(btScalar x, btScalar y) { return atan2f(x, y); } SIMD_FORCE_INLINE b3Scalar btAtan2(b3Scalar x, b3Scalar y) { return atan2f(x, y); }
SIMD_FORCE_INLINE btScalar btExp(btScalar x) { return expf(x); } SIMD_FORCE_INLINE b3Scalar btExp(b3Scalar x) { return expf(x); }
SIMD_FORCE_INLINE btScalar btLog(btScalar x) { return logf(x); } SIMD_FORCE_INLINE b3Scalar btLog(b3Scalar x) { return logf(x); }
SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return powf(x,y); } SIMD_FORCE_INLINE b3Scalar btPow(b3Scalar x,b3Scalar y) { return powf(x,y); }
SIMD_FORCE_INLINE btScalar btFmod(btScalar x,btScalar y) { return fmodf(x,y); } SIMD_FORCE_INLINE b3Scalar btFmod(b3Scalar x,b3Scalar y) { return fmodf(x,y); }
#endif #endif
#define SIMD_2_PI btScalar(6.283185307179586232) #define SIMD_2_PI b3Scalar(6.283185307179586232)
#define SIMD_PI (SIMD_2_PI * btScalar(0.5)) #define SIMD_PI (SIMD_2_PI * b3Scalar(0.5))
#define SIMD_HALF_PI (SIMD_2_PI * btScalar(0.25)) #define SIMD_HALF_PI (SIMD_2_PI * b3Scalar(0.25))
#define SIMD_RADS_PER_DEG (SIMD_2_PI / btScalar(360.0)) #define SIMD_RADS_PER_DEG (SIMD_2_PI / b3Scalar(360.0))
#define SIMD_DEGS_PER_RAD (btScalar(360.0) / SIMD_2_PI) #define SIMD_DEGS_PER_RAD (b3Scalar(360.0) / SIMD_2_PI)
#define SIMDSQRT12 btScalar(0.7071067811865475244008443621048490) #define SIMDSQRT12 b3Scalar(0.7071067811865475244008443621048490)
#define btRecipSqrt(x) ((btScalar)(btScalar(1.0)/btSqrt(btScalar(x)))) /* reciprocal square root */ #define btRecipSqrt(x) ((b3Scalar)(b3Scalar(1.0)/btSqrt(b3Scalar(x)))) /* reciprocal square root */
#ifdef BT_USE_DOUBLE_PRECISION #ifdef BT_USE_DOUBLE_PRECISION
@@ -420,48 +420,48 @@ SIMD_FORCE_INLINE btScalar btFmod(btScalar x,btScalar y) { return fmodf(x,y); }
#define SIMD_INFINITY FLT_MAX #define SIMD_INFINITY FLT_MAX
#endif #endif
SIMD_FORCE_INLINE btScalar btAtan2Fast(btScalar y, btScalar x) SIMD_FORCE_INLINE b3Scalar btAtan2Fast(b3Scalar y, b3Scalar x)
{ {
btScalar coeff_1 = SIMD_PI / 4.0f; b3Scalar coeff_1 = SIMD_PI / 4.0f;
btScalar coeff_2 = 3.0f * coeff_1; b3Scalar coeff_2 = 3.0f * coeff_1;
btScalar abs_y = btFabs(y); b3Scalar abs_y = btFabs(y);
btScalar angle; b3Scalar angle;
if (x >= 0.0f) { if (x >= 0.0f) {
btScalar r = (x - abs_y) / (x + abs_y); b3Scalar r = (x - abs_y) / (x + abs_y);
angle = coeff_1 - coeff_1 * r; angle = coeff_1 - coeff_1 * r;
} else { } else {
btScalar r = (x + abs_y) / (abs_y - x); b3Scalar r = (x + abs_y) / (abs_y - x);
angle = coeff_2 - coeff_1 * r; angle = coeff_2 - coeff_1 * r;
} }
return (y < 0.0f) ? -angle : angle; return (y < 0.0f) ? -angle : angle;
} }
SIMD_FORCE_INLINE bool btFuzzyZero(btScalar x) { return btFabs(x) < SIMD_EPSILON; } SIMD_FORCE_INLINE bool btFuzzyZero(b3Scalar x) { return btFabs(x) < SIMD_EPSILON; }
SIMD_FORCE_INLINE bool btEqual(btScalar a, btScalar eps) { SIMD_FORCE_INLINE bool btEqual(b3Scalar a, b3Scalar eps) {
return (((a) <= eps) && !((a) < -eps)); return (((a) <= eps) && !((a) < -eps));
} }
SIMD_FORCE_INLINE bool btGreaterEqual (btScalar a, btScalar eps) { SIMD_FORCE_INLINE bool btGreaterEqual (b3Scalar a, b3Scalar eps) {
return (!((a) <= eps)); return (!((a) <= eps));
} }
SIMD_FORCE_INLINE int btIsNegative(btScalar x) { SIMD_FORCE_INLINE int btIsNegative(b3Scalar x) {
return x < btScalar(0.0) ? 1 : 0; return x < b3Scalar(0.0) ? 1 : 0;
} }
SIMD_FORCE_INLINE btScalar btRadians(btScalar x) { return x * SIMD_RADS_PER_DEG; } SIMD_FORCE_INLINE b3Scalar btRadians(b3Scalar x) { return x * SIMD_RADS_PER_DEG; }
SIMD_FORCE_INLINE btScalar btDegrees(btScalar x) { return x * SIMD_DEGS_PER_RAD; } SIMD_FORCE_INLINE b3Scalar btDegrees(b3Scalar x) { return x * SIMD_DEGS_PER_RAD; }
#define BT_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name #define BT_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
#ifndef btFsel #ifndef btFsel
SIMD_FORCE_INLINE btScalar btFsel(btScalar a, btScalar b, btScalar c) SIMD_FORCE_INLINE b3Scalar btFsel(b3Scalar a, b3Scalar b, b3Scalar c)
{ {
return a >= 0 ? b : c; return a >= 0 ? b : c;
} }
#endif #endif
#define btFsels(a,b,c) (btScalar)btFsel(a,b,c) #define btFsels(a,b,c) (b3Scalar)btFsel(a,b,c)
SIMD_FORCE_INLINE bool btMachineIsLittleEndian() SIMD_FORCE_INLINE bool btMachineIsLittleEndian()
@@ -497,7 +497,7 @@ SIMD_FORCE_INLINE int btSelect(unsigned condition, int valueIfConditionNonZero,
SIMD_FORCE_INLINE float btSelect(unsigned condition, float valueIfConditionNonZero, float valueIfConditionZero) SIMD_FORCE_INLINE float btSelect(unsigned condition, float valueIfConditionNonZero, float valueIfConditionZero)
{ {
#ifdef BT_HAVE_NATIVE_FSEL #ifdef BT_HAVE_NATIVE_FSEL
return (float)btFsel((btScalar)condition - btScalar(1.0f), valueIfConditionNonZero, valueIfConditionZero); return (float)btFsel((b3Scalar)condition - b3Scalar(1.0f), valueIfConditionNonZero, valueIfConditionZero);
#else #else
return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero; return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero;
#endif #endif
@@ -602,7 +602,7 @@ SIMD_FORCE_INLINE double btUnswapEndianDouble(const unsigned char *src)
} }
// returns normalized value in range [-SIMD_PI, SIMD_PI] // returns normalized value in range [-SIMD_PI, SIMD_PI]
SIMD_FORCE_INLINE btScalar btNormalizeAngle(btScalar angleInRadians) SIMD_FORCE_INLINE b3Scalar btNormalizeAngle(b3Scalar angleInRadians)
{ {
angleInRadians = btFmod(angleInRadians, SIMD_2_PI); angleInRadians = btFmod(angleInRadians, SIMD_2_PI);
if(angleInRadians < -SIMD_PI) if(angleInRadians < -SIMD_PI)

View File

@@ -20,10 +20,10 @@ Nov.2006
#ifndef BT_STACK_ALLOC #ifndef BT_STACK_ALLOC
#define BT_STACK_ALLOC #define BT_STACK_ALLOC
#include "btScalar.h" //for btAssert #include "b3Scalar.h" //for btAssert
#include "btAlignedAllocator.h" #include "b3AlignedAllocator.h"
///The btBlock class is an internal structure for the btStackAlloc memory allocator. ///The btBlock class is an internal structure for the b3StackAlloc memory allocator.
struct btBlock struct btBlock
{ {
btBlock* previous; btBlock* previous;
@@ -31,12 +31,12 @@ struct btBlock
}; };
///The StackAlloc class provides some fast stack-based memory allocator (LIFO last-in first-out) ///The StackAlloc class provides some fast stack-based memory allocator (LIFO last-in first-out)
class btStackAlloc class b3StackAlloc
{ {
public: public:
btStackAlloc(unsigned int size) { ctor();create(size); } b3StackAlloc(unsigned int size) { ctor();create(size); }
~btStackAlloc() { destroy(); } ~b3StackAlloc() { destroy(); }
inline void create(unsigned int size) inline void create(unsigned int size)
{ {

View File

@@ -18,7 +18,7 @@ subject to the following restrictions:
#define BT_TRANSFORM_H #define BT_TRANSFORM_H
#include "btMatrix3x3.h" #include "b3Matrix3x3.h"
#ifdef BT_USE_DOUBLE_PRECISION #ifdef BT_USE_DOUBLE_PRECISION
#define btTransformData btTransformDoubleData #define btTransformData btTransformDoubleData
@@ -29,44 +29,44 @@ subject to the following restrictions:
/**@brief The btTransform class supports rigid transforms with only translation and rotation and no scaling/shear. /**@brief The b3Transform class supports rigid transforms with only translation and rotation and no scaling/shear.
*It can be used in combination with btVector3, btQuaternion and btMatrix3x3 linear algebra classes. */ *It can be used in combination with b3Vector3, b3Quaternion and b3Matrix3x3 linear algebra classes. */
ATTRIBUTE_ALIGNED16(class) btTransform { ATTRIBUTE_ALIGNED16(class) b3Transform {
///Storage for the rotation ///Storage for the rotation
btMatrix3x3 m_basis; b3Matrix3x3 m_basis;
///Storage for the translation ///Storage for the translation
btVector3 m_origin; b3Vector3 m_origin;
public: public:
/**@brief No initialization constructor */ /**@brief No initialization constructor */
btTransform() {} b3Transform() {}
/**@brief Constructor from btQuaternion (optional btVector3 ) /**@brief Constructor from b3Quaternion (optional b3Vector3 )
* @param q Rotation from quaternion * @param q Rotation from quaternion
* @param c Translation from Vector (default 0,0,0) */ * @param c Translation from Vector (default 0,0,0) */
explicit SIMD_FORCE_INLINE btTransform(const btQuaternion& q, explicit SIMD_FORCE_INLINE b3Transform(const b3Quaternion& q,
const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0))) const b3Vector3& c = b3Vector3(b3Scalar(0), b3Scalar(0), b3Scalar(0)))
: m_basis(q), : m_basis(q),
m_origin(c) m_origin(c)
{} {}
/**@brief Constructor from btMatrix3x3 (optional btVector3) /**@brief Constructor from b3Matrix3x3 (optional b3Vector3)
* @param b Rotation from Matrix * @param b Rotation from Matrix
* @param c Translation from Vector default (0,0,0)*/ * @param c Translation from Vector default (0,0,0)*/
explicit SIMD_FORCE_INLINE btTransform(const btMatrix3x3& b, explicit SIMD_FORCE_INLINE b3Transform(const b3Matrix3x3& b,
const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0))) const b3Vector3& c = b3Vector3(b3Scalar(0), b3Scalar(0), b3Scalar(0)))
: m_basis(b), : m_basis(b),
m_origin(c) m_origin(c)
{} {}
/**@brief Copy constructor */ /**@brief Copy constructor */
SIMD_FORCE_INLINE btTransform (const btTransform& other) SIMD_FORCE_INLINE b3Transform (const b3Transform& other)
: m_basis(other.m_basis), : m_basis(other.m_basis),
m_origin(other.m_origin) m_origin(other.m_origin)
{ {
} }
/**@brief Assignment Operator */ /**@brief Assignment Operator */
SIMD_FORCE_INLINE btTransform& operator=(const btTransform& other) SIMD_FORCE_INLINE b3Transform& operator=(const b3Transform& other)
{ {
m_basis = other.m_basis; m_basis = other.m_basis;
m_origin = other.m_origin; m_origin = other.m_origin;
@@ -78,49 +78,49 @@ public:
* @param t1 Transform 1 * @param t1 Transform 1
* @param t2 Transform 2 * @param t2 Transform 2
* This = Transform1 * Transform2 */ * This = Transform1 * Transform2 */
SIMD_FORCE_INLINE void mult(const btTransform& t1, const btTransform& t2) { SIMD_FORCE_INLINE void mult(const b3Transform& t1, const b3Transform& t2) {
m_basis = t1.m_basis * t2.m_basis; m_basis = t1.m_basis * t2.m_basis;
m_origin = t1(t2.m_origin); m_origin = t1(t2.m_origin);
} }
/* void multInverseLeft(const btTransform& t1, const btTransform& t2) { /* void multInverseLeft(const b3Transform& t1, const b3Transform& t2) {
btVector3 v = t2.m_origin - t1.m_origin; b3Vector3 v = t2.m_origin - t1.m_origin;
m_basis = btMultTransposeLeft(t1.m_basis, t2.m_basis); m_basis = btMultTransposeLeft(t1.m_basis, t2.m_basis);
m_origin = v * t1.m_basis; m_origin = v * t1.m_basis;
} }
*/ */
/**@brief Return the transform of the vector */ /**@brief Return the transform of the vector */
SIMD_FORCE_INLINE btVector3 operator()(const btVector3& x) const SIMD_FORCE_INLINE b3Vector3 operator()(const b3Vector3& x) const
{ {
return x.dot3(m_basis[0], m_basis[1], m_basis[2]) + m_origin; return x.dot3(m_basis[0], m_basis[1], m_basis[2]) + m_origin;
} }
/**@brief Return the transform of the vector */ /**@brief Return the transform of the vector */
SIMD_FORCE_INLINE btVector3 operator*(const btVector3& x) const SIMD_FORCE_INLINE b3Vector3 operator*(const b3Vector3& x) const
{ {
return (*this)(x); return (*this)(x);
} }
/**@brief Return the transform of the btQuaternion */ /**@brief Return the transform of the b3Quaternion */
SIMD_FORCE_INLINE btQuaternion operator*(const btQuaternion& q) const SIMD_FORCE_INLINE b3Quaternion operator*(const b3Quaternion& q) const
{ {
return getRotation() * q; return getRotation() * q;
} }
/**@brief Return the basis matrix for the rotation */ /**@brief Return the basis matrix for the rotation */
SIMD_FORCE_INLINE btMatrix3x3& getBasis() { return m_basis; } SIMD_FORCE_INLINE b3Matrix3x3& getBasis() { return m_basis; }
/**@brief Return the basis matrix for the rotation */ /**@brief Return the basis matrix for the rotation */
SIMD_FORCE_INLINE const btMatrix3x3& getBasis() const { return m_basis; } SIMD_FORCE_INLINE const b3Matrix3x3& getBasis() const { return m_basis; }
/**@brief Return the origin vector translation */ /**@brief Return the origin vector translation */
SIMD_FORCE_INLINE btVector3& getOrigin() { return m_origin; } SIMD_FORCE_INLINE b3Vector3& getOrigin() { return m_origin; }
/**@brief Return the origin vector translation */ /**@brief Return the origin vector translation */
SIMD_FORCE_INLINE const btVector3& getOrigin() const { return m_origin; } SIMD_FORCE_INLINE const b3Vector3& getOrigin() const { return m_origin; }
/**@brief Return a quaternion representing the rotation */ /**@brief Return a quaternion representing the rotation */
btQuaternion getRotation() const { b3Quaternion getRotation() const {
btQuaternion q; b3Quaternion q;
m_basis.getRotation(q); m_basis.getRotation(q);
return q; return q;
} }
@@ -128,7 +128,7 @@ public:
/**@brief Set from an array /**@brief Set from an array
* @param m A pointer to a 15 element array (12 rotation(row major padded on the right by 1), and 3 translation */ * @param m A pointer to a 15 element array (12 rotation(row major padded on the right by 1), and 3 translation */
void setFromOpenGLMatrix(const btScalar *m) void setFromOpenGLMatrix(const b3Scalar *m)
{ {
m_basis.setFromOpenGLSubMatrix(m); m_basis.setFromOpenGLSubMatrix(m);
m_origin.setValue(m[12],m[13],m[14]); m_origin.setValue(m[12],m[13],m[14]);
@@ -136,33 +136,33 @@ public:
/**@brief Fill an array representation /**@brief Fill an array representation
* @param m A pointer to a 15 element array (12 rotation(row major padded on the right by 1), and 3 translation */ * @param m A pointer to a 15 element array (12 rotation(row major padded on the right by 1), and 3 translation */
void getOpenGLMatrix(btScalar *m) const void getOpenGLMatrix(b3Scalar *m) const
{ {
m_basis.getOpenGLSubMatrix(m); m_basis.getOpenGLSubMatrix(m);
m[12] = m_origin.getX(); m[12] = m_origin.getX();
m[13] = m_origin.getY(); m[13] = m_origin.getY();
m[14] = m_origin.getZ(); m[14] = m_origin.getZ();
m[15] = btScalar(1.0); m[15] = b3Scalar(1.0);
} }
/**@brief Set the translational element /**@brief Set the translational element
* @param origin The vector to set the translation to */ * @param origin The vector to set the translation to */
SIMD_FORCE_INLINE void setOrigin(const btVector3& origin) SIMD_FORCE_INLINE void setOrigin(const b3Vector3& origin)
{ {
m_origin = origin; m_origin = origin;
} }
SIMD_FORCE_INLINE btVector3 invXform(const btVector3& inVec) const; SIMD_FORCE_INLINE b3Vector3 invXform(const b3Vector3& inVec) const;
/**@brief Set the rotational element by btMatrix3x3 */ /**@brief Set the rotational element by b3Matrix3x3 */
SIMD_FORCE_INLINE void setBasis(const btMatrix3x3& basis) SIMD_FORCE_INLINE void setBasis(const b3Matrix3x3& basis)
{ {
m_basis = basis; m_basis = basis;
} }
/**@brief Set the rotational element by btQuaternion */ /**@brief Set the rotational element by b3Quaternion */
SIMD_FORCE_INLINE void setRotation(const btQuaternion& q) SIMD_FORCE_INLINE void setRotation(const b3Quaternion& q)
{ {
m_basis.setRotation(q); m_basis.setRotation(q);
} }
@@ -172,12 +172,12 @@ public:
void setIdentity() void setIdentity()
{ {
m_basis.setIdentity(); m_basis.setIdentity();
m_origin.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)); m_origin.setValue(b3Scalar(0.0), b3Scalar(0.0), b3Scalar(0.0));
} }
/**@brief Multiply this Transform by another(this = this * another) /**@brief Multiply this Transform by another(this = this * another)
* @param t The other transform */ * @param t The other transform */
btTransform& operator*=(const btTransform& t) b3Transform& operator*=(const b3Transform& t)
{ {
m_origin += m_basis * t.m_origin; m_origin += m_basis * t.m_origin;
m_basis *= t.m_basis; m_basis *= t.m_basis;
@@ -185,24 +185,24 @@ public:
} }
/**@brief Return the inverse of this transform */ /**@brief Return the inverse of this transform */
btTransform inverse() const b3Transform inverse() const
{ {
btMatrix3x3 inv = m_basis.transpose(); b3Matrix3x3 inv = m_basis.transpose();
return btTransform(inv, inv * -m_origin); return b3Transform(inv, inv * -m_origin);
} }
/**@brief Return the inverse of this transform times the other transform /**@brief Return the inverse of this transform times the other transform
* @param t The other transform * @param t The other transform
* return this.inverse() * the other */ * return this.inverse() * the other */
btTransform inverseTimes(const btTransform& t) const; b3Transform inverseTimes(const b3Transform& t) const;
/**@brief Return the product of this transform and the other */ /**@brief Return the product of this transform and the other */
btTransform operator*(const btTransform& t) const; b3Transform operator*(const b3Transform& t) const;
/**@brief Return an identity transform */ /**@brief Return an identity transform */
static const btTransform& getIdentity() static const b3Transform& getIdentity()
{ {
static const btTransform identityTransform(btMatrix3x3::getIdentity()); static const b3Transform identityTransform(b3Matrix3x3::getIdentity());
return identityTransform; return identityTransform;
} }
@@ -219,30 +219,30 @@ public:
}; };
SIMD_FORCE_INLINE btVector3 SIMD_FORCE_INLINE b3Vector3
btTransform::invXform(const btVector3& inVec) const b3Transform::invXform(const b3Vector3& inVec) const
{ {
btVector3 v = inVec - m_origin; b3Vector3 v = inVec - m_origin;
return (m_basis.transpose() * v); return (m_basis.transpose() * v);
} }
SIMD_FORCE_INLINE btTransform SIMD_FORCE_INLINE b3Transform
btTransform::inverseTimes(const btTransform& t) const b3Transform::inverseTimes(const b3Transform& t) const
{ {
btVector3 v = t.getOrigin() - m_origin; b3Vector3 v = t.getOrigin() - m_origin;
return btTransform(m_basis.transposeTimes(t.m_basis), return b3Transform(m_basis.transposeTimes(t.m_basis),
v * m_basis); v * m_basis);
} }
SIMD_FORCE_INLINE btTransform SIMD_FORCE_INLINE b3Transform
btTransform::operator*(const btTransform& t) const b3Transform::operator*(const b3Transform& t) const
{ {
return btTransform(m_basis * t.m_basis, return b3Transform(m_basis * t.m_basis,
(*this)(t.m_origin)); (*this)(t.m_origin));
} }
/**@brief Test if two transforms have all elements equal */ /**@brief Test if two transforms have all elements equal */
SIMD_FORCE_INLINE bool operator==(const btTransform& t1, const btTransform& t2) SIMD_FORCE_INLINE bool operator==(const b3Transform& t1, const b3Transform& t2)
{ {
return ( t1.getBasis() == t2.getBasis() && return ( t1.getBasis() == t2.getBasis() &&
t1.getOrigin() == t2.getOrigin() ); t1.getOrigin() == t2.getOrigin() );
@@ -264,32 +264,32 @@ struct btTransformDoubleData
SIMD_FORCE_INLINE void btTransform::serialize(btTransformData& dataOut) const SIMD_FORCE_INLINE void b3Transform::serialize(btTransformData& dataOut) const
{ {
m_basis.serialize(dataOut.m_basis); m_basis.serialize(dataOut.m_basis);
m_origin.serialize(dataOut.m_origin); m_origin.serialize(dataOut.m_origin);
} }
SIMD_FORCE_INLINE void btTransform::serializeFloat(btTransformFloatData& dataOut) const SIMD_FORCE_INLINE void b3Transform::serializeFloat(btTransformFloatData& dataOut) const
{ {
m_basis.serializeFloat(dataOut.m_basis); m_basis.serializeFloat(dataOut.m_basis);
m_origin.serializeFloat(dataOut.m_origin); m_origin.serializeFloat(dataOut.m_origin);
} }
SIMD_FORCE_INLINE void btTransform::deSerialize(const btTransformData& dataIn) SIMD_FORCE_INLINE void b3Transform::deSerialize(const btTransformData& dataIn)
{ {
m_basis.deSerialize(dataIn.m_basis); m_basis.deSerialize(dataIn.m_basis);
m_origin.deSerialize(dataIn.m_origin); m_origin.deSerialize(dataIn.m_origin);
} }
SIMD_FORCE_INLINE void btTransform::deSerializeFloat(const btTransformFloatData& dataIn) SIMD_FORCE_INLINE void b3Transform::deSerializeFloat(const btTransformFloatData& dataIn)
{ {
m_basis.deSerializeFloat(dataIn.m_basis); m_basis.deSerializeFloat(dataIn.m_basis);
m_origin.deSerializeFloat(dataIn.m_origin); m_origin.deSerializeFloat(dataIn.m_origin);
} }
SIMD_FORCE_INLINE void btTransform::deSerializeDouble(const btTransformDoubleData& dataIn) SIMD_FORCE_INLINE void b3Transform::deSerializeDouble(const btTransformDoubleData& dataIn)
{ {
m_basis.deSerializeDouble(dataIn.m_basis); m_basis.deSerializeDouble(dataIn.m_basis);
m_origin.deSerializeDouble(dataIn.m_origin); m_origin.deSerializeDouble(dataIn.m_origin);

View File

@@ -0,0 +1,228 @@
/*
Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/
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:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef BT_TRANSFORM_UTIL_H
#define BT_TRANSFORM_UTIL_H
#include "b3Transform.h"
#define ANGULAR_MOTION_THRESHOLD b3Scalar(0.5)*SIMD_HALF_PI
SIMD_FORCE_INLINE b3Vector3 btAabbSupport(const b3Vector3& halfExtents,const b3Vector3& supportDir)
{
return b3Vector3(supportDir.getX() < b3Scalar(0.0) ? -halfExtents.getX() : halfExtents.getX(),
supportDir.getY() < b3Scalar(0.0) ? -halfExtents.getY() : halfExtents.getY(),
supportDir.getZ() < b3Scalar(0.0) ? -halfExtents.getZ() : halfExtents.getZ());
}
/// Utils related to temporal transforms
class b3TransformUtil
{
public:
static void integrateTransform(const b3Transform& curTrans,const b3Vector3& linvel,const b3Vector3& angvel,b3Scalar timeStep,b3Transform& predictedTransform)
{
predictedTransform.setOrigin(curTrans.getOrigin() + linvel * timeStep);
// #define QUATERNION_DERIVATIVE
#ifdef QUATERNION_DERIVATIVE
b3Quaternion predictedOrn = curTrans.getRotation();
predictedOrn += (angvel * predictedOrn) * (timeStep * b3Scalar(0.5));
predictedOrn.normalize();
#else
//Exponential map
//google for "Practical Parameterization of Rotations Using the Exponential Map", F. Sebastian Grassia
b3Vector3 axis;
b3Scalar fAngle = angvel.length();
//limit the angular motion
if (fAngle*timeStep > ANGULAR_MOTION_THRESHOLD)
{
fAngle = ANGULAR_MOTION_THRESHOLD / timeStep;
}
if ( fAngle < b3Scalar(0.001) )
{
// use Taylor's expansions of sync function
axis = angvel*( b3Scalar(0.5)*timeStep-(timeStep*timeStep*timeStep)*(b3Scalar(0.020833333333))*fAngle*fAngle );
}
else
{
// sync(fAngle) = sin(c*fAngle)/t
axis = angvel*( btSin(b3Scalar(0.5)*fAngle*timeStep)/fAngle );
}
b3Quaternion dorn (axis.getX(),axis.getY(),axis.getZ(),btCos( fAngle*timeStep*b3Scalar(0.5) ));
b3Quaternion orn0 = curTrans.getRotation();
b3Quaternion predictedOrn = dorn * orn0;
predictedOrn.normalize();
#endif
predictedTransform.setRotation(predictedOrn);
}
static void calculateVelocityQuaternion(const b3Vector3& pos0,const b3Vector3& pos1,const b3Quaternion& orn0,const b3Quaternion& orn1,b3Scalar timeStep,b3Vector3& linVel,b3Vector3& angVel)
{
linVel = (pos1 - pos0) / timeStep;
b3Vector3 axis;
b3Scalar angle;
if (orn0 != orn1)
{
calculateDiffAxisAngleQuaternion(orn0,orn1,axis,angle);
angVel = axis * angle / timeStep;
} else
{
angVel.setValue(0,0,0);
}
}
static void calculateDiffAxisAngleQuaternion(const b3Quaternion& orn0,const b3Quaternion& orn1a,b3Vector3& axis,b3Scalar& angle)
{
b3Quaternion orn1 = orn0.nearest(orn1a);
b3Quaternion dorn = orn1 * orn0.inverse();
angle = dorn.getAngle();
axis = b3Vector3(dorn.getX(),dorn.getY(),dorn.getZ());
axis[3] = b3Scalar(0.);
//check for axis length
b3Scalar len = axis.length2();
if (len < SIMD_EPSILON*SIMD_EPSILON)
axis = b3Vector3(b3Scalar(1.),b3Scalar(0.),b3Scalar(0.));
else
axis /= btSqrt(len);
}
static void calculateVelocity(const b3Transform& transform0,const b3Transform& transform1,b3Scalar timeStep,b3Vector3& linVel,b3Vector3& angVel)
{
linVel = (transform1.getOrigin() - transform0.getOrigin()) / timeStep;
b3Vector3 axis;
b3Scalar angle;
calculateDiffAxisAngle(transform0,transform1,axis,angle);
angVel = axis * angle / timeStep;
}
static void calculateDiffAxisAngle(const b3Transform& transform0,const b3Transform& transform1,b3Vector3& axis,b3Scalar& angle)
{
b3Matrix3x3 dmat = transform1.getBasis() * transform0.getBasis().inverse();
b3Quaternion dorn;
dmat.getRotation(dorn);
///floating point inaccuracy can lead to w component > 1..., which breaks
dorn.normalize();
angle = dorn.getAngle();
axis = b3Vector3(dorn.getX(),dorn.getY(),dorn.getZ());
axis[3] = b3Scalar(0.);
//check for axis length
b3Scalar len = axis.length2();
if (len < SIMD_EPSILON*SIMD_EPSILON)
axis = b3Vector3(b3Scalar(1.),b3Scalar(0.),b3Scalar(0.));
else
axis /= btSqrt(len);
}
};
///The btConvexSeparatingDistanceUtil can help speed up convex collision detection
///by conservatively updating a cached separating distance/vector instead of re-calculating the closest distance
class btConvexSeparatingDistanceUtil
{
b3Quaternion m_ornA;
b3Quaternion m_ornB;
b3Vector3 m_posA;
b3Vector3 m_posB;
b3Vector3 m_separatingNormal;
b3Scalar m_boundingRadiusA;
b3Scalar m_boundingRadiusB;
b3Scalar m_separatingDistance;
public:
btConvexSeparatingDistanceUtil(b3Scalar boundingRadiusA,b3Scalar boundingRadiusB)
:m_boundingRadiusA(boundingRadiusA),
m_boundingRadiusB(boundingRadiusB),
m_separatingDistance(0.f)
{
}
b3Scalar getConservativeSeparatingDistance()
{
return m_separatingDistance;
}
void updateSeparatingDistance(const b3Transform& transA,const b3Transform& transB)
{
const b3Vector3& toPosA = transA.getOrigin();
const b3Vector3& toPosB = transB.getOrigin();
b3Quaternion toOrnA = transA.getRotation();
b3Quaternion toOrnB = transB.getRotation();
if (m_separatingDistance>0.f)
{
b3Vector3 linVelA,angVelA,linVelB,angVelB;
b3TransformUtil::calculateVelocityQuaternion(m_posA,toPosA,m_ornA,toOrnA,b3Scalar(1.),linVelA,angVelA);
b3TransformUtil::calculateVelocityQuaternion(m_posB,toPosB,m_ornB,toOrnB,b3Scalar(1.),linVelB,angVelB);
b3Scalar maxAngularProjectedVelocity = angVelA.length() * m_boundingRadiusA + angVelB.length() * m_boundingRadiusB;
b3Vector3 relLinVel = (linVelB-linVelA);
b3Scalar relLinVelocLength = relLinVel.dot(m_separatingNormal);
if (relLinVelocLength<0.f)
{
relLinVelocLength = 0.f;
}
b3Scalar projectedMotion = maxAngularProjectedVelocity +relLinVelocLength;
m_separatingDistance -= projectedMotion;
}
m_posA = toPosA;
m_posB = toPosB;
m_ornA = toOrnA;
m_ornB = toOrnB;
}
void initSeparatingDistance(const b3Vector3& separatingVector,b3Scalar separatingDistance,const b3Transform& transA,const b3Transform& transB)
{
m_separatingDistance = separatingDistance;
if (m_separatingDistance>0.f)
{
m_separatingNormal = separatingVector;
const b3Vector3& toPosA = transA.getOrigin();
const b3Vector3& toPosB = transB.getOrigin();
b3Quaternion toOrnA = transA.getRotation();
b3Quaternion toOrnB = transB.getRotation();
m_posA = toPosA;
m_posB = toPosB;
m_ornA = toOrnA;
m_ornB = toOrnB;
}
}
};
#endif //BT_TRANSFORM_UTIL_H

View File

@@ -19,7 +19,7 @@
#define BT_USE_SSE_IN_API #define BT_USE_SSE_IN_API
#endif #endif
#include "btVector3.h" #include "b3Vector3.h"
#if defined (BT_USE_SSE) || defined (BT_USE_NEON) #if defined (BT_USE_SSE) || defined (BT_USE_NEON)

Some files were not shown because too many files have changed in this diff Show More