@@ -105,12 +105,12 @@ impl re_log_types::Component for ViewCoordinates {
105105}
106106
107107impl ViewCoordinates {
108- /// Default right-handed view coordinates of `re_renderer`: X=Right, Y=Up, Z=Back.
109- pub const RUB : Self = Self ( [ ViewDir :: Right , ViewDir :: Up , ViewDir :: Back ] ) ;
110-
111108 /// Default right-handed pinhole, camera, and image coordinates: X=Right, Y=Down, Z=Forward.
112109 pub const RDF : Self = Self ( [ ViewDir :: Right , ViewDir :: Down , ViewDir :: Forward ] ) ;
113110
111+ /// Default right-handed view coordinates of `re_renderer`: X=Right, Y=Up, Z=Back.
112+ pub const RUB : Self = Self ( [ ViewDir :: Right , ViewDir :: Up , ViewDir :: Back ] ) ;
113+
114114 /// Choses a coordinate system based on just an up-axis.
115115 pub fn from_up_and_handedness ( up : SignedAxis3 , handedness : Handedness ) -> Self {
116116 use ViewDir :: { Back , Down , Forward , Right , Up } ;
@@ -209,13 +209,31 @@ impl ViewCoordinates {
209209 )
210210 }
211211
212- /// Returns a matrix that transforms from RUB to this coordinate system.
212+ /// Returns a matrix that transforms from another coordinate system to this (self) one.
213+ #[ cfg( feature = "glam" ) ]
214+ #[ inline]
215+ pub fn from_other ( & self , other : & Self ) -> glam:: Mat3 {
216+ self . from_rdf ( ) * other. to_rdf ( )
217+ }
218+
219+ /// Returns a matrix that transforms this coordinate system to RDF.
213220 ///
214- /// (RUB : X=Right, Y=Up , Z=Back )
221+ /// (RDF : X=Right, Y=Down , Z=Forward )
215222 #[ cfg( feature = "glam" ) ]
216223 #[ inline]
217- pub fn from_rub ( & self ) -> glam:: Mat3 {
218- self . to_rub ( ) . transpose ( )
224+ pub fn to_rdf ( & self ) -> glam:: Mat3 {
225+ fn rdf ( dir : ViewDir ) -> [ f32 ; 3 ] {
226+ match dir {
227+ ViewDir :: Right => [ 1.0 , 0.0 , 0.0 ] ,
228+ ViewDir :: Left => [ -1.0 , 0.0 , 0.0 ] ,
229+ ViewDir :: Up => [ 0.0 , -1.0 , 0.0 ] ,
230+ ViewDir :: Down => [ 0.0 , 1.0 , 0.0 ] ,
231+ ViewDir :: Back => [ 0.0 , 0.0 , -1.0 ] ,
232+ ViewDir :: Forward => [ 0.0 , 0.0 , 1.0 ] ,
233+ }
234+ }
235+
236+ glam:: Mat3 :: from_cols_array_2d ( & [ rdf ( self . 0 [ 0 ] ) , rdf ( self . 0 [ 1 ] ) , rdf ( self . 0 [ 2 ] ) ] )
219237 }
220238
221239 /// Returns a matrix that transforms from RDF to this coordinate system.
@@ -224,8 +242,36 @@ impl ViewCoordinates {
224242 #[ cfg( feature = "glam" ) ]
225243 #[ inline]
226244 pub fn from_rdf ( & self ) -> glam:: Mat3 {
227- let rub_from_rdf = Self :: RDF . to_rub ( ) ;
228- self . from_rub ( ) * rub_from_rdf
245+ self . to_rdf ( ) . transpose ( )
246+ }
247+
248+ /// Returns a matrix that transforms this coordinate system to RUB.
249+ ///
250+ /// (RUB: X=Right, Y=Up, Z=Back)
251+ #[ cfg( feature = "glam" ) ]
252+ #[ inline]
253+ pub fn to_rub ( & self ) -> glam:: Mat3 {
254+ fn rub ( dir : ViewDir ) -> [ f32 ; 3 ] {
255+ match dir {
256+ ViewDir :: Right => [ 1.0 , 0.0 , 0.0 ] ,
257+ ViewDir :: Left => [ -1.0 , 0.0 , 0.0 ] ,
258+ ViewDir :: Up => [ 0.0 , 1.0 , 0.0 ] ,
259+ ViewDir :: Down => [ 0.0 , -1.0 , 0.0 ] ,
260+ ViewDir :: Back => [ 0.0 , 0.0 , 1.0 ] ,
261+ ViewDir :: Forward => [ 0.0 , 0.0 , -1.0 ] ,
262+ }
263+ }
264+
265+ glam:: Mat3 :: from_cols_array_2d ( & [ rub ( self . 0 [ 0 ] ) , rub ( self . 0 [ 1 ] ) , rub ( self . 0 [ 2 ] ) ] )
266+ }
267+
268+ /// Returns a matrix that transforms from RUB to this coordinate system.
269+ ///
270+ /// (RUB: X=Right, Y=Up, Z=Back)
271+ #[ cfg( feature = "glam" ) ]
272+ #[ inline]
273+ pub fn from_rub ( & self ) -> glam:: Mat3 {
274+ self . to_rub ( ) . transpose ( )
229275 }
230276
231277 /// Returns a quaternion that rotates from RUB to this coordinate system.
@@ -254,31 +300,11 @@ impl ViewCoordinates {
254300 }
255301 }
256302
257- /// Returns a matrix that transforms this coordinate system to RUB.
258- ///
259- /// (RUB: X=Right, Y=Up, Z=Back)
260- #[ cfg( feature = "glam" ) ]
261- #[ inline]
262- pub fn to_rub ( & self ) -> glam:: Mat3 {
263- fn rub ( dir : ViewDir ) -> [ f32 ; 3 ] {
264- match dir {
265- ViewDir :: Right => [ 1.0 , 0.0 , 0.0 ] ,
266- ViewDir :: Left => [ -1.0 , 0.0 , 0.0 ] ,
267- ViewDir :: Up => [ 0.0 , 1.0 , 0.0 ] ,
268- ViewDir :: Down => [ 0.0 , -1.0 , 0.0 ] ,
269- ViewDir :: Back => [ 0.0 , 0.0 , 1.0 ] ,
270- ViewDir :: Forward => [ 0.0 , 0.0 , -1.0 ] ,
271- }
272- }
273-
274- glam:: Mat3 :: from_cols_array_2d ( & [ rub ( self . 0 [ 0 ] ) , rub ( self . 0 [ 1 ] ) , rub ( self . 0 [ 2 ] ) ] )
275- }
276-
277303 #[ cfg( feature = "glam" ) ]
278304 #[ inline]
279305 pub fn handedness ( & self ) -> Option < Handedness > {
280- let to_rub = self . to_rub ( ) ;
281- let det = to_rub . determinant ( ) ;
306+ let to_rdf = self . to_rdf ( ) ;
307+ let det = to_rdf . determinant ( ) ;
282308 if det == -1.0 {
283309 Some ( Handedness :: Left )
284310 } else if det == 0.0 {
0 commit comments