@@ -192,6 +192,32 @@ public static Fixed3x3 CreateShear(Fixed64 shX, Fixed64 shY, Fixed64 shZ)
192
192
) ;
193
193
}
194
194
195
+ /// <summary>
196
+ /// Creates a scaling matrix that applies a uniform or non-uniform scale transformation.
197
+ /// </summary>
198
+ /// <param name="scale">The scale factors along the X, Y, and Z axes.</param>
199
+ /// <returns>A 3x3 scaling matrix.</returns>
200
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
201
+ public static Fixed3x3 CreateScale ( Vector3d scale )
202
+ {
203
+ return new Fixed3x3 (
204
+ scale . x , Fixed64 . Zero , Fixed64 . Zero ,
205
+ Fixed64 . Zero , scale . y , Fixed64 . Zero ,
206
+ Fixed64 . Zero , Fixed64 . Zero , scale . z
207
+ ) ;
208
+ }
209
+
210
+ /// <summary>
211
+ /// Creates a uniform scaling matrix with the same scale factor on all axes.
212
+ /// </summary>
213
+ /// <param name="scaleFactor">The uniform scale factor.</param>
214
+ /// <returns>A 3x3 scaling matrix with uniform scaling.</returns>
215
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
216
+ public static Fixed3x3 CreateScale ( Fixed64 scaleFactor )
217
+ {
218
+ return CreateScale ( new Vector3d ( scaleFactor , scaleFactor , scaleFactor ) ) ;
219
+ }
220
+
195
221
/// <summary>
196
222
/// Normalizes the basis vectors of a 3x3 matrix to ensure they are orthogonal and unit length.
197
223
/// </summary>
@@ -317,7 +343,7 @@ public static Vector3d ExtractLossyScale(Fixed3x3 matrix)
317
343
318
344
#endregion
319
345
320
- #region Matrix Operations
346
+ #region Static Matrix Operations
321
347
322
348
/// <summary>
323
349
/// Linearly interpolates between two matrices.
@@ -380,11 +406,46 @@ public static bool Invert(Fixed3x3 matrix, out Fixed3x3? result)
380
406
return true ;
381
407
}
382
408
409
+ /// <summary>
410
+ /// Transforms a direction vector from local space to world space using this transformation matrix.
411
+ /// Ignores translation.
412
+ /// </summary>
413
+ /// <param name="matrix">The transformation matrix.</param>
414
+ /// <param name="direction">The local-space direction vector.</param>
415
+ /// <returns>The transformed direction in world space.</returns>
416
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
417
+ public static Vector3d TransformDirection ( Fixed3x3 matrix , Vector3d direction )
418
+ {
419
+ return new Vector3d (
420
+ matrix . m00 * direction . x + matrix . m01 * direction . y + matrix . m02 * direction . z ,
421
+ matrix . m10 * direction . x + matrix . m11 * direction . y + matrix . m12 * direction . z ,
422
+ matrix . m20 * direction . x + matrix . m21 * direction . y + matrix . m22 * direction . z
423
+ ) ;
424
+ }
425
+
426
+ /// <summary>
427
+ /// Transforms a direction from world space into the local space of the matrix.
428
+ /// Ignores translation.
429
+ /// </summary>
430
+ /// <param name="matrix">The transformation matrix.</param>
431
+ /// <param name="direction">The world-space direction.</param>
432
+ /// <returns>The transformed local-space direction.</returns>
433
+ public static Vector3d InverseTransformDirection ( Fixed3x3 matrix , Vector3d direction )
434
+ {
435
+ if ( ! Invert ( matrix , out Fixed3x3 ? inverseMatrix ) || ! inverseMatrix . HasValue )
436
+ throw new InvalidOperationException ( "Matrix is not invertible." ) ;
437
+
438
+ return new Vector3d (
439
+ inverseMatrix . Value . m00 * direction . x + inverseMatrix . Value . m01 * direction . y + inverseMatrix . Value . m02 * direction . z ,
440
+ inverseMatrix . Value . m10 * direction . x + inverseMatrix . Value . m11 * direction . y + inverseMatrix . Value . m12 * direction . z ,
441
+ inverseMatrix . Value . m20 * direction . x + inverseMatrix . Value . m21 * direction . y + inverseMatrix . Value . m22 * direction . z
442
+ ) ;
443
+ }
444
+
383
445
#endregion
384
446
385
447
#region Operators
386
448
387
-
388
449
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
389
450
public static Fixed3x3 operator - ( Fixed3x3 a , Fixed3x3 b )
390
451
{
0 commit comments