forked from TheCherno/Hazel
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
253 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "hzpch.h" | ||
#include "Math.h" | ||
|
||
#define GLM_ENABLE_EXPERIMENTAL | ||
#include <glm/gtx/matrix_decompose.hpp> | ||
|
||
namespace Hazel::Math { | ||
|
||
bool DecomposeTransform(const glm::mat4& transform, glm::vec3& translation, glm::vec3& rotation, glm::vec3& scale) | ||
{ | ||
// From glm::decompose in matrix_decompose.inl | ||
|
||
using namespace glm; | ||
using T = float; | ||
|
||
mat4 LocalMatrix(transform); | ||
|
||
// Normalize the matrix. | ||
if (epsilonEqual(LocalMatrix[3][3], static_cast<float>(0), epsilon<T>())) | ||
return false; | ||
|
||
// First, isolate perspective. This is the messiest. | ||
if ( | ||
epsilonNotEqual(LocalMatrix[0][3], static_cast<T>(0), epsilon<T>()) || | ||
epsilonNotEqual(LocalMatrix[1][3], static_cast<T>(0), epsilon<T>()) || | ||
epsilonNotEqual(LocalMatrix[2][3], static_cast<T>(0), epsilon<T>())) | ||
{ | ||
// Clear the perspective partition | ||
LocalMatrix[0][3] = LocalMatrix[1][3] = LocalMatrix[2][3] = static_cast<T>(0); | ||
LocalMatrix[3][3] = static_cast<T>(1); | ||
} | ||
|
||
// Next take care of translation (easy). | ||
translation = vec3(LocalMatrix[3]); | ||
LocalMatrix[3] = vec4(0, 0, 0, LocalMatrix[3].w); | ||
|
||
vec3 Row[3], Pdum3; | ||
|
||
// Now get scale and shear. | ||
for (length_t i = 0; i < 3; ++i) | ||
for (length_t j = 0; j < 3; ++j) | ||
Row[i][j] = LocalMatrix[i][j]; | ||
|
||
// Compute X scale factor and normalize first row. | ||
scale.x = length(Row[0]); | ||
Row[0] = detail::scale(Row[0], static_cast<T>(1)); | ||
scale.y = length(Row[1]); | ||
Row[1] = detail::scale(Row[1], static_cast<T>(1)); | ||
scale.z = length(Row[2]); | ||
Row[2] = detail::scale(Row[2], static_cast<T>(1)); | ||
|
||
// At this point, the matrix (in rows[]) is orthonormal. | ||
// Check for a coordinate system flip. If the determinant | ||
// is -1, then negate the matrix and the scaling factors. | ||
#if 0 | ||
Pdum3 = cross(Row[1], Row[2]); // v3Cross(row[1], row[2], Pdum3); | ||
if (dot(Row[0], Pdum3) < 0) | ||
{ | ||
for (length_t i = 0; i < 3; i++) | ||
{ | ||
scale[i] *= static_cast<T>(-1); | ||
Row[i] *= static_cast<T>(-1); | ||
} | ||
} | ||
#endif | ||
|
||
rotation.y = asin(-Row[0][2]); | ||
if (cos(rotation.y) != 0) { | ||
rotation.x = atan2(Row[1][2], Row[2][2]); | ||
rotation.z = atan2(Row[0][1], Row[0][0]); | ||
} | ||
else { | ||
rotation.x = atan2(-Row[2][0], Row[1][1]); | ||
rotation.z = 0; | ||
} | ||
|
||
|
||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include <glm/glm.hpp> | ||
|
||
namespace Hazel::Math { | ||
|
||
bool DecomposeTransform(const glm::mat4& transform, glm::vec3& outTranslation, glm::vec3& outRotation, glm::vec3& outScale); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Scene: Untitled | ||
Entities: | ||
- Entity: 12837192831273 | ||
TagComponent: | ||
Tag: Top | ||
TransformComponent: | ||
Translation: [0, 0.5, 0] | ||
Rotation: [1.57079637, 0.785398185, 0] | ||
Scale: [1, 1, 1] | ||
SpriteRendererComponent: | ||
Color: [0.876447856, 0, 0.834712803, 1] | ||
- Entity: 12837192831273 | ||
TagComponent: | ||
Tag: Camera | ||
TransformComponent: | ||
Translation: [0, 1.70000005, 4] | ||
Rotation: [-0.404916406, 0, 0] | ||
Scale: [1, 1, 1] | ||
CameraComponent: | ||
Camera: | ||
ProjectionType: 0 | ||
PerspectiveFOV: 0.52359879 | ||
PerspectiveNear: 0.00999999978 | ||
PerspectiveFar: 1000 | ||
OrthographicSize: 10 | ||
OrthographicNear: -1 | ||
OrthographicFar: 1 | ||
Primary: true | ||
FixedAspectRatio: false | ||
- Entity: 12837192831273 | ||
TagComponent: | ||
Tag: Right | ||
TransformComponent: | ||
Translation: [0.351999998, 0, 0.349999994] | ||
Rotation: [0, 0.785398185, 0] | ||
Scale: [1, 1, 1] | ||
SpriteRendererComponent: | ||
Color: [0.54842025, 0, 0.586872578, 1] | ||
- Entity: 12837192831273 | ||
TagComponent: | ||
Tag: Left | ||
TransformComponent: | ||
Translation: [-0.354999989, 0, 0.349999994] | ||
Rotation: [0, -0.785398185, 0] | ||
Scale: [1, 1, 1] | ||
SpriteRendererComponent: | ||
Color: [1, 0, 0.949807167, 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.