Access to vector operators

This commit is contained in:
Dane Johnson 2021-01-15 20:33:25 -06:00
parent 7651923ee8
commit 95ccf7af6b
6 changed files with 46 additions and 8 deletions

View File

@ -4,7 +4,7 @@ set -e
mkdir -p build
cd build
cmake ..
cmake .. -DCMAKE_BUILD_TYPE=Debug
make
cd ..

View File

@ -11,7 +11,7 @@ void Lua::Initialize() {
language = this;
int err;
// Initialize Lua
luaopen_base(L);
luaL_openlibs(L);
luaopen_couch(L);
err = luaL_loadfile(L, "main.lua");
if (err == LUA_OK) {

19
core/types.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "types.h"
#include <iostream>
Vector3 operator+(const Vector3 &r, const Vector3 &l) {
Vector3 val(0.0f);
val.x = r.x + l.x;
val.y = r.y + l.y;
val.z = r.z + l.z;
return val;
}
Vector3 operator*(const Vector3 &r, const cfloat &l) {
Vector3 val(0.0f);
val.x = r.x * l;
val.y = r.y * l;
val.z = r.z * l;
return val;
}

View File

@ -15,4 +15,7 @@ typedef std::string Name;
typedef GLfloat cfloat;
typedef GLuint Id;
Vector3 operator*(const Vector3 &r, const cfloat &l);
Vector3 operator+(const Vector3 &r, const Vector3 &l);
#endif /* TYPES_H */

View File

@ -1,3 +1,5 @@
local min = math.min
local max = math.max
local ball
local ball1
local camera
@ -16,6 +18,8 @@ local ballvy = -1.0
local cam_rot_x = 0.0
local cam_rot_y = 0.0
local SPEED = 30
function init()
camera = couch.Camera()
camera:MakeCurrent()
@ -32,12 +36,15 @@ end
function update(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)
local move_vec = couch.Vector3()
move_vec = camera.transform.position + cam_forwards * delta * vz * SPEED
camera.transform.position = move_vec
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
camera.transform.rotation.x = min(max(camera.transform.rotation.x, -3.14), 3.14)
cam_rot_y = 0.0
local loc = ball1.transform.position
@ -63,9 +70,9 @@ function onkey(key, code, action, mod)
end
if key == UP and action == 1 then
vz = -1.0
elseif key == DOWN and action == 1 then
vz = 1.0
elseif key == DOWN and action == 1 then
vz = -1.0
elseif (key == DOWN or key == UP) and action == 0 then
vz = 0.0
end

View File

@ -11,15 +11,24 @@
#include "Mesh.h"
#include "Ball.h"
#include "Camera.h"
%}
%}
typedef float cfloat;
%ignore "cfloat";
class Vector3 {
public:
Vector3();
cfloat x, y, z;
};
%extend Vector3 {
Vector3 operator+(const Vector3 &o) const {
return *$self + o;
}
Vector3 operator*(const cfloat &o) const {
return *$self * o;
}
}
%ignore "Vector3";
%include "types.h"