Struct agb::display::object::AffineMatrixInstance
source · pub struct AffineMatrixInstance { /* private fields */ }
Expand description
An affine matrix that can be used on objects. It is just in time copied to vram, so you can have as many as you like of these but you can only use up to 16 in one frame. They are reference counted (Cloning is cheap) and immutable, if you want to change a matrix you must make a new one and set it on all your objects.
Implementations§
source§impl AffineMatrixInstance
impl AffineMatrixInstance
sourcepub fn new(affine_matrix: AffineMatrixObject) -> AffineMatrixInstance
pub fn new(affine_matrix: AffineMatrixObject) -> AffineMatrixInstance
Creates an instance of an affine matrix from its object form. Check out the docs for AffineMatrix to see how you can use them to create effects.
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();
}
}
Trait Implementations§
source§impl Clone for AffineMatrixInstance
impl Clone for AffineMatrixInstance
source§fn clone(&self) -> AffineMatrixInstance
fn clone(&self) -> AffineMatrixInstance
Returns a copy of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for AffineMatrixInstance
impl !Send for AffineMatrixInstance
impl !Sync for AffineMatrixInstance
impl Unpin for AffineMatrixInstance
impl !UnwindSafe for AffineMatrixInstance
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more