summaryrefslogtreecommitdiff
path: root/src/vector_3d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/vector_3d.cpp')
-rw-r--r--src/vector_3d.cpp27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/vector_3d.cpp b/src/vector_3d.cpp
index c0a9a3e..fc5d186 100644
--- a/src/vector_3d.cpp
+++ b/src/vector_3d.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 Frederico de Oliveira Linhares
+ * Copyright 2022-2024 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
#include <mruby/array.h>
-#include "rotation_3d.hpp"
+#include "orientation_3d.hpp"
void
cg_free_vector_3d(mrb_state *mrb, void* obj)
@@ -235,24 +235,17 @@ cg_cVector3D_set_xyz(mrb_state *mrb, mrb_value self)
static mrb_value
cg_cVector3D_translate(mrb_state *mrb, mrb_value self)
{
- std::shared_ptr<glm::vec3> *ptr =
- (std::shared_ptr<glm::vec3>*)DATA_PTR(self);
- std::shared_ptr<glm::vec3> *direction, *rotation;
+ auto *ptr = (std::shared_ptr<glm::vec3>*)DATA_PTR(self);
+ std::shared_ptr<glm::vec3> *direction;
+ std::shared_ptr<glm::quat> *orientation;
mrb_get_args(
mrb, "dd", &direction, &cg_vector_3d_type,
- &rotation, &cg_rotation_3d_type);
-
- glm::mat4 matrix{1.0f};
- glm::vec4 vec{(**direction), 1.0f};
- matrix = glm::rotate(matrix, (*rotation)->y, glm::vec3{0.0f, 1.0f, 0.0f});
- matrix = glm::rotate(matrix, (*rotation)->x, glm::vec3{1.0f, 0.0f, 0.0f});
- matrix = glm::rotate(matrix, (*rotation)->z, glm::vec3{0.0f, 0.0f, 1.0f});
- vec = matrix * vec;
-
- (*ptr)->x += vec.x;
- (*ptr)->y += vec.y;
- (*ptr)->z += vec.z;
+ &orientation, &cg_orientation_3d_type);
+
+ auto rotated_direction = **orientation * **direction;
+
+ **ptr += rotated_direction;
return self;
}