Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

D8575777

Terrain rendering gone wrong

This topic is 5224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here is a link to the picture of my problem, I have been scouring the internet for info tring to make terrain(most of it is OpenGL and then I try to convert to DX-C#) Problem code(I believe):
public void Render()
		{
			device.SetTexture(0, groundTexture);
			device.VertexFormat = ColorVertex.Format;
			device.SetStreamSource(0, groundVertexBuffer, 0);
			
			if(lines)
			device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, numGroundVertices);
			else
			device.DrawPrimitives(PrimitiveType.LineStrip, 0, numGroundVertices);
		}

private void CreateGround(object sender, EventArgs e)
		{

			VertexBuffer vb = (VertexBuffer)sender;
			// Fill vertex buffer
			ColorVertex[] vertices = (ColorVertex[])vb.Lock(0, 0);
		
			int count = 0;
		    // Fill in vertices
			for (int xx = 0; xx <= AREA_SIZE; xx++)
			{
				for (int zz = 0; zz <= AREA_SIZE; zz++)
				{
					vertices[count].v.X   = F*(xx+1);
					vertices[count].v.Y   = F*(hfield[(xx*AREA_SIZE+1)+zz]/128);
					vertices[count].v.Z   = F*zz;
					vertices[count].color = unchecked((int)GroundColor);
					vertices[count].tu    = xx*F/(float)AREA_SIZE;
					vertices[count].tv    = zz*F/(float)AREA_SIZE;
					//count++;
					vertices[++count].v.X   = F*(xx);
					vertices[count].v.Y   = F*(hfield[(xx*AREA_SIZE)+zz]/128);
					vertices[count].v.Z   = F*zz;
					vertices[count].color = unchecked((int)GroundColor);
					vertices[count].tu    = xx*F/(float)AREA_SIZE;
					vertices[count].tv    = zz*F/(float)AREA_SIZE;
}
}

This is just a snippet of code in a class I am making so I can just drop in the ground and not have things so flat. I have been trying to do this for awhile and am stuck, any help or point me in the right direction would be appreciated. TIA D <SPAN CLASS=editedby>[edited by - d8575777 on June 1, 2004 8:40:29 PM]</SPAN> <SPAN CLASS=editedby>[edited by - d8575777 on June 1, 2004 8:41:13 PM]</SPAN> <SPAN CLASS=editedby>[edited by - d8575777 on June 1, 2004 8:42:57 PM]</SPAN> <SPAN CLASS=editedby>[edited by - d8575777 on June 1, 2004 8:46:50 PM]</SPAN> [Edited by - D8575777 on August 24, 2004 10:04:43 AM]

Share this post


Link to post
Share on other sites
Advertisement
Are you trying to render the whole terrain with a single triangle strip?

Because it doesn''t look like your code is creating any degenerate triangles to deal with the edges of the terrain properly - although the end of your for loop is cut off so I may be wrong.

Also, I think this line:

vertices[count].v.Y = F*(hfield[(xx*AREA_SIZE+1)+zz]/128)


should be


vertices[count].v.Y = F*(hfield[((xx+1)*AREA_SIZE)+zz]/128)

Share this post


Link to post
Share on other sites
That did the trick, PEMDAS got me again, C# gives me problems when i try 2-D arrays, ie. float[][] hfield = new float[AREA_SIZE][AREA_SIZE]; doesn't work for me. Now I believe I can move on, thanks!













[edited by - D8575777 on June 2, 2004 8:43:18 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!