diff options
author | Diva Canto | 2009-12-27 08:38:44 -0800 |
---|---|---|
committer | Diva Canto | 2009-12-27 08:38:44 -0800 |
commit | 2248d2ff32cc098f55cf9f0c9c4bf062eafff0dd (patch) | |
tree | 319a8f11c155a8d6171246887602395a410527e1 /OpenSim/Client/Sirikata/Protocol/PBJ.cs | |
parent | First pass at the local connector for presence. No cache yet. Just the connec... (diff) | |
parent | Merge branch 'master' into presence-refactor (diff) | |
download | opensim-SC-2248d2ff32cc098f55cf9f0c9c4bf062eafff0dd.zip opensim-SC-2248d2ff32cc098f55cf9f0c9c4bf062eafff0dd.tar.gz opensim-SC-2248d2ff32cc098f55cf9f0c9c4bf062eafff0dd.tar.bz2 opensim-SC-2248d2ff32cc098f55cf9f0c9c4bf062eafff0dd.tar.xz |
Merge branch 'presence-refactor' of ssh://diva@opensimulator.org/var/git/opensim into presence-refactor
Diffstat (limited to 'OpenSim/Client/Sirikata/Protocol/PBJ.cs')
-rw-r--r-- | OpenSim/Client/Sirikata/Protocol/PBJ.cs | 2077 |
1 files changed, 2077 insertions, 0 deletions
diff --git a/OpenSim/Client/Sirikata/Protocol/PBJ.cs b/OpenSim/Client/Sirikata/Protocol/PBJ.cs new file mode 100644 index 0000000..46888b5 --- /dev/null +++ b/OpenSim/Client/Sirikata/Protocol/PBJ.cs | |||
@@ -0,0 +1,2077 @@ | |||
1 | using System; | ||
2 | namespace PBJ | ||
3 | { | ||
4 | |||
5 | public class IMessage | ||
6 | { | ||
7 | public virtual Google.ProtocolBuffers.IMessage _PBJISuper { get { return null; } } | ||
8 | protected virtual bool _HasAllPBJFields { get { return true; } } | ||
9 | public void WriteTo(Google.ProtocolBuffers.CodedOutputStream output) | ||
10 | { | ||
11 | _PBJISuper.WriteTo(output); | ||
12 | } | ||
13 | public override bool Equals(object other) | ||
14 | { | ||
15 | return _PBJISuper.Equals(other); | ||
16 | } | ||
17 | public int SerializedSize { get { return _PBJISuper.SerializedSize; } } | ||
18 | |||
19 | public override int GetHashCode() { return _PBJISuper.GetHashCode(); } | ||
20 | |||
21 | public override string ToString() | ||
22 | { | ||
23 | return _PBJISuper.ToString(); | ||
24 | } | ||
25 | public virtual IBuilder WeakCreateBuilderForType() { return null; } | ||
26 | public Google.ProtocolBuffers.ByteString ToByteString() | ||
27 | { | ||
28 | return _PBJISuper.ToByteString(); | ||
29 | } | ||
30 | public byte[] ToByteArray() | ||
31 | { | ||
32 | return _PBJISuper.ToByteArray(); | ||
33 | } | ||
34 | public void WriteTo(global::System.IO.Stream output) | ||
35 | { | ||
36 | _PBJISuper.WriteTo(output); | ||
37 | } | ||
38 | // Google.ProtocolBuffers.MessageDescriptor DescriptorForType { get {return _PBJISuper.DescriptorForType;} } | ||
39 | public Google.ProtocolBuffers.UnknownFieldSet UnknownFields { get { return _PBJISuper.UnknownFields; } } | ||
40 | public class IBuilder | ||
41 | { | ||
42 | public virtual Google.ProtocolBuffers.IBuilder _PBJISuper { get { return null; } } | ||
43 | protected virtual bool _HasAllPBJFields { get { return true; } } | ||
44 | } | ||
45 | } | ||
46 | |||
47 | public struct Vector2f | ||
48 | { | ||
49 | |||
50 | public float x; | ||
51 | public float y; | ||
52 | |||
53 | |||
54 | public Vector2f(float _x, float _y) | ||
55 | { | ||
56 | x = _x; y = _y; | ||
57 | } | ||
58 | |||
59 | public Vector2f(Vector2f cpy) | ||
60 | { | ||
61 | x = cpy.x; y = cpy.y; | ||
62 | } | ||
63 | |||
64 | |||
65 | public Vector2f Negate() | ||
66 | { | ||
67 | return new Vector2f(-x, -y); | ||
68 | } | ||
69 | |||
70 | public Vector2f Add(Vector2f rhs) | ||
71 | { | ||
72 | return new Vector2f(x + rhs.x, y + rhs.y); | ||
73 | } | ||
74 | |||
75 | public Vector2f Subtract(Vector2f rhs) | ||
76 | { | ||
77 | return new Vector2f(x - rhs.x, y - rhs.y); | ||
78 | } | ||
79 | |||
80 | public Vector2f Multiply(Vector2f rhs) | ||
81 | { | ||
82 | return new Vector2f(x * rhs.x, y * rhs.y); | ||
83 | } | ||
84 | |||
85 | public Vector2f Multiply(float s) | ||
86 | { | ||
87 | return new Vector2f(x * s, y * s); | ||
88 | } | ||
89 | |||
90 | public Vector2f Divide(Vector2f rhs) | ||
91 | { | ||
92 | return new Vector2f(x / rhs.x, y / rhs.y); | ||
93 | } | ||
94 | |||
95 | public Vector2f Divide(float s) | ||
96 | { | ||
97 | return new Vector2f(x / s, y / s); | ||
98 | } | ||
99 | |||
100 | public float Dot(Vector2f rhs) | ||
101 | { | ||
102 | return (x * rhs.x + y * rhs.y); | ||
103 | } | ||
104 | |||
105 | public void Normalize() | ||
106 | { | ||
107 | float len = Length; | ||
108 | if (len != 0.0) | ||
109 | { | ||
110 | x /= len; y /= len; | ||
111 | } | ||
112 | } | ||
113 | |||
114 | public Vector2f Normalized | ||
115 | { | ||
116 | get | ||
117 | { | ||
118 | Vector2f normed = new Vector2f(this); | ||
119 | normed.Normalize(); | ||
120 | return normed; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | public float SquaredLength | ||
125 | { | ||
126 | get | ||
127 | { | ||
128 | return (x * x + y * y); | ||
129 | } | ||
130 | } | ||
131 | public float Length | ||
132 | { | ||
133 | get | ||
134 | { | ||
135 | return (float)Math.Sqrt(SquaredLength); | ||
136 | } | ||
137 | } | ||
138 | |||
139 | |||
140 | public override string ToString() | ||
141 | { | ||
142 | return String.Format("<{0}, {1}>", x, y); | ||
143 | } | ||
144 | |||
145 | |||
146 | public static Vector2f operator -(Vector2f uo) | ||
147 | { | ||
148 | return uo.Negate(); | ||
149 | } | ||
150 | |||
151 | public static Vector2f operator +(Vector2f lhs, Vector2f rhs) | ||
152 | { | ||
153 | return lhs.Add(rhs); | ||
154 | } | ||
155 | |||
156 | public static Vector2f operator -(Vector2f lhs, Vector2f rhs) | ||
157 | { | ||
158 | return lhs.Subtract(rhs); | ||
159 | } | ||
160 | |||
161 | public static Vector2f operator *(Vector2f lhs, Vector2f rhs) | ||
162 | { | ||
163 | return lhs.Multiply(rhs); | ||
164 | } | ||
165 | |||
166 | public static Vector2f operator *(Vector2f lhs, float rhs) | ||
167 | { | ||
168 | return lhs.Multiply(rhs); | ||
169 | } | ||
170 | public static Vector2f operator *(float lhs, Vector2f rhs) | ||
171 | { | ||
172 | return rhs.Multiply(lhs); | ||
173 | } | ||
174 | |||
175 | public static Vector2f operator /(Vector2f lhs, Vector2f rhs) | ||
176 | { | ||
177 | return lhs.Divide(rhs); | ||
178 | } | ||
179 | |||
180 | public static Vector2f operator /(Vector2f lhs, float rhs) | ||
181 | { | ||
182 | return lhs.Divide(rhs); | ||
183 | } | ||
184 | |||
185 | } // struct Vector2f | ||
186 | |||
187 | public struct Vector2d | ||
188 | { | ||
189 | |||
190 | public double x; | ||
191 | public double y; | ||
192 | |||
193 | |||
194 | public Vector2d(double _x, double _y) | ||
195 | { | ||
196 | x = _x; y = _y; | ||
197 | } | ||
198 | |||
199 | public Vector2d(Vector2d cpy) | ||
200 | { | ||
201 | x = cpy.x; y = cpy.y; | ||
202 | } | ||
203 | |||
204 | |||
205 | public Vector2d Negate() | ||
206 | { | ||
207 | return new Vector2d(-x, -y); | ||
208 | } | ||
209 | |||
210 | public Vector2d Add(Vector2d rhs) | ||
211 | { | ||
212 | return new Vector2d(x + rhs.x, y + rhs.y); | ||
213 | } | ||
214 | |||
215 | public Vector2d Subtract(Vector2d rhs) | ||
216 | { | ||
217 | return new Vector2d(x - rhs.x, y - rhs.y); | ||
218 | } | ||
219 | |||
220 | public Vector2d Multiply(Vector2d rhs) | ||
221 | { | ||
222 | return new Vector2d(x * rhs.x, y * rhs.y); | ||
223 | } | ||
224 | |||
225 | public Vector2d Multiply(double s) | ||
226 | { | ||
227 | return new Vector2d(x * s, y * s); | ||
228 | } | ||
229 | |||
230 | public Vector2d Divide(Vector2d rhs) | ||
231 | { | ||
232 | return new Vector2d(x / rhs.x, y / rhs.y); | ||
233 | } | ||
234 | |||
235 | public Vector2d Divide(double s) | ||
236 | { | ||
237 | return new Vector2d(x / s, y / s); | ||
238 | } | ||
239 | |||
240 | public double Dot(Vector2d rhs) | ||
241 | { | ||
242 | return (x * rhs.x + y * rhs.y); | ||
243 | } | ||
244 | |||
245 | public void Normalize() | ||
246 | { | ||
247 | double len = Length; | ||
248 | if (len != 0.0) | ||
249 | { | ||
250 | x /= len; y /= len; | ||
251 | } | ||
252 | } | ||
253 | |||
254 | public Vector2d Normalized | ||
255 | { | ||
256 | get | ||
257 | { | ||
258 | Vector2d normed = new Vector2d(this); | ||
259 | normed.Normalize(); | ||
260 | return normed; | ||
261 | } | ||
262 | } | ||
263 | |||
264 | public double SquaredLength | ||
265 | { | ||
266 | get | ||
267 | { | ||
268 | return (x * x + y * y); | ||
269 | } | ||
270 | } | ||
271 | public double Length | ||
272 | { | ||
273 | get | ||
274 | { | ||
275 | return Math.Sqrt(SquaredLength); | ||
276 | } | ||
277 | } | ||
278 | |||
279 | |||
280 | public override string ToString() | ||
281 | { | ||
282 | return String.Format("<{0}, {1}>", x, y); | ||
283 | } | ||
284 | |||
285 | |||
286 | public static Vector2d operator -(Vector2d uo) | ||
287 | { | ||
288 | return uo.Negate(); | ||
289 | } | ||
290 | |||
291 | public static Vector2d operator +(Vector2d lhs, Vector2d rhs) | ||
292 | { | ||
293 | return lhs.Add(rhs); | ||
294 | } | ||
295 | |||
296 | public static Vector2d operator -(Vector2d lhs, Vector2d rhs) | ||
297 | { | ||
298 | return lhs.Subtract(rhs); | ||
299 | } | ||
300 | |||
301 | public static Vector2d operator *(Vector2d lhs, Vector2d rhs) | ||
302 | { | ||
303 | return lhs.Multiply(rhs); | ||
304 | } | ||
305 | |||
306 | public static Vector2d operator *(Vector2d lhs, double rhs) | ||
307 | { | ||
308 | return lhs.Multiply(rhs); | ||
309 | } | ||
310 | public static Vector2d operator *(double lhs, Vector2d rhs) | ||
311 | { | ||
312 | return rhs.Multiply(lhs); | ||
313 | } | ||
314 | |||
315 | public static Vector2d operator /(Vector2d lhs, Vector2d rhs) | ||
316 | { | ||
317 | return lhs.Divide(rhs); | ||
318 | } | ||
319 | |||
320 | public static Vector2d operator /(Vector2d lhs, double rhs) | ||
321 | { | ||
322 | return lhs.Divide(rhs); | ||
323 | } | ||
324 | |||
325 | } // struct Vector2d | ||
326 | |||
327 | public struct Vector3f | ||
328 | { | ||
329 | |||
330 | public float x; | ||
331 | public float y; | ||
332 | public float z; | ||
333 | |||
334 | |||
335 | public Vector3f(float _x, float _y, float _z) | ||
336 | { | ||
337 | x = _x; y = _y; z = _z; | ||
338 | } | ||
339 | |||
340 | public Vector3f(Vector3f cpy) | ||
341 | { | ||
342 | x = cpy.x; y = cpy.y; z = cpy.z; | ||
343 | } | ||
344 | |||
345 | |||
346 | public Vector3f Negate() | ||
347 | { | ||
348 | return new Vector3f(-x, -y, -z); | ||
349 | } | ||
350 | |||
351 | public Vector3f Add(Vector3f rhs) | ||
352 | { | ||
353 | return new Vector3f(x + rhs.x, y + rhs.y, z + rhs.z); | ||
354 | } | ||
355 | |||
356 | public Vector3f Subtract(Vector3f rhs) | ||
357 | { | ||
358 | return new Vector3f(x - rhs.x, y - rhs.y, z - rhs.z); | ||
359 | } | ||
360 | |||
361 | public Vector3f Multiply(Vector3f rhs) | ||
362 | { | ||
363 | return new Vector3f(x * rhs.x, y * rhs.y, z * rhs.z); | ||
364 | } | ||
365 | |||
366 | public Vector3f Multiply(float s) | ||
367 | { | ||
368 | return new Vector3f(x * s, y * s, z * s); | ||
369 | } | ||
370 | |||
371 | public Vector3f Divide(Vector3f rhs) | ||
372 | { | ||
373 | return new Vector3f(x / rhs.x, y / rhs.y, z / rhs.z); | ||
374 | } | ||
375 | |||
376 | public Vector3f Divide(float s) | ||
377 | { | ||
378 | return new Vector3f(x / s, y / s, z / s); | ||
379 | } | ||
380 | |||
381 | public float Dot(Vector3f rhs) | ||
382 | { | ||
383 | return (x * rhs.x + y * rhs.y + z * rhs.z); | ||
384 | } | ||
385 | |||
386 | public Vector3f Cross(Vector3f rhs) | ||
387 | { | ||
388 | return new Vector3f(y * rhs.z - z * rhs.y, z * rhs.x - x * rhs.z, x * rhs.y - y * rhs.x); | ||
389 | } | ||
390 | |||
391 | public void Normalize() | ||
392 | { | ||
393 | float len = Length; | ||
394 | if (len != 0.0) | ||
395 | { | ||
396 | x /= len; y /= len; z /= len; | ||
397 | } | ||
398 | } | ||
399 | |||
400 | public Vector3f Normalized | ||
401 | { | ||
402 | get | ||
403 | { | ||
404 | Vector3f normed = new Vector3f(this); | ||
405 | normed.Normalize(); | ||
406 | return normed; | ||
407 | } | ||
408 | } | ||
409 | |||
410 | public float SquaredLength | ||
411 | { | ||
412 | get | ||
413 | { | ||
414 | return (x * x + y * y + z * z); | ||
415 | } | ||
416 | } | ||
417 | public float Length | ||
418 | { | ||
419 | get | ||
420 | { | ||
421 | return (float)Math.Sqrt(SquaredLength); | ||
422 | } | ||
423 | } | ||
424 | |||
425 | |||
426 | public override string ToString() | ||
427 | { | ||
428 | return String.Format("<{0}, {1}, {2}>", x, y, z); | ||
429 | } | ||
430 | |||
431 | |||
432 | public static Vector3f operator -(Vector3f uo) | ||
433 | { | ||
434 | return uo.Negate(); | ||
435 | } | ||
436 | |||
437 | public static Vector3f operator +(Vector3f lhs, Vector3f rhs) | ||
438 | { | ||
439 | return lhs.Add(rhs); | ||
440 | } | ||
441 | |||
442 | public static Vector3f operator -(Vector3f lhs, Vector3f rhs) | ||
443 | { | ||
444 | return lhs.Subtract(rhs); | ||
445 | } | ||
446 | |||
447 | public static Vector3f operator *(Vector3f lhs, Vector3f rhs) | ||
448 | { | ||
449 | return lhs.Multiply(rhs); | ||
450 | } | ||
451 | |||
452 | public static Vector3f operator *(Vector3f lhs, float rhs) | ||
453 | { | ||
454 | return lhs.Multiply(rhs); | ||
455 | } | ||
456 | public static Vector3f operator *(float lhs, Vector3f rhs) | ||
457 | { | ||
458 | return rhs.Multiply(lhs); | ||
459 | } | ||
460 | |||
461 | public static Vector3f operator /(Vector3f lhs, Vector3f rhs) | ||
462 | { | ||
463 | return lhs.Divide(rhs); | ||
464 | } | ||
465 | |||
466 | public static Vector3f operator /(Vector3f lhs, float rhs) | ||
467 | { | ||
468 | return lhs.Divide(rhs); | ||
469 | } | ||
470 | |||
471 | } // struct Vector3f | ||
472 | |||
473 | public struct Vector3d | ||
474 | { | ||
475 | |||
476 | public double x; | ||
477 | public double y; | ||
478 | public double z; | ||
479 | |||
480 | |||
481 | public Vector3d(double _x, double _y, double _z) | ||
482 | { | ||
483 | x = _x; y = _y; z = _z; | ||
484 | } | ||
485 | |||
486 | public Vector3d(Vector3d cpy) | ||
487 | { | ||
488 | x = cpy.x; y = cpy.y; z = cpy.z; | ||
489 | } | ||
490 | |||
491 | |||
492 | public Vector3d Negate() | ||
493 | { | ||
494 | return new Vector3d(-x, -y, -z); | ||
495 | } | ||
496 | |||
497 | public Vector3d Add(Vector3d rhs) | ||
498 | { | ||
499 | return new Vector3d(x + rhs.x, y + rhs.y, z + rhs.z); | ||
500 | } | ||
501 | |||
502 | public Vector3d Subtract(Vector3d rhs) | ||
503 | { | ||
504 | return new Vector3d(x - rhs.x, y - rhs.y, z - rhs.z); | ||
505 | } | ||
506 | |||
507 | public Vector3d Multiply(Vector3d rhs) | ||
508 | { | ||
509 | return new Vector3d(x * rhs.x, y * rhs.y, z * rhs.z); | ||
510 | } | ||
511 | |||
512 | public Vector3d Multiply(double s) | ||
513 | { | ||
514 | return new Vector3d(x * s, y * s, z * s); | ||
515 | } | ||
516 | |||
517 | public Vector3d Divide(Vector3d rhs) | ||
518 | { | ||
519 | return new Vector3d(x / rhs.x, y / rhs.y, z / rhs.z); | ||
520 | } | ||
521 | |||
522 | public Vector3d Divide(double s) | ||
523 | { | ||
524 | return new Vector3d(x / s, y / s, z / s); | ||
525 | } | ||
526 | |||
527 | public double Dot(Vector3d rhs) | ||
528 | { | ||
529 | return (x * rhs.x + y * rhs.y + z * rhs.z); | ||
530 | } | ||
531 | |||
532 | public Vector3d Cross(Vector3d rhs) | ||
533 | { | ||
534 | return new Vector3d(y * rhs.z - z * rhs.y, z * rhs.x - x * rhs.z, x * rhs.y - y * rhs.x); | ||
535 | } | ||
536 | |||
537 | public void Normalize() | ||
538 | { | ||
539 | double len = Length; | ||
540 | if (len != 0.0) | ||
541 | { | ||
542 | x /= len; y /= len; z /= len; | ||
543 | } | ||
544 | } | ||
545 | |||
546 | public Vector3d Normalized | ||
547 | { | ||
548 | get | ||
549 | { | ||
550 | Vector3d normed = new Vector3d(this); | ||
551 | normed.Normalize(); | ||
552 | return normed; | ||
553 | } | ||
554 | } | ||
555 | |||
556 | public double SquaredLength | ||
557 | { | ||
558 | get | ||
559 | { | ||
560 | return (x * x + y * y + z * z); | ||
561 | } | ||
562 | } | ||
563 | public double Length | ||
564 | { | ||
565 | get | ||
566 | { | ||
567 | return Math.Sqrt(SquaredLength); | ||
568 | } | ||
569 | } | ||
570 | |||
571 | |||
572 | public override string ToString() | ||
573 | { | ||
574 | return String.Format("<{0}, {1}, {2}>", x, y, z); | ||
575 | } | ||
576 | |||
577 | |||
578 | public static Vector3d operator -(Vector3d uo) | ||
579 | { | ||
580 | return uo.Negate(); | ||
581 | } | ||
582 | |||
583 | public static Vector3d operator +(Vector3d lhs, Vector3d rhs) | ||
584 | { | ||
585 | return lhs.Add(rhs); | ||
586 | } | ||
587 | |||
588 | public static Vector3d operator -(Vector3d lhs, Vector3d rhs) | ||
589 | { | ||
590 | return lhs.Subtract(rhs); | ||
591 | } | ||
592 | |||
593 | public static Vector3d operator *(Vector3d lhs, Vector3d rhs) | ||
594 | { | ||
595 | return lhs.Multiply(rhs); | ||
596 | } | ||
597 | |||
598 | public static Vector3d operator *(Vector3d lhs, double rhs) | ||
599 | { | ||
600 | return lhs.Multiply(rhs); | ||
601 | } | ||
602 | public static Vector3d operator *(double lhs, Vector3d rhs) | ||
603 | { | ||
604 | return rhs.Multiply(lhs); | ||
605 | } | ||
606 | |||
607 | public static Vector3d operator /(Vector3d lhs, Vector3d rhs) | ||
608 | { | ||
609 | return lhs.Divide(rhs); | ||
610 | } | ||
611 | |||
612 | public static Vector3d operator /(Vector3d lhs, double rhs) | ||
613 | { | ||
614 | return lhs.Divide(rhs); | ||
615 | } | ||
616 | |||
617 | } // struct Vector3d | ||
618 | |||
619 | public struct Quaternion | ||
620 | { | ||
621 | |||
622 | public float w; | ||
623 | public float x; | ||
624 | public float y; | ||
625 | public float z; | ||
626 | |||
627 | |||
628 | public Quaternion(float _w, float _x, float _y, float _z) | ||
629 | { | ||
630 | w = _w; x = _x; y = _y; z = _z; | ||
631 | } | ||
632 | |||
633 | public Quaternion(Quaternion cpy) | ||
634 | { | ||
635 | w = cpy.w; x = cpy.x; y = cpy.y; z = cpy.z; | ||
636 | } | ||
637 | |||
638 | public static readonly Quaternion Identity = new Quaternion((float)1.0, (float)0.0, (float)0.0, (float)0.0); | ||
639 | |||
640 | public static Quaternion FromAxisAngle(Vector3f axis, float rads) | ||
641 | { | ||
642 | float halfAngle = rads * 0.5f; | ||
643 | float sinHalf = (float)Math.Sin(halfAngle); | ||
644 | float w = (float)Math.Cos(halfAngle); | ||
645 | float x = sinHalf * axis.x; | ||
646 | float y = sinHalf * axis.y; | ||
647 | float z = sinHalf * axis.z; | ||
648 | return new Quaternion(w, x, y, z); | ||
649 | } | ||
650 | |||
651 | public static Quaternion FromAxisAngle(Vector3d axis, float rads) | ||
652 | { | ||
653 | float halfAngle = rads * 0.5f; | ||
654 | float sinHalf = (float)Math.Sin(halfAngle); | ||
655 | float w = (float)Math.Cos(halfAngle); | ||
656 | float x = (float)(sinHalf * axis.x); | ||
657 | float y = (float)(sinHalf * axis.y); | ||
658 | float z = (float)(sinHalf * axis.z); | ||
659 | return new Quaternion(w, x, y, z); | ||
660 | } | ||
661 | |||
662 | |||
663 | public Quaternion Add(Quaternion rhs) | ||
664 | { | ||
665 | return new Quaternion(w + rhs.w, x + rhs.x, y + rhs.y, z + rhs.z); | ||
666 | } | ||
667 | |||
668 | public Quaternion Subtract(Quaternion rhs) | ||
669 | { | ||
670 | return new Quaternion(w - rhs.w, x - rhs.x, y - rhs.y, z - rhs.z); | ||
671 | } | ||
672 | |||
673 | public Quaternion Multiply(Quaternion rhs) | ||
674 | { | ||
675 | return new Quaternion( | ||
676 | w * rhs.w - x * rhs.x - y * rhs.y - z * rhs.z, | ||
677 | w * rhs.x + x * rhs.w + y * rhs.z - z * rhs.y, | ||
678 | w * rhs.y + y * rhs.w + z * rhs.x - x * rhs.z, | ||
679 | w * rhs.z + z * rhs.w + x * rhs.y - y * rhs.x | ||
680 | ); | ||
681 | } | ||
682 | |||
683 | public Vector3f Multiply(Vector3f rhs) | ||
684 | { | ||
685 | Vector3f qvec = new Vector3f(x, y, z); | ||
686 | Vector3f uv = qvec.Cross(rhs); | ||
687 | Vector3f uuv = qvec.Cross(uv); | ||
688 | uv *= 2.0f * w; | ||
689 | uuv *= 2.0f; | ||
690 | |||
691 | return rhs + uv + uuv; | ||
692 | } | ||
693 | |||
694 | public Vector3d Multiply(Vector3d rhs) | ||
695 | { | ||
696 | Vector3d qvec = new Vector3d(x, y, z); | ||
697 | Vector3d uv = qvec.Cross(rhs); | ||
698 | Vector3d uuv = qvec.Cross(uv); | ||
699 | uv *= 2.0f * w; | ||
700 | uuv *= 2.0f; | ||
701 | |||
702 | return rhs + uv + uuv; | ||
703 | } | ||
704 | |||
705 | public Quaternion Multiply(float rhs) | ||
706 | { | ||
707 | return new Quaternion(w * rhs, x * rhs, y * rhs, z * rhs); | ||
708 | } | ||
709 | |||
710 | public Quaternion Negate() | ||
711 | { | ||
712 | return new Quaternion(-w, -x, -y, -z); | ||
713 | } | ||
714 | |||
715 | public float Dot(Quaternion rhs) | ||
716 | { | ||
717 | return (w * rhs.w + x * rhs.x + y * rhs.y + z * rhs.z); | ||
718 | } | ||
719 | |||
720 | public float Norm | ||
721 | { | ||
722 | get | ||
723 | { | ||
724 | return (float)Math.Sqrt(w * w + x * x + y * y + z * z); | ||
725 | } | ||
726 | } | ||
727 | |||
728 | public float SquareNorm | ||
729 | { | ||
730 | get | ||
731 | { | ||
732 | return (w * w + x * x + y * y + z * z); | ||
733 | } | ||
734 | } | ||
735 | |||
736 | public void Normalize() | ||
737 | { | ||
738 | float len = SquareNorm; | ||
739 | if (len == 0.0) return; | ||
740 | float factor = 1.0f / (float)Math.Sqrt(len); | ||
741 | this *= factor; | ||
742 | } | ||
743 | |||
744 | public Quaternion Normalized | ||
745 | { | ||
746 | get | ||
747 | { | ||
748 | Quaternion q = new Quaternion(this); | ||
749 | q.Normalize(); | ||
750 | return q; | ||
751 | } | ||
752 | } | ||
753 | |||
754 | public Quaternion Inverse | ||
755 | { | ||
756 | get | ||
757 | { | ||
758 | float norm = SquareNorm; | ||
759 | if (norm > 0.0) | ||
760 | { | ||
761 | double invnorm = 1.0 / norm; | ||
762 | return new Quaternion((float)(w * invnorm), (float)(-x * invnorm), (float)(-y * invnorm), (float)(-z * invnorm)); | ||
763 | } | ||
764 | else | ||
765 | return new Quaternion((float)0.0, 0.0f, 0.0f, 0.0f); | ||
766 | } | ||
767 | } | ||
768 | |||
769 | |||
770 | public override string ToString() | ||
771 | { | ||
772 | return String.Format("<{0}, {1}, {2}, {3}>", w, x, y, z); | ||
773 | } | ||
774 | |||
775 | |||
776 | |||
777 | public static Quaternion operator -(Quaternion uo) | ||
778 | { | ||
779 | return uo.Negate(); | ||
780 | } | ||
781 | |||
782 | public static Quaternion operator +(Quaternion lhs, Quaternion rhs) | ||
783 | { | ||
784 | return lhs.Add(rhs); | ||
785 | } | ||
786 | |||
787 | public static Quaternion operator -(Quaternion lhs, Quaternion rhs) | ||
788 | { | ||
789 | return lhs.Subtract(rhs); | ||
790 | } | ||
791 | |||
792 | public static Vector3f operator *(Quaternion lhs, Vector3f rhs) | ||
793 | { | ||
794 | return lhs.Multiply(rhs); | ||
795 | } | ||
796 | |||
797 | public static Vector3d operator *(Quaternion lhs, Vector3d rhs) | ||
798 | { | ||
799 | return lhs.Multiply(rhs); | ||
800 | } | ||
801 | |||
802 | public static Quaternion operator *(Quaternion lhs, Quaternion rhs) | ||
803 | { | ||
804 | return lhs.Multiply(rhs); | ||
805 | } | ||
806 | |||
807 | public static Quaternion operator *(Quaternion lhs, float rhs) | ||
808 | { | ||
809 | return lhs.Multiply(rhs); | ||
810 | } | ||
811 | |||
812 | public static Quaternion operator *(float lhs, Quaternion rhs) | ||
813 | { | ||
814 | return rhs.Multiply(lhs); | ||
815 | } | ||
816 | |||
817 | } // struct Quaternion | ||
818 | |||
819 | |||
820 | public struct Vector4f | ||
821 | { | ||
822 | |||
823 | public float x; | ||
824 | public float y; | ||
825 | public float z; | ||
826 | public float w; | ||
827 | |||
828 | |||
829 | public Vector4f(float _x, float _y, float _z, float _w) | ||
830 | { | ||
831 | x = _x; y = _y; z = _z; w = _w; | ||
832 | } | ||
833 | |||
834 | public Vector4f(Vector4f cpy) | ||
835 | { | ||
836 | x = cpy.x; y = cpy.y; z = cpy.z; w = cpy.w; | ||
837 | } | ||
838 | |||
839 | |||
840 | public Vector4f Negate() | ||
841 | { | ||
842 | return new Vector4f(-x, -y, -z, -w); | ||
843 | } | ||
844 | |||
845 | public Vector4f Add(Vector4f rhs) | ||
846 | { | ||
847 | return new Vector4f(x + rhs.x, y + rhs.y, z + rhs.z, w + rhs.w); | ||
848 | } | ||
849 | |||
850 | public Vector4f Subtract(Vector4f rhs) | ||
851 | { | ||
852 | return new Vector4f(x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w); | ||
853 | } | ||
854 | |||
855 | public Vector4f Multiply(Vector4f rhs) | ||
856 | { | ||
857 | return new Vector4f(x * rhs.x, y * rhs.y, z * rhs.z, w * rhs.w); | ||
858 | } | ||
859 | |||
860 | public Vector4f Multiply(float s) | ||
861 | { | ||
862 | return new Vector4f(x * s, y * s, z * s, w * s); | ||
863 | } | ||
864 | |||
865 | public Vector4f Divide(Vector4f rhs) | ||
866 | { | ||
867 | return new Vector4f(x / rhs.x, y / rhs.y, z / rhs.z, w / rhs.w); | ||
868 | } | ||
869 | |||
870 | public Vector4f Divide(float s) | ||
871 | { | ||
872 | return new Vector4f(x / s, y / s, z / s, w / s); | ||
873 | } | ||
874 | |||
875 | public float Dot(Vector4f rhs) | ||
876 | { | ||
877 | return (x * rhs.x + y * rhs.y + z * rhs.z + w * rhs.w); | ||
878 | } | ||
879 | |||
880 | public void Normalize() | ||
881 | { | ||
882 | float len = Length; | ||
883 | if (len != 0.0) | ||
884 | { | ||
885 | x /= len; y /= len; z /= len; w /= len; | ||
886 | } | ||
887 | } | ||
888 | |||
889 | public Vector4f Normalized | ||
890 | { | ||
891 | get | ||
892 | { | ||
893 | Vector4f normed = new Vector4f(this); | ||
894 | normed.Normalize(); | ||
895 | return normed; | ||
896 | } | ||
897 | } | ||
898 | |||
899 | public float SquaredLength | ||
900 | { | ||
901 | get | ||
902 | { | ||
903 | return (x * x + y * y + z * z + w * w); | ||
904 | } | ||
905 | } | ||
906 | public float Length | ||
907 | { | ||
908 | get | ||
909 | { | ||
910 | return (float)Math.Sqrt(SquaredLength); | ||
911 | } | ||
912 | } | ||
913 | |||
914 | |||
915 | public override string ToString() | ||
916 | { | ||
917 | return String.Format("<{0}, {1}, {2}, {3}>", x, y, z, w); | ||
918 | } | ||
919 | |||
920 | |||
921 | public static Vector4f operator -(Vector4f uo) | ||
922 | { | ||
923 | return uo.Negate(); | ||
924 | } | ||
925 | |||
926 | public static Vector4f operator +(Vector4f lhs, Vector4f rhs) | ||
927 | { | ||
928 | return lhs.Add(rhs); | ||
929 | } | ||
930 | |||
931 | public static Vector4f operator -(Vector4f lhs, Vector4f rhs) | ||
932 | { | ||
933 | return lhs.Subtract(rhs); | ||
934 | } | ||
935 | |||
936 | public static Vector4f operator *(Vector4f lhs, Vector4f rhs) | ||
937 | { | ||
938 | return lhs.Multiply(rhs); | ||
939 | } | ||
940 | |||
941 | public static Vector4f operator *(Vector4f lhs, float rhs) | ||
942 | { | ||
943 | return lhs.Multiply(rhs); | ||
944 | } | ||
945 | public static Vector4f operator *(float lhs, Vector4f rhs) | ||
946 | { | ||
947 | return rhs.Multiply(lhs); | ||
948 | } | ||
949 | |||
950 | public static Vector4f operator /(Vector4f lhs, Vector4f rhs) | ||
951 | { | ||
952 | return lhs.Divide(rhs); | ||
953 | } | ||
954 | |||
955 | public static Vector4f operator /(Vector4f lhs, float rhs) | ||
956 | { | ||
957 | return lhs.Divide(rhs); | ||
958 | } | ||
959 | |||
960 | } // struct Vector4f | ||
961 | |||
962 | |||
963 | |||
964 | public struct Vector4d | ||
965 | { | ||
966 | |||
967 | public double x; | ||
968 | public double y; | ||
969 | public double z; | ||
970 | public double w; | ||
971 | |||
972 | |||
973 | public Vector4d(double _x, double _y, double _z, double _w) | ||
974 | { | ||
975 | x = _x; y = _y; z = _z; w = _w; | ||
976 | } | ||
977 | |||
978 | public Vector4d(Vector4d cpy) | ||
979 | { | ||
980 | x = cpy.x; y = cpy.y; z = cpy.z; w = cpy.w; | ||
981 | } | ||
982 | |||
983 | |||
984 | public Vector4d Negate() | ||
985 | { | ||
986 | return new Vector4d(-x, -y, -z, -w); | ||
987 | } | ||
988 | |||
989 | public Vector4d Add(Vector4d rhs) | ||
990 | { | ||
991 | return new Vector4d(x + rhs.x, y + rhs.y, z + rhs.z, w + rhs.w); | ||
992 | } | ||
993 | |||
994 | public Vector4d Subtract(Vector4d rhs) | ||
995 | { | ||
996 | return new Vector4d(x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w); | ||
997 | } | ||
998 | |||
999 | public Vector4d Multiply(Vector4d rhs) | ||
1000 | { | ||
1001 | return new Vector4d(x * rhs.x, y * rhs.y, z * rhs.z, w * rhs.w); | ||
1002 | } | ||
1003 | |||
1004 | public Vector4d Multiply(double s) | ||
1005 | { | ||
1006 | return new Vector4d(x * s, y * s, z * s, w * s); | ||
1007 | } | ||
1008 | |||
1009 | public Vector4d Divide(Vector4d rhs) | ||
1010 | { | ||
1011 | return new Vector4d(x / rhs.x, y / rhs.y, z / rhs.z, w / rhs.w); | ||
1012 | } | ||
1013 | |||
1014 | public Vector4d Divide(double s) | ||
1015 | { | ||
1016 | return new Vector4d(x / s, y / s, z / s, w / s); | ||
1017 | } | ||
1018 | |||
1019 | public double Dot(Vector4d rhs) | ||
1020 | { | ||
1021 | return (x * rhs.x + y * rhs.y + z * rhs.z + w * rhs.w); | ||
1022 | } | ||
1023 | |||
1024 | public void Normalize() | ||
1025 | { | ||
1026 | double len = Length; | ||
1027 | if (len != 0.0) | ||
1028 | { | ||
1029 | x /= len; y /= len; z /= len; w /= len; | ||
1030 | } | ||
1031 | } | ||
1032 | |||
1033 | public Vector4d Normalized | ||
1034 | { | ||
1035 | get | ||
1036 | { | ||
1037 | Vector4d normed = new Vector4d(this); | ||
1038 | normed.Normalize(); | ||
1039 | return normed; | ||
1040 | } | ||
1041 | } | ||
1042 | |||
1043 | public double SquaredLength | ||
1044 | { | ||
1045 | get | ||
1046 | { | ||
1047 | return (x * x + y * y + z * z + w * w); | ||
1048 | } | ||
1049 | } | ||
1050 | public double Length | ||
1051 | { | ||
1052 | get | ||
1053 | { | ||
1054 | return Math.Sqrt(SquaredLength); | ||
1055 | } | ||
1056 | } | ||
1057 | |||
1058 | |||
1059 | public override string ToString() | ||
1060 | { | ||
1061 | return String.Format("<{0}, {1}, {2}, {3}>", x, y, z, w); | ||
1062 | } | ||
1063 | |||
1064 | |||
1065 | public static Vector4d operator -(Vector4d uo) | ||
1066 | { | ||
1067 | return uo.Negate(); | ||
1068 | } | ||
1069 | |||
1070 | public static Vector4d operator +(Vector4d lhs, Vector4d rhs) | ||
1071 | { | ||
1072 | return lhs.Add(rhs); | ||
1073 | } | ||
1074 | |||
1075 | public static Vector4d operator -(Vector4d lhs, Vector4d rhs) | ||
1076 | { | ||
1077 | return lhs.Subtract(rhs); | ||
1078 | } | ||
1079 | |||
1080 | public static Vector4d operator *(Vector4d lhs, Vector4d rhs) | ||
1081 | { | ||
1082 | return lhs.Multiply(rhs); | ||
1083 | } | ||
1084 | |||
1085 | public static Vector4d operator *(Vector4d lhs, double rhs) | ||
1086 | { | ||
1087 | return lhs.Multiply(rhs); | ||
1088 | } | ||
1089 | public static Vector4d operator *(double lhs, Vector4d rhs) | ||
1090 | { | ||
1091 | return rhs.Multiply(lhs); | ||
1092 | } | ||
1093 | |||
1094 | public static Vector4d operator /(Vector4d lhs, Vector4d rhs) | ||
1095 | { | ||
1096 | return lhs.Divide(rhs); | ||
1097 | } | ||
1098 | |||
1099 | public static Vector4d operator /(Vector4d lhs, double rhs) | ||
1100 | { | ||
1101 | return lhs.Divide(rhs); | ||
1102 | } | ||
1103 | |||
1104 | } // struct Vector4d | ||
1105 | |||
1106 | |||
1107 | |||
1108 | public struct BoundingBox3f3f | ||
1109 | { | ||
1110 | Vector3f mMin; | ||
1111 | Vector3f mDiag; | ||
1112 | public BoundingBox3f3f(float minx, float miny, float minz, float diagx, float diagy, float diagz) | ||
1113 | { | ||
1114 | mMin.x = minx; | ||
1115 | mMin.y = miny; | ||
1116 | mMin.z = minz; | ||
1117 | |||
1118 | mDiag.x = diagx; | ||
1119 | mDiag.y = diagy; | ||
1120 | mDiag.z = diagz; | ||
1121 | } | ||
1122 | public BoundingBox3f3f(Vector3f min, Vector3f max) | ||
1123 | { | ||
1124 | mMin = min; | ||
1125 | mDiag = (max - min); | ||
1126 | } | ||
1127 | public BoundingBox3f3f(BoundingBox3f3f cpy, Vector3f scale) | ||
1128 | { | ||
1129 | mMin.x = (float)(cpy.mMin.x * scale.x); | ||
1130 | mMin.y = (float)(cpy.mMin.y * scale.y); | ||
1131 | mMin.z = (float)(cpy.mMin.z * scale.z); | ||
1132 | |||
1133 | mDiag.x = (float)(cpy.mDiag.x * scale.x); | ||
1134 | mDiag.y = (float)(cpy.mDiag.y * scale.y); | ||
1135 | mDiag.z = (float)(cpy.mDiag.z * scale.z); | ||
1136 | } | ||
1137 | public Vector3f Min | ||
1138 | { | ||
1139 | get | ||
1140 | { | ||
1141 | return new Vector3f(mMin.x, mMin.y, mMin.z); | ||
1142 | } | ||
1143 | } | ||
1144 | public Vector3f Max | ||
1145 | { | ||
1146 | get | ||
1147 | { | ||
1148 | return new Vector3f(mMin.x + mDiag.x, mMin.y + mDiag.y, mMin.z + mDiag.z); | ||
1149 | } | ||
1150 | } | ||
1151 | |||
1152 | public Vector3f Diag | ||
1153 | { | ||
1154 | get | ||
1155 | { | ||
1156 | return new Vector3f(mDiag.x, mDiag.y, mDiag.z); | ||
1157 | } | ||
1158 | } | ||
1159 | |||
1160 | |||
1161 | public override string ToString() | ||
1162 | { | ||
1163 | return "[" + this.Min.ToString() + " - " + this.Max.ToString() + "]"; | ||
1164 | } | ||
1165 | public BoundingBox3f3f Merge(BoundingBox3f3f other) | ||
1166 | { | ||
1167 | Vector3f thisMax = Max; | ||
1168 | Vector3f otherMax = other.Max; | ||
1169 | bool xless = other.mMin.x > mMin.x; | ||
1170 | bool yless = other.mMin.y > mMin.y; | ||
1171 | bool zless = other.mMin.z > mMin.z; | ||
1172 | |||
1173 | bool xmore = otherMax.x < thisMax.x; | ||
1174 | bool ymore = otherMax.y < thisMax.y; | ||
1175 | bool zmore = otherMax.z < thisMax.z; | ||
1176 | return new BoundingBox3f3f(xless ? mMin.x : other.mMin.x, | ||
1177 | yless ? mMin.y : other.mMin.y, | ||
1178 | zless ? mMin.z : other.mMin.z, | ||
1179 | xmore ? (xless ? mDiag.x : otherMax.x - mMin.x) : (xless ? thisMax.x - other.mMin.x : other.mDiag.x), | ||
1180 | ymore ? (yless ? mDiag.y : otherMax.y - mMin.y) : (yless ? thisMax.y - other.mMin.y : other.mDiag.y), | ||
1181 | zmore ? (zless ? mDiag.z : otherMax.z - mMin.z) : (zless ? thisMax.z - other.mMin.z : other.mDiag.z)); | ||
1182 | } | ||
1183 | |||
1184 | } // struct BoundingBox | ||
1185 | |||
1186 | public struct BoundingBox3d3f | ||
1187 | { | ||
1188 | Vector3d mMin; | ||
1189 | Vector3f mDiag; | ||
1190 | public BoundingBox3d3f(double minx, double miny, double minz, float diagx, float diagy, float diagz) | ||
1191 | { | ||
1192 | mMin.x = minx; | ||
1193 | mMin.y = miny; | ||
1194 | mMin.z = minz; | ||
1195 | |||
1196 | mDiag.x = diagx; | ||
1197 | mDiag.y = diagy; | ||
1198 | mDiag.z = diagz; | ||
1199 | } | ||
1200 | public BoundingBox3d3f(Vector3d min, Vector3f max) | ||
1201 | { | ||
1202 | mMin = min; | ||
1203 | |||
1204 | mDiag = new Vector3f((float)(max.x - min.x), | ||
1205 | (float)(max.y - min.y), | ||
1206 | (float)(max.z - min.z)); | ||
1207 | } | ||
1208 | public BoundingBox3d3f(BoundingBox3d3f cpy, Vector3d scale) | ||
1209 | { | ||
1210 | mMin.x = (double)(cpy.mMin.x * scale.x); | ||
1211 | mMin.y = (double)(cpy.mMin.y * scale.y); | ||
1212 | mMin.z = (double)(cpy.mMin.z * scale.z); | ||
1213 | |||
1214 | mDiag.x = (float)(cpy.mDiag.x * scale.x); | ||
1215 | mDiag.y = (float)(cpy.mDiag.y * scale.y); | ||
1216 | mDiag.z = (float)(cpy.mDiag.z * scale.z); | ||
1217 | } | ||
1218 | public Vector3d Min | ||
1219 | { | ||
1220 | get | ||
1221 | { | ||
1222 | return new Vector3d(mMin.x, mMin.y, mMin.z); | ||
1223 | } | ||
1224 | } | ||
1225 | public Vector3d Max | ||
1226 | { | ||
1227 | get | ||
1228 | { | ||
1229 | return new Vector3d(mMin.x + mDiag.x, mMin.y + mDiag.y, mMin.z + mDiag.z); | ||
1230 | } | ||
1231 | } | ||
1232 | |||
1233 | public Vector3d Diag | ||
1234 | { | ||
1235 | get | ||
1236 | { | ||
1237 | return new Vector3d(mDiag.x, mDiag.y, mDiag.z); | ||
1238 | } | ||
1239 | } | ||
1240 | |||
1241 | |||
1242 | public override string ToString() | ||
1243 | { | ||
1244 | return "[" + this.Min.ToString() + " - " + this.Max.ToString() + "]"; | ||
1245 | } | ||
1246 | public BoundingBox3d3f Merge(BoundingBox3d3f other) | ||
1247 | { | ||
1248 | Vector3d thisMax = Max; | ||
1249 | Vector3d otherMax = other.Max; | ||
1250 | bool xless = other.mMin.x > mMin.x; | ||
1251 | bool yless = other.mMin.y > mMin.y; | ||
1252 | bool zless = other.mMin.z > mMin.z; | ||
1253 | |||
1254 | bool xmore = otherMax.x < thisMax.x; | ||
1255 | bool ymore = otherMax.y < thisMax.y; | ||
1256 | bool zmore = otherMax.z < thisMax.z; | ||
1257 | return new BoundingBox3d3f(xless ? mMin.x : other.mMin.x, | ||
1258 | yless ? mMin.y : other.mMin.y, | ||
1259 | zless ? mMin.z : other.mMin.z, | ||
1260 | (float)(xmore ? (xless ? mDiag.x : otherMax.x - mMin.x) : (xless ? thisMax.x - other.mMin.x : other.mDiag.x)), | ||
1261 | (float)(ymore ? (yless ? mDiag.y : otherMax.y - mMin.y) : (yless ? thisMax.y - other.mMin.y : other.mDiag.y)), | ||
1262 | (float)(zmore ? (zless ? mDiag.z : otherMax.z - mMin.z) : (zless ? thisMax.z - other.mMin.z : other.mDiag.z))); | ||
1263 | } | ||
1264 | |||
1265 | } // struct BoundingBox | ||
1266 | |||
1267 | |||
1268 | |||
1269 | |||
1270 | public struct BoundingSphere3f | ||
1271 | { | ||
1272 | Vector3f mCenter; | ||
1273 | float mRadius; | ||
1274 | public BoundingSphere3f(float x, float y, float z, float r) | ||
1275 | { | ||
1276 | mCenter = new Vector3f(x, y, z); | ||
1277 | mRadius = r; | ||
1278 | } | ||
1279 | public BoundingSphere3f(Vector3f center, float radius) | ||
1280 | { | ||
1281 | mCenter = center; | ||
1282 | mRadius = radius; | ||
1283 | } | ||
1284 | public BoundingSphere3f(BoundingSphere3f cpy, float scale) | ||
1285 | { | ||
1286 | mCenter = cpy.mCenter; | ||
1287 | mRadius = cpy.mRadius * scale; | ||
1288 | } | ||
1289 | public Vector3f Center | ||
1290 | { | ||
1291 | get | ||
1292 | { | ||
1293 | return new Vector3f(mCenter.x, mCenter.y, mCenter.z); | ||
1294 | } | ||
1295 | } | ||
1296 | public float Radius | ||
1297 | { | ||
1298 | get | ||
1299 | { | ||
1300 | return mRadius; | ||
1301 | } | ||
1302 | } | ||
1303 | |||
1304 | public override string ToString() | ||
1305 | { | ||
1306 | return "[" + this.Center.ToString() + " : " + this.Radius.ToString() + "]"; | ||
1307 | } | ||
1308 | } // struct BoundingSphere3f | ||
1309 | |||
1310 | |||
1311 | |||
1312 | public struct BoundingSphere3d | ||
1313 | { | ||
1314 | Vector3d mCenter; | ||
1315 | float mRadius; | ||
1316 | public BoundingSphere3d(double x, double y, double z, float r) | ||
1317 | { | ||
1318 | mCenter.x = x; | ||
1319 | mCenter.y = y; | ||
1320 | mCenter.z = z; | ||
1321 | mRadius = r; | ||
1322 | } | ||
1323 | public BoundingSphere3d(Vector3d center, float radius) | ||
1324 | { | ||
1325 | mCenter = center; | ||
1326 | mRadius = radius; | ||
1327 | } | ||
1328 | public BoundingSphere3d(BoundingSphere3d cpy, float scale) | ||
1329 | { | ||
1330 | mCenter = cpy.mCenter; | ||
1331 | mRadius = cpy.mRadius * scale; | ||
1332 | } | ||
1333 | public Vector3d Center | ||
1334 | { | ||
1335 | get | ||
1336 | { | ||
1337 | return new Vector3d(mCenter.x, mCenter.y, mCenter.z); | ||
1338 | } | ||
1339 | } | ||
1340 | public float Radius | ||
1341 | { | ||
1342 | get | ||
1343 | { | ||
1344 | return mRadius; | ||
1345 | } | ||
1346 | } | ||
1347 | |||
1348 | public override string ToString() | ||
1349 | { | ||
1350 | return "[" + this.Center.ToString() + " : " + this.Radius.ToString() + "]"; | ||
1351 | } | ||
1352 | } // struct BoundingSphere3f | ||
1353 | |||
1354 | public struct UUID | ||
1355 | { | ||
1356 | ulong mLowOrderBytes; | ||
1357 | ulong mHighOrderBytes; | ||
1358 | |||
1359 | |||
1360 | static ulong SetUUIDlow(Google.ProtocolBuffers.ByteString data, int offset) | ||
1361 | { | ||
1362 | ulong LowOrderBytes = 0; | ||
1363 | int shiftVal = 0; | ||
1364 | for (int i = 0; i < 8; ++i) | ||
1365 | { | ||
1366 | ulong temp = data[i]; | ||
1367 | LowOrderBytes |= (temp << shiftVal); | ||
1368 | shiftVal += 8; | ||
1369 | } | ||
1370 | return LowOrderBytes; | ||
1371 | } | ||
1372 | static ulong SetUUIDhigh(Google.ProtocolBuffers.ByteString data) | ||
1373 | { | ||
1374 | return SetUUIDlow(data, 8); | ||
1375 | } | ||
1376 | static ulong SetUUIDlow(byte[] data, int offset) | ||
1377 | { | ||
1378 | ulong LowOrderBytes = 0; | ||
1379 | int shiftVal = 0; | ||
1380 | for (int i = 0; i < 8; ++i) | ||
1381 | { | ||
1382 | ulong temp = data[i]; | ||
1383 | LowOrderBytes |= (temp << shiftVal); | ||
1384 | shiftVal += 8; | ||
1385 | } | ||
1386 | return LowOrderBytes; | ||
1387 | } | ||
1388 | static ulong SetUUIDhigh(byte[] data) | ||
1389 | { | ||
1390 | return SetUUIDlow(data, 8); | ||
1391 | } | ||
1392 | public bool SetUUID(byte[] data) | ||
1393 | { | ||
1394 | if (data.Length == 16) | ||
1395 | { | ||
1396 | mLowOrderBytes = 0; | ||
1397 | mHighOrderBytes = 0; | ||
1398 | mLowOrderBytes = SetUUIDlow(data, 0); | ||
1399 | mHighOrderBytes = SetUUIDlow(data, 8); | ||
1400 | return true; | ||
1401 | } | ||
1402 | else | ||
1403 | { | ||
1404 | return false; | ||
1405 | } | ||
1406 | } | ||
1407 | public byte[] GetUUID() | ||
1408 | { | ||
1409 | byte[] data = new byte[16]; | ||
1410 | int shiftVal = 0; | ||
1411 | for (int i = 0; i < 8; ++i) | ||
1412 | { | ||
1413 | ulong temp = 0xff; | ||
1414 | temp = (mLowOrderBytes & (temp << shiftVal)); | ||
1415 | temp = (temp >> shiftVal); | ||
1416 | data[i] = (byte)temp; | ||
1417 | shiftVal += 8; | ||
1418 | } | ||
1419 | shiftVal = 0; | ||
1420 | for (int i = 8; i < 16; ++i) | ||
1421 | { | ||
1422 | ulong temp = 0xff; | ||
1423 | temp = (mHighOrderBytes & (temp << shiftVal)); | ||
1424 | temp = (temp >> shiftVal); | ||
1425 | data[i] = (byte)temp; | ||
1426 | shiftVal += 8; | ||
1427 | } | ||
1428 | return data; | ||
1429 | } | ||
1430 | |||
1431 | public static UUID Empty = new UUID(new byte[16]); | ||
1432 | public UUID(byte[] data) | ||
1433 | { | ||
1434 | if (data.Length != 16) | ||
1435 | { | ||
1436 | throw new System.ArgumentException("UUIDs must be provided 16 bytes"); | ||
1437 | } | ||
1438 | mLowOrderBytes = SetUUIDlow(data, 0); | ||
1439 | mHighOrderBytes = SetUUIDhigh(data); | ||
1440 | } | ||
1441 | public UUID(Google.ProtocolBuffers.ByteString data) | ||
1442 | { | ||
1443 | if (data.Length != 16) | ||
1444 | { | ||
1445 | throw new System.ArgumentException("UUIDs must be provided 16 bytes"); | ||
1446 | } | ||
1447 | mLowOrderBytes = SetUUIDlow(data, 0); | ||
1448 | mHighOrderBytes = SetUUIDhigh(data); | ||
1449 | } | ||
1450 | |||
1451 | } | ||
1452 | |||
1453 | |||
1454 | public struct SHA256 | ||
1455 | { | ||
1456 | ulong mLowOrderBytes; | ||
1457 | ulong mLowMediumOrderBytes; | ||
1458 | ulong mMediumHighOrderBytes; | ||
1459 | ulong mHighOrderBytes; | ||
1460 | |||
1461 | |||
1462 | static ulong SetLMH(Google.ProtocolBuffers.ByteString data, int offset) | ||
1463 | { | ||
1464 | ulong LowOrderBytes = 0; | ||
1465 | int shiftVal = 0; | ||
1466 | for (int i = 0; i < 8; ++i) | ||
1467 | { | ||
1468 | ulong temp = data[i]; | ||
1469 | LowOrderBytes |= (temp << shiftVal); | ||
1470 | shiftVal += 8; | ||
1471 | } | ||
1472 | return LowOrderBytes; | ||
1473 | } | ||
1474 | static ulong SetLow(Google.ProtocolBuffers.ByteString data) | ||
1475 | { | ||
1476 | return SetLMH(data, 0); | ||
1477 | } | ||
1478 | static ulong SetLowMedium(Google.ProtocolBuffers.ByteString data) | ||
1479 | { | ||
1480 | return SetLMH(data, 8); | ||
1481 | } | ||
1482 | static ulong SetMediumHigh(Google.ProtocolBuffers.ByteString data) | ||
1483 | { | ||
1484 | return SetLMH(data, 16); | ||
1485 | } | ||
1486 | static ulong SetHigh(Google.ProtocolBuffers.ByteString data) | ||
1487 | { | ||
1488 | return SetLMH(data, 24); | ||
1489 | } | ||
1490 | static ulong SetLMH(byte[] data, int offset) | ||
1491 | { | ||
1492 | ulong LowOrderBytes = 0; | ||
1493 | int shiftVal = 0; | ||
1494 | for (int i = 0; i < 8; ++i) | ||
1495 | { | ||
1496 | ulong temp = data[i]; | ||
1497 | LowOrderBytes |= (temp << shiftVal); | ||
1498 | shiftVal += 8; | ||
1499 | } | ||
1500 | return LowOrderBytes; | ||
1501 | } | ||
1502 | static ulong SetLow(byte[] data) | ||
1503 | { | ||
1504 | return SetLMH(data, 0); | ||
1505 | } | ||
1506 | static ulong SetLowMedium(byte[] data) | ||
1507 | { | ||
1508 | return SetLMH(data, 8); | ||
1509 | } | ||
1510 | static ulong SetMediumHigh(byte[] data) | ||
1511 | { | ||
1512 | return SetLMH(data, 16); | ||
1513 | } | ||
1514 | static ulong SetHigh(byte[] data) | ||
1515 | { | ||
1516 | return SetLMH(data, 24); | ||
1517 | } | ||
1518 | public bool SetSHA256(byte[] data) | ||
1519 | { | ||
1520 | if (data.Length == 32) | ||
1521 | { | ||
1522 | mLowOrderBytes = SetLow(data); | ||
1523 | mLowMediumOrderBytes = SetLowMedium(data); | ||
1524 | mMediumHighOrderBytes = SetMediumHigh(data); | ||
1525 | mHighOrderBytes = SetHigh(data); | ||
1526 | return true; | ||
1527 | } | ||
1528 | else | ||
1529 | { | ||
1530 | return false; | ||
1531 | } | ||
1532 | } | ||
1533 | public byte[] GetBinaryData() | ||
1534 | { | ||
1535 | byte[] data = new byte[32]; | ||
1536 | int shiftVal = 0; | ||
1537 | for (int i = 0; i < 8; ++i) | ||
1538 | { | ||
1539 | ulong temp = 0xff; | ||
1540 | temp = (mLowOrderBytes & (temp << shiftVal)); | ||
1541 | temp = (temp >> shiftVal); | ||
1542 | data[i] = (byte)temp; | ||
1543 | shiftVal += 8; | ||
1544 | } | ||
1545 | shiftVal = 0; | ||
1546 | for (int i = 8; i < 16; ++i) | ||
1547 | { | ||
1548 | ulong temp = 0xff; | ||
1549 | temp = (mLowMediumOrderBytes & (temp << shiftVal)); | ||
1550 | temp = (temp >> shiftVal); | ||
1551 | data[i] = (byte)temp; | ||
1552 | shiftVal += 8; | ||
1553 | } | ||
1554 | shiftVal = 0; | ||
1555 | for (int i = 16; i < 24; ++i) | ||
1556 | { | ||
1557 | ulong temp = 0xff; | ||
1558 | temp = (mMediumHighOrderBytes & (temp << shiftVal)); | ||
1559 | temp = (temp >> shiftVal); | ||
1560 | data[i] = (byte)temp; | ||
1561 | shiftVal += 8; | ||
1562 | } | ||
1563 | shiftVal = 0; | ||
1564 | for (int i = 24; i < 32; ++i) | ||
1565 | { | ||
1566 | ulong temp = 0xff; | ||
1567 | temp = (mHighOrderBytes & (temp << shiftVal)); | ||
1568 | temp = (temp >> shiftVal); | ||
1569 | data[i] = (byte)temp; | ||
1570 | shiftVal += 8; | ||
1571 | } | ||
1572 | return data; | ||
1573 | } | ||
1574 | |||
1575 | public static SHA256 Empty = new SHA256(new byte[32]); | ||
1576 | public SHA256(byte[] data) | ||
1577 | { | ||
1578 | if (data.Length != 32) | ||
1579 | { | ||
1580 | throw new System.ArgumentException("SHA256s must be provided 32 bytes"); | ||
1581 | } | ||
1582 | mLowOrderBytes = SetLow(data); | ||
1583 | mLowMediumOrderBytes = SetLowMedium(data); | ||
1584 | mMediumHighOrderBytes = SetMediumHigh(data); | ||
1585 | mHighOrderBytes = SetHigh(data); | ||
1586 | } | ||
1587 | public SHA256(Google.ProtocolBuffers.ByteString data) | ||
1588 | { | ||
1589 | if (data.Length != 32) | ||
1590 | { | ||
1591 | throw new System.ArgumentException("SHA256s must be provided 32 bytes"); | ||
1592 | } | ||
1593 | mLowOrderBytes = SetLow(data); | ||
1594 | mLowMediumOrderBytes = SetLowMedium(data); | ||
1595 | mMediumHighOrderBytes = SetMediumHigh(data); | ||
1596 | mHighOrderBytes = SetHigh(data); | ||
1597 | } | ||
1598 | |||
1599 | } | ||
1600 | |||
1601 | |||
1602 | |||
1603 | |||
1604 | public struct Time | ||
1605 | { | ||
1606 | ulong usec; | ||
1607 | public Time(ulong usec_since_epoch) | ||
1608 | { | ||
1609 | usec = usec_since_epoch; | ||
1610 | } | ||
1611 | public ulong toMicro() | ||
1612 | { | ||
1613 | return usec; | ||
1614 | } | ||
1615 | } | ||
1616 | public class Duration | ||
1617 | { | ||
1618 | long usec; | ||
1619 | public Duration(long time_since) | ||
1620 | { | ||
1621 | usec = time_since; | ||
1622 | } | ||
1623 | public long toMicro() | ||
1624 | { | ||
1625 | return usec; | ||
1626 | } | ||
1627 | } | ||
1628 | |||
1629 | class _PBJ | ||
1630 | { | ||
1631 | |||
1632 | public static bool ValidateBool(bool d) | ||
1633 | { | ||
1634 | return true; | ||
1635 | } | ||
1636 | public static bool ValidateDouble(double d) | ||
1637 | { | ||
1638 | return true; | ||
1639 | } | ||
1640 | public static bool ValidateFloat(float d) | ||
1641 | { | ||
1642 | return true; | ||
1643 | } | ||
1644 | public static bool ValidateUint64(ulong d) | ||
1645 | { | ||
1646 | return true; | ||
1647 | } | ||
1648 | public static bool ValidateUint32(uint d) | ||
1649 | { | ||
1650 | return true; | ||
1651 | } | ||
1652 | public static bool ValidateUint16(ushort d) | ||
1653 | { | ||
1654 | return true; | ||
1655 | } | ||
1656 | public static bool ValidateUint8(byte d) | ||
1657 | { | ||
1658 | return true; | ||
1659 | } | ||
1660 | public static bool ValidateInt64(long d) | ||
1661 | { | ||
1662 | return true; | ||
1663 | } | ||
1664 | public static bool ValidateInt32(int d) | ||
1665 | { | ||
1666 | return true; | ||
1667 | } | ||
1668 | public static bool ValidateInt16(short d) | ||
1669 | { | ||
1670 | return true; | ||
1671 | } | ||
1672 | public static bool ValidateInt8(sbyte d) | ||
1673 | { | ||
1674 | return true; | ||
1675 | } | ||
1676 | public static bool ValidateString<S>(S input) | ||
1677 | { | ||
1678 | return true; | ||
1679 | } | ||
1680 | public static bool ValidateBytes<B>(B input) | ||
1681 | { | ||
1682 | return true; | ||
1683 | } | ||
1684 | public static bool ValidateUuid(Google.ProtocolBuffers.ByteString input) | ||
1685 | { | ||
1686 | return input.Length == 16; | ||
1687 | } | ||
1688 | public static bool ValidateSha256(Google.ProtocolBuffers.ByteString input) | ||
1689 | { | ||
1690 | return input.Length == 32; | ||
1691 | } | ||
1692 | public static bool ValidateAngle(float input) | ||
1693 | { | ||
1694 | return input >= 0 && input <= 3.1415926536 * 2.0; | ||
1695 | } | ||
1696 | public static bool ValidateTime(ulong input) | ||
1697 | { | ||
1698 | return true; | ||
1699 | } | ||
1700 | public static bool ValidateDuration(long input) | ||
1701 | { | ||
1702 | return true; | ||
1703 | } | ||
1704 | public static bool ValidateFlags(ulong input, ulong verification) | ||
1705 | { | ||
1706 | return (input & verification) == input; | ||
1707 | } | ||
1708 | |||
1709 | |||
1710 | |||
1711 | |||
1712 | public static bool CastBool(bool d) | ||
1713 | { | ||
1714 | return d; | ||
1715 | } | ||
1716 | public static double CastDouble(double d) | ||
1717 | { | ||
1718 | return d; | ||
1719 | } | ||
1720 | public static float CastFloat(float d) | ||
1721 | { | ||
1722 | return d; | ||
1723 | } | ||
1724 | public static ulong CastUint64(ulong d) | ||
1725 | { | ||
1726 | return d; | ||
1727 | } | ||
1728 | public static uint CastUint32(uint d) | ||
1729 | { | ||
1730 | return d; | ||
1731 | } | ||
1732 | public static ushort CastUint16(ushort d) | ||
1733 | { | ||
1734 | return d; | ||
1735 | } | ||
1736 | public static byte CastUint8(byte d) | ||
1737 | { | ||
1738 | return d; | ||
1739 | } | ||
1740 | public static long CastInt64(long d) | ||
1741 | { | ||
1742 | return d; | ||
1743 | } | ||
1744 | public static int CastInt32(int d) | ||
1745 | { | ||
1746 | return d; | ||
1747 | } | ||
1748 | public static short CastInt16(short d) | ||
1749 | { | ||
1750 | return d; | ||
1751 | } | ||
1752 | public static sbyte CastInt8(sbyte d) | ||
1753 | { | ||
1754 | return d; | ||
1755 | } | ||
1756 | public static S CastString<S>(S input) | ||
1757 | { | ||
1758 | return input; | ||
1759 | } | ||
1760 | public static B CastBytes<B>(B input) | ||
1761 | { | ||
1762 | return input; | ||
1763 | } | ||
1764 | |||
1765 | |||
1766 | |||
1767 | public static bool CastBool() | ||
1768 | { | ||
1769 | return false; | ||
1770 | } | ||
1771 | public static double CastDouble() | ||
1772 | { | ||
1773 | return 0; | ||
1774 | } | ||
1775 | public static float CastFloat() | ||
1776 | { | ||
1777 | return 0; | ||
1778 | } | ||
1779 | public static ulong CastUint64() | ||
1780 | { | ||
1781 | return 0; | ||
1782 | } | ||
1783 | public static uint CastUint32() | ||
1784 | { | ||
1785 | return 0; | ||
1786 | } | ||
1787 | public static ushort CastUint16() | ||
1788 | { | ||
1789 | return 0; | ||
1790 | } | ||
1791 | public static byte CastUint8() | ||
1792 | { | ||
1793 | return 0; | ||
1794 | } | ||
1795 | public static long CastInt64() | ||
1796 | { | ||
1797 | return 0; | ||
1798 | } | ||
1799 | public static int CastInt32() | ||
1800 | { | ||
1801 | return 0; | ||
1802 | } | ||
1803 | public static short CastInt16() | ||
1804 | { | ||
1805 | return 0; | ||
1806 | } | ||
1807 | public static sbyte CastInt8() | ||
1808 | { | ||
1809 | return 0; | ||
1810 | } | ||
1811 | public static string CastString() | ||
1812 | { | ||
1813 | return ""; | ||
1814 | } | ||
1815 | public static Google.ProtocolBuffers.ByteString CastBytes() | ||
1816 | { | ||
1817 | return Google.ProtocolBuffers.ByteString.Empty; | ||
1818 | } | ||
1819 | |||
1820 | |||
1821 | public static ulong CastFlags(ulong data, ulong allFlagsOn) | ||
1822 | { | ||
1823 | return allFlagsOn & data; | ||
1824 | } | ||
1825 | public static ulong CastFlags(ulong allFlagsOn) | ||
1826 | { | ||
1827 | return 0; | ||
1828 | } | ||
1829 | |||
1830 | public static Vector3f CastNormal(float x, float y) | ||
1831 | { | ||
1832 | float neg = (x > 1.5f || y > 1.5f) ? -1.0f : 1.0f; | ||
1833 | if (x > 1.5) | ||
1834 | x -= 3; | ||
1835 | if (y > 1.5) | ||
1836 | y -= 3; | ||
1837 | return new Vector3f(x, y, neg - neg * (float)Math.Sqrt(x * x + y * y)); | ||
1838 | } | ||
1839 | public static Vector3f CastNormal() | ||
1840 | { | ||
1841 | return new Vector3f(0, 1, 0); | ||
1842 | } | ||
1843 | |||
1844 | |||
1845 | public static Vector2f CastVector2f(float x, float y) | ||
1846 | { | ||
1847 | return new Vector2f(x, y); | ||
1848 | } | ||
1849 | public static Vector2f CastVector2f() | ||
1850 | { | ||
1851 | return new Vector2f(0, 0); | ||
1852 | } | ||
1853 | |||
1854 | public static Vector3f CastVector3f(float x, float y, float z) | ||
1855 | { | ||
1856 | return new Vector3f(x, y, z); | ||
1857 | } | ||
1858 | public static Vector3f CastVector3f() | ||
1859 | { | ||
1860 | return new Vector3f(0, 0, 0); | ||
1861 | } | ||
1862 | |||
1863 | public static Vector4f CastVector4f(float x, float y, float z, float w) | ||
1864 | { | ||
1865 | return new Vector4f(x, y, z, w); | ||
1866 | } | ||
1867 | public static Vector4f CastVector4f() | ||
1868 | { | ||
1869 | return new Vector4f(0, 0, 0, 0); | ||
1870 | } | ||
1871 | public static Vector2d CastVector2d(double x, double y) | ||
1872 | { | ||
1873 | return new Vector2d(x, y); | ||
1874 | } | ||
1875 | public static Vector2d CastVector2d() | ||
1876 | { | ||
1877 | return new Vector2d(0, 0); | ||
1878 | } | ||
1879 | |||
1880 | public static Vector3d CastVector3d(double x, double y, double z) | ||
1881 | { | ||
1882 | return new Vector3d(x, y, z); | ||
1883 | } | ||
1884 | public static Vector3d CastVector3d() | ||
1885 | { | ||
1886 | return new Vector3d(0, 0, 0); | ||
1887 | } | ||
1888 | |||
1889 | public static Vector4d CastVector4d(double x, double y, double z, double w) | ||
1890 | { | ||
1891 | return new Vector4d(x, y, z, w); | ||
1892 | } | ||
1893 | public static Vector4d CastVector4d() | ||
1894 | { | ||
1895 | return new Vector4d(0, 0, 0, 0); | ||
1896 | } | ||
1897 | |||
1898 | public static BoundingSphere3f CastBoundingsphere3f(float x, float y, float z, float r) | ||
1899 | { | ||
1900 | return new BoundingSphere3f(new Vector3f(x, y, z), r); | ||
1901 | } | ||
1902 | public static BoundingSphere3d CastBoundingsphere3d(double x, double y, double z, double r) | ||
1903 | { | ||
1904 | return new BoundingSphere3d(new Vector3d(x, y, z), (float)r); | ||
1905 | } | ||
1906 | |||
1907 | public static BoundingSphere3f CastBoundingsphere3f() | ||
1908 | { | ||
1909 | return new BoundingSphere3f(new Vector3f(0, 0, 0), 0); | ||
1910 | } | ||
1911 | public static BoundingSphere3d CastBoundingsphere3d() | ||
1912 | { | ||
1913 | return new BoundingSphere3d(new Vector3d(0, 0, 0), (float)0); | ||
1914 | } | ||
1915 | |||
1916 | |||
1917 | public static BoundingBox3f3f CastBoundingbox3f3f(float x, float y, float z, float dx, float dy, float dz) | ||
1918 | { | ||
1919 | return new BoundingBox3f3f(x, y, z, dx, dy, dz); | ||
1920 | } | ||
1921 | public static BoundingBox3d3f CastBoundingbox3d3f(double x, double y, double z, double dx, double dy, double dz) | ||
1922 | { | ||
1923 | return new BoundingBox3d3f(x, y, z, (float)dx, (float)dy, (float)dz); | ||
1924 | } | ||
1925 | |||
1926 | public static BoundingBox3f3f CastBoundingbox3f3f() | ||
1927 | { | ||
1928 | return new BoundingBox3f3f(new Vector3f(0, 0, 0), new Vector3f(0, 0, 0)); | ||
1929 | } | ||
1930 | public static BoundingBox3d3f CastBoundingbox3d3f() | ||
1931 | { | ||
1932 | return new BoundingBox3d3f(0, 0, 0, 0, 0, 0); | ||
1933 | } | ||
1934 | |||
1935 | |||
1936 | |||
1937 | public static Quaternion CastQuaternion(float x, float y, float z) | ||
1938 | { | ||
1939 | float neg = (x > 1.5 || y > 1.5 || z > 1.5) ? -1.0f : 1.0f; | ||
1940 | if (x > 1.5) | ||
1941 | x -= 3.0f; | ||
1942 | if (y > 1.5) | ||
1943 | y -= 3.0f; | ||
1944 | if (z > 1.5) | ||
1945 | z -= 3.0f; | ||
1946 | return new Quaternion(neg - neg * (float)Math.Sqrt(x * x + y * y + z * z), x, y, z); | ||
1947 | } | ||
1948 | public static Quaternion CastQuaternion() | ||
1949 | { | ||
1950 | return new Quaternion(1, 0, 0, 0); | ||
1951 | } | ||
1952 | |||
1953 | public static UUID CastUuid(Google.ProtocolBuffers.ByteString input) | ||
1954 | { | ||
1955 | return new UUID(input); | ||
1956 | } | ||
1957 | public static SHA256 CastSha256(Google.ProtocolBuffers.ByteString input) | ||
1958 | { | ||
1959 | return new SHA256(input); | ||
1960 | } | ||
1961 | public static SHA256 CastSha256() | ||
1962 | { | ||
1963 | return SHA256.Empty; | ||
1964 | } | ||
1965 | public static UUID CastUuid() | ||
1966 | { | ||
1967 | return UUID.Empty; | ||
1968 | } | ||
1969 | |||
1970 | public static float CastAngle(float d) | ||
1971 | { | ||
1972 | return d; | ||
1973 | } | ||
1974 | public static float CastAngle() | ||
1975 | { | ||
1976 | return 0; | ||
1977 | } | ||
1978 | |||
1979 | public static Time CastTime(ulong t) | ||
1980 | { | ||
1981 | return new Time(t); | ||
1982 | } | ||
1983 | public static Time CastTime() | ||
1984 | { | ||
1985 | return new Time(0); | ||
1986 | } | ||
1987 | public static Duration CastDuration(long t) | ||
1988 | { | ||
1989 | return new Duration(t); | ||
1990 | } | ||
1991 | public static Duration CastDuration() | ||
1992 | { | ||
1993 | return new Duration(0); | ||
1994 | } | ||
1995 | |||
1996 | public static T Construct<T>(T retval) | ||
1997 | { | ||
1998 | return retval; | ||
1999 | } | ||
2000 | public static long Construct(Duration d) | ||
2001 | { | ||
2002 | return d.toMicro(); | ||
2003 | } | ||
2004 | public static ulong Construct(Time t) | ||
2005 | { | ||
2006 | return t.toMicro(); | ||
2007 | } | ||
2008 | public static Google.ProtocolBuffers.ByteString Construct(UUID u) | ||
2009 | { | ||
2010 | byte[] data = u.GetUUID(); | ||
2011 | Google.ProtocolBuffers.ByteString retval = Google.ProtocolBuffers.ByteString.CopyFrom(data, 0, 16); | ||
2012 | return retval; | ||
2013 | } | ||
2014 | public static Google.ProtocolBuffers.ByteString Construct(SHA256 u) | ||
2015 | { | ||
2016 | byte[] data = u.GetBinaryData(); | ||
2017 | Google.ProtocolBuffers.ByteString retval = Google.ProtocolBuffers.ByteString.CopyFrom(data, 0, 16); | ||
2018 | return retval; | ||
2019 | } | ||
2020 | public static float[] ConstructNormal(Vector3f d) | ||
2021 | { | ||
2022 | return new float[] { d.x + (d.z < 0 ? 3.0f : 0.0f), d.y }; | ||
2023 | } | ||
2024 | public static float[] ConstructQuaternion(Quaternion d) | ||
2025 | { | ||
2026 | return new float[] { d.x + (d.w < 0 ? 3.0f : 0.0f), d.y, d.z }; | ||
2027 | } | ||
2028 | |||
2029 | public static float[] ConstructVector2f(Vector2f d) | ||
2030 | { | ||
2031 | return new float[] { d.x, d.y }; | ||
2032 | } | ||
2033 | public static double[] ConstructVector2d(Vector2d d) | ||
2034 | { | ||
2035 | return new double[] { d.x, d.y }; | ||
2036 | } | ||
2037 | |||
2038 | public static float[] ConstructVector3f(Vector3f d) | ||
2039 | { | ||
2040 | return new float[] { d.x, d.y, d.z }; | ||
2041 | } | ||
2042 | public static double[] ConstructVector3d(Vector3d d) | ||
2043 | { | ||
2044 | return new double[] { d.x, d.y, d.z }; | ||
2045 | } | ||
2046 | public static float[] ConstructVector4f(Vector4f d) | ||
2047 | { | ||
2048 | return new float[] { d.x, d.y, d.z, d.w }; | ||
2049 | } | ||
2050 | public static double[] ConstructVector4d(Vector4d d) | ||
2051 | { | ||
2052 | return new double[] { d.x, d.y, d.z, d.w }; | ||
2053 | } | ||
2054 | |||
2055 | |||
2056 | public static float[] ConstructBoundingsphere3f(BoundingSphere3f d) | ||
2057 | { | ||
2058 | return new float[] { d.Center.x, d.Center.y, d.Center.z, d.Radius }; | ||
2059 | } | ||
2060 | public static double[] ConstructBoundingsphere3d(BoundingSphere3d d) | ||
2061 | { | ||
2062 | return new double[] { d.Center.x, d.Center.y, d.Center.z, d.Radius }; | ||
2063 | } | ||
2064 | |||
2065 | public static float[] ConstructBoundingbox3f3f(BoundingBox3f3f d) | ||
2066 | { | ||
2067 | return new float[] { d.Min.x, d.Min.y, d.Min.z, d.Diag.x, d.Diag.y, d.Diag.z }; | ||
2068 | } | ||
2069 | public static double[] ConstructBoundingbox3d3f(BoundingBox3d3f d) | ||
2070 | { | ||
2071 | return new double[] { d.Min.x, d.Min.y, d.Min.z, d.Diag.x, d.Diag.y, d.Diag.z }; | ||
2072 | } | ||
2073 | |||
2074 | |||
2075 | } | ||
2076 | |||
2077 | } | ||