-
Notifications
You must be signed in to change notification settings - Fork 0
/
CullGrid.cs
1009 lines (914 loc) · 33.9 KB
/
CullGrid.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;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using uLink;
using UnityEngine;
public class CullGrid : UnityEngine.MonoBehaviour
{
private static bool cull_prebinding = true;
private static CullGridRuntime grid;
private static bool has_grid;
[SerializeField]
private CullGridSetup setup;
private void Awake()
{
RegisterGrid(this);
}
public static bool CellContainsPoint(ushort cell, ref Vector2 flatPoint)
{
return (cell == grid.FlatCell(ref flatPoint));
}
public static bool CellContainsPoint(ushort cell, ref Vector3 worldPoint)
{
return (cell == grid.WorldCell(ref worldPoint));
}
public static bool CellContainsPoint(ushort cell, ref Vector2 flatPoint, out ushort cell_point)
{
cell_point = grid.FlatCell(ref flatPoint);
return (cell == cell_point);
}
public static bool CellContainsPoint(ushort cell, ref Vector3 worldPoint, out ushort cell_point)
{
cell_point = grid.WorldCell(ref worldPoint);
return (cell_point == cell);
}
public static ushort CellFromGroupID(int groupID)
{
if ((groupID < grid.groupBegin) || (groupID >= grid.groupEnd))
{
throw new ArgumentOutOfRangeException("groupID", groupID, "groupID < grid.groupBegin || groupID >= grid.groupEnd");
}
return (ushort) (groupID - grid.groupBegin);
}
public static ushort CellFromGroupID(int groupID, out ushort x, out ushort y)
{
ushort num = CellFromGroupID(groupID);
x = (ushort) (num % grid.cellsWide);
y = (ushort) (num / grid.cellsWide);
return num;
}
private void DrawGizmosNow()
{
}
private void DrawGrid(int cell)
{
if (cell != -1)
{
this.DrawGrid(this.GetCenterSetup(cell));
}
}
private void DrawGrid(Vector3 center)
{
Vector3 vector = (Vector3) (base.transform.right * (((float) this.setup.cellSquareDimension) / 2f));
Vector3 vector2 = (Vector3) (base.transform.forward * (((float) this.setup.cellSquareDimension) / 2f));
DrawQuadRayCastDown((center + vector) + vector2, (center + vector) - vector2, (center - vector) - vector2, (center - vector) + vector2);
}
private void DrawGrid(int centerCell, int xOffset, int yOffset)
{
this.DrawGrid((int) ((centerCell + xOffset) + ((this.setup.cellsWide * 2) * yOffset)));
}
private void DrawGrid(Vector3 center, float sizeX, float sizeY)
{
Vector3 vector = (Vector3) (base.transform.right * (sizeX / 2f));
Vector3 vector2 = (Vector3) (base.transform.forward * (sizeY / 2f));
DrawQuadRayCastDown((center + vector) + vector2, (center + vector) - vector2, (center - vector) - vector2, (center - vector) + vector2);
}
private static void DrawQuadRayCastDown(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
{
RaycastDownVect(ref a);
RaycastDownVect(ref b);
RaycastDownVect(ref c);
RaycastDownVect(ref d);
Gizmos.DrawLine(a, b);
Gizmos.DrawLine(b, c);
Gizmos.DrawLine(c, d);
Gizmos.DrawLine(d, a);
if (a.y > c.y)
{
if (b.y > d.y)
{
if ((b.y - d.y) > (a.y - c.y))
{
Gizmos.DrawLine(b, d);
}
else
{
Gizmos.DrawLine(a, c);
}
}
else if ((d.y - b.y) > (a.y - c.y))
{
Gizmos.DrawLine(d, b);
}
else
{
Gizmos.DrawLine(a, c);
}
}
else if (b.y > d.y)
{
if ((b.y - d.y) > (c.y - a.y))
{
Gizmos.DrawLine(b, d);
}
else
{
Gizmos.DrawLine(c, a);
}
}
else if ((d.y - b.y) > (c.y - a.y))
{
Gizmos.DrawLine(d, b);
}
else
{
Gizmos.DrawLine(c, a);
}
}
public static Vector2 Flat(Vector3 triD)
{
Vector2 vector;
vector.x = triD.x;
vector.y = triD.z;
return vector;
}
public static ushort FlatCell(Vector2 flat)
{
return grid.FlatCell(ref flat);
}
public static ushort FlatCell(ref Vector2 flat)
{
return grid.FlatCell(ref flat);
}
public static int FlatGroupID(ref Vector2 flat)
{
return (grid.FlatCell(ref flat) + grid.groupBegin);
}
private Vector3 GetCenterSetup(int cell)
{
CullGridSetup setup = this.setup;
return (Vector3) ((base.transform.position + (base.transform.forward * (((cell / setup.cellsWide) - ((((float) setup.cellsTall) / 2f) - (((float) (2 - (setup.cellsTall & 1))) / 2f))) * setup.cellSquareDimension))) + (base.transform.right * (((cell % setup.cellsWide) - ((((float) setup.cellsWide) / 2f) - (((float) (2 - (setup.cellsWide & 1))) / 2f))) * setup.cellSquareDimension)));
}
public static bool GroupIDContainsPoint(int groupID, ref Vector2 flatPoint)
{
return (((groupID >= grid.groupBegin) && (groupID < grid.groupEnd)) && CellContainsPoint((ushort) (groupID - grid.groupBegin), ref flatPoint));
}
public static bool GroupIDContainsPoint(int groupID, ref Vector3 worldPoint)
{
return (((groupID >= grid.groupBegin) && (groupID < grid.groupEnd)) && CellContainsPoint((ushort) (groupID - grid.groupBegin), ref worldPoint));
}
public static bool GroupIDContainsPoint(int groupID, ref Vector2 flatPoint, out int groupID_point)
{
ushort num;
if ((groupID < grid.groupBegin) || (groupID >= grid.groupEnd))
{
groupID_point = NetworkGroup.unassigned.id;
return false;
}
if (!CellContainsPoint((ushort) (groupID - grid.groupBegin), ref flatPoint, out num))
{
groupID_point = num + grid.groupBegin;
return false;
}
groupID_point = groupID;
return true;
}
public static bool GroupIDContainsPoint(int groupID, ref Vector3 worldPoint, out int groupID_point)
{
ushort num;
if ((groupID < grid.groupBegin) || (groupID >= grid.groupEnd))
{
groupID_point = NetworkGroup.unassigned.id;
return false;
}
if (!CellContainsPoint(CellFromGroupID(groupID), ref worldPoint, out num))
{
groupID_point = GroupIDFromCell(num);
return false;
}
groupID_point = groupID;
return true;
}
public static int GroupIDFromCell(ushort cell)
{
if (cell >= grid.numCells)
{
throw new ArgumentOutOfRangeException("cell", cell, "cell >= grid.numCells");
}
return (grid.groupBegin + cell);
}
public static bool IsCellGroup(NetworkGroup group)
{
return IsCellGroupID(group.id);
}
public static bool IsCellGroupID(int usedGroup)
{
return ((has_grid && (usedGroup >= grid.groupBegin)) && (usedGroup < grid.groupEnd));
}
private static void RaycastDownVect(ref Vector3 a)
{
RaycastHit hit;
if (Physics.Raycast(new Vector3(a.x, 10000f, a.z), Vector3.down, out hit, float.PositiveInfinity))
{
a = hit.point + ((Vector3) (Vector3.up * a.y));
}
}
private static void RegisterGrid(CullGrid grid)
{
if (grid != null)
{
CullGrid.grid = new CullGridRuntime(grid);
has_grid = true;
}
}
public static ushort WorldCell(Vector3 world)
{
return grid.WorldCell(ref world);
}
public static ushort WorldCell(ref Vector3 world)
{
return grid.WorldCell(ref world);
}
public static int WorldGroupID(ref Vector3 world)
{
return (grid.WorldCell(ref world) + grid.groupBegin);
}
public static bool autoPrebindInInstantiate
{
get
{
return (has_grid && cull_prebinding);
}
}
public static int Tall
{
get
{
return grid.cellsTall;
}
}
public static int Wide
{
get
{
return grid.cellsWide;
}
}
[StructLayout(LayoutKind.Explicit, Size=2)]
public struct CellID
{
[FieldOffset(0)]
public ushort id;
private const ushort kInvalidID = 0xffff;
public CellID(ushort cellID)
{
this.id = cellID;
}
public bool ContainsFlatPoint(Vector2 flatPoint)
{
return CullGrid.grid.Contains(this.id, ref flatPoint);
}
public bool ContainsFlatPoint(ref Vector2 flatPoint)
{
return (this.valid && CullGrid.grid.Contains(this.id, ref flatPoint));
}
public bool ContainsWorldPoint(Vector3 worldPoint)
{
return CullGrid.grid.Contains(this.id, ref worldPoint);
}
public bool ContainsWorldPoint(ref Vector3 worldPoint)
{
return (this.valid && CullGrid.grid.Contains(this.id, ref worldPoint));
}
private static ushort NextDown(ushort id)
{
return (((id / CullGrid.grid.cellsWide) != 0) ? ((ushort) (id - CullGrid.grid.cellsWide)) : ((ushort) 0xffff));
}
private static ushort NextLeft(ushort id)
{
return (((id % CullGrid.grid.cellsWide) != 0) ? ((ushort) (id - 1)) : ((ushort) 0xffff));
}
private static ushort NextRight(ushort id)
{
return (((id % CullGrid.grid.cellsWide) != CullGrid.grid.cellWideLast) ? ((ushort) (id + 1)) : ((ushort) 0xffff));
}
private static ushort NextUp(ushort id)
{
return (((id / CullGrid.grid.cellsWide) != CullGrid.grid.cellTallLast) ? ((ushort) (id + CullGrid.grid.cellsWide)) : ((ushort) 0xffff));
}
public int column
{
get
{
return (!this.valid ? -1 : (this.id % CullGrid.grid.cellsWide));
}
}
public CullGrid.CellID down
{
get
{
CullGrid.CellID lid;
lid.id = !this.valid ? ((ushort) 0xffff) : NextDown(this.id);
return lid;
}
}
public Vector2 flatCenter
{
get
{
Vector2 vector;
CullGrid.grid.GetCenter(this.id, out vector);
return vector;
}
}
public Vector2 flatMax
{
get
{
Vector2 vector;
CullGrid.grid.GetMin(this.id, out vector);
return vector;
}
}
public Vector2 flatMin
{
get
{
Vector2 vector;
CullGrid.grid.GetMax(this.id, out vector);
return vector;
}
}
public Rect flatRect
{
get
{
Rect rect;
CullGrid.grid.GetRect(this.id, out rect);
return rect;
}
}
public NetworkGroup group
{
get
{
return (!this.valid ? NetworkGroup.unassigned : CullGrid.GroupIDFromCell(this.id));
}
}
public int groupID
{
get
{
return (!this.valid ? NetworkGroup.unassigned.id : CullGrid.GroupIDFromCell(this.id));
}
}
public CullGrid.CellID left
{
get
{
CullGrid.CellID lid;
lid.id = !this.valid ? ((ushort) 0xffff) : NextLeft(this.id);
return lid;
}
}
public bool mostBottom
{
get
{
return (this.valid && ((this.id / CullGrid.grid.cellsWide) == 0));
}
}
public bool mostLeft
{
get
{
return (this.valid && ((this.id % CullGrid.grid.cellsWide) == 0));
}
}
public bool mostRight
{
get
{
return (this.valid && ((this.id % CullGrid.grid.cellsWide) == CullGrid.grid.cellWideLast));
}
}
public bool mostTop
{
get
{
return (this.valid && ((this.id / CullGrid.grid.cellsWide) == CullGrid.grid.cellTallLast));
}
}
public CullGrid.CellID right
{
get
{
CullGrid.CellID lid;
lid.id = !this.valid ? ((ushort) 0xffff) : NextRight(this.id);
return lid;
}
}
public int row
{
get
{
return (!this.valid ? -1 : (this.id / CullGrid.grid.cellsWide));
}
}
public CullGrid.CellID up
{
get
{
CullGrid.CellID lid;
lid.id = !this.valid ? ((ushort) 0xffff) : NextUp(this.id);
return lid;
}
}
public bool valid
{
get
{
return (this.id < CullGrid.grid.numCells);
}
}
public Bounds worldBounds
{
get
{
Bounds bounds;
CullGrid.grid.GetBounds(this.id, out bounds);
return bounds;
}
}
public Vector3 worldCenter
{
get
{
Vector3 vector;
CullGrid.grid.GetCenter(this.id, out vector);
return vector;
}
}
public Vector3 worldMax
{
get
{
Vector3 vector;
CullGrid.grid.GetMin(this.id, out vector);
return vector;
}
}
public Vector3 worldMin
{
get
{
Vector3 vector;
CullGrid.grid.GetMax(this.id, out vector);
return vector;
}
}
}
private class CullGridRuntime : CullGridSetup
{
public ushort cellTallLast;
public double cellTallLastTimesSquareDimension;
public ushort cellWideLast;
public double cellWideLastTimesSquareDimension;
public CullGrid cullGrid;
public double flat_tall_ofs;
public double flat_wide_ofs;
public double fx;
public double fy;
public double fz;
public int groupEnd;
public double halfCellTall;
public double halfCellTallMinusHalfTwoMinusOddTall;
public double halfCellWide;
public double halfCellWideMinusHalfTwoMinusOddWide;
public double halfTwoMinusOddTall;
public double halfTwoMinusOddWide;
private const double kMAX_WORLD_Y = 32000.0;
private const double kMIN_WORLD_Y = -32000.0;
public int numCells;
public double px;
public double py;
public double pz;
public double rx;
public double ry;
public double rz;
public Transform transform;
public int twoMinusOddTall;
public int twoMinusOddWide;
public CullGridRuntime(CullGrid cullGrid) : base(cullGrid.setup)
{
this.cullGrid = cullGrid;
this.transform = cullGrid.transform;
this.halfCellTall = ((double) base.cellsTall) / 2.0;
this.halfCellWide = ((double) base.cellsWide) / 2.0;
this.twoMinusOddTall = 2 - (base.cellsTall & 1);
this.twoMinusOddWide = 2 - (base.cellsWide & 1);
this.halfTwoMinusOddTall = ((double) this.twoMinusOddTall) / 2.0;
this.halfTwoMinusOddWide /= 2.0;
this.halfCellTallMinusHalfTwoMinusOddTall = this.halfCellTall - this.halfTwoMinusOddTall;
this.halfCellWideMinusHalfTwoMinusOddWide = this.halfCellWide - this.halfTwoMinusOddWide;
Vector3 forward = this.transform.forward;
Vector3 right = this.transform.right;
Vector3 position = this.transform.position;
this.fx = forward.x;
this.fy = forward.y;
this.fz = forward.z;
double num = Math.Sqrt(((this.fx * this.fx) + (this.fy * this.fy)) + (this.fz * this.fz));
this.fx /= num;
this.fy /= num;
this.fz /= num;
this.rx = right.x;
this.ry = right.y;
this.rz = right.z;
num = Math.Sqrt(((this.rx * this.rx) + (this.ry * this.ry)) + (this.rz * this.rz));
this.rx /= num;
this.ry /= num;
this.rz /= num;
this.px = position.x;
this.py = position.y;
this.pz = position.z;
this.flat_wide_ofs = base.cellSquareDimension * (this.halfCellWide - (((double) (1 - (base.cellsWide & 1))) / 2.0));
this.flat_tall_ofs = base.cellSquareDimension * (this.halfCellTall - (((double) (1 - (base.cellsTall & 1))) / 2.0));
this.cellTallLast = (ushort) (base.cellsTall - 1);
this.cellWideLast = (ushort) (base.cellsWide - 1);
this.cellTallLastTimesSquareDimension = this.cellTallLast * base.cellSquareDimension;
this.cellWideLastTimesSquareDimension = this.cellWideLast * base.cellSquareDimension;
this.numCells = base.cellsTall * base.cellsWide;
this.groupEnd = base.groupBegin + this.numCells;
}
public bool Contains(int cell, ref Vector2 flatPoint)
{
return (((cell >= 0) && (cell < this.numCells)) && (this.FlatCell(ref flatPoint) == cell));
}
public bool Contains(int cell, ref Vector3 worldPoint)
{
return (((cell >= 0) && (cell < this.numCells)) && (this.WorldCell(ref worldPoint) == cell));
}
public bool Contains(int x, int y, ref Vector2 flatPoint)
{
return this.Contains((y * base.cellsWide) + x, ref flatPoint);
}
public bool Contains(int x, int y, ref Vector3 worldPoint)
{
return this.Contains((y * base.cellsWide) + x, ref worldPoint);
}
public System.Collections.Generic.List<ushort> EnumerateNearbyCells(int cell)
{
return this.EnumerateNearbyCells(cell, cell % CullGrid.grid.cellsWide, cell / CullGrid.grid.cellsWide);
}
public System.Collections.Generic.List<ushort> EnumerateNearbyCells(int x, int y)
{
return this.EnumerateNearbyCells((y * base.cellsWide) + x, x, y);
}
public System.Collections.Generic.List<ushort> EnumerateNearbyCells(int i, int x, int y)
{
if (i < 0)
{
throw new ArgumentOutOfRangeException("i", i, "i<0");
}
if (x < 0)
{
throw new ArgumentOutOfRangeException("x", x, "x<0");
}
if (y < 0)
{
throw new ArgumentOutOfRangeException("y", y, "y<0");
}
System.Collections.Generic.List<ushort> list = new System.Collections.Generic.List<ushort>();
int num = -(base.gatheringCellsCenter % base.gatheringCellsWide);
int num2 = -(base.gatheringCellsCenter / base.gatheringCellsWide);
for (int j = 0; j < base.gatheringCellsWide; j++)
{
int num4 = j + num;
int num5 = x + num4;
if ((num5 >= 0) && (num5 < base.cellsWide))
{
for (int k = 0; k < base.gatheringCellsTall; k++)
{
int num7 = k + num2;
int num8 = y + num7;
if (((num8 >= 0) && (num8 < base.cellsTall)) && base.GetGatheringBit(j, k))
{
ushort item = (ushort) (num5 + (num8 * base.cellsWide));
if ((num8 == y) && (num5 == x))
{
list.Insert(0, item);
}
else
{
list.Add(item);
}
}
}
}
}
return list;
}
public ushort FlatCell(ref Vector2 point)
{
int cellWideLast;
int cellTallLast;
double num2 = point.x + this.flat_wide_ofs;
if (num2 <= 0.0)
{
cellWideLast = 0;
}
else if (num2 >= this.cellWideLastTimesSquareDimension)
{
cellWideLast = this.cellWideLast;
}
else
{
cellWideLast = (int) Math.Floor((double) (num2 / ((double) base.cellSquareDimension)));
}
double num4 = point.y + this.flat_tall_ofs;
if (num4 <= 0.0)
{
cellTallLast = 0;
}
else if (num4 >= this.cellTallLastTimesSquareDimension)
{
cellTallLast = this.cellTallLast;
}
else
{
cellTallLast = (int) Math.Floor((double) (num4 / ((double) base.cellSquareDimension)));
}
return (ushort) ((cellTallLast * base.cellsWide) + cellWideLast);
}
public ushort FlatCell(ref Vector2 point, out ushort x, out ushort y)
{
double num = point.x + this.flat_wide_ofs;
if (num <= 0.0)
{
x = 0;
}
else if (num >= this.cellWideLastTimesSquareDimension)
{
x = this.cellWideLast;
}
else
{
x = (ushort) Math.Floor((double) (num / ((double) base.cellSquareDimension)));
}
double num2 = point.y + this.flat_tall_ofs;
if (num2 <= 0.0)
{
y = 0;
}
else if (num2 >= this.cellTallLastTimesSquareDimension)
{
y = this.cellTallLast;
}
else
{
y = (ushort) Math.Floor((double) (num2 / ((double) base.cellSquareDimension)));
}
return (ushort) ((y * base.cellsWide) + x);
}
public void GetBounds(int cell, out Bounds bounds)
{
Vector3 vector;
int x = cell % base.cellsWide;
int y = cell / base.cellsWide;
this.GetCenter(x, y, out vector);
bounds = new Bounds(vector, new Vector3((float) base.cellSquareDimension, 64000f, (float) base.cellSquareDimension));
}
public void GetBounds(int x, int y, out Bounds bounds)
{
Vector3 vector;
this.GetCenter(x, y, out vector);
bounds = new Bounds(vector, new Vector3((float) base.cellSquareDimension, 64000f, (float) base.cellSquareDimension));
}
public void GetCenter(int cell, out Vector2 center)
{
double num = ((cell % base.cellsWide) - this.halfCellWideMinusHalfTwoMinusOddWide) * base.cellSquareDimension;
double num2 = ((cell / base.cellsWide) - this.halfCellTallMinusHalfTwoMinusOddTall) * base.cellSquareDimension;
center.x = (float) ((this.px + (this.fx * num2)) + (this.rx * num));
center.y = (float) ((this.pz + (this.fz * num2)) + (this.rz * num));
}
public void GetCenter(int cell, out Vector3 center)
{
double num = ((cell % base.cellsWide) - this.halfCellWideMinusHalfTwoMinusOddWide) * base.cellSquareDimension;
double num2 = ((cell / base.cellsWide) - this.halfCellTallMinusHalfTwoMinusOddTall) * base.cellSquareDimension;
center.x = (float) ((this.px + (this.fx * num2)) + (this.rx * num));
center.y = (float) ((this.py + (this.fy * num2)) + (this.ry * num));
center.z = (float) ((this.pz + (this.fz * num2)) + (this.rz * num));
}
public void GetCenter(int x, int y, out Vector2 center)
{
double num = (x - this.halfCellWideMinusHalfTwoMinusOddWide) * base.cellSquareDimension;
double num2 = (y - this.halfCellTallMinusHalfTwoMinusOddTall) * base.cellSquareDimension;
center.x = (float) ((this.px + (this.fx * num2)) + (this.rx * num));
center.y = (float) ((this.pz + (this.fz * num2)) + (this.rz * num));
}
public void GetCenter(int x, int y, out Vector3 center)
{
double num = (x - this.halfCellWideMinusHalfTwoMinusOddWide) * base.cellSquareDimension;
double num2 = (y - this.halfCellTallMinusHalfTwoMinusOddTall) * base.cellSquareDimension;
center.x = (float) ((this.px + (this.fx * num2)) + (this.rx * num));
center.y = (float) ((this.py + (this.fy * num2)) + (this.ry * num));
center.z = (float) ((this.pz + (this.fz * num2)) + (this.rz * num));
}
public void GetMax(int cell, out Vector2 max)
{
double num = (((cell % base.cellsWide) - this.halfCellWideMinusHalfTwoMinusOddWide) + 0.5) * base.cellSquareDimension;
double num2 = (((cell / base.cellsWide) - this.halfCellTallMinusHalfTwoMinusOddTall) + 0.5) * base.cellSquareDimension;
max.x = (float) ((this.px + (this.fx * num2)) + (this.rx * num));
max.y = (float) ((this.pz + (this.fz * num2)) + (this.rz * num));
}
public void GetMax(int cell, out Vector3 max)
{
double num = (((cell % base.cellsWide) - this.halfCellWideMinusHalfTwoMinusOddWide) + 0.5) * base.cellSquareDimension;
double num2 = (((cell / base.cellsWide) - this.halfCellTallMinusHalfTwoMinusOddTall) + 0.5) * base.cellSquareDimension;
max.x = (float) ((this.px + (this.fx * num2)) + (this.rx * num));
max.y = (float) (32000.0 + ((this.py + (this.fy * num2)) + (this.ry * num)));
max.z = (float) ((this.pz + (this.fz * num2)) + (this.rz * num));
}
public void GetMax(int x, int y, out Vector2 max)
{
double num = ((x - this.halfCellTallMinusHalfTwoMinusOddTall) + 0.5) * base.cellSquareDimension;
double num2 = ((y - this.halfCellTallMinusHalfTwoMinusOddTall) + 0.5) * base.cellSquareDimension;
max.x = (float) ((this.px + (this.fx * num2)) + (this.rx * num));
max.y = (float) ((this.pz + (this.fz * num2)) + (this.rz * num));
}
public void GetMax(int x, int y, out Vector3 max)
{
double num = ((x - this.halfCellWideMinusHalfTwoMinusOddWide) + 0.5) * base.cellSquareDimension;
double num2 = ((y - this.halfCellTallMinusHalfTwoMinusOddTall) + 0.5) * base.cellSquareDimension;
max.x = (float) ((this.px + (this.fx * num2)) + (this.rx * num));
max.y = (float) (32000.0 + ((this.py + (this.fy * num2)) + (this.ry * num)));
max.z = (float) ((this.pz + (this.fz * num2)) + (this.rz * num));
}
public void GetMin(int cell, out Vector2 min)
{
double num = (((cell % base.cellsWide) - this.halfCellWideMinusHalfTwoMinusOddWide) - 0.5) * base.cellSquareDimension;
double num2 = (((cell / base.cellsWide) - this.halfCellTallMinusHalfTwoMinusOddTall) - 0.5) * base.cellSquareDimension;
min.x = (float) ((this.px + (this.fx * num2)) + (this.rx * num));
min.y = (float) ((this.pz + (this.fz * num2)) + (this.rz * num));
}
public void GetMin(int cell, out Vector3 min)
{
double num = (((cell % base.cellsWide) - this.halfCellWideMinusHalfTwoMinusOddWide) - 0.5) * base.cellSquareDimension;
double num2 = (((cell / base.cellsWide) - this.halfCellTallMinusHalfTwoMinusOddTall) - 0.5) * base.cellSquareDimension;
min.x = (float) ((this.px + (this.fx * num2)) + (this.rx * num));
min.y = (float) (-32000.0 + ((this.py + (this.fy * num2)) + (this.ry * num)));
min.z = (float) ((this.pz + (this.fz * num2)) + (this.rz * num));
}
public void GetMin(int x, int y, out Vector2 min)
{
double num = ((x - this.halfCellWideMinusHalfTwoMinusOddWide) - 0.5) * base.cellSquareDimension;
double num2 = ((y - this.halfCellTallMinusHalfTwoMinusOddTall) - 0.5) * base.cellSquareDimension;
min.x = (float) ((this.px + (this.fx * num2)) + (this.rx * num));
min.y = (float) ((this.pz + (this.fz * num2)) + (this.rz * num));
}
public void GetMin(int x, int y, out Vector3 min)
{
double num = ((x - this.halfCellWideMinusHalfTwoMinusOddWide) - 0.5) * base.cellSquareDimension;
double num2 = ((y - this.halfCellTallMinusHalfTwoMinusOddTall) - 0.5) * base.cellSquareDimension;
min.x = (float) ((this.px + (this.fx * num2)) + (this.rx * num));
min.y = (float) (-32000.0 + ((this.py + (this.fy * num2)) + (this.ry * num)));
min.z = (float) ((this.pz + (this.fz * num2)) + (this.rz * num));
}
public void GetRect(int cell, out Rect rect)
{
float num7;
float num8;
float num9;
float num10;
int num = cell % base.cellsWide;
int num2 = cell / base.cellsWide;
double num3 = ((num - this.halfCellWideMinusHalfTwoMinusOddWide) - 0.5) * base.cellSquareDimension;
double num4 = ((num2 - this.halfCellTallMinusHalfTwoMinusOddTall) - 0.5) * base.cellSquareDimension;
double num5 = num3 + base.cellSquareDimension;
double num6 = num4 + base.cellSquareDimension;
double num11 = (this.px + (this.fx * num4)) + (this.rx * num3);
double num12 = (this.px + (this.fx * num6)) + (this.ry * num5);
if (num11 < num12)
{
num7 = (float) num11;
num8 = (float) (num12 - num11);
}
else
{
num7 = (float) num12;
num8 = (float) (num11 - num12);
}
num11 = (this.pz + (this.fz * num4)) + (this.rx * num3);
num12 = (this.pz + (this.fz * num6)) + (this.rx * num5);
if (num11 < num12)
{
num9 = (float) num11;
num10 = (float) (num12 - num11);
}
else
{
num9 = (float) num12;
num10 = (float) (num11 - num12);
}
rect = new Rect(num7, num9, num8, num10);
}
public void GetRect(int x, int y, out Rect rect)
{
float num5;
float num6;
float num7;
float num8;
double num = ((x - this.halfCellWideMinusHalfTwoMinusOddWide) - 0.5) * base.cellSquareDimension;
double num2 = ((y - this.halfCellTallMinusHalfTwoMinusOddTall) - 0.5) * base.cellSquareDimension;
double num3 = num + base.cellSquareDimension;
double num4 = num2 + base.cellSquareDimension;
double num9 = (this.px + (this.fx * num2)) + (this.rx * num);
double num10 = (this.px + (this.fx * num4)) + (this.ry * num3);
if (num9 < num10)
{
num5 = (float) num9;
num6 = (float) (num10 - num9);
}
else
{
num5 = (float) num10;
num6 = (float) (num9 - num10);
}
num9 = (this.pz + (this.fz * num2)) + (this.rx * num);
num10 = (this.pz + (this.fz * num4)) + (this.rx * num3);
if (num9 < num10)
{
num7 = (float) num9;
num8 = (float) (num10 - num9);
}
else
{
num7 = (float) num10;
num8 = (float) (num9 - num10);
}
rect = new Rect(num5, num7, num6, num8);
}
public ushort WorldCell(ref Vector3 point)
{
int cellWideLast;
int cellTallLast;
double num2 = point.x + this.flat_wide_ofs;
if (num2 <= 0.0)
{
cellWideLast = 0;
}
else if (num2 >= this.cellWideLastTimesSquareDimension)
{
cellWideLast = this.cellWideLast;
}
else
{
cellWideLast = (int) Math.Floor((double) (num2 / ((double) base.cellSquareDimension)));
}
double num4 = point.z + this.flat_tall_ofs;
if (num4 <= 0.0)
{
cellTallLast = 0;
}
else if (num4 >= this.cellTallLastTimesSquareDimension)
{
cellTallLast = this.cellTallLast;
}
else
{
cellTallLast = (int) Math.Floor((double) (num4 / ((double) base.cellSquareDimension)));
}
return (ushort) ((cellTallLast * base.cellsWide) + cellWideLast);
}
public ushort WorldCell(ref Vector3 point, out ushort x, out ushort y)
{
double num = point.x + this.flat_wide_ofs;
if (num <= 0.0)
{
x = 0;
}
else if (num >= this.cellWideLastTimesSquareDimension)
{
x = this.cellWideLast;
}
else
{
x = (ushort) Math.Floor((double) (num / ((double) base.cellSquareDimension)));
}
double num2 = point.z + this.flat_tall_ofs;
if (num2 <= 0.0)
{
y = 0;
}
else if (num2 >= this.cellTallLastTimesSquareDimension)
{
y = this.cellTallLast;
}