Hello ! I modified the JCudaDriverGLSample3. I changed the way of positioning objects (points). I don’t have the meshWidth and meshHeight to calculate the position but I use this function (I created also the additional class Point3d):
private void initMesh()
{
pBuffer = Buffers.newDirectFloatBuffer(360600 * 4);
for(float x = -6.0f; x < 6.0f; x += 0.02f)
{
for(float z = -14.0f; z < -2.0f; z += 0.02f)
{
pBuffer.put(new Point3D(x, 0, z, 1).getBuffer());
}
}
pBuffer.flip();
}
runJava function (the sin wave pattern is a little bit simpler):
gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vertexBufferObject);
ByteBuffer byteBuffer = gl.glMapBuffer(GL3.GL_ARRAY_BUFFER, GL3.GL_READ_WRITE);
if (byteBuffer == null)
{
throw new RuntimeException("Unable to map buffer");
}
FloatBuffer vertices = byteBuffer.asFloatBuffer();
for(int i = 0; i < 360600; i++)
{
vX = vertices.get(i * 4);
vY = vertices.get(i * 4 + 1);
vZ = vertices.get(i * 4 + 2);
float freq = 1.5f;
float w = (float) Math.sin(vX * freq + animationState);
vertices.put(i * 4, vX);
vertices.put(i * 4 + 1, w);
vertices.put(i * 4 + 2, vZ);
}
gl.glUnmapBuffer(GL3.GL_ARRAY_BUFFER);
gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
I need to write my own cu file but I have no idea how the kernel should looks like in this case.