private void UpdateClipmaps() { // This avoids the clipmap from overruning and going bad if (m_sectorsToWorkParallel.Count > 0) { return; } Vector3D camera = MySector.MainCamera.Position - PlanetTranslation; double distance = camera.Length(); // Update only if relevant if (distance > Planet.AverageRadius + m_clipmaps[0].FaceHalf && Proxies.Count == 0) { return; } distance = Math.Abs(Planet.Provider.Shape.GetDistanceToSurfaceCacheless(camera)); // Get cubemap coordinates Vector2D texcoords; int direction; MyPlanetCubemapHelper.ProjectToCube(ref camera, out direction, out texcoords); // Update each clipmap accordingly. for (int face = 0; face < 6; ++face) { ActiveFace = face; ActiveClipmap = m_clipmaps[face]; Vector2D localCoords; MyPlanetCubemapHelper.TranslateTexcoordsToFace(ref texcoords, direction, face, out localCoords); Vector3D pos; pos.X = localCoords.X * ActiveClipmap.FaceHalf; pos.Y = localCoords.Y * ActiveClipmap.FaceHalf; if ((face ^ direction) == 1) { pos.Z = distance + Planet.AverageRadius * 2; } else { pos.Z = distance; } //pos.Z = 0; ActiveClipmap.Update(pos); EvaluateOperations(); // Enqueue operations from this clipmap. } ActiveFace = -1; }
public MyEnvironmentSector GetSectorForPosition(Vector3D positionWorld) { var positionLocal = positionWorld - PlanetTranslation; int face; Vector2D texcoords; MyPlanetCubemapHelper.ProjectToCube(ref positionLocal, out face, out texcoords); texcoords *= m_clipmaps[face].FaceHalf; var handler = m_clipmaps[face].GetHandler(texcoords); if (handler != null) { return(handler.EnvironmentSector); } return(null); }