glBufferSubData

for (int i=0; i<pack.triangles.length; i++){
	final float intersection = MouseManager.intersectRayTriangle(camera.getPosition(), mouseray.getDirection(), pack.triangles[i]);
	if(intersection != -1) {
		System.out.println("Triangle: " + i);
		ModelLoader.storeModel(pack.model);
		final float[] buffer = new float[]{5};
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, pack.model.getVbos()[0]);
		ModelLoader.modBuffer(pack.model.getVbos()[0], i*3*4+4, buffer); //triangle * vertices * byte size + byte skip to get to Y
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
		ModelLoader.finalizeModel();
		break;
	}
}

I am having a problem with this code. It reads, for each triangle, if there is collision, bind the model and its position vbo and modify the position of the triangle so its 5 higher.

I understand that there is a 4 byte offset. I am using GL_FLOAT. This will not work unless I manually count the bytes. I must be doing something wrong.

Aren’t you missing that your vertex has two components (x and y)?

i34*2+4 //triangle * vertices * byte size(of vertex, two components) + byte skip to get to Y

i342+4 > vertex count * 4 when i > ~200. The vertex count is 7720 (i don’t remember right off) or so, and triangles are 400. Even when i strip 2. I get the error i34 even.

I have no idea what the actual problem is as you haven’t really said there is a problem.

Anyway, personally, i think you are going about this completely wrong. When I did my picking code I did this.

  • Used the index array and took 3 at a time to form each triangles
  • Did an intersection check on this triangle and returned the distance to the camera
  • The nearest object is the object picked

You can optimise your data set by using an OctTree / QuadTree to intersect the box first to narrow down which triangles to check (as its cheaper to check AABB than it is to check triangles).

No idea where collision comes in to the ray triangle thing, you should explain things a lot more clearly

That is exactly what I am doing, minus the area check. That isn’t my worry right now.
My problem, and goal thereof for this, is to get the triangle’s vertices inside my VBO and edit them, but nothing I do seems to work.

I can edit the model information perfectly calculating from zero, but I am missing something with the triangles I guess.

I think you have a multi part question then

Part 1 : Putting all the possible triangles in to the required buffers.

Your vertex buffer only contains points, which in your case are all vertices of the triangles you want to draw. The way you make them in to triangles is to use the index buffer and to tell the draw elements method that you want to draw triangles. The draw elements method then takes the index buffer, 3 elements at a time and indexes them back in to the vertex buffer.


renderer.glBindBuffer(renderer.GL_ARRAY_BUFFER, sizeBufferId);
        renderer.glBufferData(renderer.GL_ARRAY_BUFFER, sizeData, drawFrequency);

What are you talking about?
My vbo is a list of vertices. There are 3 floats per vertex, as it is 3D. Each float is 4 bytes. I know all this, but what problem is when I bind the vbo, I am getting errors setting the correct vertex to a specified value. I can’t find a formula I suppose.

I generate a 20 by 20 point field in the manor of
int pointer = 0;
for (x=0; x<20; i++) {
for (y=0; y<20; i++) {
vertices[pointer++] = generatedvertex;
}
}

It is in the order of a row of points. My indices are then calculated separately and used to indicate triangles. So I store 3 values inside of a triangle class. One for each believed index of the triangles points in the array. But when it comes to byte array calculations, its idk.

Resolved. I multiplied the ia component, which is the index of the vertex array’s first index, by 4 and it was all good. Then translated by 4. It works now, didn’t before. Oh well.