base
This commit is contained in:
@@ -80,65 +80,81 @@ public:
|
||||
void LookAt(glm::vec3 eye, glm::vec3 target) noexcept {
|
||||
TranslateTo(eye);
|
||||
orient = -orient * target;
|
||||
version++;
|
||||
}
|
||||
|
||||
void TranslateBy(glm::vec3 e) noexcept {
|
||||
pos += e;
|
||||
version++;
|
||||
}
|
||||
|
||||
void TranslateTo(glm::vec3 e) noexcept {
|
||||
pos = e;
|
||||
version++;
|
||||
}
|
||||
|
||||
void ScaleBy(glm::vec3 e) noexcept {
|
||||
scale *= e;
|
||||
version++;
|
||||
}
|
||||
|
||||
void ScaleBy(GLfloat e) noexcept {
|
||||
scale *= e;
|
||||
version++;
|
||||
}
|
||||
|
||||
void ScaleTo(glm::vec3 e) noexcept {
|
||||
scale = e;
|
||||
version++;
|
||||
}
|
||||
|
||||
void ScaleTo(GLfloat e) noexcept {
|
||||
scale = glm::vec3(e);
|
||||
version++;
|
||||
}
|
||||
|
||||
void ScaleToX(GLfloat e) noexcept {
|
||||
scale.x = e;
|
||||
version++;
|
||||
}
|
||||
|
||||
void ScaleToY(GLfloat e) noexcept {
|
||||
scale.y = e;
|
||||
version++;
|
||||
}
|
||||
|
||||
void ScaleToZ(GLfloat e) noexcept {
|
||||
scale.z = e;
|
||||
version++;
|
||||
}
|
||||
|
||||
void RotateToQuaternion(glm::quat q) noexcept {
|
||||
orient = q;
|
||||
version++;
|
||||
}
|
||||
|
||||
void RotateByQuaternion(glm::quat q) noexcept {
|
||||
orient = q * orient;
|
||||
version++;
|
||||
}
|
||||
|
||||
void NormalizeRotation() noexcept {
|
||||
orient = glm::normalize(orient);
|
||||
version++;
|
||||
}
|
||||
|
||||
void RotateByQuaternionCumulate(glm::quat q) noexcept {
|
||||
orient = orient * q;
|
||||
version++;
|
||||
}
|
||||
|
||||
void RotateByEulerAnglesCumulate(glm::vec3 e) noexcept {
|
||||
orient = orient * glm::quat(e);
|
||||
version++;
|
||||
}
|
||||
void RotateToEulerAngles(glm::vec3 e) noexcept {
|
||||
orient = glm::quat(e);
|
||||
version++;
|
||||
}
|
||||
void RotateByEulerAngles(glm::vec3 e) noexcept {
|
||||
RotateByQuaternion(glm::quat(e));
|
||||
@@ -185,6 +201,12 @@ public:
|
||||
target.scale = scale;
|
||||
target.orient = orient;
|
||||
target.pos = pos;
|
||||
target.version++;
|
||||
}
|
||||
|
||||
// Goes up every time it moves, turns or is resized, so other code can tell when something it worked out is stale
|
||||
unsigned int GetVersion() const noexcept {
|
||||
return version;
|
||||
}
|
||||
|
||||
glm::mat4 GetScaleMatrix() const noexcept {
|
||||
@@ -199,8 +221,19 @@ public:
|
||||
return glm::mat4_cast(orient);
|
||||
}
|
||||
|
||||
// Kept until the transform changes. Physics asks for the same ones many times a step.
|
||||
glm::mat4 GetMatrix() const noexcept {
|
||||
return GetTranslationMatrix() * GetRotationMatrix() * GetScaleMatrix();
|
||||
if (cachedMatrixVersion != version) {
|
||||
// The rotation with each axis scaled and the translation dropped in, rather than three full matrices multiplied
|
||||
glm::mat4 matrix = glm::mat4_cast(orient);
|
||||
matrix[0] *= scale.x;
|
||||
matrix[1] *= scale.y;
|
||||
matrix[2] *= scale.z;
|
||||
matrix[3] = glm::vec4(pos, 1.0f);
|
||||
cachedMatrix = matrix;
|
||||
cachedMatrixVersion = version;
|
||||
}
|
||||
return cachedMatrix;
|
||||
}
|
||||
|
||||
glm::mat4 GetMatrixRotationless() const noexcept {
|
||||
@@ -221,6 +254,10 @@ private:
|
||||
glm::vec3 pos;
|
||||
glm::vec3 scale;
|
||||
glm::quat orient;
|
||||
|
||||
unsigned int version = 1;
|
||||
mutable unsigned int cachedMatrixVersion = 0;
|
||||
mutable glm::mat4 cachedMatrix = glm::mat4(1.0f);
|
||||
};
|
||||
|
||||
class t_package {
|
||||
|
||||
Reference in New Issue
Block a user