Is the size of your vertex also 16 bytes?
Each vertex x, y, z coordinate is packed into a separate float element.
[0] [1] [2] = Vertex1
[3] [4] [5] = Vertex2, etc.
I will get an access violation error if I use anything greater than sizeof(float).
Code: Select all
btCollisionShape* shape = new btConvexHullShape(settings.vertices().data(), settings.vertices().size(), sizeof(float));
I presume I am therefore going to have to iterate through the array and create a new array of btVector3 from the elements?
Code: Select all
int numElements = settings.vertices().size();
btAlignedObjectArray<btVector3> vertices;
//std::vector<btVector3> vertices;
vertices.reserve(numElements / 3);
for (int i = 0; i < numElements; i += 3)
{
vertices.push_back(btVector3(settings.vertices().Get(i), settings.vertices().Get(i + 1), settings.vertices().Get(i + 2)));
}
In order to see if that has worked I am attempting to draw the convex hull as a wireframe. Unfortunately after trying to get the underlying btConvexPolyhedron I run into bad pointer (with *cp not *convexHullShape) problems which indicates something is incorrect.
Code: Select all
const btConvexHullShape* convexHullShape = static_cast<const btConvexHullShape*>(m_body->getCollisionShape());
const btConvexPolyhedron *cp = convexHullShape->getConvexPolyhedron();
I am stuck as to what that could be though.
EDIT:
The min max points for the AABB are also (0, 0, 0) showing that shape is not created correctly:
Code: Select all
btTransform trans = m_body->getWorldTransform();
btVector3 min;
btVector3 max;
convexHullShape->getAabb(trans, min, max);
const btVector3 &pos = trans.getOrigin();
const btVector3 &e = max - pos;
const btMatrix3x3 &m = m_body->getWorldTransform().getBasis();
EDIT2:
I have tried adding each point explicitly, it's not ideal but I can get a valid AABB with this approach
Code: Select all
btConvexHullShape *shape = new btConvexHullShape();
for (int i = 0; i < numElements; i += 3)
{
shape->addPoint(btVector3(settings.vertices().Get(i), settings.vertices().Get(i + 1), settings.vertices().Get(i + 2)));
}
The btConvexPolyhedron pointer is still not valid though.