@@ -106,6 +106,11 @@ fn az_alt<B>(az: Angle, alt: Angle) -> SphericalVec<B> {
106106 spherical ( 1.0 , az, alt)
107107}
108108
109+ /// Helper to create a translation from a point
110+ fn origin < S , D > ( o : Point3 < D > ) -> Mat4 < S , D > {
111+ translate ( o. to ( ) . to_vec ( ) ) . to ( )
112+ }
113+
109114//
110115// Inherent impls
111116//
@@ -379,8 +384,7 @@ impl PitchYawRoll {
379384
380385 /// Returns the matrix from view to world space.
381386 pub fn view_to_world ( & self ) -> Mat4 < View , World > {
382- let trans: Mat4 < World , World > = translate ( self . pos . to_vec ( ) . to ( ) ) . to ( ) ;
383- self . rot . then ( & trans)
387+ self . rot . then ( & origin ( self . pos ) )
384388 }
385389}
386390
@@ -403,10 +407,10 @@ impl Transform for FirstPerson {
403407 let right = Vec3 :: Y . cross ( & fwd_move) ;
404408
405409 // World-to-view is inverse of camera's world transform
406- let transl = translate ( -pos. to_vec ( ) . to ( ) ) ;
407- let orient = orient_z ( fwd. to ( ) , right) . transpose ( ) ;
410+ let origin : Mat4 < World > = origin ( -pos. to ( ) ) ;
411+ let orient: Mat4 < _ , View > = orient_z ( fwd. to ( ) , right) . transpose ( ) . to ( ) ;
408412
409- transl . then ( & orient) . to ( )
413+ origin . then ( & orient)
410414 }
411415}
412416
@@ -419,7 +423,7 @@ impl Transform for Orbit {
419423
420424 // TODO Work out how and whether this is the correct inverse
421425 // of the view-to-world transform
422- translate ( self . target . to_vec ( ) . to ( ) ) // to world-space target
426+ origin :: < ( ) , ( ) > ( self . target . to ( ) )
423427 . then ( & rotate_y ( self . dir . az ( ) ) ) // to world-space az
424428 . then ( & rotate_x ( self . dir . alt ( ) ) ) // to world-space alt
425429 . then ( & translate ( self . dir . r ( ) * Vec3 :: Z ) ) // view space
@@ -429,10 +433,9 @@ impl Transform for Orbit {
429433
430434impl Transform for PitchYawRoll {
431435 fn world_to_view ( & self ) -> Mat4 < World , View > {
432- let trans = translate ( -self . pos . to_vec ( ) . to ( ) ) . to ( ) ;
433- let rot = self . rot . transpose ( ) ;
434-
435- trans. then ( & rot)
436+ let origin = origin ( -self . pos ) ;
437+ let orient = self . rot . transpose ( ) ;
438+ origin. then ( & orient)
436439 }
437440}
438441
0 commit comments