Skip to content

Commit

Permalink
add .set_rotation(mat4)
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Nov 15, 2024
1 parent a7404c2 commit 04da2f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion res/content/base/scripts/hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions res/scripts/hud_classes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions src/logic/scripting/lua/libs/libtext3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<l_show>},
{"hide", lua::wrap<l_hide>},
Expand All @@ -100,6 +109,7 @@ const luaL_Reg text3dlib[] = {
{"set_axis_x", lua::wrap<l_set_axis_x>},
{"get_axis_y", lua::wrap<l_get_axis_y>},
{"set_axis_y", lua::wrap<l_set_axis_y>},
{"set_rotation", lua::wrap<l_set_rotation>},
{"update_settings", lua::wrap<l_update_settings>},
{NULL, NULL}
};

0 comments on commit 04da2f5

Please sign in to comment.