From 04da2f5e69abed16c5047fb3a6fc669b9be1f59e Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 15 Nov 2024 04:29:52 +0300 Subject: [PATCH] add .set_rotation(mat4) --- res/content/base/scripts/hud.lua | 3 ++- res/scripts/hud_classes.lua | 1 + src/logic/scripting/lua/libs/libtext3d.cpp | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/res/content/base/scripts/hud.lua b/res/content/base/scripts/hud.lua index 67ca3587..12fc3d08 100644 --- a/res/content/base/scripts/hud.lua +++ b/res/content/base/scripts/hud.lua @@ -39,5 +39,6 @@ function on_hud_render() note:update_settings({ color={math.sin(time.uptime() * 12) * 0.5 + 0.5, 0, 0, 1} }) - note:set_axis_x({math.sin(time.uptime()), 0, math.cos(time.uptime())}) + -- note:set_axis_x({math.sin(time.uptime()), 0, math.cos(time.uptime())}) + note:set_rotation(mat4.rotate({1, 1, 0}, time.uptime() * 57)) end diff --git a/res/scripts/hud_classes.lua b/res/scripts/hud_classes.lua index 0e418a3e..dc373c6e 100644 --- a/res/scripts/hud_classes.lua +++ b/res/scripts/hud_classes.lua @@ -6,6 +6,7 @@ local Text3D = {__index={ set_axis_x=function(self, v) return gfx.text3d.set_axis_x(self.id, v) end, get_axis_y=function(self) return gfx.text3d.get_axis_y(self.id) end, set_axis_y=function(self, v) return gfx.text3d.set_axis_y(self.id, v) end, + set_rotation=function(self, m) return gfx.text3d.set_rotation(self.id, m) end, get_text=function(self) return gfx.text3d.get_text(self.id) end, set_text=function(self, s) return gfx.text3d.set_text(self.id, s) end, update_settings=function(self, t) return gfx.text3d.update_settings(self.id, t) end, diff --git a/src/logic/scripting/lua/libs/libtext3d.cpp b/src/logic/scripting/lua/libs/libtext3d.cpp index ccbb5977..433a959e 100644 --- a/src/logic/scripting/lua/libs/libtext3d.cpp +++ b/src/logic/scripting/lua/libs/libtext3d.cpp @@ -89,6 +89,15 @@ static int l_update_settings(lua::State* L) { return 0; } +static int l_set_rotation(lua::State* L) { + if (auto note = renderer->texts->get(lua::tointeger(L, 1))) { + auto matrix = lua::tomat4(L, 2); + note->setAxisX(matrix * glm::vec4(1, 0, 0, 1)); + note->setAxisY(matrix * glm::vec4(0, 1, 0, 1)); + } + return 0; +} + const luaL_Reg text3dlib[] = { {"show", lua::wrap}, {"hide", lua::wrap}, @@ -100,6 +109,7 @@ const luaL_Reg text3dlib[] = { {"set_axis_x", lua::wrap}, {"get_axis_y", lua::wrap}, {"set_axis_y", lua::wrap}, + {"set_rotation", lua::wrap}, {"update_settings", lua::wrap}, {NULL, NULL} };