OBJ models collision detection issue

Ive tried and tried and tried to get the collision box collision working here, but the y axis always seems to be inverted :S

heres my code, would be grateful if you could look throught it and find the issue

Collision Class:


public static boolean CubeCube(boundingBox b1,boundingBox b2){					
	   if (b1.x > b2.x+b2.w) return false;
	   if (b1.x+b1.w < b2.x) return false;
	   if (b1.y > b2.y+b2.h) return false;
	   if (b1.y+b1.h < b2.y) return false;
	   if (b1.z > b2.z+b2.d) return false;
	   if (b1.z+b1.d < b2.z) return false;
	   return true;
	}

Bounding box generation for obj model:


int i=0;
		for (Vector3f o: vertices) {
		    if(vertices.get(i).x < lowx){
		    	lowx = vertices.get(i).x;
		    }
		    if(vertices.get(i).y < lowy){
		    	lowy = vertices.get(i).y;
		    }
		    if(vertices.get(i).z < lowz){
		    	lowz = vertices.get(i).z;
		    }
		    if(vertices.get(i).x > highx){
		    	highx = vertices.get(i).x;
		    }
		    if(vertices.get(i).y > highy){
		    	highy = vertices.get(i).y;
		    }
		    if(vertices.get(i).z > highz){
		    	highz = vertices.get(i).z;
		    }
		    i++;
		}
		this.b = new boundingBox(lowx,lowy,lowz,highx-lowx,highy-lowy,highz-lowz);

Collision call:

if(collision.CubeCube(new boundingBox(position.x,position.y,position.z,0,0,0),main.m.b))
        	main.m.color = new Vector3f(1.0f,0.0f,0.0f);
        else 
        	main.m.color = new Vector3f(1.0f,1.0f,1.0f);

Bounding box class:


public class boundingBox {
	float x,y,z;
	float w,h,d;
	float min_x,min_y,min_z;
	float max_x,max_y,max_z;
	Vector3f center;
	float r[];
	public boundingBox(float x,float y,float z,float w,float h, float d){
		this.x = x;
		this.y = y;
		this.z = z;
		this.w = w;
		this.h = h;
		this.d = d;
		this.min_x=x;
		this.min_y=y;
		this.min_z=z;
		this.max_x=x+w;
		this.max_y=y+h;
		this.max_z=z+d;
		this.center = new Vector3f((float)(x+(w*0.5)),(float)(y+(h*0.5)),(float)(z+(d*0.5)));
		this.r = new float[3];
		r[0] = (float) (w * 0.5);
		r[1] = (float) (h * 0.5);
		r[2] = (float) (d * 0.5);
	}
}

Thanks for taking the time to look through i am always grateful to any responses or improvements people give me :slight_smile:

If the y-axis always seems reversed, then maybe you forgot that the (x,y)-plane on a computer screen starts with (0, 0) in the top left corner? and has positive y going downwards? :slight_smile:

Also in your box generation code, there really isn’t any need for the i variable.

You could just write the code as:


for (Vector3f vertice: vertices) {
    if(vertice.x < lowx){
        lowx = vertice.x;
    }

    if(vertice.y < lowy){
        lowy = vertice.y;
    }

    if(vertice.z < lowz){
        lowz = vertice.z;
    }

    if(vertice.x > highx){
        highx = vertice.x;
    }

    if(vertice.y > highy){
        highy = vertice.y;
    }
    if(vertice.z > highz){
        highz = vertice.z;
    }
}
this.b = new boundingBox(lowx,lowy,lowz,highx-lowx,highy-lowy,highz-lowz);

Thanks for your reply but i dont quite understand what your suggesting about reversing the y-axis, hwo would i change my code to work with that?