Пример #1
0
        public static void ClientSmallIntersect(EntIntersectInfo entInfo, MyCubeGrid grid, MatrixD matrix, MatrixD matrixInv, ConcurrentQueue <MyCubeGrid> eject)
        {
            try
            {
                if (grid == null)
                {
                    return;
                }
                var contactPoint = ContactPointOutside(grid, matrix);
                if (!(Vector3D.Transform(contactPoint, matrixInv).LengthSquared() <= 1))
                {
                    return;
                }
                entInfo.ContactPoint = contactPoint;

                var approching = Vector3.Dot(grid.Physics.LinearVelocity, grid.PositionComp.WorldVolume.Center - contactPoint) < 0;
                if (approching)
                {
                    eject.Enqueue(grid);
                }
            }
            catch (Exception ex) { Log.Line($"Exception in ClientSmallIntersect: {ex}"); }
        }
Пример #2
0
        public static void SmallIntersect(EntIntersectInfo entInfo, ConcurrentQueue <IMySlimBlock> fewDmgBlocks, ConcurrentQueue <IMySlimBlock> destroyedBlocks, ConcurrentQueue <MyAddForceData> force, ConcurrentQueue <MyImpulseData> impulse, MyCubeGrid grid, MatrixD matrix, MatrixD matrixInv, bool damageBlocks = true)
        {
            try
            {
                var contactPoint = ContactPointOutside(grid, matrix);
                if (!(Vector3D.Transform(contactPoint, matrixInv).LengthSquared() <= 1))
                {
                    return;
                }

                var getBlocks = new List <IMySlimBlock>();
                (grid as IMyCubeGrid).GetBlocks(getBlocks);
                var blockPoints  = new Vector3D[9];
                var collisionAvg = Vector3D.Zero;
                var c3           = 0;
                for (int i = 0; i < getBlocks.Count; i++)
                {
                    var block = getBlocks[i];
                    if (damageBlocks && block.IsDestroyed)
                    {
                        destroyedBlocks.Enqueue(block);
                        continue;
                    }

                    BoundingBoxD blockBox;
                    block.GetWorldBoundingBox(out blockBox);
                    blockBox.GetCorners(blockPoints);
                    blockPoints[8] = blockBox.Center;
                    for (int j = 8; j > -1; j--)
                    {
                        var point = blockPoints[j];
                        if (Vector3.Transform(point, matrixInv).LengthSquared() > 1)
                        {
                            continue;
                        }
                        c3++;
                        collisionAvg += point;
                        if (damageBlocks)
                        {
                            fewDmgBlocks.Enqueue(block);
                        }
                        break;
                    }
                }

                if (collisionAvg != Vector3D.Zero)
                {
                    collisionAvg        /= c3;
                    entInfo.ContactPoint = collisionAvg;
                    var mass = grid.GetCurrentMass();

                    var transformInv  = matrixInv;
                    var normalMat     = MatrixD.Transpose(transformInv);
                    var localNormal   = Vector3D.Transform(collisionAvg, transformInv);
                    var surfaceNormal = Vector3D.Normalize(Vector3D.TransformNormal(localNormal, normalMat));
                    var gridLinearVel = grid.Physics.LinearVelocity;
                    var gridLinearLen = gridLinearVel.Length();

                    var forceData = new MyAddForceData {
                        MyGrid = grid, Force = (grid.PositionComp.WorldAABB.Center - matrix.Translation) * (mass * gridLinearLen), MaxSpeed = MathHelper.Clamp(gridLinearLen, 10, gridLinearLen * 0.5f)
                    };
                    var impulseData = new MyImpulseData {
                        MyGrid = grid, Direction = mass * 0.015 * -Vector3D.Dot(gridLinearVel, surfaceNormal) * surfaceNormal, Position = collisionAvg
                    };
                    force.Enqueue(forceData);
                    impulse.Enqueue(impulseData);
                    entInfo.Damage = mass * 0.5f;
                }
            }
            catch (Exception ex) { Log.Line($"Exception in SmallIntersect: {ex}"); }
        }