private void UpdateWorldVolume() { this.PositionLeftBottomCorner = (Vector3)(this.WorldMatrix.Translation - this.SizeInMetresHalf); PositionComp.WorldAABB = new BoundingBoxD((Vector3D)PositionLeftBottomCorner, (Vector3D)PositionLeftBottomCorner + (Vector3D)SizeInMetres); PositionComp.WorldVolume = BoundingSphereD.CreateFromBoundingBox(PositionComp.WorldAABB); Render.InvalidateRenderObjects(); }
/// <summary> /// Update volume hr and of all children. /// </summary> /// <param name="volume"></param> private void UpdateAABBHr(ref BoundingBoxD volume) { UpdateWorldVolume(); BoundingBoxD.CreateMerged(ref m_invalidBox, ref m_worldAABB, out m_worldAABBHr); m_worldVolumeHr = BoundingSphereD.CreateFromBoundingBox(m_worldAABBHr); BoundingBoxD.CreateMerged(ref m_worldAABBHr, ref volume, out volume); }
private void FindGridBounds() { BoxAAB = new BoundingBoxD(); BoxAAB.Include(_BiggestGrid.CalculateBoundingBox()); MatrixD BiggestGridMatrix = _BiggestGrid.PositionAndOrientation.Value.GetMatrix(); MatrixD BiggestGridMatrixToLocal = MatrixD.Invert(BiggestGridMatrix); Vector3D[] corners = new Vector3D[8]; foreach (var grid in _grids) { if (grid == _BiggestGrid) { continue; } BoundingBoxD box = grid.CalculateBoundingBox(); MyOrientedBoundingBoxD worldBox = new MyOrientedBoundingBoxD(box, grid.PositionAndOrientation.Value.GetMatrix()); worldBox.Transform(BiggestGridMatrixToLocal); worldBox.GetCorners(corners, 0); foreach (var corner in corners) { BoxAAB.Include(corner); } } BoundingSphereD Sphere = BoundingSphereD.CreateFromBoundingBox(BoxAAB); BoxD = new MyOrientedBoundingBoxD(BoxAAB, BiggestGridMatrix); SphereD = new BoundingSphereD(BoxD.Center, Sphere.Radius); //Test bounds to make sure they are in the right spot /* * * long ID = MySession.Static.Players.TryGetIdentityId(76561198045096439); * Vector3D[] array = new Vector3D[8]; * BoxD.GetCorners(array, 0); * * for (int i = 0; i <= 7; i++) * { * CharacterUtilities.SendGps(array[i], i.ToString(), ID, 10); * } */ //Log.Info($"HangarDebug: {BoxD.ToString()}"); }
private void CreateVertexBuffer(List <MyRenderBatchPart> batchParts, int vbSize) { if (m_vertexBuffer == null || m_vertexBuffer.Description.SizeInBytes < vbSize) { if (m_vertexBuffer != null) { m_vertexBuffer.Dispose(); } m_vertexBuffer = new VertexBuffer(MyRender.GraphicsDevice, vbSize, Usage.WriteOnly, VertexFormat.None, Pool.Default); } // Transform and copy vertices int vbOffset = 0; for (int i = 0; i < batchParts.Count; i++) { var part = batchParts[i]; var model = MyRenderModels.GetModel(part.Model); var matrix = part.ModelMatrix; var modelVb = model.VertexBuffer.Lock(0, model.GetVBSize, LockFlags.ReadOnly); var compoundVb = m_vertexBuffer.Lock(vbOffset, model.GetVBSize, LockFlags.None); for (int v = 0; v < model.GetVerticesCount(); v++) { var vertexPos = v * model.GetVertexStride(); modelVb.Seek(vertexPos, System.IO.SeekOrigin.Begin); var position = modelVb.Read <HalfVector4>(); Vector3D pos = (Vector3D)VF_Packer.UnpackPosition(ref position); var transformedPos = Vector3D.Transform(pos, matrix); m_localAABB = m_localAABB.Include(ref transformedPos); var transformedPos2 = (Vector3)transformedPos; compoundVb.Write <HalfVector4>(VF_Packer.PackPosition(ref transformedPos2)); // Transform and copy position compoundVb.WriteRange(modelVb.PositionPointer, model.GetVertexStride() - (modelVb.Position - vertexPos)); // Copy rest } m_vertexBuffer.Unlock(); model.VertexBuffer.Unlock(); vbOffset += model.GetVBSize; } BoundingSphereD.CreateFromBoundingBox(ref m_localAABB, out m_localVolume); m_localVolumeOffset = m_localVolume.Center; SetDirty(); }
internal void SetInstanceData(MyRenderInstanceBuffer buffer, int instanceStart, int instanceCount, BoundingBoxD localAabb) { m_localAABB = localAabb; m_localVolume = BoundingSphereD.CreateFromBoundingBox(m_localAABB); m_localVolumeOffset = m_localVolume.Center; SetDirty(); m_instanceStart = instanceStart; m_instanceCount = instanceCount; if (m_instanceBuffer != buffer) { m_instanceBuffer = buffer; UnloadVertexDeclaration(); CreateVertexDeclaration(); } }
public override void UpdateWorldAABB() { BoundingSphereD.CreateFromBoundingBox(ref m_aabb, out m_volume); base.UpdateWorldAABB(); }
public override void UpdateWorldAABB() { m_aabb = m_actualWorldAABB; BoundingSphereD.CreateFromBoundingBox(ref m_aabb, out m_volume); Flags &= ~MyElementFlag.EF_AABB_DIRTY; }