The second object, the nut, seems to be good candidate for a convex hull object but the first, the virtual hand, is not a convex object because of the fingers and the curling palm and should be loaded as an impact mesh.
The impact meshes files have a specific data format in Bullet Physics. Here below some code to create an impact mesh, plus an example of an original .obj file of a chair, generated in Blender and formatted for Bullet Physics.
Code: Select all
std::shared_ptr<ImpactMesh> createImpactMesh(std::string nameNode, // offroad truck, bunny, chair, revolution surface,...
btGImpactMeshShape* impactMeshShape,
const btVector3& position = btVector3(0.0f, 10.0f, 0.0f),
std::string textureName = "bunny",
const btVector3& impactMeshScale = btVector3(1.0f, 1.0f, 1.0f),
const float& mass = 50.0f,
const btQuaternion& orientation = btQuaternion(0.0f, 0.0f, 0.0f, 1.0f),
std::string meshName = "bunny",
bool addChild = true);
Code: Select all
std::shared_ptr<ImpactMesh> ObjectFactory::createImpactMesh(std::string nameNode, btGImpactMeshShape* impactMeshShape,
const btVector3& position, std::string textureName, const btVector3& impactMeshScale, const float& mass,
const btQuaternion& orientation, std::string meshName, bool addChild) {
impactMeshShape->setLocalScaling(impactMeshScale);
impactMeshShape->setMargin(0.04f);
impactMeshShape->updateBound();
std::shared_ptr<ImpactMesh> impactMesh = std::shared_ptr<ImpactMesh>(new ImpactMesh(nameNode,
impactMeshShape, position, textureName, mass, orientation, meshName));
if (m_dynamicsWorld && addChild)
m_dynamicsWorld->addRigidBody(impactMesh->getRigidBody());
if (m_world && addChild)
m_world->addChild(impactMesh);
impactMesh->initRenderer(m_renderer);
return impactMesh;
}
Code: Select all
#ifndef IMPACT_MESH_H
#define IMPACT_MESH_H
#include "GeodePhysics.h"
#include "BulletCollision/Gimpact/btGImpactShape.h"
class ImpactMesh : public GeodePhysics {
public:
ImpactMesh(std::string nameNode, btGImpactMeshShape* impactMeshShape, const btVector3 &position, std::string textureName,
const btScalar &mass, const btQuaternion &orientation, std::string meshName);
~ImpactMesh() {}
virtual void update() override;
virtual void deleteAllChildren() override {}
virtual void printAllChildren() override {}
private:
};
#endif
Code: Select all
#include "ImpactMesh.h"
#include <glm/gtc/matrix_transform.hpp>
#include "utils.h"
#include "log.h"
ImpactMesh::ImpactMesh(std::string nameNode, btGImpactMeshShape* impactMeshShape, const btVector3 &position, std::string textureName,
const btScalar &mass, const btQuaternion &orientation, std::string meshName) :
GeodePhysics(nameNode, impactMeshShape, position, textureName, mass, orientation, meshName) {
logFileStderr("MESSAGE: Using mesh \"%s\"... \n", m_meshesNames[0].c_str());
logFileStderr("MESSAGE: Using texture \"%s\"... \n", m_texturesNames[0].c_str());
btVector3 halfSize = impactMeshShape->getLocalScaling();
btTransform transform = m_rigidBody->getWorldTransform();
m_modelMatrix = bullet2glm(transform) * glm::scale(glm::mat4(1.0), bullet2glm(halfSize));
// logFileStderr("model matrix: \n"); printMat4(m_modelMatrix);
// print();
}
void ImpactMesh::update() {
btTransform transform = m_rigidBody->getWorldTransform();
const btGImpactMeshShape* impactMeshShape = static_cast<const btGImpactMeshShape*>(m_collisionShape);
btVector3 halfSize = impactMeshShape->getLocalScaling();
m_modelMatrix = bullet2glm(transform) * glm::scale(glm::mat4(1.0), bullet2glm(halfSize));
// logFileStderr("transform matrix: \n"); printMat4(bullet2glm(transform));
m_boundingSphereCenter = bullet2glm(m_rigidBody->getCenterOfMassPosition() + btVector3(0.0f, m_boundingSphereRadius, 0.0f));
}
You do not have the required permissions to view the files attached to this post.