@@ -92,362 +92,6 @@ public static Matrix4x4 toMatrix4x4(this Matrix3 matrix3) {
9292
9393 return matrix ;
9494 }
95-
96- public static Matrix4x4 createCylindricalProjectionTransform (
97- float radius ,
98- float angle ,
99- float perspective = 0.001f ,
100- Axis orientation = Axis . vertical
101- ) {
102- D . assert ( perspective >= 0 && perspective <= 1.0 ) ;
103-
104- Matrix4x4 result = Matrix4x4 . identity ;
105- result [ 3 , 2 ] = - perspective ;
106- result [ 2 , 3 ] = - radius ;
107- result [ 3 , 3 ] = perspective * radius + 1.0f ;
108-
109- result *= (
110- orientation == Axis . horizontal
111- ? rotationY ( angle )
112- : rotationX ( angle )
113- ) * translationValues ( 0.0f , 0.0f , radius ) ;
114-
115- return result ;
116- }
117-
118- public static Matrix4x4 rotationY ( float angle ) {
119- var matrix = Matrix4x4 . zero ;
120- matrix [ 15 ] = 1.0f ;
121- float c = Mathf . Cos ( angle ) ;
122- float s = Mathf . Sin ( angle ) ;
123- matrix [ 0 ] = c ;
124- matrix [ 1 ] = 0.0f ;
125- matrix [ 2 ] = - s ;
126- matrix [ 4 ] = 0.0f ;
127- matrix [ 5 ] = 1.0f ;
128- matrix [ 6 ] = 0.0f ;
129- matrix [ 8 ] = s ;
130- matrix [ 9 ] = 0.0f ;
131- matrix [ 10 ] = c ;
132- matrix [ 3 ] = 0.0f ;
133- matrix [ 7 ] = 0.0f ;
134- matrix [ 11 ] = 0.0f ;
135- return matrix ;
136- }
137-
138- public static Matrix4x4 rotationX ( float angle ) {
139- var matrix = Matrix4x4 . zero ;
140- matrix [ 15 ] = 1.0f ;
141- float c = Mathf . Cos ( angle ) ;
142- float s = Mathf . Sin ( angle ) ;
143- matrix [ 0 ] = 1.0f ;
144- matrix [ 1 ] = 0.0f ;
145- matrix [ 2 ] = 0.0f ;
146- matrix [ 4 ] = 0.0f ;
147- matrix [ 5 ] = c ;
148- matrix [ 6 ] = s ;
149- matrix [ 8 ] = 0.0f ;
150- matrix [ 9 ] = - s ;
151- matrix [ 10 ] = c ;
152- matrix [ 3 ] = 0.0f ;
153- matrix [ 7 ] = 0.0f ;
154- matrix [ 11 ] = 0.0f ;
155- return matrix ;
156- }
157-
158- public static Matrix4x4 translationValues ( float x , float y , float z ) {
159- var matrix = Matrix4x4 . identity ;
160- matrix [ 14 ] = z ;
161- matrix [ 13 ] = y ;
162- matrix [ 12 ] = x ;
163- return matrix ;
164- }
165-
166- public static Matrix4x4 translate ( this Matrix4x4 m , Vector4 x , float y = 0.0f , float z = 0.0f ) {
167- float tw = x . w ;
168- float tx = x . x ;
169- float ty = x . y ;
170- float tz = x . z ;
171-
172- float t1 = m [ 0 ] * tx + m [ 4 ] * ty + m [ 8 ] * tz + m [ 12 ] * tw ;
173- float t2 = m [ 1 ] * tx + m [ 5 ] * ty + m [ 9 ] * tz + m [ 13 ] * tw ;
174- float t3 = m [ 2 ] * tx + m [ 6 ] * ty + m [ 10 ] * tz + m [ 14 ] * tw ;
175- float t4 = m [ 3 ] * tx + m [ 7 ] * ty + m [ 11 ] * tz + m [ 15 ] * tw ;
176- m [ 12 ] = t1 ;
177- m [ 13 ] = t2 ;
178- m [ 14 ] = t3 ;
179- m [ 15 ] = t4 ;
180- return m ;
181- }
182-
183- public static Matrix4x4 translate ( this Matrix4x4 m , Vector3 x , float y = 0.0f , float z = 0.0f ) {
184- float tw = 1.0f ;
185- float tx = x . x ;
186- float ty = x . y ;
187- float tz = x . z ;
188-
189- float t1 = m [ 0 ] * tx + m [ 4 ] * ty + m [ 8 ] * tz + m [ 12 ] * tw ;
190- float t2 = m [ 1 ] * tx + m [ 5 ] * ty + m [ 9 ] * tz + m [ 13 ] * tw ;
191- float t3 = m [ 2 ] * tx + m [ 6 ] * ty + m [ 10 ] * tz + m [ 14 ] * tw ;
192- float t4 = m [ 3 ] * tx + m [ 7 ] * ty + m [ 11 ] * tz + m [ 15 ] * tw ;
193- m [ 12 ] = t1 ;
194- m [ 13 ] = t2 ;
195- m [ 14 ] = t3 ;
196- m [ 15 ] = t4 ;
197- return m ;
198- }
199-
200- public static Matrix4x4 translate ( this Matrix4x4 m , float x , float y = 0.0f , float z = 0.0f ) {
201- float tw = 1.0f ;
202- float tx = x ;
203- float ty = y ;
204- float tz = z ;
205-
206- float t1 = m [ 0 ] * tx + m [ 4 ] * ty + m [ 8 ] * tz + m [ 12 ] * tw ;
207- float t2 = m [ 1 ] * tx + m [ 5 ] * ty + m [ 9 ] * tz + m [ 13 ] * tw ;
208- float t3 = m [ 2 ] * tx + m [ 6 ] * ty + m [ 10 ] * tz + m [ 14 ] * tw ;
209- float t4 = m [ 3 ] * tx + m [ 7 ] * ty + m [ 11 ] * tz + m [ 15 ] * tw ;
210- m [ 12 ] = t1 ;
211- m [ 13 ] = t2 ;
212- m [ 14 ] = t3 ;
213- m [ 15 ] = t4 ;
214- return m ;
215- }
216-
217- public static void multiply ( this Matrix3 m , Matrix3 arg ) {
218- float m00 = m [ 0 ] ;
219- float m01 = m [ 3 ] ;
220- float m02 = m [ 6 ] ;
221- float m10 = m [ 1 ] ;
222- float m11 = m [ 4 ] ;
223- float m12 = m [ 7 ] ;
224- float m20 = m [ 2 ] ;
225- float m21 = m [ 5 ] ;
226- float m22 = m [ 8 ] ;
227- List < float > argStorage = new List < float > {
228- arg [ 0 ] , arg [ 1 ] , arg [ 2 ] , arg [ 3 ] , arg [ 4 ] , arg [ 5 ] , arg [ 6 ] , arg [ 7 ] , arg [ 8 ]
229- } ;
230- float n00 = argStorage [ 0 ] ;
231- float n01 = argStorage [ 3 ] ;
232- float n02 = argStorage [ 6 ] ;
233- float n10 = argStorage [ 1 ] ;
234- float n11 = argStorage [ 4 ] ;
235- float n12 = argStorage [ 7 ] ;
236- float n20 = argStorage [ 2 ] ;
237- float n21 = argStorage [ 5 ] ;
238- float n22 = argStorage [ 8 ] ;
239- m [ 0 ] = ( m00 * n00 ) + ( m01 * n10 ) + ( m02 * n20 ) ;
240- m [ 3 ] = ( m00 * n01 ) + ( m01 * n11 ) + ( m02 * n21 ) ;
241- m [ 6 ] = ( m00 * n02 ) + ( m01 * n12 ) + ( m02 * n22 ) ;
242- m [ 1 ] = ( m10 * n00 ) + ( m11 * n10 ) + ( m12 * n20 ) ;
243- m [ 4 ] = ( m10 * n01 ) + ( m11 * n11 ) + ( m12 * n21 ) ;
244- m [ 7 ] = ( m10 * n02 ) + ( m11 * n12 ) + ( m12 * n22 ) ;
245- m [ 2 ] = ( m20 * n00 ) + ( m21 * n10 ) + ( m22 * n20 ) ;
246- m [ 5 ] = ( m20 * n01 ) + ( m21 * n11 ) + ( m22 * n21 ) ;
247- m [ 8 ] = ( m20 * n02 ) + ( m21 * n12 ) + ( m22 * n22 ) ;
248- }
249-
250- public static void multiply ( this Matrix4x4 m , Matrix4x4 arg ) {
251- float m00 = m [ 0 ] ;
252- float m01 = m [ 4 ] ;
253- float m02 = m [ 8 ] ;
254- float m03 = m [ 12 ] ;
255- float m10 = m [ 1 ] ;
256- float m11 = m [ 5 ] ;
257- float m12 = m [ 9 ] ;
258- float m13 = m [ 13 ] ;
259- float m20 = m [ 2 ] ;
260- float m21 = m [ 6 ] ;
261- float m22 = m [ 10 ] ;
262- float m23 = m [ 14 ] ;
263- float m30 = m [ 3 ] ;
264- float m31 = m [ 7 ] ;
265- float m32 = m [ 11 ] ;
266- float m33 = m [ 15 ] ;
267- List < float > argStorage = new List < float > {
268- arg . m00 , arg . m01 , arg . m02 , arg . m03 ,
269- arg . m10 , arg . m11 , arg . m12 , arg . m13 ,
270- arg . m20 , arg . m21 , arg . m22 , arg . m23 ,
271- arg . m30 , arg . m31 , arg . m32 , arg . m33 ,
272- } ;
273- float n00 = argStorage [ 0 ] ;
274- float n01 = argStorage [ 4 ] ;
275- float n02 = argStorage [ 8 ] ;
276- float n03 = argStorage [ 12 ] ;
277- float n10 = argStorage [ 1 ] ;
278- float n11 = argStorage [ 5 ] ;
279- float n12 = argStorage [ 9 ] ;
280- float n13 = argStorage [ 13 ] ;
281- float n20 = argStorage [ 2 ] ;
282- float n21 = argStorage [ 6 ] ;
283- float n22 = argStorage [ 10 ] ;
284- float n23 = argStorage [ 14 ] ;
285- float n30 = argStorage [ 3 ] ;
286- float n31 = argStorage [ 7 ] ;
287- float n32 = argStorage [ 11 ] ;
288- float n33 = argStorage [ 15 ] ;
289- m [ 0 ] = ( m00 * n00 ) + ( m01 * n10 ) + ( m02 * n20 ) + ( m03 * n30 ) ;
290- m [ 4 ] = ( m00 * n01 ) + ( m01 * n11 ) + ( m02 * n21 ) + ( m03 * n31 ) ;
291- m [ 8 ] = ( m00 * n02 ) + ( m01 * n12 ) + ( m02 * n22 ) + ( m03 * n32 ) ;
292- m [ 12 ] = ( m00 * n03 ) + ( m01 * n13 ) + ( m02 * n23 ) + ( m03 * n33 ) ;
293- m [ 1 ] = ( m10 * n00 ) + ( m11 * n10 ) + ( m12 * n20 ) + ( m13 * n30 ) ;
294- m [ 5 ] = ( m10 * n01 ) + ( m11 * n11 ) + ( m12 * n21 ) + ( m13 * n31 ) ;
295- m [ 9 ] = ( m10 * n02 ) + ( m11 * n12 ) + ( m12 * n22 ) + ( m13 * n32 ) ;
296- m [ 13 ] = ( m10 * n03 ) + ( m11 * n13 ) + ( m12 * n23 ) + ( m13 * n33 ) ;
297- m [ 2 ] = ( m20 * n00 ) + ( m21 * n10 ) + ( m22 * n20 ) + ( m23 * n30 ) ;
298- m [ 6 ] = ( m20 * n01 ) + ( m21 * n11 ) + ( m22 * n21 ) + ( m23 * n31 ) ;
299- m [ 10 ] = ( m20 * n02 ) + ( m21 * n12 ) + ( m22 * n22 ) + ( m23 * n32 ) ;
300- m [ 14 ] = ( m20 * n03 ) + ( m21 * n13 ) + ( m22 * n23 ) + ( m23 * n33 ) ;
301- m [ 3 ] = ( m30 * n00 ) + ( m31 * n10 ) + ( m32 * n20 ) + ( m33 * n30 ) ;
302- m [ 7 ] = ( m30 * n01 ) + ( m31 * n11 ) + ( m32 * n21 ) + ( m33 * n31 ) ;
303- m [ 11 ] = ( m30 * n02 ) + ( m31 * n12 ) + ( m32 * n22 ) + ( m33 * n32 ) ;
304- m [ 15 ] = ( m30 * n03 ) + ( m31 * n13 ) + ( m32 * n23 ) + ( m33 * n33 ) ;
305- }
306-
307- public static void scale ( this Matrix4x4 m , object x , float ? y = null , float ? z = null ) {
308- float sx = 0f ;
309- float sy = 0f ;
310- float sz = 0f ;
311- float sw = x is Vector4 _xv4 ? _xv4 . w : 1.0f ;
312- if ( x is Vector3 xv3 ) {
313- sx = xv3 . x ;
314- sy = xv3 . y ;
315- sz = xv3 . z ;
316- }
317- else if ( x is Vector4 xv4 ) {
318- sx = xv4 . x ;
319- sy = xv4 . y ;
320- sz = xv4 . z ;
321- }
322- else if ( x is float xf ) {
323- sx = xf ;
324- sy = y ?? xf ;
325- sz = z ?? xf ;
326- }
327-
328- m [ 0 ] *= sx ;
329- m [ 1 ] *= sx ;
330- m [ 2 ] *= sx ;
331- m [ 3 ] *= sx ;
332- m [ 4 ] *= sy ;
333- m [ 5 ] *= sy ;
334- m [ 6 ] *= sy ;
335- m [ 7 ] *= sy ;
336- m [ 8 ] *= sz ;
337- m [ 9 ] *= sz ;
338- m [ 10 ] *= sz ;
339- m [ 11 ] *= sz ;
340- m [ 12 ] *= sw ;
341- m [ 13 ] *= sw ;
342- m [ 14 ] *= sw ;
343- m [ 15 ] *= sw ;
344- }
345-
346- public static Rect inverseTransformRect ( Matrix4x4 transform , Rect rect ) {
347- D . assert ( rect != null ) ;
348- D . assert ( transform . determinant != 0.0 ) ;
349- if ( transform == Matrix4x4 . identity )
350- return rect ;
351- var copy = transform ;
352- copy . invert ( ) ;
353- transform = copy ;
354- return transformRect ( transform , rect ) ;
355- }
356-
357- public static float invert ( this Matrix4x4 m ) {
358- return m . copyInverse ( ) ;
359- }
360-
361- public static float copyInverse ( this Matrix4x4 m ) {
362- List < float > argStorage = new List < float > {
363- m . m00 , m . m01 , m . m02 , m . m03 ,
364- m . m10 , m . m11 , m . m12 , m . m13 ,
365- m . m20 , m . m21 , m . m22 , m . m23 ,
366- m . m30 , m . m31 , m . m32 , m . m33 ,
367- } ;
368- float a00 = argStorage [ 0 ] ;
369- float a01 = argStorage [ 1 ] ;
370- float a02 = argStorage [ 2 ] ;
371- float a03 = argStorage [ 3 ] ;
372- float a10 = argStorage [ 4 ] ;
373- float a11 = argStorage [ 5 ] ;
374- float a12 = argStorage [ 6 ] ;
375- float a13 = argStorage [ 7 ] ;
376- float a20 = argStorage [ 8 ] ;
377- float a21 = argStorage [ 9 ] ;
378- float a22 = argStorage [ 10 ] ;
379- float a23 = argStorage [ 11 ] ;
380- float a30 = argStorage [ 12 ] ;
381- float a31 = argStorage [ 13 ] ;
382- float a32 = argStorage [ 14 ] ;
383- float a33 = argStorage [ 15 ] ;
384- float b00 = a00 * a11 - a01 * a10 ;
385- float b01 = a00 * a12 - a02 * a10 ;
386- float b02 = a00 * a13 - a03 * a10 ;
387- float b03 = a01 * a12 - a02 * a11 ;
388- float b04 = a01 * a13 - a03 * a11 ;
389- float b05 = a02 * a13 - a03 * a12 ;
390- float b06 = a20 * a31 - a21 * a30 ;
391- float b07 = a20 * a32 - a22 * a30 ;
392- float b08 = a20 * a33 - a23 * a30 ;
393- float b09 = a21 * a32 - a22 * a31 ;
394- float b10 = a21 * a33 - a23 * a31 ;
395- float b11 = a22 * a33 - a23 * a32 ;
396- float det =
397- ( b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06 ) ;
398- if ( det == 0.0f ) {
399- m [ 0 ] = argStorage [ 0 ] ;
400- m [ 1 ] = argStorage [ 1 ] ;
401- m [ 2 ] = argStorage [ 2 ] ;
402- m [ 3 ] = argStorage [ 3 ] ;
403- m [ 4 ] = argStorage [ 4 ] ;
404- m [ 5 ] = argStorage [ 5 ] ;
405- m [ 6 ] = argStorage [ 6 ] ;
406- m [ 7 ] = argStorage [ 7 ] ;
407- m [ 8 ] = argStorage [ 8 ] ;
408- m [ 9 ] = argStorage [ 9 ] ;
409- m [ 10 ] = argStorage [ 10 ] ;
410- m [ 11 ] = argStorage [ 11 ] ;
411- m [ 12 ] = argStorage [ 12 ] ;
412- m [ 13 ] = argStorage [ 13 ] ;
413- m [ 14 ] = argStorage [ 14 ] ;
414- m [ 15 ] = argStorage [ 15 ] ;
415- return 0.0f ;
416- }
417-
418- float invDet = 1.0f / det ;
419- m [ 0 ] = ( a11 * b11 - a12 * b10 + a13 * b09 ) * invDet ;
420- m [ 1 ] = ( - a01 * b11 + a02 * b10 - a03 * b09 ) * invDet ;
421- m [ 2 ] = ( a31 * b05 - a32 * b04 + a33 * b03 ) * invDet ;
422- m [ 3 ] = ( - a21 * b05 + a22 * b04 - a23 * b03 ) * invDet ;
423- m [ 4 ] = ( - a10 * b11 + a12 * b08 - a13 * b07 ) * invDet ;
424- m [ 5 ] = ( a00 * b11 - a02 * b08 + a03 * b07 ) * invDet ;
425- m [ 6 ] = ( - a30 * b05 + a32 * b02 - a33 * b01 ) * invDet ;
426- m [ 7 ] = ( a20 * b05 - a22 * b02 + a23 * b01 ) * invDet ;
427- m [ 8 ] = ( a10 * b10 - a11 * b08 + a13 * b06 ) * invDet ;
428- m [ 9 ] = ( - a00 * b10 + a01 * b08 - a03 * b06 ) * invDet ;
429- m [ 10 ] = ( a30 * b04 - a31 * b02 + a33 * b00 ) * invDet ;
430- m [ 11 ] = ( - a20 * b04 + a21 * b02 - a23 * b00 ) * invDet ;
431- m [ 12 ] = ( - a10 * b09 + a11 * b07 - a12 * b06 ) * invDet ;
432- m [ 13 ] = ( a00 * b09 - a01 * b07 + a02 * b06 ) * invDet ;
433- m [ 14 ] = ( - a30 * b03 + a31 * b01 - a32 * b00 ) * invDet ;
434- m [ 15 ] = ( a20 * b03 - a21 * b01 + a22 * b00 ) * invDet ;
435- return det ;
436- }
437-
438- public static Matrix3 toMatrix3 ( this Matrix4x4 m ) {
439- var m3 = Matrix3 . I ( ) ;
440- m3 [ 0 ] = m [ 0 ] ;
441- m3 [ 1 ] = m [ 1 ] ;
442- m3 [ 2 ] = m [ 2 ] ;
443- m3 [ 3 ] = m [ 3 ] ;
444- m3 [ 4 ] = m [ 4 ] ;
445- m3 [ 5 ] = m [ 5 ] ;
446- m3 [ 6 ] = m [ 6 ] ;
447- m3 [ 7 ] = m [ 7 ] ;
448- m3 [ 8 ] = m [ 8 ] ;
449- return m3 ;
450- }
45195 }
45296
45397 public class TransformProperty : DiagnosticsProperty < Matrix3 > {
0 commit comments