mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 05:23:09 +02:00
fix penetration direction for sphere-vs-AACube
This commit is contained in:
parent
f033990fae
commit
65d3b4dc39
1 changed files with 8 additions and 5 deletions
|
@ -607,12 +607,15 @@ bool sphereAACube(const glm::vec3& sphereCenter, float sphereRadius, const glm::
|
||||||
if (glm::dot(surfaceAB, BA) > 0.f) {
|
if (glm::dot(surfaceAB, BA) > 0.f) {
|
||||||
CollisionInfo* collision = collisions.getNewCollision();
|
CollisionInfo* collision = collisions.getNewCollision();
|
||||||
if (collision) {
|
if (collision) {
|
||||||
glm::vec3 normal(floorf(BA.x/maxBA), floorf(BA.y/maxBA), floorf(BA.z/maxBA));
|
// penetration is parallel to box side direction
|
||||||
std::cout << "adebug normal = " << normal << std::endl; // adebug
|
glm::vec3 direction;
|
||||||
normal = glm::normalize(normal);
|
modff(BA.x/maxBA, &(direction.x));
|
||||||
collision->_penetration = glm::dot(surfaceAB, normal) * normal;
|
modff(BA.y/maxBA, &(direction.y));
|
||||||
|
modff(BA.z/maxBA, &(direction.z));
|
||||||
|
direction = glm::normalize(direction);
|
||||||
|
collision->_penetration = glm::dot(surfaceAB, direction) * direction;
|
||||||
// contactPoint is on surface of A
|
// contactPoint is on surface of A
|
||||||
collision->_contactPoint = sphereCenter - sphereRadius * normal;
|
collision->_contactPoint = sphereCenter - sphereRadius * direction;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue