Jump to content

  • Log In with Google      Sign In   
  • Create Account

sublixt

Member Since 05 Sep 2011
Offline Last Active Oct 04 2012 06:28 PM

Topics I've Started

Use of Index Buffer Objects with models

22 May 2012 - 08:13 PM

I was wondering what is the advantage of using a Vertex Buffer Object with Index Buffer Object in OpenGL in respect to rendering models. From the way I've done it, more memory is being used because with the .obj file format has vertices, vertex normals, and vertex textures all split up then brought togethor in faces. The way I do VBO and IBO I use the glVertexAttribPointer function and define offsets for the vertex, vertex normal, and vertex texture which is not the way that the .obj file seperates its data. This, for me, makes the VBO IBO pair less efficient that just using a VBO. Is this the only way to do it or is there another way to use an IBO to make it act more in the way an obj file works?
P.S. sorry if my wording is bad I'm still learning OpenGL and I don't know the terminology very well.

AABB sweep collision detection problem

29 March 2012 - 12:45 PM

I am having trouble trying to figure out aabb collision detection. I am trying converting the code from this tutorial (http://www.gamasutra...ames.php?page=3) to java/groovy but it doesnt work. I have checked through the code several times and I could not see any logic errors caused by translation. I was wondering if anyone could point out or suggest what might be wrong with it.

the main collision class with the problem that I am having.
//this class is made in groovy to take advantage of overloading constructors
public class Collision {
public static boolean collide(AABB first, AABB other, Float u0, Float u1){
  //AABB class contains 3 vectors
  //location - the x, y, z location
  //extents - the extents of the bounding box
  //sweep - the distance traveled that frame
  Vector va = new Vector(first.sweep);
  Vector vb = new Vector(other.sweep);

  Vector v = vb - va;
  Vector v0 = new Vector(0.0f, 0.0f, 0.0f);
  Vector v1 = new Vector(1.0f, 1.0f, 1.0f);

  if(overlap(first, other)){
   u0 = 0.0f;
   u1 = 0.0f;
   return true;
  }


  for(int i = 0; i < 3; i++){
   if(max(i, first) < min(i, other) && v[i] < 0)
	v0[i] = (float)((max(i, first) - min(i, other) / v[i]));
   else if(max(i, other) < min(i, first) && v[i] > 0)
	v0[i] = (float)((min(i, first) - max(i, other)) / v[i]);
  
   if(max(i, other) > min(i, first) && v[i] < 0)
	v1[i] = (float)((min(i, first) - max(i, other)) / v[i]);
   else if(max(i, first) < min(i, other) && v[i] > 0)
	v1[i] = (float)((max(i, first) - min(i, other)) / v[i]);
  }

  u0 = Math.max(v0.x, Math.max(v0.y, v0.z));
  u1 = Math.min(v1.x, Math.min(v1.y, v1.z));
  return u0 <= u1;
}

private static boolean overlap(AABB first, AABB other) {
	 Vector T = other.location - first.location;

	 return Math.abs(T.x) <= (first.location.x + other.location.x) &&
   Math.abs(T.y) <= (first.location.y + other.location.y) &&
   Math.abs(T.z) <= (first.location.z + other.location.z);
}

private static float max(int i, AABB bla){
  bla.location[i] + bla.bounds[i];
}

private static float min(int i, AABB bla){
  bla.location[i];
}
}

the class that handels the vectors
it is a wraper class for vector3f letting me overload operators
class Vector extends Vector3f {
public Vector(float f, float g, float h) {
  super(f, g, h);
}

public Vector(Vector3f a){
  super(a);
}

public Vector plus(Vector other){
  return new Vector((float) (x + other.x), (float) (y + other.y), (float) (z + other.z));
}

public Vector minus(Vector other){
  return new Vector((float) (x - other.x), (float) (y - other.y), (float) (z - other.z));
}

public Float getAt(Integer i){
  if(i > 2 || i < 0)
   throw new IndexOutOfBoundsException("Vector index out of bounds");
  
  switch(i){
   case 0: return x;
   case 1: return y;
   case 2: return z;
  }
}

public void putAt(Integer i, Float a){
  if(i > 2 || i < 0)
   throw new IndexOutOfBoundsException("Vector index out of bounds");
  
  switch(i){
   case 0: x = a; return;
   case 1: y = a; return;
   case 2: z = a; return;
  }
}

public static Vector downcast(Vector3f down){
  return new Vector(down.x, down.y, down.z);
}
}

PARTNERS