-
Notifications
You must be signed in to change notification settings - Fork 1
/
3DTransform.pck.st
3076 lines (2515 loc) · 91.6 KB
/
3DTransform.pck.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'From Cuis 4.2 of 25 July 2013 [latest update: #2400] on 6 July 2015 at 1:38:12.630297 pm'!
'Description Based on 3DTransform-pbm.19.mcz'!
!provides: '3DTransform' 1 1!
!requires: 'FFI' 1 8 nil!
!classDefinition: #CatmullRom category: #'3DTransform-Vectors'!
Object subclass: #CatmullRom
instanceVariableNames: 'p1 p2 p3 p4'
classVariableNames: ''
poolDictionaries: ''
category: '3DTransform-Vectors'!
!classDefinition: 'CatmullRom class' category: #'3DTransform-Vectors'!
CatmullRom class
instanceVariableNames: ''!
!classDefinition: #Vector category: #'3DTransform-Vectors'!
FloatArray variableWordSubclass: #Vector
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: '3DTransform-Vectors'!
!classDefinition: 'Vector class' category: #'3DTransform-Vectors'!
Vector class
instanceVariableNames: ''!
!classDefinition: #Matrix4x4 category: #'3DTransform-Vectors'!
Vector variableWordSubclass: #Matrix4x4
instanceVariableNames: ''
classVariableNames: 'IdentityMatrix ZeroMatrix'
poolDictionaries: ''
category: '3DTransform-Vectors'!
!classDefinition: 'Matrix4x4 class' category: #'3DTransform-Vectors'!
Matrix4x4 class
instanceVariableNames: ''!
!classDefinition: #Quaternion category: #'3DTransform-Vectors'!
Vector variableWordSubclass: #Quaternion
instanceVariableNames: ''
classVariableNames: 'QuaternionIdentity'
poolDictionaries: ''
category: '3DTransform-Vectors'!
!classDefinition: 'Quaternion class' category: #'3DTransform-Vectors'!
Quaternion class
instanceVariableNames: ''!
!classDefinition: #Vector2 category: #'3DTransform-Vectors'!
Vector variableWordSubclass: #Vector2
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: '3DTransform-Vectors'!
!classDefinition: 'Vector2 class' category: #'3DTransform-Vectors'!
Vector2 class
instanceVariableNames: ''!
!classDefinition: #Vector3 category: #'3DTransform-Vectors'!
Vector variableWordSubclass: #Vector3
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: '3DTransform-Vectors'!
!classDefinition: 'Vector3 class' category: #'3DTransform-Vectors'!
Vector3 class
instanceVariableNames: ''!
!classDefinition: #Vector4 category: #'3DTransform-Vectors'!
Vector variableWordSubclass: #Vector4
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: '3DTransform-Vectors'!
!classDefinition: 'Vector4 class' category: #'3DTransform-Vectors'!
Vector4 class
instanceVariableNames: ''!
!classDefinition: #VectorArray category: #'3DTransform-Arrays'!
Vector variableWordSubclass: #VectorArray
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: '3DTransform-Arrays'!
!classDefinition: 'VectorArray class' category: #'3DTransform-Arrays'!
VectorArray class
instanceVariableNames: ''!
!classDefinition: #MatrixArray category: #'3DTransform-Arrays'!
VectorArray variableWordSubclass: #MatrixArray
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: '3DTransform-Arrays'!
!classDefinition: 'MatrixArray class' category: #'3DTransform-Arrays'!
MatrixArray class
instanceVariableNames: ''!
!classDefinition: #Matrix4x4Array category: #'3DTransform-Arrays'!
MatrixArray variableWordSubclass: #Matrix4x4Array
instanceVariableNames: ''
classVariableNames: 'Zero4x4Matrix'
poolDictionaries: ''
category: '3DTransform-Arrays'!
!classDefinition: 'Matrix4x4Array class' category: #'3DTransform-Arrays'!
Matrix4x4Array class
instanceVariableNames: ''!
!classDefinition: #Texture2Array category: #'3DTransform-Arrays'!
VectorArray variableWordSubclass: #Texture2Array
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: '3DTransform-Arrays'!
!classDefinition: 'Texture2Array class' category: #'3DTransform-Arrays'!
Texture2Array class
instanceVariableNames: ''!
!classDefinition: #Vector2Array category: #'3DTransform-Arrays'!
VectorArray variableWordSubclass: #Vector2Array
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: '3DTransform-Arrays'!
!classDefinition: 'Vector2Array class' category: #'3DTransform-Arrays'!
Vector2Array class
instanceVariableNames: ''!
!classDefinition: #Vector3Array category: #'3DTransform-Arrays'!
VectorArray variableWordSubclass: #Vector3Array
instanceVariableNames: ''
classVariableNames: 'ZeroVertex'
poolDictionaries: ''
category: '3DTransform-Arrays'!
!classDefinition: 'Vector3Array class' category: #'3DTransform-Arrays'!
Vector3Array class
instanceVariableNames: ''!
!classDefinition: #VectorColor3Array category: #'3DTransform-Arrays'!
VectorArray variableWordSubclass: #VectorColor3Array
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: '3DTransform-Arrays'!
!classDefinition: 'VectorColor3Array class' category: #'3DTransform-Arrays'!
VectorColor3Array class
instanceVariableNames: ''!
!classDefinition: #VectorColor4Array category: #'3DTransform-Arrays'!
VectorArray variableWordSubclass: #VectorColor4Array
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: '3DTransform-Arrays'!
!classDefinition: 'VectorColor4Array class' category: #'3DTransform-Arrays'!
VectorColor4Array class
instanceVariableNames: ''!
!classDefinition: #VectorRotationArray category: #'3DTransform-Arrays'!
VectorArray variableWordSubclass: #VectorRotationArray
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: '3DTransform-Arrays'!
!classDefinition: 'VectorRotationArray class' category: #'3DTransform-Arrays'!
VectorRotationArray class
instanceVariableNames: ''!
!classDefinition: #VectorColor category: #'3DTransform-Vectors'!
Vector variableWordSubclass: #VectorColor
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: '3DTransform-Vectors'!
!classDefinition: 'VectorColor class' category: #'3DTransform-Vectors'!
VectorColor class
instanceVariableNames: ''!
!classDefinition: #VectorColor3 category: #'3DTransform-Vectors'!
Vector variableWordSubclass: #VectorColor3
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: '3DTransform-Vectors'!
!classDefinition: 'VectorColor3 class' category: #'3DTransform-Vectors'!
VectorColor3 class
instanceVariableNames: ''!
!CatmullRom commentStamp: 'das 8/1/2006 16:30' prior: 0!
Simple Catmull-Rom spline object. Simply seed it with four vectors of any dimensionality, then ask for the interpolated value with CatmullRom>>at:t where t is a value between 0.0 and 1.0.!
!Vector commentStamp: '<historical>' prior: 0!
I am the superclass for all floating point vector objects in Croquet.!
!Matrix4x4 commentStamp: '<historical>' prior: 0!
I represent a standard 4x4 transformation matrix used throughout 3D graphics.!
!Quaternion commentStamp: '<historical>' prior: 0!
I represent general 3d rotations by using Unit-Quaternions. Unit-Quaternions are one of the best available representation for rotations in computer graphics because they provide an easy way of doing arithmetic with them and also because they allow us to use spherical linear interpolation (so-called "slerps") of rotations.
Indexed Variables:
a <Float> the real part of the quaternion
b <Float> the first imaginary part of the quaternion
c <Float> the second imaginary part of the quaternion
d <Float> the third imaginary part of the quaternion
!
!Vector2 commentStamp: '<historical>' prior: 0!
I represent simple 2D coordinates in Croquet. I may be used to represent both, 2D points and 2D texture coordinates. !
!Vector3 commentStamp: '<historical>' prior: 0!
I represent simple 3D coordinates, used throughout Croquet.!
!Vector4 commentStamp: '<historical>' prior: 0!
I represent 3D points in homogenous coordinates.!
!VectorArray commentStamp: '<historical>' prior: 0!
I am an array of Vectors.!
!MatrixArray commentStamp: '<historical>' prior: 0!
I am an array of Matrices.!
!Matrix4x4Array commentStamp: '<historical>' prior: 0!
I am an array of Matrix4x4Arrays.!
!Texture2Array commentStamp: '<historical>' prior: 0!
I am an efficient representation of texture coordinates.!
!Vector2Array commentStamp: '<historical>' prior: 0!
I am an efficient representation of Vector2 elements!
!Vector3Array commentStamp: '<historical>' prior: 0!
I am an efficient representation of Vector3 elements.!
!VectorColor4Array commentStamp: 'das 5/22/2005 15:23' prior: 0!
I am an inplace storage area for Color4 items used during lighting and shading.!
!VectorRotationArray commentStamp: '<historical>' prior: 0!
I am an array of Quaternions.!
!VectorColor commentStamp: '<historical>' prior: 0!
I represent an RGBA color value in floating point format. I am used during the lighting and shading computations.!
!SequenceableCollection methodsFor: '*3DTransform' stamp: 'ar 2/7/2006 17:36'!
asVectorColor
^ VectorColor new copyFrom: self.! !
!FloatArray methodsFor: '*3DTransform' stamp: 'ar 2/2/2006 20:15'!
floatAt: index
<primitive: 'primitiveAt' module: 'FloatArrayPlugin'>
^Float fromIEEE32Bit: (self basicAt: index)! !
!FloatArray methodsFor: '*3DTransform' stamp: 'ar 2/2/2006 20:15'!
floatAt: index put: value
<primitive: 'primitiveAtPut' module: 'FloatArrayPlugin'>
value isFloat
ifTrue:[self basicAt: index put: value asIEEE32BitWord]
ifFalse:[self at: index put: value asFloat].
^value! !
!Color methodsFor: '*3DTransform' stamp: 'ar 2/7/2006 17:35'!
asVectorColor
"Convert the receiver into a color"
^VectorColor new loadFrom: self! !
!Point methodsFor: '*3DTransform' stamp: 'das 5/23/2005 10:42'!
@ aNumber
^Vector3 x: x y: y z: aNumber! !
!CatmullRom methodsFor: 'compute' stamp: 'das 8/1/2006 16:19'!
at: t
| t2 t3 |
t2 := t*t.
t3 := t2 *t.
^ p1 + (p2 * t) + (p3 *t2) + (p4 * t3).! !
!CatmullRom methodsFor: 'initialize' stamp: 'das 8/1/2006 16:17'!
v1: v1 v2:v2 v3:v3 v4:v4
p1 := v2.
p2 := v3 - v1 * 0.5.
p3 := (2*v1) - (5*v2) + (4*v3) - v4 * 0.5.
p4 := v1 negated + (3*v2) - (3*v3) + v4 * 0.5. ! !
!CatmullRom class methodsFor: 'instance creation' stamp: 'das 8/1/2006 16:51'!
test
| points pen cr |
"This generates a nice shape on the screen. "
points := {0@0. 0@100. 100@100. 100@200. 200@200. 200@300. 300@300. 300@200. 400@200. 400@100. 500@100. 500@0.}.
pen := Pen new.
pen defaultNib:2.
pen color: Color red.
pen combinationRule: Form over.
pen up.
pen goto:0@100.
pen down.
1 to: points size - 3 do:[:i |
cr := CatmullRom varray: (points copyFrom:i to: i+3) .
1 to:10 do:[ :j | pen goto: (cr at: j/10.0)].
].! !
!CatmullRom class methodsFor: 'instance creation' stamp: 'das 8/1/2006 16:31'!
v1: v1 v2: v2 v3: v3 v4:v4
^ self new v1:v1 v2:v2 v3: v3 v4:v4.! !
!CatmullRom class methodsFor: 'instance creation' stamp: 'das 8/1/2006 16:32'!
varray: varray
^ self new v1:(varray at:1) v2:(varray at:2) v3: (varray at:3) v4:(varray at:4).! !
!Vector methodsFor: 'as yet unclassified' stamp: 'ar 2/7/2006 16:51'!
copyFrom: array
| sz |
sz := self size min: array size.
1 to: sz do:[:index | self at:index put: (array at: index)].! !
!Vector methodsFor: 'accessing' stamp: 'ar 2/2/2001 15:47'!
floatAt: index
"For subclasses that override #at:"
<primitive: 'primitiveAt' module: 'FloatArrayPlugin'>
^Float fromIEEE32Bit: (self basicAt: index)! !
!Vector methodsFor: 'accessing' stamp: 'ar 2/2/2001 15:47'!
floatAt: index put: value
"For subclasses that override #at:put:"
<primitive: 'primitiveAtPut' module: 'FloatArrayPlugin'>
self basicAt: index put: value asIEEE32BitWord.
^value! !
!Vector methodsFor: 'initialize'!
loadFrom: srcObject
self == srcObject ifTrue:[^self].
self class == srcObject class
ifTrue:[self replaceFrom: 1 to: self size with: srcObject startingAt: 1]
ifFalse:[self privateLoadFrom: srcObject]! !
!Vector methodsFor: 'accessing' stamp: 'ar 2/1/1999 21:23'!
numElements
^self class numElements! !
!Vector methodsFor: 'private' stamp: 'ar 2/1/1999 21:23'!
privateLoadFrom: srcObject
"Load the receiver from the given source object."
self error:'Cannot load a ', srcObject class name,' into a ', self class name.! !
!Vector methodsFor: 'private' stamp: 'ar 7/22/2006 19:39'!
replaceFrom: start to: stop with: replacement startingAt: repStart
"Primitive. This destructively replaces elements from start to stop in the receiver starting at index, repStart, in the collection, replacement. Answer the receiver. Range checks are performed in the primitive only. Optional. See Object documentation whatIsAPrimitive."
| index repOff |
<primitive: 105>
repOff := repStart - start.
index := start - 1.
[(index := index + 1) <= stop]
whileTrue: [self basicAt: index put: (replacement basicAt: repOff + index)]! !
!Vector methodsFor: 'accessing' stamp: 'ar 2/15/1999 22:10'!
wordAt: index
<primitive: 60>
^self primitiveFailed! !
!Vector methodsFor: 'accessing' stamp: 'ar 2/15/1999 22:10'!
wordAt: index put: value
<primitive: 61>
^self primitiveFailed! !
!Vector class methodsFor: 'island' stamp: 'ar 3/13/2006 17:15'!
howToPassAsArgument
"We clone all vectors, even the array ones to point out that manipulation of those vectors outside of some context is not a goof idea. We may reassess this later."
^#passByClone:! !
!Vector class methodsFor: 'class initialization' stamp: 'ar 3/8/2006 23:11'!
initialize
"Vector initialize"
DataStream initialize. "register with DataStream"! !
!Vector class methodsFor: 'instance creation' stamp: 'ar 2/1/1999 21:20'!
new
^super new: self numElements! !
!Vector class methodsFor: 'instance creation' stamp: 'ar 2/1/1999 21:21'!
numElements
^0! !
!Matrix4x4 methodsFor: 'transforming' stamp: 'das 5/22/2005 14:23'!
* m2
"Perform a 4x4 matrix multiplication."
| result |
result := self class new.
self privateTransformMatrix: self with: m2 into: result.
^result! !
!Matrix4x4 methodsFor: 'transforming' stamp: 'das 5/22/2005 14:24'!
*= m2
"Perform a 4x4 matrix multiplication with result into self."
| result |
result := self * m2.
self replaceFrom: 1 to: 16 with: result startingAt: 1.
! !
!Matrix4x4 methodsFor: 'arithmetic' stamp: 'das 5/22/2005 14:24'!
+ aMatrix
| res |
res := self copy.
res += aMatrix.
^ res.! !
!Matrix4x4 methodsFor: 'arithmetic' stamp: 'das 5/22/2005 14:24'!
+= aMatrix
"Optimized for Matrix/Matrix operations"
<primitive: 'primitiveAddFloatArray' module: 'FloatArrayPlugin'>
^super + aMatrix! !
!Matrix4x4 methodsFor: 'arithmetic' stamp: 'das 5/22/2005 14:24'!
- aMatrix
| res |
res := self copy.
res -= aMatrix.
^ res.! !
!Matrix4x4 methodsFor: 'arithmetic' stamp: 'das 5/22/2005 14:25'!
-= aMatrix
"Optimized for Matrix/Matrix operations"
<primitive: 'primitiveSubFloatArray' module: 'FloatArrayPlugin'>
^super - aMatrix! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a11
"Return the element a11"
^self at: 1! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a11: aNumber
"Store the element a11"
self at: 1 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a12
"Return the element a12"
^self at: 2! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a12: aNumber
"Store the element a12"
self at: 2 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a13
"Return the element a13"
^self at: 3! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a13: aNumber
"Store the element a13"
self at: 3 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a14
"Return the element a14"
^self at: 4! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a14: aNumber
"Store the element a14"
self at: 4 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a21
"Return the element a21"
^self at: 5! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a21: aNumber
"Store the element a21"
self at: 5 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a22
"Return the element a22"
^self at: 6! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a22: aNumber
"Store the element a22"
self at: 6 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a23
"Return the element a23"
^self at: 7! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a23: aNumber
"Store the element a23"
self at: 7 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a24
"Return the element a24"
^self at: 8! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a24: aNumber
"Store the element a24"
self at: 8 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a31
"Return the element a31"
^self at: 9! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a31: aNumber
"Store the element a31"
self at: 9 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a32
"Return the element a32"
^self at: 10! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a32: aNumber
"Store the element a32"
self at: 10 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a33
"Return the element a33"
^self at: 11! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a33: aNumber
"Store the element a33"
self at: 11 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a34
"Return the element a34"
^self at: 12! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a34: aNumber
"Store the element a34"
self at: 12 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a41
"Return the element a41"
^self at: 13! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a41: aNumber
"Store the element a41"
self at: 13 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a42
"Return the element a42"
^self at: 14! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a42: aNumber
"Store the element a42"
self at: 14 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a43
"Return the element a43"
^self at: 15! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a43: aNumber
"Store the element a43"
self at: 15 put: aNumber! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a44
"Return the element a44"
^self at: 16! !
!Matrix4x4 methodsFor: 'element-access' stamp: 'das 5/16/2005 12:06'!
a44: aNumber
"Store the element a44"
self at: 16 put: aNumber! !
!Matrix4x4 methodsFor: 'accessing' stamp: 'das 5/22/2005 15:18'!
addRotationAroundX: anAngle
| rtrans res |
rtrans := Matrix4x4 identity.
rtrans rotationAroundX: anAngle.
res := Matrix4x4 new.
self privateTransformMatrix: self with: rtrans into: res.
self replaceFrom: 1 to: 16 with: res startingAt: 1.
! !
!Matrix4x4 methodsFor: 'accessing' stamp: 'das 5/22/2005 15:00'!
addRotationAroundY: anAngle
| rtrans res |
rtrans := Matrix4x4 identity.
rtrans rotationAroundY: anAngle.
res := Matrix4x4 new.
self privateTransformMatrix: self with: rtrans into: res.
self replaceFrom: 1 to: 16 with: res startingAt: 1.
! !
!Matrix4x4 methodsFor: 'accessing' stamp: 'das 5/22/2005 15:00'!
addRotationAroundZ: anAngle
| rtrans res |
rtrans := Matrix4x4 identity.
rtrans rotationAroundZ: anAngle.
res := Matrix4x4 new.
self privateTransformMatrix: self with: rtrans into: res.
self replaceFrom: 1 to: 16 with: res startingAt: 1.
! !
!Matrix4x4 methodsFor: 'accessing' stamp: 'das 5/16/2005 12:06'!
alternateRotation
"Return the angular rotation around each axis of the matrix"
| cp sp cy sy cr sr vAngles |
vAngles := Vector3 new.
((self a13) = 0) ifTrue: [ ((self a33) >= 0) ifTrue: [ vAngles at: 2 put: 0.
cr := (self a11).
sr := (self a12).
cp := (self a33). ]
ifFalse: [ vAngles at: 2 put: (Float pi).
cr := (self a11) negated.
sr := (self a12) negated.
cp := (self a33) negated. ]
]
ifFalse: [
vAngles at: 2 put: (((self a13) negated) arcTan: (self a33)).
cy := (vAngles at: 3) cos.
sy := (vAngles at: 3) sin.
cr := (cy * (self a11)) + (sy * (self a31)).
sr := (cy* (self a12)) + (sy * (self a32)).
cp := (cy * (self a33)) - (sy * (self a13)).
].
sp := (self a23).
vAngles at: 1 put: (sp arcTan: cp).
vAngles at: 3 put: (sr arcTan: cr).
vAngles at: 1 put: ((vAngles at: 1) radiansToDegrees).
vAngles at: 2 put: ((vAngles at: 2) radiansToDegrees).
vAngles at: 3 put: ((vAngles at: 3) radiansToDegrees).
^ vAngles.
! !
!Matrix4x4 methodsFor: 'converting' stamp: 'das 5/16/2005 12:06'!
asMatrix4x4
^self! !
!Matrix4x4 methodsFor: 'converting' stamp: 'das 5/22/2005 12:08'!
asQuaternion
"Convert the matrix to a quaternion"
| x y z a a2 x2 y2 a4 |
a2 := 0.25 * (1.0 + (self a11) + (self a22) + (self a33)).
(a2 > 0) ifTrue: [
a := a2 sqrt.
a4 := 4.0 * a.
x := ((self a32) - (self a23)) / a4.
y := ((self a13) - (self a31)) / a4.
z := ((self a21) - (self a12)) / a4.
]
ifFalse: [
a := 0.
x2 := -0.5 * ((self a22) + (self a33)).
(x2 > 0) ifTrue: [
x := x2 sqrt.
x2 := 2 * x.
y := (self a21) / x2.
z := (self a31) / x2.
]
ifFalse: [
x := 0.
y2 := 0.5 * (1.0 - (self a33)).
(y2 > 0) ifTrue: [
y := y2 sqrt.
y2 := 2 * y.
z := (self a32) / y2.
]
ifFalse: [
y := 0.0.
z := 1.0.
]
]
].
^ (Quaternion a: a b: x c: y d: z).
! !
!Matrix4x4 methodsFor: 'accessing' stamp: 'das 5/16/2005 12:06'!
at: i at: j
^ self at: ((i - 1) * 4 + j).
! !
!Matrix4x4 methodsFor: 'accessing' stamp: 'das 5/16/2005 12:06'!
at: i at: j put: aValue
^ self at: ((i - 1) * 4 + j) put: aValue.
! !
!Matrix4x4 methodsFor: 'initialize' stamp: 'das 9/11/2006 13:32'!
at: a up: u
" dominant at vector - up can change. See #up:at:."
| side up at |
side := (a cross: u) normalized negated.
up := (side cross: a) normalized negated.
at := a normalized.
self a11: side x.
self a21: side y.
self a31: side z.
self a12: up x.
self a22: up y.
self a32: up z.
self a13: at x.
self a23: at y.
self a33: at z.
self a44: 1.0.
! !
!Matrix4x4 methodsFor: 'row-access' stamp: 'das 5/16/2005 12:06'!
column1
"Return column 1"
^ (Vector3 x: (self a11) y: (self a21) z: (self a31)).
! !
!Matrix4x4 methodsFor: 'row-access' stamp: 'das 5/16/2005 12:06'!
column1: col
"Set column 1"
self a11: col x.
self a21: col y.
self a31: col z.
! !
!Matrix4x4 methodsFor: 'row-access' stamp: 'das 5/16/2005 12:06'!
column2
"Return column 2"
^ (Vector3 x: (self a12) y: (self a22) z: (self a32)).
! !
!Matrix4x4 methodsFor: 'row-access' stamp: 'das 5/16/2005 12:06'!
column2: col
"Set column 2"
self a12: col x.
self a22: col y.
self a32: col z.
! !
!Matrix4x4 methodsFor: 'row-access' stamp: 'das 5/16/2005 12:06'!
column3
"Return column 3"
^ (Vector3 x: (self a13) y: (self a23) z: (self a33)).
! !
!Matrix4x4 methodsFor: 'row-access' stamp: 'das 5/16/2005 12:06'!
column3: col
"Set column 3"
self a13: col x.
self a23: col y.
self a33: col z.
! !
!Matrix4x4 methodsFor: 'transforming' stamp: 'das 5/16/2005 12:06'!
composeWith: m2
"Perform a 4x4 matrix multiplication."
^self composedWithLocal: m2.! !
!Matrix4x4 methodsFor: 'transforming' stamp: 'das 5/16/2005 12:06'!
composeWith: m2 times: nTimes
"Perform a 4x4 matrix exponentiation and multiplication."
| result |
result := self.
nTimes negative ifTrue: [ self halt ].
nTimes >= 2 ifTrue: [
result := result composeWith: (m2 composedWithLocal: m2) times: nTimes // 2 ].
(nTimes \\ 2) = 1 ifTrue: [ result := result composedWithLocal: m2].
^ result
! !
!Matrix4x4 methodsFor: 'transforming' stamp: 'das 5/22/2005 15:15'!
composedWithGlobal: aMatrix4x4
| result |
result := self class new.
self privateTransformMatrix: aMatrix4x4 with: self into: result.
^result! !
!Matrix4x4 methodsFor: 'transforming' stamp: 'das 5/22/2005 14:32'!
composedWithLocal: aMatrix4x4
| result |
result := self class new.
self privateTransformMatrix: self with: aMatrix4x4 into: result.
^result! !
!Matrix4x4 methodsFor: 'transforming' stamp: 'das 8/31/2006 19:54'!
counterTransposed
"flip across the other diagonal from normal transpose. Just the 3x3 part. Do not use this unless you really know what you are doing."
| matrix |
matrix := self class new.
matrix
a11: self a33; a12: self a23; a13: self a13; a14: self a14;
a21: self a32; a22: self a22; a23: self a12; a24: self a24;
a31: self a31; a32: self a21; a33: self a11; a34: self a34;
a41: self a41; a42: self a42; a43: self a43; a44: self a44.
^matrix! !
!Matrix4x4 methodsFor: 'accessing' stamp: 'das 5/22/2005 09:52'!
getFrom: m2
1 to: 16 do:[:i | self at: i put: (m2 at: i)].! !
!Matrix4x4 methodsFor: 'transforming' stamp: 'bgf 9/12/2006 17:35'!
globalDirToLocal: aPoint
^ self inverseTransformation localDirToGlobal: aPoint! !
!Matrix4x4 methodsFor: 'transforming' stamp: 'bgf 9/12/2006 17:35'!
globalPointToLocal: aPoint
"Convenience method for inverse of localPointToGlobal."
^ self inverseTransformation localPointToGlobal: aPoint! !
!Matrix4x4 methodsFor: 'solving' stamp: 'das 5/16/2005 12:06'!
inplaceDecomposeLU
"Decompose the receiver in place by using gaussian elimination w/o pivot search"
| x |
1 to: 4 do:[:j|
"i-th equation (row)"
j+1 to: 4 do:[:i|
x := (self at: i at: j) / (self at: j at: j).
j to: 4 do:[:k|
self at: i at: k put: (self at: i at: k) - ((self at: j at: k) * x)].
self at: i at: j put: x]].
! !
!Matrix4x4 methodsFor: 'solving' stamp: 'ar 3/26/2006 22:53'!
inplaceHouseHolderInvert
"Solve the linear equation self * aVector = x by using HouseHolder's transformation.
Note: This scheme is numerically better than using gaussian elimination even though it takes
somewhat longer"
| d x sigma beta sum s|
<primitive:'primitiveInplaceHouseHolderInvert' module:'CroquetPlugin'>
x := Matrix4x4 identity.
d := Matrix4x4 new.
1 to: 4 do:[:j|
sigma := 0.0.
j to: 4 do:[:i| sigma := sigma + ((self at: i at: j) squared)].
sigma isZero ifTrue:[^nil]. "matrix is singular"
((self at: j at: j) < 0.0)
ifTrue:[ s:= sigma sqrt]
ifFalse:[ s:= sigma sqrt negated].
1 to: 4 do:[:r| d at: j at: r put: s].
beta := 1.0 / ( s * (self at: j at: j) - sigma).
self at: j at: j put: ((self at: j at: j) - s).
"update remaining columns"
j+1 to: 4 do:[:k|
sum := 0.0.
j to: 4 do:[:i| sum := sum + ((self at: i at: j) * (self at: i at: k))].
sum := sum * beta.
j to: 4 do:[:i|
self at: i at: k put: ((self at: i at: k) + ((self at: i at: j) * sum))]].
"update vector"
1 to: 4 do:[:r|
sum := nil.
j to: 4 do:[:i|
sum := sum isNil
ifTrue:[(x at: i at: r) * (self at: i at: j)]
ifFalse:[sum + ((x at: i at: r) * (self at: i at: j))]].
sum := sum * beta.
j to: 4 do:[:i|
x at: i at: r put:((x at: i at: r) + (sum * (self at: i at: j)))].
].
].
"Now calculate result"
1 to: 4 do:[:r|
4 to: 1 by: -1 do:[:i|
i+1 to: 4 do:[:j|
x at: i at: r put: ((x at: i at: r) - ((x at: j at: r) * (self at: i at: j))) ].
x at: i at: r put: ((x at: i at: r) / (d at: i at: r))].
].
self loadFrom: x.
"Return receiver"! !
!Matrix4x4 methodsFor: 'solving' stamp: 'das 5/16/2005 12:06'!
inplaceHouseHolderTransform: aVector
"Solve the linear equation self * aVector = x by using HouseHolder's transformation.
Note: This scheme is numerically better than using gaussian elimination even though it takes
somewhat longer"
| d x sigma beta sum s|
x := Array with: aVector x with: aVector y with: aVector z with: aVector w.
d := Array new: 4.
1 to: 4 do:[:j|
sigma := 0.0.
j to: 4 do:[:i| sigma := sigma + ((self at: i at: j) squared)].
sigma isZero ifTrue:[^nil]. "matrix is singular"
((self at: j at: j) < 0.0)
ifTrue:[ s:= d at: j put: (sigma sqrt)]
ifFalse:[ s:= d at: j put: (sigma sqrt negated)].
beta := 1.0 / ( s * (self at: j at: j) - sigma).
self at: j at: j put: ((self at: j at: j) - s).
"update remaining columns"
j+1 to: 4 do:[:k|
sum := 0.0.
j to: 4 do:[:i| sum := sum + ((self at: i at: j) * (self at: i at: k))].
sum := sum * beta.
j to: 4 do:[:i|
self at: i at: k put: ((self at: i at: k) + ((self at: i at: j) * sum))]].
"update vector"
sum := nil.
j to: 4 do:[:i|
sum := sum isNil
ifTrue:[(x at: i) * (self at: i at: j)]
ifFalse:[sum + ((x at: i) * (self at: i at: j))]].
sum := sum * beta.
j to: 4 do:[:i|
x at: i put:((x at: i) + (sum * (self at: i at: j)))].
].
"Now calculate result"
4 to: 1 by: -1 do:[:i|
i+1 to: 4 do:[:j|
x at: i put: ((x at: i) - ((x at: j) * (self at: i at: j))) ].
x at: i put: ((x at: i) / (d at: i))].
^Vector4 x: (x at: 1) y: (x at: 2) z: (x at: 3) w: (x at: 4)
! !
!Matrix4x4 methodsFor: 'transforming' stamp: 'pb 7/6/2015 13:36'!
inverseTransformation
"Return the inverse matrix of the receiver."
^ self shallowCopy inplaceHouseHolderInvert.! !
!Matrix4x4 methodsFor: 'testing' stamp: 'das 5/22/2005 15:16'!
isIdentity
^self = IdentityMatrix! !
!Matrix4x4 methodsFor: 'testing' stamp: 'das 5/22/2005 15:17'!
isZero
^self = ZeroMatrix! !
!Matrix4x4 methodsFor: 'accessing' stamp: 'das 5/16/2005 12:06'!
localBoxToGlobal: aTBox
^TBox min: (self localPointToGlobal: aTBox min) max: (self localPointToGlobal: aTBox max).! !
!Matrix4x4 methodsFor: 'transforming' stamp: 'ar 3/26/2006 22:42'!
localDirToGlobal: aVector
"Multiply direction vector with the receiver"
| x y z rx ry rz |
<primitive: 'primitiveTransformDirection' module: 'CroquetPlugin'>
x := aVector x.
y := aVector y.
z := aVector z.
rx := (x * self a11) + (y * self a12) + (z * self a13).
ry := (x * self a21) + (y * self a22) + (z * self a23).
rz := (x * self a31) + (y * self a32) + (z * self a33).
^Vector3 x: rx y: ry z: rz! !
!Matrix4x4 methodsFor: 'transforming' stamp: 'ar 3/26/2006 22:43'!
localPointToGlobal: aVector
"Multiply aVector (temporarily converted to 4D) with the receiver"
| x y z rx ry rz rw |
<primitive: 'primitiveTransformVector3' module: 'CroquetPlugin'>
x := aVector x.
y := aVector y.
z := aVector z.
rx := (x * self a11) + (y * self a12) + (z * self a13) + self a14.
ry := (x * self a21) + (y * self a22) + (z * self a23) + self a24.
rz := (x * self a31) + (y * self a32) + (z * self a33) + self a34.
rw := (x * self a41) + (y * self a42) + (z * self a43) + self a44.
^Vector3 x:(rx/rw) y: (ry/rw) z: (rz/rw)! !