1
+ use crate :: { PositionedGlyph , TextSection } ;
1
2
use bevy_math:: { Mat4 , Vec3 } ;
3
+ use bevy_render:: pipeline:: IndexFormat ;
2
4
use bevy_render:: {
3
5
draw:: { Draw , DrawContext , DrawError , Drawable } ,
4
6
mesh,
@@ -8,19 +10,18 @@ use bevy_render::{
8
10
renderer:: { BindGroup , RenderResourceBindings , RenderResourceId } ,
9
11
} ;
10
12
use bevy_sprite:: TextureAtlasSprite ;
13
+ use bevy_transform:: prelude:: GlobalTransform ;
11
14
use bevy_utils:: tracing:: error;
12
15
13
- use crate :: { PositionedGlyph , TextSection } ;
14
- use bevy_render:: pipeline:: IndexFormat ;
15
-
16
16
pub struct DrawableText < ' a > {
17
17
pub render_resource_bindings : & ' a mut RenderResourceBindings ,
18
- pub position : Vec3 ,
18
+ pub global_transform : GlobalTransform ,
19
19
pub scale_factor : f32 ,
20
20
pub sections : & ' a [ TextSection ] ,
21
21
pub text_glyphs : & ' a Vec < PositionedGlyph > ,
22
22
pub msaa : & ' a Msaa ,
23
23
pub font_quad_vertex_layout : & ' a VertexBufferLayout ,
24
+ pub alignment_offset : Vec3 ,
24
25
}
25
26
26
27
impl < ' a > Drawable for DrawableText < ' a > {
@@ -76,20 +77,12 @@ impl<'a> Drawable for DrawableText<'a> {
76
77
flip_y : false ,
77
78
} ;
78
79
79
- // To get the rendering right for non-one scaling factors, we need
80
- // the sprite to be drawn in "physical" coordinates. This is because
81
- // the shader uses the size of the sprite to control the size on
82
- // screen. To accomplish this we make the sprite transform
83
- // convert from physical coordinates to logical coordinates in
84
- // addition to altering the origin. Since individual glyphs will
85
- // already be in physical coordinates, we just need to convert the
86
- // overall position to physical coordinates to get the sprites
87
- // physical position.
88
-
89
- let transform = Mat4 :: from_scale ( Vec3 :: splat ( 1. / self . scale_factor ) )
90
- * Mat4 :: from_translation (
91
- self . position * self . scale_factor + tv. position . extend ( 0. ) ,
92
- ) ;
80
+ let scale_transform = Mat4 :: from_scale ( Vec3 :: splat ( 1. / self . scale_factor ) ) ;
81
+ let transform = Mat4 :: from_rotation_translation (
82
+ self . global_transform . rotation ,
83
+ self . global_transform . translation ,
84
+ ) * scale_transform
85
+ * Mat4 :: from_translation ( self . alignment_offset + tv. position . extend ( 0. ) ) ;
93
86
94
87
let transform_buffer = context. get_uniform_buffer ( & transform) . unwrap ( ) ;
95
88
let sprite_buffer = context. get_uniform_buffer ( & sprite) . unwrap ( ) ;
0 commit comments