More quality of life
This commit is contained in:
parent
fdeff15bd6
commit
3eaca9903b
@ -52,7 +52,10 @@ void Lua::Update(double delta) {
|
||||
if (HasHook("update")) {
|
||||
lua_getglobal(L, "update");
|
||||
lua_pushnumber(L, delta);
|
||||
lua_call(L, 1, 0);
|
||||
int err = lua_pcall(L, 1, 0, 0);
|
||||
if (err != LUA_OK) {
|
||||
Error();
|
||||
}
|
||||
}
|
||||
#endif // LUA_SCRIPTING
|
||||
}
|
||||
@ -89,7 +92,10 @@ void Lua::LuaKeyHandler(Window *window, int key, int code, int action, int mods)
|
||||
lua_pushinteger(L, code);
|
||||
lua_pushinteger(L, action);
|
||||
lua_pushinteger(L, mods);
|
||||
lua_call(L, 4, 0);
|
||||
int err = lua_pcall(L, 4, 0, 0);
|
||||
if (err != LUA_OK) {
|
||||
Error();
|
||||
}
|
||||
#endif // LUA_SCRIPTING
|
||||
}
|
||||
|
||||
@ -101,6 +107,9 @@ void Lua::LuaMousePositionHandler(Window *window, double xpos, double ypos, doub
|
||||
lua_pushnumber(L, ypos);
|
||||
lua_pushnumber(L, relx);
|
||||
lua_pushnumber(L, rely);
|
||||
lua_call(L, 4, 0);
|
||||
int err = lua_pcall(L, 4, 0, 1);
|
||||
if (err != LUA_OK) {
|
||||
Error();
|
||||
}
|
||||
#endif // LUA_SCRIPTING
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
void Initialize();
|
||||
void Update(double delta);
|
||||
void Close();
|
||||
void Error();
|
||||
static void Error();
|
||||
bool HasHook(const char *name);
|
||||
private:
|
||||
#ifdef LUA_SCRIPTING
|
||||
|
@ -8,7 +8,6 @@ public:
|
||||
virtual void Initialize() = 0;
|
||||
virtual void Update(double delta) = 0;
|
||||
virtual void Close() = 0;
|
||||
virtual void Error() = 0;
|
||||
virtual bool HasHook(const char * name) = 0;
|
||||
static ScriptingLanguage *GetCurrentLanguage();
|
||||
protected:
|
||||
|
@ -24,14 +24,24 @@ void Transform::Translate(cfloat x, cfloat y, cfloat z) {
|
||||
}
|
||||
|
||||
|
||||
Vector3 Transform::Forward() {
|
||||
Vector3 forward(0.0f, 0.0f, -1.0f);
|
||||
Matrix Transform::RotationMatrix() {
|
||||
Matrix mat(1.0f);
|
||||
|
||||
mat = glm::rotate(mat, this->rotation.z, Vector3(0.0f, 0.0f, 1.0f));
|
||||
mat = glm::rotate(mat, this->rotation.y, Vector3(0.0f, 1.0f, 0.0f));
|
||||
mat = glm::rotate(mat, this->rotation.x, Vector3(1.0f, 0.0f, 0.0f));
|
||||
|
||||
|
||||
return glm::vec3(mat * glm::vec4(forward, 1.0f));
|
||||
return mat;
|
||||
}
|
||||
|
||||
Vector3 Transform::Forward() {
|
||||
return glm::vec3(RotationMatrix() * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f));
|
||||
}
|
||||
|
||||
Vector3 Transform::Up() {
|
||||
return glm::vec3(RotationMatrix() * glm::vec4(0.0f, 1.0f, 0.0f, 1.0f));
|
||||
}
|
||||
|
||||
Vector3 Transform::Right() {
|
||||
return glm::vec3(RotationMatrix() * glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ struct Transform {
|
||||
Vector3 scale;
|
||||
void Translate(cfloat x, cfloat y, cfloat z);
|
||||
Vector3 Forward();
|
||||
Vector3 Right();
|
||||
Vector3 Up();
|
||||
Matrix RotationMatrix();
|
||||
};
|
||||
|
||||
#endif /* TRANSFORM_H */
|
||||
|
@ -61,12 +61,11 @@ end
|
||||
|
||||
function update(delta)
|
||||
local cam_forwards = camera.transform:Forward()
|
||||
local cam_rotation = camera.transform.rotation
|
||||
print (cam_forwards.x, cam_forwards.y, cam_forwards.z)
|
||||
print (cam_rotation.x, cam_rotation.y, cam_rotation.z)
|
||||
|
||||
local cam_right = camera.transform:Right()
|
||||
|
||||
local move_vec = couch.Vector3()
|
||||
move_vec = camera.transform.position + cam_forwards * delta * vz * SPEED
|
||||
move_vec = move_vec + cam_right * delta * vx * SPEED
|
||||
camera.transform.position = move_vec
|
||||
|
||||
camera.transform.rotation.y = camera.transform.rotation.y - cam_rot_x * delta
|
||||
@ -94,6 +93,14 @@ function onkey(key, code, action, mod)
|
||||
elseif (key == couch.KEY_W or key == couch.KEY_S) and action == couch.ACTION_RELEASE then
|
||||
vz = 0.0
|
||||
end
|
||||
|
||||
if key == couch.KEY_A and action == couch.ACTION_PRESS then
|
||||
vx = -1.0
|
||||
elseif key == couch.KEY_D and action == couch.ACTION_PRESS then
|
||||
vx = 1.0
|
||||
elseif (key == couch.KEY_D or key == couch.KEY_A) and action == couch.ACTION_RELEASE then
|
||||
vx = 0.0
|
||||
end
|
||||
end
|
||||
|
||||
function onmousemotion(_, _, relx, rely)
|
||||
|
Loading…
Reference in New Issue
Block a user