mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-22 18:43:20 +02:00
Merge pull request #7746 from AndrewMeadows/supress-spurious-logs
reduce warnings about truncated kinematic timesteps
This commit is contained in:
commit
8c7ef31636
2 changed files with 28 additions and 16 deletions
|
@ -884,7 +884,24 @@ void EntityItem::simulate(const quint64& now) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityItem::stepKinematicMotion(float timeElapsed) {
|
bool EntityItem::stepKinematicMotion(float timeElapsed) {
|
||||||
|
// get all the data
|
||||||
|
Transform transform;
|
||||||
|
glm::vec3 linearVelocity;
|
||||||
|
glm::vec3 angularVelocity;
|
||||||
|
getLocalTransformAndVelocities(transform, linearVelocity, angularVelocity);
|
||||||
|
|
||||||
|
// find out if it is moving
|
||||||
|
bool isSpinning = (glm::length2(angularVelocity) > 0.0f);
|
||||||
|
float linearSpeedSquared = glm::length2(linearVelocity);
|
||||||
|
bool isTranslating = linearSpeedSquared > 0.0f;
|
||||||
|
bool moving = isTranslating || isSpinning;
|
||||||
|
if (!moving) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (timeElapsed <= 0.0f) {
|
if (timeElapsed <= 0.0f) {
|
||||||
|
// someone gave us a useless time value so bail early
|
||||||
|
// but return 'true' because it is moving
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -894,13 +911,7 @@ bool EntityItem::stepKinematicMotion(float timeElapsed) {
|
||||||
}
|
}
|
||||||
timeElapsed = glm::min(timeElapsed, MAX_TIME_ELAPSED);
|
timeElapsed = glm::min(timeElapsed, MAX_TIME_ELAPSED);
|
||||||
|
|
||||||
Transform transform;
|
if (isSpinning) {
|
||||||
glm::vec3 linearVelocity;
|
|
||||||
glm::vec3 angularVelocity;
|
|
||||||
getLocalTransformAndVelocities(transform, linearVelocity, angularVelocity);
|
|
||||||
|
|
||||||
bool moving = false;
|
|
||||||
if (glm::length2(angularVelocity) > 0.0f) {
|
|
||||||
// angular damping
|
// angular damping
|
||||||
if (_angularDamping > 0.0f) {
|
if (_angularDamping > 0.0f) {
|
||||||
angularVelocity *= powf(1.0f - _angularDamping, timeElapsed);
|
angularVelocity *= powf(1.0f - _angularDamping, timeElapsed);
|
||||||
|
@ -922,14 +933,12 @@ bool EntityItem::stepKinematicMotion(float timeElapsed) {
|
||||||
}
|
}
|
||||||
transform.setRotation(rotation);
|
transform.setRotation(rotation);
|
||||||
}
|
}
|
||||||
moving = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 position = transform.getTranslation();
|
glm::vec3 position = transform.getTranslation();
|
||||||
float linearSpeedSquared = glm::length2(linearVelocity);
|
|
||||||
const float MIN_KINEMATIC_LINEAR_SPEED_SQUARED =
|
const float MIN_KINEMATIC_LINEAR_SPEED_SQUARED =
|
||||||
KINEMATIC_LINEAR_SPEED_THRESHOLD * KINEMATIC_LINEAR_SPEED_THRESHOLD;
|
KINEMATIC_LINEAR_SPEED_THRESHOLD * KINEMATIC_LINEAR_SPEED_THRESHOLD;
|
||||||
if (linearSpeedSquared > 0.0f) {
|
if (isTranslating) {
|
||||||
glm::vec3 deltaVelocity = Vectors::ZERO;
|
glm::vec3 deltaVelocity = Vectors::ZERO;
|
||||||
|
|
||||||
// linear damping
|
// linear damping
|
||||||
|
@ -971,14 +980,12 @@ bool EntityItem::stepKinematicMotion(float timeElapsed) {
|
||||||
linearVelocity += deltaVelocity;
|
linearVelocity += deltaVelocity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
moving = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (moving) {
|
transform.setTranslation(position);
|
||||||
transform.setTranslation(position);
|
setLocalTransformAndVelocities(transform, linearVelocity, angularVelocity);
|
||||||
setLocalTransformAndVelocities(transform, linearVelocity, angularVelocity);
|
|
||||||
}
|
return true;
|
||||||
return moving;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityItem::isMoving() const {
|
bool EntityItem::isMoving() const {
|
||||||
|
|
|
@ -74,13 +74,18 @@ void EntitySimulation::addEntityInternal(EntityItemPointer entity) {
|
||||||
if (entity->isMovingRelativeToParent() && !entity->getPhysicsInfo()) {
|
if (entity->isMovingRelativeToParent() && !entity->getPhysicsInfo()) {
|
||||||
QMutexLocker lock(&_mutex);
|
QMutexLocker lock(&_mutex);
|
||||||
_simpleKinematicEntities.insert(entity);
|
_simpleKinematicEntities.insert(entity);
|
||||||
|
entity->setLastSimulated(usecTimestampNow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntitySimulation::changeEntityInternal(EntityItemPointer entity) {
|
void EntitySimulation::changeEntityInternal(EntityItemPointer entity) {
|
||||||
QMutexLocker lock(&_mutex);
|
QMutexLocker lock(&_mutex);
|
||||||
if (entity->isMovingRelativeToParent() && !entity->getPhysicsInfo()) {
|
if (entity->isMovingRelativeToParent() && !entity->getPhysicsInfo()) {
|
||||||
|
int numKinematicEntities = _simpleKinematicEntities.size();
|
||||||
_simpleKinematicEntities.insert(entity);
|
_simpleKinematicEntities.insert(entity);
|
||||||
|
if (numKinematicEntities != _simpleKinematicEntities.size()) {
|
||||||
|
entity->setLastSimulated(usecTimestampNow());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
_simpleKinematicEntities.remove(entity);
|
_simpleKinematicEntities.remove(entity);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue