simplify transform usage where possible (#494)
This commit is contained in:
parent
a5259ab45f
commit
e81111c1b1
@ -1,4 +1,4 @@
|
||||
use bevy_math::{Mat3, Mat4, Quat, Vec3};
|
||||
use bevy_math::{Mat3, Mat4, Quat, Vec3, Vec4};
|
||||
use bevy_property::Properties;
|
||||
use std::fmt;
|
||||
|
||||
@ -60,6 +60,10 @@ impl Transform {
|
||||
Vec3::from(self.value.w_axis().truncate())
|
||||
}
|
||||
|
||||
pub fn translation_mut(&mut self) -> &mut Vec4 {
|
||||
self.value.w_axis_mut()
|
||||
}
|
||||
|
||||
pub fn rotation(&self) -> Quat {
|
||||
let scale = self.scale();
|
||||
|
||||
|
@ -193,7 +193,7 @@ pub fn flex_node_system(
|
||||
for (entity, mut node, mut transform, parent) in &mut node_transform_query.iter() {
|
||||
let layout = flex_surface.get_layout(entity).unwrap();
|
||||
node.size = Vec2::new(layout.size.width, layout.size.height);
|
||||
let mut position = transform.translation();
|
||||
let position = transform.translation_mut();
|
||||
position.set_x(layout.location.x + layout.size.width / 2.0);
|
||||
position.set_y(layout.location.y + layout.size.height / 2.0);
|
||||
if let Some(parent) = parent {
|
||||
@ -202,7 +202,5 @@ pub fn flex_node_system(
|
||||
*position.y_mut() -= parent_layout.size.height / 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
transform.set_translation(position);
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ fn update_node_entity(
|
||||
parent_result: Option<f32>,
|
||||
previous_result: Option<f32>,
|
||||
) -> Option<f32> {
|
||||
let mut transform = node_query.get_mut::<Transform>(entity).ok()?;
|
||||
let mut z = UI_Z_STEP;
|
||||
let parent_global_z = parent_result.unwrap();
|
||||
if let Some(previous_global_z) = previous_result {
|
||||
@ -47,9 +46,8 @@ fn update_node_entity(
|
||||
};
|
||||
let global_z = z + parent_global_z;
|
||||
|
||||
let mut position = transform.translation();
|
||||
position.set_z(z);
|
||||
transform.set_translation(position);
|
||||
let mut transform = node_query.get_mut::<Transform>(entity).ok()?;
|
||||
transform.translation_mut().set_z(z);
|
||||
|
||||
Some(global_z)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{CalculatedSize, Node};
|
||||
use bevy_asset::{Assets, Handle};
|
||||
use bevy_ecs::{Changed, Query, Res, ResMut};
|
||||
use bevy_math::{Size, Vec3};
|
||||
use bevy_math::Size;
|
||||
use bevy_render::{
|
||||
draw::{Draw, DrawContext, Drawable},
|
||||
prelude::Msaa,
|
||||
@ -61,9 +61,7 @@ pub fn draw_text_system(
|
||||
mut query: Query<(&mut Draw, &Text, &Node, &GlobalTransform)>,
|
||||
) {
|
||||
for (mut draw, text, node, global_transform) in &mut query.iter() {
|
||||
let position = Vec3::from(global_transform.value().w_axis().truncate())
|
||||
- (node.size / 2.0).extend(0.0);
|
||||
|
||||
let position = global_transform.translation() - (node.size / 2.0).extend(0.0);
|
||||
let mut drawable_text = DrawableText {
|
||||
font: fonts.get(&text.font).unwrap(),
|
||||
font_atlas_set: font_atlas_sets
|
||||
|
@ -170,15 +170,11 @@ fn paddle_movement_system(
|
||||
direction += 1.0;
|
||||
}
|
||||
|
||||
transform.translate(Vec3::unit_x() * time.delta_seconds * direction * paddle.speed);
|
||||
|
||||
let translation = transform.translation_mut();
|
||||
// move the paddle horizontally
|
||||
*translation.x_mut() += time.delta_seconds * direction * paddle.speed;
|
||||
// bound the paddle within the walls
|
||||
let translation = transform.translation();
|
||||
transform.set_translation(Vec3::new(
|
||||
f32::max(-380.0, f32::min(380.0, translation.x())),
|
||||
translation.y(),
|
||||
translation.z(),
|
||||
));
|
||||
*translation.x_mut() = translation.x().min(380.0).max(-380.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user