Skip to main content

Turtle3d

Struct Turtle3d 

Source
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

Source

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 about U, turning H toward and away from L;
  • & and ^ pitch about L, turning H away from and toward U;
  • \ and / roll about H, turning L toward and away from U;
  • | yaws half a turn.
Source

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.

Source

pub fn step(&mut self)

One step along H.

Trait Implementations§

Source§

impl Clone for Turtle3d

Source§

fn clone(&self) -> Turtle3d

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Turtle3d

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Turtle3d

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Turtle3d

Source§

fn eq(&self, other: &Turtle3d) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Turtle3d

Source§

impl StructuralPartialEq for Turtle3d

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,