diff --git a/.idea/dictionaries/ricardo.xml b/.idea/dictionaries/ricardo.xml
index f1c6e3b..523d073 100644
--- a/.idea/dictionaries/ricardo.xml
+++ b/.idea/dictionaries/ricardo.xml
@@ -1,8 +1,10 @@
+ quat
shaders
tangram
+ threeengine
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 50dd9e5..8183bd5 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,7 @@
-
+
@@ -16,32 +16,65 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
@@ -62,165 +95,110 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- cross
- operator^
- proje
- Vector
- IsNormalized
- THRESH_VECTOR_NORMALIZED
normalize
GetSafeNormal
normal
@@ -263,15 +235,26 @@
Tangram.json
Wireframe.json
UniformBlockBinding
+ qtrn
+ x
+ y
+ z
+ float
+ vector
- Vector
Vector2
Matrix
TMatrix
SimpleColor/program.json
Wireframe/program.json
+ Vector
+ Quat
+ X
+ Y
+ Z
+ number
@@ -280,28 +263,6 @@
@@ -348,9 +331,9 @@
DEFINITION_ORDER
-
+
-
+
@@ -455,13 +438,7 @@
-
-
-
-
-
-
-
+
@@ -475,20 +452,23 @@
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
@@ -516,7 +496,7 @@
-
+
@@ -535,7 +515,7 @@
-
+
@@ -572,6 +552,8 @@
+
+
@@ -582,9 +564,12 @@
+
+
+
-
+
@@ -596,21 +581,21 @@
-
-
+
-
-
+
+
-
-
+
+
+
-
+
@@ -641,419 +626,394 @@
-
-
-
-
-
-
-
-
+
-
-
+
+
-
+
-
-
+
+
+
-
+
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
+
+
-
-
+
-
-
+
+
-
+
+
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
-
+
-
-
+
+
-
+
+
-
-
+
+
+
-
+
-
-
+
+
+
-
+
-
-
+
+
+
-
+
-
-
-
-
-
+
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
-
-
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
+
-
+
-
-
-
-
-
+
+
+
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
+
-
+
-
-
-
-
-
-
-
-
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
+
-
-
+
+
-
+
-
-
+
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bbcac65..663acfe 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,34 +21,34 @@ elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
ENDIF ()
set(SOURCE_FILES
- src/Debug.h src/Engine.cpp src/Engine.h
- src/json.hpp
- src/Math/Vector.cpp src/Math/Vector.h
- src/Math/Vector2.cpp src/Math/Vector2.h
- src/Math/Maths.cpp src/Math/Maths.h
- src/Math/Vector4.cpp src/Math/Vector4.h
- src/Math/Matrix.cpp src/Math/Matrix.h
- src/Math/TMatrix.h
- src/Math/Matrix3.cpp src/Math/Matrix3.h
- src/Math/Matrix2.cpp src/Math/Matrix2.h
- src/Shader/Shader.cpp src/Shader/Shader.h
- src/Shader/ShaderProgram.cpp src/Shader/ShaderProgram.h
- src/OpenGLUtils.h
- src/Tangram/Tangram.cpp src/Tangram/Tangram.h
- src/IActor.h
- src/Tangram/Triangle.cpp src/Tangram/Triangle.h
- src/Tangram/Square.cpp src/Tangram/Square.h
- src/Tangram/Parallelogram.cpp src/Tangram/Parallelogram.h
- src/Tangram3D/Cube.cpp src/Tangram3D/Cube.h
- src/Camera/Camera.cpp src/Camera/Camera.h
- src/Tangram3D/Tangram3D.cpp src/Tangram3D/Tangram3D.h
- src/Tangram3D/CameraController.cpp src/Tangram3D/CameraController.h
- src/Input.cpp src/Input.h
- src/Camera/LookAt.cpp src/Camera/LookAt.h
- src/Camera/Perspective.cpp src/Camera/Perspective.h
- src/Camera/Ortho.cpp src/Camera/Ortho.h
- src/Tangram3D/Triangle3D.cpp src/Tangram3D/Triangle3D.h
- src/Tangram3D/Parallelogram3D.h src/Tangram3D/Parallelogram3D.cpp)
+ src/Engine/Debug.h src/Engine/Engine.cpp src/Engine/Engine.h
+ src/Engine/json.hpp
+ src/Engine/Math/Vector.cpp src/Engine/Math/Vector.h
+ src/Engine/Math/Vector2.cpp src/Engine/Math/Vector2.h
+ src/Engine/Math/Maths.cpp src/Engine/Math/Maths.h
+ src/Engine/Math/Vector4.cpp src/Engine/Math/Vector4.h
+ src/Engine/Math/Matrix.cpp src/Engine/Math/Matrix.h
+ src/Engine/Math/TMatrix.h
+ src/Engine/Math/Matrix3.cpp src/Engine/Math/Matrix3.h
+ src/Engine/Math/Matrix2.cpp src/Engine/Math/Matrix2.h
+ src/Engine/Shader/Shader.cpp src/Engine/Shader/Shader.h
+ src/Engine/Shader/ShaderProgram.cpp src/Engine/Shader/ShaderProgram.h
+ src/Engine/OpenGLUtils.h
+ src/Examples/Tangram/Tangram.cpp src/Examples/Tangram/Tangram.h
+ src/Engine/IActor.h
+ src/Examples/Tangram/Triangle.cpp src/Examples/Tangram/Triangle.h
+ src/Examples/Tangram/Square.cpp src/Examples/Tangram/Square.h
+ src/Examples/Tangram/Parallelogram.cpp src/Examples/Tangram/Parallelogram.h
+ src/Examples/Tangram3D/Cube.cpp src/Examples/Tangram3D/Cube.h
+ src/Engine/Camera/Camera.cpp src/Engine/Camera/Camera.h
+ src/Examples/Tangram3D/Tangram3D.cpp src/Examples/Tangram3D/Tangram3D.h
+ src/Examples/Tangram3D/CameraController.cpp src/Examples/Tangram3D/CameraController.h
+ src/Engine/Input.cpp src/Engine/Input.h
+ src/Engine/Camera/LookAt.cpp src/Engine/Camera/LookAt.h
+ src/Engine/Camera/Perspective.cpp src/Engine/Camera/Perspective.h
+ src/Engine/Camera/Ortho.cpp src/Engine/Camera/Ortho.h
+ src/Examples/Tangram3D/Triangle3D.cpp src/Examples/Tangram3D/Triangle3D.h
+ src/Examples/Tangram3D/Parallelogram3D.h src/Examples/Tangram3D/Parallelogram3D.cpp src/Engine/Math/Quat.cpp src/Engine/Math/Quat.h)
set(TESTS_SOURCE_FILES src/Tests/catch.hpp src/Tests/tests.cpp src/Tests/VectorTests.h src/Tests/MatrixTests.h)
@@ -70,12 +70,11 @@ elseif (UNIX AND NOT APPLE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wextra -pedantic -g3 -Og -Wuninitialized")
+ FIND_PACKAGE(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
find_package(GLEW REQUIRED)
- if (NOT (OpenGL_FOUND AND GLUT_FOUND AND GLEW_FOUND))
- message(FATAL_ERROR "Some needed libraries were not found. Try running:\n\tsudo apt install freeglut3-dev libglew-dev libxmu-dev libxi-dev")
- endif ()
+ message(STATUS "GLEW and FreeGlut need to be installed.\nRun:\tsudo apt install freeglut3-dev libglew-dev libxmu-dev libxi-dev")
endif ()
include_directories(${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS})
diff --git a/src/Camera/Camera.cpp b/src/Engine/Camera/Camera.cpp
similarity index 100%
rename from src/Camera/Camera.cpp
rename to src/Engine/Camera/Camera.cpp
diff --git a/src/Camera/Camera.h b/src/Engine/Camera/Camera.h
similarity index 100%
rename from src/Camera/Camera.h
rename to src/Engine/Camera/Camera.h
diff --git a/src/Camera/LookAt.cpp b/src/Engine/Camera/LookAt.cpp
similarity index 100%
rename from src/Camera/LookAt.cpp
rename to src/Engine/Camera/LookAt.cpp
diff --git a/src/Camera/LookAt.h b/src/Engine/Camera/LookAt.h
similarity index 87%
rename from src/Camera/LookAt.h
rename to src/Engine/Camera/LookAt.h
index 440682f..cf94058 100644
--- a/src/Camera/LookAt.h
+++ b/src/Engine/Camera/LookAt.h
@@ -10,14 +10,16 @@
namespace ThreeEngine {
- class LookAt : public Matrix{
+ class LookAt : public Matrix {
public:
Vector eye, center, up, view, v, side, s, u;
LookAt(Vector eye, Vector center, Vector up);
- LookAt(Matrix other);
+
+ explicit LookAt(Matrix other);
void Set(Vector eye, Vector center, Vector up);
+
void SetM(Vector eye, Vector v, Vector s, Vector u);
};
diff --git a/src/Camera/Ortho.cpp b/src/Engine/Camera/Ortho.cpp
similarity index 100%
rename from src/Camera/Ortho.cpp
rename to src/Engine/Camera/Ortho.cpp
diff --git a/src/Camera/Ortho.h b/src/Engine/Camera/Ortho.h
similarity index 100%
rename from src/Camera/Ortho.h
rename to src/Engine/Camera/Ortho.h
diff --git a/src/Camera/Perspective.cpp b/src/Engine/Camera/Perspective.cpp
similarity index 100%
rename from src/Camera/Perspective.cpp
rename to src/Engine/Camera/Perspective.cpp
diff --git a/src/Camera/Perspective.h b/src/Engine/Camera/Perspective.h
similarity index 100%
rename from src/Camera/Perspective.h
rename to src/Engine/Camera/Perspective.h
diff --git a/src/Debug.h b/src/Engine/Debug.h
similarity index 97%
rename from src/Debug.h
rename to src/Engine/Debug.h
index 6eb2cb9..9e04033 100644
--- a/src/Debug.h
+++ b/src/Engine/Debug.h
@@ -28,8 +28,8 @@ namespace ThreeEngine {
std::unique_ptr formatted;
va_list ap;
while (1) {
- formatted.reset(
- new char[n]); /* Wrap the plain char array into the unique_ptr */
+ /* Wrap the plain char array into the unique_ptr */
+ formatted.reset(new char[n]);
#if OS_WIN
strcpy_s(&formatted[0], n, fmt_str.c_str());
#else
diff --git a/src/Engine.cpp b/src/Engine/Engine.cpp
similarity index 100%
rename from src/Engine.cpp
rename to src/Engine/Engine.cpp
diff --git a/src/Engine.h b/src/Engine/Engine.h
similarity index 100%
rename from src/Engine.h
rename to src/Engine/Engine.h
diff --git a/src/IActor.h b/src/Engine/IActor.h
similarity index 100%
rename from src/IActor.h
rename to src/Engine/IActor.h
diff --git a/src/Input.cpp b/src/Engine/Input.cpp
similarity index 100%
rename from src/Input.cpp
rename to src/Engine/Input.cpp
diff --git a/src/Input.h b/src/Engine/Input.h
similarity index 100%
rename from src/Input.h
rename to src/Engine/Input.h
diff --git a/src/Math/Maths.cpp b/src/Engine/Math/Maths.cpp
similarity index 83%
rename from src/Math/Maths.cpp
rename to src/Engine/Math/Maths.cpp
index a24f25f..3b3dfcc 100644
--- a/src/Math/Maths.cpp
+++ b/src/Engine/Math/Maths.cpp
@@ -17,4 +17,8 @@ namespace ThreeEngine {
number Maths::ToRadians(number degrees) {
return degrees * Maths::PI / 180.0f;
}
+
+ number Maths::ToDegrees(number radians) {
+ return radians * 180.0f / Maths::PI;
+ }
}
\ No newline at end of file
diff --git a/src/Math/Maths.h b/src/Engine/Math/Maths.h
similarity index 88%
rename from src/Math/Maths.h
rename to src/Engine/Math/Maths.h
index c5ba343..26d74da 100644
--- a/src/Math/Maths.h
+++ b/src/Engine/Math/Maths.h
@@ -17,11 +17,11 @@ namespace ThreeEngine {
typedef float number;
/// Epsilon is the difference between 1.0 and the next value representable by the floating-point.
- const float Epsilon = static_cast(1.0e-5);
+ const number Epsilon = 1.0e-5f;
//const float Epsilon = std::numeric_limits::epsilon();
/// Units in the Last Place to take into account in a floating-point type.
- const float ULP = 3.0f;
+ const number ULP = 3.0f;
struct Maths {
enum Axis { X, Y, Z, W };
@@ -32,6 +32,8 @@ namespace ThreeEngine {
static number ToRadians(number degrees);
+ static number ToDegrees(number radians);
+
private:
Maths() = default;
};
diff --git a/src/Math/Matrix.cpp b/src/Engine/Math/Matrix.cpp
similarity index 99%
rename from src/Math/Matrix.cpp
rename to src/Engine/Math/Matrix.cpp
index e063279..38712f9 100644
--- a/src/Math/Matrix.cpp
+++ b/src/Engine/Math/Matrix.cpp
@@ -16,7 +16,7 @@ namespace ThreeEngine {
Reset(0.0f);
}
- Matrix::Matrix(number in) {
+ Matrix::Matrix(const number& in) {
Reset(in);
}
diff --git a/src/Math/Matrix.h b/src/Engine/Math/Matrix.h
similarity index 99%
rename from src/Math/Matrix.h
rename to src/Engine/Math/Matrix.h
index f916511..ce5436a 100644
--- a/src/Math/Matrix.h
+++ b/src/Engine/Math/Matrix.h
@@ -20,7 +20,7 @@ namespace ThreeEngine {
Matrix();
- explicit Matrix(number in);
+ explicit Matrix(const number& in);
explicit Matrix(Matrix2 m);
diff --git a/src/Math/Matrix2.cpp b/src/Engine/Math/Matrix2.cpp
similarity index 100%
rename from src/Math/Matrix2.cpp
rename to src/Engine/Math/Matrix2.cpp
diff --git a/src/Math/Matrix2.h b/src/Engine/Math/Matrix2.h
similarity index 100%
rename from src/Math/Matrix2.h
rename to src/Engine/Math/Matrix2.h
diff --git a/src/Math/Matrix3.cpp b/src/Engine/Math/Matrix3.cpp
similarity index 100%
rename from src/Math/Matrix3.cpp
rename to src/Engine/Math/Matrix3.cpp
diff --git a/src/Math/Matrix3.h b/src/Engine/Math/Matrix3.h
similarity index 100%
rename from src/Math/Matrix3.h
rename to src/Engine/Math/Matrix3.h
diff --git a/src/Engine/Math/Quat.cpp b/src/Engine/Math/Quat.cpp
new file mode 100644
index 0000000..b645e6d
--- /dev/null
+++ b/src/Engine/Math/Quat.cpp
@@ -0,0 +1,204 @@
+/*
+ * File Quat.cpp in project ThreeEngine
+ *
+ * Copyright (C) Ricardo Rodrigues 2017 - All Rights Reserved
+ */
+#include "Quat.h"
+
+using namespace std;
+
+namespace ThreeEngine {
+
+ Quat::Quat() = default;
+
+ Quat::~Quat() = default;
+
+ Quat::Quat(number InX, number InY, number InZ, number InW) : T(InX), X(InY), Y(InZ), Z(InW) { }
+
+ Quat::Quat(const Quat& Q) {
+ operator=(Q);
+ }
+
+ Quat& Quat::operator=(const Quat& Other) = default;
+
+ Quat::Quat(const Vector& v) : T(0), X(v.X), Y(v.Y), Z(v.Z) { }
+
+ void Quat::Clean() {
+ if (abs(T) < Epsilon) { T = 0; }
+ if (abs(X) < Epsilon) { X = 0; }
+ if (abs(Y) < Epsilon) { Y = 0; }
+ if (abs(Z) < Epsilon) { Z = 0; }
+ }
+
+ number Quat::DistSquared() const {
+ return T * T + X * X + Y * Y + Z * Z;
+ }
+
+ number Quat::Dist() const {
+ return sqrt(DistSquared());
+ }
+
+ Quat Quat::Normalize() const {
+ number s = 1 / Dist();
+ return (*this) * s;
+ }
+
+ Quat Quat::Conjugate() const {
+ return Quat(T, -X, -Y, -Z);
+ }
+
+ Quat Quat::Inverse() const {
+ return Conjugate() * (1.0f / DistSquared());
+ }
+
+ Quat Quat::operator*(const number s) const {
+ return Quat(
+ T * s,
+ X * s,
+ Y * s,
+ Z * s
+ );
+ }
+
+ Quat Quat::operator*(const Quat& q) const {
+ return Quat(
+ T * q.T - X * q.X - Y * q.Y - Z * q.Z,
+ T * q.X + X * q.T + Y * q.Z - Z * q.Y,
+ T * q.Y + Y * q.T + Z * q.X - X * q.Z,
+ T * q.Z + Z * q.T + X * q.Y - Y * q.X
+ );
+ }
+
+ Quat Quat::operator+(const Quat& q) const {
+ return Quat(
+ T + q.T,
+ X + q.X,
+ Y + q.Y,
+ Z + q.Z
+ );
+ }
+
+ Quat operator*(const number& value, const Quat& quat) {
+ return quat * value;
+ }
+
+ bool Quat::operator==(const Quat& q) const {
+ return (abs(T - q.T) < Epsilon && abs(X - q.X) < Epsilon &&
+ abs(Y - q.Y) < Epsilon && abs(q.Z - q.Z) < Epsilon);
+ }
+
+ Matrix Quat::ToMatrix() {
+
+ Quat qN = Normalize();
+
+ number xx = qN.X * qN.X;
+ number xy = qN.X * qN.Y;
+ number xz = qN.X * qN.Z;
+ number xt = qN.X * qN.T;
+ number yy = qN.Y * qN.Y;
+ number yz = qN.Y * qN.Z;
+ number yt = qN.Y * qN.T;
+ number zz = qN.Z * qN.Z;
+ number zt = qN.Z * qN.T;
+
+ return {
+ 1.0f - 2.0f * (yy + zz), 2.0f * (xy - zt), 2.0f * (xz + yt), 0,
+ 2.0f * (xy + zt), 1.0f - 2.0f * (xx + zz), 2.0f * (yz - xt), 0,
+ 2.0f * (xz - yt), 2.0f * (yz + xt), 1.0f - 2.0f * (xx + yy), 0,
+ 0, 0, 0, 1
+ };
+ }
+
+ Quat Quat::FromAngleAxis(number theta, Vector axis) {
+ Vector axisN = Vector::Normalize(axis);
+
+ Quat q;
+ number angle = Maths::ToRadians(theta);
+ q.T = cos(angle / 2.0f);
+ number s = sin(angle / 2.0f);
+ q.X = axisN.X * s;
+ q.Y = axisN.Y * s;
+ q.Z = axisN.Z * s;
+ q.Clean();
+
+ return q.Normalize();
+ }
+
+ Quat Quat::FromAngleAxis(number theta, Vector4 axis) {
+ Vector v = axis;
+ return FromAngleAxis(theta, v);
+ }
+
+ void Quat::ToAngleAxis(const Quat& q, number& theta, Vector& axis) {
+ Quat qN = q.Normalize();
+ theta = Maths::ToDegrees(2.0f * acos(qN.T));
+
+ number s = sqrt(1.0f - qN.T * qN.T);
+ if (s < Epsilon) {
+ axis.X = 1.0f;
+ axis.Y = 0.0f;
+ axis.Z = 0.0f;
+ } else {
+ axis.X = qN.X / s;
+ axis.Y = qN.Y / s;
+ axis.Z = qN.Z / s;
+ }
+ }
+
+ void Quat::ToAngleAxis(const Quat& q, number& theta, Vector4& axis) {
+ Quat qN = q.Normalize();
+ theta = Maths::ToDegrees(2.0f * acos(qN.T));
+
+ number s = sqrt(1.0f - qN.T * qN.T);
+ if (s < Epsilon) {
+ axis.X = 1.0f;
+ axis.Y = 0.0f;
+ axis.Z = 0.0f;
+ axis.W = 1.0f;
+ } else {
+ axis.X = qN.X / s;
+ axis.Y = qN.Y / s;
+ axis.Z = qN.Z / s;
+ axis.W = 1.0f;
+ }
+ }
+
+ Quat Quat::Lerp(const Quat& q0, const Quat& q1, number time) {
+ number cos_angle = q0.X * q1.X + q0.Y * q1.Y + q0.Z * q1.Z + q0.T * q1.T;
+ number t1 = (cos_angle > 0) ? time : -time;
+
+ return ((1 - time) * q0 + t1 * q1).Normalize();
+ }
+
+ Quat Quat::Slerp(const Quat& q0, const Quat& q1, number time) {
+ number angle = acos(q0.X * q1.X + q0.Y * q1.Y + q0.Z * q1.Z + q0.T * q1.T);
+ number t0 = sin((1 - time) * angle) / sin(angle);
+ number t1 = sin(time * angle) / sin(angle);
+
+ return (t0 * q0 + t1 * q1);
+ }
+
+ bool Quat::Equals(const Quat& q0, const Quat& q1) {
+ return q0 == q1;
+ }
+
+ Quat::operator std::string() {
+ return "(" + to_string(T) + ", " + to_string(X) + ", " + to_string(Y) + ", " +
+ to_string(Z) + ")";
+ }
+
+ std::string Quat::ToStringAngleAxis() {
+
+ float thetaf;
+ Vector axis_f;
+ ToAngleAxis(*this, thetaf, axis_f);
+
+ return "[ angle = " + to_string(thetaf) + " axis = " + static_cast(axis_f) + " ]";
+ }
+
+ std::ostream& operator<<(std::ostream& os, const Quat& quat) {
+ os << "(" << quat.T << ", " << quat.X << ", " << quat.Y << ", " << quat.Z << ")";
+ return os;
+ }
+
+} /* namespace Divisaction */
\ No newline at end of file
diff --git a/src/Engine/Math/Quat.h b/src/Engine/Math/Quat.h
new file mode 100644
index 0000000..ebf59e1
--- /dev/null
+++ b/src/Engine/Math/Quat.h
@@ -0,0 +1,94 @@
+/*
+ * File Quat.h in project ThreeEngine
+ *
+ * Copyright (C) Ricardo Rodrigues 2017 - All Rights Reserved
+ */
+#ifndef THREEENGINE_QUAT_H
+#define THREEENGINE_QUAT_H
+
+#include "Maths.h"
+#include "Vector.h"
+#include "Matrix.h"
+
+namespace ThreeEngine {
+
+ struct Quat {
+ public:
+
+ /** The quaternion's X-component. */
+ number T;
+
+ /** The quaternion's Y-component. */
+ number X;
+
+ /** The quaternion's Z-component. */
+ number Y;
+
+ /** The quaternion's W-component. */
+ number Z;
+
+ Quat();
+
+ Quat(number InX, number InY, number InZ, number InW);
+
+ /**
+ * Copy constructor.
+ *
+ * @param Q A Quaternion object to use to create new quaternion from.
+ */
+ Quat(const Quat& Q);
+
+ Quat(const Vector& v);
+
+ virtual ~Quat();
+
+ Quat& operator=(const Quat& Other);
+
+ void Clean();
+
+ number DistSquared() const;
+
+ number Dist() const;
+
+ Quat Normalize() const;
+
+ Quat Conjugate() const;
+
+ Quat Inverse() const;
+
+ Quat operator*(number s) const;
+
+ Quat operator*(const Quat& q) const;
+
+ Quat operator+(const Quat& q) const;
+
+ friend Quat operator*(const number& value, const Quat& quat);
+
+ bool operator==(const Quat& q) const;
+
+ Matrix ToMatrix();
+
+ operator std::string();
+
+ std::string ToStringAngleAxis();
+
+ friend std::ostream& operator<<(std::ostream& os, const Quat& quat);
+
+ static Quat FromAngleAxis(number theta, Vector axis);
+
+ static void ToAngleAxis(const Quat& q, number& theta, Vector& axis);
+
+ static Quat FromAngleAxis(number theta, Vector4 axis);
+
+ static void ToAngleAxis(const Quat& q, number& theta, Vector4& axis);
+
+ static Quat Lerp(const Quat& q0, const Quat& q1, number time);
+
+ static Quat Slerp(const Quat& q0, const Quat& q1, number time);
+
+ static bool Equals(const Quat& q0, const Quat& q1);
+ };
+
+} /* namespace Divisaction */
+
+#endif //THREEENGINE_QUAT_H
diff --git a/src/Math/TMatrix.h b/src/Engine/Math/TMatrix.h
similarity index 100%
rename from src/Math/TMatrix.h
rename to src/Engine/Math/TMatrix.h
diff --git a/src/Math/Vector.cpp b/src/Engine/Math/Vector.cpp
similarity index 98%
rename from src/Math/Vector.cpp
rename to src/Engine/Math/Vector.cpp
index 51bfb12..013ad2e 100644
--- a/src/Math/Vector.cpp
+++ b/src/Engine/Math/Vector.cpp
@@ -212,6 +212,12 @@ namespace ThreeEngine {
return (std::abs(1.0f - DistSquared()) < Epsilon);
}
+ Vector Vector::Normalize(Vector v) {
+ Vector vNorm = v;
+ vNorm.Normalize();
+ return vNorm;
+ }
+
float& Vector::operator[](int Index) {
switch (Index) {
case 0:
diff --git a/src/Math/Vector.h b/src/Engine/Math/Vector.h
similarity index 97%
rename from src/Math/Vector.h
rename to src/Engine/Math/Vector.h
index bbf3da4..4747874 100644
--- a/src/Math/Vector.h
+++ b/src/Engine/Math/Vector.h
@@ -38,7 +38,7 @@ namespace ThreeEngine {
Vector(number inX, number inY, number inZ);
- Vector(const Vector2& other, number inZ = 0);
+ explicit Vector(const Vector2& other, number inZ = 0);
Vector(const Vector& other);
@@ -292,6 +292,13 @@ namespace ThreeEngine {
*/
bool IsNormalized() const;
+ /**
+ * Normalize this vector in-place if it is large enough.
+ *
+ * @return true if the vector was normalized correctly, false otherwise.
+ */
+ static Vector Normalize(Vector v);
+
/**
* Gets specific component of the vector.
*
diff --git a/src/Math/Vector2.cpp b/src/Engine/Math/Vector2.cpp
similarity index 100%
rename from src/Math/Vector2.cpp
rename to src/Engine/Math/Vector2.cpp
diff --git a/src/Math/Vector2.h b/src/Engine/Math/Vector2.h
similarity index 100%
rename from src/Math/Vector2.h
rename to src/Engine/Math/Vector2.h
diff --git a/src/Math/Vector4.cpp b/src/Engine/Math/Vector4.cpp
similarity index 100%
rename from src/Math/Vector4.cpp
rename to src/Engine/Math/Vector4.cpp
diff --git a/src/Math/Vector4.h b/src/Engine/Math/Vector4.h
similarity index 100%
rename from src/Math/Vector4.h
rename to src/Engine/Math/Vector4.h
diff --git a/src/OpenGLUtils.h b/src/Engine/OpenGLUtils.h
similarity index 100%
rename from src/OpenGLUtils.h
rename to src/Engine/OpenGLUtils.h
diff --git a/src/Shader/Shader.cpp b/src/Engine/Shader/Shader.cpp
similarity index 100%
rename from src/Shader/Shader.cpp
rename to src/Engine/Shader/Shader.cpp
diff --git a/src/Shader/Shader.h b/src/Engine/Shader/Shader.h
similarity index 100%
rename from src/Shader/Shader.h
rename to src/Engine/Shader/Shader.h
diff --git a/src/Shader/ShaderProgram.cpp b/src/Engine/Shader/ShaderProgram.cpp
similarity index 100%
rename from src/Shader/ShaderProgram.cpp
rename to src/Engine/Shader/ShaderProgram.cpp
diff --git a/src/Shader/ShaderProgram.h b/src/Engine/Shader/ShaderProgram.h
similarity index 100%
rename from src/Shader/ShaderProgram.h
rename to src/Engine/Shader/ShaderProgram.h
diff --git a/src/json.hpp b/src/Engine/json.hpp
similarity index 100%
rename from src/json.hpp
rename to src/Engine/json.hpp
diff --git a/src/Tangram/Parallelogram.cpp b/src/Examples/Tangram/Parallelogram.cpp
similarity index 98%
rename from src/Tangram/Parallelogram.cpp
rename to src/Examples/Tangram/Parallelogram.cpp
index 27ba2d1..69eb508 100644
--- a/src/Tangram/Parallelogram.cpp
+++ b/src/Examples/Tangram/Parallelogram.cpp
@@ -4,7 +4,7 @@
* Copyright (C) Ricardo Rodrigues 2017 - All Rights Reserved
*/
#include "Parallelogram.h"
-#include "../OpenGLUtils.h"
+#include "../../Engine/OpenGLUtils.h"
#define VERTICES 0
#define COLORS 1
diff --git a/src/Tangram/Parallelogram.h b/src/Examples/Tangram/Parallelogram.h
similarity index 85%
rename from src/Tangram/Parallelogram.h
rename to src/Examples/Tangram/Parallelogram.h
index 88dc0b3..5123982 100644
--- a/src/Tangram/Parallelogram.h
+++ b/src/Examples/Tangram/Parallelogram.h
@@ -7,9 +7,9 @@
#define THREEENGINE_PARALLELOGRAM_H
#include
-#include "../IActor.h"
-#include "../Shader/ShaderProgram.h"
-#include "../OpenGLUtils.h"
+#include "../../Engine/IActor.h"
+#include "../../Engine/Shader/ShaderProgram.h"
+#include "../../Engine/OpenGLUtils.h"
namespace ThreeEngine {
diff --git a/src/Tangram/Square.cpp b/src/Examples/Tangram/Square.cpp
similarity index 98%
rename from src/Tangram/Square.cpp
rename to src/Examples/Tangram/Square.cpp
index 5271d20..3582187 100644
--- a/src/Tangram/Square.cpp
+++ b/src/Examples/Tangram/Square.cpp
@@ -4,7 +4,7 @@
* Copyright (C) Ricardo Rodrigues 2017 - All Rights Reserved
*/
#include "Square.h"
-#include "../OpenGLUtils.h"
+#include "../../Engine/OpenGLUtils.h"
#define VERTICES 0
#define COLORS 1
diff --git a/src/Tangram/Square.h b/src/Examples/Tangram/Square.h
similarity index 84%
rename from src/Tangram/Square.h
rename to src/Examples/Tangram/Square.h
index 8289e56..c5964aa 100644
--- a/src/Tangram/Square.h
+++ b/src/Examples/Tangram/Square.h
@@ -7,9 +7,9 @@
#define THREEENGINE_SQUARE_H
#include
-#include "../IActor.h"
-#include "../Shader/ShaderProgram.h"
-#include "../OpenGLUtils.h"
+#include "../../Engine/IActor.h"
+#include "../../Engine/Shader/ShaderProgram.h"
+#include "../../Engine/OpenGLUtils.h"
namespace ThreeEngine {
diff --git a/src/Tangram/Tangram.cpp b/src/Examples/Tangram/Tangram.cpp
similarity index 99%
rename from src/Tangram/Tangram.cpp
rename to src/Examples/Tangram/Tangram.cpp
index db2ee48..e5173a3 100644
--- a/src/Tangram/Tangram.cpp
+++ b/src/Examples/Tangram/Tangram.cpp
@@ -5,11 +5,11 @@
*/
#include
#include "Tangram.h"
-#include "../Math/Matrix.h"
+#include "../../Engine/Math/Matrix.h"
#include "Triangle.h"
#include "Square.h"
#include "Parallelogram.h"
-#include "../Debug.h"
+#include "../../Engine/Debug.h"
#define VERTICES 0
#define COLORS 1
diff --git a/src/Tangram/Tangram.h b/src/Examples/Tangram/Tangram.h
similarity index 86%
rename from src/Tangram/Tangram.h
rename to src/Examples/Tangram/Tangram.h
index 8e46ff2..015759d 100644
--- a/src/Tangram/Tangram.h
+++ b/src/Examples/Tangram/Tangram.h
@@ -6,9 +6,9 @@
#ifndef THREEENGINE_TANGRAM_H
#define THREEENGINE_TANGRAM_H
-#include "../Engine.h"
-#include "../Shader/ShaderProgram.h"
-#include "../IActor.h"
+#include "../../Engine/Engine.h"
+#include "../../Engine/Shader/ShaderProgram.h"
+#include "../../Engine/IActor.h"
namespace ThreeEngine {
diff --git a/src/Tangram/Triangle.cpp b/src/Examples/Tangram/Triangle.cpp
similarity index 98%
rename from src/Tangram/Triangle.cpp
rename to src/Examples/Tangram/Triangle.cpp
index 434e8ef..80b5661 100644
--- a/src/Tangram/Triangle.cpp
+++ b/src/Examples/Tangram/Triangle.cpp
@@ -4,7 +4,7 @@
* Copyright (C) Ricardo Rodrigues 2017 - All Rights Reserved
*/
#include "Triangle.h"
-#include "../OpenGLUtils.h"
+#include "../../Engine/OpenGLUtils.h"
#define VERTICES 0
#define COLORS 1
diff --git a/src/Tangram/Triangle.h b/src/Examples/Tangram/Triangle.h
similarity index 85%
rename from src/Tangram/Triangle.h
rename to src/Examples/Tangram/Triangle.h
index 9436a97..918733d 100644
--- a/src/Tangram/Triangle.h
+++ b/src/Examples/Tangram/Triangle.h
@@ -7,9 +7,9 @@
#define THREEENGINE_TRIANGLE_H
#include
-#include "../IActor.h"
-#include "../Shader/ShaderProgram.h"
-#include "../OpenGLUtils.h"
+#include "../../Engine/IActor.h"
+#include "../../Engine/Shader/ShaderProgram.h"
+#include "../../Engine/OpenGLUtils.h"
namespace ThreeEngine {
diff --git a/src/Tangram3D/CameraController.cpp b/src/Examples/Tangram3D/CameraController.cpp
similarity index 96%
rename from src/Tangram3D/CameraController.cpp
rename to src/Examples/Tangram3D/CameraController.cpp
index 132818b..57784a1 100644
--- a/src/Tangram3D/CameraController.cpp
+++ b/src/Examples/Tangram3D/CameraController.cpp
@@ -4,9 +4,9 @@
* Copyright (C) Ricardo Rodrigues 2017 - All Rights Reserved
*/
#include "CameraController.h"
-#include "../Camera/Ortho.h"
-#include "../Camera/Perspective.h"
-#include "../Camera/LookAt.h"
+#include "../../Engine/Camera/Ortho.h"
+#include "../../Engine/Camera/Perspective.h"
+#include "../../Engine/Camera/LookAt.h"
namespace ThreeEngine {
diff --git a/src/Tangram3D/CameraController.h b/src/Examples/Tangram3D/CameraController.h
similarity index 95%
rename from src/Tangram3D/CameraController.h
rename to src/Examples/Tangram3D/CameraController.h
index 58872c3..a390f7f 100644
--- a/src/Tangram3D/CameraController.h
+++ b/src/Examples/Tangram3D/CameraController.h
@@ -6,7 +6,7 @@
#ifndef THREEENGINE_CAMERACONTROLLER_H
#define THREEENGINE_CAMERACONTROLLER_H
-#include "../Engine.h"
+#include "../../Engine/Engine.h"
namespace ThreeEngine {
diff --git a/src/Tangram3D/Cube.cpp b/src/Examples/Tangram3D/Cube.cpp
similarity index 100%
rename from src/Tangram3D/Cube.cpp
rename to src/Examples/Tangram3D/Cube.cpp
diff --git a/src/Tangram3D/Cube.h b/src/Examples/Tangram3D/Cube.h
similarity index 84%
rename from src/Tangram3D/Cube.h
rename to src/Examples/Tangram3D/Cube.h
index aac4b8e..c8556ac 100644
--- a/src/Tangram3D/Cube.h
+++ b/src/Examples/Tangram3D/Cube.h
@@ -7,9 +7,9 @@
#define THREEENGINE_CUBE_H
#include
-#include "../IActor.h"
-#include "../Shader/ShaderProgram.h"
-#include "../OpenGLUtils.h"
+#include "../../Engine/IActor.h"
+#include "../../Engine/Shader/ShaderProgram.h"
+#include "../../Engine/OpenGLUtils.h"
namespace ThreeEngine {
diff --git a/src/Tangram3D/Parallelogram3D.cpp b/src/Examples/Tangram3D/Parallelogram3D.cpp
similarity index 100%
rename from src/Tangram3D/Parallelogram3D.cpp
rename to src/Examples/Tangram3D/Parallelogram3D.cpp
diff --git a/src/Tangram3D/Parallelogram3D.h b/src/Examples/Tangram3D/Parallelogram3D.h
similarity index 86%
rename from src/Tangram3D/Parallelogram3D.h
rename to src/Examples/Tangram3D/Parallelogram3D.h
index dbe2d98..6b60188 100644
--- a/src/Tangram3D/Parallelogram3D.h
+++ b/src/Examples/Tangram3D/Parallelogram3D.h
@@ -7,9 +7,9 @@
#define THREEENGINE_PARALLELOGRAM3D_H
#include
-#include "../IActor.h"
-#include "../Shader/ShaderProgram.h"
-#include "../OpenGLUtils.h"
+#include "../../Engine/IActor.h"
+#include "../../Engine/Shader/ShaderProgram.h"
+#include "../../Engine/OpenGLUtils.h"
namespace ThreeEngine {
diff --git a/src/Tangram3D/Tangram3D.cpp b/src/Examples/Tangram3D/Tangram3D.cpp
similarity index 98%
rename from src/Tangram3D/Tangram3D.cpp
rename to src/Examples/Tangram3D/Tangram3D.cpp
index 787430b..3623d25 100644
--- a/src/Tangram3D/Tangram3D.cpp
+++ b/src/Examples/Tangram3D/Tangram3D.cpp
@@ -5,8 +5,8 @@
*/
#include "Tangram3D.h"
#include "Cube.h"
-#include "../Camera/Perspective.h"
-#include "../Camera/LookAt.h"
+#include "../../Engine/Camera/Perspective.h"
+#include "../../Engine/Camera/LookAt.h"
#include "Triangle3D.h"
#include "Parallelogram3D.h"
diff --git a/src/Tangram3D/Tangram3D.h b/src/Examples/Tangram3D/Tangram3D.h
similarity index 86%
rename from src/Tangram3D/Tangram3D.h
rename to src/Examples/Tangram3D/Tangram3D.h
index 6a4a178..05e333f 100644
--- a/src/Tangram3D/Tangram3D.h
+++ b/src/Examples/Tangram3D/Tangram3D.h
@@ -6,9 +6,9 @@
#ifndef THREEENGINE_TANGRAM3D_H
#define THREEENGINE_TANGRAM3D_H
-#include "../Engine.h"
-#include "../Shader/ShaderProgram.h"
-#include "../IActor.h"
+#include "../../Engine/Engine.h"
+#include "../../Engine/Shader/ShaderProgram.h"
+#include "../../Engine/IActor.h"
#include "CameraController.h"
namespace ThreeEngine {
diff --git a/src/Tangram3D/Triangle3D.cpp b/src/Examples/Tangram3D/Triangle3D.cpp
similarity index 100%
rename from src/Tangram3D/Triangle3D.cpp
rename to src/Examples/Tangram3D/Triangle3D.cpp
diff --git a/src/Tangram3D/Triangle3D.h b/src/Examples/Tangram3D/Triangle3D.h
similarity index 85%
rename from src/Tangram3D/Triangle3D.h
rename to src/Examples/Tangram3D/Triangle3D.h
index 64574e2..efb3c4a 100644
--- a/src/Tangram3D/Triangle3D.h
+++ b/src/Examples/Tangram3D/Triangle3D.h
@@ -7,9 +7,9 @@
#define THREEENGINE_TRIANGLE3D_H
#include
-#include "../IActor.h"
-#include "../Shader/ShaderProgram.h"
-#include "../OpenGLUtils.h"
+#include "../../Engine/IActor.h"
+#include "../../Engine/Shader/ShaderProgram.h"
+#include "../../Engine/OpenGLUtils.h"
namespace ThreeEngine {
diff --git a/src/Tests/MatrixTests.h b/src/Tests/MatrixTests.h
index 2282495..91912e6 100644
--- a/src/Tests/MatrixTests.h
+++ b/src/Tests/MatrixTests.h
@@ -5,10 +5,10 @@
#ifndef THREEENGINE_MATRIXTESTS_H
#define THREEENGINE_MATRIXTESTS_H
-#include "../Math/Matrix.h"
-#include "../Math/TMatrix.h"
-#include "../Math/Matrix3.h"
-#include "../Math/Matrix2.h"
+#include "../Engine/Math/Matrix.h"
+#include "../Engine/Math/TMatrix.h"
+#include "../Engine/Math/Matrix3.h"
+#include "../Engine/Math/Matrix2.h"
SCENARIO("matrix arithmetic testing", "[matrix]") {
@@ -245,14 +245,14 @@ SCENARIO("matrix arithmetic testing", "[matrix]") {
THEN("vector +-*/ number") {
CHECK((m + 1.0f) == Matrix(2));
- CHECK((m - 1.0f) == Matrix(0));
+ CHECK((m - 1.0f) == Matrix((const number) 0));
CHECK((m * 2.0f) == Matrix(2));
CHECK((m / 2.0f) == Matrix(.5f));
}
THEN("number +-*/ vector") {
CHECK((1.0f + m) == Matrix(2));
- CHECK((1.0f - m) == Matrix(0));
+ CHECK((1.0f - m) == Matrix((const number) 0));
CHECK((2.0f * m) == Matrix(2));
CHECK((2.0f / m) == Matrix(2));
}
diff --git a/src/Tests/VectorTests.h b/src/Tests/VectorTests.h
index 265ef41..131c332 100644
--- a/src/Tests/VectorTests.h
+++ b/src/Tests/VectorTests.h
@@ -5,10 +5,10 @@
#ifndef THREEENGINE_VECTORTESTS_H
#define THREEENGINE_VECTORTESTS_H
-#include "../Math/Vector.h"
-#include "../Math/Vector2.h"
+#include "../Engine/Math/Vector.h"
+#include "../Engine/Math/Vector2.h"
+#include "../Engine/Math/Vector4.h"
#include "catch.hpp"
-#include "../Math/Vector4.h"
SCENARIO("vectors arithmetic testing", "[vector]") {
diff --git a/src/Tests/tests.cpp b/src/Tests/tests.cpp
index 0a0950e..e6cc583 100644
--- a/src/Tests/tests.cpp
+++ b/src/Tests/tests.cpp
@@ -7,7 +7,7 @@
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
-#include "../Math/Maths.h"
+#include "../Engine/Math/Maths.h"
// this assures that all the tests in the .h files are using the 3Engine namespace
using namespace ThreeEngine;
diff --git a/src/main.cpp b/src/main.cpp
index 5392b67..3d72c47 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3,7 +3,8 @@
//
#include
-#include "Tangram3D/Tangram3D.h"
+#include "Examples/Tangram3D/Tangram3D.h"
+#include "Engine/Math/Quat.h"
using namespace ThreeEngine;
@@ -16,11 +17,17 @@ int main(int argc, char* argv[]) {
srand(static_cast (time(0)));
{
+ Quat q = Quat::FromAngleAxis(90, Vector(0, 0, 1));
+ Quat qi = q.Inverse();
+ Vector4 v = {1, 0, 0, 0};
+ Quat r = q * Quat(v) * qi;
+ Debug::Log(r);
+
Tangram3D engine;
engine.shapeToShow = Tangram3D::ShapeType3D::CUBE;
engine.Init(argc, argv);
engine.Run();
}
-
+
exit(EXIT_SUCCESS);
}
\ No newline at end of file