# Help with Grid and Terrain

I’m trying to make some terrain with a grid that looks up the height and sets all the triangles with the Y that has this point as a shared coordinate. My code Is included and so is an image of the result, which has only the one triangle being affected. For now I am not worried about memory efficiency.

``````void makeVertexGrid(int row, int column)
{

int i = 0;
float firsttriangle = { {1.,.5,-5.},
{-1.,.5,5.},
{-1.,.5,-5.} };

float secondtriangle = { {1,.5,-5  },
{1,.5,5},
{-1,.5,5} };
//rows
for (int r = 0; r < 8 ; r++)
{
if (r > 0)
{
//next colum so add 10 z units each time
firsttriangle = (firsttriangle + 10.0f);
firsttriangle = firsttriangle + 10.0f;
firsttriangle = firsttriangle + 10.0f;
secondtriangle = secondtriangle + 10.0f;
secondtriangle = secondtriangle + 10.0f;
secondtriangle = secondtriangle + 10.0f;

firsttriangle = 1.f; //firsttriangle = .5f;
firsttriangle = -1.f; //firsttriangle = .5f;
firsttriangle = -1.f; //firsttriangle = .5f;
secondtriangle = 1.f; //secondtriangle = .5;
secondtriangle = 1.f; //secondtriangle = .5;
secondtriangle = -1.f; //secondtriangle = .5;
}
for (int c = 0 ; c<  30; c++)
{
// X
g_vertex_buffer_data[i++] = firsttriangle[(c % 3)]++;
firsttriangle[(c % 3)]++;
//Y
g_vertex_buffer_data[i++] = gridForY(r + 5, c + 1);
//Z
g_vertex_buffer_data[i++] = firsttriangle[c % 3];
}

for (int c = 0 ; c < 30; c++)
{
g_vertex_buffer_data[i++] = secondtriangle[(c % 3)][(0)]++;
secondtriangle[(c % 3)][(0)]++;
g_vertex_buffer_data[i++] = gridForY(r + 5, c + 1);
g_vertex_buffer_data[i++] = secondtriangle[c % 3];

}

}

}
``````

My idea was to get this working and than get help / manage the terrain as quads instead of triangles.

What do I need to do to get this point shared by all the triangles that share this coordinate?

Also, my goal was to get some experience with C++ projects so I can get a job. I chose a ball that moves on a rotated terrain. Am I being to ambitious? I’m not sure if there is enough sample code / help to learn this. Could you advise me? OpenGL is interesting.

Thank you,
Josheir Just to explain: the two double array triangles are the three vertices, for each triangle, one in each row : x y z.

Thanks for your time,

Josheir