SFCBias
11-09-2010 20:45:26
I'm finding it a little difficult to build the library so i'm just going to submit this as a patch. As far as an example, I can try to create one but you would have to build it on your own.
This is the patch for the Heightfield collision need to change header and source..
Create this as you would any other collision but you don't need to create a body for it.Umm... notify me of any problems and that should be it.
OgreNewt_CollisionPrimitives.h
OgreNewt_CollisionPrimitives.cpp
This is the patch for the Heightfield collision need to change header and source..
Create this as you would any other collision but you don't need to create a body for it.Umm... notify me of any problems and that should be it.
OgreNewt_CollisionPrimitives.h
//! HeightField Collision
/*!
builds a HeightField collision from raw data or directly from a OgreTerrain page
more info: http://newtondynamics.com/wiki/index.php5?title=NewtonCreateHeightFieldCollision
*/
class _OgreNewtExport HeightField : public OgreNewt::Collision
{
public:
HeightField(const World* world, Ogre::Terrain *terrain, int shapeID);
~HeightField(){}
};
OgreNewt_CollisionPrimitives.cpp
HeightField::HeightField(const OgreNewt::World *world,
Ogre::Terrain *terrain, int shapeID) :
OgreNewt::Collision(world)
{
int width, height;
width = height = terrain->getSize() - 1;
int size = width * height;
float* array32 = new float[size];
char* attributes;
// find the min am max in the map
float min = terrain->getMinHeight();
float max = terrain->getMaxHeight();
// crate the new map
unsigned short* elevation = new unsigned short[size];
attributes = (char*) malloc(width * width * sizeof(char));
//float scale = max - min;
float scale = (fabs(max - min) > 1.0e-1f) ? 1.0 : 66535.0f / (max
- min);
// nwo populate the elavation map
Ogre::Real horizontalScale = (terrain->getWorldSize()
/ (terrain->getSize() - 2));
int x = 0;
for (int i = 0; i < width; i++)
{
for (int k = 0; k < height; k++)
{
array32[x] = terrain->getHeightAtPoint(i, k);
x++;
}
}
for (int i = 0; i < size; i++)
{
elevation[i] = (unsigned short) ((array32[i] - min) * scale);
}
float verticalScale = (1.0f / (scale));
m_col = NewtonCreateHeightFieldCollision(m_world->getNewtonWorld(),
width, height, 1, elevation, attributes, horizontalScale,
verticalScale, 2);
delete[] elevation;
delete[] array32;
free(attributes);
NewtonBody* body = NewtonCreateBody(m_world->getNewtonWorld(),
m_col);
// Ogre::SceneNode * sn = m_world->getRootSceneNode();
float matrix[16];
Ogre::Quaternion rot(Ogre::Degree(90), Ogre::Vector3(0, 1, 0));
rot = rot * Ogre::Quaternion::IDENTITY;
OgreNewt::Converters::QuatPosToMatrix(rot, Ogre::Vector3::ZERO,
&matrix[0]);
float mX = width / 2 * horizontalScale;
float mZ = height / 2 * horizontalScale;
matrix[12] -= mX;
matrix[13] += min;
matrix[14] += mZ;
NewtonBodySetMatrix(body, &matrix[0]);
// NewtonBodySetUserData(body, sn);
/* createRigidBody(WORLD,
collision, terrain);*/
// NewtonReleaseCollision(WORLD, collision);
}