pub struct Turtle3d {
pub pos: [f32; 3],
pub heading: [f32; 3],
pub left: [f32; 3],
pub up: [f32; 3],
}Expand description
The space turtle’s state: a position and an orientation frame of three unit
vectors, heading H, left L and up U, with U = H x L.
It starts at the origin heading world +y with left -x and up +z, so a
grammar that only yaws draws in the xy plane facing a camera at yaw 0,
and turns the same way round as the flat turtle does.
Fields§
§pos: [f32; 3]Where the pen is.
heading: [f32; 3]H: the direction a step moves.
left: [f32; 3]L: the direction a + turns toward.
up: [f32; 3]U: H x L.
Implementations§
Source§impl Turtle3d
impl Turtle3d
Sourcepub fn turn(&mut self, ch: char, angle: f32) -> bool
pub fn turn(&mut self, ch: char, angle: f32) -> bool
Apply one turn symbol by angle radians, and say whether ch was one.
+and-yaw aboutU, turningHtoward and away fromL;&and^pitch aboutL, turningHaway from and towardU;\and/roll aboutH, turningLtoward and away fromU;|yaws half a turn.
Sourcepub fn orthonormalize(&mut self)
pub fn orthonormalize(&mut self)
Pull the frame back onto an orthonormal one, by Gram-Schmidt in the
order H, L, then U = H x L.
Each turn is a rotation in exact arithmetic, but in f32 it leaves the
three vectors a few ulps off unit length and off square, and the error
compounds: an unbounded walk would shear and grow its steps. Restoring
after every turn holds the error to one turn’s worth. H is kept as
turned, so a step goes exactly where the turn pointed it.