feat: add camera-facing billboard quad rendering with rotation invariance

This commit is contained in:
2025-09-18 10:47:02 +02:00
parent e3509a7ece
commit 74342b5d1a

View File

@@ -220,6 +220,24 @@ fn main() {
let my_vao = unsafe { create_vao(&vertices, &colors, &indices) };
let billboard_vertices = vec![
-0.5, -0.5, 0.0,
-0.5, 0.5, 0.0,
0.5, 0.5, 0.0,
0.5, -0.5, 0.0,
];
let billboard_indices = vec![
0, 1, 2,
0, 2, 3,
];
let billboard_colors = vec![
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
];
let billboard_vao = unsafe { create_vao(&billboard_vertices, &billboard_colors, &billboard_indices) };
// == // Set up your shaders here
// Basic usage of shader helper:
@@ -356,6 +374,21 @@ fn main() {
gl::UNSIGNED_INT,
std::ptr::null(),
);
// Draw billboard (camera-facing quad)
let translation_bill = glm::translation(&glm::vec3(0.0, 0.0, -2.0));
let inv_rot_y = glm::rotation(cam_yaw, &glm::vec3(0.0, 1.0, 0.0));
let inv_rot_x = glm::rotation(cam_pitch, &glm::vec3(1.0, 0.0, 0.0));
let model_billboard = translation_bill * inv_rot_y * inv_rot_x;
let transform_bill = projection * view * model_billboard;
gl::UniformMatrix4fv(transform_loc, 1, gl::FALSE, transform_bill.as_ptr());
gl::BindVertexArray(billboard_vao);
gl::DrawElements(
gl::TRIANGLES,
billboard_indices.len() as i32,
gl::UNSIGNED_INT,
std::ptr::null(),
);
}
// Display the new color buffer on the display