
Help with Impulse resolution and position correction
Not totally sure how you get your normals, trry something like this:
void Bound3vsBound3(vec2& correction, bound3 a, bound3 b)
{
// simple lookup table for the normals
vec2 normals[4] =
{
vec2(1,0), vec2(0,1), vec2(-1,0), vec2(0,-1);
}
float overlapx = min(b.max.x, a.max.x) - max(b.min.x, a.min.x);
float overlapy = min(b.max.y, a.max.y) - max(b.min.y, a.min.y);
if(overlapx > overlapy) // least penetration is along y
{
correction = a.min.y < b.min.y ? normals[1] * overlapy :normals[3] * overlapy;
}
else // least penetration is along x
{
correction = a.min.x < b.min.x ? normals[0] * overlapx : normals[2] * overlapx;
}
}
Ahh okay. So the vector lookup table is for each normal coming off each side, understood. The overlap in x is taking the min of the two points, taken away from the max of the other. Same for the overlap in y.
Then, the two if statements are comparing the axis of least penitration. Gotcha. Once thing I am a little confused about, what are the "?" and ":" meant to represent?
Update
Never mind, they are ternary operators. Cheers
Then, the two if statements are comparing the axis of least penitration. Gotcha. Once thing I am a little confused about, what are the "?" and ":" meant to represent?
Update
Never mind, they are ternary operators. Cheers
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement