[ODE] Extracting terrain data from Demeter

Nate W coding at natew.com
Fri Aug 15 13:33:01 2003


On Sat, 16 Aug 2003, Sandeep KL wrote:

> i got my terrain collider working finally!!
> even if ur diagonal is the other way round, it should be easy to fix. all u 
> have to do is change the vertex orders in ur collision functions........it 
> is pretty straight forward........shouldnt be hard!

Yep.  I fixed it last night, after writing that message.  Didn't get
around to testing it until today though.  I've put the changed code at the
end of this message.

> Heres the code for a collider (sphere - heightfield) if u need more
> help on this.......send me a mail......i shall send u the entire code
> for a sphere-heightfield and a box-heightfield collider......

This would probably make a very good addition to ODE!

-- 

Nate Waddoups
Redmond WA USA
http://www.natew.com

--

	// Each square in the height map has 4 corners, as follows:
	//
	// 3 4
	// 1 2
	//
	// 1 = x,	y
	// 2 = x+1,	y
	// 3 = x,	y+1
	// 4 = x+1, y+1
	//
	// Triangles are: 1,2,3 and 4,3,2
	//
	for (int iX = 0; iX < iMaxX - 1; iX++)	
	{
		iTriangle = (iY * (iMaxY - 1) * 2) + (iX * 2);

		// X, Y
		iIndex = (iY * iMaxX) + iX;
		m_pTriangleArray[iTriangle].v1 = iIndex;

		// X+1, Y
		iIndex = (iY * iMaxX) + iX + 1;
		m_pTriangleArray[iTriangle].v2 = iIndex;
			
		// X, Y+1
		iIndex = ((iY * iMaxX) + iX) + iMaxX;
		m_pTriangleArray[iTriangle].v3 = iIndex;

		iTriangle++;
	
		// X + 1, Y + 1
		iIndex = ((iY * iMaxX) + iX) + 1 + iMaxX;
		m_pTriangleArray[iTriangle].v1 = iIndex;			
			
		// X, Y + 1
		iIndex = ((iY * iMaxX) + iX) + iMaxX;
		m_pTriangleArray[iTriangle].v2 = iIndex;

		// X+1, Y
		iIndex = (iY * iMaxX) + iX + 1;
		m_pTriangleArray[iTriangle].v3 = iIndex;
	}