Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit d19680e

Browse files
nat-rixTrueDoctor
authored andcommitted
This will be squashed anyway
1 parent a78fa42 commit d19680e

File tree

10 files changed

+331
-129
lines changed

10 files changed

+331
-129
lines changed

rask-engine/src/boxes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ impl From<&spine::skeleton::srt::SRT> for RBox {
159159

160160
impl From<&Mat3> for RBox {
161161
fn from(mat: &Mat3) -> RBox {
162-
let pos = Vec2::from(*mat * Vec3::new(-1.0, -1.0, 1.0));
163-
let v1 = Mat2::from(mat) * Vec2::new(0.0, 2.0);
164-
let v2 = Mat2::from(mat) * Vec2::new(2.0, 0.0);
162+
let pos = (*mat * Vec3::new(-1.0, -1.0, 1.0)).into();
163+
let v1 = (*mat * Vec3::new(0.0, 2.0, 0.0)).into();
164+
let v2 = (*mat * Vec3::new(2.0, 0.0, 0.0)).into();
165165
RBox { pos, v1, v2 }
166166
}
167167
}

rask-engine/src/collide.rs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::math::{Vec2, EPSILON};
99
/// A trait for objects that can collide with other objects.
1010
pub trait Collide<Rhs = Self> {
1111
/// calculate the penetration depth (a scalar ratio of `dv`)
12+
/// as well as the normal of the colliding edge
1213
/// of the collision after applying the velocity,
1314
/// if there was any.
1415
/// `dv` is the difference between the two velocities
@@ -39,8 +40,8 @@ impl Collide for Collidable {
3940
}
4041

4142
impl Collidable {
42-
pub fn shift(&self, dv: Vec2) -> Collidable {
43-
match self {
43+
pub fn shift(&mut self, dv: Vec2) {
44+
*self = match self {
4445
Collidable::AABox(a) => Collidable::AABox(AABox {
4546
pos: a.pos + dv,
4647
size: a.size,
@@ -55,32 +56,6 @@ impl Collidable {
5556
}
5657
}
5758

58-
/// calculate the minimal axis aligned bounding box that contains all `Collidable`s of a given set
59-
pub fn calculate_aabb<'a, I: Iterator<Item = &'a Collidable>>(vals: I) -> AABox {
60-
let [(mut minx, mut maxx), (mut miny, mut maxy)] = [(f32::INFINITY, f32::NEG_INFINITY); 2];
61-
let mut minmax = |v1: &Vec2, v2: &Vec2| {
62-
minx = f32::min(minx, v1.x());
63-
maxx = f32::max(maxx, v2.x());
64-
miny = f32::min(miny, v1.y());
65-
maxy = f32::max(maxy, v2.y());
66-
};
67-
for val in vals {
68-
match val {
69-
Collidable::Point(v) => minmax(v, v),
70-
Collidable::AABox(AABox { pos, size }) => minmax(pos, &(*pos + *size)),
71-
&Collidable::RBox(RBox { pos, v1, v2 }) => {
72-
for point in &[pos, pos + v1, pos + v2, pos + v1 + v2] {
73-
minmax(point, point)
74-
}
75-
}
76-
};
77-
}
78-
AABox {
79-
pos: Vec2::new(minx, miny),
80-
size: Vec2::new(maxx - minx, maxy - miny),
81-
}
82-
}
83-
8459
// Given a fraction of the dv vectors length,
8560
// return the amount to set the objects back
8661
// in case of a collision
@@ -104,6 +79,26 @@ macro_rules! impl_collide {
10479
Self::$C(other)
10580
}
10681
}
82+
83+
impl Collide<$A> for Collidable {
84+
fn collide_after(&self, other: &$A, dv: Vec2) -> Option<f32> {
85+
match self {
86+
Collidable::Point(s) => s.collide_after(other, dv),
87+
Collidable::AABox(s) => s.collide_after(other, dv),
88+
Collidable::RBox(s) => s.collide_after(other, dv),
89+
}
90+
}
91+
}
92+
93+
impl Collide<Collidable> for $A {
94+
fn collide_after(&self, other: &Collidable, dv: Vec2) -> Option<f32> {
95+
match other {
96+
Collidable::Point(s) => self.collide_after(s, dv),
97+
Collidable::AABox(s) => self.collide_after(s, dv),
98+
Collidable::RBox(s) => self.collide_after(s, dv),
99+
}
100+
}
101+
}
107102
};
108103
(for {$A:ident, $B:ident} $item:item) => {
109104
impl Collide<$B> for $A {

rask-engine/src/engine/components.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub struct Vel(pub Vec2);
5050

5151
#[derive(Debug, Clone, Copy, Default, Component)]
5252
#[storage(VecStorage)]
53-
pub struct Vel_(pub Vec2);
53+
pub struct DeltaVel(pub Vec2);
5454

5555
#[derive(Debug, Clone, Copy, Default, Component)]
5656
#[storage(VecStorage)]
@@ -124,13 +124,13 @@ pub struct Sprite {
124124
pub sub_id: u64,
125125
}
126126

127-
#[derive(Debug, Clone)]
128-
pub struct Transform {
129-
pub mat3: Mat3,
130-
}
127+
#[derive(Debug, Default, Clone, Component)]
128+
pub struct Transform(pub Mat3);
131129

132-
impl Component for Transform {
133-
type Storage = FlaggedStorage<Self, DenseVecStorage<Self>>;
130+
impl Transform {
131+
pub fn shift(&mut self, vec: Vec2) {
132+
self.0 = Mat3::translation(vec.x(), vec.y()) * self.0
133+
}
134134
}
135135

136136
#[derive(Debug, Default, Clone, Copy, Component)]

rask-engine/src/engine/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ impl GameEngine for RaskEngine {
123123
.build();
124124
let _char = world
125125
.create_entity()
126-
.with(Pos(Vec2::new(0.0, 0.0)))
126+
.with(Pos(Vec2::new(0.3, 0.0)))
127127
.with(Vel(Vec2::new(0.0, 0.0)))
128-
.with(Vel_(Vec2::zero()))
128+
.with(DeltaVel(Vec2::zero()))
129129
.with(Speed(0.4))
130130
.with(Mass(1.0))
131131
.with(Animation {

0 commit comments

Comments
 (0)