Add "origin" to draw calls with a transform
This commit is contained in:
parent
a14f79cadd
commit
4ef4e707c6
3 changed files with 75 additions and 5 deletions
|
@ -14,6 +14,7 @@ pub trait ImageInterface {
|
||||||
y: f32,
|
y: f32,
|
||||||
color: Color,
|
color: Color,
|
||||||
transform: Transform,
|
transform: Transform,
|
||||||
|
origin: Vector,
|
||||||
) -> Result<(), String>;
|
) -> Result<(), String>;
|
||||||
fn draw_sub_transform(
|
fn draw_sub_transform(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -22,6 +23,7 @@ pub trait ImageInterface {
|
||||||
y: f32,
|
y: f32,
|
||||||
color: Color,
|
color: Color,
|
||||||
transform: Transform,
|
transform: Transform,
|
||||||
|
origin: Vector,
|
||||||
) -> Result<(), String>;
|
) -> Result<(), String>;
|
||||||
fn get_w(&self) -> usize;
|
fn get_w(&self) -> usize;
|
||||||
fn get_h(&self) -> usize;
|
fn get_h(&self) -> usize;
|
||||||
|
@ -76,6 +78,7 @@ pub trait GameInterface {
|
||||||
circle: Circle,
|
circle: Circle,
|
||||||
color: Color,
|
color: Color,
|
||||||
transform: Transform,
|
transform: Transform,
|
||||||
|
origin: Vector,
|
||||||
) -> Result<(), String>;
|
) -> Result<(), String>;
|
||||||
fn draw_rect(&mut self, rect: Rectangle, color: Color) -> Result<(), String>;
|
fn draw_rect(&mut self, rect: Rectangle, color: Color) -> Result<(), String>;
|
||||||
fn draw_rect_ex(
|
fn draw_rect_ex(
|
||||||
|
@ -90,6 +93,7 @@ pub trait GameInterface {
|
||||||
rect: Rectangle,
|
rect: Rectangle,
|
||||||
color: Color,
|
color: Color,
|
||||||
transform: Transform,
|
transform: Transform,
|
||||||
|
origin: Vector,
|
||||||
) -> Result<(), String>;
|
) -> Result<(), String>;
|
||||||
|
|
||||||
fn load_image(&mut self, path: &Path) -> Result<Box<dyn ImageInterface>, String>;
|
fn load_image(&mut self, path: &Path) -> Result<Box<dyn ImageInterface>, String>;
|
||||||
|
|
|
@ -15,6 +15,8 @@ use std::{
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::faux_quicksilver::Vector;
|
||||||
|
|
||||||
use super::{FontInterface, GameInterface, ImageInterface, MusicInterface, SoundInterface};
|
use super::{FontInterface, GameInterface, ImageInterface, MusicInterface, SoundInterface};
|
||||||
|
|
||||||
fn fqcolor_to_color(c: crate::faux_quicksilver::Color) -> ffi::Color {
|
fn fqcolor_to_color(c: crate::faux_quicksilver::Color) -> ffi::Color {
|
||||||
|
@ -62,6 +64,7 @@ impl ImageInterface for RaylibImageHandler {
|
||||||
y: f32,
|
y: f32,
|
||||||
color: crate::faux_quicksilver::Color,
|
color: crate::faux_quicksilver::Color,
|
||||||
transform: crate::faux_quicksilver::Transform,
|
transform: crate::faux_quicksilver::Transform,
|
||||||
|
origin: Vector,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
@ -73,6 +76,7 @@ impl ImageInterface for RaylibImageHandler {
|
||||||
y: f32,
|
y: f32,
|
||||||
color: crate::faux_quicksilver::Color,
|
color: crate::faux_quicksilver::Color,
|
||||||
transform: crate::faux_quicksilver::Transform,
|
transform: crate::faux_quicksilver::Transform,
|
||||||
|
origin: Vector,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
@ -328,6 +332,7 @@ impl GameInterface for RaylibGame {
|
||||||
circle: crate::faux_quicksilver::Circle,
|
circle: crate::faux_quicksilver::Circle,
|
||||||
color: crate::faux_quicksilver::Color,
|
color: crate::faux_quicksilver::Color,
|
||||||
transform: crate::faux_quicksilver::Transform,
|
transform: crate::faux_quicksilver::Transform,
|
||||||
|
origin: Vector,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
@ -364,6 +369,7 @@ impl GameInterface for RaylibGame {
|
||||||
rect: crate::faux_quicksilver::Rectangle,
|
rect: crate::faux_quicksilver::Rectangle,
|
||||||
color: crate::faux_quicksilver::Color,
|
color: crate::faux_quicksilver::Color,
|
||||||
transform: crate::faux_quicksilver::Transform,
|
transform: crate::faux_quicksilver::Transform,
|
||||||
|
origin: Vector,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
|
@ -643,12 +643,28 @@ impl ParticleSystem {
|
||||||
* Transform::rotate(particle.r);
|
* Transform::rotate(particle.r);
|
||||||
window
|
window
|
||||||
.get_gi_mut()
|
.get_gi_mut()
|
||||||
.draw_rect_transform(particle.rect, self.color, transform * pre_transform)
|
.draw_rect_transform(
|
||||||
|
particle.rect,
|
||||||
|
self.color,
|
||||||
|
transform * pre_transform,
|
||||||
|
Vector {
|
||||||
|
x: particle.rect.x + particle.rect.w / 2.0,
|
||||||
|
y: particle.rect.y + particle.rect.h / 2.0,
|
||||||
|
},
|
||||||
|
)
|
||||||
.ok();
|
.ok();
|
||||||
} else {
|
} else {
|
||||||
window
|
window
|
||||||
.get_gi_mut()
|
.get_gi_mut()
|
||||||
.draw_circle_transform(particle.circle, self.color, transform)
|
.draw_circle_transform(
|
||||||
|
particle.circle,
|
||||||
|
self.color,
|
||||||
|
transform,
|
||||||
|
Vector {
|
||||||
|
x: particle.circle.x,
|
||||||
|
y: particle.circle.y,
|
||||||
|
},
|
||||||
|
)
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -761,6 +777,10 @@ impl RotatingParticleSystem {
|
||||||
transform
|
transform
|
||||||
* Transform::translate(-moved_rect.x / 2.0, -moved_rect.y / 2.0)
|
* Transform::translate(-moved_rect.x / 2.0, -moved_rect.y / 2.0)
|
||||||
* Transform::rotate(self.r * 1.3),
|
* Transform::rotate(self.r * 1.3),
|
||||||
|
Vector {
|
||||||
|
x: moved_rect.x + moved_rect.w / 2.0,
|
||||||
|
y: moved_rect.y + moved_rect.h / 2.0,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.ok();
|
.ok();
|
||||||
} else {
|
} else {
|
||||||
|
@ -770,7 +790,15 @@ impl RotatingParticleSystem {
|
||||||
solid_color.a = (self.particle_system.opacity * 255.0) as u8;
|
solid_color.a = (self.particle_system.opacity * 255.0) as u8;
|
||||||
window
|
window
|
||||||
.get_gi_mut()
|
.get_gi_mut()
|
||||||
.draw_circle_transform(moved_cir, solid_color, transform)
|
.draw_circle_transform(
|
||||||
|
moved_cir,
|
||||||
|
solid_color,
|
||||||
|
transform,
|
||||||
|
Vector {
|
||||||
|
x: moved_cir.x,
|
||||||
|
y: moved_cir.y,
|
||||||
|
},
|
||||||
|
)
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -856,7 +884,15 @@ impl ExplConvParticleSystem {
|
||||||
* 255.0) as u8;
|
* 255.0) as u8;
|
||||||
window
|
window
|
||||||
.get_gi_mut()
|
.get_gi_mut()
|
||||||
.draw_circle_transform(particle.circle, self.color, transform)
|
.draw_circle_transform(
|
||||||
|
particle.circle,
|
||||||
|
self.color,
|
||||||
|
transform,
|
||||||
|
Vector {
|
||||||
|
x: particle.circle.x,
|
||||||
|
y: particle.circle.y,
|
||||||
|
},
|
||||||
|
)
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -932,7 +968,15 @@ impl Planet {
|
||||||
self.particle_system.draw(window, transform);
|
self.particle_system.draw(window, transform);
|
||||||
window
|
window
|
||||||
.get_gi_mut()
|
.get_gi_mut()
|
||||||
.draw_circle_transform(self.circle, self.color, transform)
|
.draw_circle_transform(
|
||||||
|
self.circle,
|
||||||
|
self.color,
|
||||||
|
transform,
|
||||||
|
Vector {
|
||||||
|
x: self.circle.x,
|
||||||
|
y: self.circle.y,
|
||||||
|
},
|
||||||
|
)
|
||||||
.ok();
|
.ok();
|
||||||
for moon in &mut self.moons {
|
for moon in &mut self.moons {
|
||||||
moon.draw(window, transform);
|
moon.draw(window, transform);
|
||||||
|
@ -999,6 +1043,10 @@ impl Star {
|
||||||
image_rect.y,
|
image_rect.y,
|
||||||
self.color,
|
self.color,
|
||||||
transform * Transform::rotate(self.r),
|
transform * Transform::rotate(self.r),
|
||||||
|
Vector {
|
||||||
|
x: image_rect.x + image_rect.w / 2.0,
|
||||||
|
y: image_rect.y + image_rect.h / 2.0,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
|
@ -1108,6 +1156,10 @@ impl Fish {
|
||||||
body_rect.y,
|
body_rect.y,
|
||||||
self.color,
|
self.color,
|
||||||
transform * body_tr,
|
transform * body_tr,
|
||||||
|
Vector {
|
||||||
|
x: self.body_rect.x + self.body_rect.w / 2.0,
|
||||||
|
y: self.body_rect.y + self.body_rect.h / 2.0,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.ok();
|
.ok();
|
||||||
let mut tail_rect = self.tail_rect;
|
let mut tail_rect = self.tail_rect;
|
||||||
|
@ -1128,6 +1180,10 @@ impl Fish {
|
||||||
tail_rect.y,
|
tail_rect.y,
|
||||||
self.color,
|
self.color,
|
||||||
transform * tail_tr,
|
transform * tail_tr,
|
||||||
|
Vector {
|
||||||
|
x: self.tail_rect.x + self.tail_rect.w / 2.0,
|
||||||
|
y: self.tail_rect.y + self.tail_rect.h / 2.0,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
|
@ -1914,6 +1970,10 @@ impl GameState {
|
||||||
Color::from_rgba(255, 255, 255, (self.player_particles.opacity * 255.0) as u8),
|
Color::from_rgba(255, 255, 255, (self.player_particles.opacity * 255.0) as u8),
|
||||||
Transform::translate(-self.player.x / 2.0, -self.player.y / 2.0)
|
Transform::translate(-self.player.x / 2.0, -self.player.y / 2.0)
|
||||||
* Transform::rotate(self.player_r as f32),
|
* Transform::rotate(self.player_r as f32),
|
||||||
|
Vector {
|
||||||
|
x: self.player.x + self.player.w / 2.0,
|
||||||
|
y: self.player.y + self.player.h / 2.0,
|
||||||
|
},
|
||||||
)?;
|
)?;
|
||||||
self.joining_particles.draw(window, Transform::IDENTITY);
|
self.joining_particles.draw(window, Transform::IDENTITY);
|
||||||
for expl_conv_ps in &mut self.expl_conv_p_systems {
|
for expl_conv_ps in &mut self.expl_conv_p_systems {
|
||||||
|
|
Loading…
Reference in a new issue