Пример #1
0
        private void CalculateGridPosition(Vector3D Target)
        {
            List <MyObjectBuilder_CubeGrid> TotalGrids = new List <MyObjectBuilder_CubeGrid>();
            List <MyObjectBuilder_Cockpit>  cockpits   = new List <MyObjectBuilder_Cockpit>();
            Vector3D forwardVector = Vector3D.Zero;


            Hangar.Debug("Total Grids to be pasted: " + _grids.Count());

            //Attempt to get gravity/Artificial gravity to align the grids to


            //Here you can adjust the offset from the surface and rotation.
            //Unfortunatley we move the grid again after this to find a free space around the character. Perhaps later i can incorporate that into
            //LordTylus's existing grid checkplament method
            float gravityRotation = 0f;

            Vector3 gravityDirectionalVector = MyGravityProviderSystem.CalculateNaturalGravityInPoint(Target);

            if (gravityDirectionalVector == Vector3.Zero)
            {
                gravityDirectionalVector = MyGravityProviderSystem.CalculateArtificialGravityInPoint(Target);
            }
            Vector3D upDirectionalVector;

            if (gravityDirectionalVector != Vector3.Zero)
            {
                Hangar.Debug("Attempting to correct grid orientation!");
                gravityDirectionalVector.Normalize();
                upDirectionalVector = -gravityDirectionalVector;

                if (forwardVector == Vector3D.Zero)
                {
                    forwardVector = Vector3D.CalculatePerpendicularVector(gravityDirectionalVector);
                    if (gravityRotation != 0f)
                    {
                        MatrixD matrixa = MatrixD.CreateFromAxisAngle(upDirectionalVector, gravityRotation);
                        forwardVector = Vector3D.Transform(forwardVector, matrixa);
                    }
                }
            }
            else if (forwardVector == Vector3D.Zero)
            {
                forwardVector       = Vector3D.Right;
                upDirectionalVector = Vector3D.Up;
            }
            else
            {
                upDirectionalVector = Vector3D.CalculatePerpendicularVector(-forwardVector);
            }

            BeginAlignToGravity(_grids, Target, forwardVector, upDirectionalVector);
        }
Пример #2
0
        private bool CalculateGridPosition()
        {
            List <MyObjectBuilder_CubeGrid> TotalGrids = new List <MyObjectBuilder_CubeGrid>();
            List <MyObjectBuilder_Cockpit>  cockpits   = new List <MyObjectBuilder_Cockpit>();
            Vector3D direction = _PlayerPosition;



            //Get all cockpit blkocks on the grid
            foreach (var shipBlueprint in _ShipBlueprints)
            {
                TotalGrids.AddRange(shipBlueprint.CubeGrids.ToList());
                foreach (MyObjectBuilder_CubeGrid grid in shipBlueprint.CubeGrids)
                {
                    cockpits.AddRange(grid.CubeBlocks.OfType <MyObjectBuilder_Cockpit>().ToList());
                }
            }

            MyObjectBuilder_CubeGrid[] array = TotalGrids.ToArray();
            if (array.Length == 0)
            {
                //Simple grid/objectbuilder null check. If there are no gridys then why continue?
                return(false);
            }
            Hangar.Debug("Total Grids to be pasted: " + array.Count());

            if (cockpits.Count > 0)
            {
                //Main.Debug("Cockpits found!");
                foreach (MyObjectBuilder_Cockpit Block in cockpits)
                {
                    if (Block.IsMainCockpit)
                    {
                        Hangar.Debug("Main cockpit found! Attempting to Align!");
                        direction = new Vector3D(Block.Orientation.x, Block.Orientation.y, Block.Orientation.z);
                        break;
                    }
                }
            }
            else
            {
                Hangar.Debug("No Cockpits. Continuing based off of grid pivot point!");
            }


            //Attempt to get gravity/Artificial gravity to align the grids to
            Vector3D position = _PlayerPosition;

            //Here you can adjust the offset from the surface and rotation.
            //Unfortunatley we move the grid again after this to find a free space around the character. Perhaps later i can incorporate that into
            //LordTylus's existing grid checkplament method
            float gravityOffset   = 0f;
            float gravityRotation = 0f;

            Vector3 vector = MyGravityProviderSystem.CalculateNaturalGravityInPoint(position);

            if (vector == Vector3.Zero)
            {
                vector = MyGravityProviderSystem.CalculateArtificialGravityInPoint(position);
            }
            Vector3D vector3D;

            if (vector != Vector3.Zero)
            {
                Hangar.Debug("Attempting to correct grid orientation!");
                vector.Normalize();
                vector3D  = -vector;
                position += vector * gravityOffset;
                if (direction == Vector3D.Zero)
                {
                    direction = Vector3D.CalculatePerpendicularVector(vector);
                    if (gravityRotation != 0f)
                    {
                        MatrixD matrixa = MatrixD.CreateFromAxisAngle(vector3D, gravityRotation);
                        direction = Vector3D.Transform(direction, matrixa);
                    }
                }
            }
            else if (direction == Vector3D.Zero)
            {
                direction = Vector3D.Right;
                vector3D  = Vector3D.Up;
            }
            else
            {
                vector3D = Vector3D.CalculatePerpendicularVector(-direction);
            }


            return(BeginAlignToGravity(array, position, direction, vector3D));
        }
Пример #3
0
 public Vector3D GetArtificialGravity()
 {
     return(MyGravityProviderSystem.CalculateArtificialGravityInPoint(WorldMatrix.Translation));
 }
Пример #4
0
        private bool CalculateGridPosition()
        {
            List <MyObjectBuilder_CubeGrid> TotalGrids = new List <MyObjectBuilder_CubeGrid>();
            List <MyObjectBuilder_Cockpit>  cockpits   = new List <MyObjectBuilder_Cockpit>();
            Vector3D forwardVector = Vector3D.Zero;



            //Get all cockpit blkocks on the grid
            foreach (var shipBlueprint in _ShipBlueprints)
            {
                TotalGrids.AddRange(shipBlueprint.CubeGrids.ToList());
            }

            MyObjectBuilder_CubeGrid[] array = TotalGrids.ToArray();
            if (array.Length == 0)
            {
                //Simple grid/objectbuilder null check. If there are no gridys then why continue?
                return(false);
            }
            Hangar.Debug("Total Grids to be pasted: " + array.Count());

            //Attempt to get gravity/Artificial gravity to align the grids to
            Vector3D position = _PlayerPosition;

            //Here you can adjust the offset from the surface and rotation.
            //Unfortunatley we move the grid again after this to find a free space around the character. Perhaps later i can incorporate that into
            //LordTylus's existing grid checkplament method
            float gravityOffset   = 0f;
            float gravityRotation = 0f;

            Vector3 gravityDirectionalVector = MyGravityProviderSystem.CalculateNaturalGravityInPoint(position);

            if (gravityDirectionalVector == Vector3.Zero)
            {
                gravityDirectionalVector = MyGravityProviderSystem.CalculateArtificialGravityInPoint(position);
            }
            Vector3D upDirectionalVector;

            if (gravityDirectionalVector != Vector3.Zero)
            {
                Hangar.Debug("Attempting to correct grid orientation!");
                gravityDirectionalVector.Normalize();
                upDirectionalVector = -gravityDirectionalVector;
                position           += gravityDirectionalVector * gravityOffset;
                if (forwardVector == Vector3D.Zero)
                {
                    forwardVector = Vector3D.CalculatePerpendicularVector(gravityDirectionalVector);
                    if (gravityRotation != 0f)
                    {
                        MatrixD matrixa = MatrixD.CreateFromAxisAngle(upDirectionalVector, gravityRotation);
                        forwardVector = Vector3D.Transform(forwardVector, matrixa);
                    }
                }
            }
            else if (forwardVector == Vector3D.Zero)
            {
                forwardVector       = Vector3D.Right;
                upDirectionalVector = Vector3D.Up;
            }
            else
            {
                upDirectionalVector = Vector3D.CalculatePerpendicularVector(-forwardVector);
            }

            return(BeginAlignToGravity(array, forwardVector, upDirectionalVector));
        }
Пример #5
0
        private bool CalculateGridPosition(Vector3D Target)
        {
            Vector3D forwardVector = Vector3D.Zero;


            //Hangar.Debug("Total Grids to be pasted: " + _grids.Count());

            //Attempt to get gravity/Artificial gravity to align the grids to


            //Here you can adjust the offset from the surface and rotation.
            //Unfortunatley we move the grid again after this to find a free space around the character. Perhaps later i can incorporate that into
            //LordTylus's existing grid checkplament method
            float gravityRotation = 0f;

            Vector3 gravityDirectionalVector = MyGravityProviderSystem.CalculateNaturalGravityInPoint(Target);

            bool AllowAlignToNatrualGravity = false;

            if (AllowAlignToNatrualGravity && gravityDirectionalVector == Vector3.Zero)
            {
                gravityDirectionalVector = MyGravityProviderSystem.CalculateArtificialGravityInPoint(Target);
            }


            if (gravityDirectionalVector == Vector3.Zero)
            {
                return(false);
            }


            //Calculate and apply grid rotation
            Vector3D upDirectionalVector;

            if (gravityDirectionalVector != Vector3.Zero)
            {
                gravityDirectionalVector.Normalize();
                upDirectionalVector = -gravityDirectionalVector;

                if (forwardVector == Vector3D.Zero)
                {
                    forwardVector = Vector3D.CalculatePerpendicularVector(gravityDirectionalVector);
                    if (gravityRotation != 0f)
                    {
                        MatrixD matrixa = MatrixD.CreateFromAxisAngle(upDirectionalVector, gravityRotation);
                        forwardVector = Vector3D.Transform(forwardVector, matrixa);
                    }
                }
            }
            else if (forwardVector == Vector3D.Zero)
            {
                forwardVector       = Vector3D.Right;
                upDirectionalVector = Vector3D.Up;
            }
            else
            {
                upDirectionalVector = Vector3D.CalculatePerpendicularVector(-forwardVector);
            }

            BeginAlignToGravity(Target, forwardVector, upDirectionalVector);
            return(true);
        }