public void Update(GameTime gameTime, float heightAbovePlanetSurface, Vector3 cameraPos) { if (SystemCore.ActiveScene.LightsInScene.Count > 0) { DiffuseLight light = SystemCore.ActiveScene.LightsInScene[0] as DiffuseLight; if (groundScatteringHelper != null) { groundScatteringHelper.Update(heightAbovePlanetSurface, light.LightDirection, cameraPos - CurrentCenterPosition); if (atmosphere != null) { atmosphere.Update(light.LightDirection, cameraPos, heightAbovePlanetSurface); } } if (CurrentOrbit != null) { Vector3 pointToOrbit = CurrentOrbit.OrbitPoint; if (CurrentOrbit.BodyToOrbit != null) { pointToOrbit = CurrentOrbit.BodyToOrbit.CurrentCenterPosition; } CalculateOrbit(pointToOrbit, CurrentOrbit.Axis, CurrentOrbit.Speed); } if (CurrentSpin != null) { CalculateRotation(CurrentSpin.Axis, CurrentSpin.Speed); } } }
public void Update(GameTime gameTime) { Vector3 planetCenter = Transform.AbsoluteTransform.Translation; Vector3 toCenterOfPlanet = Transform.AbsoluteTransform.Translation - SystemCore.ActiveCamera.Position; float distanceToCenterOfPlanet = toCenterOfPlanet.Length(); float surfaceDistance = distanceToCenterOfPlanet - radius; if (HasAtmosphere) { atmosphere.Update(sunDirection, SystemCore.ActiveCamera.Position, distanceToCenterOfPlanet); atmosphericScatteringHelper.Update(distanceToCenterOfPlanet, sunDirection, SystemCore.ActiveCamera.Position - Transform.AbsoluteTransform.Translation); } float farPlaneMultiplier = MonoMathHelper.MapFloatRange(radius, radius * 2, 0.3f, 1f, surfaceDistance); GenerateCustomProjectionMatrix(distanceToCenterOfPlanet * farPlaneMultiplier); var frustrum = new BoundingFrustum(SystemCore.ActiveCamera.View * customProjection); int activeCount = 0; foreach (PlanetNode node in activePatches.Values) { node.Update(); //all nodes are flagged for removal every frame. //The LOD calculation will unflag if nodes should be kept. node.remove = true; if (!frustrum.Intersects(node.boundingSphere)) { node.Disable(); } else { if (SystemWarGlobalSettings.RenderQuadtreeConnectivity) { RenderConnections(node); } node.Enable(); activeCount++; } } if (SystemWarGlobalSettings.RepairSeams) { CalculateConnectivity(); } for (int i = 0; i < rootNodes.Count; i++) { PlanetNode root = rootNodes[i]; CalculatePatchLOD(root.normal, root.step, root.depth, root.min, root.max); } //removes nodes that have not had their flags refreshed by the LOD pass RemoveStaleNodes(); int patchCountPerFrame = 10; for (int i = 0; i < patchCountPerFrame; i++) { PlanetNode finishedNode; if (PlanetBuilder.GetBuiltNodes(Name, out finishedNode)) { AddPatch(finishedNode); } } }