Skip to content

Commit

Permalink
add 'perspective' NotePreset property
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Nov 14, 2024
1 parent 2147f50 commit 525cf1e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion res/content/base/scripts/hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ function on_hud_open()

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

Expand Down
16 changes: 14 additions & 2 deletions src/graphics/render/TextsRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,24 @@ void TextsRenderer::renderNote(
return;
}
} else {
float scale = 1.0f;
if (glm::abs(preset.perspective) > 0.0001f) {
float scale2 = scale /
(glm::distance(camera.position, pos) *
util::sqr(camera.zoom) *
glm::sqrt(glm::tan(camera.getFov() * 0.5f)));
scale = scale2 * preset.perspective +
scale * (1.0f - preset.perspective);
}
auto projpos = camera.getProjView() * glm::vec4(pos, 1.0f);
pos = projpos;
if (pos.z < 0.0f) {
return;
}
pos /= pos.z;
pos.z = 0;
xvec = {2.0f/Window::width, 0, 0};
yvec = {0, 2.0f/Window::height, 0};
xvec = {2.0f/Window::width*scale, 0, 0};
yvec = {0, 2.0f/Window::height*scale, 0};
}
auto color = preset.color;
batch.setColor(glm::vec4(color.r, color.g, color.b, color.a * opacity));
Expand Down
2 changes: 2 additions & 0 deletions src/presets/NotePreset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dv::value NotePreset::serialize() const {
{"scale", scale},
{"render_distance", renderDistance},
{"xray_opacity", xrayOpacity},
{"perspective", perspective},
});
}

Expand All @@ -49,4 +50,5 @@ void NotePreset::deserialize(const dv::value& src) {
src.at("scale").get(scale);
src.at("render_distance").get(renderDistance);
src.at("xray_opacity").get(xrayOpacity);
src.at("perspective").get(perspective);
}
1 change: 1 addition & 0 deletions src/presets/NotePreset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct NotePreset : public Serializable {
float scale = 1.0f;
float renderDistance = 10.0f;
float xrayOpacity = 0.0f;
float perspective = 0.0f;

dv::value serialize() const override;
void deserialize(const dv::value& src) override;
Expand Down
4 changes: 4 additions & 0 deletions src/window/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ void Camera::setFov(float fov) {
float Camera::getFov() const {
return fov;
}

float Camera::getAspectRatio() const {
return aspect;
}
2 changes: 2 additions & 0 deletions src/window/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ class Camera {

void setFov(float fov);
float getFov() const;

float getAspectRatio() const;
};

0 comments on commit 525cf1e

Please sign in to comment.