summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFrederico Linhares <fred@linhares.blue>2022-10-07 10:15:11 -0300
committerFrederico Linhares <fred@linhares.blue>2022-10-07 10:15:11 -0300
commit63d7d305da643ec20fed3cdd60c4daec29272c41 (patch)
tree048ed0a0f976b4b53d75493bf4d4fa368ced4f87 /src
parent942a710653f69e6569ad09b5a9962f966b9425ad (diff)
feat Add new getters and setters to Vector3D
Diffstat (limited to 'src')
-rw-r--r--src/vector_3d.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/src/vector_3d.cpp b/src/vector_3d.cpp
index 6417a18..c0a9a3e 100644
--- a/src/vector_3d.cpp
+++ b/src/vector_3d.cpp
@@ -20,6 +20,8 @@
#include <glm/vec3.hpp>
+#include <mruby/array.h>
+
#include "rotation_3d.hpp"
void
@@ -81,6 +83,59 @@ cg_cVector3D_get_z(mrb_state *mrb, mrb_value self)
return mrb_float_value(mrb, (*ptr)->z);
}
+mrb_value
+cg_cVector3D_get_xy(mrb_state *mrb, mrb_value self)
+{
+ std::shared_ptr<glm::vec3> *ptr =
+ (std::shared_ptr<glm::vec3>*)DATA_PTR(self);
+
+ mrb_value array = mrb_ary_new_capa(mrb, 2);
+ mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->x));
+ mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->y));
+
+ return array;
+}
+
+mrb_value
+cg_cVector3D_get_xz(mrb_state *mrb, mrb_value self)
+{
+ std::shared_ptr<glm::vec3> *ptr =
+ (std::shared_ptr<glm::vec3>*)DATA_PTR(self);
+
+ mrb_value array = mrb_ary_new_capa(mrb, 2);
+ mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->x));
+ mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->z));
+
+ return array;
+}
+
+mrb_value
+cg_cVector3D_get_yz(mrb_state *mrb, mrb_value self)
+{
+ std::shared_ptr<glm::vec3> *ptr =
+ (std::shared_ptr<glm::vec3>*)DATA_PTR(self);
+
+ mrb_value array = mrb_ary_new_capa(mrb, 2);
+ mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->y));
+ mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->z));
+
+ return array;
+}
+
+mrb_value
+cg_cVector3D_get_xyz(mrb_state *mrb, mrb_value self)
+{
+ std::shared_ptr<glm::vec3> *ptr =
+ (std::shared_ptr<glm::vec3>*)DATA_PTR(self);
+
+ mrb_value array = mrb_ary_new_capa(mrb, 3);
+ mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->x));
+ mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->y));
+ mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->z));
+
+ return array;
+}
+
static mrb_value
cg_cVector3D_set_x(mrb_state *mrb, mrb_value self)
{
@@ -121,6 +176,63 @@ cg_cVector3D_set_z(mrb_state *mrb, mrb_value self)
}
static mrb_value
+cg_cVector3D_set_xy(mrb_state *mrb, mrb_value self)
+{
+ mrb_float x, y;
+ std::shared_ptr<glm::vec3> *ptr =
+ (std::shared_ptr<glm::vec3>*)DATA_PTR(self);
+
+ mrb_get_args(mrb, "ff", &x, &y);
+ (*ptr)->x = x;
+ (*ptr)->y = y;
+
+ return self;
+}
+
+static mrb_value
+cg_cVector3D_set_xz(mrb_state *mrb, mrb_value self)
+{
+ mrb_float x, z;
+ std::shared_ptr<glm::vec3> *ptr =
+ (std::shared_ptr<glm::vec3>*)DATA_PTR(self);
+
+ mrb_get_args(mrb, "ff", &x, &z);
+ (*ptr)->x = x;
+ (*ptr)->z = z;
+
+ return self;
+}
+
+static mrb_value
+cg_cVector3D_set_yz(mrb_state *mrb, mrb_value self)
+{
+ mrb_float y, z;
+ std::shared_ptr<glm::vec3> *ptr =
+ (std::shared_ptr<glm::vec3>*)DATA_PTR(self);
+
+ mrb_get_args(mrb, "ff", &y, &z);
+ (*ptr)->y = y;
+ (*ptr)->z = z;
+
+ return self;
+}
+
+static mrb_value
+cg_cVector3D_set_xyz(mrb_state *mrb, mrb_value self)
+{
+ mrb_float x, y, z;
+ std::shared_ptr<glm::vec3> *ptr =
+ (std::shared_ptr<glm::vec3>*)DATA_PTR(self);
+
+ mrb_get_args(mrb, "fff", &x, &y, &z);
+ (*ptr)->x = x;
+ (*ptr)->y = y;
+ (*ptr)->z = z;
+
+ return self;
+}
+
+static mrb_value
cg_cVector3D_translate(mrb_state *mrb, mrb_value self)
{
std::shared_ptr<glm::vec3> *ptr =
@@ -166,6 +278,16 @@ cg_vector_3d_init(mrb_state *mrb)
mrb, cg_cVector3D, "z", cg_cVector3D_get_z, MRB_ARGS_NONE());
mrb_define_method(
+ mrb, cg_cVector3D, "xy", cg_cVector3D_get_xy, MRB_ARGS_NONE());
+ mrb_define_method(
+ mrb, cg_cVector3D, "xz", cg_cVector3D_get_xz, MRB_ARGS_NONE());
+ mrb_define_method(
+ mrb, cg_cVector3D, "yz", cg_cVector3D_get_yz, MRB_ARGS_NONE());
+
+ mrb_define_method(
+ mrb, cg_cVector3D, "xyz", cg_cVector3D_get_xyz, MRB_ARGS_NONE());
+
+ mrb_define_method(
mrb, cg_cVector3D, "x=", cg_cVector3D_set_x, MRB_ARGS_REQ(1));
mrb_define_method(
mrb, cg_cVector3D, "y=", cg_cVector3D_set_y, MRB_ARGS_REQ(1));
@@ -173,5 +295,15 @@ cg_vector_3d_init(mrb_state *mrb)
mrb, cg_cVector3D, "z=", cg_cVector3D_set_z, MRB_ARGS_REQ(1));
mrb_define_method(
+ mrb, cg_cVector3D, "set_xy", cg_cVector3D_set_xy, MRB_ARGS_REQ(2));
+ mrb_define_method(
+ mrb, cg_cVector3D, "set_xz", cg_cVector3D_set_xz, MRB_ARGS_REQ(2));
+ mrb_define_method(
+ mrb, cg_cVector3D, "set_yz", cg_cVector3D_set_yz, MRB_ARGS_REQ(2));
+
+ mrb_define_method(
+ mrb, cg_cVector3D, "set_xyz", cg_cVector3D_set_xyz, MRB_ARGS_REQ(3));
+
+ mrb_define_method(
mrb, cg_cVector3D, "translate", cg_cVector3D_translate, MRB_ARGS_REQ(2));
}