Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Computing the normals of AABB collision  (Read 2592 times)

0 Members and 2 Guests are viewing this topic.

Tweezy

  • Newbie
  • *
  • Posts: 43
    • View Profile
Computing the normals of AABB collision
« on: February 19, 2014, 10:55:29 pm »
Hi. I'm using a simple min and max AABB collision method for testing out whenever two AABB objects have intersected, this works fine.

The next thing I need to do is position correction, so basically when an object collides it does position correction and pushes the object out of the collided one and positions to correctly.

To do this the way I want to do it, I need normals. I'm reading over some research for computing the normals, but it doesn't make much sense. Here is what I think I need to do:


1. I need to gather information about different points on my collision objects:

Code: [Select]
float a, b, c, otherA, otherB, otherC;

a = min.x - max.y;
b = min.x+max.x - max.y+min.x;
c = ((min.x - max.x)*min.y+(max.y-min.y)*min.x);

otherA = other.min.y - other.max.y;
otherB = other.max.x - other.min.x;
otherC = ((other.min.x - other.max.x)*other.min.y+(other.max.y-other.min.y)*other.min.x);

The next thing I need to do is normalise:

Code: [Select]
        float normalise = sqrt(a * a) + (b * b);
        float normaliseOther = sqrt(otherA * otherA) + (otherB * otherB);

Now that I have normalised, I can get the normal...

Code: [Select]

vector2D normal(a/normalise,b/normalise);
vector2D normalOther(otherA/normaliseOther,otherB/normaliseOther);


Inside my game.cpp I have a small detectCollision function...

Code: [Select]

void game::detectCollision()
{
for (int i=0; i<sObj.sObject.size(); i++) // Integer iteration
{
if(p.AABB(sObj.sObject[i])==true) // going over each object in my sObj (staticObject) vector
{
p.postionCorrection(sObj.sObject[i]); // calling the positionCorrection function against my sObj vector
}
if(p.AABB(sObj.sObject[i])==false)
{
p.getIEulerY(); // calling my improved euler
}
}
}

The thing I want to do now is test whenever each of my static objects and player object has normals, but I really have no clue on how to do this.

Been going at this for a week now :/
« Last Edit: February 19, 2014, 11:30:34 pm by Tweezy »

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Re: Computing the normals of AABB collision
« Reply #1 on: February 20, 2014, 12:42:10 am »
Looks like you still lack basic concepts of physics. Mind if I ask you why don't you use Box2D, for example?

Tweezy

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Computing the normals of AABB collision
« Reply #2 on: February 20, 2014, 12:48:17 am »
Looks like you still lack basic concepts of physics. Mind if I ask you why don't you use Box2D, for example?

We've all got to learn somewhere. I feel as if using Box2D would remove that massive learning curve. I decided to design my own game engine so that I would learn! Learning I am :) I've done collision detection, tilemaps, integration, texture management. Such a good vibe getting all of those working, I want to continue that on :) As of now i've hit a little snag and I feel like my knowledge in normals isn't up to scratch, so I am here asking for help :) Maybe you know some good web resources where I can read up?