-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneGraph.cs
More file actions
79 lines (61 loc) · 2.4 KB
/
SceneGraph.cs
File metadata and controls
79 lines (61 loc) · 2.4 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
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
using System.Linq;
using OpenTK;
namespace Template_P3
{
public class SceneGraph
{
Node root;
RenderTarget target; // intermediate render target
ScreenQuad quad; // screen filling quad for post processing
bool useRenderTarget = false; //ZET OP TRUE VOOR POST-PROCESSING
Game game;
public SceneGraph(Game game)
{
this.game = game;
// create the render target
target = new RenderTarget(game.screen.width, game.screen.height);
quad = new ScreenQuad();
}
public void RenderSceneGraph()
{
Matrix4 transform = game.TWorld * game.TCamera.Inverted() * game.TCamPerspective;
if (useRenderTarget)
{
// enable render target
target.Bind();
TransformNodesToCamera(root, transform * root.Matrix);
// render quad
target.Unbind();
quad.Render(game.postproc, target.GetTextureID());
}
else
{
// render scene directly to the screen
TransformNodesToCamera(root, transform * root.Matrix);
}
}
/// <summary>
/// Will loop through the scenegraph, from the root to the leaves. It will Render each node with orientation with respect to the parents above it.
/// </summary>
/// <param name="transformParents">the multiplied transformation matrices from all parent above the current node</param>
void TransformNodesToCamera(Node node, Matrix4 transformParents)
{
//Matrix4 TransformedMatrix = transformParents * node.Matrix;
Matrix4 TransformedMatrix = node.Matrix * transformParents;
// TODO: welke volgorde is correct??
node.NodeMesh.Render(game.shader, TransformedMatrix, game.TWorld, game.wood);
if (node.Children.Any()) //if there exists something within the children list:
{
foreach (Node childnode in node.Children)
{
TransformNodesToCamera(childnode, TransformedMatrix);
}
}
}
public Node Root
{
get { return root; }
set { root = value; }
}
}
}