summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerwincoumans <erwincoumans@google.com>2019-07-31 18:49:37 -0700
committerGitHub <noreply@github.com>2019-07-31 18:49:37 -0700
commit14cc0ec2eeaf0db6435699b365f3383e75bd42ad (patch)
treef97c3c6044738e11058136ef1d648abc3e2a3c48
parent789769eac925d1052c94316e0d9b1d916a689998 (diff)
parent397767cb605488eeef58d62079e9632deaf47606 (diff)
downloadbullet3-14cc0ec2eeaf0db6435699b365f3383e75bd42ad.tar.gz
Merge pull request #2346 from erwincoumans/master
add texture support for cube, when using createCollisionShape(GEOM_BOX)
-rw-r--r--examples/ExampleBrowser/OpenGLGuiHelper.cpp57
1 files changed, 55 insertions, 2 deletions
diff --git a/examples/ExampleBrowser/OpenGLGuiHelper.cpp b/examples/ExampleBrowser/OpenGLGuiHelper.cpp
index afd810980..a3197749d 100644
--- a/examples/ExampleBrowser/OpenGLGuiHelper.cpp
+++ b/examples/ExampleBrowser/OpenGLGuiHelper.cpp
@@ -144,6 +144,7 @@ struct MyHashShape
int m_shapeType;
btVector3 m_sphere0Pos;
btVector3 m_sphere1Pos;
+ btVector3 m_halfExtents;
btScalar m_radius0;
btScalar m_radius1;
btTransform m_childTransform;
@@ -156,6 +157,7 @@ struct MyHashShape
m_shapeType(0),
m_sphere0Pos(btVector3(0, 0, 0)),
m_sphere1Pos(btVector3(0, 0, 0)),
+ m_halfExtents(btVector3(0, 0, 0)),
m_radius0(0),
m_radius1(0),
m_deformFunc(0),
@@ -170,12 +172,13 @@ struct MyHashShape
bool sameShapeType = m_shapeType == other.m_shapeType;
bool sameSphere0 = m_sphere0Pos == other.m_sphere0Pos;
bool sameSphere1 = m_sphere1Pos == other.m_sphere1Pos;
+ bool sameHalfExtents = m_halfExtents == other.m_halfExtents;
bool sameRadius0 = m_radius0 == other.m_radius0;
bool sameRadius1 = m_radius1 == other.m_radius1;
bool sameTransform = m_childTransform == other.m_childTransform;
bool sameUpAxis = m_upAxis == other.m_upAxis;
bool sameHalfHeight = m_halfHeight == other.m_halfHeight;
- return sameShapeType && sameSphere0 && sameSphere1 && sameRadius0 && sameRadius1 && sameTransform && sameUpAxis && sameHalfHeight;
+ return sameShapeType && sameSphere0 && sameSphere1 && sameHalfExtents && sameRadius0 && sameRadius1 && sameTransform && sameUpAxis && sameHalfHeight;
}
//to our success
SIMD_FORCE_INLINE unsigned int getHash() const
@@ -447,8 +450,56 @@ void OpenGLGuiHelper::createCollisionShapeGraphicsObject(btCollisionShape* colli
btAlignedObjectArray<GLInstanceVertex> gfxVertices;
btAlignedObjectArray<int> indices;
int strideInBytes = 9 * sizeof(float);
- //if (collisionShape->getShapeType()==BOX_SHAPE_PROXYTYPE)
+ if (collisionShape->getShapeType() == BOX_SHAPE_PROXYTYPE)
{
+ btBoxShape* boxShape = (btBoxShape*)collisionShape;
+
+
+ btAlignedObjectArray<float> transformedVertices;
+
+ btVector3 halfExtents = boxShape->getHalfExtentsWithMargin();
+
+ MyHashShape shape;
+ shape.m_shapeType = boxShape->getShapeType();
+ shape.m_halfExtents = halfExtents;
+ shape.m_deformFunc = 0; ////no deform
+ int graphicsShapeIndex = -1;
+ int* graphicsShapeIndexPtr = m_data->m_hashShapes[shape];
+
+ if (graphicsShapeIndexPtr)
+ {
+ graphicsShapeIndex = *graphicsShapeIndexPtr;
+ }
+ else
+ {
+ int numVertices = sizeof(cube_vertices_textured) / strideInBytes;
+ transformedVertices.resize(numVertices * 9);
+ for (int i = 0; i < numVertices; i++)
+ {
+ btVector3 vert;
+ vert.setValue(cube_vertices_textured[i * 9 + 0],
+ cube_vertices_textured[i * 9 + 1],
+ cube_vertices_textured[i * 9 + 2]);
+
+ btVector3 trVer = halfExtents * vert;
+ transformedVertices[i * 9 + 0] = trVer[0];
+ transformedVertices[i * 9 + 1] = trVer[1];
+ transformedVertices[i * 9 + 2] = trVer[2];
+ transformedVertices[i * 9 + 3] = cube_vertices_textured[i * 9 + 3];
+ transformedVertices[i * 9 + 4] = cube_vertices_textured[i * 9 + 4];
+ transformedVertices[i * 9 + 5] = cube_vertices_textured[i * 9 + 5];
+ transformedVertices[i * 9 + 6] = cube_vertices_textured[i * 9 + 6];
+ transformedVertices[i * 9 + 7] = cube_vertices_textured[i * 9 + 7];
+ transformedVertices[i * 9 + 8] = cube_vertices_textured[i * 9 + 8];
+ }
+
+ int numIndices = sizeof(cube_indices) / sizeof(int);
+ graphicsShapeIndex = registerGraphicsShape(&transformedVertices[0], numVertices, cube_indices, numIndices, B3_GL_TRIANGLES, m_data->m_checkedTextureGrey);
+ m_data->m_hashShapes.insert(shape, graphicsShapeIndex);
+ }
+
+ collisionShape->setUserIndex(graphicsShapeIndex);
+ return;
}
@@ -571,6 +622,8 @@ void OpenGLGuiHelper::createCollisionShapeGraphicsObject(btCollisionShape* colli
}
}
+
+
if (collisionShape->getShapeType() == SPHERE_SHAPE_PROXYTYPE)
{
btSphereShape* sphereShape = (btSphereShape*)collisionShape;