I've been trying for weeks to get AABB collision set up on my DX11 project.
So far, I have a 'condition' set up in place, so that when both cubes collide the 'light' cube will show within the scene. At this moment, the cubes pass through each other, which causes the light to show, but I can't figure out how to actually stop them from passing through each other. When cube1 hits cube2, they'll simply collide and won't be able to pass through each other.
This manages the user input
//Manage the users input via keyboard
class Vector3 {
public:
float x;
float y;
float z;
};
class UserInput
{
public:
float xPos;
float yPos;
float zPos;
Vector3 vecMin;
Vector3 vecMax;
float rotationX;
float rotationY;
float rotationZ;
bool isMoving;
bool isMovingRight;
bool isMovingLeft;
bool isMovingUp;
bool isMovingDown;
bool isMovingCloser;
bool isMovingFurther;
bool isRotatingX;
bool isRotatingY;
bool isRotatingZ;
UserInput()
{
rotationX = 0.0f;
rotationY = 0.0f;
rotationZ = 0.0f;
isMovingRight = false;
isMovingLeft = false;
isMovingUp = false;
isMovingDown = false;
isMovingCloser = false;
isMovingFurther = false;
isRotatingX = false;
isRotatingY = false;
isRotatingZ = false;
}
void UpdatePos()
{
//-1 and +1 from the origin of the cube (centre)
vecMin.x = xPos - 1.0f;
vecMax.x = xPos + 1.0f;
vecMin.y = yPos - 1.0f;
vecMax.y = yPos + 1.0f;
vecMin.z = zPos - 1.0f;
vecMax.z = zPos + 1.0f;
}
};
AABB Collision Function
bool AABBtoAABB(const UserInput& box1, const UserInput& box2)
{
return!(box1.vecMin.x > box2.vecMax.x ||
box1.vecMax.x < box2.vecMin.x ||
box1.vecMax.y < box2.vecMin.y ||
box1.vecMin.y > box2.vecMax.y ||
box1.vecMin.z > box2.vecMax.z ||
box1.vecMax.z < box2.vecMin.z);
}
Update Function
//Update each Frame
void Update()
{
AABBtoAABB(input[0], input[1]);
input[0].UpdatePos();
input[1].UpdatePos();
}