コード例 #1
0
        private void ProcessBatch()
        {
            foreach (var modifyModel in m_batchedModifyItems)
            {
                ModifyItemModel(modifyModel.LocalId, modifyModel.LocalModelId, false, false);
            }

            if (Physics != null)
            {
                Physics.ContactPointCallback -= Physics_ContactPointCallback;
                Physics.Close();
                Physics = null;
            }

            BoundingBoxD aabbWorld = BoundingBoxD.CreateInvalid();
            Dictionary <MyStringHash, HkShape> subtypeIdToShape = new Dictionary <MyStringHash, HkShape>(MyStringHash.Comparer);
            HkStaticCompoundShape sectorRootShape = new HkStaticCompoundShape(HkReferencePolicy.None);

            m_physicsShapeInstanceIdToLocalId.Clear();
            m_localIdToPhysicsShapeInstanceId.Clear();

            foreach (var item in m_itemsData)
            {
                if (!item.Value.Enabled)
                {
                    continue;
                }

                int     physicsShapeInstanceId;
                var     data    = item.Value;
                int     modelId = data.ModelId;
                MyModel model   = MyModels.GetModelOnlyData(MyModel.GetById(modelId));
                var     matrix  = data.Transform.TransformMatrix;

                aabbWorld.Include(model.BoundingBox.Transform(matrix));

                if (AddPhysicsShape(data.SubtypeId, model, ref matrix, sectorRootShape, subtypeIdToShape, out physicsShapeInstanceId))
                {
                    m_physicsShapeInstanceIdToLocalId[physicsShapeInstanceId] = item.Key;
                    m_localIdToPhysicsShapeInstanceId[item.Key] = physicsShapeInstanceId;
                }
            }

            foreach (var item in m_batchedAddItems)
            {
                var matrix     = MatrixD.CreateWorld(item.Position, Vector3D.Forward, Vector3D.Up);
                var definition = m_definition.GetItemDefinition(item.SubtypeId);
                AddItem(definition, ref matrix, ref aabbWorld, sectorRootShape, subtypeIdToShape, item.LocalModelId);
            }

            PrepareItemsPhysics(sectorRootShape, ref aabbWorld);
            PrepareItemsGraphics();

            foreach (var pair in subtypeIdToShape)
            {
                pair.Value.RemoveReference();
            }

            subtypeIdToShape.Clear();
        }
コード例 #2
0
        private bool IsPlayerNearby()
        {
            BoundingBoxD playerBox = BoundingBoxD.CreateInvalid();

            Sandbox.Game.Entities.MyEntities.GetInflatedPlayerBoundingBox(ref playerBox, 2000f);
            return(playerBox.Contains(base.ShipController.PositionComp.GetPosition()) == ContainmentType.Contains);
        }
コード例 #3
0
        protected void UpdateRenderObject()
        {
            m_actualWorldAABB = BoundingBoxD.CreateInvalid();

            if (AnimationController.CharacterBones != null)
            {
                for (int i = 1; i < Model.Bones.Length; i++)
                {
                    Vector3D p1 = Vector3D.Transform(AnimationController.CharacterBones[i].Parent.AbsoluteTransform.Translation, WorldMatrix);
                    Vector3D p2 = Vector3D.Transform(AnimationController.CharacterBones[i].AbsoluteTransform.Translation, WorldMatrix);

                    m_actualWorldAABB.Include(ref p1);
                    m_actualWorldAABB.Include(ref p2);
                }
            }

            ContainmentType containmentType;

            m_aabb.Contains(ref m_actualWorldAABB, out containmentType);
            if (containmentType != ContainmentType.Contains)
            {
                m_actualWorldAABB.Inflate(0.5f);
                MatrixD worldMatrix = WorldMatrix;
                VRageRender.MyRenderProxy.UpdateRenderObject(Render.RenderObjectIDs[0], ref worldMatrix, false, m_actualWorldAABB);
                m_aabb = m_actualWorldAABB;
            }
        }
コード例 #4
0
        private static void CalculateAABB(ref BoundingBoxD bbox, out float scaleZ, out float scaleXY, Vector3D position, Vector3 direction, Vector3 up, float reflectorConeMaxAngleCos, float reflectorRange)
        {
            float cosAngle = 1 - reflectorConeMaxAngleCos;

            scaleZ = reflectorRange;
            // Calculate cone side (hypotenuse of triangle)
            float side = reflectorRange / cosAngle;

            // Calculate cone bottom scale (Pythagoras theorem)
            scaleXY = (float)System.Math.Sqrt(side * side - reflectorRange * reflectorRange) * 2;

            Vector3 coneSideDirection = Vector3.Cross(up, direction);

            coneSideDirection = MyUtils.Normalize(coneSideDirection);

            Vector3D coneCenter = position + direction * scaleZ;
            Vector3D pt1        = coneCenter + coneSideDirection * scaleXY / 2 + up * scaleXY / 2;
            Vector3D pt2        = coneCenter - coneSideDirection * scaleXY / 2 + up * scaleXY / 2;
            Vector3D pt3        = coneCenter + coneSideDirection * scaleXY / 2 - up * scaleXY / 2;
            Vector3D pt4        = coneCenter - coneSideDirection * scaleXY / 2 - up * scaleXY / 2;

            bbox = BoundingBoxD.CreateInvalid();
            bbox = bbox.Include(ref position);
            //bbox = bbox.Include(ref coneCenter);
            bbox = bbox.Include(ref pt1);
            bbox = bbox.Include(ref pt2);
            bbox = bbox.Include(ref pt3);
            bbox = bbox.Include(ref pt4);
        }
コード例 #5
0
        public ConstructionCopy(ProceduralRoom room, RoomRemapper remapper = null)
        {
            Logger = room.Owner.Logger.Root().CreateProxy(GetType().Name);
            var i = room.Part.PrimaryGrid;
            var o = new MyObjectBuilder_CubeGrid
            {
                GridSizeEnum           = i.GridSizeEnum,
                IsStatic               = true,
                DampenersEnabled       = true,
                Handbrake              = true,
                DisplayName            = room.Owner.Seed.Name,
                DestructibleBlocks     = true,
                IsRespawnGrid          = false,
                Editable               = true,
                PersistentFlags        = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.CastShadows,
                PositionAndOrientation = new MyPositionAndOrientation(GridCreator.WorldTransformFor(room.Owner))
            };

            BoundingBox = BoundingBoxD.CreateInvalid();

            Construction = room.Owner;
            PrimaryGrid  = o;
            AuxGrids     = new List <MyObjectBuilder_CubeGrid>();
            m_remapper   = remapper ?? new RoomRemapper(Logger.Root());

            var iwatch = new Stopwatch();

            m_remapper.Remap(room, this);
            Logger.Debug("Added room {3} of {0} blocks with {1} aux grids in {2}", room.Part.PrimaryGrid.CubeBlocks.Count, room.Part.Prefab.CubeGrids.Length - 1, iwatch.Elapsed, room.Part.Name);
        }
コード例 #6
0
        protected static void DrawRemovingCubes(Vector3I?startRemove, Vector3I?continueBuild, MySlimBlock removeBlock)
        {
            if (startRemove == null || continueBuild == null || removeBlock == null)
            {
                return;
            }

            Color white = Color.White;

            Vector3I stepDelta;
            Vector3I counter;
            int      stepCount;

            ComputeSteps(startRemove.Value, continueBuild.Value, Vector3I.One, out stepDelta, out counter, out stepCount);

            var          matrix = removeBlock.CubeGrid.WorldMatrix;
            BoundingBoxD aabb   = BoundingBoxD.CreateInvalid();

            aabb.Include((startRemove.Value * removeBlock.CubeGrid.GridSize));
            aabb.Include((continueBuild.Value * removeBlock.CubeGrid.GridSize));
            aabb.Min -= new Vector3(removeBlock.CubeGrid.GridSize / 2.0f + 0.02f);
            aabb.Max += new Vector3(removeBlock.CubeGrid.GridSize / 2.0f + 0.02f);

            MySimpleObjectDraw.DrawTransparentBox(ref matrix, ref aabb, ref white, MySimpleObjectRasterizer.Wireframe, counter, 0.04f, null, "GizmoDrawLineRed", true);
            Color faceColor = new Color(Color.Red * 0.2f, 0.3f);

            MySimpleObjectDraw.DrawTransparentBox(ref matrix, ref aabb, ref faceColor, MySimpleObjectRasterizer.Solid, 0, 0.04f, "Square", null, true);
        }
コード例 #7
0
 public MyRenderBatch(uint id, string debugName, MatrixD worldMatrix, RenderFlags renderFlags, List <MyRenderBatchPart> batchParts)
     : base(id, debugName, worldMatrix, renderFlags)
 {
     m_localAABB = BoundingBoxD.CreateInvalid();
     m_batchParts.Clear();
     m_batchParts.AddList(batchParts);
 }
コード例 #8
0
        private static void SendGlobalOutputMessages()
        {
            ProfilerShort.Begin("SendGlobalOutputMessages");
            ProfilerShort.Begin("Root");
            foreach (var groupRootComponent in MyComponentFactory <MyGroupRootComponent> .GetAll())
            {
                if (true)
                {
                    BoundingBoxD bb = BoundingBoxD.CreateInvalid();

                    foreach (var child in groupRootComponent.m_children)
                    {
                        if (child.IsVisible)
                        {
                            bb.Include(child.Aabb);
                        }
                    }

                    if (MyRender11.Environment.ViewFrustumClippedD.Contains(bb) != VRageMath.ContainmentType.Disjoint)
                    {
                        MyRenderProxy.VisibleObjectsWrite.Add(groupRootComponent.Owner.ID);
                    }
                }
            }

            ProfilerShort.BeginNextBlock("Clipmap");
            foreach (var id in MyClipmapFactory.ClipmapByID.Keys)
            {
                MyRenderProxy.VisibleObjectsWrite.Add(id);
            }
            ProfilerShort.End();
            ProfilerShort.End();
        }
コード例 #9
0
        protected static bool TestBlockPlacementArea(MySlimBlock block, ref MyGridPlacementSettings settings, bool dynamicMode)
        {
            var localAabb = BoundingBoxD.CreateInvalid();

            localAabb.Include(block.Min * block.CubeGrid.GridSize - block.CubeGrid.GridSize / 2);
            localAabb.Include(block.Max * block.CubeGrid.GridSize + block.CubeGrid.GridSize / 2);
            return(MyCubeGrid.TestBlockPlacementArea(block.BlockDefinition, block.Orientation, block.CubeGrid.WorldMatrix, ref settings, localAabb, dynamicMode, ignoredEntity: block.CubeGrid));
        }
コード例 #10
0
        protected static bool TestVoxelPlacement(MySlimBlock block, ref MyGridPlacementSettings settings, bool dynamicMode)
        {
            var localAabb = BoundingBoxD.CreateInvalid();

            localAabb.Include(block.Min * block.CubeGrid.GridSize - block.CubeGrid.GridSize / 2);
            localAabb.Include(block.Max * block.CubeGrid.GridSize + block.CubeGrid.GridSize / 2);
            return(MyCubeGrid.TestVoxelPlacement(block.BlockDefinition, settings, dynamicMode, block.CubeGrid.WorldMatrix, localAabb));
        }
コード例 #11
0
            internal bool OnAddedToScene(MyClipmapCellProxy cellProxy)
            {
                if (!IsUsed())
                {
                    return(false);
                }

                bool         lodAabbChanged = false;
                int          rootProxy      = m_boundingBoxes.GetRoot();
                BoundingBoxD lodAabbBefore  = BoundingBoxD.CreateInvalid();

                if (rootProxy != -1)
                {
                    lodAabbBefore = m_boundingBoxes.GetAabb(rootProxy);
                }

                BoundingBoxD cellAabb = (BoundingBoxD)cellProxy.LocalAabb;

                m_cellProxyToAabbProxy.Add(cellProxy, m_boundingBoxes.AddProxy(ref cellAabb, null, 0));

                if (rootProxy != -1)
                {
                    BoundingBoxD lodAabbAfter = m_boundingBoxes.GetAabb(rootProxy);
                    lodAabbChanged = lodAabbBefore.Equals(lodAabbAfter);
                }

                if (lodAabbChanged)
                {
                    InvalidateAllMergedMeshesInLod();
                }

                Vector3D translation = cellProxy.Translation;
                int      divideIndex = GetDivideIndex(ref translation);

                m_trackedActors[divideIndex].Add(cellProxy.Actor);

                MyMergedLodMeshId mergedLodMeshId = MyMeshes.GetMergedLodMesh(m_mergedLodMeshProxies[divideIndex].MeshId, 0);
                LodMeshId         lodMeshToMerge  = MyMeshes.GetLodMesh(cellProxy.MeshId, 0);
                bool mergedMesh = mergedLodMeshId.MergeLodMesh(lodMeshToMerge);

                if (mergedMesh)
                {
                    InvalidateAllMergedMeshesInLod();
                }

                TryCancelMergeJob(divideIndex, MeshId.NULL);
                bool startedMerge = TryStartMergeJob(divideIndex, 1000);

                bool shouldMarkDirty = !mergedMesh && !startedMerge;

                if (shouldMarkDirty)
                {
                    m_dirtyProxyIndices.Add(divideIndex);
                }

                return(shouldMarkDirty);
            }
コード例 #12
0
        private static bool IntersectsVoxelSurface(OrientedBoundingBoxD box)
        {
            var data = VoxelData;

            using (PoolManager.Get(out List <MyEntity> entities))
            {
                MyGamePruningStructure.GetTopmostEntitiesInBox(box.GetAABB(), entities, MyEntityQueryType.Static);
                foreach (var ent in entities)
                {
                    if (ent is MyVoxelBase voxel && !(ent is MyVoxelPhysics))
                    {
                        var invWorld      = voxel.PositionComp.WorldMatrixInvScaled;
                        var storageBounds = BoundingBoxD.CreateInvalid();
                        var voxelOffset   = (voxel.Size >> 1) + voxel.StorageMin;
                        var storageObb    = box;
                        storageObb.Transform(invWorld);
                        storageObb.HalfExtent /= voxel.VoxelSize;
                        storageObb.Center      = storageObb.Center / voxel.VoxelSize + voxelOffset;
                        storageBounds.Include(storageObb.GetAABB());

                        var storageMin = Vector3I.Max(Vector3I.Floor(storageBounds.Min), voxel.StorageMin);
                        var storageMax = Vector3I.Min(Vector3I.Ceiling(storageBounds.Max), voxel.StorageMax);
                        var localBox   = new BoundingBoxI(storageMin, storageMax);
                        localBox.Inflate(1);
                        var floatBox = new BoundingBox(localBox);
                        if (voxel.IntersectStorage(ref floatBox) == ContainmentType.Disjoint)
                        {
                            continue;
                        }
                        data.Resize(storageMin, storageMax);
                        voxel.Storage.ReadRange(data, MyStorageDataTypeFlags.Content, 0, storageMin, storageMax);
                        foreach (var pt in new BoundingBoxI(Vector3I.Zero, storageMax - storageMin).EnumeratePoints())
                        {
                            var voxelBox    = new BoundingBoxD(storageMin + pt, storageMin + pt + 1);
                            var containment = storageObb.Contains(ref voxelBox);
                            if (containment == ContainmentType.Disjoint)
                            {
                                continue;
                            }
                            var tmpPt   = pt;
                            var index   = data.ComputeLinear(ref tmpPt);
                            var content = data.Content(index);
                            if (containment == ContainmentType.Intersects && content >= 127)
                            {
                                return(true);
                            }
                            if (containment == ContainmentType.Contains && content > 0)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
コード例 #13
0
        private void CalculateShape()
        {
            if (!Definition.RequiredSupport.HasValue)
            {
                return;
            }
            var shape = Definition.RequiredSupport.Value;
            var edge  = _bendy.Edges.FirstOrDefault();
            var curve = edge?.Curve;

            if (curve == null)
            {
                return;
            }
            _shapeDirty = false;
            _localBox   = BoundingBoxD.CreateInvalid();
            for (var i = 0; i < shape.Segments; i++)
            {
                Matrix matrix;
                {
                    var t   = (i + 0.5f) / shape.Segments;
                    var pos = (Vector3)Vector3D.Transform(curve.Sample(t), Entity.PositionComp.WorldMatrixNormalizedInv);
                    var up  = Vector3.TransformNormal(Vector3.Lerp((Vector3)edge.From.Up, (Vector3)edge.To.Up, t),
                                                      Entity.PositionComp.WorldMatrixNormalizedInv);
                    var tan = Vector3.TransformNormal((Vector3)curve.SampleDerivative(t), Entity.PositionComp.WorldMatrixNormalizedInv);
                    tan.Normalize();
                    up.Normalize();

                    matrix = Matrix.CreateWorld(Vector3.Zero, tan, up);
                }

                var box = BoundingBox.CreateInvalid();
                var mi  = Entity.PositionComp.WorldMatrixNormalizedInv * (MatrixD)Matrix.Invert(ref matrix);

                for (var j = 0; j <= 1; j++)
                {
                    var t    = (i + j) / (float)shape.Segments;
                    var pos  = curve.Sample(t);
                    var up   = Vector3.Lerp((Vector3)edge.From.Up, (Vector3)edge.To.Up, t);
                    var tan  = (Vector3)curve.SampleDerivative(t);
                    var norm = Vector3.Cross(up, tan);
                    norm.Normalize();

                    var nl = (Vector3)Vector3D.TransformNormal(norm, ref mi);
                    var ul = (Vector3)Vector3D.TransformNormal(up, ref mi);
                    var pl = (Vector3)Vector3D.Transform(pos, ref mi);

                    box.Include(pl + nl * shape.HalfWidth + ul * shape.VerticalOffset);
                    box.Include(pl - nl * shape.HalfWidth + ul * shape.VerticalOffset);
                }

                var obb = new OrientedBoundingBox(Vector3.Transform(box.Center, matrix), box.HalfExtents, Quaternion.CreateFromRotationMatrix(matrix));
                _localBox = _localBox.Include(obb.GetAABB());
            }
        }
コード例 #14
0
        internal static BoundingBoxD MakeAabbFromSpotlightCone(ref MySpotlightInfo spotlight, Vector3D position)
        {
            float ratio = (float)Math.Sqrt(1 - spotlight.ApertureCos * spotlight.ApertureCos) / spotlight.ApertureCos;
            float h     = ratio * spotlight.Range;
            var   bb    = BoundingBoxD.CreateInvalid();

            bb.Include(new Vector3D(-h, -h, 0));
            bb.Include(new Vector3D(h, h, -spotlight.Range));

            return(bb.Transform(MatrixD.CreateLookAtInverse(position, position + spotlight.Direction, spotlight.Up)));
        }
コード例 #15
0
        public override void UpdateWorldAABB()
        {
            m_aabb = BoundingBoxD.CreateInvalid();
            var pointA = (Vector3D)m_pointA;
            var pointB = (Vector3D)m_pointB;

            m_aabb.Include(ref pointA);
            m_aabb.Include(ref pointB);
            m_aabb.Inflate(0.25);
            m_aabb.Translate(m_worldPosition);
            base.UpdateWorldAABB();
        }
コード例 #16
0
        void UpdateBoundingFrustum()
        {
            //  Update frustum
            BoundingFrustum.Matrix = ViewProjectionMatrix;

            //  Update bounding box
            BoundingBox = BoundingBoxD.CreateInvalid();
            BoundingBox.Include(ref BoundingFrustum);

            //  Update bounding sphere
            BoundingSphere = MyUtils.GetBoundingSphereFromBoundingBox(ref BoundingBox);
        }
コード例 #17
0
        internal void UpdateBeforeDraw()
        {
            if (m_dirtyProxy)
            {
                RebuildProxies();
            }

            foreach (var val in m_materialGroups.Values)
            {
                var index = val.m_index;
                val.UpdateProxyVerticesNum(ref m_proxy.Proxies[index]);
            }

            if (m_dirtyPosition)
            {
                foreach (var val in m_materialGroups.Values)
                {
                    val.UpdateAll();
                }

                m_dirtyPosition = false;
            }

            if (m_dirtyTree)
            {
                var bb = BoundingBoxD.CreateInvalid();

                foreach (var child in m_children)
                {
                    if (child.m_visible && child.GetRenderable() != null && !child.GetRenderable().IsRendered)
                    {
                        bb.Include(child.Aabb);
                    }
                }

                m_owner.Aabb = bb;

                if (m_materialGroups.Count > 0)
                {
                    if (m_btreeProxy == -1)
                    {
                        m_btreeProxy = MyScene.GroupsDBVH.AddProxy(ref m_owner.Aabb, m_proxy, 0);
                    }
                    else
                    {
                        MyScene.GroupsDBVH.MoveProxy(m_btreeProxy, ref m_owner.Aabb, Vector3.Zero);
                    }
                }

                m_dirtyTree = false;
            }
        }
コード例 #18
0
        internal void Construct()
        {
            m_components.Clear();

            m_visible          = true;
            m_renderProxyDirty = true;

            m_ID                = new MyIDTracker <MyActor>();
            m_localAabb         = null;
            m_relativeTransform = null;

            Aabb = BoundingBoxD.CreateInvalid();
        }
コード例 #19
0
ファイル: MyActor.cs プロジェクト: parhelia512/SpaceEngineers
        internal void Construct()
        {
            m_components.Clear();

            m_visible = true;

            MyUtils.Init(ref m_ID);
            m_ID.Clear();
            LocalAabb         = null;
            RelativeTransform = null;

            Aabb = BoundingBoxD.CreateInvalid();
        }
コード例 #20
0
        public bool GetIslandAABBForEntity(IMyEntity entity, out BoundingBoxD aabb)
        {
            int islandIndex;

            aabb = BoundingBoxD.CreateInvalid();
            if (m_rootEntityIslandIndex.TryGetValue(entity, out islandIndex))
            {
                aabb = m_rootIslands[islandIndex].AABB;
                return(true);
            }

            return(false);
        }
コード例 #21
0
        public void Update()
        {
            m_actualWorldAABB = BoundingBoxD.CreateInvalid();

            ContainmentType containmentType;

            m_aabb.Contains(ref m_actualWorldAABB, out containmentType);
            if (containmentType != ContainmentType.Contains)
            {
                SetDirty();
                MyRender.UpdateRenderObject(this, false);
            }
        }
コード例 #22
0
        private static void VoxelReading()
        {
            var camera = MySector.MainCamera;

            if (camera == null)
            {
                return;
            }

            var         offset         = 0; // MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF;
            var         targetPosition = camera.Position + (Vector3D)camera.ForwardVector * 4.5f - offset;
            MyVoxelBase targetVoxelMap = null;

            foreach (var voxelMap in MySession.Static.VoxelMaps.Instances)
            {
                if (voxelMap.PositionComp.WorldAABB.Contains(targetPosition) == ContainmentType.Contains)
                {
                    targetVoxelMap = voxelMap;
                    break;
                }
            }
            if (targetVoxelMap == null)
            {
                return;
            }

            var      targetMin = targetPosition - Vector3.One * MyVoxelConstants.VOXEL_SIZE_IN_METRES;
            var      targetMax = targetPosition + Vector3.One * MyVoxelConstants.VOXEL_SIZE_IN_METRES;
            Vector3I minVoxel, maxVoxel;

            MyVoxelCoordSystems.WorldPositionToVoxelCoord(targetVoxelMap.PositionLeftBottomCorner, ref targetMin, out minVoxel);
            MyVoxelCoordSystems.WorldPositionToVoxelCoord(targetVoxelMap.PositionLeftBottomCorner, ref targetMax, out maxVoxel);
            MyVoxelCoordSystems.VoxelCoordToWorldPosition(targetVoxelMap.PositionLeftBottomCorner, ref minVoxel, out targetMin);
            MyVoxelCoordSystems.VoxelCoordToWorldPosition(targetVoxelMap.PositionLeftBottomCorner, ref maxVoxel, out targetMax);

            {
                BoundingBoxD bbox = BoundingBoxD.CreateInvalid();
                bbox.Include(targetMin);
                bbox.Include(targetMax);
                VRageRender.MyRenderProxy.DebugDrawAABB(bbox, Vector3.One, 1f, 1f, true);
            }

            if (MyInput.Static.IsNewLeftMousePressed())
            {
                var cache = new MyStorageData();
                cache.Resize(minVoxel, maxVoxel);
                targetVoxelMap.Storage.ReadRange(cache, MyStorageDataTypeFlags.Content, 0, ref minVoxel, ref maxVoxel);
                targetVoxelMap.Storage.WriteRange(cache, MyStorageDataTypeFlags.Content, ref minVoxel, ref maxVoxel);
                Debug.Assert(true);
            }
        }
コード例 #23
0
        internal static VRageMath.BoundingBoxD GetBoundingBox(ref Vector3D worldPointA, ref Vector3D worldPointB)
        {
            var worldPosition = (worldPointA + worldPointB) * 0.5f;
            var pointA        = worldPointA - worldPosition;
            var pointB        = worldPointB - worldPosition;

            var aabb = BoundingBoxD.CreateInvalid();

            aabb.Include(ref pointA);
            aabb.Include(ref pointB);
            aabb.Inflate(0.25);
            //aabb.Translate(worldPosition);
            return(aabb);
        }
コード例 #24
0
        static void UpdateBoundingFrustum()
        {
            //  Update frustum
            m_boundingFrustum.Matrix = ViewProjectionMatrix;

            //  Update bounding box
            BoundingBox = BoundingBoxD.CreateInvalid();
            //todo
            //BoundingBox = BoundingBoxHelper.AddFrustum(ref BoundingFrustum, ref BoundingBox);

            //  Update bounding sphere
            //todo
            //BoundingSphere = MyUtils.GetBoundingSphereFromBoundingBox(ref BoundingBox);
        }
コード例 #25
0
        public MeshGradeShape(EdgeBlit edge, ICurve curve, TriangleUtil.Triangle[] tri)
        {
            var box = BoundingBoxD.CreateInvalid();

            foreach (var k in tri)
            {
                box.Include(k.Origin);
                box.Include(k.Origin + k.Edge1);
                box.Include(k.Origin + k.Edge2);
            }

            Box    = box.Inflate(0.5f);
            _tris  = tri;
            _edge  = edge;
            _curve = curve;
        }
コード例 #26
0
        public override void UpdateWorldAABB()
        {
            CulledObjects.GetAll(m_list, true);

            m_localAABB = BoundingBoxD.CreateInvalid();


            foreach (var element in m_list)
            {
                m_localAABB = m_localAABB.Include(element.WorldAABB);
            }

            m_aabb = m_localAABB.Transform(ref m_worldMatrix);

            base.UpdateWorldAABB();
        }
コード例 #27
0
        public void Init(IMyEnvironmentOwner owner, ref MyEnvironmentSectorParameters parameters)
        {
            // Copy parameters in
            SectorCenter = parameters.Center;

            Bounds = parameters.Bounds;

            m_dataRange = parameters.DataRange;

            m_environment = (MyProceduralEnvironmentDefinition)parameters.Environment;

            EnvironmentDefinition = parameters.Environment;

            m_owner = owner;

            m_provider = parameters.Provider;

            // Compute appropriate render origin.
            Vector3D center = parameters.Center;

            owner.ProjectPointToSurface(ref center);

            if (!Engine.Platform.Game.IsDedicated)
            {
                m_render = new MyInstancedRenderSector(string.Format("{0}:Sector({1:X})", owner, parameters.SectorId), MatrixD.CreateTranslation(center));
            }

            SectorId = parameters.SectorId;

            BoundingBoxD worldBounds = BoundingBoxD.CreateInvalid();

            for (int i = 0; i < 8; ++i)
            {
                worldBounds.Include(Bounds[i]);
            }

            // Entity stuff
            PositionComp.SetPosition(parameters.Center);
            PositionComp.WorldAABB = worldBounds;

            // Add missing stuff
            AddDebugRenderComponent(new MyDebugRenderComponentEnvironmentSector(this));
            GameLogic = new MyNullGameLogicComponent();
            Save      = false;

            IsClosed = false;
        }
コード例 #28
0
        public void Start(MyParticleEffect effect)
        {
            System.Diagnostics.Debug.Assert(m_effect == null);
            System.Diagnostics.Debug.Assert(m_particles.Count == 0);
            System.Diagnostics.Debug.Assert(Birth == null);

            m_effect = effect;
            m_name   = "ParticleGeneration";

            m_emitter.Start();

            m_lastEffectPosition = null;
            IsInherited          = false;
            m_birthRate          = 0.0f;
            m_particlesToCreate  = 0.0f;
            m_AABB = BoundingBoxD.CreateInvalid();
        }
コード例 #29
0
        private BoundingBoxD GetAggregateBBox()
        {
            if (m_grid.MarkedForClose)
            {
                return(BoundingBoxD.CreateInvalid());
            }
            BoundingBoxD bbox = m_grid.PositionComp.WorldAABB;

            foreach (var grid in m_connectedGrids)
            {
                if (grid.PositionComp != null)
                {
                    bbox.Include(grid.PositionComp.WorldAABB);
                }
            }
            return(bbox);
        }
コード例 #30
0
        private void ExecuteUpdate(long dt)
        {
            _updateScheduled = false;
            if (!_powerObserver.IsPowered)
            {
                return;
            }
            if (Definition.RequiredStates.Count > 0 && _state != null && !Definition.RequiredStates.Contains(_state.CurrentState))
            {
                return;
            }
            using (PoolManager.Get(out List <OrientedBoundingBoxD> boxes))
                using (PoolManager.Get(out List <MyVoxelBase> voxels))
                {
                    GatherWorldVolumes(boxes);
                    if (boxes.Count == 0)
                    {
                        return;
                    }
                    var worldBounds = BoundingBoxD.CreateInvalid();
                    foreach (var box in boxes)
                    {
                        worldBounds.Include(box.GetAABB());
                    }
                    GatherVoxels(worldBounds, voxels);
                    if (voxels.Count == 0)
                    {
                        return;
                    }
                    var availableForDeposit = ComputeDepositAvailability();
                    if (availableForDeposit == 0)
                    {
                        return;
                    }

                    var used = PerformVoxelOp(voxels, boxes, Definition.PlacementDefinition.Material.Index,
                                              availableForDeposit, _miningBuffer, Definition.RemoveFarmingItems);
                    if (used <= 0)
                    {
                        return;
                    }
                    _eventBus?.Invoke(EventDidWork, true);
                    UseDepositMaterials(used);
                    GiftMiningMaterials();
                }
        }