Advertisement

Making a grid

Started by May 09, 2003 03:12 PM
1 comment, last by Yoshy 21 years, 9 months ago
Hi everyone, I have a small problem; I''m trying to make a grid with tri stips. I want the smallest vertex count I can have.. The vertices are at the right place but I can''t figure out the index to use. Here''s what I''ve tried (taken straight out of my engine):

m_Surface.iNumVertex = (m_iWaterX+1) * m_iWaterY;
m_Surface.iNumIndices = m_iWaterX * m_iWaterY;
OwnNextAlloc;m_Surface.vVertexList = new Vertex[ m_Surface.iNumVertex + 1 ];
OwnNextAlloc;m_Surface.pIndices = new INDEX[ m_Surface.iNumIndices + 1 ];

m_Surface.rmRenderMode = RENDER_WIREFRAME;
m_Surface.rtRenderType = RENDER_STRIP;
m_Surface.pMaterial = &m_Material;

float MidX = m_iWaterX / 2.0f;
float MidY = m_iWaterY / 2.0f;

for ( int X = 0; X < m_iWaterX; X++ )
{
	Vertex vGenA; // Vertex to put

	for ( int Z = 0; Z < m_iWaterY; Z++ ) {
        vGenA.v3Point.Set( float(X+1 - m_iWaterX) + MidX, 0.0f, float(Z - m_iWaterY) + MidY );
		vGenA.tcTexture.Set( float(X+1) / float(m_iWaterX), float(Z) / float(m_iWaterY) );
		vGenA.cVertexCol.Set( float(X+1) / float(m_iWaterX), float(Z) / float(m_iWaterY), 1, 1);

		m_Surface.vVertexList[VertexNumber++] = vGenA;
	}
} // END FOR

for ( int i = 0; i < m_iWaterX; i++ ) {
	bool Switch = (i % 2) != 0;
	int PartA = (Switch) ? -(m_iWaterY-1) : m_iWaterY;

	for ( int j = 0; j < m_iWaterY; j++ ) {
		INDEX CurrentIndice = (i * m_iWaterY) + j;
		m_Surface.pIndices[ CurrentIndice ] = CurrentIndice + PartA;
	}
}
 
I tried to make an algorithme on paper but I guess I''m not that good at it Thanks in advance ! _____________________
_____________________
Look into GL Evaluators, gamedev posted an article recently on it, that is by far the fastest way to render a grid.
Advertisement
Well, I need the vertex coords... And it isn't sure the render is OpenGL... it could be software.

Besides, the Y coord on the grid needs to be dynamic...

[edited by - Yoshy on May 9, 2003 11:47:25 PM]
_____________________

This topic is closed to new replies.

Advertisement