public QuadTreeNode(GraphicsDevice graphicsDevice, HeightProvider heightProvider, NodeType nodeType, QuadTreeNode parentNode, float edgeLengthFlat, Vector3Double originPositionFlat, Vector3 upDirectionFlat, Vector3 rightDirectionFlat, float radiusSphere) { _graphicsDevice = graphicsDevice; _heightProvider = heightProvider; _nodeType = nodeType; _parentNode = parentNode; _edgeLengthFlat = edgeLengthFlat; _halfEdgeLengthFlat = _edgeLengthFlat / 2; _quarterEdgeLengthFlat = _edgeLengthFlat / 4; _originPositionFlat = originPositionFlat; _upDirectionFlat = upDirectionFlat; _rightDirectionFlat = rightDirectionFlat; _radiusSphere = radiusSphere; Vector3 originPositionSphereNormal = Vector3Double.Normalize(_originPositionFlat); Vector3Double originPositionSpherePosition = new Vector3Double(_radiusSphere * originPositionSphereNormal); OriginPositionSphere = originPositionSpherePosition + _heightProvider.GetHeight(originPositionSpherePosition) * originPositionSphereNormal; IndexBuffer = _indexBuffers[IndexBufferSelection.Base]; }
public void UpdateChildrenRecursively(GraphicsDevice graphicsDevice, HeightProvider heightProvider, Vector3Double cameraPosition, List <QuadTreeNode> renderQueue, List <QuadTreeNode> disposalQueue, int childCreationDepth) { // Node should have children if (childCreationDepth < MaxChildCreationDepth && _halfEdgeLengthFlat > EdgeLengthLimit && Vector3Double.Distance(OriginPositionSphere, cameraPosition) < SplitDistanceMultiplier * _edgeLengthFlat) { // Add children if they aren't there if (!_hasChildren) { ChildUpLeft = new QuadTreeNode(graphicsDevice, heightProvider, NodeType.ChildUpLeft, this, _halfEdgeLengthFlat, _originPositionFlat + _quarterEdgeLengthFlat * (_upDirectionFlat - _rightDirectionFlat), _upDirectionFlat, _rightDirectionFlat, _radiusSphere); ChildUpRight = new QuadTreeNode(graphicsDevice, heightProvider, NodeType.ChildUpRight, this, _halfEdgeLengthFlat, _originPositionFlat + _quarterEdgeLengthFlat * (_upDirectionFlat + _rightDirectionFlat), _upDirectionFlat, _rightDirectionFlat, _radiusSphere); ChildDownRight = new QuadTreeNode(graphicsDevice, heightProvider, NodeType.ChildDownRight, this, _halfEdgeLengthFlat, _originPositionFlat + _quarterEdgeLengthFlat * (-_upDirectionFlat + _rightDirectionFlat), _upDirectionFlat, _rightDirectionFlat, _radiusSphere); ChildDownLeft = new QuadTreeNode(graphicsDevice, heightProvider, NodeType.ChildDownLeft, this, _halfEdgeLengthFlat, _originPositionFlat + _quarterEdgeLengthFlat * (-_upDirectionFlat - _rightDirectionFlat), _upDirectionFlat, _rightDirectionFlat, _radiusSphere); _hasChildren = true; childCreationDepth += 1; } ChildUpLeft.UpdateChildrenRecursively(graphicsDevice, heightProvider, cameraPosition, renderQueue, disposalQueue, childCreationDepth); ChildUpRight.UpdateChildrenRecursively(graphicsDevice, heightProvider, cameraPosition, renderQueue, disposalQueue, childCreationDepth); ChildDownRight.UpdateChildrenRecursively(graphicsDevice, heightProvider, cameraPosition, renderQueue, disposalQueue, childCreationDepth); ChildDownLeft.UpdateChildrenRecursively(graphicsDevice, heightProvider, cameraPosition, renderQueue, disposalQueue, childCreationDepth); } // Node shouldn't have children else { // Remove children and mark them for disposal if they are there if (_hasChildren) { disposalQueue.Add(ChildUpLeft); disposalQueue.Add(ChildUpRight); disposalQueue.Add(ChildDownRight); disposalQueue.Add(ChildDownLeft); ChildUpLeft = null; ChildUpRight = null; ChildDownRight = null; ChildDownLeft = null; _hasChildren = false; } if (VertexBuffer == null) { CalculateContents(); } renderQueue.Add(this); } }
public World(GraphicsDevice graphicsDevice, HeightProvider heightProvider, float radius, DirectionLight light, Random starDomeRandom, Atmosphere atmosphere) { _graphicsDevice = graphicsDevice; _heightProvider = heightProvider; _rootNodes = new QuadTreeNode[6] { new QuadTreeNode(_graphicsDevice, _heightProvider, NodeType.Root, null, 2 * radius, new Vector3Double(radius, 0, 0), -Vector3.UnitZ, Vector3.UnitY, radius), new QuadTreeNode(_graphicsDevice, _heightProvider, NodeType.Root, null, 2 * radius, new Vector3Double(-radius, 0, 0), Vector3.UnitZ, Vector3.UnitY, radius), new QuadTreeNode(_graphicsDevice, _heightProvider, NodeType.Root, null, 2 * radius, new Vector3Double(0, radius, 0), Vector3.UnitZ, Vector3.UnitX, radius), new QuadTreeNode(_graphicsDevice, _heightProvider, NodeType.Root, null, 2 * radius, new Vector3Double(0, -radius, 0), -Vector3.UnitZ, Vector3.UnitX, radius), new QuadTreeNode(_graphicsDevice, _heightProvider, NodeType.Root, null, 2 * radius, new Vector3Double(0, 0, radius), -Vector3.UnitY, Vector3.UnitX, radius), new QuadTreeNode(_graphicsDevice, _heightProvider, NodeType.Root, null, 2 * radius, new Vector3Double(0, 0, -radius), Vector3.UnitY, Vector3.UnitX, radius) }; _newRenderQueues = new List <QuadTreeNode>[6] { new List <QuadTreeNode>(), new List <QuadTreeNode>(), new List <QuadTreeNode>(), new List <QuadTreeNode>(), new List <QuadTreeNode>(), new List <QuadTreeNode>() }; _newDisposalQueues = new List <QuadTreeNode>[6] { new List <QuadTreeNode>(), new List <QuadTreeNode>(), new List <QuadTreeNode>(), new List <QuadTreeNode>(), new List <QuadTreeNode>(), new List <QuadTreeNode>() }; Radius = radius; Light = light; StarDome = new StarDome(starDomeRandom); Atmosphere = atmosphere; RenderQueue = new List <QuadTreeNode>(); }