diff --git a/core/component/camera.cpp b/core/component/camera.cpp index d7a68dc..a953734 100644 --- a/core/component/camera.cpp +++ b/core/component/camera.cpp @@ -18,7 +18,7 @@ glm::mat4 Camera::getViewMatrix() { return glm::mat4(1.0f); } else { auto tf = lockedOwner->getComponent(); - return glm::lookAt(glm::vec3(tf->position.x, tf->position.y, tf->position.z), position + front, up); + return glm::lookAt(glm::vec3(tf->position.x(), tf->position.y(), tf->position.z()), position + front, up); } } diff --git a/core/component/light.hpp b/core/component/light.hpp index 0003caf..339205e 100644 --- a/core/component/light.hpp +++ b/core/component/light.hpp @@ -1,7 +1,7 @@ #pragma once #include "component/component.hpp" -#include "vector/vector3.hpp" +#include "vector/vector.hpp" namespace SpaceEngine { @@ -22,7 +22,7 @@ class Light : public Component { // Specific attributes LightType type; - Vector3 direction; + Vec3d direction; float spotAngle; /** diff --git a/core/component/transform.cpp b/core/component/transform.cpp index 076154e..335c6c1 100644 --- a/core/component/transform.cpp +++ b/core/component/transform.cpp @@ -4,8 +4,8 @@ namespace SpaceEngine { Transform::Transform(std::weak_ptr owner, std::string name) : Component(owner) { this->name = name; - this->position = Vector3(); - this->scale = Vector3(1.0f, 1.0f, 1.0f); + this->position = Vec3d(); + this->scale = Vec3d(1.0f, 1.0f, 1.0f); } } diff --git a/core/component/transform.hpp b/core/component/transform.hpp index 352d289..a8c81ee 100644 --- a/core/component/transform.hpp +++ b/core/component/transform.hpp @@ -3,7 +3,7 @@ #include #include "component/component.hpp" -#include "vector/vector3.hpp" +#include "vector/vector.hpp" namespace SpaceEngine { @@ -12,9 +12,9 @@ namespace SpaceEngine { * * Properties: * - name (std::string): The name of the object. - * - position (Vector3): The position of the transform in 3D space. - * - rotation (Vector3): The rotation of the transform in 3D space. - * - scale (Vector3): The scale of the transform in 3D space. + * - position (Vec3d): The position of the transform in 3D space. + * - rotation (Vec3d): The rotation of the transform in 3D space. + * - scale (Vec3d): The scale of the transform in 3D space. * * Methods: * - Transform(std::string name): Default constructor: Initializes a new transform component with default values. @@ -23,9 +23,9 @@ namespace SpaceEngine { class Transform : public Component { public: std::string name; /* The name of the object. */ - Vector3 position; /* The position of the transform in 3D space. */ - Vector3 rotation; /* The rotation of the transform in 3D space. */ - Vector3 scale; /* The scale of the transform in 3D space. */ + Vec3d position; /* The position of the transform in 3D space. */ + Vec3d rotation; /* The rotation of the transform in 3D space. */ + Vec3d scale; /* The scale of the transform in 3D space. */ /** * @brief Default constructor: Initializes a new transform component with default values. diff --git a/core/vector/vector.hpp b/core/vector/vector.hpp index f33fda6..44ae857 100644 --- a/core/vector/vector.hpp +++ b/core/vector/vector.hpp @@ -51,9 +51,6 @@ class Vector { // Equality operators. constexpr bool operator==(const Vector& vec) const noexcept; constexpr bool operator!=(const Vector& vec) const noexcept; - - // stdout - std::ostream& operator<< <>(std::ostream& stream, const Vector& vec); }; // Aliases diff --git a/core/vector/vector.inl b/core/vector/vector.inl index 7c3965c..5a75f83 100644 --- a/core/vector/vector.inl +++ b/core/vector/vector.inl @@ -206,4 +206,5 @@ std::ostream& operator<<(std::ostream& stream, const Vector& vec) { return stream; } + } diff --git a/editor/main.cpp b/editor/main.cpp index f0df21d..b6c04f0 100644 --- a/editor/main.cpp +++ b/editor/main.cpp @@ -206,11 +206,11 @@ int main() { if (modelRenderer && modelRenderer->model) { auto tf = entity->getComponent(); glm::mat4 model = glm::mat4(1.0f); - model = glm::translate(model, glm::vec3(tf->position.x, tf->position.y, tf->position.z)); - model = glm::scale(model, glm::vec3(tf->scale.x, tf->scale.y, tf->scale.z)); - model = glm::rotate(model, static_cast(glm::radians(tf->rotation.x)), glm::vec3(1.0f, 0.0f, 0.0f)); - model = glm::rotate(model, static_cast(glm::radians(tf->rotation.y)), glm::vec3(0.0f, 1.0f, 0.0f)); - model = glm::rotate(model, static_cast(glm::radians(tf->rotation.z)), glm::vec3(0.0f, 0.0f, 1.0f)); + model = glm::translate(model, glm::vec3(tf->position.x(), tf->position.y(), tf->position.z())); + model = glm::scale(model, glm::vec3(tf->scale.x(), tf->scale.y(), tf->scale.z())); + model = glm::rotate(model, static_cast(glm::radians(tf->rotation.x())), glm::vec3(1.0f, 0.0f, 0.0f)); + model = glm::rotate(model, static_cast(glm::radians(tf->rotation.y())), glm::vec3(0.0f, 1.0f, 0.0f)); + model = glm::rotate(model, static_cast(glm::radians(tf->rotation.z())), glm::vec3(0.0f, 0.0f, 1.0f)); shader.setMat4("model", model); modelRenderer->model->draw(shader); } diff --git a/editor/menu/component_viewer.cpp b/editor/menu/component_viewer.cpp index beb4537..2355075 100644 --- a/editor/menu/component_viewer.cpp +++ b/editor/menu/component_viewer.cpp @@ -12,27 +12,27 @@ void Menu::initComponentViewers() { ImGui::PushItemWidth(75); ImGui::Text("Position"); ImGui::SameLine(100); - if (ImGui::InputDouble("##transform.position.x", &transform->position.x)) {} + if (ImGui::InputDouble("##transform.position.x", &transform->position.x())) {} ImGui::SameLine(180); - if (ImGui::InputDouble("##transform.position.y", &transform->position.y)) {} + if (ImGui::InputDouble("##transform.position.y", &transform->position.y())) {} ImGui::SameLine(260); - if (ImGui::InputDouble("##transform.position.z", &transform->position.z)) {} + if (ImGui::InputDouble("##transform.position.z", &transform->position.z())) {} ImGui::Text("Rotation"); ImGui::SameLine(100); - if (ImGui::InputDouble("##transform.rotation.x", &transform->rotation.x)) {} + if (ImGui::InputDouble("##transform.rotation.x", &transform->rotation.x())) {} ImGui::SameLine(180); - if (ImGui::InputDouble("##transform.rotation.y", &transform->rotation.y)) {} + if (ImGui::InputDouble("##transform.rotation.y", &transform->rotation.y())) {} ImGui::SameLine(260); - if (ImGui::InputDouble("##transform.rotation.z", &transform->rotation.z)) {} + if (ImGui::InputDouble("##transform.rotation.z", &transform->rotation.z())) {} ImGui::Text("Scale"); ImGui::SameLine(100); - if (ImGui::InputDouble("##transform.scale.x", &transform->scale.x)) {} + if (ImGui::InputDouble("##transform.scale.x", &transform->scale.x())) {} ImGui::SameLine(180); - if (ImGui::InputDouble("##transform.scale.y", &transform->scale.y)) {} + if (ImGui::InputDouble("##transform.scale.y", &transform->scale.y())) {} ImGui::SameLine(260); - if (ImGui::InputDouble("##transform.scale.z", &transform->scale.z)) {} + if (ImGui::InputDouble("##transform.scale.z", &transform->scale.z())) {} } }; diff --git a/tests/test_vector2.cpp b/tests/test_vector2.cpp index a66d32f..7776966 100644 --- a/tests/test_vector2.cpp +++ b/tests/test_vector2.cpp @@ -7,41 +7,50 @@ int testVector2() { Vec2f vec1(1.0f, 2.0f); Vec2f vec2(3.0f, 5.0f); - /* Addition check */ - Vec2f add_result = vec1 + vec2; - custom_assert((add_result.x() == 4.0f && add_result.y() == 7.0f), "Addition check failed"); - - /* Subtraction check */ - Vec2f sub_result = vec1 - vec2; - custom_assert((sub_result.x() == -2.0f && sub_result.y() == -3.0f), "Subtraction check failed"); - - /* Addition assignment check */ - Vec2f vec3(2.0f, 3.0f); - vec3 += vec1; - custom_assert((vec3.x() == 3.0f && vec3.y() == 5.0f), "Addition assignment check failed"); - - /* Subtraction assignment check */ - Vec2f vec4(5.0f, 7.0f); - vec4 -= vec1; - custom_assert((vec4.x() == 4.0f && vec4.y() == 5.0f), "Subtraction assignment check failed"); - - /* Multiplication assignment check */ - Vec2f vec5(2.0f, 4.0f); - vec5 *= 2.0f; // Assuming scalar multiplication - custom_assert((vec5.x() == 4.0f && vec5.y() == 8.0f), "Multiplication assignment check failed"); - - // Since the Vector class does not directly support division by another Vector, - // this section will be omitted or you need to implement it in the Vector class. - - /* Equality check */ - Vec2f vec7(3.0f, 5.0f); - custom_assert((vec2.x() == vec7.x() && vec2.y() == vec7.y()), "Equality check failed"); - - /* Inequality check */ - Vec2f vec8(1.0f, 7.0f); - custom_assert((vec1.x() != vec8.x() || vec1.y() != vec8.y()), "Inequality check failed"); - - // The distance and glm cast checks are omitted since they would require additional implementation details. - + // Test addition + auto add_result = vec1 + vec2; + custom_assert(add_result.x() == 4.0f && add_result.y() == 7.0f, "Vec2f addition failed"); + + // Test subtraction + auto sub_result = vec1 - vec2; + custom_assert(sub_result.x() == -2.0f && sub_result.y() == -3.0f, "Vec2f subtraction failed"); + + // Test multiplication by a scalar + auto mul_result_scalar = vec1 * 2.0f; + custom_assert(mul_result_scalar.x() == 2.0f && mul_result_scalar.y() == 4.0f, "Vec2f scalar multiplication failed"); + + // Test division by a scalar + auto div_result_scalar = vec1 / 2.0f; + custom_assert(div_result_scalar.x() == 0.5f && div_result_scalar.y() == 1.0f, "Vec2f scalar division failed"); + + // Test += with a vector + Vec2f vec3 = vec1; + vec3 += vec2; + custom_assert(vec3.x() == 4.0f && vec3.y() == 7.0f, "Vec2f += failed"); + + // Test -= with a vector + vec3 = vec1; + vec3 -= vec2; + custom_assert(vec3.x() == -2.0f && vec3.y() == -3.0f, "Vec2f -= failed"); + + // Test *= with a scalar + vec3 = vec1; + vec3 *= 2.0f; + custom_assert(vec3.x() == 2.0f && vec3.y() == 4.0f, "Vec2f *= failed"); + + // Test /= with a scalar + vec3 = vec1; + vec3 /= 2.0f; + custom_assert(vec3.x() == 0.5f && vec3.y() == 1.0f, "Vec2f /= failed"); + + // Test operator[] + custom_assert(vec1[0] == 1.0f && vec1[1] == 2.0f, "Vec2f operator[] failed"); + + // Test equality + Vec2f vec4(1.0f, 2.0f); + custom_assert(vec1 == vec4, "Vec2f equality failed"); + + // Test inequality + custom_assert(vec1 != vec2, "Vec2f inequality failed"); return 0; } diff --git a/tests/test_vector3.cpp b/tests/test_vector3.cpp index c8067f9..6aeff1d 100644 --- a/tests/test_vector3.cpp +++ b/tests/test_vector3.cpp @@ -1,55 +1,56 @@ #include "test.hpp" -// #include "vector/vector3.hpp" +#include "vector/vector.hpp" -// using SpaceEngine::Vector3; +using SpaceEngine::Vec3f; int testVector3() { - // Vector3 vec1 = Vector3(1.0, 2.0, 3.0); - // Vector3 vec2 = Vector3(3.0, 5.0, 7.0); - - // /* Addition check */ - // Vector3 add_result = vec1 + vec2; - // custom_assert(add_result == Vector3(4.0, 7.0, 10.0)); - - // /* Subtraction check */ - // Vector3 sub_result = vec1 - vec2; - // custom_assert(sub_result == Vector3(-2.0, -3.0, -4.0)); - - // /* Addition assignment check */ - // Vector3 vec3(2.0, 3.0, 4.0); - // vec3 += vec1; - // custom_assert(vec3 == Vector3(3.0, 5.0, 7.0)); - - // /* Subtraction assignment check */ - // Vector3 vec4(5.0, 7.0, 9.0); - // vec4 -= vec1; - // custom_assert(vec4 == Vector3(4.0, 5.0, 6.0)); - - // /* Multiplication assignment check */ - // Vector3 vec5(2.0, 4.0, 6.0); - // vec5 *= vec1; - // custom_assert(vec5 == Vector3(2.0, 8.0, 18.0)); - - // /* Division assignment check */ - // Vector3 vec6(6.0, 8.0, 12.0); - // vec6 /= vec2; - // custom_assert(vec6 == Vector3(2.0, 1.6, 1.7142857142857142)); - - // /* Equality check */ - // Vector3 vec7(3.0, 5.0, 7.0); - // custom_assert(vec2 == vec7); - - // /* Inequality check */ - // Vector3 vec8(1.0, 7.0, 9.0); - // custom_assert(vec1 != vec8); - - // /* Distance check */ - // double distance_result = vec1.distance(vec2); - // custom_assert(distance_result == sqrt(29.)); - - // /* glm cast check */ - // glm::vec3 glm_vec = vec1; - // custom_assert(glm_vec == glm::vec3(1.0, 2.0, 3.0)); - + Vec3f vec1(1.0f, 2.0f, 3.0f); + Vec3f vec2(4.0f, 5.0f, 6.0f); + + // Test addition + auto add_result = vec1 + vec2; + custom_assert(add_result.x() == 5.0f && add_result.y() == 7.0f && add_result.z() == 9.0f, "Vec3f addition failed"); + + // Test subtraction + auto sub_result = vec1 - vec2; + custom_assert(sub_result.x() == -3.0f && sub_result.y() == -3.0f && sub_result.z() == -3.0f, "Vec3f subtraction failed"); + + // Test multiplication by a scalar + auto mul_result_scalar = vec1 * 2.0f; + custom_assert(mul_result_scalar.x() == 2.0f && mul_result_scalar.y() == 4.0f && mul_result_scalar.z() == 6.0f, "Vec3f scalar multiplication failed"); + + // Test division by a scalar + auto div_result_scalar = vec1 / 2.0f; + custom_assert(div_result_scalar.x() == 0.5f && div_result_scalar.y() == 1.0f && div_result_scalar.z() == 1.5f, "Vec3f scalar division failed"); + + // Test += with a vector + Vec3f vec3 = vec1; + vec3 += vec2; + custom_assert(vec3.x() == 5.0f && vec3.y() == 7.0f && vec3.z() == 9.0f, "Vec3f += failed"); + + // Test -= with a vector + vec3 = vec1; + vec3 -= vec2; + custom_assert(vec3.x() == -3.0f && vec3.y() == -3.0f && vec3.z() == -3.0f, "Vec3f -= failed"); + + // Test *= with a scalar + vec3 = vec1; + vec3 *= 2.0f; + custom_assert(vec3.x() == 2.0f && vec3.y() == 4.0f && vec3.z() == 6.0f, "Vec3f *= failed"); + + // Test /= with a scalar + vec3 = vec1; + vec3 /= 2.0f; + custom_assert(vec3.x() == 0.5f && vec3.y() == 1.0f && vec3.z() == 1.5f, "Vec3f /= failed"); + + // Test operator[] + custom_assert(vec1[0] == 1.0f && vec1[1] == 2.0f && vec1[2] == 3.0f, "Vec3f operator[] failed"); + + // Test equality + Vec3f vec4(1.0f, 2.0f, 3.0f); + custom_assert(vec1 == vec4, "Vec3f equality failed"); + + // Test inequality + custom_assert(vec1 != vec2, "Vec3f inequality failed"); return 0; }