コード例 #1
0
        private HkdBreakableShape AddMountForShape(HkdBreakableShape shape, Matrix transform, ref BoundingBox blockBB)
        {
            Vector4 min;
            Vector4 max;

            shape.GetShape().GetLocalAABB(0.01f, out min, out max);//.Transform(CubeGrid.PositionComp.WorldMatrix);
            var bb = new BoundingBox(new Vector3(min), new Vector3(max));

            bb      = bb.Transform(transform);
            bb.Min /= CubeGrid.GridSize; //normalize for mount point
            bb.Max /= CubeGrid.GridSize;

            bb.Inflate(0.04f);//add tolerance (fracture shapes are smaller than block)
            bb.Min += blockBB.HalfExtents;
            bb.Max += blockBB.HalfExtents;

            if (blockBB.Contains(bb) == ContainmentType.Intersects)
            {
                bb.Inflate(-0.04f);
                foreach (var directionEnum in Base6Directions.EnumDirections)
                {
                    int     dirEnum   = (int)directionEnum;
                    Vector3 direction = Base6Directions.Directions[dirEnum];
                    Vector3 absDir    = Vector3.Abs(direction);
                    var     mp        = new MyCubeBlockDefinition.MountPoint();
                    mp.Start   = bb.Min;
                    mp.End     = bb.Max;
                    mp.Enabled = true;
                    var  start = mp.Start * absDir / (blockBB.HalfExtents * 2) - absDir * 0.04f;
                    var  end   = mp.End * absDir / (blockBB.HalfExtents * 2) + absDir * 0.04f;
                    bool add   = false;
                    bool one   = false;
                    if (start.Max() < 1 && end.Max() > 1 && direction.Max() > 0)
                    {
                        add = true;
                        one = true;
                    }
                    else if (start.Min() < 0 && end.Max() > 0 && direction.Min() < 0)
                    {
                        add = true;
                    }
                    if (!add)
                    {
                        continue;
                    }
                    mp.Start -= mp.Start * absDir - absDir * 0.04f;
                    mp.End   -= mp.End * absDir + absDir * 0.04f;
                    if (one)
                    {
                        mp.Start += absDir * blockBB.HalfExtents * 2;
                        mp.End   += absDir * blockBB.HalfExtents * 2;
                    }
                    mp.Start -= blockBB.HalfExtents - Vector3.One / 2;
                    mp.End   -= blockBB.HalfExtents - Vector3.One / 2;
                    mp.Normal = new Vector3I(direction);
                    MountPoints.Add(mp);
                }
            }
            return(shape);
        }
コード例 #2
0
        static bool FindMountPoint(HkShapeCutterUtil cutter, HkShape shape, Vector3 direction, float gridSize, List <Sandbox.Definitions.MyCubeBlockDefinition.MountPoint> mountPoints)
        {
            //VRageRender.MyRenderProxy.DebugDrawLine3D(drawMatrix.Translation, Vector3D.Transform(direction, drawMatrix), Color.Green, Color.Green, false);
            //float offset = (gridSize * 0.9f) / 2.0f;
            float offset      = (gridSize * 0.75f) / 2.0f; //because fracture pieces can be bit inside the cube
            Plane plane       = new Plane(-direction, offset);
            float minimumSize = 0.2f;

            Vector3 min, max;

            if (cutter.Cut(shape, new Vector4(plane.Normal.X, plane.Normal.Y, plane.Normal.Z, plane.D), out min, out max))
            {
                var aabb = new BoundingBox(min, max);
                aabb.InflateToMinimum(new Vector3(minimumSize));
                float centerOffset = gridSize * 0.5f;
                //    VRageRender.MyRenderProxy.DebugDrawOBB(boxC, Color.Red, 0.02f, true, false);

                MyCubeBlockDefinition.MountPoint mountPoint = new MyCubeBlockDefinition.MountPoint();
                mountPoint.Normal  = new Vector3I(direction);
                mountPoint.Start   = (aabb.Min + new Vector3(centerOffset)) / gridSize;
                mountPoint.End     = (aabb.Max + new Vector3(centerOffset)) / gridSize;
                mountPoint.Enabled = true;
                //because it didnt work if shape wasnt realy near the edge
                var  zExt = Vector3.Abs(direction) * mountPoint.Start;
                bool add  = zExt.AbsMax() > 0.5f;
                mountPoint.Start -= zExt;
                mountPoint.Start -= direction * 0.04f;
                mountPoint.End   -= Vector3.Abs(direction) * mountPoint.End;
                mountPoint.End   += direction * 0.04f;
                if (add)
                {
                    mountPoint.Start += Vector3.Abs(direction);
                    mountPoint.End   += Vector3.Abs(direction);
                }
                mountPoints.Add(mountPoint);

                return(true);
            }

            return(false);
        }
コード例 #3
0
        private bool IsPressurized(IMySlimBlock block, Vector3I pos, Vector3 normal)
        {
            var def = (MyCubeBlockDefinition)block.BlockDefinition;

            if (def.BuildProgressModels.Length > 0)
            {
                MyCubeBlockDefinition.BuildProgressModel buildProgressModel = def.BuildProgressModels[def.BuildProgressModels.Length - 1];
                if (block.BuildLevelRatio < buildProgressModel.BuildRatioUpperBound)
                {
                    return(false);
                }
            }
            Matrix matrix;

            block.Orientation.GetMatrix(out matrix);
            matrix.TransposeRotationInPlace();
            Vector3 vector   = Vector3.Transform(normal, matrix);
            Vector3 position = Vector3.Zero;

            if (block.FatBlock != null)
            {
                position = pos - block.FatBlock.Position;
            }
            Vector3 value = Vector3.Transform(position, matrix) + def.Center;
            bool    flag  = def.IsCubePressurized[Vector3I.Round(value)][Vector3I.Round(vector)];

            if (flag)
            {
                return(true);
            }
            if (block.FatBlock != null)
            {
                MyCubeBlock fatBlock = (MyCubeBlock)block.FatBlock;
                bool        result;
                if (fatBlock is MyDoor)
                {
                    MyDoor myDoor = fatBlock as MyDoor;
                    if (!myDoor.Open)
                    {
                        MyCubeBlockDefinition.MountPoint[] mountPoints = def.MountPoints;
                        for (int i = 0; i < mountPoints.Length; i++)
                        {
                            MyCubeBlockDefinition.MountPoint mountPoint = mountPoints[i];
                            if (vector == mountPoint.Normal)
                            {
                                result = false;
                                return(result);
                            }
                        }
                        return(true);
                    }
                    return(false);
                }
                else if (fatBlock is MyAdvancedDoor)
                {
                    MyAdvancedDoor myAdvancedDoor = fatBlock as MyAdvancedDoor;
                    if (myAdvancedDoor.FullyClosed)
                    {
                        MyCubeBlockDefinition.MountPoint[] mountPoints2 = def.MountPoints;
                        for (int j = 0; j < mountPoints2.Length; j++)
                        {
                            MyCubeBlockDefinition.MountPoint mountPoint2 = mountPoints2[j];
                            if (vector == mountPoint2.Normal)
                            {
                                result = false;
                                return(result);
                            }
                        }
                        return(true);
                    }
                    return(false);
                }
                else if (fatBlock is MyAirtightSlideDoor)
                {
                    MyAirtightDoorGeneric myAirtightDoorGeneric = fatBlock as MyAirtightDoorGeneric;
                    if (myAirtightDoorGeneric.IsFullyClosed && vector == Vector3.Forward)
                    {
                        return(true);
                    }
                    return(false);
                }
                else
                {
                    if (!(fatBlock is MyAirtightDoorGeneric))
                    {
                        return(false);
                    }
                    MyAirtightDoorGeneric myAirtightDoorGeneric2 = fatBlock as MyAirtightDoorGeneric;
                    if (myAirtightDoorGeneric2.IsFullyClosed && (vector == Vector3.Forward || vector == Vector3.Backward))
                    {
                        return(true);
                    }
                    return(false);
                }
            }
            return(false);
        }