Exemple #1
0
        /// <summary>
        /// Update position and orientation of body and neck
        /// </summary>
        private bool FrameStarted(FrameEvent evt)
        {
            if (Pauser.IsPaused)
                return true;

            // update position
            Vector3 derivedInterp = interpNode._getDerivedPosition();
            Vector3 derivedDerpy = this.RootNode._getDerivedPosition();

            Vector3 displacement = derivedInterp - derivedDerpy;
            this.RootNode.Translate(displacement * 6 * evt.timeSinceLastFrame);

            // update orientation of derpy
            Vector3 lookat_body = this.RootNode.Position - followKart.ActualPosition;
            Euler temp_body = bodyFacing.GetRotationTo(lookat_body, true, false, true);
            Radian tempTime = new Radian(evt.timeSinceLastFrame * 3f);
            temp_body.LimitYaw(tempTime);

            bodyFacing = bodyFacing + temp_body;
            this.RootNode.Orientation = bodyFacing;

            // update orientation of neck
            Vector3 lookat_neck = this.RootNode.ConvertWorldToLocalPosition(followKart.ActualPosition);
            Euler temp_neck = neckFacing.GetRotationTo(-lookat_neck, true, true, true);
            tempTime *= 1.5f;
            temp_neck.LimitYaw(tempTime);
            temp_neck.LimitPitch(tempTime);

            neckFacing = neckFacing + temp_neck;
            neckFacing.LimitYaw(NECK_YAW_LIMIT);
            neckFacing.LimitPitch(NECK_PITCH_LIMIT);
            neckBone.Orientation = neckFacing;

            return true;
        }
        /// <summary>
        /// Rotate the neck bone to face the kart. Will eventually need to redo this when we have multiple karts, to face whichever's nearest, etc.
        /// </summary>
        bool FrameStarted(FrameEvent evt)
        {
            if (!Pauser.IsPaused) {
                Vector3 lookat = RootNode.ConvertWorldToLocalPosition(followKart.ActualPosition);
                // temp is how much you need to rotate to get from the current orientation to the new orientation
                // we use -lookat because our bone points towards +Z, whereas this code was originally made for things facing towards -Z
                Euler temp = neckFacing.GetRotationTo(-lookat, true, true, true);
                // limit the offset so the head turns at a maximum of 3 radians per second
                Radian tempTime = new Radian(evt.timeSinceLastFrame * 3);
                temp.LimitYaw(tempTime);
                temp.LimitPitch(tempTime);

                neckFacing = neckFacing + temp;
                neckFacing.LimitYaw(NECK_YAW_LIMIT);
                neckFacing.LimitPitch(NECK_PITCH_LIMIT);
                neckbone.Orientation = neckFacing;
            }

            return true;
        }