-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneGraph.cs
More file actions
32 lines (26 loc) · 1.44 KB
/
SceneGraph.cs
File metadata and controls
32 lines (26 loc) · 1.44 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
using OpenTK;
using Template_P3;
namespace template_P3
{
class SceneGraph
{
public Node world = new Node();
public void Render(Shader shader, Matrix4 transform, float frameDuration)
{
var bb = this.GetSceneBoundingBox(transform);
world.Render(shader, transform, Matrix4.Identity, bb, frameDuration);
}
private Plane[] GetSceneBoundingBox(Matrix4 transform)
{
Plane[] bb = new Plane[6];
var mt = Matrix4.Invert(Matrix4.Transpose(transform));
bb[0] = new Plane(Vector3.Normalize(Vector3.Transform(new Vector3(1, 0, 0), mt)), Vector3.Transform(new Vector3(-1, 0, 0), mt));
bb[1] = new Plane(Vector3.Normalize(Vector3.Transform(new Vector3(-1, 0, 0), mt)), Vector3.Transform(new Vector3(1, 0, 0), mt));
bb[2] = new Plane(Vector3.Normalize(Vector3.Transform(new Vector3(0, 1, 0), mt)), Vector3.Transform(new Vector3(0, -1, 0), mt));
bb[3] = new Plane(Vector3.Normalize(Vector3.Transform(new Vector3(0, -1, 0), mt)), Vector3.Transform(new Vector3(0, 1, 0), mt));
bb[4] = new Plane(Vector3.Normalize(Vector3.Transform(new Vector3(0, 0, 1), mt)), Vector3.Transform(new Vector3(0, 0, -1), mt));
bb[5] = new Plane(Vector3.Normalize(Vector3.Transform(new Vector3(0, 0, -1), mt)), Vector3.Transform(new Vector3(0, 0, 1), mt));
return bb;
}
}
}