mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 13:53:38 +02:00
fix angular velocity damping so we don't get bad quats
This commit is contained in:
parent
cbdaf76b88
commit
a3e47aa301
1 changed files with 19 additions and 14 deletions
|
@ -535,21 +535,27 @@ void EntityItem::update(const quint64& updateTime) {
|
||||||
if (hasAngularVelocity()) {
|
if (hasAngularVelocity()) {
|
||||||
glm::quat rotation = getRotation();
|
glm::quat rotation = getRotation();
|
||||||
glm::vec3 angularVelocity = glm::radians(getAngularVelocity());
|
glm::vec3 angularVelocity = glm::radians(getAngularVelocity());
|
||||||
float angle = timeElapsed * glm::length(angularVelocity);
|
float angularSpeed = glm::length(angularVelocity);
|
||||||
glm::quat dQ = glm::angleAxis(angle, glm::normalize(angularVelocity));
|
|
||||||
rotation = dQ * rotation;
|
|
||||||
setRotation(rotation);
|
|
||||||
|
|
||||||
// handle damping for angular velocity
|
if (angularSpeed < EPSILON_VELOCITY_LENGTH) {
|
||||||
if (getAngularDamping() > 0.0f) {
|
setAngularVelocity(NO_ANGULAR_VELOCITY);
|
||||||
glm::vec3 dampingResistance = getAngularVelocity() * getAngularDamping();
|
} else {
|
||||||
if (wantDebug) {
|
float angle = timeElapsed * angularSpeed;
|
||||||
qDebug() << " getDamping():" << getDamping();
|
glm::quat dQ = glm::angleAxis(angle, glm::normalize(angularVelocity));
|
||||||
qDebug() << " dampingResistance:" << dampingResistance;
|
rotation = dQ * rotation;
|
||||||
qDebug() << " dampingResistance * timeElapsed:" << dampingResistance * timeElapsed;
|
setRotation(rotation);
|
||||||
|
|
||||||
|
// handle damping for angular velocity
|
||||||
|
if (getAngularDamping() > 0.0f) {
|
||||||
|
glm::vec3 dampingResistance = getAngularVelocity() * getAngularDamping();
|
||||||
|
glm::vec3 newAngularVelocity = getAngularVelocity() - (dampingResistance * timeElapsed);
|
||||||
|
setAngularVelocity(newAngularVelocity);
|
||||||
|
if (wantDebug) {
|
||||||
|
qDebug() << " getDamping():" << getDamping();
|
||||||
|
qDebug() << " dampingResistance:" << dampingResistance;
|
||||||
|
qDebug() << " newAngularVelocity:" << newAngularVelocity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
glm::vec3 newAngularVelocity = getAngularVelocity() - (dampingResistance * timeElapsed);
|
|
||||||
setAngularVelocity(newAngularVelocity);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,7 +655,6 @@ void EntityItem::copyChangedProperties(const EntityItem& other) {
|
||||||
|
|
||||||
EntityItemProperties EntityItem::getProperties() const {
|
EntityItemProperties EntityItem::getProperties() const {
|
||||||
EntityItemProperties properties;
|
EntityItemProperties properties;
|
||||||
|
|
||||||
properties._id = getID();
|
properties._id = getID();
|
||||||
properties._idSet = true;
|
properties._idSet = true;
|
||||||
properties._created = _created;
|
properties._created = _created;
|
||||||
|
|
Loading…
Reference in a new issue