mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 16:18:05 +02:00
fix syntax and missing constant name
This commit is contained in:
parent
30615f09c5
commit
e47524d70a
2 changed files with 32 additions and 20 deletions
|
@ -24,15 +24,15 @@ void Transform::evalRotationScale(Quat& rotation, Vec3& scale, const Mat3& rotat
|
||||||
int count = 0;
|
int count = 0;
|
||||||
Mat3 rotationMat = rotationScaleMatrix;
|
Mat3 rotationMat = rotationScaleMatrix;
|
||||||
do {
|
do {
|
||||||
Mat3 nextRotation;
|
|
||||||
Mat3 currInvTranspose = glm::inverse(glm::transpose(rotationMat));
|
Mat3 currInvTranspose = glm::inverse(glm::transpose(rotationMat));
|
||||||
|
|
||||||
|
Mat3 nextRotation = 0.5f * (rotationMat + currInvTranspose);
|
||||||
// Go through every component in the matrices and find the next matrix
|
// Go through every component in the matrices and find the next matrix
|
||||||
for (int i = 0; i < 3; i++) {
|
/* for (int i = 0; i < 3; i++) {
|
||||||
for (int j = 0; j <3; j++) {
|
for (int j = 0; j <3; j++) {
|
||||||
nextRotation[j][i] = 0.5f * (rotationMat[j][i] + currInvTranspose[j][i]);
|
nextRotation[j][i] = 0.5f * (rotationMat[j][i] + currInvTranspose[j][i]);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
norm = 0.0;
|
norm = 0.0;
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
|
|
@ -31,9 +31,9 @@ public:
|
||||||
|
|
||||||
Transform() :
|
Transform() :
|
||||||
_translation(0),
|
_translation(0),
|
||||||
_rotation(1.f, 0, 0, 0),
|
_rotation(1.0f, 0, 0, 0),
|
||||||
_scale(1.f),
|
_scale(1.0f),
|
||||||
_flags(1) // invalid cache
|
_flags(FLAG_CACHE_INVALID_BITSET) // invalid cache
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
Transform(const Transform& transform) :
|
Transform(const Transform& transform) :
|
||||||
|
@ -67,7 +67,7 @@ public:
|
||||||
void postScale(float scale);
|
void postScale(float scale);
|
||||||
void postScale(const Vec3& scale);
|
void postScale(const Vec3& scale);
|
||||||
|
|
||||||
bool isIdentity() const { return (_flags & ~Flags(1)).none(); }
|
bool isIdentity() const { return (_flags & ~Flags(FLAG_CACHE_INVALID_BITSET)).none(); }
|
||||||
bool isTranslating() const { return _flags[FLAG_TRANSLATION]; }
|
bool isTranslating() const { return _flags[FLAG_TRANSLATION]; }
|
||||||
bool isRotating() const { return _flags[FLAG_ROTATION]; }
|
bool isRotating() const { return _flags[FLAG_ROTATION]; }
|
||||||
bool isScaling() const { return _flags[FLAG_SCALING]; }
|
bool isScaling() const { return _flags[FLAG_SCALING]; }
|
||||||
|
@ -99,8 +99,9 @@ protected:
|
||||||
FLAG_PROJECTION,
|
FLAG_PROJECTION,
|
||||||
|
|
||||||
NUM_FLAGS,
|
NUM_FLAGS,
|
||||||
};
|
|
||||||
|
|
||||||
|
FLAG_CACHE_INVALID_BITSET = 1,
|
||||||
|
};
|
||||||
typedef std::bitset<NUM_FLAGS> Flags;
|
typedef std::bitset<NUM_FLAGS> Flags;
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,9 +134,9 @@ protected:
|
||||||
|
|
||||||
inline void Transform::setIdentity() {
|
inline void Transform::setIdentity() {
|
||||||
_translation = Vec3(0);
|
_translation = Vec3(0);
|
||||||
_rotation = Quat(1.f, 0, 0, 0);
|
_rotation = Quat(1.0f, 0, 0, 0);
|
||||||
_scale = Vec3(1.f);
|
_scale = Vec3(1.0f);
|
||||||
_flags = Flags(1);
|
_flags = Flags(FLAG_CACHE_INVALID_BITSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Transform::Vec3& Transform::getTranslation() const {
|
inline const Transform::Vec3& Transform::getTranslation() const {
|
||||||
|
@ -224,7 +225,7 @@ inline const Transform::Vec3& Transform::getScale() const {
|
||||||
inline void Transform::setScale(float scale) {
|
inline void Transform::setScale(float scale) {
|
||||||
invalidCache();
|
invalidCache();
|
||||||
flagUniform();
|
flagUniform();
|
||||||
if (scale == 1.f) {
|
if (scale == 1.0f) {
|
||||||
unflagScaling();
|
unflagScaling();
|
||||||
} else {
|
} else {
|
||||||
flagScaling();
|
flagScaling();
|
||||||
|
@ -244,7 +245,7 @@ inline void Transform::setScale(const Vec3& scale) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Transform::postScale(float scale) {
|
inline void Transform::postScale(float scale) {
|
||||||
if (scale == 1.f) return;
|
if (scale == 1.0f) return;
|
||||||
if (isScaling()) {
|
if (isScaling()) {
|
||||||
// if already scaling, just invalid cache and aply uniform scale
|
// if already scaling, just invalid cache and aply uniform scale
|
||||||
invalidCache();
|
invalidCache();
|
||||||
|
@ -289,10 +290,15 @@ inline void Transform::evalFromRawMatrix(const Mat3& rotationScaleMatrix) {
|
||||||
inline Transform& Transform::evalInverse(Transform& inverse) const {
|
inline Transform& Transform::evalInverse(Transform& inverse) const {
|
||||||
inverse.setIdentity();
|
inverse.setIdentity();
|
||||||
if (isScaling()) {
|
if (isScaling()) {
|
||||||
|
// TODO: At some point we will face the case when scale is 0 and so 1/0 will blow up...
|
||||||
|
// WHat should we do for this one?
|
||||||
|
assert(_scale.x != 0);
|
||||||
|
assert(_scale.y != 0);
|
||||||
|
assert(_scale.z != 0);
|
||||||
if (isNonUniform()) {
|
if (isNonUniform()) {
|
||||||
inverse.setScale(Vec3(1.f/_scale.x, 1.f/_scale.y, 1.f/_scale.z));
|
inverse.setScale(Vec3(1.0f/_scale.x, 1.0f/_scale.y, 1.0f/_scale.z));
|
||||||
} else {
|
} else {
|
||||||
inverse.setScale(1.f/_scale.x);
|
inverse.setScale(1.0f/_scale.x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isRotating()) {
|
if (isRotating()) {
|
||||||
|
@ -306,9 +312,15 @@ inline Transform& Transform::evalInverse(Transform& inverse) const {
|
||||||
|
|
||||||
inline Transform& Transform::mult( Transform& result, const Transform& left, const Transform& right) {
|
inline Transform& Transform::mult( Transform& result, const Transform& left, const Transform& right) {
|
||||||
result = left;
|
result = left;
|
||||||
if ( right.isTranslating()) result.postTranslate(right.getTranslation());
|
if (right.isTranslating()) {
|
||||||
if ( right.isRotating()) result.postRotate(right.getRotation());
|
result.postTranslate(right.getTranslation());
|
||||||
if (right.isScaling()) result.postScale(right.getScale());
|
}
|
||||||
|
if (right.isRotating()) {
|
||||||
|
result.postRotate(right.getRotation());
|
||||||
|
}
|
||||||
|
if (right.isScaling()) {
|
||||||
|
result.postScale(right.getScale());
|
||||||
|
}
|
||||||
|
|
||||||
// HACK: In case of an issue in the Transform multiplication results, to make sure this code is
|
// HACK: In case of an issue in the Transform multiplication results, to make sure this code is
|
||||||
// working properly uncomment the next 2 lines and compare the results, they should be the same...
|
// working properly uncomment the next 2 lines and compare the results, they should be the same...
|
||||||
|
@ -321,7 +333,7 @@ inline Transform& Transform::mult( Transform& result, const Transform& left, con
|
||||||
inline void Transform::updateCache() const {
|
inline void Transform::updateCache() const {
|
||||||
if (isCacheInvalid()) {
|
if (isCacheInvalid()) {
|
||||||
if (isRotating()) {
|
if (isRotating()) {
|
||||||
glm::mat3x3 rot = glm::mat3_cast(_rotation);
|
Mat3 rot = glm::mat3_cast(_rotation);
|
||||||
|
|
||||||
if (isScaling()) {
|
if (isScaling()) {
|
||||||
rot[0] *= _scale.x;
|
rot[0] *= _scale.x;
|
||||||
|
@ -338,7 +350,7 @@ inline void Transform::updateCache() const {
|
||||||
_matrix[2] = Vec4(0.f, 0.f, _scale.z, 0.f);
|
_matrix[2] = Vec4(0.f, 0.f, _scale.z, 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
_matrix[3] = Vec4(_translation, 1.f);
|
_matrix[3] = Vec4(_translation, 1.0f);
|
||||||
validCache();
|
validCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue