rogerdv
22-09-2010 14:25:12
I have set up the basic creation of objects and ogrebulet initialization according to the demos:
Static meshes (trees, houses)
This is for creating animated stuff, like player and NPCs
the terrain:
and I update the physics world each frame. But this seems to be enough for the boxes demo, but in my game I dont get any visible result, the player moves through objects without any collision detection. PErhaps the problem is that Im still moving the nodes with ogre translate methods, should I use something else, like applying forces?
Static meshes (trees, houses)
void btPhysics::createStaticShape(Ogre::String name, Ogre::Entity *mesh, Ogre::SceneNode *node, float mass)
{
Vector3 size;
AxisAlignedBox boundingB = mesh->getBoundingBox();
size = boundingB.getSize();
size /= 2.0f; // only the half needed
size *= 0.96f;
StaticMeshToShapeConverter *trimeshConverter = new StaticMeshToShapeConverter(mesh);
TriangleMeshCollisionShape *sceneTriMeshShape = trimeshConverter->createTrimesh();
delete trimeshConverter;
RigidBody *defaultBody = new OgreBulletDynamics::RigidBody(name, mWorld);
defaultBody->setShape(node, sceneTriMeshShape, 0.6f, // dynamic body restitution
0.6f, // dynamic body friction
mass, // dynamic bodymass
node->getPosition(), // starting position of the box
Quaternion(1,0,0,0));// orientation of the box*/
mBodies.push_back(defaultBody);
mShapes.push_back(sceneTriMeshShape);
}This is for creating animated stuff, like player and NPCs
void btPhysics::createAnimatedShape(Ogre::String name, Ogre::Entity *mesh, Ogre::SceneNode *node)
{
Vector3 size;
AxisAlignedBox boundingB = mesh->getBoundingBox();
size = boundingB.getSize();
size /= 2.0f; // only the half needed
size *= 0.96f;
StaticMeshToShapeConverter *trimeshConverter = new StaticMeshToShapeConverter(mesh);
TriangleMeshCollisionShape *sceneTriMeshShape = trimeshConverter->createTrimesh();
delete trimeshConverter;
RigidBody *defaultBody = new OgreBulletDynamics::RigidBody(name, mWorld);
defaultBody->setShape(node, sceneTriMeshShape, 0.6f, // dynamic body restitution
0.6f, // dynamic body friction
2.0, // dynamic bodymass
node->getPosition(), // starting position of the box
Quaternion(1,0,0,0));// orientation of the box*/
defaultBody->setKinematicObject(true);
defaultBody->disableDeactivation();
mBodies.push_back(defaultBody);
mShapes.push_back(sceneTriMeshShape);
}the terrain:
void btPhysics::createTerrainShape(Ogre::SceneNode *node, Ogre::Image heightmap, float worldsize, float maxheight)
{
int pagesize = heightmap.getWidth();
float *heights = new float [pagesize*pagesize];
for(unsigned y = 0; y < pagesize; ++y) {
for(unsigned x = 0; x < pagesize; ++x) {
Ogre::ColourValue color = heightmap.getColourAt(x, y, 0);
heights[x + y *pagesize] = color.r;
}
}
Vector3 terrainScale(worldsize /(pagesize-1), maxheight, worldsize /(pagesize-1));
HeightmapCollisionShape *mTerrainShape = new HeightmapCollisionShape(pagesize, pagesize, terrainScale, heights, true);
RigidBody *defaultTerrainBody = new RigidBody("Terrain", mWorld);
const float terrainBodyRestitution = 0.6f;
const float terrainBodyFriction = 0.8f;
Ogre::Vector3 terrainShiftPos( (terrainScale.x * (pagesize - 1) / 2), 0, (terrainScale.z * (pagesize - 1) / 2));
terrainShiftPos.y = terrainScale.y / 2 * terrainScale.y;
defaultTerrainBody->setStaticShape (node, mTerrainShape, terrainBodyRestitution, terrainBodyFriction, terrainShiftPos);
mBodies.push_back(defaultTerrainBody);
mShapes.push_back(mTerrainShape);
}and I update the physics world each frame. But this seems to be enough for the boxes demo, but in my game I dont get any visible result, the player moves through objects without any collision detection. PErhaps the problem is that Im still moving the nodes with ogre translate methods, should I use something else, like applying forces?