@@ -108,14 +108,15 @@ pub fn push_constants_to_bytes(push_constants: &PushConstant) -> &[u32] {
108108
109109// --------------------------------- COMPONENT ---------------------------------
110110
111+ const ROTATION_TURNS_PER_SECOND : f32 = 0.12 ;
112+
111113pub struct PushConstantsExample {
112- frame_number : u64 ,
114+ elapsed_seconds : f32 ,
113115 shader : Shader ,
114116 fs : Shader ,
115117 mesh : Option < Mesh > ,
116118 render_pipeline : Option < ResourceId > ,
117119 render_pass : Option < ResourceId > ,
118- last_frame : std:: time:: Duration ,
119120 width : u32 ,
120121 height : u32 ,
121122}
@@ -227,34 +228,33 @@ impl Component<ComponentResult, String> for PushConstantsExample {
227228 return Ok ( ComponentResult :: Success ) ;
228229 }
229230
230- /// Update the frame number every frame.
231+ /// Update elapsed time every frame.
231232 fn on_update (
232233 & mut self ,
233234 last_frame : & std:: time:: Duration ,
234235 ) -> Result < ComponentResult , String > {
235- self . last_frame = * last_frame;
236- self . frame_number += 1 ;
236+ self . elapsed_seconds += last_frame. as_secs_f32 ( ) ;
237237 return Ok ( ComponentResult :: Success ) ;
238238 }
239239
240240 fn on_render (
241241 & mut self ,
242242 render_context : & mut lambda:: render:: RenderContext ,
243243 ) -> Vec < lambda:: render:: command:: RenderCommand > {
244- self . frame_number += 1 ;
245244 let camera = SimpleCamera {
246245 position : [ 0.0 , 0.0 , 3.0 ] ,
247246 field_of_view_in_turns : 0.25 ,
248247 near_clipping_plane : 0.1 ,
249248 far_clipping_plane : 100.0 ,
250249 } ;
250+ let angle_in_turns = ROTATION_TURNS_PER_SECOND * self . elapsed_seconds ;
251251 let mesh_matrix = compute_model_view_projection_matrix_about_pivot (
252252 & camera,
253253 self . width . max ( 1 ) ,
254254 self . height . max ( 1 ) ,
255255 [ 0.0 , -1.0 / 3.0 , 0.0 ] ,
256256 [ 0.0 , 1.0 , 0.0 ] ,
257- 0.001 * self . frame_number as f32 ,
257+ angle_in_turns ,
258258 0.5 ,
259259 [ 0.0 , 1.0 / 3.0 , 0.0 ] ,
260260 ) ;
@@ -329,10 +329,9 @@ impl Default for PushConstantsExample {
329329 let fs = builder. build ( triangle_fragment_shader) ;
330330
331331 return Self {
332- frame_number : 0 ,
332+ elapsed_seconds : 0. 0,
333333 shader,
334334 fs,
335- last_frame : std:: time:: Duration :: from_secs ( 0 ) ,
336335 mesh : None ,
337336 render_pipeline : None ,
338337 render_pass : None ,
0 commit comments