forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathUtility.cs
More file actions
45 lines (43 loc) · 1.41 KB
/
Copy pathMathUtility.cs
File metadata and controls
45 lines (43 loc) · 1.41 KB
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
using Unity.Collections;
using Unity.Mathematics;
using UnityEngine;
namespace Samples.Common
{
public struct GeneratePoints
{
static public void RandomPointsInSphere(float3 center, float radius, ref NativeArray<float3> points)
{
var radiusSquared = radius * radius;
var pointsFound = 0;
var count = points.Length;
while (pointsFound < count)
{
var p = new float3
{
x = UnityEngine.Random.Range(-radius, radius),
y = UnityEngine.Random.Range(-radius, radius),
z = UnityEngine.Random.Range(-radius, radius)
};
if (math.lengthsq(p) < radiusSquared)
{
points[pointsFound] = center + p;
pointsFound++;
}
}
}
static public void RandomPointsOnCircle(float3 center, float radius, ref NativeArray<float3> points)
{
var count = points.Length;
for (int i = 0; i < count; i++)
{
float angle = UnityEngine.Random.Range(0.0f, Mathf.PI * 2.0f);
points[i] = center + new float3
{
x = math.sin(angle) * radius,
y = 0,
z = math.cos(angle) * radius
};
}
}
}
}