Skip to content

Commit

Permalink
add text3d.get_axis_x, .set_axis_x, .get_axis_y, .set_axis_y
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Nov 15, 2024
1 parent 525cf1e commit a8388a6
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
6 changes: 3 additions & 3 deletions res/content/base/scripts/hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ function on_hud_open()
end)

note = gfx.text3d.new({0.5, 99.5, 0.0015}, "Segmentation fault", {
scale=0.005,
color={0, 0, 0, 1},
display="projected",
perspective=1.0,
scale=2.0
display="static_billboard",
xray_opacity=0.2
})
end

Expand Down
16 changes: 16 additions & 0 deletions src/graphics/render/TextNote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ void TextNote::setPosition(const glm::vec3& position) {
const glm::vec3& TextNote::getPosition() const {
return position;
}

const glm::vec3& TextNote::getAxisX() const {
return xAxis;
}

const glm::vec3& TextNote::getAxisY() const {
return yAxis;
}

void TextNote::setAxisX(const glm::vec3& vec) {
xAxis = vec;
}

void TextNote::setAxisY(const glm::vec3& vec) {
yAxis = vec;
}
10 changes: 9 additions & 1 deletion src/graphics/render/TextNote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class TextNote {
std::wstring text;
NotePreset preset;
glm::vec3 position;

glm::vec3 xAxis {1, 0, 0};
glm::vec3 yAxis {0, 1, 0};
public:
TextNote(std::wstring text, NotePreset preset, glm::vec3 position);

Expand All @@ -19,6 +22,11 @@ class TextNote {
void updatePreset(const dv::value& data);

void setPosition(const glm::vec3& position);

const glm::vec3& getPosition() const;

const glm::vec3& getAxisX() const;
const glm::vec3& getAxisY() const;

void setAxisX(const glm::vec3& vec);
void setAxisY(const glm::vec3& vec);
};
4 changes: 2 additions & 2 deletions src/graphics/render/TextsRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ void TextsRenderer::renderNote(
}
const auto& font = assets.require<Font>("normal");

glm::vec3 xvec {1, 0, 0};
glm::vec3 yvec {0, 1, 0};
glm::vec3 xvec = note.getAxisX();
glm::vec3 yvec = note.getAxisY();

int width = font.calcWidth(text, text.length());
if (preset.displayMode == NoteDisplayMode::Y_FREE_BILLBOARD ||
Expand Down
32 changes: 31 additions & 1 deletion src/logic/scripting/lua/libs/libtext3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,40 @@ static int l_get_pos(lua::State* L) {
}
return 0;
}

static int l_set_pos(lua::State* L) {
if (auto note = renderer->texts->get(lua::tointeger(L, 1))) {
note->setPosition(lua::tovec3(L, 2));
}
return 0;
}

static int l_get_axis_x(lua::State* L) {
if (auto note = renderer->texts->get(lua::tointeger(L, 1))) {
return lua::pushvec(L, note->getAxisX());
}
return 0;
}
static int l_set_axis_x(lua::State* L) {
if (auto note = renderer->texts->get(lua::tointeger(L, 1))) {
note->setAxisX(lua::tovec3(L, 2));
}
return 0;
}


static int l_get_axis_y(lua::State* L) {
if (auto note = renderer->texts->get(lua::tointeger(L, 1))) {
return lua::pushvec(L, note->getAxisY());
}
return 0;
}
static int l_set_axis_y(lua::State* L) {
if (auto note = renderer->texts->get(lua::tointeger(L, 1))) {
note->setAxisY(lua::tovec3(L, 2));
}
return 0;
}

static int l_update_settings(lua::State* L) {
if (auto note = renderer->texts->get(lua::tointeger(L, 1))) {
note->updatePreset(lua::tovalue(L, 2));
Expand All @@ -70,6 +96,10 @@ const luaL_Reg text3dlib[] = {
{"set_text", lua::wrap<l_set_text>},
{"get_pos", lua::wrap<l_get_pos>},
{"set_pos", lua::wrap<l_set_pos>},
{"get_axis_x", lua::wrap<l_get_axis_x>},
{"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>},
{"update_settings", lua::wrap<l_update_settings>},
{NULL, NULL}
};

0 comments on commit a8388a6

Please sign in to comment.