|
|
|
@ -286,6 +286,49 @@ const short cube_tris[] =
|
|
|
|
|
const int cube_num_verts = 8;
|
|
|
|
|
const int cube_num_tris = 12;
|
|
|
|
|
|
|
|
|
|
// Internal version that does not copy buffers
|
|
|
|
|
void createTriShape(int32_t numFaces, void *triArray,
|
|
|
|
|
int32_t numVerts, void *vertArray,
|
|
|
|
|
float *trans, float *matrix)
|
|
|
|
|
{
|
|
|
|
|
// This struct holds the index and vertex buffers of a single
|
|
|
|
|
// trimesh.
|
|
|
|
|
btIndexedMesh im;
|
|
|
|
|
|
|
|
|
|
// Set up the triangles
|
|
|
|
|
int numTriangles = numFaces / 3;
|
|
|
|
|
im.m_numTriangles = numTriangles;
|
|
|
|
|
im.m_triangleIndexStride = 6; // 3 indices * 2 bytes per short
|
|
|
|
|
im.m_triangleIndexBase = (unsigned char*)triArray;
|
|
|
|
|
|
|
|
|
|
// Set up the vertices
|
|
|
|
|
im.m_numVertices = numVerts;
|
|
|
|
|
im.m_vertexStride = 12; // 4 bytes per float * 3 floats per vertex
|
|
|
|
|
im.m_vertexBase = (unsigned char*)vertArray;
|
|
|
|
|
|
|
|
|
|
// Transform vertex values in vb according to 'trans' and 'matrix'
|
|
|
|
|
float *vb = (float*)im.m_vertexBase;
|
|
|
|
|
for(int i=0; i<numVerts; i++)
|
|
|
|
|
{
|
|
|
|
|
float x,y,z;
|
|
|
|
|
|
|
|
|
|
// Reinventing basic linear algebra for the win!
|
|
|
|
|
x = matrix[0]*vb[0]+matrix[1]*vb[1]+matrix[2]*vb[2] + trans[0];
|
|
|
|
|
y = matrix[3]*vb[0]+matrix[4]*vb[1]+matrix[5]*vb[2] + trans[1];
|
|
|
|
|
z = matrix[6]*vb[0]+matrix[7]*vb[1]+matrix[8]*vb[2] + trans[2];
|
|
|
|
|
*(vb++) = x;
|
|
|
|
|
*(vb++) = y;
|
|
|
|
|
*(vb++) = z;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If no mesh is currently active, create one
|
|
|
|
|
if(g_currentMesh == NULL)
|
|
|
|
|
g_currentMesh = new btTriangleIndexVertexArray;
|
|
|
|
|
|
|
|
|
|
// Add the mesh. Nif data stores triangle indices as shorts.
|
|
|
|
|
g_currentMesh->addIndexedMesh(im, PHY_SHORT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create a (trimesh) box with the given dimensions. Used for bounding
|
|
|
|
|
// boxes. TODO: I guess we have to use the NIF-specified bounding box
|
|
|
|
|
// for this, not our automatically calculated one.
|
|
|
|
@ -327,54 +370,11 @@ extern "C" void bullet_createTriShape(int32_t numFaces,
|
|
|
|
|
float *trans,
|
|
|
|
|
float *matrix)
|
|
|
|
|
{
|
|
|
|
|
createTriShape(numFaces, copyBuffer(triArray, 2, numFaces)
|
|
|
|
|
createTriShape(numFaces, copyBuffer(triArray, 2, numFaces),
|
|
|
|
|
numVerts, copyBuffer(vertArray, 12, numVerts),
|
|
|
|
|
trans, matrix);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Internal version that does not copy buffers
|
|
|
|
|
void createTriShape(int32_t numFaces, void *triArray,
|
|
|
|
|
int32_t numVerts, void *vertArray,
|
|
|
|
|
float *trans, float *matrix)
|
|
|
|
|
{
|
|
|
|
|
// This struct holds the index and vertex buffers of a single
|
|
|
|
|
// trimesh.
|
|
|
|
|
btIndexedMesh im;
|
|
|
|
|
|
|
|
|
|
// Set up the triangles
|
|
|
|
|
int numTriangles = numFaces / 3;
|
|
|
|
|
im.m_numTriangles = numTriangles;
|
|
|
|
|
im.m_triangleIndexStride = 6; // 3 indices * 2 bytes per short
|
|
|
|
|
im.m_triangleIndexBase = (unsigned char*)triArray;
|
|
|
|
|
|
|
|
|
|
// Set up the vertices
|
|
|
|
|
im.m_numVertices = numVerts;
|
|
|
|
|
im.m_vertexStride = 12; // 4 bytes per float * 3 floats per vertex
|
|
|
|
|
im.m_vertexBase = (unsigned char*)vertArray;
|
|
|
|
|
|
|
|
|
|
// Transform vertex values in vb according to 'trans' and 'matrix'
|
|
|
|
|
float *vb = (float*)im.m_vertexBase;
|
|
|
|
|
for(int i=0; i<numVerts; i++)
|
|
|
|
|
{
|
|
|
|
|
float x,y,z;
|
|
|
|
|
|
|
|
|
|
// Reinventing basic linear algebra for the win!
|
|
|
|
|
x = matrix[0]*vb[0]+matrix[1]*vb[1]+matrix[2]*vb[2] + trans[0];
|
|
|
|
|
y = matrix[3]*vb[0]+matrix[4]*vb[1]+matrix[5]*vb[2] + trans[1];
|
|
|
|
|
z = matrix[6]*vb[0]+matrix[7]*vb[1]+matrix[8]*vb[2] + trans[2];
|
|
|
|
|
*(vb++) = x;
|
|
|
|
|
*(vb++) = y;
|
|
|
|
|
*(vb++) = z;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If no mesh is currently active, create one
|
|
|
|
|
if(g_currentMesh == NULL)
|
|
|
|
|
g_currentMesh = new btTriangleIndexVertexArray;
|
|
|
|
|
|
|
|
|
|
// Add the mesh. Nif data stores triangle indices as shorts.
|
|
|
|
|
g_currentMesh->addIndexedMesh(im, PHY_SHORT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the shape built up so far, if any. This clears g_currentMesh,
|
|
|
|
|
// so the next call to createTriShape will start a new shape.
|
|
|
|
|
extern "C" btCollisionShape *bullet_getFinalShape()
|
|
|
|
|