-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.cs
More file actions
41 lines (36 loc) · 973 Bytes
/
Copy pathUtil.cs
File metadata and controls
41 lines (36 loc) · 973 Bytes
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
using System;
using System.Numerics;
namespace RayTracer
{
class Util
{
[ThreadStatic]
private static Random rand;// = new Random();
public static void InitRandom(int seed)
{
rand = new Random(seed);
}
public static float Rand()
{
return (float)rand.NextDouble();
}
public static Vector3 RandInUnitSphere()
{
Vector3 p;
do
{
p = 2.0f * new Vector3(Rand(), Rand(), Rand()) - Vector3.One;
} while (p.LengthSquared() >= 1.0f);
return p;
}
public static Vector3 RandInUnitDisk()
{
Vector3 p;
do
{
p = 2.0f * new Vector3(Rand(), Rand(), 0) - new Vector3(1.0f, 1.0f, 0.0f);
} while (p.LengthSquared() >= 1.0f);
return p;
}
}
}