diff --git a/include/J3ML/LinearAlgebra/AxisAngle.h b/include/J3ML/LinearAlgebra/AxisAngle.h index 3a60d73..b885157 100644 --- a/include/J3ML/LinearAlgebra/AxisAngle.h +++ b/include/J3ML/LinearAlgebra/AxisAngle.h @@ -14,8 +14,6 @@ namespace LinearAlgebra public: AxisAngle(); - AxisAngle(Vector3 axis, float angle); - - + AxisAngle(const Vector3& axis, float angle); }; } \ No newline at end of file diff --git a/include/J3ML/LinearAlgebra/Quaternion.h b/include/J3ML/LinearAlgebra/Quaternion.h index 06ed631..7161ecd 100644 --- a/include/J3ML/LinearAlgebra/Quaternion.h +++ b/include/J3ML/LinearAlgebra/Quaternion.h @@ -4,6 +4,7 @@ #include #include +#include namespace LinearAlgebra { @@ -17,8 +18,6 @@ namespace LinearAlgebra // @note The input data is not normalized after construction, this has to be done manually. Quaternion(float X, float Y, float Z, float W); - - // Constructs this quaternion by specifying a rotation axis and the amount of rotation to be performed about that axis // @param rotationAxis The normalized rotation axis to rotate about. If using Vector4 version of the constructor, the w component of this vector must be 0. Quaternion(const Vector3& rotationAxis, float rotationAngleBetween) { SetFromAxisAngle(rotationAxis, rotationAngleBetween); } @@ -71,7 +70,7 @@ namespace LinearAlgebra Vector4 operator * (const Vector4& rhs) const; // Divides a quaternion by another. Divison "a / b" results in a quaternion that rotates the orientation b to coincide with orientation of - //Quaternion operator / (const Quaternion& rhs) const; + Quaternion operator / (const Quaternion& rhs) const; Quaternion operator +(const Quaternion& rhs) const; Quaternion operator +() const; Quaternion operator -() const; diff --git a/include/J3ML/LinearAlgebra/Vector4.h b/include/J3ML/LinearAlgebra/Vector4.h index cef20f1..6eba284 100644 --- a/include/J3ML/LinearAlgebra/Vector4.h +++ b/include/J3ML/LinearAlgebra/Vector4.h @@ -16,7 +16,6 @@ namespace LinearAlgebra { Vector4(Vector4&& move) = default; Vector4& operator=(const Vector4& rhs); - float GetX() const; float GetY() const; float GetZ() const; diff --git a/main.cpp b/main.cpp index f7263ae..a9db1dc 100644 --- a/main.cpp +++ b/main.cpp @@ -5,4 +5,13 @@ int main(int argc, char** argv) { std::cout << "j3ml demo coming soon" << std::endl; return 0; -} \ No newline at end of file +} + +#ifdef __WIN32 +extern "C" { + int wmain(int argc, wchar_t* argv[]) + { + return main(argc, reinterpret_cast(argv)); + } +}; +#endif \ No newline at end of file diff --git a/src/J3ML/LinearAlgebra/EulerAngle.cpp b/src/J3ML/LinearAlgebra/EulerAngle.cpp index 24e7f0d..4f1f726 100644 --- a/src/J3ML/LinearAlgebra/EulerAngle.cpp +++ b/src/J3ML/LinearAlgebra/EulerAngle.cpp @@ -47,4 +47,6 @@ EulerAngle EulerAngle::movementAngle() const a.roll = (sin(Math::Radians(yaw)) * cos(Math::Radians(pitch))); return a; } + + EulerAngle::EulerAngle() : pitch(0), yaw(0), roll(0) {} } \ No newline at end of file diff --git a/src/J3ML/LinearAlgebra/Quaternion.cpp b/src/J3ML/LinearAlgebra/Quaternion.cpp index 037f363..44844e1 100644 --- a/src/J3ML/LinearAlgebra/Quaternion.cpp +++ b/src/J3ML/LinearAlgebra/Quaternion.cpp @@ -135,11 +135,34 @@ namespace LinearAlgebra { y*reciprocalSinAngle, z*reciprocalSinAngle }; - return {axis, angle}; + return AxisAngle(axis, angle); } float Quaternion::AngleBetween(const Quaternion &target) const { Quaternion delta = target / *this; return delta.Normalize().Angle(); } + + Quaternion Quaternion::operator/(const Quaternion &rhs) const { + return { + x*rhs.w - y*rhs.z + z*rhs.y - w*rhs.x, + x*rhs.z + y*rhs.w - z*rhs.x - w*rhs.y, + -x*rhs.y + y*rhs.x + z*rhs.w - w*rhs.z, + x*rhs.x + y*rhs.y + z*rhs.z + w*rhs.w + }; + } + + Matrix3x3 Quaternion::ToMatrix3x3() const { + return { + 1 - 2 *(y*y) - 2*(z*z), 2*x*y - 2*z*w, 2*x*z + 2*y*w, + 2*x*y + 2*z*w, 1-2*x*x - 2*z*z, 2*y*z - 2*x*w, + 2*x*z - 2*y*w, 2*y*z + 2*x*w, 1-2*x*x - 2*y*y + }; + } + + Quaternion Quaternion::operator+(const Quaternion &rhs) const { + return { + x + rhs.x, y + rhs.y, z + rhs.z,w + rhs.w + }; + } } \ No newline at end of file diff --git a/src/J3ML/LinearAlgebra/Vector4.cpp b/src/J3ML/LinearAlgebra/Vector4.cpp index f5f2986..6b30bc3 100644 --- a/src/J3ML/LinearAlgebra/Vector4.cpp +++ b/src/J3ML/LinearAlgebra/Vector4.cpp @@ -1,6 +1,9 @@ -#include + #pragma region vector4 + +#include +#include #include #include @@ -131,6 +134,11 @@ Vector4 Vector4::operator-(const Vector4& rhs) const return this->Distance(rhs) <= margin; } + Vector4::Vector4(const Vector3 &xyz, float w) : x(xyz.x), y(xyz.y), z(xyz.z), w(w) + { + + } + } #pragma endregion \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b543626..60eabab 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,10 +10,10 @@ add_library(GTest::GTest INTERFACE IMPORTED) target_link_libraries(GTest::GTest INTERFACE gtest_main) -file(GLOB_RECURSE TEST_SRC "*.cpp") +file(GLOB_RECURSE TEST_SRC "tests.cpp" "*.cpp") add_executable(Test ${TEST_SRC}) target_link_libraries(Test PUBLIC J3ML) #find_package(GTest REQUIRED) target_link_libraries(Test PRIVATE GTest::GTest) include_directories("include") -add_test(NAME "J3MLTestSuite" COMMAND J3MLTestSuite) \ No newline at end of file +add_test(NAME "J3MLTestSuite" COMMAND Test) \ No newline at end of file diff --git a/tests/LinearAlgebra/Vector2Tests.cpp b/tests/LinearAlgebra/Vector2Tests.cpp index 9cc6d5a..8b217cb 100644 --- a/tests/LinearAlgebra/Vector2Tests.cpp +++ b/tests/LinearAlgebra/Vector2Tests.cpp @@ -2,27 +2,24 @@ #include -TEST(Vector2Test, V2_Constructor_Default) { } +TEST(Vector2Test, V2_Constructor_Default) +{ + EXPECT_EQ(LinearAlgebra::Vector2(), LinearAlgebra::Vector2::Up); +} + +/* TEST(Vector2Test, V2_Addition) { } TEST(Vector2Test, V2_Subtraction) { } TEST(Vector2Test, V2_Multiplication) { } TEST(Vector2Test, V2_Division) { } TEST(Vector2Test, V2_Equality) { } TEST(Vector2Test, V2_Array_Operator_Indexing) { } - - -TEST(Vector2Test, V2_Normalize) -{ - -} - -TEST(Vector2Test, V2_Dot) -{ - -} - +TEST(Vector2Test, V2_Normalize) { } +TEST(Vector2Test, V2_Dot) { } TEST(Vector2Test, V2_Min) { } TEST(Vector2Test, V2_Max) { } TEST(Vector2Test, V2_Distance) { } TEST(Vector2Test, V2_Length) { } -TEST(Vector2Test, V2_Clamp) { } \ No newline at end of file +TEST(Vector2Test, V2_Clamp) { } + + */ \ No newline at end of file diff --git a/tests/tests.cpp b/tests/tests.cpp index ce43c6b..95e0b3d 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -4,4 +4,13 @@ GTEST_API_ int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); -} \ No newline at end of file +} + +#ifdef __WIN32 +extern "C" { + int wmain(int argc, wchar_t* argv[]) + { + return main(argc, reinterpret_cast(argv)); + } +}; +#endif \ No newline at end of file