diff --git a/core/Transform.cpp b/core/Transform.cpp index d8fd740..8b2ca0d 100644 --- a/core/Transform.cpp +++ b/core/Transform.cpp @@ -13,3 +13,13 @@ Transform::Transform(Vector3 position, Vector3 rotation) { void Transform::Translate(cfloat x, cfloat y, cfloat z) { position = position + Vector3(x, y, z); } + + +Vector3 Transform::Forward() { + Vector3 forward(0.0f, 0.0f, -1.0f); + Matrix mat(1.0f); + mat = glm::rotate(mat, this->rotation.x, Vector3(1.0f, 0.0f, 0.0f)); + mat = glm::rotate(mat, this->rotation.y, Vector3(0.0f, 1.0f, 0.0f)); + mat = glm::rotate(mat, this->rotation.z, Vector3(0.0f, 0.0f, 1.0f)); + return mat * glm::vec4(forward, 1.0f); +} diff --git a/core/Transform.h b/core/Transform.h index 1eb3e39..03a1407 100644 --- a/core/Transform.h +++ b/core/Transform.h @@ -1,6 +1,8 @@ #ifndef TRANSFORM_H #define TRANSFORM_H +#include + #include "types.h" struct Transform { @@ -9,6 +11,7 @@ struct Transform { Vector3 position; Vector3 rotation; void Translate(cfloat x, cfloat y, cfloat z); + Vector3 Forward(); }; #endif /* TRANSFORM_H */ diff --git a/main.lua b/main.lua index c39c9b7..c584541 100644 --- a/main.lua +++ b/main.lua @@ -31,7 +31,10 @@ function init() end function update(delta) - camera.transform:Translate(vx * delta, 0.0, vz * delta) + local cam_forwards = camera.transform:Forward() + --local vec1 = couch.Vector3() + couch.Vector3() + --camera.transform.position = camera.transform.position + cam_forwards + --camera.transform:Translate(vx * delta, 0.0, vz * delta) camera.transform.rotation.y = camera.transform.rotation.y - cam_rot_x * delta cam_rot_x = 0.0 camera.transform.rotation.x = camera.transform.rotation.x - cam_rot_y * delta diff --git a/scripting/.dir-locals.el b/scripting/.dir-locals.el new file mode 100644 index 0000000..10c00c3 --- /dev/null +++ b/scripting/.dir-locals.el @@ -0,0 +1,4 @@ +;;; Directory Local Variables +;;; For more information see (info "(emacs) Directory Variables") + +((c-mode . ((mode . c++)))) diff --git a/scripting/couch.i b/scripting/couch.i index 372790e..52884a1 100644 --- a/scripting/couch.i +++ b/scripting/couch.i @@ -1,9 +1,9 @@ %module couch -%typemap(in) cfloat { - $1 = (cfloat) lua_tonumber(L, $input); - } +%include "typemaps.i" + %{ +#include "types.h" #include "Node.h" #include "Transform.h" #include "Spatial.h" @@ -11,11 +11,18 @@ #include "Mesh.h" #include "Ball.h" #include "Camera.h" -%} + %} + typedef float cfloat; -struct Vector3 { +%ignore "cfloat"; + +class Vector3 { +public: cfloat x, y, z; }; +%ignore "Vector3"; + +%include "types.h" %include "Node.h" %include "Spatial.h" %include "Transform.h" @@ -23,3 +30,4 @@ struct Vector3 { %include "Mesh.h" %include "Ball.h" %include "Camera.h" +