public void Init(IMy2DClipmapManager parent, int x, int y, int lod, ref BoundingBox2D bounds) { m_manager = (MyPlanetEnvironmentComponent)parent; var bounds3D = new BoundingBoxD(new Vector3D(bounds.Min, 0), new Vector3D(bounds.Max, 0)); Lod = lod; Face = m_manager.ActiveFace; var matrix = m_manager.ActiveClipmap.WorldMatrix; bounds3D = bounds3D.Transform(matrix); Coords = new Vector2I(x, y); Id = MyPlanetSectorId.MakeSectorId(x, y, m_manager.ActiveFace, lod); m_manager.RegisterProxy(this); MyEnvironmentSectorParameters sectorParams; matrix.Translation = Vector3D.Zero; sectorParams.SurfaceBasisX = Vector3.Transform(new Vector3(bounds.Width / 2, 0, 0), matrix); sectorParams.SurfaceBasisY = Vector3.Transform(new Vector3(0, bounds.Height / 2, 0), matrix); sectorParams.Center = bounds3D.Center; if (lod > m_manager.MaxLod) { return; } if (!m_manager.TryGetSector(Id, out EnvironmentSector)) { sectorParams.SectorId = Id; sectorParams.EntityId = MyPlanetSectorId.MakeSectorId(x, y, m_manager.ActiveFace, lod); sectorParams.Bounds = m_manager.GetBoundingShape(ref sectorParams.Center, ref sectorParams.SurfaceBasisX, ref sectorParams.SurfaceBasisY);; sectorParams.Environment = m_manager.EnvironmentDefinition; sectorParams.DataRange = new BoundingBox2I(Coords << lod, ((Coords + 1) << lod) - 1); sectorParams.Provider = m_manager.Providers[m_manager.ActiveFace]; EnvironmentSector = m_manager.EnvironmentDefinition.CreateSector(); EnvironmentSector.Init(m_manager, ref sectorParams); m_manager.Planet.AddChildEntity((MyEntity)EnvironmentSector); } m_manager.EnqueueOperation(this, lod); LodSet = lod; EnvironmentSector.OnLodCommit += sector_OnMyLodCommit; }
public void Init(IMy2DClipmapManager parent, int x, int y, int lod, ref BoundingBox2D bounds) { m_manager = (MyPlanetEnvironmentComponent)parent; var bounds3D = new BoundingBoxD(new Vector3D(bounds.Min, 0), new Vector3D(bounds.Max, 0)); Lod = lod; Face = m_manager.ActiveFace; var matrix = m_manager.ActiveClipmap.WorldMatrix; bounds3D = bounds3D.Transform(matrix); Coords = new Vector2I(x, y); Id = MyPlanetSectorId.MakeSectorId(x, y, m_manager.ActiveFace, lod); m_manager.RegisterProxy(this); MyEnvironmentSectorParameters sectorParams; matrix.Translation = Vector3D.Zero; sectorParams.SurfaceBasisX = Vector3.Transform(new Vector3(bounds.Width / 2, 0, 0), matrix); sectorParams.SurfaceBasisY = Vector3.Transform(new Vector3(0, bounds.Height / 2, 0), matrix); sectorParams.Center = bounds3D.Center; if (lod > m_manager.MaxLod) return; if (!m_manager.TryGetSector(Id, out EnvironmentSector)) { sectorParams.SectorId = Id; sectorParams.EntityId = MyPlanetSectorId.MakeSectorId(x, y, m_manager.ActiveFace, lod); sectorParams.Bounds = m_manager.GetBoundingShape(ref sectorParams.Center, ref sectorParams.SurfaceBasisX, ref sectorParams.SurfaceBasisY); ; sectorParams.Environment = m_manager.EnvironmentDefinition; sectorParams.DataRange = new BoundingBox2I(Coords << lod, ((Coords + 1) << lod) - 1); sectorParams.Provider = m_manager.Providers[m_manager.ActiveFace]; EnvironmentSector = m_manager.EnvironmentDefinition.CreateSector(); EnvironmentSector.Init(m_manager, ref sectorParams); m_manager.Planet.AddChildEntity((MyEntity)EnvironmentSector); } m_manager.EnqueueOperation(this, lod); LodSet = lod; EnvironmentSector.OnLodCommit += sector_OnMyLodCommit; }
public unsafe void Init(IMy2DClipmapManager manager, ref MatrixD worldMatrix, double sectorSize, double faceSize) { m_manager = manager; WorldMatrix = worldMatrix; InverseWorldMatrix = Matrix.Invert(worldMatrix); m_size = faceSize; m_splits = Math.Max(MathHelper.Log2Floor((int)(faceSize / sectorSize)), 1); m_lodSizes = new double[m_splits + 1]; for (int i = 0; i <= m_splits; i++) { m_lodSizes[m_splits - i] = faceSize / (1 << (i + 1)); } m_keepLodSizes = new double[m_splits + 1]; for (int i = 0; i <= m_splits; i++) { m_keepLodSizes[i] = 1.5 * m_lodSizes[i]; } m_queryBounds = new BoundingBox2D[m_splits + 1]; m_keepBounds = new BoundingBox2D[m_splits + 1]; PrepareAllocator(); m_root = AllocNode(); fixed(Node *nodes = m_nodes) { Node *root = nodes + m_root; root->Lod = m_splits; } BoundingBox2D rootBounds = new BoundingBox2D(new Vector2D(-faceSize / 2), new Vector2D(faceSize / 2)); m_nodeHandlers[m_root] = new THandler(); m_nodeHandlers[m_root].Init(m_manager, 0, 0, m_splits, ref rootBounds); }
public void Init(IMy2DClipmapManager parent, int x, int y, int lod, ref BoundingBox2D bounds) { m_parent = (SectorTreeComponent)parent; Bounds = new BoundingBoxD(new Vector3D(bounds.Min, 0), new Vector3D(bounds.Max, 50)); Lod = lod; var matrix = m_parent.m_tree[m_parent.m_activeClipmap].WorldMatrix; Bounds = Bounds.TransformFast(matrix); Coords = new Vector2I(x, y); m_parent.m_handlers.Add(this); var center = Bounds.Center; // Sector Frustum Vector3D[] v = new Vector3D[8]; v[0] = Vector3D.Transform(new Vector3D(bounds.Min.X, bounds.Min.Y, 0), matrix); v[1] = Vector3D.Transform(new Vector3D(bounds.Max.X, bounds.Min.Y, 0), matrix); v[2] = Vector3D.Transform(new Vector3D(bounds.Min.X, bounds.Max.Y, 0), matrix); v[3] = Vector3D.Transform(new Vector3D(bounds.Max.X, bounds.Max.Y, 0), matrix); for (int i = 0; i < 4; ++i) { //v[i] -= WorldMatrix.Translation; v[i].Normalize(); v[i + 4] = v[i] * m_parent.Radius; v[i] *= m_parent.Radius + 50; //v[i] += WorldMatrix.Translation; //v[i + 4] += WorldMatrix.Translation; } FrustumBounds = v; }