Hi again,
I have been busy coding a extensible yet simple scene graph for DE, but I'm having bit of problems with the rendering principles of this engine.
First I would like to use the already made Camera classes of the engine to do the view/projection things, but I have literally no idea how the engine handles the rendering. I have tried to read the source and the help and got the impression that delta collects the rendering of every frame and at the beginning of the next frame it actually renders them.
Ok now I create a scenegraph with the node :
Code:
SceneGraphNode root = new SceneGraphNode();
SceneGraphNode a = new SceneGraphNodeBox(Color.Red);
SceneGraphNode b = new SceneGraphNodeBox(Color.Green);
root.Add(a);
root.Add(b);
a.LocalPosition = new Vector(0, 10, 0);
b.LocalPosition = new Vector(-10, 0, 0);
BaseCamera.Current = new LookAtCamera(new Vector(0, 0, 20), Vector.Zero);
root.Update(true); // here the actual rendering happens
The SceneGraphNodeBox is just a basic box node for testing :
Code:
class SceneGraphNodeBox : SceneGraphNode
{
public Color Color
{
get;
set;
}
public SceneGraphNodeBox(Color color)
{
this.Color = color;
}
public override void Render()
{
Box.DrawOutline(new Vector(-1, -1, -1), new Vector(1, 1, 1), this.Color);
}
}
Ok, now the SceneGraphNode it self renders the whole tree with the update(bool) method (names will change to render when i get this to work). The camera classes update the ViewProjection and ViewInverse so we don't need to worry about them, let the camera do it's stuff, just use the data collected. Now the rendering in the node.
Code:
// mWorldTransformation is the objects transformation in the world space, calculated and tested, it is correct
Matrix.Multiply(ref mWorldTransformation, ref Screen.ViewProjection3D, ref Screen.ViewProjection3D);
Render();
This is all very simple yet totally wrong, now the ViewProjection3D is a cumulative product of all the scenegraph nodes (ie. having more than one node will mess up the viewproj matrix). But this way there is something on the screen (granted the upvector get's messed up, but still, it renders stuff). However there is only ONE box in the screen but there should be two. If I comment either one of the nodes a or b, other shows up, the rendering is not done when It is asked, it only renders the last Box.DrawOutline method.
Now we can fix the cumulative effect on the update method simply by storing the last viewproj matrix and restoring it after the render :
Code:
// store old
Matrix old = Screen.ViewProjection3D;
// mWorldTransformation is the objects transformation in the world space, calculated and tested, it is correct
Matrix.Multiply(ref mWorldTransformation, ref Screen.ViewProjection3D, ref Screen.ViewProjection3D);
Render();
// restore old
Screen.ViewProjection3D = old;
But now there is abolutely nothing on screen!
DynamicModules (especially the camera) seem to reset their state on their run (when the proj/viewinv and updatescreen is called). But they do not remember the states when something is actually drawn. How can I manipulate the view matrices when drawing multiple stuff on screen to actually make the scenegraph work???
I tried to create custom cameras with no Run methods to prevent the state from being reset - yet this is all hacky and I possibly could make it work rewriting some code from cameras, this is all wrong as I would like to use the Camera classes from the engine. No need to rewrite the wheel right...
Another problem, when I make a Game class like in the examples the Game's Run method is never called - even the static constructor of my Game class is never called. What seems to be the problem here? I have to use the optionalRunCode delegate to test and draw stuff - the only way it works. I start the Game with Game.Start();
Edited by user Sunday, September 4, 2011 1:32:14 PM(UTC)
| Reason: Typos.