Skip to main content
gamedev.net
🔒 Locked

creating vertices

Started by steg 2 replies 350+ views
Original Post
steg
steg
Hi all, I am creating my terrain vertices as follows:
      
	for (int amount = 0; amount <= m_zDim; amount++)
	{
		for(int i = 0; i <= m_xDim; i++)
		{
			y = GetHeight(i,amount);  // vary this amount for height

			m_pTestQuad[i+index].x = x;
			m_pTestQuad[i+index].y = y;
			m_pTestQuad[i+index].z = z;
			m_pTestQuad[i+index].DiffuseColor = RGB(0,0,220);
			x+=16;  // width of quad

		}
		x = 0;
		z -= 20;    // depth of quad

	//	y = 0;

		index += m_xDim + 1;   // next quad

	}

  
m_xDim is the dimension of the map, now for some reason, what is drawn doesn't look like the heigh map I created in Terragen, anyone see what could be wrong here ? I am using index buffers and tri-lists, my indices are created as follows where LOD is the level of detail (just using 1) :
  
void CTerrain::CreateLODIndices(int LOD)
{
	int index = 0;
	int offset = 0;
	m_pLOD1Indices = new WORD[(m_xDim/LOD)*(m_zDim/LOD)*6];   

	m_LOD = LOD;

	int x = m_xDim + 1;
	for(int row=0; row < (m_zDim/LOD); row++)
	{
		for(int col=0; col < m_xDim/LOD; col++)
		{

			m_pLOD1Indices[index] = LOD * (col + offset);
			
			m_pLOD1Indices[index+1] = LOD * (col + offset + x + 1);
			m_pLOD1Indices[index+2] = LOD * (col + offset + x);

			m_pLOD1Indices[index+3] = LOD * (col + offset + 1);
			m_pLOD1Indices[index+4] = LOD * (col + offset + 1 + x);
			m_pLOD1Indices[index+5] = LOD * (col + offset);

			index += 6;
		}
		offset += x;
	}
}
    
  
And I get the height as follows :
        
float CTerrain::GetHeight(int i, int j)
{
	return g_HeightMap[i*(m_xDim)+j];
}
    
Puzzling me ? Kind regards, Steve [edited by - steg on May 20, 2003 7:15:34 AM] [edited by - steg on May 20, 2003 7:16:25 AM]
If it isn't working, take a bath, have a think and try again...
steg
steg
I''ve added a zip file of the program if you would care to take a look, it is in the downloads section of the link below in my signature.

Use cursor keys for forwards and backwards, rotate left and right. Put numlock on and use keys 8 and 2 for up down and 4 and 6 for straife left/right.

See how ugly the terrain is!

Kinds regards,
Steve



As I get older, my mind becomes more cluttered.

[3d Game development]
If it isn't working, take a bath, have a think and try again...
Dreamforger
Dreamforger
First of all: your homepage''s download link doesn''t work. So I couldn''t try your prog.

In order for your code to be correct the following must hold true:

1) xDim and yDim are the number of polygons in your terrain. Not the number of control points. Otherwise the indexing wouldn''t work.
2) z of the first snippet was initialised.
3) "index += m_xDim + 1; // next quad" should be "...// next line" Either comment correctly or don''t

If it isn''t any of of the above, your problem is buried someplace I can''t see.

You might want to look into trianglestrips. You only need (xDim+1)*(yDim)*2 instead of xDim*yDim*6 indices.




---------------------------
I may be getting older, but I refuse to grow up
I may be getting older, but I refuse to grow up
steg
steg
Homepage link should be working now, switched site over to a linux server not long ago, sorry for any inconvenience.

Sorry, should have shown that z and x are initialised to zero at start.

m_zDim is row of quads, m_xDim is column of quads, both set to 128.

As for comments, I am versed in software engineering tehcniques and yes, I should have put a more decent comment in there!

Did use tri-strips and got fed up with struggling with degenerate triangles.

Thanks,
Steve

If it isn't working, take a bath, have a think and try again...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.