Skip to content

Commit

Permalink
#13 Use 4x4 matrices for transform stack
Browse files Browse the repository at this point in the history
  • Loading branch information
wtholliday committed Sep 10, 2023
1 parent 6bffa52 commit 9b1ce10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub type LocalPoint = Point2D<f32, LocalSpace>;
pub type LocalVector = Vector2D<f32, LocalSpace>;
pub type LocalSize = Size2D<f32, LocalSpace>;

pub type LocalToWorld = Transform2D<f32, LocalSpace, WorldSpace>;
pub type LocalToWorld = Transform3D<f32, LocalSpace, WorldSpace>;
pub type WorldToLocal = Transform2D<f32, WorldSpace, LocalSpace>;
pub type LocalTransform = Transform2D<f32, LocalSpace, LocalSpace>;

Expand Down
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ impl Vger {
let m = *self.tx_stack.last().unwrap();
self.scenes[self.cur_scene]
.xforms
.push(m.to_3d().to_array());
.push(m.to_array());
let n = self.xform_count;
self.xform_count += 1;
return n;
Expand All @@ -812,22 +812,23 @@ impl Vger {
/// Translates the coordinate system.
pub fn translate<Vec: Into<LocalVector>>(&mut self, offset: Vec) {
if let Some(m) = self.tx_stack.last_mut() {
*m = (*m).pre_translate(offset.into());
let off: LocalVector = offset.into();
*m = (*m).pre_translate(off.to_3d());
}
}

/// Scales the coordinate system.
pub fn scale<Vec: Into<LocalVector>>(&mut self, scale: Vec) {
if let Some(m) = self.tx_stack.last_mut() {
let s: LocalVector = scale.into();
*m = (*m).pre_scale(s.x, s.y);
*m = (*m).pre_scale(s.x, s.y, 1.0);
}
}

/// Rotates the coordinate system.
pub fn rotate(&mut self, theta: f32) {
if let Some(m) = self.tx_stack.last_mut() {
*m = m.pre_rotate(euclid::Angle::<f32>::radians(theta));
*m = m.pre_rotate(0.0,0.0,1.0,euclid::Angle::<f32>::radians(theta));
}
}

Expand All @@ -841,7 +842,7 @@ impl Vger {
if let Some(m) = self.scissor_stack.last_mut() {
*m = Scissor::new();
if let Some(xform) = self.tx_stack.last().unwrap().inverse() {
m.xform = xform.to_3d().to_array();
m.xform = xform.to_array();
m.origin = rect.origin.to_array();
m.size = rect.size.to_array();
}
Expand Down

0 comments on commit 9b1ce10

Please sign in to comment.