mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 13:58:51 +02:00
fix sphere-vs-axis-aligned-cube logic
This commit is contained in:
parent
06784aa960
commit
8d6fa8f904
1 changed files with 3 additions and 2 deletions
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include "GeometryUtil.h"
|
#include "GeometryUtil.h"
|
||||||
#include "ShapeCollider.h"
|
#include "ShapeCollider.h"
|
||||||
|
#include "StreamUtils.h"
|
||||||
|
|
||||||
// NOTE:
|
// NOTE:
|
||||||
//
|
//
|
||||||
|
@ -601,9 +602,9 @@ bool sphereAACube(const glm::vec3& sphereCenter, float sphereRadius, const glm::
|
||||||
// compute the nearest point on cube
|
// compute the nearest point on cube
|
||||||
float maxBA = glm::max(glm::max(fabs(BA.x), fabs(BA.y)), fabs(BA.z));
|
float maxBA = glm::max(glm::max(fabs(BA.x), fabs(BA.y)), fabs(BA.z));
|
||||||
glm::vec3 surfaceB = cubeCenter - (0.5f * cubeSide / maxBA) * BA;
|
glm::vec3 surfaceB = cubeCenter - (0.5f * cubeSide / maxBA) * BA;
|
||||||
// collision happens when "vector to surfaceB from surfaceA" dots with BA to produce a positive value
|
// collision happens when "vector to surfaceB from surfaceA" dots with BA to produce a negative value
|
||||||
glm::vec3 surfaceBA = surfaceB - surfaceA;
|
glm::vec3 surfaceBA = surfaceB - surfaceA;
|
||||||
if (glm::dot(surfaceBA, BA) > 0.f) {
|
if (glm::dot(surfaceBA, BA) < 0.f) {
|
||||||
CollisionInfo* collision = collisions.getNewCollision();
|
CollisionInfo* collision = collisions.getNewCollision();
|
||||||
if (collision) {
|
if (collision) {
|
||||||
collision->_penetration = surfaceBA;
|
collision->_penetration = surfaceBA;
|
||||||
|
|
Loading…
Reference in a new issue