Skip to content

Commit

Permalink
feat(transform): Allow a transform to use screen as origin (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
suspistew authored Feb 19, 2022
1 parent 1561b60 commit c85ef1e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/mario/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use scion::{
utils::file::{app_base_path, read_file},
Scion,
};
use scion::core::components::maths::transform::TransformBuilder;

use crate::{character_control_system::move_char_system, collisions_system::collider_system};

Expand Down
13 changes: 13 additions & 0 deletions src/core/components/maths/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Transform {
pub(crate) angle: f32,
pub(crate) dirty: bool,
pub(crate) dirty_child: bool,
pub(crate) use_screen_as_origin: bool,
bounds: Bounds,
}

Expand All @@ -31,6 +32,7 @@ impl Default for Transform {
angle: 0.0,
dirty: false,
dirty_child: true,
use_screen_as_origin: false,
bounds: Default::default(),
}
}
Expand All @@ -46,6 +48,7 @@ impl Transform {
angle,
dirty: false,
dirty_child: true,
use_screen_as_origin: false,
bounds: Default::default(),
}
}
Expand Down Expand Up @@ -134,6 +137,11 @@ impl Transform {
self.handle_bounds();
}

pub fn set_use_screen_as_origin(&mut self, new_value: bool) {
self.use_screen_as_origin = new_value;
self.handle_bounds();
}

/// Configure the minimum and maximum global values of x and y
pub fn set_global_translation_bounds(
&mut self,
Expand Down Expand Up @@ -217,6 +225,11 @@ impl TransformBuilder {
self
}

pub fn with_screen_as_origin(mut self) -> Self{
self.transform.use_screen_as_origin = true;
self
}

pub fn build(self) -> Transform { self.transform }
}

Expand Down
2 changes: 1 addition & 1 deletion src/rendering/gl_representations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl From<UniformData<'_>> for GlUniform {
y: uniform_data.transform.global_translation.y(),
z: uniform_data.transform.global_translation.z() as f32,
});
if !uniform_data.is_ui_component {
if !uniform_data.is_ui_component && !uniform_data.transform.use_screen_as_origin {
model_trans.append_translation(Vec3 {
x: -1. * uniform_data.camera.1.global_translation().x(),
y: -1. * uniform_data.camera.1.global_translation().y(),
Expand Down

0 comments on commit c85ef1e

Please # to comment.