Beispiel #1
0
        private void phantom_Leave(HkPhantomCallbackShape shape, HkRigidBody body)
        {
            VRage.ProfilerShort.Begin("MergeLeave");
            var entities = MyPhysicsExtensions.GetAllEntities(body);

            foreach (var entity in entities)
            {
                m_gridList.Remove(entity as MyCubeGrid);
            }
            entities.Clear();
            VRage.ProfilerShort.End();
        }
        void phantom_Leave(HkPhantomCallbackShape sender, HkRigidBody body)
        {
            ProfilerShort.Begin("GravityLeave");
            var entity = MyPhysicsExtensions.GetEntity(body, 0);// jn: TODO we should collect bodies not entities

            lock (m_locker)
            {
                if (entity != null)
                {
                    m_containedEntities.Remove(entity);
                    MyTrace.Send(TraceWindow.EntityId, string.Format("Entity left gravity field, entity: {0}", entity));
                }
            }
            ProfilerShort.End();
        }
        void phantom_Enter(HkPhantomCallbackShape sender, HkRigidBody body)
        {
            ProfilerShort.Begin("GravityEnter");
            var entity = MyPhysicsExtensions.GetEntity(body, 0);// jn: TODO we should collect bodies not entities

            // HACK: disabled gravity for ships (there may be more changes so I won't add Entity.RespectsGravity now)
            lock (m_locker)
            {
                if (entity != null && !(entity is MyCubeGrid))
                {
                    MyTrace.Send(TraceWindow.EntityId, string.Format("Entity entered gravity field, entity: {0}", entity));
                    m_containedEntities.Add(entity);

                    if (entity.Physics.HasRigidBody)
                    {
                        ((MyPhysicsBody)entity.Physics).RigidBody.Activate();
                    }
                }
            }
            ProfilerShort.End();
        }
Beispiel #4
0
        private void phantom_Enter(HkPhantomCallbackShape shape, HkRigidBody body)
        {
            VRage.ProfilerShort.Begin("MergeEnter");
            var entities = MyPhysicsExtensions.GetAllEntities(body);

            foreach (var entity in entities)
            {
                var other = entity as MyCubeGrid;
                if (other == null || other.GridSizeEnum != CubeGrid.GridSizeEnum || other == this.CubeGrid)
                {
                    continue;
                }
                if (other.Physics.RigidBody != body)
                {
                    continue;
                }
                var added = m_gridList.Add(other);
                //Debug.Assert(added, "entity already in list");
            }
            entities.Clear();
            VRage.ProfilerShort.End();
        }
        private MyEntity FindBody(out Vector3D pivot)
        {
            pivot = Vector3D.Zero;
            if (CubeGrid.Physics == null)
            {
                return(null);
            }
            Quaternion orientation;
            Vector3    halfExtents;

            foreach (var m in m_lockPositions)
            {
                GetBoxFromMatrix(m, out halfExtents, out pivot, out orientation);
                HkBoxShape boxShape;
                try
                {
                    halfExtents *= new Vector3(2.0f, 1.0f, 2.0f);
                    orientation.Normalize();
                    MyPhysics.GetPenetrationsBox(ref halfExtents, ref pivot, ref orientation, m_penetrations, MyPhysics.CollisionLayers.DefaultCollisionLayer);
                    boxShape = new HkBoxShape(halfExtents);
                    Matrix tranform = Matrix.CreateFromQuaternion(orientation);
                    //tranform.Translation = pivot;
                    //MyOrientedBoundingBoxD obb = new MyOrientedBoundingBoxD(new BoundingBoxD(-halfExtents, halfExtents),tranform);
                    //tranform.Translation = Vector3D.Zero;
                    //MyRenderProxy.DebugDrawOBB(obb, Color.Red, 1, false, false);

                    foreach (var obj in m_penetrations)
                    {
                        var entity = MyPhysicsExtensions.GetCollisionEntity(obj) as MyEntity;

                        if (entity == null)// || entity.Parent != null)
                        {
                            continue;
                        }

                        if (entity.GetPhysicsBody().WeldInfo.Children.Count > 0)
                        {
                            Matrix t2;
                            foreach (var child in entity.GetPhysicsBody().WeldInfo.Children)
                            {
                                var childEnt = child.Entity as MyEntity;
                                t2             = childEnt.GetPhysicsBody().WeldInfo.Transform *entity.Physics.RigidBody.GetRigidBodyMatrix();
                                t2.Translation = entity.Physics.ClusterToWorld(t2.Translation);
                                //obb = new MyOrientedBoundingBoxD((BoundingBoxD)childEnt.PositionComp.LocalAABB, t2);
                                //MyRenderProxy.DebugDrawOBB(obb, Color.Green, 1, false, false);
                                t2.Translation = t2.Translation - pivot;
                                if (MyPhysics.IsPenetratingShapeShape(boxShape, ref tranform, child.WeldedRigidBody.GetShape(), ref t2))
                                {
                                    if (
                                        CanAttachTo(obj, child.Entity as MyEntity))
                                    {
                                        return(child.Entity as MyEntity);
                                    }
                                }
                            }
                            t2             = entity.Physics.RigidBody.GetRigidBodyMatrix();
                            t2.Translation = entity.Physics.ClusterToWorld(t2.Translation) - pivot;

                            if (MyPhysics.IsPenetratingShapeShape(boxShape, ref tranform, entity.GetPhysicsBody().GetShape(), ref t2) &&
                                CanAttachTo(obj, entity))
                            {
                                return(entity);
                            }
                        }
                        else if (CanAttachTo(obj, entity))
                        {
                            return(entity);
                        }
                    }
                }
                finally
                {
                    boxShape.Base.RemoveReference();
                    m_penetrations.Clear();
                }
            }
            return(null);
        }