More quality of life

This commit is contained in:
Dane Johnson
2021-01-21 11:12:45 -06:00
parent 6f03ed7295
commit 43996eb2e6
6 changed files with 41 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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

View File

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