1
- use std:: { path:: Path , rc:: Rc } ;
1
+ use std:: {
2
+ cell:: Cell ,
3
+ path:: Path ,
4
+ rc:: { Rc , Weak } ,
5
+ } ;
2
6
3
7
/// Renders a brdf example
4
8
use gfx_maths:: * ;
5
9
use vulkan_engine:: {
6
- core:: engine:: Engine ,
10
+ core:: { engine:: Engine , input :: Input } ,
7
11
scene:: {
8
12
component:: {
9
13
camera_component:: CameraComponent , debug_movement_component:: DebugMovementComponent ,
10
- light_component:: LightComponent , renderer:: RendererComponent ,
14
+ light_component:: LightComponent , renderer:: RendererComponent , Component ,
11
15
} ,
16
+ entity:: Entity ,
12
17
light:: { DirectionalLight , PointLight } ,
13
18
material:: MaterialPipeline ,
14
19
model:: Model ,
@@ -112,43 +117,24 @@ fn setup(engine: &mut Engine) {
112
117
}
113
118
}
114
119
115
- scene
116
- . new_entity_with_transform (
117
- "DirLight1" . to_string ( ) ,
118
- Transform {
119
- position : Vec3 :: zero ( ) ,
120
- rotation : Quaternion :: axis_angle ( Vec3 :: new ( 1.0 , 0.0 , 0.0 ) , -90.0f32 . to_radians ( ) ) ,
121
- scale : Vec3 :: one ( ) ,
122
- } ,
123
- )
124
- . new_component :: < LightComponent > ( )
125
- . light
126
- . set (
127
- DirectionalLight {
128
- direction : Vec4 :: zero ( ) ,
129
- illuminance : Vec4 :: new ( 10.1 , 10.1 , 10.1 , 0.0 ) ,
130
- }
131
- . into ( ) ,
132
- ) ;
120
+ let sun = scene. new_entity_with_transform (
121
+ "Sun" . to_string ( ) ,
122
+ Transform {
123
+ position : Vec3 :: zero ( ) ,
124
+ rotation : Quaternion :: axis_angle ( Vec3 :: new ( 1.0 , 0.0 , 0.0 ) , -90.0f32 . to_radians ( ) ) ,
125
+ scale : Vec3 :: one ( ) ,
126
+ } ,
127
+ ) ;
133
128
134
- scene
135
- . new_entity_with_transform (
136
- "DirLight2" . to_string ( ) ,
137
- Transform {
138
- position : Vec3 :: zero ( ) ,
139
- rotation : Quaternion :: axis_angle ( Vec3 :: new ( 1.0 , 0.0 , 0.0 ) , 90.0f32 . to_radians ( ) ) ,
140
- scale : Vec3 :: one ( ) ,
141
- } ,
142
- )
143
- . new_component :: < LightComponent > ( )
144
- . light
145
- . set (
146
- DirectionalLight {
147
- direction : Vec4 :: zero ( ) ,
148
- illuminance : Vec4 :: new ( 1.6 , 1.6 , 1.6 , 0.0 ) ,
149
- }
150
- . into ( ) ,
151
- ) ;
129
+ sun. new_component :: < LightComponent > ( ) . light . set (
130
+ DirectionalLight {
131
+ direction : Vec4 :: zero ( ) ,
132
+ illuminance : Vec4 :: new ( 239.0 , 245.0 , 218.0 , 0.0 ) / 50.0 ,
133
+ }
134
+ . into ( ) ,
135
+ ) ;
136
+
137
+ sun. new_component :: < RotationComponent > ( ) ;
152
138
153
139
scene
154
140
. new_entity_with_transform (
@@ -188,46 +174,9 @@ fn setup(engine: &mut Engine) {
188
174
) ;
189
175
scene
190
176
. new_entity_with_transform (
191
- "PointLight White 3" . to_string ( ) ,
192
- Transform {
193
- position : Vec3 :: new ( 0.1 , -3.0 , -3.0 ) ,
194
- rotation : Quaternion :: identity ( ) ,
195
- scale : Vec3 :: one ( ) ,
196
- } ,
197
- )
198
- . new_component :: < LightComponent > ( )
199
- . light
200
- . set (
201
- PointLight {
202
- position : Vec4 :: zero ( ) ,
203
- luminous_flux : Vec4 :: new ( 100.0 , 100.0 , 100.0 , 0.0 ) ,
204
- }
205
- . into ( ) ,
206
- ) ;
207
- scene
208
- . new_entity_with_transform (
209
- "PointLight White 4" . to_string ( ) ,
210
- Transform {
211
- position : Vec3 :: new ( 0.1 , -3.0 , -3.0 ) ,
212
- rotation : Quaternion :: identity ( ) ,
213
- scale : Vec3 :: one ( ) ,
214
- } ,
215
- )
216
- . new_component :: < LightComponent > ( )
217
- . light
218
- . set (
219
- PointLight {
220
- position : Vec4 :: zero ( ) ,
221
- luminous_flux : Vec4 :: new ( 100.0 , 100.0 , 100.0 , 0.0 ) ,
222
- }
223
- . into ( ) ,
224
- ) ;
225
-
226
- scene
227
- . new_entity_with_transform (
228
- "PointLight Red" . to_string ( ) ,
177
+ "PointLight Cyan 3" . to_string ( ) ,
229
178
Transform {
230
- position : Vec3 :: new ( 0.0 , 0.0 , - 3 .0) ,
179
+ position : Vec3 :: new ( 0.0 , 0.0 , 8 .0) ,
231
180
rotation : Quaternion :: identity ( ) ,
232
181
scale : Vec3 :: one ( ) ,
233
182
} ,
@@ -237,10 +186,49 @@ fn setup(engine: &mut Engine) {
237
186
. set (
238
187
PointLight {
239
188
position : Vec4 :: zero ( ) ,
240
- luminous_flux : Vec4 :: new ( 100 .0, 0 .0, 0 .0, 0.0 ) ,
189
+ luminous_flux : Vec4 :: new ( 0 .0, 160 .0, 145 .0, 0.0 ) * 2.0 ,
241
190
}
242
191
. into ( ) ,
243
192
) ;
244
193
245
194
scene. load ( ) ;
246
195
}
196
+
197
+ #[ derive( Debug ) ]
198
+ struct RotationComponent {
199
+ entity : Weak < Entity > ,
200
+ rotation_speed : Cell < f32 > ,
201
+ }
202
+
203
+ impl Component for RotationComponent {
204
+ fn create ( entity : & Rc < Entity > ) -> Rc < Self >
205
+ where
206
+ Self : Sized ,
207
+ {
208
+ Rc :: new ( Self {
209
+ entity : Rc :: downgrade ( entity) ,
210
+ rotation_speed : Cell :: new ( 30.0 ) ,
211
+ } )
212
+ }
213
+
214
+ fn load ( & self ) { }
215
+
216
+ fn start ( & self ) { }
217
+
218
+ fn update ( & self , _: & Input , delta : f32 ) {
219
+ if let Some ( entity) = self . entity . upgrade ( ) {
220
+ let mut transform = entity. transform . borrow_mut ( ) ;
221
+
222
+ let mut rotation = transform. rotation ;
223
+ rotation = Quaternion :: axis_angle (
224
+ Vec3 :: new ( 0.0 , 0.0 , 1.0 ) ,
225
+ self . rotation_speed . get ( ) . to_radians ( ) * delta,
226
+ ) * rotation;
227
+ transform. rotation = rotation;
228
+ }
229
+ }
230
+
231
+ fn inspector_name ( & self ) -> & ' static str {
232
+ "TimeOfDayComponent"
233
+ }
234
+ }
0 commit comments