Пример #1
0
        public void RefreshControllers()
        {
            PhysicsObject objectBase         = null;
            string        switchInstanceName = null;

            enableStartInfo     = true;
            switchPhysicsObject = null;

            for (int i = 0; i < 10; i++)
            {
                switchInstanceName = "Switch " + i.ToString();

                objectBase = scene.Factory.PhysicsObjectManager.Find(switchInstanceName + instanceIndexName);

                if (objectBase != null)
                {
                    userData = (MenuData)objectBase.UserControllers.PostTransformMethodArgs.UserDataObj;

                    userData.OldMouseState = demo.GetMouseState();

                    objectBase.UserControllers.PostTransformMethodArgs.UserDataObj = userData;
                }
            }

            objectBase = scene.Factory.PhysicsObjectManager.Find("Switch Right" + instanceIndexName);

            if (objectBase != null)
            {
                userData = (MenuData)objectBase.UserControllers.PostTransformMethodArgs.UserDataObj;

                userData.OldMouseState = demo.GetMouseState();

                objectBase.UserControllers.PostTransformMethodArgs.UserDataObj = userData;
            }

            objectBase = scene.Factory.PhysicsObjectManager.Find("Switch Left" + instanceIndexName);

            if (objectBase != null)
            {
                userData = (MenuData)objectBase.UserControllers.PostTransformMethodArgs.UserDataObj;

                userData.OldMouseState = demo.GetMouseState();

                objectBase.UserControllers.PostTransformMethodArgs.UserDataObj = userData;
            }
        }
Пример #2
0
        void SwitchLeft(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            float time = args.Time;

            MenuData userData = (MenuData)args.UserDataObj;

            string switchSliderConstraintName = userData.SwitchSliderConstraintName;
            int    sceneIndex  = userData.SceneIndex;
            int    switchIndex = userData.SwitchIndex;

            if (baseSceneIndex > 0)
            {
                objectBase.Material.SetAmbient(0.4f, 0.4f, 0.25f);
            }
            else
            {
                objectBase.Material.SetAmbient(0.4f, 0.4f, 0.4f);
            }

            PhysicsObject physicsObjectWithActiveCamera = scene.GetPhysicsObjectWithActiveCamera(0);

            if (physicsObjectWithActiveCamera == null)
            {
                return;
            }

            PhysicsCamera activeCamera = physicsObjectWithActiveCamera.Camera;

            if (activeCamera == null)
            {
                return;
            }

            Vector3 switchVelocity;

            ScreenToRayController screenToRayController = physicsObjectWithActiveCamera.InternalControllers.ScreenToRayController;

            Constraint switchSliderConstraint = scene.Factory.ConstraintManager.Find(switchSliderConstraintName);

            string sceneName = demo.Scenes[sceneIndex].SceneName;

            DemoMouseState mouseState    = demo.GetMouseState();
            DemoMouseState oldMouseState = userData.OldMouseState;
            int            deltaX        = mouseState.X - oldMouseState.X;
            int            deltaY        = mouseState.Y - oldMouseState.Y;

            if (switchSliderConstraint != null)
            {
                if (screenToRayController.IsHitPhysicsObject && (screenToRayController.HitPhysicsObject == objectBase))
                {
                    if (((switchPhysicsObject != objectBase) && !mouseState[MouseButton.Left] && !mouseState[MouseButton.Middle] && !mouseState[MouseButton.Right] && (Math.Abs(deltaX) + Math.Abs(deltaY) != 0)) || ((switchPhysicsObject == objectBase) && (switchSliderConstraint.ControlDistanceZ < -4.95f)) || ((switchPhysicsObject == objectBase) && (Math.Abs(deltaX) + Math.Abs(deltaY) != 0)))
                    {
                        enableStartInfo = false;

                        if (infoScreen != null)
                        {
                            infoScreen.EnableDrawing = false;
                        }

                        if (infoDescription != null)
                        {
                            infoDescription.EnableDrawing = false;
                        }

                        switchPhysicsObject = objectBase;

                        Vector3.Multiply(ref unitZ, -10.0f, out switchVelocity);
                        objectBase.MainWorldTransform.SetLinearVelocity(ref switchVelocity);
                        objectBase.MainWorldTransform.SetAngularVelocity(ref vectorZero);
                    }

                    if ((switchPhysicsObject == objectBase) && mouseState[MouseButton.Left] && !oldMouseState[MouseButton.Left] && (switchSliderConstraint.ControlDistanceZ <= -0.5f))
                    {
                        baseSceneIndex = Math.Max(baseSceneIndex - 1, 0);
                    }
                }
                else
                {
                    if ((switchPhysicsObject == objectBase) && (switchSliderConstraint.ControlDistanceZ >= -0.05))
                    {
                        if (infoScreen != null)
                        {
                            infoScreen.EnableDrawing = false;
                        }

                        if (infoDescription != null)
                        {
                            infoDescription.EnableDrawing = false;
                        }

                        switchPhysicsObject = null;
                    }
                }
            }

            userData.OldMouseState = mouseState;
            args.UserDataObj       = userData;
        }