Example #1
0
        /// <summary>
        /// Yaw this Entity around the world Up Vector (default is Y-axis).
        /// </summary>
        /// <param name="amount">Amount of radians to yaw.</param>
        public void YawAroundWorldUp(float amount)
        {
            MsgModifyRotation modRotMsg = ObjectPool.Aquire <MsgModifyRotation>();

            modRotMsg.Rotation     = Matrix.CreateRotationY(amount);
            modRotMsg.UniqueTarget = this.uniqueID;
            this.game.SendMessage(modRotMsg);
        }
Example #2
0
        /// <summary>
        /// Roll this Entity around its own Forward vector.
        /// </summary>
        /// <param name="amount">Amount of radians to roll.</param>
        public void Roll(float amount)
        {
            MsgModifyRotation modRotMsg = ObjectPool.Aquire <MsgModifyRotation>();

            modRotMsg.Rotation     = Matrix.CreateFromAxisAngle(this.rotation.Forward, amount);
            modRotMsg.UniqueTarget = this.uniqueID;
            this.game.SendMessage(modRotMsg);
        }
Example #3
0
        /// <summary>
        /// Update the component
        /// </summary>
        /// <param name="gameTime">XNA Timing snapshot</param>
        public override void Update(GameTime gameTime)
        {
            // We factor time into our constant rotations. After all, they wouldn't be "constant" if they were frame-rate dependant.
            float timeDelta = gameTime.ElapsedGameTime.Milliseconds;

            timeDelta  = MathHelper.Max(timeDelta, 1u);  // We make sure timedelta is never less than 1ms for movement.
            timeDelta *= 0.001f;

            Matrix constRot = Matrix.CreateFromYawPitchRoll(amountYAxisPerSecond * timeDelta, amountXAxisPerSecond * timeDelta, amountZAxisPerSecond * timeDelta);

            MsgModifyRotation modRotMsg = ObjectPool.Aquire <MsgModifyRotation>();

            modRotMsg.Rotation     = constRot;
            modRotMsg.UniqueTarget = this.parentEntity.UniqueID;
            this.parentEntity.Game.SendMessage(modRotMsg);
        }
Example #4
0
        /// <summary>
        /// Send a message directly to an Entity through this method.
        /// This function MUST be called only from QSGame, otherwise it will never mark the message properly for release
        /// and it will leak memory.
        /// </summary>
        /// <param name="message">Message to send</param>
        /// <returns>Returns true if message was handled</returns>
        public virtual bool ExecuteMessage(IMessage message)
        {
            switch (message.Type)
            {
            case MessageType.GetName:
            {
                MsgGetName msgGetName = message as MsgGetName;
                message.TypeCheck(msgGetName);

                msgGetName.Name = this.name;
            }
            break;

            case MessageType.GetParentID:
            {
                MsgGetParentID msgGetID = message as MsgGetParentID;
                message.TypeCheck(msgGetID);

                if (this.parentEntity != null)
                {
                    msgGetID.ParentEntityID = this.parentEntity.UniqueID;
                }
            }
            break;

            case MessageType.SetPosition:
            {
                MsgSetPosition setPositionMsg = message as MsgSetPosition;
                message.TypeCheck(setPositionMsg);

                this.Position = setPositionMsg.Position;
            }
            break;

            case MessageType.ModifyPosition:
            {
                MsgModifyPosition modPosMsg = message as MsgModifyPosition;
                message.TypeCheck(modPosMsg);

                this.Position += modPosMsg.Position;
            }
            break;

            case MessageType.GetPosition:
            {
                MsgGetPosition getPosMsg = message as MsgGetPosition;
                message.TypeCheck(getPosMsg);

                getPosMsg.Position = this.position;
            }
            break;

            case MessageType.SetRotation:
            {
                MsgSetRotation setRotMsg = message as MsgSetRotation;
                message.TypeCheck(setRotMsg);

                this.Rotation = setRotMsg.Rotation;
            }
            break;

            case MessageType.ModifyRotation:
            {
                MsgModifyRotation modRotMsg = message as MsgModifyRotation;
                message.TypeCheck(modRotMsg);

                this.Rotation *= modRotMsg.Rotation;
            }
            break;

            case MessageType.GetRotation:
            {
                MsgGetRotation getRotMsg = message as MsgGetRotation;
                message.TypeCheck(getRotMsg);

                getRotMsg.Rotation = this.rotation;
            }
            break;

            case MessageType.GetVectorForward:
            {
                MsgGetVectorForward getVectorMsg = message as MsgGetVectorForward;
                message.TypeCheck(getVectorMsg);

                getVectorMsg.Forward = this.rotation.Forward;
            }
            break;

            case MessageType.GetVectorUp:
            {
                MsgGetVectorUp getVectorMsg = message as MsgGetVectorUp;
                message.TypeCheck(getVectorMsg);

                getVectorMsg.Up = this.rotation.Up;
            }
            break;

            case MessageType.GetVectorRight:
            {
                MsgGetVectorRight getVectorMsg = message as MsgGetVectorRight;
                message.TypeCheck(getVectorMsg);

                getVectorMsg.Right = this.rotation.Right;
            }
            break;

            case MessageType.LookAtPosition:
            {
                MsgLookAtPosition setPositionMsg = message as MsgLookAtPosition;
                message.TypeCheck(setPositionMsg);

                this.LookAt(setPositionMsg.Position);
            }
            break;

            case MessageType.Pitch:
            {
                MsgModifyPitch camPitchMsg = message as MsgModifyPitch;
                message.TypeCheck(camPitchMsg);

                Pitch(camPitchMsg.PitchAmount);
            }
            break;

            case MessageType.Yaw:
            {
                MsgModifyYaw camYawMsg = message as MsgModifyYaw;
                message.TypeCheck(camYawMsg);

                Yaw(camYawMsg.YawAmount);
            }
            break;

            case MessageType.YawWorldUp:
            {
                MsgModifyYawWorldUp camYawMsg = message as MsgModifyYawWorldUp;
                message.TypeCheck(camYawMsg);

                YawAroundWorldUp(camYawMsg.YawAmount);
            }
            break;

            case MessageType.SetParent:
            {
                MsgSetParent msgSetParent = message as MsgSetParent;
                message.TypeCheck(msgSetParent);

                SetParent(msgSetParent.ParentEntity);
            }
            break;

            case MessageType.RemoveChild:
            {
                MsgRemoveChild msgRemChild = message as MsgRemoveChild;
                message.TypeCheck(msgRemChild);

                RemoveChild(msgRemChild.Child);
            }
            break;

            case MessageType.ParentRemoved:
            {
                MsgParentRemoved msgParentRem = message as MsgParentRemoved;
                message.TypeCheck(msgParentRem);

                if (parentEntity == msgParentRem.Parent)
                {
                    SetParent(null);
                }
            }
            break;

            case MessageType.ParentAdded:
            {
                MsgParentAdded msgParentAdded = message as MsgParentAdded;
                message.TypeCheck(msgParentAdded);

                SetParent(msgParentAdded.Parent);
            }
            break;

            case MessageType.ChildRemoved:
            {
                MsgChildRemoved msgChildRem = message as MsgChildRemoved;
                message.TypeCheck(msgChildRem);

                if (msgChildRem.Child != null)
                {
                    this.children.Remove(msgChildRem.Data.UniqueID);
                }
            }
            break;

            case MessageType.ChildAdded:
            {
                MsgChildAdded msgChildAdd = message as MsgChildAdded;
                message.TypeCheck(msgChildAdd);

                if (msgChildAdd.Child != null && msgChildAdd.Child != this)
                {
                    this.children.Add(msgChildAdd.Data.UniqueID, msgChildAdd.Child);
                }
            }
            break;

            default:
                return(SendMessageThroughComponents(message));
            }

            // For messages handled directly by the Entity but aren't Request Protocol,
            // we still pass them to the Entity's components in case those components care.
            if (message.Protocol != MessageProtocol.Request)
            {
                return(SendMessageThroughComponents(message));
            }

            return(true);
        }