Okay, well I've been busy for the past week or so and haven't been able to work on this so I just slapped some code together, and nothing appears to be renderering...
Setup Code:
class Planet {
private Quad[] quads;
private Vector3 centre;
private float[,] depthTable;
public Quad[] Quads {
get { return quads; }
}
public float[,] DepthTable {
get { return depthTable; }
}
public Planet(GraphicsDevice device) {
Vector3 cubeDimensions = new Vector3(4120, 4120, 4120);
centre = new Vector3(0, 0, 0);
quads = new Quad[6];
quads[0] = new Quad(ref device, Face.Top, cubeDimensions, centre);
quads[1] = new Quad(ref device, Face.Bottom, cubeDimensions, centre);
quads[2] = new Quad(ref device, Face.Front, cubeDimensions, centre);
quads[3] = new Quad(ref device, Face.Back, cubeDimensions, centre);
quads[4] = new Quad(ref device, Face.Left, cubeDimensions, centre);
quads[5] = new Quad(ref device, Face.Right, cubeDimensions, centre);
float depth = cubeDimensions.X;
depthTable = new float[6, 2];
for (int x = 0; x < depthTable.GetLength(0); x++) {
depthTable[x, 0] = x + 1;
depthTable[x, 1] = (depth /= 2f);
}
for (int i = 0; i < quads.GetLength(0); i++) {
quads[i].ConstructNode(0, depthTable.GetLength(0));
}
}
}
Quad code:
public void ConstructNode(int depth, int maxDepth) {
this.depth = depth;
ConstructQuad();
if (depth >= maxDepth) {
this.leaf = true;
return;
} else if (depth < maxDepth) {
this.leaf = false;
children = new Quad[2, 2];
for (int x = 0; x < children.GetLength(0); x++) {
for (int y = 0; y < children.GetLength(1); y++) {
children[x, y] = new Quad(ref device, face, this.dimensions, this.planetCentre);
children[x, y].Index = new Vector2(x + index.X * 2, y + index.Y * 2);
children[x, y].SetSize(width / 2, height / 2);
children[x, y].ConstructNode(depth + 1, maxDepth);
}
}
}
}
Rendering code:
private void RenderPlanet(Planet planet) {
Quad[] quads = planet.Quads;
float[,] depthTable = planet.DepthTable;
foreach (Quad root in quads) {
Quad[] children = root.GetChildren().ToArray();
TraverseChildren(children, depthTable);
}
}
private void TraverseChildren(Quad[] children, float[,] depthTable) {
if (children != null) {
foreach (Quad child in children) {
Vector3 quadCentre = child.QuadCentre;
float distance = -1f;
Vector3.Distance(ref position, ref quadCentre, out distance);
float depthLevel = DetermineDepth(distance, depthTable);
if (depthLevel > child.Depth) {
TraverseChildren(child.GetChildren(), depthTable);
}
else if (depthLevel == child.Depth) {
RenderChild(child);
}
if (child.Depth == 0 && depthLevel == 0) {
RenderChild(child);
break;
}
}
}
}
private float DetermineDepth(float distance, float[,] depthTable) {
float depthLevel = 0;
for (int i = 0; i < depthTable.GetLength(0); i++) {
if (distance < depthTable[i, 1]) {
depthLevel = i;
}
}
return depthLevel;
}
private void RenderChild(Quad quad) {
device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
RasterizerState rs = new RasterizerState();
rs.CullMode = CullMode.None;
rs.FillMode = mode;
device.RasterizerState = rs;
device.DepthStencilState = DepthStencilState.Default;
Matrix world = Matrix.Identity * Matrix.CreateTranslation(new Vector3(64 / 2, 0, 64 / 2));
effect.CurrentTechnique = effect.Techniques["Coloured"];
effect.Parameters["View"].SetValue(view);
effect.Parameters["Projection"].SetValue(projection);
effect.Parameters["World"].SetValue(world);
foreach (EffectPass pass in effect.CurrentTechnique.Passes) {
pass.Apply();
device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, quad.Vertices.ToArray(), 0, quad.Vertices.Count, quad.Indices.ToArray(), 0, quad.Indices.Count / 3);
}
}
Knowing me I've properly made a *really* stupid mistake somewhere. ATM I am also learning C++ and Open GL using SFML for windowing. The reason for this is that I am using my laptop more and more, and since I am running debian on it, I can't work on this project. Thus far I actually prefer C++ and Open GL over C# and XNA. Once I learn enough I think I rewrite this in that...