pub struct AffineMatrix { /* private fields */ }
Expand description

An affine matrix stored in a way that is efficient for the GBA to perform operations on. This implements multiplication.

Implementations§

source§

impl AffineMatrix

source

pub fn identity() -> Self

The Identity matrix. The identity matrix can be thought of as 1 and is represented by I. For a matrix A, A ≡ A * I ≡ I * A.

source

pub fn from_rotation<const N: usize>(angle: Num<i32, N>) -> Self

Generates the matrix that represents a rotation

Examples found in repository?
examples/sprites.rs (line 29)
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
fn all_sprites(gfx: &OamManaged, rotation_speed: Num<i32, 16>) {
    let mut input = agb::input::ButtonController::new();
    let mut objs = Vec::new();

    let mut rotation: Num<i32, 16> = num!(0.);

    let rotation_matrix = AffineMatrix::from_rotation(rotation);
    let matrix = object::AffineMatrixInstance::new(rotation_matrix.to_object_wrapping());

    for y in 0..9 {
        for x in 0..14 {
            let mut obj = gfx.object_sprite(&SPRITES[0]);
            obj.set_affine_matrix(matrix.clone());
            obj.show_affine(object::AffineMode::Affine);
            obj.set_position((x * 16 + 8, y * 16 + 8).into());
            objs.push(obj);
        }
    }

    let mut count = 0;
    let mut image = 0;

    let vblank = agb::interrupt::VBlank::get();

    loop {
        vblank.wait_for_vblank();
        input.update();

        if input.is_just_pressed(agb::input::Button::A) {
            break;
        }

        rotation += rotation_speed;
        let rotation_matrix = AffineMatrix::from_rotation(rotation);

        let matrix = object::AffineMatrixInstance::new(rotation_matrix.to_object_wrapping());

        for obj in objs.iter_mut() {
            obj.set_affine_matrix(matrix.clone());
        }

        count += 1;

        if count % 5 == 0 {
            image += 1;
            image %= SPRITES.len();
            for (i, obj) in objs.iter_mut().enumerate() {
                let this_image = (image + i) % SPRITES.len();
                obj.set_sprite(gfx.sprite(&SPRITES[this_image]));
            }
        }
        gfx.commit();
    }
}
source

pub fn from_translation(position: Vector2D<Num<i32, 8>>) -> Self

Generates the matrix that represents a translation by the position

source

pub fn position(&self) -> Vector2D<Num<i32, 8>>

The position fields of the matrix

source

pub fn try_to_background(&self) -> Result<AffineMatrixBackground, OverflowError>

Attempts to convert the matrix to one which can be used in affine backgrounds.

source

pub fn to_background_wrapping(&self) -> AffineMatrixBackground

Converts the matrix to one which can be used in affine backgrounds wrapping any value which is too large to be represented there.

source

pub fn try_to_object(&self) -> Result<AffineMatrixObject, OverflowError>

Attempts to convert the matrix to one which can be used in affine objects.

source

pub fn to_object_wrapping(&self) -> AffineMatrixObject

Converts the matrix to one which can be used in affine objects wrapping any value which is too large to be represented there.

Examples found in repository?
examples/sprites.rs (line 30)
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
fn all_sprites(gfx: &OamManaged, rotation_speed: Num<i32, 16>) {
    let mut input = agb::input::ButtonController::new();
    let mut objs = Vec::new();

    let mut rotation: Num<i32, 16> = num!(0.);

    let rotation_matrix = AffineMatrix::from_rotation(rotation);
    let matrix = object::AffineMatrixInstance::new(rotation_matrix.to_object_wrapping());

    for y in 0..9 {
        for x in 0..14 {
            let mut obj = gfx.object_sprite(&SPRITES[0]);
            obj.set_affine_matrix(matrix.clone());
            obj.show_affine(object::AffineMode::Affine);
            obj.set_position((x * 16 + 8, y * 16 + 8).into());
            objs.push(obj);
        }
    }

    let mut count = 0;
    let mut image = 0;

    let vblank = agb::interrupt::VBlank::get();

    loop {
        vblank.wait_for_vblank();
        input.update();

        if input.is_just_pressed(agb::input::Button::A) {
            break;
        }

        rotation += rotation_speed;
        let rotation_matrix = AffineMatrix::from_rotation(rotation);

        let matrix = object::AffineMatrixInstance::new(rotation_matrix.to_object_wrapping());

        for obj in objs.iter_mut() {
            obj.set_affine_matrix(matrix.clone());
        }

        count += 1;

        if count % 5 == 0 {
            image += 1;
            image %= SPRITES.len();
            for (i, obj) in objs.iter_mut().enumerate() {
                let this_image = (image + i) % SPRITES.len();
                obj.set_sprite(gfx.sprite(&SPRITES[this_image]));
            }
        }
        gfx.commit();
    }
}
source

pub fn from_scale(scale: Vector2D<Num<i32, 8>>) -> AffineMatrix

Creates an affine matrix from a given (x, y) scaling. This will scale by the inverse, ie (2, 2) will produce half the size.

Trait Implementations§

source§

impl Clone for AffineMatrix

source§

fn clone(&self) -> AffineMatrix

Returns a copy of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
source§

impl Debug for AffineMatrix

source§

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

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

impl Default for AffineMatrix

source§

fn default() -> Self

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

impl From<AffineMatrixBackground> for AffineMatrix

source§

fn from(mat: AffineMatrixBackground) -> Self

Converts to this type from the input type.
source§

impl From<AffineMatrixObject> for AffineMatrix

source§

fn from(mat: AffineMatrixObject) -> Self

Converts to this type from the input type.
source§

impl Mul for AffineMatrix

§

type Output = AffineMatrix

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
source§

impl MulAssign for AffineMatrix

source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
source§

impl PartialEq for AffineMatrix

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<AffineMatrix> for AffineMatrixBackground

§

type Error = OverflowError

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

fn try_from(value: AffineMatrix) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<AffineMatrix> for AffineMatrixObject

§

type Error = OverflowError

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

fn try_from(value: AffineMatrix) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for AffineMatrix

source§

impl Eq for AffineMatrix

source§

impl StructuralEq for AffineMatrix

source§

impl StructuralPartialEq for AffineMatrix

Auto Trait Implementations§

§

impl RefUnwindSafe for AffineMatrix

§

impl Send for AffineMatrix

§

impl Sync for AffineMatrix

§

impl Unpin for AffineMatrix

§

impl UnwindSafe for AffineMatrix

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.