Struct fj_math::Transform

source ·
#[repr(C)]
pub struct Transform(_);
Expand description

An affine transform

Implementations§

Construct an identity transform

Construct a translation

Construct a rotation

The direction of the vector defines the rotation axis. Its length defines the angle of the rotation.

Transform the given point

Examples found in repository?
src/transform.rs (line 61)
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    pub fn transform_line(&self, line: &Line<3>) -> Line<3> {
        Line::from_origin_and_direction(
            self.transform_point(&line.origin()),
            self.transform_vector(&line.direction()),
        )
    }

    /// Transform the given segment
    pub fn transform_segment(&self, segment: &Segment<3>) -> Segment<3> {
        let [a, b] = &segment.points();
        Segment::from([self.transform_point(a), self.transform_point(b)])
    }

    /// Transform the given triangle
    pub fn transform_triangle(&self, triangle: &Triangle<3>) -> Triangle<3> {
        let [a, b, c] = &triangle.points();
        Triangle::from([
            self.transform_point(a),
            self.transform_point(b),
            self.transform_point(c),
        ])
    }

    /// Transform the given circle
    pub fn transform_circle(&self, circle: &Circle<3>) -> Circle<3> {
        Circle::new(
            self.transform_point(&circle.center()),
            self.transform_vector(&circle.a()),
            self.transform_vector(&circle.b()),
        )
    }

    /// Inverse transform
    pub fn inverse(&self) -> Self {
        Self(self.0.inverse())
    }

    /// Transpose transform
    pub fn transpose(&self) -> Self {
        Self(nalgebra::Transform::from_matrix_unchecked(
            self.0.to_homogeneous().transpose(),
        ))
    }

    /// Project transform according to camera specification, return data as an array.
    /// Used primarily for graphics code.
    pub fn project_to_array(
        &self,
        aspect_ratio: f64,
        fovy: f64,
        znear: f64,
        zfar: f64,
    ) -> [Scalar; 16] {
        let projection = Perspective3::new(aspect_ratio, fovy, znear, zfar);

        let mut array = [0.; 16];
        array.copy_from_slice(
            (projection.to_projective() * self.0).matrix().as_slice(),
        );

        array.map(Scalar::from)
    }

    /// Transform the given axis-aligned bounding box
    pub fn transform_aabb(&self, aabb: &Aabb<3>) -> Aabb<3> {
        Aabb {
            min: self.transform_point(&aabb.min),
            max: self.transform_point(&aabb.max),
        }
    }

Inverse transform given point

Transform the given vector

Examples found in repository?
src/transform.rs (line 62)
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
    pub fn transform_line(&self, line: &Line<3>) -> Line<3> {
        Line::from_origin_and_direction(
            self.transform_point(&line.origin()),
            self.transform_vector(&line.direction()),
        )
    }

    /// Transform the given segment
    pub fn transform_segment(&self, segment: &Segment<3>) -> Segment<3> {
        let [a, b] = &segment.points();
        Segment::from([self.transform_point(a), self.transform_point(b)])
    }

    /// Transform the given triangle
    pub fn transform_triangle(&self, triangle: &Triangle<3>) -> Triangle<3> {
        let [a, b, c] = &triangle.points();
        Triangle::from([
            self.transform_point(a),
            self.transform_point(b),
            self.transform_point(c),
        ])
    }

    /// Transform the given circle
    pub fn transform_circle(&self, circle: &Circle<3>) -> Circle<3> {
        Circle::new(
            self.transform_point(&circle.center()),
            self.transform_vector(&circle.a()),
            self.transform_vector(&circle.b()),
        )
    }

Transform the given line

Transform the given segment

Transform the given triangle

Transform the given circle

Inverse transform

Examples found in repository?
src/transform.rs (line 144)
143
144
145
    pub fn extract_translation(&self) -> Self {
        *self * self.extract_rotation().inverse()
    }

Transpose transform

Project transform according to camera specification, return data as an array. Used primarily for graphics code.

Transform the given axis-aligned bounding box

Exposes the data of this Transform as a slice of f64.

Extract the rotation component of this transform

Examples found in repository?
src/transform.rs (line 144)
143
144
145
    pub fn extract_translation(&self) -> Self {
        *self * self.extract_rotation().inverse()
    }

Extract the translation component of this transform

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.