add 'perspective' NotePreset property

This commit is contained in:
MihailRis 2024-11-15 02:21:05 +03:00
parent 2147f507a6
commit 525cf1ed4b
6 changed files with 26 additions and 3 deletions

View File

@ -29,7 +29,9 @@ function on_hud_open()
note = gfx.text3d.new({0.5, 99.5, 0.0015}, "Segmentation fault", { note = gfx.text3d.new({0.5, 99.5, 0.0015}, "Segmentation fault", {
color={0, 0, 0, 1}, color={0, 0, 0, 1},
display="projected" display="projected",
perspective=1.0,
scale=2.0
}) })
end end

View File

@ -68,12 +68,24 @@ void TextsRenderer::renderNote(
return; return;
} }
} else { } 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); auto projpos = camera.getProjView() * glm::vec4(pos, 1.0f);
pos = projpos; pos = projpos;
if (pos.z < 0.0f) {
return;
}
pos /= pos.z; pos /= pos.z;
pos.z = 0; pos.z = 0;
xvec = {2.0f/Window::width, 0, 0}; xvec = {2.0f/Window::width*scale, 0, 0};
yvec = {0, 2.0f/Window::height, 0}; yvec = {0, 2.0f/Window::height*scale, 0};
} }
auto color = preset.color; auto color = preset.color;
batch.setColor(glm::vec4(color.r, color.g, color.b, color.a * opacity)); batch.setColor(glm::vec4(color.r, color.g, color.b, color.a * opacity));

View File

@ -36,6 +36,7 @@ dv::value NotePreset::serialize() const {
{"scale", scale}, {"scale", scale},
{"render_distance", renderDistance}, {"render_distance", renderDistance},
{"xray_opacity", xrayOpacity}, {"xray_opacity", xrayOpacity},
{"perspective", perspective},
}); });
} }
@ -49,4 +50,5 @@ void NotePreset::deserialize(const dv::value& src) {
src.at("scale").get(scale); src.at("scale").get(scale);
src.at("render_distance").get(renderDistance); src.at("render_distance").get(renderDistance);
src.at("xray_opacity").get(xrayOpacity); src.at("xray_opacity").get(xrayOpacity);
src.at("perspective").get(perspective);
} }

View File

@ -22,6 +22,7 @@ struct NotePreset : public Serializable {
float scale = 1.0f; float scale = 1.0f;
float renderDistance = 10.0f; float renderDistance = 10.0f;
float xrayOpacity = 0.0f; float xrayOpacity = 0.0f;
float perspective = 0.0f;
dv::value serialize() const override; dv::value serialize() const override;
void deserialize(const dv::value& src) override; void deserialize(const dv::value& src) override;

View File

@ -66,3 +66,7 @@ void Camera::setFov(float fov) {
float Camera::getFov() const { float Camera::getFov() const {
return fov; return fov;
} }
float Camera::getAspectRatio() const {
return aspect;
}

View File

@ -35,4 +35,6 @@ public:
void setFov(float fov); void setFov(float fov);
float getFov() const; float getFov() const;
float getAspectRatio() const;
}; };