Add sample rendering #2
|
|
@ -9,11 +9,11 @@ pub(crate) fn rotation(yaw: f32, pitch: f32) -> Mat3 {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn view(yaw: f32, pitch: f32, distance: f32) -> Affine3A {
|
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 {
|
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)]
|
#[cfg(test)]
|
||||||
|
|
@ -50,10 +50,10 @@ mod tests {
|
||||||
fn test_view() {
|
fn test_view() {
|
||||||
let mut ok = true;
|
let mut ok = true;
|
||||||
for (yaw, pitch, x1, y1, z1) in [
|
for (yaw, pitch, x1, y1, z1) in [
|
||||||
(0.0, 0.0, [0., 0., 2.], [-1., 0., 3.], [0., 1., 3.]),
|
(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.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.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.5, 0.5, [-1., 0., -3.], [0., -1., -3.], [0., 0., -2.]),
|
||||||
] {
|
] {
|
||||||
let m = view(yaw * PI, pitch * PI, 3.);
|
let m = view(yaw * PI, pitch * PI, 3.);
|
||||||
for (label, world, expected) in
|
for (label, world, expected) in
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ impl Default for RedrawArgs {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
background: vec4(0.25, 0.49, 0.93, 1.00),
|
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_pitch: std::f32::consts::FRAC_PI_6,
|
||||||
cam_distance: 3.,
|
cam_distance: 3.,
|
||||||
cam_fovy: std::f32::consts::FRAC_PI_2,
|
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.] {
|
for m in [1., -1.] {
|
||||||
let base = mesh.vertices.len() as u16;
|
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 {
|
let vertex = render::mesh::Vertex {
|
||||||
position: (m * w + offset),
|
position: (m * w + offset),
|
||||||
color: gray + color_level * m * w,
|
color: gray + color_level * m * w,
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@
|
||||||
<double>5.000000000000000</double>
|
<double>5.000000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<double>45.000000000000000</double>
|
<double>135.000000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user