[ODE] Problems with trimesh

Pawel S unixbird at yahoo.se
Mon Feb 28 12:52:17 MST 2005


Hello!

I'm having problems with creating a trimesh from regular grid terrain
data. The terrain is 512x512 large. I've tried both
dGeomTriMeshDataBuildSimple and dGeomTriMeshDataBuildDouble1 with no
success. I use a sphere to test my code. With dGeomTriMeshDataBuildSimple
the sphere seems to move in the z-y plane (up-down and forward-backward)
and disappears after a few bounces. With dGeomTriMeshDataBuildDouble1 the
sphere falls through as if there wasn't any trimesh to stop it.

Here is a piece of my code:

// types
typedef dReal tVertex[ 3 ];

// vars
tVertex* m_pVerts;
int* m_pVertIndices;
tVertex* m_pNormals;

int iVert = 0;
for ( int iz1 = 0; iz1 < m_iSize + 1; iz1++ )
{
	for ( int ix1 = 0; ix1 < m_iSize + 1; ix1++ )
	{
		m_pVerts[ iVert ][ _x_ ] = ix1;
		m_pVerts[ iVert ][ _y_ ] = GetElevation( ix1, iz1 );
		m_pVerts[ iVert ][ _z_ ] = iz1;
		iVert++;
	}
}

int iVertIndex = 0;
int iTriIndex = 0;
for ( int iz2 = 0; iz2 < m_iSize; iz2++ )
{
	cVector v1, v2, v3, vN;

	for ( int ix2 = 0; ix2 < m_iSize; ix2++ )
	{

// filling in the first triangle of a square
m_pVertIndices[ iVertIndex ] = m_iSize * iz2 + ix2;
v1 = cVector( m_pVerts[ m_pVertIndices[ iVertIndex ] ] );
iVertIndex++;

m_pVertIndices[ iVertIndex ] = m_iSize * iz2 + ix2 + 1;
v2 = cVector( m_pVerts[ m_pVertIndices[ iVertIndex ] ] );
iVertIndex++;

m_pVertIndices[ iVertIndex ] = m_iSize * iz2 + ix2 + m_iSize + 1;
v3 = cVector( m_pVerts[ m_pVertIndices[ iVertIndex ] ] );
iVertIndex++;

vN = CrossProduct( v2 - v1, v2 - v3 );
m_pNormals[ iTriIndex ][ _x_ ] = vN.x;
m_pNormals[ iTriIndex ][ _y_ ] = vN.y;
m_pNormals[ iTriIndex ][ _z_ ] = vN.z;
iTriIndex++;

// the second triangle
m_pVertIndices[ iVertIndex ] = m_iSize * iz2 + ix2 + m_iSize + 1;
v1 = cVector( m_pVerts[ m_pVertIndices[ iVertIndex ] ] );
iVertIndex++;

m_pVertIndices[ iVertIndex ] = m_iSize * iz2 + ix2 + m_iSize;
v2 = cVector( m_pVerts[ m_pVertIndices[ iVertIndex ] ] );
iVertIndex++;

m_pVertIndices[ iVertIndex ] = m_iSize * iz2 + ix2;
v3 = cVector( m_pVerts[ m_pVertIndices[ iVertIndex ] ] );
iVertIndex++;

vN = CrossProduct( v2 - v1, v2 - v3 );
m_pNormals[ iTriIndex ][ _x_ ] = vN.x;
m_pNormals[ iTriIndex ][ _y_ ] = vN.y;
m_pNormals[ iTriIndex ][ _z_ ] = vN.z;
iTriIndex++;
	}
}

// and finally creating the trimesh
int iNumVerts = Terrain.GetNumVerts();

// case a
TerrainMeshDataID = dGeomTriMeshDataCreate();
//dGeomTriMeshDataBuildSimple( TerrainMeshDataID,
(dReal*)Terrain.GetVerts(), iNumVerts, Terrain.GetVertIndices(),
Terrain.GetNumIndices() );

// case b
dGeomTriMeshDataBuildDouble1( TerrainMeshDataID,
Terrain.GetVerts(), sizeof( tVertex ), iNumVerts,
Terrain.GetVertIndices(), Terrain.GetNumTris(), 3 * sizeof( uint ),
Terrain.GetNormals() );

TerrainGeomID = dCreateTriMesh( WorldSpace, TerrainMeshDataID, 0, 0, 0 );

With regards
Pawel S



More information about the ODE mailing list