Advertisement

Help with Impulse resolution and position correction

Started by March 05, 2014 02:26 PM
2 comments, last by Doublefris 10 years, 11 months ago
Fixed my issue smile.png

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;
	}
}
Advertisement
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

I noticed I made some errors when posting that code, tell me if you got everything to work :p, for the record I didn't test anything though I did just now make some changes to it.

This topic is closed to new replies.

Advertisement