Hello,
i wanted some help with some code i wrote. i want to make a surface which should act like water. i’m using a trianglestriparray with coordinates by reference. that way i can move the points of my surface up and down to make it look like water waves. for some reason it doesn’t work correctly. my surface it not created right.
below is the geometry creation part:
eg. resolution = 10
{
int N = resolution * 2;
geometry = new TriangleStripArray(N,
GeometryArray.COORDINATES |
GeometryArray.TEXTURE_COORDINATE_2 | GeometryArray.BY_REFERENCE,
2, new int[]{0, 1}, new int[]{N}
); // GeometryArray.NORMALS |
vertices = new float[(resolution - 1) * resolution * 6];
texCoords1 = new float[(resolution - 1) * resolution * 4];
texCoords2 = new float[(resolution - 1) * resolution * 4];
for (int i = 0; i < resolution - 1; i += 1)
{
for (int j = 0; j < resolution; j++)
{
vertices[i * N + j * 2] = i;
vertices[i * N + j * 2 + 1] = 0.0f;
vertices[i * N + j * 2 + 2] = j;
vertices[i * N + j * 2 + 3] = i + 1;
vertices[i * N + j * 2 + 4] = 0.0f;
vertices[i * N + j * 2 + 5] = j;
texCoords1[i * 2 + 0] = (float) i / (float) (resolution - 1);
texCoords1[i * 2 + 1] = (float) j / (float) (resolution - 1);
texCoords1[i * 2 + 2] = ((float) i + 1.0f) / (float) (resolution - 1);
texCoords1[i * 2 + 3] = (float) j / (float) (resolution - 1);
}
if (i % (resolution / 10) == 0)
{
//lf.setValue(lf.getValue() + 10); // change value of progressbar
}
}
geometry.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);
geometry.setCapability(GeometryArray.ALLOW_REF_DATA_READ);
geometry.setCoordRefFloat(vertices);
//geometry.setNormalRefFloat(normals);
geometry.setTexCoordRefFloat(0, texCoords1);
geometry.setTexCoordRefFloat(1, texCoords2);
}
the code doesn't work correctly. it shows a surface with some angles and wrongly oriented. but it should be flat (since all Y values are 0, should be altered by referencing them).