Jump to content
  • Advertisement
Sign in to follow this  
Irlan Robson


This topic is 2102 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

What is the mistake I made on the code below...

	bool TestAABB(Entity& a, Entity& b, glm::vec3& mtd)
		glm::vec3 ra = a.GetR();
		glm::vec3 rb = b.GetR();

		glm::vec3 sa = a.GetScale() * 0.5f;
		glm::vec3 sb = b.GetScale() * 0.5f;

		float mtd_distance = FLT_MAX;
		int mtd_axis = -1;

		for (int i = 0; i < 3; ++i) {

			float distance = abs(ra[i] - rb[i]) - (sa[i] + sb[i]);

			if (distance > 0.0f) { 
				return false;

			if (abs(distance) < mtd_distance) {
				mtd_distance = abs(distance);
				mtd_axis = i;

		if (mtd_axis == -1) {
			return false;

		glm::vec3 n = glm::normalize(ra - rb);
		mtd[mtd_axis] = n[mtd_axis] * mtd_distance;

		return true;

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!