Access to vector operators
This commit is contained in:
parent
7651923ee8
commit
95ccf7af6b
@ -4,7 +4,7 @@ set -e
|
|||||||
|
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
cd build
|
cd build
|
||||||
cmake ..
|
cmake .. -DCMAKE_BUILD_TYPE=Debug
|
||||||
make
|
make
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ void Lua::Initialize() {
|
|||||||
language = this;
|
language = this;
|
||||||
int err;
|
int err;
|
||||||
// Initialize Lua
|
// Initialize Lua
|
||||||
luaopen_base(L);
|
luaL_openlibs(L);
|
||||||
luaopen_couch(L);
|
luaopen_couch(L);
|
||||||
err = luaL_loadfile(L, "main.lua");
|
err = luaL_loadfile(L, "main.lua");
|
||||||
if (err == LUA_OK) {
|
if (err == LUA_OK) {
|
||||||
|
19
core/types.cpp
Normal file
19
core/types.cpp
Normal 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;
|
||||||
|
}
|
@ -15,4 +15,7 @@ typedef std::string Name;
|
|||||||
typedef GLfloat cfloat;
|
typedef GLfloat cfloat;
|
||||||
typedef GLuint Id;
|
typedef GLuint Id;
|
||||||
|
|
||||||
|
Vector3 operator*(const Vector3 &r, const cfloat &l);
|
||||||
|
Vector3 operator+(const Vector3 &r, const Vector3 &l);
|
||||||
|
|
||||||
#endif /* TYPES_H */
|
#endif /* TYPES_H */
|
||||||
|
17
main.lua
17
main.lua
@ -1,3 +1,5 @@
|
|||||||
|
local min = math.min
|
||||||
|
local max = math.max
|
||||||
local ball
|
local ball
|
||||||
local ball1
|
local ball1
|
||||||
local camera
|
local camera
|
||||||
@ -16,6 +18,8 @@ local ballvy = -1.0
|
|||||||
local cam_rot_x = 0.0
|
local cam_rot_x = 0.0
|
||||||
local cam_rot_y = 0.0
|
local cam_rot_y = 0.0
|
||||||
|
|
||||||
|
local SPEED = 30
|
||||||
|
|
||||||
function init()
|
function init()
|
||||||
camera = couch.Camera()
|
camera = couch.Camera()
|
||||||
camera:MakeCurrent()
|
camera:MakeCurrent()
|
||||||
@ -32,12 +36,15 @@ end
|
|||||||
|
|
||||||
function update(delta)
|
function update(delta)
|
||||||
local cam_forwards = camera.transform:Forward()
|
local cam_forwards = camera.transform:Forward()
|
||||||
--local vec1 = couch.Vector3() + couch.Vector3()
|
|
||||||
--camera.transform.position = camera.transform.position + cam_forwards
|
local move_vec = couch.Vector3()
|
||||||
--camera.transform:Translate(vx * delta, 0.0, vz * delta)
|
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
|
camera.transform.rotation.y = camera.transform.rotation.y - cam_rot_x * delta
|
||||||
cam_rot_x = 0.0
|
cam_rot_x = 0.0
|
||||||
camera.transform.rotation.x = camera.transform.rotation.x - cam_rot_y * delta
|
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
|
cam_rot_y = 0.0
|
||||||
|
|
||||||
local loc = ball1.transform.position
|
local loc = ball1.transform.position
|
||||||
@ -63,9 +70,9 @@ function onkey(key, code, action, mod)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if key == UP and action == 1 then
|
if key == UP and action == 1 then
|
||||||
vz = -1.0
|
|
||||||
elseif key == DOWN and action == 1 then
|
|
||||||
vz = 1.0
|
vz = 1.0
|
||||||
|
elseif key == DOWN and action == 1 then
|
||||||
|
vz = -1.0
|
||||||
elseif (key == DOWN or key == UP) and action == 0 then
|
elseif (key == DOWN or key == UP) and action == 0 then
|
||||||
vz = 0.0
|
vz = 0.0
|
||||||
end
|
end
|
||||||
|
@ -11,15 +11,24 @@
|
|||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
#include "Ball.h"
|
#include "Ball.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
typedef float cfloat;
|
typedef float cfloat;
|
||||||
%ignore "cfloat";
|
%ignore "cfloat";
|
||||||
|
|
||||||
class Vector3 {
|
class Vector3 {
|
||||||
public:
|
public:
|
||||||
|
Vector3();
|
||||||
cfloat x, y, z;
|
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";
|
%ignore "Vector3";
|
||||||
|
|
||||||
%include "types.h"
|
%include "types.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user