Jump to content
  • Advertisement
Sign in to follow this  
AgentChaos

Convert Terrain from XNA to DX9 C++

This topic is 2831 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

Sorry about bad english
I'm trying to convert this code:


private void SetUpVertices()
{
vertices = new VertexPositionColor[terrainWidth * terrainHeight];
for (int x = 0; x < terrainWidth; x++)
{
for (int y = 0; y < terrainHeight; y++)
{
vertices[x + y * terrainWidth].Position = new Vector3(x, 0, -y);
vertices[x + y * terrainWidth].Color = Color.White;
}
}
}



to C++
and i convert my terrain from 1 dimensional array
to multidimensional arry for my vertices like in the XNA tut.
Here:


OURCUSTOMVERTEX **cv_Vertices = new
OURCUSTOMVERTEX*[WIDTH];
for (int i = 0; i < HEIGHT; i++)
{
cv_Vertices = new OURCUSTOMVERTEX [WIDTH];
}

if (f_DataFile.is_open())
{
for (int i = 0;i< (offset);i++)
{
dummy = f_DataFile.get();
}

for (int x=0;x< WIDTH;x++)
{
for (int y=0; y< HEIGHT;y++)
{
int height = f_DataFile.get();
height += f_DataFile.get();
height += f_DataFile.get();
height /= 8;

cv_Vertices[x][y].x = x;
cv_Vertices[x][y].y = y;
cv_Vertices[x][y].z = height;
cv_Vertices[x][y].color0xffffffff;
}
}
}



But My terrain look very bad:http://img202.imageshack.us/f/terrainy.jpg/

Maybe there is another way? the problem is with the location in the arry [x][y],its suposs to be another thing.

Share this post


Link to post
Share on other sites
Advertisement
I don't see why you'd want a 2 dimensional array in the C++ version. The vertex data probably needs to be contiguous and the only way to guarantee that is to new a single array.

Share this post


Link to post
Share on other sites
Don't use a multidimensional array. Go back to a single like in the XNA version and see what the results are.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!