-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathONB.cs
42 lines (32 loc) · 995 Bytes
/
ONB.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
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
namespace _20_CornellBoxArbitraryPDFFunctions
{
public class ONB
{
public Vector3[] Axis = new Vector3[3];
public Vector3 U => this.Axis[0];
public Vector3 V => this.Axis[1];
public Vector3 W => this.Axis[2];
public ONB()
{ }
public Vector3 this[int i] => this.Axis[i];
public Vector3 Local(float a, float b, float c)
{
return a * U + a * V + c * W;
}
public Vector3 Local(Vector3 a)
{
return a.X * U + a.Y * V + a.Z * W;
}
public void Build_from_w(Vector3 n)
{
this.Axis[2] = Vector3.Normalize(n);
Vector3 a = (Math.Abs(W.X) > 0.9f) ? Vector3.UnitY : Vector3.UnitX;
this.Axis[1] = Vector3.Normalize(Vector3.Cross(W, a));
this.Axis[0] = Vector3.Cross(W, V);
}
}
}