Struct agb::display::affine::AffineMatrix
source · 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
impl AffineMatrix
sourcepub fn identity() -> Self
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
.
sourcepub fn from_rotation<const N: usize>(angle: Num<i32, N>) -> Self
pub fn from_rotation<const N: usize>(angle: Num<i32, N>) -> Self
Generates the matrix that represents a rotation
Examples found in repository?
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();
}
}
sourcepub fn from_translation(position: Vector2D<Num<i32, 8>>) -> Self
pub fn from_translation(position: Vector2D<Num<i32, 8>>) -> Self
Generates the matrix that represents a translation by the position
sourcepub fn try_to_background(&self) -> Result<AffineMatrixBackground, OverflowError>
pub fn try_to_background(&self) -> Result<AffineMatrixBackground, OverflowError>
Attempts to convert the matrix to one which can be used in affine backgrounds.
sourcepub fn to_background_wrapping(&self) -> AffineMatrixBackground
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.
sourcepub fn try_to_object(&self) -> Result<AffineMatrixObject, OverflowError>
pub fn try_to_object(&self) -> Result<AffineMatrixObject, OverflowError>
Attempts to convert the matrix to one which can be used in affine objects.
sourcepub fn to_object_wrapping(&self) -> AffineMatrixObject
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?
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();
}
}
sourcepub fn from_scale(scale: Vector2D<Num<i32, 8>>) -> AffineMatrix
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
impl Clone for AffineMatrix
source§fn clone(&self) -> AffineMatrix
fn clone(&self) -> AffineMatrix
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for AffineMatrix
impl Debug for AffineMatrix
source§impl Default for AffineMatrix
impl Default for AffineMatrix
source§impl From<AffineMatrixBackground> for AffineMatrix
impl From<AffineMatrixBackground> for AffineMatrix
source§fn from(mat: AffineMatrixBackground) -> Self
fn from(mat: AffineMatrixBackground) -> Self
source§impl From<AffineMatrixObject> for AffineMatrix
impl From<AffineMatrixObject> for AffineMatrix
source§fn from(mat: AffineMatrixObject) -> Self
fn from(mat: AffineMatrixObject) -> Self
source§impl Mul for AffineMatrix
impl Mul for AffineMatrix
source§impl MulAssign for AffineMatrix
impl MulAssign for AffineMatrix
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read more