void CCollisionManager::DetectCollisions() { m_collisionsArray.clear(); for( int i=0; i<m_cubes.size(); i++ ) { for( int j=i; j<m_cubes.size(); j++ ) { if( i != j ) { vector<vec3> hitPoints; int numHitPoints = 0; float penetrationBox = 0.0f; vec3 hitNormalBox; bool hitBox = CubeCubeCollisionCheck( m_cubes[i], m_cubes[j], hitPoints, numHitPoints, penetrationBox, hitNormalBox ); if (hitBox) { for (int k=0; k<numHitPoints; k++) { AddCollision( m_cubes[i], m_cubes[j], hitPoints[k], hitNormalBox, penetrationBox ); } } } } } }
void* OgreNewtonSceneBody::AddCollisionTree (SceneNode* const treeNode) { OgreNewtonWorld* const world = (OgreNewtonWorld*) GetNewton(); // convert the nod and all its children to a newton mesh OgreNewtonMesh mesh (world, treeNode); mesh.Polygonize(); // create a collision tree mesh dNewtonCollisionMesh meshCollision (world, mesh, 0); // add this collision to the scene body return AddCollision (&meshCollision); }
void* OgreNewtonSceneBody::AddTerrain (Terrain* const terrain) { OgreNewtonWorld* const world = (OgreNewtonWorld*) GetNewton(); int width = terrain->getSize() - 1; int height = terrain->getSize() - 1; int size = width * height; // Real min = terrain->getMinHeight(); // Real max = terrain->getMaxHeight(); Real horizontalScale = (terrain->getWorldSize() / (terrain->getSize() - 1)); dNewtonScopeBuffer<dFloat> elevations(size); dNewtonScopeBuffer<char> attributes(size); for (int i = 0; i < width; i++) { int index = i * height; for (int k = 0; k < height; k++) { // for now make collsionID zero, until we can get material information from the terrain tile attributes[index] = 0; elevations[index] = terrain->getHeightAtPoint(i, k); index ++; } } // build the height field collision dNewtonCollisionHeightField terrainCollision (world, width, height, 5, 0, 1.0f, horizontalScale, &elevations[0], &attributes[0], 0); // set the offset matrix for this collision shape Vector3 posit (-(width / 2.0f) * horizontalScale, 0.0f, (height / 2.0f) * horizontalScale); Quaternion rot(Ogre::Degree(90.0f), Ogre::Vector3(0.0f, 1.0f, 0.0f)); Matrix4 matrix; matrix.makeTransform (posit, Vector3(1.0f, 1.0f, 1.0f), rot); matrix = matrix.transpose(); terrainCollision.SetMatrix (&matrix[0][0]); return AddCollision (&terrainCollision); }