Advertisement Jump to content
Sign in to follow this  
Tweezy

Help with Impulse resolution and position correction

This topic is 1777 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

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;
	}
}
Edited by Doublefris

Share this post


Link to post
Share on other sites
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 Edited by Tweezy

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!