-
Notifications
You must be signed in to change notification settings - Fork 1
/
EMath.cs
603 lines (532 loc) · 24.8 KB
/
EMath.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
#define OPTIMIZEDMATH
using System;
using UnityEngine;
namespace EManagersLib {
/// <summary>
/// UnityEngine.Mathf is extraordinarily slow compared to System.Math
/// and these are common Mathf methods that are optimized. I hate re-inventing
/// the wheel, but these speed ups are drastic enough to do them
/// </summary>
#if OPTIMIZEDMATH
public readonly struct EMath {
public static readonly Vector2 Vector2Zero = Vector2.zero;
public static readonly Vector3 Vector3Zero = Vector3.zero;
public static readonly Vector4 Vector4Zero = Vector4.zero;
public static readonly Vector3 Vector3Down = Vector3.down;
public static readonly Vector3 Vector3Up = Vector3.up;
public static readonly Vector3 Vector3Left = Vector3.left;
public static readonly Vector3 Vector3Right = Vector3.right;
public static readonly Vector3 Vector3Forward = Vector3.forward;
public static readonly Vector3 DefaultLodMin = new Vector3(100000f, 100000f, 100000f);
public static readonly Vector3 DefaultLodMax = new Vector3(-100000f, -100000f, -100000f);
public static readonly Vector3 DefaultLod100 = new Vector3(100f, 100f, 100f);
public static readonly Color ColorClear = Color.clear;
/// <summary>
/// Get Matrix.identity using this static variable. It's about ~5x faster
/// </summary>
public static readonly Matrix4x4 matrix4Identity = Matrix4x4.identity;
/// <summary>
/// Functions exactly the same as Mathf.Approximately but 52x faster
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static bool Approximately(float a, float b) => a + 0.0000000596f >= b && a - 0.0000000596f <= b;
/// <summary>
/// Functions exactly the same as Mathf.Abs but ~4x faster
/// </summary>
/// <param name="val"></param>
/// <returns>Returns absolute number</returns>
public static int Abs(int val) => val < 0 ? -val : val;
/// <summary>
/// Functions exactly the same as Mathf.Abs but ~4x faster
/// </summary>
/// <param name="val"></param>
/// <returns>Returns absolute number</returns>
public static float Abs(float val) => val < 0 ? -val : val;
/// <summary>
/// Functions exactly the same as Mathf.RoundToInt but ~77x faster
/// </summary>
/// <param name="f">The value that will be rounded</param>
/// <returns>The rounded result</returns>
public static int RoundToInt(float f) => f >= 0 ? (int)(f + 0.5f) : -(int)(0.5f - f);
/// <summary>
/// Functions exactly the same as Mathf.Clamp but ~28x faster
/// </summary>
/// <param name="val">The value needing bounds check</param>
/// <param name="min">The minimum limit</param>
/// <param name="max">The maximum limit</param>
/// <returns>Returns the clamped result</returns>
public static int Clamp(int val, int min, int max) => val < min ? min : (val > max ? max : val);
/// <summary>
/// Functions exactly the same as Mathf.Clamp but ~28x faster
/// </summary>
/// <param name="val">The value needing bounds check</param>
/// <param name="min">The minimum limit</param>
/// <param name="max">The maximum limit</param>
/// <returns>Returns the clamped result</returns>
public static float Clamp(float val, float min, float max) => val < min ? min : (val > max ? max : val);
/// <summary>
/// Same as Mathf.Clamp01, clamps between 0 and 1
/// </summary>
/// <param name="val"></param>
/// <returns>Returns value between 0 and 1</returns>
public static float Clamp01(float val) => val > 1f ? 1f : (val < 0f ? 0f : val);
/// <summary>
/// Same as Mathf.Clamp01, clamps between 0 and 1
/// </summary>
/// <param name="val"></param>
/// <returns>Returns value between 0 and 1</returns>
public static int Clamp01(int val) => val > 1 ? 1 : (val < 0 ? 0 : val);
/// <summary>
/// Same as Mathf.Floor except ~56x faster
/// </summary>
/// <param name="val">float</param>
/// <returns>Returns the rounded value</returns>
public static float Floor(float val) => (int)val;
/// <summary>
/// Same as Mathf.Lerp, this version is about ~1.5x faster
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="t"></param>
/// <returns></returns>
public static float Lerp(float a, float b, float t) => a + (b - a) * (t > 1 ? 1 : (t < 0 ? 0 : t));
/// <summary>
/// Same as Vector3.Lerp, just slightly faster
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="t"></param>
/// <returns>Returns Vector3</returns>
public static Vector3 Lerp(Vector3 a, Vector3 b, float t) {
t = t > 1 ? 1 : (t < 0 ? 0 : t);
return new Vector3(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t);
}
/// <summary>
/// I don't know why Mathf.Max and Math.Max is so slow, but this method will work ~27x faster
/// </summary>
/// <param name="a">First value to compare</param>
/// <param name="b">Second value to compare</param>
/// <returns>Returns the maximum value</returns>
public static int Max(int a, int b) => a > b ? a : b;
/// <summary>
/// I don't know why Mathf.Min and Math.Min is so slow, but this method will work ~27x faster
/// </summary>
/// <param name="a">First value to compare</param>
/// <param name="b">Second value to compare</param>
/// <returns>Returns the minimum value</returns>
public static int Min(int a, int b) => a < b ? a : b;
/// <summary>
/// I don't know why Mathf.Max and Math.Max is so slow, but this method will work ~27x faster
/// </summary>
/// <param name="a">First value to compare</param>
/// <param name="b">Second value to compare</param>
/// <returns>Returns the maximum value</returns>
public static float Max(float a, float b) => a > b ? a : b;
/// <summary>
/// I don't know why Mathf.Min and Math.Min is so slow, but this method will work ~27x faster
/// </summary>
/// <param name="a">First value to compare</param>
/// <param name="b">Second value to compare</param>
/// <returns>Returns the minimum value</returns>
public static float Min(float a, float b) => a < b ? a : b;
/// <summary>
/// Compares Vector3 and returns the max, this method is about ~2x faster than Vector3.Max
/// </summary>
/// <param name="lhs">Vector3</param>
/// <param name="rhs">Vector3</param>
/// <returns>Returns the max vector3</returns>
public static Vector3 Max(Vector3 lhs, Vector3 rhs) => new Vector3(Max(lhs.x, rhs.x), Max(lhs.y, rhs.y), Max(lhs.z, rhs.z));
/// <summary>
/// Compares Vector3 and returns the min, this method is about ~2x faster than Vector3.Min
/// </summary>
/// <param name="lhs">Vector3</param>
/// <param name="rhs">Vector3</param>
/// <returns>Returns the min vector3</returns>
public static Vector3 Min(Vector3 lhs, Vector3 rhs) => new Vector3(Min(lhs.x, rhs.x), Min(lhs.y, rhs.y), Min(lhs.z, rhs.z));
/// <summary>
/// This sine function is an approximation accurate to about ~0.001f, the speed up is about ~20x faster
/// </summary>
/// <param name="x"></param>
/// <returns>Returns the sine result in float</returns>
public unsafe static float Sin(double x) {
int k;
double y;
double z;
z = x;
z *= 0.3183098861837907;
z += 6755399441055744.0;
k = *((int*)&z);
z = k;
z *= 3.1415926535897932;
x -= z;
y = x;
y *= x;
z = 0.0073524681968701;
z *= y;
z -= 0.1652891139701474;
z *= y;
z += 0.9996919862959676;
x *= z;
k &= 1;
k += k;
z = k;
z *= x;
x -= z;
return (float)x;
}
/// <summary>
/// This cosine function is an approximation accurate to about ~0.001f, the speed up is about ~20x faster
/// </summary>
/// <param name="x"></param>
/// <returns>Returns the cosine result in float</returns>
public static float Cos(float x) => Sin(x + 1.5707963f);
/// <summary>
/// Functions just like Mathf::ACos
/// </summary>
/// <param name="f"></param>
/// <returns></returns>
public static float Acos(float f) => (float)Math.Acos(f);
/// <summary>
/// Functions just like Mathf::Asin
/// </summary>
/// <param name="f"></param>
/// <returns></returns>
public static float Asin(float f) => (float)Math.Asin(f);
/// <summary>
/// Functions just like Mathf::Atan2
/// </summary>
/// <param name="y"></param>
/// <param name="x"></param>
/// <returns></returns>
public static float Atan2(float y, float x) => (float)Math.Atan2(y, x);
/// <summary>
/// Functions just like Mathf::Atan
/// </summary>
/// <param name="f"></param>
/// <returns></returns>
public static float Atan(float f) => (float)Math.Atan(f);
/// <summary>
/// Functions exactly the same as Mathf.Repeat, just faster
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static float Repeat(float a, float b) => a % b;
/// <summary>
/// This Sqrt function is accurate to only 0.01f, the speed is about ~3x faster
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public static unsafe float SqrtFast(float x) {
float xHalf = 0.5f * x;
int tmp = 0x5f3759df - (*(int*)&x >> 1);
float xRes = *(float*)&tmp;
xRes *= (1.5f - (xHalf * xRes * xRes));
return xRes * x;
}
public static float Sqrt(float f) => (float)Math.Sqrt(f);
/// <summary>
/// Functions Exactly the same as Mathf.Sign
/// </summary>
/// <param name="a"></param>
/// <returns></returns>
public static float Sign(float a) => a < 0 ? -1 : 1;
/// <summary>
/// Functions Exactly the same as Mathf.Sign
/// </summary>
/// <param name="a"></param>
/// <returns></returns>
public static int Sign(int a) => a < 0 ? -1 : 1;
/// <summary>
/// Functions Exactly like Mathf.FloorToInt, just ~8x faster
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public static int FloorToInt(float val) => (val < 0) ? (int)(val - 1) : (int)val;
/// <summary>
/// Functions like Mathf.CeilToInt, just ~3x faster
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public static int CeilToInt(float val) => (val < 0) ? (int)(val) : (val % (int)val > 0f ? (int)(val + 1) : (int)val);
public static bool IsNearlyEqual(float a, float b, float epsilon = 0.0001f) => a == b || Abs(a - b) < epsilon;
/// <summary>
/// Functions exactly like MathUtils.SmoothStep. This one is only 1.2x faster
/// </summary>
/// <param name="edge0"></param>
/// <param name="edge1"></param>
/// <param name="x"></param>
/// <returns></returns>
public static float SmoothStep(float edge0, float edge1, float x) {
x = (x - edge0) / (edge1 - edge0);
x = x < 0 ? 0 : (x > 1 ? 1 : x);
return x * x * (3f - 2f * x);
}
/// <summary>
/// Functions exactly the same as RenderManager.CameraInfo.CheckRenderDistance, but ~15x faster
/// </summary>
/// <param name="cameraInfo"></param>
/// <param name="point"></param>
/// <param name="maxDistance"></param>
/// <returns></returns>
public static bool ECheckRenderDistance(RenderManager.CameraInfo cameraInfo, Vector3 point, float maxDistance) {
float distance = maxDistance * 0.45f;
Vector3 campos = cameraInfo.m_position;
Vector3 camforward = cameraInfo.m_forward;
float x = point.x - campos.x - camforward.x * distance;
float y = point.y - campos.y - camforward.y * distance;
float z = point.z - campos.z - camforward.z * distance;
return (x * x + y * y + z * z) < maxDistance * maxDistance * 0.3025f;
}
}
#else
public struct EMath {
public static readonly Vector2 Vector2Zero = Vector2.zero;
public static readonly Vector3 Vector3Zero = Vector3.zero;
public static readonly Vector4 Vector4Zero = Vector4.zero;
public static readonly Vector3 Vector3Down = Vector3.down;
public static readonly Vector3 Vector3Up = Vector3.up;
public static readonly Vector3 Vector3Left = Vector3.left;
public static readonly Vector3 Vector3Right = Vector3.right;
public static readonly Vector3 Vector3Forward = Vector3.forward;
public static readonly Color ColorClear = Color.clear;
public static readonly Color ColorBlack = Color.black;
/// <summary>
/// Get Matrix.identity using this static variable. It's about ~5x faster
/// </summary>
public static readonly Matrix4x4 matrix4Identity = Matrix4x4.identity;
/// <summary>
/// Functions exactly the same as Mathf.Approximately but 52x faster
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static bool Approximately(float a, float b) => Abs(b - a) < Max(1E-06f * Max(Abs(a), Abs(b)), Mathf.Epsilon * 8f);
/// <summary>
/// Functions exactly the same as Mathf.Abs but ~4x faster
/// </summary>
/// <param name="val"></param>
/// <returns>Returns absolute number</returns>
public static int Abs(int val) => val < 0 ? -val : val;
/// <summary>
/// Functions exactly the same as Mathf.Abs but ~4x faster
/// </summary>
/// <param name="val"></param>
/// <returns>Returns absolute number</returns>
public static float Abs(float val) => val < 0 ? -val : val;
/// <summary>
/// Functions exactly the same as Mathf.RoundToInt but ~77x faster
/// </summary>
/// <param name="f">The value that will be rounded</param>
/// <returns>The rounded result</returns>
public static int RoundToInt(float f) => (int)Math.Round(f);
/// <summary>
/// Functions exactly the same as Mathf.Clamp but ~28x faster
/// </summary>
/// <param name="val">The value needing bounds check</param>
/// <param name="min">The minimum limit</param>
/// <param name="max">The maximum limit</param>
/// <returns>Returns the clamped result</returns>
public static int Clamp(int val, int min, int max) => val < min ? min : (val > max ? max : val);
/// <summary>
/// Functions exactly the same as Mathf.Clamp but ~28x faster
/// </summary>
/// <param name="val">The value needing bounds check</param>
/// <param name="min">The minimum limit</param>
/// <param name="max">The maximum limit</param>
/// <returns>Returns the clamped result</returns>
public static float Clamp(float val, float min, float max) => val < min ? min : (val > max ? max : val);
/// <summary>
/// Same as Mathf.Clamp01, clamps between 0 and 1
/// </summary>
/// <param name="val"></param>
/// <returns>Returns value between 0 and 1</returns>
public static float Clamp01(float val) => val > 1f ? 1f : (val < 0f ? 0f : val);
/// <summary>
/// Same as Mathf.Clamp01, clamps between 0 and 1
/// </summary>
/// <param name="val"></param>
/// <returns>Returns value between 0 and 1</returns>
public static int Clamp01(int val) => val > 1 ? 1 : (val < 0 ? 0 : val);
/// <summary>
/// Same as Mathf.Floor except ~56x faster
/// </summary>
/// <param name="val">float</param>
/// <returns>Returns the rounded value</returns>
public static float Floor(float val) => (int)val;
/// <summary>
/// Same as Mathf.Lerp, this version is about ~1.5x faster
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="t"></param>
/// <returns></returns>
public static float Lerp(float a, float b, float t) => a + (b - a) * (t > 1 ? 1 : (t < 0 ? 0 : t));
/// <summary>
/// Same as Vector3.Lerp, just slightly faster
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="t"></param>
/// <returns>Returns Vector3</returns>
public static Vector3 Lerp(Vector3 a, Vector3 b, float t) {
t = t > 1 ? 1 : (t < 0 ? 0 : t);
return new Vector3(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t);
}
/// <summary>
/// I don't know why Mathf.Max and Math.Max is so slow, but this method will work ~27x faster
/// </summary>
/// <param name="a">First value to compare</param>
/// <param name="b">Second value to compare</param>
/// <returns>Returns the maximum value</returns>
public static int Max(int a, int b) => a > b ? a : b;
/// <summary>
/// I don't know why Mathf.Min and Math.Min is so slow, but this method will work ~27x faster
/// </summary>
/// <param name="a">First value to compare</param>
/// <param name="b">Second value to compare</param>
/// <returns>Returns the minimum value</returns>
public static int Min(int a, int b) => a < b ? a : b;
/// <summary>
/// I don't know why Mathf.Max and Math.Max is so slow, but this method will work ~27x faster
/// </summary>
/// <param name="a">First value to compare</param>
/// <param name="b">Second value to compare</param>
/// <returns>Returns the maximum value</returns>
public static float Max(float a, float b) => a > b ? a : b;
/// <summary>
/// I don't know why Mathf.Min and Math.Min is so slow, but this method will work ~27x faster
/// </summary>
/// <param name="a">First value to compare</param>
/// <param name="b">Second value to compare</param>
/// <returns>Returns the minimum value</returns>
public static float Min(float a, float b) => a < b ? a : b;
/// <summary>
/// Compares Vector3 and returns the max, this method is about ~2x faster than Vector3.Max
/// </summary>
/// <param name="lhs">Vector3</param>
/// <param name="rhs">Vector3</param>
/// <returns>Returns the max vector3</returns>
public static Vector3 Max(Vector3 lhs, Vector3 rhs) => new Vector3(Max(lhs.x, rhs.x), Max(lhs.y, rhs.y), Max(lhs.z, rhs.z));
/// <summary>
/// Compares Vector3 and returns the min, this method is about ~2x faster than Vector3.Min
/// </summary>
/// <param name="lhs">Vector3</param>
/// <param name="rhs">Vector3</param>
/// <returns>Returns the min vector3</returns>
public static Vector3 Min(Vector3 lhs, Vector3 rhs) => new Vector3(Min(lhs.x, rhs.x), Min(lhs.y, rhs.y), Min(lhs.z, rhs.z));
/// <summary>
/// This sine function is an approximation accurate to about ~0.001f, the speed up is about ~20x faster
/// </summary>
/// <param name="x"></param>
/// <returns>Returns the sine result in float</returns>
public static float Sin(float x) => (float)Math.Sin(x);
/// <summary>
/// This cosine function is an approximation accurate to about ~0.001f, the speed up is about ~20x faster
/// </summary>
/// <param name="x"></param>
/// <returns>Returns the cosine result in float</returns>
public static float Cos(float x) => (float)Math.Cos(x);
/// <summary>
/// Functions just like Mathf::ACos
/// </summary>
/// <param name="f"></param>
/// <returns></returns>
public static float Acos(float f) => (float)Math.Acos(f);
/// <summary>
/// Functions just like Mathf::Asin
/// </summary>
/// <param name="f"></param>
/// <returns></returns>
public static float Asin(float f) => (float)Math.Asin(f);
/// <summary>
/// Functions just like Mathf::Atan2
/// </summary>
/// <param name="y"></param>
/// <param name="x"></param>
/// <returns></returns>
public static float Atan2(float y, float x) => (float)Math.Atan2(y, x);
/// <summary>
/// Functions just like Mathf::Atan
/// </summary>
/// <param name="f"></param>
/// <returns></returns>
public static float Atan(float f) => (float)Math.Atan(f);
/// <summary>
/// Functions exactly the same as Mathf.Repeat, just faster
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static float Repeat(float a, float b) => a % b;
/// <summary>
/// This Sqrt function is accurate to only 0.01f, the speed is about ~3x faster
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public static unsafe float SqrtFast(float x) {
float xHalf = 0.5f * x;
int tmp = 0x5f3759df - (*(int*)&x >> 1);
float xRes = *(float*)&tmp;
xRes *= (1.5f - (xHalf * xRes * xRes));
return xRes * x;
}
public static float Sqrt(float f) => (float)Math.Sqrt(f);
/// <summary>
/// Functions Exactly the same as Mathf.Sign
/// </summary>
/// <param name="a"></param>
/// <returns></returns>
public static float Sign(float a) => a < 0 ? -1 : 1;
/// <summary>
/// Functions Exactly the same as Mathf.Sign
/// </summary>
/// <param name="a"></param>
/// <returns></returns>
public static int Sign(int a) => a < 0 ? -1 : 1;
/// <summary>
/// Functions Exactly like Mathf.FloorToInt, just ~8x faster
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public static int FloorToInt(float val) => (int)Math.Floor(val);
/// <summary>
/// Functions like Mathf.CeilToInt, just ~3x faster
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public static int CeilToInt(float val) => (int)Math.Ceiling(val);
public static bool IsNearlyEqual(float a, float b, float epsilon = 0.0001f) => a == b || Abs(a - b) < epsilon;
/// <summary>
/// Functions exactly like MathUtils.SmoothStep. This one is only 1.2x faster
/// </summary>
/// <param name="edge0"></param>
/// <param name="edge1"></param>
/// <param name="x"></param>
/// <returns></returns>
public static float SmoothStep(float edge0, float edge1, float x) {
x = (x - edge0) / (edge1 - edge0);
x = x < 0 ? 0 : (x > 1 ? 1 : x);
return x * x * (3f - 2f * x);
}
/// <summary>
/// Functions exactly the same as RenderManager.CameraInfo.CheckRenderDistance, but ~15x faster
/// </summary>
/// <param name="cameraInfo"></param>
/// <param name="point"></param>
/// <param name="maxDistance"></param>
/// <returns></returns>
public static bool ECheckRenderDistance(RenderManager.CameraInfo cameraInfo, Vector3 point, float maxDistance) {
float distance = maxDistance * 0.45f;
Vector3 campos = cameraInfo.m_position;
Vector3 camforward = cameraInfo.m_forward;
float x = point.x - campos.x - camforward.x * distance;
float y = point.y - campos.y - camforward.y * distance;
float z = point.z - campos.z - camforward.z * distance;
return (x * x + y * y + z * z) < maxDistance * maxDistance * 0.3025f;
}
}
#endif
}