1
1
use bevy:: {
2
2
asset:: { AssetServerSettings , LoadState } ,
3
3
input:: mouse:: MouseMotion ,
4
+ math:: Vec3A ,
4
5
prelude:: * ,
5
6
render:: {
6
7
camera:: { Camera2d , Camera3d , CameraProjection } ,
@@ -9,6 +10,9 @@ use bevy::{
9
10
scene:: InstanceId ,
10
11
} ;
11
12
13
+ #[ derive( Debug , Hash , PartialEq , Eq , Clone , SystemLabel ) ]
14
+ struct CameraControllerCheckSystem ;
15
+
12
16
fn main ( ) {
13
17
println ! (
14
18
"
@@ -41,9 +45,9 @@ Controls:
41
45
. add_startup_system ( setup)
42
46
. add_system_to_stage ( CoreStage :: PreUpdate , scene_load_check)
43
47
. add_system_to_stage ( CoreStage :: PreUpdate , camera_spawn_check)
44
- . add_system ( camera_controller_check. label ( "camera_controller_check" ) )
48
+ . add_system ( camera_controller_check. label ( CameraControllerCheckSystem ) )
45
49
. add_system ( update_lights)
46
- . add_system ( camera_controller. after ( "camera_controller_check" ) )
50
+ . add_system ( camera_controller. after ( CameraControllerCheckSystem ) )
47
51
. run ( ) ;
48
52
}
49
53
@@ -133,29 +137,30 @@ fn camera_spawn_check(
133
137
return ;
134
138
}
135
139
136
- let mut min = Vec3 :: splat ( f32:: MAX ) ;
137
- let mut max = Vec3 :: splat ( f32:: MIN ) ;
140
+ let mut min = Vec3A :: splat ( f32:: MAX ) ;
141
+ let mut max = Vec3A :: splat ( f32:: MIN ) ;
138
142
for ( transform, maybe_aabb) in meshes. iter ( ) {
139
143
let aabb = maybe_aabb. unwrap ( ) ;
140
144
// If the Aabb had not been rotated, applying the non-uniform scale would produce the
141
145
// correct bounds. However, it could very well be rotated and so we first convert to
142
146
// a Sphere, and then back to an Aabb to find the conservative min and max points.
143
147
let sphere = Sphere {
144
- center : transform. mul_vec3 ( aabb. center ) ,
145
- radius : ( transform. scale * aabb. half_extents ) . length ( ) ,
148
+ center : Vec3A :: from ( transform. mul_vec3 ( Vec3 :: from ( aabb. center ) ) ) ,
149
+ radius : ( Vec3A :: from ( transform. scale ) * aabb. half_extents ) . length ( ) ,
146
150
} ;
147
151
let aabb = Aabb :: from ( sphere) ;
148
152
min = min. min ( aabb. min ( ) ) ;
149
153
max = max. max ( aabb. max ( ) ) ;
150
154
}
151
155
152
156
let size = ( max - min) . length ( ) ;
153
- let aabb = Aabb :: from_min_max ( min, max) ;
157
+ let aabb = Aabb :: from_min_max ( Vec3 :: from ( min) , Vec3 :: from ( max) ) ;
154
158
155
159
if !scene_handle. has_camera {
156
- let transform =
157
- Transform :: from_translation ( aabb. center + size * Vec3 :: new ( 0.5 , 0.25 , 0.5 ) )
158
- . looking_at ( aabb. center , Vec3 :: Y ) ;
160
+ let transform = Transform :: from_translation (
161
+ Vec3 :: from ( aabb. center ) + size * Vec3 :: new ( 0.5 , 0.25 , 0.5 ) ,
162
+ )
163
+ . looking_at ( Vec3 :: from ( aabb. center ) , Vec3 :: Y ) ;
159
164
let view = transform. compute_matrix ( ) ;
160
165
let mut perspective_projection = PerspectiveProjection :: default ( ) ;
161
166
perspective_projection. far = perspective_projection. far . max ( size * 10.0 ) ;
0 commit comments