Object rotation!

This commit is contained in:
Evan Pratten 2022-04-02 16:41:11 -04:00
parent 10fbc84252
commit d65dc12299

View File

@ -8,7 +8,7 @@ use nalgebra as na;
use raylib::{ use raylib::{
camera::Camera2D, camera::Camera2D,
color::Color, color::Color,
math::Vector2, math::{Rectangle, Vector2},
prelude::{RaylibDraw, RaylibDrawHandle, RaylibMode2D}, prelude::{RaylibDraw, RaylibDrawHandle, RaylibMode2D},
texture::Texture2D, texture::Texture2D,
RaylibHandle, RaylibThread, RaylibHandle, RaylibThread,
@ -242,8 +242,8 @@ impl MapRenderer {
draw_handle, draw_handle,
obj_ref.position - (tex.size() / 2.0), obj_ref.position - (tex.size() / 2.0),
None, None,
None, Some(tex.size() / 2.0),
Some(obj_ref.rotation_radians), Some(obj_ref.rotation_radians.to_degrees()),
None, None,
); );
} else { } else {
@ -253,14 +253,28 @@ impl MapRenderer {
.get_mut(&object_key) .get_mut(&object_key)
.unwrap(); .unwrap();
let p: Vector2 = obj_ref.position.into(); let p: Vector2 = obj_ref.position.into();
draw_handle.draw_texture_ex( let r1 = Rectangle {
x: 0.0,
y: 0.0,
width: tex.width as f32,
height: tex.height as f32,
};
let r2 = Rectangle {
x: p.x,
y: p.y,
width: tex.width as f32,
height: tex.height as f32,
};
draw_handle.draw_texture_pro(
&tex, &tex,
p - Vector2::new( r1,
r2,
Vector2::new(
tex.width as f32 / 2.0, tex.width as f32 / 2.0,
tex.height as f32 / 2.0, tex.height as f32 / 2.0,
), ),
obj_ref.rotation_radians, obj_ref.rotation_radians.to_degrees(),
1.0,
Color::WHITE, Color::WHITE,
); );
} }
@ -293,8 +307,8 @@ impl MapRenderer {
draw_handle, draw_handle,
obj_ref.position - (tex.size() / 2.0), obj_ref.position - (tex.size() / 2.0),
None, None,
None, Some(tex.size() / 2.0),
Some(obj_ref.rotation_radians), Some(obj_ref.rotation_radians.to_degrees()),
Some(tint), Some(tint),
); );
} else { } else {
@ -304,14 +318,28 @@ impl MapRenderer {
.get_mut(&object_key) .get_mut(&object_key)
.unwrap(); .unwrap();
let p: Vector2 = obj_ref.position.into(); let p: Vector2 = obj_ref.position.into();
draw_handle.draw_texture_ex( let r1 = Rectangle {
x: 0.0,
y: 0.0,
width: tex.width as f32,
height: tex.height as f32,
};
let r2 = Rectangle {
x: p.x,
y: p.y,
width: tex.width as f32,
height: tex.height as f32,
};
draw_handle.draw_texture_pro(
&tex, &tex,
p - Vector2::new( r1,
r2,
Vector2::new(
tex.width as f32 / 2.0, tex.width as f32 / 2.0,
tex.height as f32 / 2.0, tex.height as f32 / 2.0,
), ),
obj_ref.rotation_radians, obj_ref.rotation_radians.to_degrees(),
1.0,
tint, tint,
); );
} }