budnhead/org.niclasundharald.engine/graphics/GLScene.cs

72 lines
1.3 KiB
C#

using System;
using OpenTK;
namespace org.niclasundharald.engine.graphics
{
public class GLScene
{
GLSceneOrientation sceneOrientation;
ShaderProgram shader;
WorldObject root;
public GLScene()
{
sceneOrientation = GlobalDefaults.instance().ActiveScene;
shader = GlobalDefaults.instance().DefaultShaderProgram;
root = new ObjectGroup();
}
public GLScene(GLSceneOrientation sceneOrientation)
{
this.sceneOrientation = sceneOrientation;
shader = GlobalDefaults.instance().DefaultShaderProgram;
root = new ObjectGroup();
}
public WorldObject RootObject {
get { return this.root; }
set { this.root = value; }
}
public void draw(){
Matrix4 objectMatrix = Matrix4.Identity;
shader.use();
if (root != null){
draw( objectMatrix, root );
}
foreach (WorldObject child in Actor.activeActors){
draw( objectMatrix, child );
}
}
public void draw(Matrix4 baseMatrix,WorldObject wo){
Matrix4 objectMatrix = wo.Transformation * baseMatrix;
//Console.WriteLine("draw(,{0}",wo);
//Console.WriteLine("draw(): o={0}\noM=\n{1}",wo,objectMatrix);
shader.setup(objectMatrix, sceneOrientation);
Model3D m3d = wo.getModel3D();
if (m3d != null){
m3d.draw();
}
foreach (WorldObject child in wo.Children){
draw( objectMatrix, child );
}
}
}
}