Somewhat improved wrapping

This commit is contained in:
Dane Johnson 2021-01-15 17:51:19 -06:00
parent 2a12a1f119
commit 7651923ee8
5 changed files with 34 additions and 6 deletions

View File

@ -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);
}

View File

@ -1,6 +1,8 @@
#ifndef TRANSFORM_H
#define TRANSFORM_H
#include <glm/gtc/matrix_transform.hpp>
#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 */

View File

@ -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

4
scripting/.dir-locals.el Normal file
View File

@ -0,0 +1,4 @@
;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")
((c-mode . ((mode . c++))))

View File

@ -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"