This is called an AABB (Axis Aligned Bounding Box). The collision checks for these are pretty fast and simple. Basically you just check their relative positions and see if all three axes overlap:
public static boolean checkCollision(ObjectBox a, ObjectBox b){
{
//check the X axis
if(Math.abs(a.getX() - b.getX()) < a.getSizeX() + b.getSizeX())
{
//check the Y axis
if(Math.abs(a.getY() - b.getY()) < a.getSizeY() + b.getSizeY())
{
//check the Z axis
if(Math.abs(a.getZ() - b.getZ()) < a.getSizeZ() + b.getSizeZ())
{
return true;
}
}
}
return false;
}
Only if all three axes overlap there is a collision. For example, if the cubes were overlapping on the X and Z axes and not the Y, it means that the cubes are above or below each other and not colliding. You can optimize the code above slightly, if there's an axis you're more likely to be colliding on, put that check first so you don't need to check the others.
Keep in mind, the above code assumes that the position is the center of the cube and the size is getting the half extents of the cube. If your getSize_
functions are returning the full dimension, you'll need to half them for the above to work properly.