mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
saner orthographic projection
This commit is contained in:
parent
e72b5583d1
commit
db6a365b13
6 changed files with 9 additions and 13 deletions
|
@ -55,7 +55,7 @@ pub struct OrthographicProjection {
|
|||
|
||||
impl CameraProjection for OrthographicProjection {
|
||||
fn get_view_matrix(&self) -> Mat4 {
|
||||
let projection = Mat4::orthographic_rh_gl(
|
||||
let projection = Mat4::orthographic_rh(
|
||||
self.left,
|
||||
self.right,
|
||||
self.bottom,
|
||||
|
@ -92,8 +92,8 @@ impl Default for OrthographicProjection {
|
|||
right: 0.0,
|
||||
bottom: 0.0,
|
||||
top: 0.0,
|
||||
near: 0.0,
|
||||
far: 1.0,
|
||||
near: -1.0,
|
||||
far: 0.1,
|
||||
window_origin: WindowOrigin::Center,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@ layout(set = 1, binding = 0) uniform Quad {
|
|||
void main() {
|
||||
v_Uv = Vertex_Uv;
|
||||
vec3 position = Vertex_Position * vec3(Quad_Size, 0.0);
|
||||
position = position + vec3(Quad_Position, -Quad_ZIndex);
|
||||
position = position + vec3(Quad_Position, Quad_ZIndex);
|
||||
gl_Position = ViewProj * vec4(position, 1.0);
|
||||
}
|
|
@ -19,6 +19,6 @@ layout(set = 1, binding = 0) uniform Quad {
|
|||
void main() {
|
||||
v_Uv = Vertex_Uv;
|
||||
vec3 position = Vertex_Position * vec3(Quad_Size, 0.0);
|
||||
position = position + vec3(Quad_Position, -Quad_ZIndex);
|
||||
position = position + vec3(Quad_Position, Quad_ZIndex);
|
||||
gl_Position = ViewProj * vec4(position, 1.0);
|
||||
}
|
|
@ -20,7 +20,7 @@ pub fn ui_update_system() -> Box<dyn Schedulable> {
|
|||
let mut window_quad = Quad {
|
||||
size: Vec2::new(window.width as f32, window.height as f32),
|
||||
position: Vec2::new(0.0, 0.0),
|
||||
z_index: 0.9999,
|
||||
z_index: 0.0,
|
||||
};
|
||||
for entity in node_query
|
||||
.iter_entities(world)
|
||||
|
@ -57,7 +57,7 @@ fn update_node_entity(world: &mut SubWorld, entity: Entity, parent_quad: Quad) -
|
|||
return Some(Quad {
|
||||
size: quad.size,
|
||||
position: quad.position - quad.size / 2.0,
|
||||
z_index: quad.z_index - UI_Z_STEP,
|
||||
z_index: quad.z_index + UI_Z_STEP,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,6 @@ fn update_node_entity(world: &mut SubWorld, entity: Entity, parent_quad: Quad) -
|
|||
fn process_child_result(_parent_result: Quad, child_result: Quad) -> Quad {
|
||||
// "earlier" children are sorted behind "later" children
|
||||
let mut result = child_result.clone();
|
||||
result.z_index -= UI_Z_STEP;
|
||||
result.z_index += UI_Z_STEP;
|
||||
result
|
||||
}
|
||||
|
|
|
@ -17,10 +17,6 @@ fn setup(
|
|||
.build()
|
||||
.add_entity(OrthographicCameraEntity::default())
|
||||
.add_entity(SpriteEntity {
|
||||
quad: Quad {
|
||||
z_index: 0.5,
|
||||
..Default::default()
|
||||
},
|
||||
material: materials.add(texture_handle.into()),
|
||||
..Default::default()
|
||||
});
|
||||
|
|
|
@ -42,7 +42,7 @@ fn setup(
|
|||
sprite: SpriteSheetSprite {
|
||||
index: 0,
|
||||
scale: 6.0,
|
||||
position: Vec3::new(0.0, 0.0, -0.5),
|
||||
position: Vec3::new(0.0, 0.0, 0.0),
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue