Expand description
2D camera that can be controlled by mouse. Offset and scale can be changed.
Note: You can get a Camera2D
using `let cam2d: Camera2D = (&cam).into();
Fields
offset: Vec2
scale: f32
Implementations
sourceimpl Camera
impl Camera
pub fn new(offset: Vec2, scale: f32) -> Self
sourcepub fn scale_wheel(&mut self, center: Vec2, wheel_value: f32, scale_factor: f32)
pub fn scale_wheel(&mut self, center: Vec2, wheel_value: f32, scale_factor: f32)
If wheel_value
has positive value, scale cam around point center
by factor scale_factor
.
If wheel_value
is negative, then scale by 1.0/scale_factor
. If wheel_value
equals 0.0
or scale_factor
equals 1.0
, nothing happens.
sourcepub fn scale_mul(&mut self, center: Vec2, mul_to_scale: f32)
pub fn scale_mul(&mut self, center: Vec2, mul_to_scale: f32)
Adds mul_to_scale
to current scale of cam. Scale is changed around point center
.
sourcepub fn scale_new(&mut self, center: Vec2, new_scale: f32)
pub fn scale_new(&mut self, center: Vec2, new_scale: f32)
Replace current scale of camera with new_scale
. Scale is changed around point center
.
sourcepub fn update(&mut self, mouse_pos: Vec2, should_offset: bool)
pub fn update(&mut self, mouse_pos: Vec2, should_offset: bool)
Update camera position by new mouse position. This method must be run at every frame. should_offset
controls if the camera should actually move or not.
Note: It’s better to use mouse_position_local
with this method, otherwise if you use mouse_position
the movement is way too big.
Trait Implementations
impl Copy for Camera
Auto Trait Implementations
impl RefUnwindSafe for Camera
impl Send for Camera
impl Sync for Camera
impl Unpin for Camera
impl UnwindSafe for Camera
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more