LWJGL openGL - set new position of vertex array

Hello,

I got a massive problem to understand how I can set a new position of my vertex array.

If this is my quad

float[] vertices =
			{      
    -1.0f, -1.0f, 1.0f,
		    1.0f, -1.0f, 1.0f,
		    -1.0f, 1.0f, 1.0f,
		    1.0f, 1.0f, 1.0f,

		    -1.0f, -1.0f, -1.0f,
		    1.0f, -1.0f, -1.0f,
		    -1.0f, 1.0f, -1.0f,
		    1.0f, 1.0f, -1.0f,

		    -1.0f, 1.0f, 1.0f,
		    1.0f, 1.0f, 1.0f,
		    -1.0f, 1.0f, -1.0f,
		    1.0f, 1.0f, -1.0f,

		    -1.0f, -1.0f, 1.0f,
		    1.0f, -1.0f, 1.0f,
		    -1.0f, -1.0f, -1.0f,
		    1.0f, -1.0f, -1.0f,

		    -1.0f, -1.0f, 1.0f,
		    -1.0f, 1.0f, 1.0f,
		    -1.0f, -1.0f, -1.0f,
		    -1.0f, 1.0f, -1.0f,

		    1.0f, -1.0f, 1.0f,
		    1.0f, 1.0f, 1.0f,
		    1.0f, -1.0f, -1.0f,
		    1.0f, 1.0f, -1.0f};

And I want that quad to move, do I have to iterate through each vertex and change it? glTranslatef() is a possibilty, BUT the vertices aren’t changed, so I cannot make a collision detection, right? It will only be moved on the screen as I render it, but the numbers would be the same. So how can I do this effiently? I’am really suprised, because every single tutorial (written or youtube) do not cover this. They only translate them around, and that should be all?? BTW, has anyone a good collision detection tutorial for me? I really appreciate any help :-*

How are you using the vertices inside the Vertex Array for collision? usually you should use a class you made called “box.java” or so for collision detection which has the position and data like width height depth? so actually you should use glTranslatef(); with the coordinates you get from the object of the class “box.java” to draw it at the right position and collision detection should be calculated with the data inside the Object no?

Hi,

I currently have these fixed vertices and add a value on the x and z axis to “move” them. This is done by a loop. So I’m iterating over all vertices and add a value. Because I think (I might be very very wrong), that “only” translating them, won’t do anything on the vertices. The data is the same. So how could I possibly check for collision, if i check always the same information. I have to change them. But how? With stupid for loops?! Not really :smiley:

You do not use your render data for collision detection. You have two data sets one for rendering and one for collision. In most cases the data you need for collision is much simpler.

i.e. let’s say that you use 1000 triangles to render a sphere, but to calculate the collision you just need the center position and the radius.

In more complex games you have a simplified collision mesh. Say you have a nice detailed 3D character with some thousand triangles, you collision mesh would just be a collection of some basic shapes. The head would be a sphere the arms and legs a some boxes and so on.

You can even use different collision meshes for different tasks. For example ego-shooters use a simple box to check the collision of a player with the world and a more detailed one (aka hit-boxes) to detect hits.

Hey that really brought light into it. Thanks a lot. So I render my stuff and moving them around with translations and so on. And If I want to check for collision, I use the ordinary xyz with height depth values, which I change simultaneously!? That makes sense. By the way, using the SAT for collision detection is the right ways, or?

Another question. As I said, these vertices are fixed. I have a class Cube(x, y, z, width, height, depth), how would you bring them in the array?

write a factory method which generates a mesh from a Cube?


class Mesh{
  static Mesh from(Cube c);
  static Mesh from(Sphere s, float tesselation);
  ...
}