mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-13 21:27:21 +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++) {
|
||||
if (i != j) {
|
||||
glm::vec3 diff = _bballPosition[i] - _bballPosition[j];
|
||||
float penetration = glm::length(diff) - (_bballRadius[i] + _bballRadius[j]);
|
||||
if (penetration < 0.f) {
|
||||
// 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;
|
||||
|
||||
float diffLength = glm::length(diff);
|
||||
float penetration = diffLength - (_bballRadius[i] + _bballRadius[j]);
|
||||
|
||||
if (diffLength != 0) {
|
||||
if (penetration < 0.f) {
|
||||
// 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() :
|
||||
_position(0,0,0),
|
||||
_orientation(),
|
||||
_direction(0,0,0),
|
||||
_up(0,0,0),
|
||||
_right(0,0,0),
|
||||
_direction(IDENTITY_FRONT),
|
||||
_up(IDENTITY_UP),
|
||||
_right(IDENTITY_RIGHT),
|
||||
_fieldOfView(0.0),
|
||||
_aspectRatio(1.0f),
|
||||
_nearClip(0.1f),
|
||||
|
|
Loading…
Reference in a new issue