Extract yaw-pitch-roll processing into a function
This commit is contained in:
parent
5d36770a2e
commit
675d9f837d
34
src/main.rs
34
src/main.rs
|
|
@ -38,6 +38,23 @@ impl Image {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ypr_to_mat(ypr: Vec3) -> Mat3 {
|
||||||
|
let Vec3 { x: yaw, y: pitch, z: roll } = ypr;
|
||||||
|
let m_roll = mat3(
|
||||||
|
roll.cos(), roll.sin(), 0.0,
|
||||||
|
-roll.sin(), roll.cos(), 0.0,
|
||||||
|
0.0, 0.0, 1.0);
|
||||||
|
let m_yaw = mat3(
|
||||||
|
yaw.cos(), 0.0, yaw.sin(),
|
||||||
|
0.0, 1.0, 0.0,
|
||||||
|
-yaw.sin(), 0.0, yaw.cos());
|
||||||
|
let m_pitch = mat3(
|
||||||
|
1.0, 0.0, 0.0,
|
||||||
|
0.0, pitch.cos(), -pitch.sin(),
|
||||||
|
0.0, pitch.sin(), pitch.cos());
|
||||||
|
m_roll * m_pitch * m_yaw
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
let mesh = {
|
let mesh = {
|
||||||
|
|
@ -50,22 +67,7 @@ fn main() -> io::Result<()> {
|
||||||
h: H,
|
h: H,
|
||||||
data: vec![0; (3 * W * H) as usize],
|
data: vec![0; (3 * W * H) as usize],
|
||||||
};
|
};
|
||||||
let yaw = PI / 4.0;
|
let m_view = ypr_to_mat(vec3(135.0 * PI / 180.0, -30.0 * PI / 180.0, 0.0f32));
|
||||||
let pitch = PI / 6.0;
|
|
||||||
let roll = 0.0f32;
|
|
||||||
let m_roll = mat3(
|
|
||||||
roll.cos(), roll.sin(), 0.0,
|
|
||||||
-roll.sin(), roll.cos(), 0.0,
|
|
||||||
0.0, 0.0, 1.0);
|
|
||||||
let m_yaw = mat3(
|
|
||||||
-yaw.cos(), 0.0, yaw.sin(),
|
|
||||||
0.0, 1.0, 0.0,
|
|
||||||
-yaw.sin(), 0.0, -yaw.cos());
|
|
||||||
let m_pitch = mat3(
|
|
||||||
1.0, 0.0, 0.0,
|
|
||||||
0.0, pitch.cos(), pitch.sin(),
|
|
||||||
0.0, -pitch.sin(), pitch.cos());
|
|
||||||
let m_view = m_roll * m_pitch * m_yaw;
|
|
||||||
let m_camera = transpose(&m_view);
|
let m_camera = transpose(&m_view);
|
||||||
let img_size = vec2(W as f32, H as f32);
|
let img_size = vec2(W as f32, H as f32);
|
||||||
for y in 0..H {
|
for y in 0..H {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user