Beispiel #1
0
        static void CycleRequest_Implementation(MyEntityCyclingOrder order, bool reset, bool findLarger, float metricValue, long currentEntityId, CyclingOptions options)
        {
            if (reset)
            {
                metricValue     = float.MinValue;
                currentEntityId = 0;
                findLarger      = false;
            }

            MyEntityCycling.FindNext(order, ref metricValue, ref currentEntityId, findLarger, options);

            var      e   = MyEntities.GetEntityByIdOrDefault(currentEntityId);
            Vector3D pos = e != null ? e.WorldMatrix.Translation : Vector3D.Zero;

            if (MyEventContext.Current.IsLocallyInvoked)
            {
                Cycle_Implementation(metricValue, currentEntityId, pos);
            }
            else
            {
                var proxy = e as IMyEventProxy;
                if (proxy != null)
                {
                    if (proxy is MyCubeGrid && (proxy as MyCubeGrid).Physics == null)
                    {
                        //don't send grids without physics
                    }
                    else
                    {
                        MyMultiplayer.ReplicateImmediatelly(proxy, MyEventContext.Current.Sender);
                    }
                }
                MyMultiplayer.RaiseStaticEvent(x => Cycle_Implementation, metricValue, currentEntityId, pos, MyEventContext.Current.Sender);
            }
        }
Beispiel #2
0
        private void MoveAndRotate_ConstantDelta(Vector3 moveIndicator, Vector2 rotationIndicator, float rollIndicator)
        {
            MyEntity entity;

            this.m_cycling.Enabled = true;
            bool flag = false;

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.TOOLBAR_UP) && MySession.Static.IsUserAdmin(Sync.MyId))
            {
                MyEntityCycling.FindNext(MyEntityCyclingOrder.Characters, ref this.m_cyclingMetricValue, ref this.m_entityID, false, this.m_cycling);
                flag = true;
            }
            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.TOOLBAR_DOWN) && MySession.Static.IsUserAdmin(Sync.MyId))
            {
                MyEntityCycling.FindNext(MyEntityCyclingOrder.Characters, ref this.m_cyclingMetricValue, ref this.m_entityID, true, this.m_cycling);
                flag = true;
            }
            if (!MyInput.Static.IsAnyCtrlKeyPressed() && !MyInput.Static.IsAnyShiftKeyPressed())
            {
                if (MyInput.Static.PreviousMouseScrollWheelValue() < MyInput.Static.MouseScrollWheelValue())
                {
                    this.ThirdPersonCameraOrbit /= 1.1000000238418579;
                }
                else if (MyInput.Static.PreviousMouseScrollWheelValue() > MyInput.Static.MouseScrollWheelValue())
                {
                    this.ThirdPersonCameraOrbit *= 1.1000000238418579;
                }
            }
            if (flag)
            {
                MyEntities.TryGetEntityById(this.m_entityID, out this.m_character, false);
            }
            MyEntities.TryGetEntityById(this.TrackedEntity, out entity, false);
            if (entity != null)
            {
                Vector3D position = entity.PositionComp.GetPosition();
                if (!this.AlignSpectatorToGravity)
                {
                    base.Position = position + (Vector3D.Normalize(base.Position - base.Target) * base.ThirdPersonCameraDelta.Length());
                    base.Target   = position;
                }
                else
                {
                    MatrixD xd;
                    this.m_roll  = 0.0;
                    this.m_yaw   = 0.0;
                    this.m_pitch = 0.0;
                    this.ComputeGravityAlignedOrientation(out xd);
                    base.Position         = position + Vector3D.Transform(base.ThirdPersonCameraDelta, xd);
                    base.Target           = position;
                    base.m_orientation.Up = xd.Up;
                }
            }
            if ((MyInput.Static.IsAnyAltKeyPressed() && !MyInput.Static.IsAnyCtrlKeyPressed()) && !MyInput.Static.IsAnyShiftKeyPressed())
            {
                base.MoveAndRotate(moveIndicator, rotationIndicator, rollIndicator);
            }
        }
Beispiel #3
0
        // ------------------------------------------------------------------------------------------------
        private void MoveAndRotate_ConstantDelta(Vector3 moveIndicator, Vector2 rotationIndicator, float rollIndicator)
        {
            m_cycling.Enabled = true;
            bool findNew = false;

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.TOOLBAR_UP) && MySession.Static.LocalHumanPlayer.IsAdmin)
            {
                MyEntityCycling.FindNext(MyEntityCyclingOrder.Characters, ref m_cyclingMetricValue, ref m_entityID, false, m_cycling);
                findNew = true;
            }
            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.TOOLBAR_DOWN) && MySession.Static.LocalHumanPlayer.IsAdmin)
            {
                MyEntityCycling.FindNext(MyEntityCyclingOrder.Characters, ref m_cyclingMetricValue, ref m_entityID, true, m_cycling);
                findNew = true;
            }

            //zoom
            if (!MyInput.Static.IsAnyCtrlKeyPressed() && !MyInput.Static.IsAnyShiftKeyPressed())
            {
                if (MyInput.Static.PreviousMouseScrollWheelValue() < MyInput.Static.MouseScrollWheelValue())
                {
                    ThirdPersonCameraOrbit /= 1.1f;
                }
                else if (MyInput.Static.PreviousMouseScrollWheelValue() > MyInput.Static.MouseScrollWheelValue())
                {
                    ThirdPersonCameraOrbit *= 1.1f;
                }
            }
            if (findNew)
            {
                MyEntities.TryGetEntityById(m_entityID, out m_character);
            }

            if (m_character != null || MySession.Static.ControlledEntity != null)
            {
                if (MyInput.Static.IsAnyAltKeyPressed())
                {
                    m_orbitY += rotationIndicator.Y * 0.0025f * SpeedModeAngular;
                    m_orbitX -= rotationIndicator.X * 0.0025f * SpeedModeAngular;
                    m_orbitX  = (float)MathHelper.Clamp(m_orbitX, -((Math.PI / 2) - 0.0001f), ((Math.PI / 2) - 0.0001f));
                }

                MatrixD gravityOrientationMatrix;
                MatrixD rotationMatrix = MatrixD.CreateRotationX(m_orbitX) * MatrixD.CreateRotationY(m_orbitY);

                m_roll  = 0;
                m_yaw   = 0;
                m_pitch = 0;
                m_lastOrientationWeight = 0;
                ComputeGravityAlignedOrientation(out gravityOrientationMatrix);
                Vector3D target = m_character == null?MySession.Static.ControlledEntity.Entity.PositionComp.GetPosition() : m_character.PositionComp.GetPosition();

                Position         = target + Vector3D.Transform(ThirdPersonCameraOrbit, rotationMatrix * gravityOrientationMatrix);
                Target           = target;
                m_orientation.Up = gravityOrientationMatrix.Up;
            }
        }
        // ------------------------------------------------------------------------------------------------
        private void MoveAndRotate_ConstantDelta(Vector3 moveIndicator, Vector2 rotationIndicator, float rollIndicator)
        {
            m_cycling.Enabled = true;
            bool findNew = false;

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.TOOLBAR_UP) && MySession.Static.LocalHumanPlayer.IsAdmin)
            {
                MyEntityCycling.FindNext(MyEntityCyclingOrder.Characters, ref m_cyclingMetricValue, ref m_entityID, false, m_cycling);
                findNew = true;
            }
            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.TOOLBAR_DOWN) && MySession.Static.LocalHumanPlayer.IsAdmin)
            {
                MyEntityCycling.FindNext(MyEntityCyclingOrder.Characters, ref m_cyclingMetricValue, ref m_entityID, true, m_cycling);
                findNew = true;
            }

            //zoom
            if (!MyInput.Static.IsAnyCtrlKeyPressed() && !MyInput.Static.IsAnyShiftKeyPressed())
            {
                if (MyInput.Static.PreviousMouseScrollWheelValue() < MyInput.Static.MouseScrollWheelValue())
                {
                    ThirdPersonCameraOrbit /= 1.1f;
                }
                else if (MyInput.Static.PreviousMouseScrollWheelValue() > MyInput.Static.MouseScrollWheelValue())
                {
                    ThirdPersonCameraOrbit *= 1.1f;
                }
            }
            if (findNew)
            {
                MyEntities.TryGetEntityById(m_entityID, out m_character);
            }

            //var target = (Vector3D)MySession.Static.ControlledEntity.Entity.PositionComp.GetPosition();

            MyEntity trackedEntity;

            MyEntities.TryGetEntityById(TrackedEntity, out trackedEntity);

            if (trackedEntity != null)
            {
                var target = trackedEntity.PositionComp.GetPosition();

                if (AlignSpectatorToGravity)
                {
                    MatrixD gravityOrientationMatrix;
                    m_roll  = 0;
                    m_yaw   = 0;
                    m_pitch = 0;
                    ComputeGravityAlignedOrientation(out gravityOrientationMatrix);
                    Position         = target + Vector3D.Transform(ThirdPersonCameraDelta, gravityOrientationMatrix);
                    Target           = target;
                    m_orientation.Up = gravityOrientationMatrix.Up;
                }
                else
                {
                    var delta = Vector3D.Normalize(Position - Target) * ThirdPersonCameraDelta.Length();
                    Position = target + delta;
                    Target   = target;
                }
            }

            if (MyInput.Static.IsAnyAltKeyPressed() && !MyInput.Static.IsAnyCtrlKeyPressed() &&
                !MyInput.Static.IsAnyShiftKeyPressed())
            {
                base.MoveAndRotate(moveIndicator, rotationIndicator, rollIndicator);
            }
        }