Add sample rendering #2

Merged
noteuclid merged 7 commits from sample into master 2026-10-25 12:48:40 +03:00
3 changed files with 9 additions and 9 deletions
Showing only changes of commit 344a604877 - Show all commits

View File

@ -9,11 +9,11 @@ pub(crate) fn rotation(yaw: f32, pitch: f32) -> Mat3 {
}
pub(crate) fn view(yaw: f32, pitch: f32, distance: f32) -> Affine3A {
Affine3A::from_mat3_translation(rotation(yaw, pitch), vec3(0., 0., distance))
Affine3A::from_mat3_translation(rotation(-yaw, -pitch), vec3(0., 0., -distance))
}
pub(crate) fn projection(fovy: f32, aspect: f32) -> Mat4 {
Mat4::perspective_lh(fovy, aspect, 0.1, 10.0)
Mat4::perspective_rh(fovy, aspect, 0.1, 10.0)
}
#[cfg(test)]
@ -50,10 +50,10 @@ mod tests {
fn test_view() {
let mut ok = true;
for (yaw, pitch, x1, y1, z1) in [
(0.0, 0.0, [0., 0., 2.], [-1., 0., 3.], [0., 1., 3.]),
(0.5, 0.0, [1., 0., 3.], [0., 0., 2.], [0., 1., 3.]),
(0.0, 0.5, [0., -1., 3.], [-1., 0., 3.], [0., 0., 2.]),
(0.5, 0.5, [1., 0., 3.], [0., -1., 3.], [0., 0., 2.]),
(0.0, 0.0, [0., 0., -4.], [-1., 0., -3.], [0., 1., -3.]),
(0.5, 0.0, [-1., 0., -3.], [0., 0., -2.], [0., 1., -3.]),
(0.0, 0.5, [0., 1., -3.], [-1., 0., -3.], [0., 0., -2.]),
(0.5, 0.5, [-1., 0., -3.], [0., -1., -3.], [0., 0., -2.]),
] {
let m = view(yaw * PI, pitch * PI, 3.);
for (label, world, expected) in

View File

@ -19,7 +19,7 @@ impl Default for RedrawArgs {
fn default() -> Self {
Self {
background: vec4(0.25, 0.49, 0.93, 1.00),
cam_yaw: std::f32::consts::FRAC_PI_4,
cam_yaw: 3. * std::f32::consts::FRAC_PI_4,
cam_pitch: std::f32::consts::FRAC_PI_6,
cam_distance: 3.,
cam_fovy: std::f32::consts::FRAC_PI_2,
@ -56,7 +56,7 @@ fn cube(a: f32, b: f32) -> render::mesh::CpuMeshIndexed {
] {
for m in [1., -1.] {
let base = mesh.vertices.len() as u16;
for offset in [m * v + u, -m * v + u, -m * v - u, m * v - u] {
for offset in [m * v + u, m * v - u, -m * v - u, -m * v + u] {
let vertex = render::mesh::Vertex {
position: (m * w + offset),
color: gray + color_level * m * w,

View File

@ -71,7 +71,7 @@
<double>5.000000000000000</double>
</property>
<property name="value">
<double>45.000000000000000</double>
<double>135.000000000000000</double>
</property>
</widget>
</item>