示例#1
0
 private bool EntInside(MyEntity entity, ref MyOrientedBoundingBoxD bOriBBoxD)
 {
     if (entity != null && CustomCollision.PointInShield(entity.PositionComp.WorldVolume.Center, DetectMatrixOutsideInv))
     {
         if (CustomCollision.ObbCornersInShield(bOriBBoxD, DetectMatrixOutsideInv, _obbCorners))
         {
             var bPhysics   = entity.Physics;
             var sPhysics   = Shield.CubeGrid.Physics;
             var sLSpeed    = sPhysics.LinearVelocity;
             var sASpeed    = sPhysics.AngularVelocity * 50;
             var sLSpeedLen = sLSpeed.LengthSquared();
             var sASpeedLen = sASpeed.LengthSquared();
             var sSpeedLen  = sLSpeedLen > sASpeedLen ? sLSpeedLen : sASpeedLen;
             var direction  = Vector3D.Normalize(entity.PositionComp.WorldAABB.Center - DetectionCenter);
             var forceData  = new MyForceData {
                 Entity = entity, Force = direction * (bPhysics.Mass * 10), MaxSpeed = sSpeedLen + 3
             };
             if (!bPhysics.IsStatic)
             {
                 var forceEvent = Session.Instance.ForceDataPool.Get();
                 forceEvent.Init(forceData, this);
                 Session.Instance.ThreadEvents.Enqueue(forceEvent);
             }
             return(true);
         }
     }
     return(false);
 }
 private bool GridInside(MyCubeGrid grid, MyOrientedBoundingBoxD bOriBBoxD)
 {
     if (grid != null && CustomCollision.PointInShield(grid.PositionComp.WorldVolume.Center, DetectMatrixOutsideInv))
     {
         if (CustomCollision.ObbCornersInShield(bOriBBoxD, DetectMatrixOutsideInv, _obbCorners))
         {
             var sMass      = ((MyCubeGrid)Shield.CubeGrid).GetCurrentMass();
             var bPhysics   = ((IMyCubeGrid)grid).Physics;
             var sPhysics   = Shield.CubeGrid.Physics;
             var sLSpeed    = sPhysics.LinearVelocity;
             var sASpeed    = sPhysics.AngularVelocity * 50;
             var sLSpeedLen = sLSpeed.LengthSquared();
             var sASpeedLen = sASpeed.LengthSquared();
             var sSpeedLen  = sLSpeedLen > sASpeedLen ? sLSpeedLen : sASpeedLen;
             var forceData  = new MyAddForceData {
                 MyGrid = grid, Force = -(grid.PositionComp.WorldAABB.Center - sPhysics.CenterOfMassWorld) * -sMass, MaxSpeed = sSpeedLen + 3
             };
             if (!bPhysics.IsStatic)
             {
                 ForceData.Enqueue(forceData);
             }
             return(true);
         }
     }
     return(false);
 }
 private bool EntInside(MyEntity entity, MyOrientedBoundingBoxD bOriBBoxD)
 {
     if (entity != null && CustomCollision.PointInShield(entity.PositionComp.WorldVolume.Center, DetectMatrixOutsideInv))
     {
         if (CustomCollision.ObbCornersInShield(bOriBBoxD, DetectMatrixOutsideInv, _obbCorners))
         {
             var bPhysics   = entity.Physics;
             var sPhysics   = Shield.CubeGrid.Physics;
             var sLSpeed    = sPhysics.LinearVelocity;
             var sASpeed    = sPhysics.AngularVelocity * 50;
             var sLSpeedLen = sLSpeed.LengthSquared();
             var sASpeedLen = sASpeed.LengthSquared();
             var sSpeedLen  = sLSpeedLen > sASpeedLen ? sLSpeedLen : sASpeedLen;
             var forceData  = new MyForceData {
                 Entity = entity, Force = -(entity.PositionComp.WorldAABB.Center - sPhysics.CenterOfMassWorld) * -int.MaxValue, MaxSpeed = sSpeedLen + 3
             };
             if (!bPhysics.IsStatic)
             {
                 Session.Instance.ThreadEvents.Enqueue(new ForceDataThreadEvent(forceData, this));
             }
             return(true);
         }
     }
     return(false);
 }