Collision for new terrain

shanefarris

20-06-2010 08:00:32

When we setup collision for the heightmap terrain (the old version) we would pass in a scale vector which looks like its used only for the "getHeightAt" method used in a standard terrain collision listener. Now that Ogre has a get height method for the terrain, is it still necessary to pass this vector in?

Here is the getHeightAt method in the OgreOdeGeometry.h file:

inline Ogre::Real getHeightAt(const reVector3Df& position)
{
_num_query++;
const reVector3Df pos (position.x * _sample_width - (_centered?_halfWorldSizeX:0),
position.y,
position.z * _sample_height - (_centered?_halfWorldSizeZ:0));
_ray.setOrigin(pos);
_ray_query->setRay(_ray);
_distance_to_terrain = static_cast<Ogre::Real>(0.0);
_ray_query->execute(this);
return position.y - _distance_to_terrain;
}


_sample_width and _sample_height are only used in this method (from what I can tell), and they are set using the scale vector passed in by the TerrainGeometry constructor:


TerrainGeometry::TerrainGeometry(World *world, Space* space,
const reVector3Df &scale,
int nodes_per_sideX,
int nodes_per_sideY,
Ogre::Real worldSizeX,
Ogre::Real worldSizeZ,
bool centered,
Ogre::Real thickness) :
Geometry(world, space),
_sample_width(scale.x),
_sample_height(scale.z),
_max_height (scale.y),
_halfWorldSizeX(worldSizeX * 0.5),
_halfWorldSizeZ(worldSizeZ * 0.5),
_centered(centered)
{
dHeightfieldDataID heightid = dGeomHeightfieldDataCreate();
dGeomHeightfieldDataBuildCallback( heightid, //getSpaceID(space),
this, // pUserData ?
TerrainGeometry::_heightCallback,
(dReal) (worldSizeX), //X
(dReal) (worldSizeZ), //Z
nodes_per_sideX, // w // Vertex count along edge >= 2
nodes_per_sideY, // h // Vertex count along edge >= 2
REAL( 1.0 ), //scale
REAL( 0.0 ), // vOffset
thickness, // vThickness
0); // nWrapMode


// Give some very bounds which, while conservative,
// makes AABB computation more accurate than +/-INF.
dGeomHeightfieldDataSetBounds( heightid, REAL( 0.0 ), _max_height );
_geom = dCreateHeightfield( getSpaceID(space), heightid, 1 );

_listener = 0;
_ray = Ogre::Ray (reVector3Df::ZERO, reVector3Df::NEGATIVE_UNIT_Y);
_ray_query = _world->getSceneManager()->createRayQuery(_ray);

_ray_query->setQueryTypeMask(SceneManager::WORLD_GEOMETRY_TYPE_MASK );
_ray_query->setWorldFragmentType(Ogre::SceneQuery::WFT_SINGLE_INTERSECTION);

registerGeometry();

if (_centered)
{
// PLSM2 is centered by default.
//setPosition (reVector3Df::ZERO);
;
}
else
{
// TSM is not centered by default.
setPosition (reVector3Df(_halfWorldSizeX,
0,
_halfWorldSizeZ));
}
setOrientation(Ogre::Quaternion::ZERO);
}



I think we don't need this vector anymore, thoughts?

Thanks.

kamaliang

27-09-2010 03:42:38

I think so...but I was confused with these new terrain working with the OgreOde... :oops: