-
Notifications
You must be signed in to change notification settings - Fork 3
/
PBJ.cs
1748 lines (1453 loc) · 44 KB
/
PBJ.cs
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
using System;
namespace PBJ {
public class IMessage {
public virtual Google.ProtocolBuffers.IMessage _PBJISuper { get { return null;} }
protected virtual bool _HasAllPBJFields { get { return true; } }
public void WriteTo(Google.ProtocolBuffers.CodedOutputStream output){
_PBJISuper.WriteTo(output);
}
public override bool Equals (object other){
return _PBJISuper.Equals(other);
}
public int SerializedSize { get { return _PBJISuper.SerializedSize; } }
public override int GetHashCode() {return _PBJISuper.GetHashCode();}
public override string ToString() {
return _PBJISuper.ToString();
}
public virtual IBuilder WeakCreateBuilderForType() { return null;}
public Google.ProtocolBuffers.ByteString ToByteString () {
return _PBJISuper.ToByteString();
}
public byte[] ToByteArray () {
return _PBJISuper.ToByteArray();
}
public void WriteTo(global::System.IO.Stream output) {
_PBJISuper.WriteTo(output);
}
// Google.ProtocolBuffers.MessageDescriptor DescriptorForType { get {return _PBJISuper.DescriptorForType;} }
public Google.ProtocolBuffers.UnknownFieldSet UnknownFields { get { return _PBJISuper.UnknownFields;} }
public class IBuilder {
public virtual Google.ProtocolBuffers.IBuilder _PBJISuper { get { return null;} }
protected virtual bool _HasAllPBJFields { get { return true; } }
}
}
public struct Vector2f {
public float x;
public float y;
public Vector2f(float _x, float _y) {
x = _x; y = _y;
}
public Vector2f(Vector2f cpy) {
x = cpy.x; y = cpy.y;
}
public Vector2f Negate() {
return new Vector2f(-x, -y);
}
public Vector2f Add(Vector2f rhs) {
return new Vector2f(x + rhs.x, y + rhs.y);
}
public Vector2f Subtract(Vector2f rhs) {
return new Vector2f(x - rhs.x, y - rhs.y);
}
public Vector2f Multiply(Vector2f rhs) {
return new Vector2f(x * rhs.x, y * rhs.y);
}
public Vector2f Multiply(float s) {
return new Vector2f(x * s, y * s);
}
public Vector2f Divide(Vector2f rhs) {
return new Vector2f(x / rhs.x, y / rhs.y);
}
public Vector2f Divide(float s) {
return new Vector2f(x / s, y / s);
}
public float Dot(Vector2f rhs) {
return (x*rhs.x + y*rhs.y);
}
public void Normalize() {
float len = Length;
if (len != 0.0) {
x /= len; y /= len;
}
}
public Vector2f Normalized {
get {
Vector2f normed = new Vector2f(this);
normed.Normalize();
return normed;
}
}
public float SquaredLength {
get {
return (x*x + y*y);
}
}
public float Length {
get {
return (float)Math.Sqrt(SquaredLength);
}
}
public override string ToString() {
return String.Format("<{0}, {1}>", x, y);
}
public static Vector2f operator-(Vector2f uo) {
return uo.Negate();
}
public static Vector2f operator+(Vector2f lhs, Vector2f rhs) {
return lhs.Add(rhs);
}
public static Vector2f operator-(Vector2f lhs, Vector2f rhs) {
return lhs.Subtract(rhs);
}
public static Vector2f operator*(Vector2f lhs, Vector2f rhs) {
return lhs.Multiply(rhs);
}
public static Vector2f operator*(Vector2f lhs, float rhs) {
return lhs.Multiply(rhs);
}
public static Vector2f operator*(float lhs, Vector2f rhs) {
return rhs.Multiply(lhs);
}
public static Vector2f operator/(Vector2f lhs, Vector2f rhs) {
return lhs.Divide(rhs);
}
public static Vector2f operator/(Vector2f lhs, float rhs) {
return lhs.Divide(rhs);
}
} // struct Vector2f
public struct Vector2d {
public double x;
public double y;
public Vector2d(double _x, double _y) {
x = _x; y = _y;
}
public Vector2d(Vector2d cpy) {
x = cpy.x; y = cpy.y;
}
public Vector2d Negate() {
return new Vector2d(-x, -y);
}
public Vector2d Add(Vector2d rhs) {
return new Vector2d(x + rhs.x, y + rhs.y);
}
public Vector2d Subtract(Vector2d rhs) {
return new Vector2d(x - rhs.x, y - rhs.y);
}
public Vector2d Multiply(Vector2d rhs) {
return new Vector2d(x * rhs.x, y * rhs.y);
}
public Vector2d Multiply(double s) {
return new Vector2d(x * s, y * s);
}
public Vector2d Divide(Vector2d rhs) {
return new Vector2d(x / rhs.x, y / rhs.y);
}
public Vector2d Divide(double s) {
return new Vector2d(x / s, y / s);
}
public double Dot(Vector2d rhs) {
return (x*rhs.x + y*rhs.y);
}
public void Normalize() {
double len = Length;
if (len != 0.0) {
x /= len; y /= len;
}
}
public Vector2d Normalized {
get {
Vector2d normed = new Vector2d(this);
normed.Normalize();
return normed;
}
}
public double SquaredLength {
get {
return (x*x + y*y);
}
}
public double Length {
get {
return Math.Sqrt(SquaredLength);
}
}
public override string ToString() {
return String.Format("<{0}, {1}>", x, y);
}
public static Vector2d operator-(Vector2d uo) {
return uo.Negate();
}
public static Vector2d operator+(Vector2d lhs, Vector2d rhs) {
return lhs.Add(rhs);
}
public static Vector2d operator-(Vector2d lhs, Vector2d rhs) {
return lhs.Subtract(rhs);
}
public static Vector2d operator*(Vector2d lhs, Vector2d rhs) {
return lhs.Multiply(rhs);
}
public static Vector2d operator*(Vector2d lhs, double rhs) {
return lhs.Multiply(rhs);
}
public static Vector2d operator*(double lhs, Vector2d rhs) {
return rhs.Multiply(lhs);
}
public static Vector2d operator/(Vector2d lhs, Vector2d rhs) {
return lhs.Divide(rhs);
}
public static Vector2d operator/(Vector2d lhs, double rhs) {
return lhs.Divide(rhs);
}
} // struct Vector2d
public struct Vector3f {
public float x;
public float y;
public float z;
public Vector3f(float _x, float _y, float _z) {
x = _x; y = _y; z = _z;
}
public Vector3f(Vector3f cpy) {
x = cpy.x; y = cpy.y; z = cpy.z;
}
public Vector3f Negate() {
return new Vector3f(-x, -y, -z);
}
public Vector3f Add(Vector3f rhs) {
return new Vector3f(x + rhs.x, y + rhs.y, z + rhs.z);
}
public Vector3f Subtract(Vector3f rhs) {
return new Vector3f(x - rhs.x, y - rhs.y, z - rhs.z);
}
public Vector3f Multiply(Vector3f rhs) {
return new Vector3f(x * rhs.x, y * rhs.y, z * rhs.z);
}
public Vector3f Multiply(float s) {
return new Vector3f(x * s, y * s, z * s);
}
public Vector3f Divide(Vector3f rhs) {
return new Vector3f(x / rhs.x, y / rhs.y, z / rhs.z);
}
public Vector3f Divide(float s) {
return new Vector3f(x / s, y / s, z / s);
}
public float Dot(Vector3f rhs) {
return (x*rhs.x + y*rhs.y + z*rhs.z);
}
public Vector3f Cross(Vector3f rhs) {
return new Vector3f( y*rhs.z - z*rhs.y, z*rhs.x - x*rhs.z, x*rhs.y - y*rhs.x);
}
public void Normalize() {
float len = Length;
if (len != 0.0) {
x /= len; y /= len; z /= len;
}
}
public Vector3f Normalized {
get {
Vector3f normed = new Vector3f(this);
normed.Normalize();
return normed;
}
}
public float SquaredLength {
get {
return (x*x + y*y + z*z);
}
}
public float Length {
get {
return (float)Math.Sqrt(SquaredLength);
}
}
public override string ToString() {
return String.Format("<{0}, {1}, {2}>", x, y, z);
}
public static Vector3f operator-(Vector3f uo) {
return uo.Negate();
}
public static Vector3f operator+(Vector3f lhs, Vector3f rhs) {
return lhs.Add(rhs);
}
public static Vector3f operator-(Vector3f lhs, Vector3f rhs) {
return lhs.Subtract(rhs);
}
public static Vector3f operator*(Vector3f lhs, Vector3f rhs) {
return lhs.Multiply(rhs);
}
public static Vector3f operator*(Vector3f lhs, float rhs) {
return lhs.Multiply(rhs);
}
public static Vector3f operator*(float lhs, Vector3f rhs) {
return rhs.Multiply(lhs);
}
public static Vector3f operator/(Vector3f lhs, Vector3f rhs) {
return lhs.Divide(rhs);
}
public static Vector3f operator/(Vector3f lhs, float rhs) {
return lhs.Divide(rhs);
}
} // struct Vector3f
public struct Vector3d {
public double x;
public double y;
public double z;
public Vector3d(double _x, double _y, double _z) {
x = _x; y = _y; z = _z;
}
public Vector3d(Vector3d cpy) {
x = cpy.x; y = cpy.y; z = cpy.z;
}
public Vector3d Negate() {
return new Vector3d(-x, -y, -z);
}
public Vector3d Add(Vector3d rhs) {
return new Vector3d(x + rhs.x, y + rhs.y, z + rhs.z);
}
public Vector3d Subtract(Vector3d rhs) {
return new Vector3d(x - rhs.x, y - rhs.y, z - rhs.z);
}
public Vector3d Multiply(Vector3d rhs) {
return new Vector3d(x * rhs.x, y * rhs.y, z * rhs.z);
}
public Vector3d Multiply(double s) {
return new Vector3d(x * s, y * s, z * s);
}
public Vector3d Divide(Vector3d rhs) {
return new Vector3d(x / rhs.x, y / rhs.y, z / rhs.z);
}
public Vector3d Divide(double s) {
return new Vector3d(x / s, y / s, z / s);
}
public double Dot(Vector3d rhs) {
return (x*rhs.x + y*rhs.y + z*rhs.z);
}
public Vector3d Cross(Vector3d rhs) {
return new Vector3d( y*rhs.z - z*rhs.y, z*rhs.x - x*rhs.z, x*rhs.y - y*rhs.x);
}
public void Normalize() {
double len = Length;
if (len != 0.0) {
x /= len; y /= len; z /= len;
}
}
public Vector3d Normalized {
get {
Vector3d normed = new Vector3d(this);
normed.Normalize();
return normed;
}
}
public double SquaredLength {
get {
return (x*x + y*y + z*z);
}
}
public double Length {
get {
return Math.Sqrt(SquaredLength);
}
}
public override string ToString() {
return String.Format("<{0}, {1}, {2}>", x, y, z);
}
public static Vector3d operator-(Vector3d uo) {
return uo.Negate();
}
public static Vector3d operator+(Vector3d lhs, Vector3d rhs) {
return lhs.Add(rhs);
}
public static Vector3d operator-(Vector3d lhs, Vector3d rhs) {
return lhs.Subtract(rhs);
}
public static Vector3d operator*(Vector3d lhs, Vector3d rhs) {
return lhs.Multiply(rhs);
}
public static Vector3d operator*(Vector3d lhs, double rhs) {
return lhs.Multiply(rhs);
}
public static Vector3d operator*(double lhs, Vector3d rhs) {
return rhs.Multiply(lhs);
}
public static Vector3d operator/(Vector3d lhs, Vector3d rhs) {
return lhs.Divide(rhs);
}
public static Vector3d operator/(Vector3d lhs, double rhs) {
return lhs.Divide(rhs);
}
} // struct Vector3d
public struct Quaternion {
public float w;
public float x;
public float y;
public float z;
public Quaternion(float _w, float _x, float _y, float _z) {
w = _w; x = _x; y = _y; z = _z;
}
public Quaternion(Quaternion cpy) {
w = cpy.w; x = cpy.x; y = cpy.y; z = cpy.z;
}
public static readonly Quaternion Identity = new Quaternion((float)1.0, (float)0.0, (float)0.0, (float)0.0);
public static Quaternion FromAxisAngle(Vector3f axis, float rads) {
float halfAngle = rads * 0.5f;
float sinHalf = (float)Math.Sin(halfAngle);
float w = (float)Math.Cos(halfAngle);
float x = sinHalf*axis.x;
float y = sinHalf*axis.y;
float z = sinHalf*axis.z;
return new Quaternion(w, x, y, z);
}
public static Quaternion FromAxisAngle(Vector3d axis, float rads) {
float halfAngle = rads * 0.5f;
float sinHalf = (float)Math.Sin(halfAngle);
float w = (float)Math.Cos(halfAngle);
float x = (float)(sinHalf*axis.x);
float y = (float)(sinHalf*axis.y);
float z = (float)(sinHalf*axis.z);
return new Quaternion(w, x, y, z);
}
public Quaternion Add(Quaternion rhs) {
return new Quaternion(w + rhs.w, x + rhs.x, y + rhs.y, z + rhs.z);
}
public Quaternion Subtract(Quaternion rhs) {
return new Quaternion(w - rhs.w, x - rhs.x, y - rhs.y, z - rhs.z);
}
public Quaternion Multiply(Quaternion rhs) {
return new Quaternion(
w*rhs.w - x*rhs.x - y*rhs.y - z*rhs.z,
w*rhs.x + x*rhs.w + y*rhs.z - z*rhs.y,
w*rhs.y + y*rhs.w + z*rhs.x - x*rhs.z,
w*rhs.z + z*rhs.w + x*rhs.y - y*rhs.x
);
}
public Vector3f Multiply(Vector3f rhs) {
Vector3f qvec = new Vector3f(x, y, z);
Vector3f uv = qvec.Cross(rhs);
Vector3f uuv = qvec.Cross(uv);
uv *= 2.0f * w;
uuv *= 2.0f;
return rhs + uv + uuv;
}
public Vector3d Multiply(Vector3d rhs) {
Vector3d qvec = new Vector3d(x, y, z);
Vector3d uv = qvec.Cross(rhs);
Vector3d uuv = qvec.Cross(uv);
uv *= 2.0f * w;
uuv *= 2.0f;
return rhs + uv + uuv;
}
public Quaternion Multiply(float rhs) {
return new Quaternion(w*rhs, x*rhs, y*rhs, z*rhs);
}
public Quaternion Negate() {
return new Quaternion(-w, -x, -y, -z);
}
public float Dot(Quaternion rhs) {
return (w*rhs.w + x*rhs.x + y*rhs.y + z*rhs.z);
}
public float Norm {
get {
return (float)Math.Sqrt(w*w + x*x + y*y + z*z);
}
}
public float SquareNorm {
get {
return (w*w + x*x + y*y + z*z);
}
}
public void Normalize() {
float len = SquareNorm;
if (len == 0.0) return;
float factor = 1.0f / (float)Math.Sqrt(len);
this *= factor;
}
public Quaternion Normalized {
get {
Quaternion q = new Quaternion(this);
q.Normalize();
return q;
}
}
public Quaternion Inverse {
get {
float norm = SquareNorm;
if (norm > 0.0) {
double invnorm = 1.0 / norm;
return new Quaternion((float)(w*invnorm), (float)(-x*invnorm), (float)(-y*invnorm), (float)(-z*invnorm));
}
else
return new Quaternion((float)0.0, 0.0f, 0.0f, 0.0f);
}
}
public override string ToString() {
return String.Format("<{0}, {1}, {2}, {3}>", w, x, y, z);
}
public static Quaternion operator-(Quaternion uo) {
return uo.Negate();
}
public static Quaternion operator+(Quaternion lhs, Quaternion rhs) {
return lhs.Add(rhs);
}
public static Quaternion operator-(Quaternion lhs, Quaternion rhs) {
return lhs.Subtract(rhs);
}
public static Vector3f operator*(Quaternion lhs, Vector3f rhs) {
return lhs.Multiply(rhs);
}
public static Vector3d operator*(Quaternion lhs, Vector3d rhs) {
return lhs.Multiply(rhs);
}
public static Quaternion operator*(Quaternion lhs, Quaternion rhs) {
return lhs.Multiply(rhs);
}
public static Quaternion operator*(Quaternion lhs, float rhs) {
return lhs.Multiply(rhs);
}
public static Quaternion operator*(float lhs, Quaternion rhs) {
return rhs.Multiply(lhs);
}
} // struct Quaternion
public struct Vector4f {
public float x;
public float y;
public float z;
public float w;
public Vector4f(float _x, float _y, float _z, float _w) {
x = _x; y = _y; z = _z; w = _w;
}
public Vector4f(Vector4f cpy) {
x = cpy.x; y = cpy.y; z = cpy.z; w = cpy.w;
}
public Vector4f Negate() {
return new Vector4f(-x, -y, -z, -w);
}
public Vector4f Add(Vector4f rhs) {
return new Vector4f(x + rhs.x, y + rhs.y, z + rhs.z, w + rhs.w);
}
public Vector4f Subtract(Vector4f rhs) {
return new Vector4f(x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w);
}
public Vector4f Multiply(Vector4f rhs) {
return new Vector4f(x * rhs.x, y * rhs.y, z * rhs.z, w*rhs.w);
}
public Vector4f Multiply(float s) {
return new Vector4f(x * s, y * s, z * s, w * s);
}
public Vector4f Divide(Vector4f rhs) {
return new Vector4f(x / rhs.x, y / rhs.y, z / rhs.z, w / rhs.w);
}
public Vector4f Divide(float s) {
return new Vector4f(x / s, y / s, z / s, w / s);
}
public float Dot(Vector4f rhs) {
return (x*rhs.x + y*rhs.y + z*rhs.z + w*rhs.w);
}
public void Normalize() {
float len = Length;
if (len != 0.0) {
x /= len; y /= len; z /= len; w /= len;
}
}
public Vector4f Normalized {
get {
Vector4f normed = new Vector4f(this);
normed.Normalize();
return normed;
}
}
public float SquaredLength {
get {
return (x*x + y*y + z*z + w*w);
}
}
public float Length {
get {
return (float)Math.Sqrt(SquaredLength);
}
}
public override string ToString() {
return String.Format("<{0}, {1}, {2}, {3}>", x, y, z, w);
}
public static Vector4f operator-(Vector4f uo) {
return uo.Negate();
}
public static Vector4f operator+(Vector4f lhs, Vector4f rhs) {
return lhs.Add(rhs);
}
public static Vector4f operator-(Vector4f lhs, Vector4f rhs) {
return lhs.Subtract(rhs);
}
public static Vector4f operator*(Vector4f lhs, Vector4f rhs) {
return lhs.Multiply(rhs);
}
public static Vector4f operator*(Vector4f lhs, float rhs) {
return lhs.Multiply(rhs);
}
public static Vector4f operator*(float lhs, Vector4f rhs) {
return rhs.Multiply(lhs);
}
public static Vector4f operator/(Vector4f lhs, Vector4f rhs) {
return lhs.Divide(rhs);
}
public static Vector4f operator/(Vector4f lhs, float rhs) {
return lhs.Divide(rhs);
}
} // struct Vector4f
public struct Vector4d {
public double x;
public double y;
public double z;
public double w;
public Vector4d(double _x, double _y, double _z, double _w) {
x = _x; y = _y; z = _z; w = _w;
}
public Vector4d(Vector4d cpy) {
x = cpy.x; y = cpy.y; z = cpy.z; w = cpy.w;
}
public Vector4d Negate() {
return new Vector4d(-x, -y, -z, -w);
}
public Vector4d Add(Vector4d rhs) {
return new Vector4d(x + rhs.x, y + rhs.y, z + rhs.z, w + rhs.w);
}
public Vector4d Subtract(Vector4d rhs) {
return new Vector4d(x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w);
}
public Vector4d Multiply(Vector4d rhs) {
return new Vector4d(x * rhs.x, y * rhs.y, z * rhs.z, w*rhs.w);
}
public Vector4d Multiply(double s) {
return new Vector4d(x * s, y * s, z * s, w * s);
}
public Vector4d Divide(Vector4d rhs) {
return new Vector4d(x / rhs.x, y / rhs.y, z / rhs.z, w / rhs.w);
}
public Vector4d Divide(double s) {
return new Vector4d(x / s, y / s, z / s, w / s);
}
public double Dot(Vector4d rhs) {
return (x*rhs.x + y*rhs.y + z*rhs.z + w*rhs.w);
}
public void Normalize() {
double len = Length;
if (len != 0.0) {
x /= len; y /= len; z /= len; w /= len;
}
}
public Vector4d Normalized {
get {
Vector4d normed = new Vector4d(this);
normed.Normalize();
return normed;
}
}
public double SquaredLength {
get {
return (x*x + y*y + z*z + w*w);
}
}
public double Length {
get {
return Math.Sqrt(SquaredLength);
}
}
public override string ToString() {
return String.Format("<{0}, {1}, {2}, {3}>", x, y, z, w);
}
public static Vector4d operator-(Vector4d uo) {
return uo.Negate();
}
public static Vector4d operator+(Vector4d lhs, Vector4d rhs) {
return lhs.Add(rhs);
}
public static Vector4d operator-(Vector4d lhs, Vector4d rhs) {
return lhs.Subtract(rhs);
}
public static Vector4d operator*(Vector4d lhs, Vector4d rhs) {
return lhs.Multiply(rhs);
}
public static Vector4d operator*(Vector4d lhs, double rhs) {
return lhs.Multiply(rhs);
}
public static Vector4d operator*(double lhs, Vector4d rhs) {
return rhs.Multiply(lhs);
}
public static Vector4d operator/(Vector4d lhs, Vector4d rhs) {
return lhs.Divide(rhs);
}
public static Vector4d operator/(Vector4d lhs, double rhs) {
return lhs.Divide(rhs);
}
} // struct Vector4d
public struct BoundingBox3f3f {
Vector3f mMin;
Vector3f mDiag;
public BoundingBox3f3f(float minx, float miny, float minz,float diagx,float diagy,float diagz) {
mMin.x=minx;
mMin.y=miny;
mMin.z=minz;
mDiag.x=diagx;
mDiag.y=diagy;
mDiag.z=diagz;
}
public BoundingBox3f3f(Vector3f min, Vector3f max) {
mMin=min;
mDiag=(max-min);
}
public BoundingBox3f3f(BoundingBox3f3f cpy, Vector3f scale) {
mMin.x=(float)(cpy.mMin.x*scale.x);
mMin.y=(float)(cpy.mMin.y*scale.y);
mMin.z=(float)(cpy.mMin.z*scale.z);
mDiag.x=(float)(cpy.mDiag.x*scale.x);
mDiag.y=(float)(cpy.mDiag.y*scale.y);
mDiag.z=(float)(cpy.mDiag.z*scale.z);
}
public Vector3f Min {
get {
return new Vector3f(mMin.x,mMin.y,mMin.z);
}
}
public Vector3f Max {
get {
return new Vector3f(mMin.x+mDiag.x,mMin.y+mDiag.y,mMin.z+mDiag.z);
}
}
public Vector3f Diag {
get {
return new Vector3f(mDiag.x,mDiag.y,mDiag.z);
}
}
public override string ToString() {
return "["+this.Min.ToString()+" - "+this.Max.ToString()+"]";
}
public BoundingBox3f3f Merge(BoundingBox3f3f other) {
Vector3f thisMax=Max;
Vector3f otherMax=other.Max;
bool xless=other.mMin.x>mMin.x;
bool yless=other.mMin.y>mMin.y;
bool zless=other.mMin.z>mMin.z;
bool xmore=otherMax.x<thisMax.x;
bool ymore=otherMax.y<thisMax.y;
bool zmore=otherMax.z<thisMax.z;
return new BoundingBox3f3f(xless?mMin.x:other.mMin.x,
yless?mMin.y:other.mMin.y,
zless?mMin.z:other.mMin.z,
xmore?(xless?mDiag.x:otherMax.x-mMin.x):(xless?thisMax.x-other.mMin.x:other.mDiag.x),
ymore?(yless?mDiag.y:otherMax.y-mMin.y):(yless?thisMax.y-other.mMin.y:other.mDiag.y),
zmore?(zless?mDiag.z:otherMax.z-mMin.z):(zless?thisMax.z-other.mMin.z:other.mDiag.z));
}
} // struct BoundingBox
public struct BoundingBox3d3f {
Vector3d mMin;
Vector3f mDiag;
public BoundingBox3d3f(double minx, double miny, double minz,float diagx,float diagy,float diagz) {
mMin.x=minx;
mMin.y=miny;
mMin.z=minz;
mDiag.x=diagx;
mDiag.y=diagy;
mDiag.z=diagz;
}
public BoundingBox3d3f(Vector3d min, Vector3f max) {
mMin=min;
mDiag=new Vector3f((float)(max.x-min.x),
(float)(max.y-min.y),
(float)(max.z-min.z));
}
public BoundingBox3d3f(BoundingBox3d3f cpy, Vector3d scale) {
mMin.x=(double)(cpy.mMin.x*scale.x);
mMin.y=(double)(cpy.mMin.y*scale.y);
mMin.z=(double)(cpy.mMin.z*scale.z);
mDiag.x=(float)(cpy.mDiag.x*scale.x);
mDiag.y=(float)(cpy.mDiag.y*scale.y);
mDiag.z=(float)(cpy.mDiag.z*scale.z);
}
public Vector3d Min {
get {
return new Vector3d(mMin.x,mMin.y,mMin.z);
}
}
public Vector3d Max {
get {
return new Vector3d(mMin.x+mDiag.x,mMin.y+mDiag.y,mMin.z+mDiag.z);
}
}