mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 15:59:49 +02:00
Adding comments and minor cleanup after tracking down some NaN's that were showing up in collision sound triggers.
This commit is contained in:
parent
5e77f5643d
commit
70c675e9be
2 changed files with 14 additions and 11 deletions
|
@ -592,6 +592,7 @@ bool findSpherePenetrationOp(OctreeElement* element, void* extraData) {
|
||||||
if (element->hasContent()) {
|
if (element->hasContent()) {
|
||||||
glm::vec3 elementPenetration;
|
glm::vec3 elementPenetration;
|
||||||
if (element->findSpherePenetration(args->center, args->radius, elementPenetration, &args->penetratedObject)) {
|
if (element->findSpherePenetration(args->center, args->radius, elementPenetration, &args->penetratedObject)) {
|
||||||
|
// NOTE: it is possible for this penetration accumulation algorithm to produce a final penetration vector with zero length.
|
||||||
args->penetration = addPenetrations(args->penetration, elementPenetration * (float)(TREE_SCALE));
|
args->penetration = addPenetrations(args->penetration, elementPenetration * (float)(TREE_SCALE));
|
||||||
args->found = true;
|
args->found = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,8 +79,8 @@ void ParticleCollisionSystem::updateCollisionWithVoxels(Particle* particle) {
|
||||||
// let the particles run their collision scripts if they have them
|
// let the particles run their collision scripts if they have them
|
||||||
particle->collisionWithVoxel(voxelDetails);
|
particle->collisionWithVoxel(voxelDetails);
|
||||||
|
|
||||||
collisionInfo._penetration /= (float)(TREE_SCALE);
|
|
||||||
updateCollisionSound(particle, collisionInfo._penetration, COLLISION_FREQUENCY);
|
updateCollisionSound(particle, collisionInfo._penetration, COLLISION_FREQUENCY);
|
||||||
|
collisionInfo._penetration /= (float)(TREE_SCALE);
|
||||||
applyHardCollision(particle, ELASTICITY, DAMPING, collisionInfo);
|
applyHardCollision(particle, ELASTICITY, DAMPING, collisionInfo);
|
||||||
|
|
||||||
delete voxelDetails; // cleanup returned details
|
delete voxelDetails; // cleanup returned details
|
||||||
|
@ -134,7 +134,6 @@ void ParticleCollisionSystem::updateCollisionWithParticles(Particle* particleA)
|
||||||
|
|
||||||
_packetSender->releaseQueuedMessages();
|
_packetSender->releaseQueuedMessages();
|
||||||
|
|
||||||
penetration /= (float)(TREE_SCALE);
|
|
||||||
updateCollisionSound(particleA, penetration, COLLISION_FREQUENCY);
|
updateCollisionSound(particleA, penetration, COLLISION_FREQUENCY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,8 +183,8 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) {
|
||||||
}
|
}
|
||||||
// HACK END
|
// HACK END
|
||||||
|
|
||||||
collisionInfo._penetration /= (float)(TREE_SCALE);
|
|
||||||
updateCollisionSound(particle, collisionInfo._penetration, COLLISION_FREQUENCY);
|
updateCollisionSound(particle, collisionInfo._penetration, COLLISION_FREQUENCY);
|
||||||
|
collisionInfo._penetration /= (float)(TREE_SCALE);
|
||||||
applyHardCollision(particle, elasticity, damping, collisionInfo);
|
applyHardCollision(particle, elasticity, damping, collisionInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,8 +215,8 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) {
|
||||||
}
|
}
|
||||||
// HACK END
|
// HACK END
|
||||||
|
|
||||||
collisionInfo._penetration /= (float)(TREE_SCALE);
|
|
||||||
updateCollisionSound(particle, collisionInfo._penetration, COLLISION_FREQUENCY);
|
updateCollisionSound(particle, collisionInfo._penetration, COLLISION_FREQUENCY);
|
||||||
|
collisionInfo._penetration /= (float)(TREE_SCALE);
|
||||||
applyHardCollision(particle, ELASTICITY, damping, collisionInfo);
|
applyHardCollision(particle, ELASTICITY, damping, collisionInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,18 +292,21 @@ void ParticleCollisionSystem::updateCollisionSound(Particle* particle, const glm
|
||||||
velocity -= _scale * glm::length(gravity) * GRAVITY_EARTH * deltaTime * glm::normalize(gravity);
|
velocity -= _scale * glm::length(gravity) * GRAVITY_EARTH * deltaTime * glm::normalize(gravity);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
float velocityTowardCollision = glm::dot(velocity, glm::normalize(penetration));
|
float normalSpeed = glm::dot(velocity, glm::normalize(penetration));
|
||||||
float velocityTangentToCollision = glm::length(velocity) - velocityTowardCollision;
|
// NOTE: it is possible for normalSpeed to be NaN at this point
|
||||||
|
// (sometimes the average penetration of a bunch of voxels is a zero length vector which cannot be normalized)
|
||||||
|
// however the check below will fail (NaN comparisons always fail) and everything will be fine.
|
||||||
|
|
||||||
if (velocityTowardCollision > AUDIBLE_COLLISION_THRESHOLD) {
|
if (normalSpeed > AUDIBLE_COLLISION_THRESHOLD) {
|
||||||
// Volume is proportional to collision velocity
|
// Volume is proportional to collision velocity
|
||||||
// Base frequency is modified upward by the angle of the collision
|
// Base frequency is modified upward by the angle of the collision
|
||||||
// Noise is a function of the angle of collision
|
// Noise is a function of the angle of collision
|
||||||
// Duration of the sound is a function of both base frequency and velocity of impact
|
// Duration of the sound is a function of both base frequency and velocity of impact
|
||||||
|
float tangentialSpeed = glm::length(velocity) - normalSpeed;
|
||||||
_audio->startCollisionSound(
|
_audio->startCollisionSound(
|
||||||
std::min(COLLISION_LOUDNESS * velocityTowardCollision, 1.f),
|
std::min(COLLISION_LOUDNESS * normalSpeed, 1.f),
|
||||||
frequency * (1.f + velocityTangentToCollision / velocityTowardCollision),
|
frequency * (1.f + tangentialSpeed / normalSpeed),
|
||||||
std::min(velocityTangentToCollision / velocityTowardCollision * NOISE_SCALING, 1.f),
|
std::min(tangentialSpeed / normalSpeed * NOISE_SCALING, 1.f),
|
||||||
1.f - DURATION_SCALING * powf(frequency, 0.5f) / velocityTowardCollision, false);
|
1.f - DURATION_SCALING * powf(frequency, 0.5f) / normalSpeed, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue