@@ -99,6 +99,24 @@ pub fn push_constants_to_bytes(push_constants: &PushConstant) -> &[u32] {
9999 return bytes;
100100}
101101
102+ fn make_transform (
103+ translate : [ f32 ; 3 ] ,
104+ angle : f32 ,
105+ scale : f32 ,
106+ ) -> [ [ f32 ; 4 ] ; 4 ] {
107+ let c = angle. cos ( ) * scale;
108+ let s = angle. sin ( ) * scale;
109+
110+ let [ x, y, z] = translate;
111+
112+ return [
113+ [ c, 0.0 , s, 0.0 ] ,
114+ [ 0.0 , scale, 0.0 , 0.0 ] ,
115+ [ -s, 0.0 , c, 0.0 ] ,
116+ [ x, y, z, 1.0 ] ,
117+ ] ;
118+ }
119+
102120// --------------------------------- COMPONENT ---------------------------------
103121
104122pub struct PushConstantsExample {
@@ -190,6 +208,7 @@ impl Component for PushConstantsExample {
190208 }
191209
192210 fn on_event ( & mut self , event : lambda:: core:: events:: Events ) {
211+ // Only handle resizes.
193212 match event {
194213 lambda:: core:: events:: Events :: Window { event, issued_at } => {
195214 match event {
@@ -216,16 +235,12 @@ impl Component for PushConstantsExample {
216235 render_context : & mut lambda:: core:: render:: RenderContext ,
217236 ) -> Vec < lambda:: core:: render:: command:: RenderCommand > {
218237 self . frame_number += 1 ;
219- let mut camera = [ 0.0 , 0.0 , -2.0 ] ;
238+ let camera = [ 0.0 , 0.0 , -2.0 ] ;
220239 let view: [ [ f32 ; 4 ] ; 4 ] = matrix:: translation_matrix ( camera) ;
221240
222241 // Create a projection matrix.
223- let mut projection: [ [ f32 ; 4 ] ; 4 ] = matrix:: perspective_matrix (
224- 0.25 ,
225- ( self . width / self . height ) as f32 ,
226- 0.1 ,
227- 200.0 ,
228- ) ;
242+ let projection: [ [ f32 ; 4 ] ; 4 ] =
243+ matrix:: perspective_matrix ( 0.25 , ( 4 / 3 ) as f32 , 0.1 , 100.0 ) ;
229244
230245 // Rotate model.
231246 let model: [ [ f32 ; 4 ] ; 4 ] = matrix:: rotate_matrix (
@@ -236,6 +251,8 @@ impl Component for PushConstantsExample {
236251
237252 // Create render matrix.
238253 let mesh_matrix = projection. multiply ( & view) . multiply ( & model) ;
254+ let mesh_matrix =
255+ make_transform ( [ 0.0 , 0.0 , 0.5 ] , self . frame_number as f32 * 0.01 , 0.5 ) ;
239256
240257 // Create viewport.
241258 let viewport =
@@ -245,7 +262,7 @@ impl Component for PushConstantsExample {
245262 . render_pipeline
246263 . expect ( "No render pipeline actively set for rendering." ) ;
247264
248- let mut commands = vec ! [
265+ return vec ! [
249266 RenderCommand :: SetViewports {
250267 start_at: 0 ,
251268 viewports: vec![ viewport. clone( ) ] ,
@@ -280,11 +297,8 @@ impl Component for PushConstantsExample {
280297 RenderCommand :: Draw {
281298 vertices: 0 ..self . mesh. as_ref( ) . unwrap( ) . vertices( ) . len( ) as u32 ,
282299 } ,
300+ RenderCommand :: EndRenderPass ,
283301 ] ;
284-
285- commands. push ( RenderCommand :: EndRenderPass ) ;
286-
287- return commands;
288302 }
289303}
290304
0 commit comments