mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:50:00 +02:00
fix a NaN in ViewFrustum and BuckyBalls
This commit is contained in:
parent
161b8ad50b
commit
b78e723253
2 changed files with 21 additions and 16 deletions
|
@ -106,21 +106,26 @@ void BuckyBalls::simulate(float deltaTime, const HandData* handData) {
|
||||||
for (int j = 0; j < NUM_BBALLS; j++) {
|
for (int j = 0; j < NUM_BBALLS; j++) {
|
||||||
if (i != j) {
|
if (i != j) {
|
||||||
glm::vec3 diff = _bballPosition[i] - _bballPosition[j];
|
glm::vec3 diff = _bballPosition[i] - _bballPosition[j];
|
||||||
float penetration = glm::length(diff) - (_bballRadius[i] + _bballRadius[j]);
|
|
||||||
if (penetration < 0.f) {
|
float diffLength = glm::length(diff);
|
||||||
// Colliding - move away and transfer velocity
|
float penetration = diffLength - (_bballRadius[i] + _bballRadius[j]);
|
||||||
_bballPosition[i] -= glm::normalize(diff) * penetration * COLLISION_BLEND_RATE;
|
|
||||||
if (glm::dot(_bballVelocity[i], diff) < 0.f) {
|
if (diffLength != 0) {
|
||||||
_bballVelocity[i] = _bballVelocity[i] * (1.f - COLLISION_BLEND_RATE) +
|
if (penetration < 0.f) {
|
||||||
glm::reflect(_bballVelocity[i], glm::normalize(diff)) * COLLISION_BLEND_RATE;
|
// Colliding - move away and transfer velocity
|
||||||
|
_bballPosition[i] -= glm::normalize(diff) * penetration * COLLISION_BLEND_RATE;
|
||||||
|
if (glm::dot(_bballVelocity[i], diff) < 0.f) {
|
||||||
|
_bballVelocity[i] = _bballVelocity[i] * (1.f - COLLISION_BLEND_RATE) +
|
||||||
|
glm::reflect(_bballVelocity[i], glm::normalize(diff)) * COLLISION_BLEND_RATE;
|
||||||
|
}
|
||||||
|
} else if ((penetration > EPSILON) && (penetration < BBALLS_ATTRACTION_DISTANCE)) {
|
||||||
|
// If they get close to each other, bring them together with magnetic force
|
||||||
|
_bballPosition[i] -= glm::normalize(diff) * penetration * ATTRACTION_BLEND_RATE;
|
||||||
|
|
||||||
|
// Also make their velocities more similar
|
||||||
|
_bballVelocity[i] = _bballVelocity[i] * (1.f - ATTRACTION_VELOCITY_BLEND_RATE) + _bballVelocity[j] * ATTRACTION_VELOCITY_BLEND_RATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((penetration > EPSILON) && (penetration < BBALLS_ATTRACTION_DISTANCE)) {
|
|
||||||
// If they get close to each other, bring them together with magnetic force
|
|
||||||
_bballPosition[i] -= glm::normalize(diff) * penetration * ATTRACTION_BLEND_RATE;
|
|
||||||
// Also make their velocities more similar
|
|
||||||
_bballVelocity[i] = _bballVelocity[i] * (1.f - ATTRACTION_VELOCITY_BLEND_RATE) + _bballVelocity[j] * ATTRACTION_VELOCITY_BLEND_RATE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,9 @@ using namespace std;
|
||||||
ViewFrustum::ViewFrustum() :
|
ViewFrustum::ViewFrustum() :
|
||||||
_position(0,0,0),
|
_position(0,0,0),
|
||||||
_orientation(),
|
_orientation(),
|
||||||
_direction(0,0,0),
|
_direction(IDENTITY_FRONT),
|
||||||
_up(0,0,0),
|
_up(IDENTITY_UP),
|
||||||
_right(0,0,0),
|
_right(IDENTITY_RIGHT),
|
||||||
_fieldOfView(0.0),
|
_fieldOfView(0.0),
|
||||||
_aspectRatio(1.0f),
|
_aspectRatio(1.0f),
|
||||||
_nearClip(0.1f),
|
_nearClip(0.1f),
|
||||||
|
|
Loading…
Reference in a new issue