コード例 #1
0
        private void ControlBiped(InputManager input, float dTimeMs)
        {
            // If input is in line with avatar orientation, you get all movement, otherwise, some of the movement is dulled to get reorientation

            Vector3 moveInput = Vector3.Zero;

            if (ActiveInputMap.FullIntervalMap.ContainsKey(FullIntervalControlActions.MoveLeftRightRate))
            {
                moveInput.X += input.GetFullIntervalControlValue(ActiveInputMap.FullIntervalMap[FullIntervalControlActions.MoveLeftRightRate],
                                                                 InputIndex);
            }

            if (ActiveInputMap.FullIntervalMap.ContainsKey(FullIntervalControlActions.MoveDownUpRate))
            {
                moveInput.Z -= input.GetFullIntervalControlValue(ActiveInputMap.FullIntervalMap[FullIntervalControlActions.MoveDownUpRate],
                                                                 InputIndex);
            }

            float moveAmount = moveInput.Length();

            if (moveAmount > 0.0f)
            {
                // Transform (rotation only) the input from view space into world space
                Matrix cameraRotation = mReferenceCam.Transform;
                cameraRotation.Translation = Vector3.Zero;
                moveInput = Vector3.Transform(moveInput, cameraRotation);

                if (moveInput.X != 0.0f || moveInput.Z != 0.0f)
                {
                    moveInput.Y = 0.0f;
                    Quaternion directionDiff = SpaceUtils.GetSweptQuaternion(BepuConverter.Convert(mBipedControl.Controller.HorizontalViewDirection), moveInput);

                    mBipedControl.OrientationChange = directionDiff;
                }
            }

            mBipedControl.HorizontalMovement = Vector2.UnitY * moveAmount;

            // Crouching:
            if (input.CheckForBinaryInput(ActiveInputMap, BinaryControlActions.Crouch, InputIndex))
            {
                mBipedControl.DesiredMovementActions |= BipedControllerComponent.MovementActions.Crouching;
            }
            else
            {
                mBipedControl.DesiredMovementActions &= ~BipedControllerComponent.MovementActions.Crouching;
            }

            // Jumping:
            if (input.CheckForNewBinaryInput(ActiveInputMap, BinaryControlActions.Jump, InputIndex))
            {
                mBipedControl.DesiredMovementActions |= BipedControllerComponent.MovementActions.Jumping;
            }
            else
            {
                mBipedControl.DesiredMovementActions &= ~BipedControllerComponent.MovementActions.Jumping;
            }
        }
コード例 #2
0
        private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e)
        {
            float elapsedTime = (float)(e.GameTime.ElapsedGameTime.TotalSeconds);

            Actor avatar = GameResources.ActorManager.GetActorById(ActorId);
            BipedControllerComponent bipedControl = avatar.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control);

            // Update the camera.
            Vector3 desiredCameraPosition;

            if (mInputMode == InputMode.Aloof)
            {
                Matrix        cameraRotation = Matrix.CreateFromYawPitchRoll(mMmoCameraDesc.Yaw, mMmoCameraDesc.Pitch, 0.0f);
                BepuRay       boomRay        = new BepuRay(mAvatarBepuEntity.Position, BepuConverter.Convert(cameraRotation.Backward));
                RayCastResult result;

                GameResources.ActorManager.SimSpace.RayCast(boomRay, mMmoCameraDesc.Distance, CameraClipFilter, out result);

                desiredCameraPosition = result.HitObject != null?
                                        BepuConverter.Convert(BEPUutilities.Vector3.Lerp(result.HitData.Location, mAvatarBepuEntity.Position, 0.05f)) :
                                            BepuConverter.Convert(mAvatarBepuEntity.Position) + mMmoCameraDesc.Distance * cameraRotation.Backward;
            }
            else if (mInputMode == InputMode.Aiming)
            {
                Matrix viewRotation = Matrix.CreateWorld(Vector3.Zero, BepuConverter.Convert(
                                                             bipedControl.Controller.ViewDirection), Vector3.Up);
                desiredCameraPosition = BepuConverter.Convert(mAvatarBepuEntity.Position) + Vector3.Transform(
                    mAimingCameraOffset, viewRotation);
            }
            else
            {
                desiredCameraPosition = mCamera.Transform.Translation;
            }

            Vector3 newCameraPosition = desiredCameraPosition;

            Vector3 desiredCameraDirection;

            if (mInputMode == InputMode.Aloof)
            {
                desiredCameraDirection = BepuConverter.Convert(mAvatarBepuEntity.Position) - newCameraPosition;
            }
            else if (mInputMode == InputMode.Aiming)
            {
                desiredCameraDirection = BepuConverter.Convert(bipedControl.Controller.ViewDirection);
            }
            else
            {
                desiredCameraDirection = mCamera.Transform.Forward;
            }
            desiredCameraDirection.Normalize();

            Vector3 newCameraDirection = desiredCameraDirection;

            if (mCameraSmoothingEngaged)
            {
                Vector3    positionDelta  = desiredCameraPosition - mCamera.Transform.Translation;
                Quaternion directionDelta = SpaceUtils.GetSweptQuaternion(mCamera.Transform.Forward, desiredCameraDirection);

                const float POSITION_DELTA_THRESHHOLD  = 4.0f;
                const float DIRECTION_DELTA_THRESHHOLD = MathHelper.Pi / 16.0f;

                float positionDeltaLength = positionDelta.Length();
                float directionDeltaAngle = (float)(SpaceUtils.GetQuaternionAngle(directionDelta));

                float fractionComplete = Math.Min(POSITION_DELTA_THRESHHOLD / positionDeltaLength,
                                                  DIRECTION_DELTA_THRESHHOLD / directionDeltaAngle);

                if (fractionComplete < 1.0f)
                {
                    newCameraPosition = Vector3.Lerp(mCamera.Transform.Translation, desiredCameraPosition, fractionComplete);
                    Quaternion smoothedCamRotation = Quaternion.Slerp(Quaternion.Identity, directionDelta, fractionComplete);
                    newCameraDirection = Vector3.Transform(mCamera.Transform.Forward, smoothedCamRotation);
                }
            }
            else
            {
                mCameraSmoothingEngaged = true;
            }

            mCamera.Transform = Matrix.CreateWorld(newCameraPosition, newCameraDirection, Vector3.Up);
        }