Esempio n. 1
0
        /// <summary>
        /// Moves and Rotates entity
        /// </summary>
        /// <param name="newPosition"></param>
        /// <param name="newOrientation"></param>
        /// <param name="entity"></param>
        public static void MoveAndRotateObject(Vector3 newPosition, Matrix newOrientation, MyEntity entity)
        {
            BoundingSphere sphere = new BoundingSphere(newPosition + entity.LocalVolumeOffset, entity.WorldVolume.Radius);

            if (MyMwcSectorConstants.SECTOR_SIZE_FOR_PHYS_OBJECTS_BOUNDING_BOX.Contains(sphere) == MinerWarsMath.ContainmentType.Contains)
            {
                Matrix entityBeforeMoveOrientation = entity.GetWorldRotation();
                Vector3 entityBeforeMovePosition = entity.GetPosition();

                if (entityBeforeMovePosition != newPosition || entityBeforeMoveOrientation != newOrientation)
                {
                    // Move object
                    bool moveSuccesfull = entity.MoveAndRotate(newPosition, newOrientation);
                    Vector3 currentPosition = entity.GetPosition();
                    Matrix currentOrientation = entity.GetWorldRotation();

                    if (moveSuccesfull)
                    {
                        //entity.UpdateWorldMatrix();
                        //  Play movement or rotation sounds
                        if (MyMinerGame.TotalGamePlayTimeInMilliseconds > m_delayMovementSoundInMillis)
                        {
                            if (entityBeforeMovePosition != currentPosition)
                            {
                                MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorObjectMoveStep);
                            }

                            if (entityBeforeMoveOrientation != currentOrientation)
                            {
                                MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorObjectRotateStep);
                            }

                            m_delayMovementSoundInMillis = MyMinerGame.TotalGamePlayTimeInMilliseconds + MyEditorConstants.DELAY_OBJECT_MOVEMENT_SOUND_IN_MILLIS;
                        }

                        MyEditor.Static.RecheckAllColidingEntitesAndClearNonColiding();//check all coliding entites to see if any went out of collision state
                        
                        //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("CheckAllCollidingObjectsForEntity");

                        // This was taking up to 170ms for 800 prefabs, so its replaced by void CheckCollisions(IEnumerable<MyEntity> entities) in HandleInput().
                        //MyEditor.Static.CheckAllCollidingObjectsForEntity(entity);//check all colliding state of entity after move

                        //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); 
                    }
                    else
                    {
                        if (MyMinerGame.TotalGamePlayTimeInMilliseconds > m_delayMovementSoundInMillis)
                        {
                            if ((entityBeforeMovePosition != currentPosition) || (entityBeforeMoveOrientation != currentOrientation))
                            {
                                MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorObjectMoveInvalid);
                                m_delayMovementSoundInMillis = MyMinerGame.TotalGamePlayTimeInMilliseconds + 1000;
                            }
                        }
                    }

                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This method calculates new object position when its being rotated - in case only one object is selected and rotated
        /// only rotation is changed, but for multiple selected object, rotation is calculated based on the objects selected center
        /// </summary>
        static void GetRotationAndPosition(MyEntity entity, Matrix rotation, out Vector3 newPosition, out Matrix newRotation)
        {
            Matrix entityOrientation = entity.GetWorldRotation();
            Vector3 entityPosition = entity.GetPosition();
            Vector3 gizmoPosition = Position;

            if (ActivePivot == PivotType.OBJECT_CENTER)
            {
                //gizmoPosition = entityPosition;
            }

            Matrix localRot = Matrix.Identity;
            localRot.Forward = entityOrientation.Forward;
            localRot.Up = entityOrientation.Up;
            localRot.Right = entityOrientation.Right;
            m_localRight = MyMwcUtils.Normalize(m_localRight);
            localRot.Translation = entityPosition - gizmoPosition;

            Matrix rot = localRot * rotation;
            newPosition = rot.Translation + gizmoPosition;
            entityOrientation.Forward = rot.Forward;
            entityOrientation.Up = rot.Up;
            entityOrientation.Right = rot.Right;
            entityOrientation.Translation = Vector3.Zero;
            newRotation = entityOrientation;
        }