コード例 #1
0
 // frame centered at cockpit location and aligned with camera direction
 public virtual Frame3f GetViewFrame2D()
 {
     return(new Frame3f(Vector3f.Zero, ActiveCamera.GetRotation()));
 }
コード例 #2
0
ファイル: FScene.cs プロジェクト: yoshi-1224/frame3Sharp
        public void Reset(bool bKeepBoundsObjects = true, bool bKeepLighting = true)
        {
            ClearHistory();

            ClearSelection();
            RemoveAllSceneObjects();
            foreach (var so in vDeleted)
            {
                so.Disconnect(true);
                so.RootGameObject.Destroy();
            }
            vDeleted.Clear();

            RemoveAllUIElements();

            LinkManager.RemoveAllLinks();

            SetCurrentTime(0);
            SelectionMask = null;

            // save bounds objects
            var         save_bounds = vBoundsObjects;
            fGameObject boundsGO    = null;

            if (bKeepBoundsObjects)
            {
                boundsGO = bounds_objects;
                boundsGO.SetParent(null, true);
            }

            // save lighting objects
            fGameObject lightingGO = null;

            if (bKeepLighting)
            {
                lightingGO = lighting_objects;
                lightingGO.SetParent(null, true);
            }

            // save camera
            CameraState camera_state = ActiveCamera.Manipulator().GetCurrentState(this);

            // make sure we get rid of any cruft
            sceneRoot.Destroy();

            // rebuild scene
            initialize_scene_root();

            // restore camera
            ActiveCamera.Manipulator().SetCurrentSceneState(this, camera_state);

            // restore bounds objects
            if (bKeepBoundsObjects)
            {
                bounds_objects.Destroy();
                boundsGO.SetParent(sceneRoot, true);
                bounds_objects = boundsGO;
                vBoundsObjects = save_bounds;
            }

            // restore lighting objects
            if (bKeepLighting)
            {
                lighting_objects.Destroy();
                lightingGO.SetParent(sceneRoot, true);
                lighting_objects = lightingGO;
            }
        }
コード例 #3
0
ファイル: CameraManager.cs プロジェクト: ErtyHackward/utopia
 public override void VTSUpdate(double interpolationHd, float interpolationLd, float elapsedTime)
 {
     ActiveCamera.VTSUpdate(interpolationHd, interpolationLd, elapsedTime);
 }
コード例 #4
0
        public override void OnLoad()
        {
            //handle movement
            rnd = new Random();
            KeyboardHandler.RegisterKeyDown(Key.W, () => { playerController.MoveForward(); });
            KeyboardHandler.RegisterKeyDown(Key.S, () => { playerController.MoveBack(); });
            KeyboardHandler.RegisterKeyDown(Key.A, () => { playerController.MoveLeft(); });
            KeyboardHandler.RegisterKeyDown(Key.D, () => { playerController.MoveRight(); });
            KeyboardHandler.RegisterKeyDown(Key.ShiftLeft, () => { /*playerController.Translate(-Vector3.UnitY);*/ });
            KeyboardHandler.RegisterKeyDown(Key.Space, () => { /*playerController.Jump(); */ playerController.Translate(Vector3.UnitY); });
            KeyboardHandler.RegisterKeyDown(Key.Escape, () => { Window.Close(); });
            MouseHandler.MouseLocked   = true;
            MouseHandler.CursorVisible = false;
            //KeyboardHandler.RegisterKeyDown(Key.Q, () => { ActiveCamera.Transform.LocalRotation = ActiveCamera.Transform.LocalPosition.LookAt(Vector3.Zero, Vector3.UnitY); });
            KeyboardHandler.RegisterKeyDown(Key.E, () =>
            {
                Vector2 sp = new Vector2(MouseHandler.X, MouseHandler.Y);
                GameObjectFactory.CreateCube(ActiveCamera.Transform.LocalPosition + ActiveCamera.Transform.LocalForward * 4f, new Vector3(Mathf.Rnd, Mathf.Rnd, Mathf.Rnd));                 //
            });
            MouseHandler.OnMouseMove += MouseHandler_OnMouseMove;
            MouseHandler.RegisterButtonDown(MouseButton.Left, () =>
            {
                Vector2 sp = new Vector2(MouseHandler.X, MouseHandler.Y);
                var go     = GameObjectFactory.CreateCube(ActiveCamera.Transform.LocalPosition + ActiveCamera.ScreenToDirection(sp) * 2f, new Vector3(0.3f, 0.3f, 0.3f));             //
                go.Component <MeshRenderer>().Parameters.SetParameter <float>("_color", Mathf.Rnd, Mathf.Rnd, Mathf.Rnd, 1);
                go.AddComponent <Rigidbody>().SetCollisionBox(Vector3.One * 0.15f, Vector3.One * 0.3f);
            });

            Log.ShowDebug = true;
            Log.Debug("Creating gui");
            SceneRenderer.AmbientLight      = new Vector3(0.05f, 0.05f, 0.05f);
            SceneRenderer.SkylightColor     = new Vector3(1, 1, 1);
            SceneRenderer.SkylightDirection = new Vector3(1, 0, 0);
            //Setup font
            defaultFont = new Font("arial", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ß!\"§$%&/()=?`+#*'äüö-.,:; ", 68);
            //Setup Camera

            ActiveCamera.GameObject.Transform.Position = new Vector3(4, 3, 4);
            playerController = ActiveCamera.GameObject.AddComponent <PlayerControllerGhost>();
            //Setup Multisampler & Screen buffer
            var sf = SurfaceFormat.Surface2D;

            sf.Multisampling = 1;
            multisampler     = new Surface(Window.Width, Window.Height, sf);

            postEffect  = new Material(Shaders["screenCA"], RenderMode.Opaque);
            sf          = SurfaceFormat.Surface2D;
            sf.WrapMode = TextureWrapMode.MirroredRepeat;
            postEffect.AddTexture("_tex", new Surface(Window.Width, Window.Height, sf));
            postEffect.Parameters.SetParameter <float>("baseBlur", 0f);
            postEffect.Parameters.SetParameter <float>("blur", 2f);
            postEffect.Parameters.SetParameter <float>("chromatic", 0.1f);

            //Create base plate
            var basePlate = GameObjectFactory.CreatePlane(new Vector3(15, 15, 15), Vector3.Zero);

            basePlate.Component <MeshRenderer>().Parameters.SetParameter <float>("_color", 1, 1, 1, 1);
            var prb = basePlate.AddComponent <Rigidbody>();

            prb.SetCollisionBox(new Vector3(7.5f, -0.25f, 7.5f), new Vector3(15, 1f, 15));
            prb.MakeStatic();
            //Create sun image plane
            sun = new Surface("sun.png");
            Material sunMat = new Material(Shaders["lit"], RenderMode.Translucent);

            sunMat.AddTexture("_tex", sun);
            sunMat.Parameters.SetParameter <float>("_color", 1f, 1f, 0f, 1f);
            GameObjectFactory.CreatePlane(Vector3.One * 4, new Vector3(3, 2, 0)).Component <MeshRenderer>().Material = sunMat;
            //red cube
            var cu = GameObjectFactory.CreateCube(new Vector3(0, 3.5f, 0), Vector3.One * 2f);

            cu.Component <MeshRenderer>().Parameters.SetParameter <float>("_color", 1, 0, 0, 1);
            //prb = cu.AddComponent<Rigidbody>();
            //prb.SetCollisionConvexMesh(cu.Component<MeshRenderer>().Mesh, Vector3.One * 0.5f, cu.Transform.Scale);
            //prb.SetMass(8.0f);
            //prb.Body.IsStatic = true;
            //Create gui
            var guiObj = CreateGameObject("GUI");

            gui = guiObj.AddComponent <Gui>();
            gui.Setup(Window.Width, Window.Height);
            Vector2 ss = ActiveCamera.NearplaneSize;

            guiObj.Transform.LocalPosition = new Vector3(ss.X / -2, ss.Y / 2, -(ActiveCamera.ZNear + 0.001f));
            gui.Transform.LocalScale       = new Vector3(ss.X, 1, ss.Y);
            guiObj.Transform.Rotate(guiObj.Transform.LocalRight, Mathf.Deg2Rad(90));
            guiObj.Parent = CameraContainer;
            //Mesh p = Mesh.LoadOBJ("E:\\Coding\\WIP\\SharpGL\\Models\\BumbleBee\\RB-BumbleBee.obj");

            /* var robot = CreateGameObject("car");
             * robot.Transform.LocalScale = new Vector3(0.005f, 0.005f, 0.005f);
             * robot.Transform.Rotate(Vector3.UnitX,- Mathf.PI/2);
             * robot.Transform.Translate(new Vector3(-2f, 0.4f, 0));
             * var robotM = robot.AddComponent<MeshRenderer>();
             * robotM.Mesh = p;
             * robotM.Material = Materials["lit"];
             * robotM.Parameters.SetParameter<float>("_color", 0.3f, 0.3f, 0.4f, 1f);*/
            Mesh p = Mesh.LoadOBJ("E:\\Coding\\WIP\\SharpGL\\Models\\911\\Porsche_911_GT2.obj");

            car = CreateGameObject("car");
            //robot.Transform.LocalScale = new Vector3(0.005f, 0.005f, 0.005f);
            // robot.Transform.Rotate(Vector3.UnitX, -Mathf.PI / 2);
            car.Transform.Translate(new Vector3(1f, 1f, 0));
            var carM = car.AddComponent <MeshRenderer>();

            carM.Mesh     = p;
            carM.Material = Materials["lit"];
            carM.Parameters.SetParameter <float>("_color", 0.6f, 0.3f, 0.4f, 1f);
            //setup rotating cubes
            rotator = GameObjectFactory.CreateCube(new Vector3(-4, 0, 2), Vector3.One);
            GameObjectFactory.CreateCube(new Vector3(2, 0, 2), Vector3.One).Parent = rotator;

            //Create plane for camera image displaying
            canvas = new Canvas(1024, 1024, false);
            canvas.Clear(0, 0, 0, 0.5f);
            canvas.DrawText(",.-+ A B C ABC def 123", Shaders["text"], defaultFont, 0.5f, new Vector2(300, 300), new Vector4(1, 0, 0, 1));
            var plane = GameObjectFactory.CreatePlane(Vector3.One * 4, new Vector3(3, 4, -2));

            plane.Transform.Rotate(Vector3.UnitX, 1f);
            planeRenderer = plane.Component <MeshRenderer>();
            (planeRenderer.Material = new Material(Shaders["unlit"], RenderMode.Opaque)).AddTexture("_tex", canvas.Surface);
        }
コード例 #5
0
 public void TypesOfCameras(ActiveCamera activeCamera)
 { // 0: The firstPerson player camera. 1: The diceCam is active with this num. 2: The third person player camera is active. 3: The TVcam is active in this turn.
     cam.transform.SetParent(camParentObjects[(int)activeCamera]);
     cam.position    = camParentObjects[(int)activeCamera].position;
     cam.eulerAngles = camParentObjects[(int)activeCamera].eulerAngles;
 }
コード例 #6
0
    public void CameraChanged(string cameraType)
    {


        switch (cameraType)
        {
            case "Title":
                _cameraEnum = ActiveCamera.Title;
                break;
            case "PlayerFly":
                _cameraEnum = ActiveCamera.PlayerFly;
                break;
            case "PlayerGrounded":
                _cameraEnum = ActiveCamera.PlayerGrounded;
                break;
        }

        //change to make sure the Update() changes the active camera
        cameraChanged = true;
        //allows for camera smoothing function to run
        cameraSmooth = true;
        cameraTimer = Time.time;
    }
コード例 #7
0
        private void ApplyKeyBindings(FrameEventArgs e)
        {
            Vector3 direction = Vector3.Zero;
            bool    rotated   = false;

            slowFlySpeed  = Keyboard[Key.AltLeft];
            fastFlySpeed  = Keyboard[Key.ShiftLeft];
            movementSpeed = fastFlySpeed ? 10.0f : 1.0f;
            movementSpeed = slowFlySpeed ? 0.01f : movementSpeed;



            // Calibrator (for translation debugging)
            if (Keyboard[Key.Number1])
            {
                ActiveCamera.calibTrans.X += ActiveCamera.calibSpeed.X;
            }
            if (Keyboard[Key.Number2])
            {
                ActiveCamera.calibTrans.X -= ActiveCamera.calibSpeed.X;
            }
            if (Keyboard[Key.Number3])
            {
                ActiveCamera.calibTrans.Y += ActiveCamera.calibSpeed.Y;
            }
            if (Keyboard[Key.Number4])
            {
                ActiveCamera.calibTrans.Y -= ActiveCamera.calibSpeed.Y;
            }
            if (Keyboard[Key.Number5])
            {
                ActiveCamera.calibTrans.Z += ActiveCamera.calibSpeed.Z;
            }
            if (Keyboard[Key.Number6])
            {
                ActiveCamera.calibTrans.Z -= ActiveCamera.calibSpeed.Z;
            }

            // Calibrator (for orientation debugging)
            if (Keyboard[Key.Number6])
            {
                ActiveCamera.calibOrient.X += ActiveCamera.calibSpeed.X;
            }
            if (Keyboard[Key.Number7])
            {
                ActiveCamera.calibOrient.X -= ActiveCamera.calibSpeed.X;
            }
            if (Keyboard[Key.Number8])
            {
                ActiveCamera.calibOrient.Y += ActiveCamera.calibSpeed.Y;
            }
            if (Keyboard[Key.Number9])
            {
                ActiveCamera.calibOrient.Y -= ActiveCamera.calibSpeed.Y;
            }
            if (Keyboard[Key.Minus])
            {
                ActiveCamera.calibOrient.Z += ActiveCamera.calibSpeed.Z;
            }
            if (Keyboard[Key.Plus])
            {
                ActiveCamera.calibOrient.Z -= ActiveCamera.calibSpeed.Z;
            }



            if (Keyboard[Key.Escape] || Keyboard[Key.Q])
            {
                // QUIT APPLICATION
                if (window.WindowState == WindowState.Fullscreen)
                {
                    window.WindowState = WindowState.Normal;
                }

                X3DProgram.Quit();
            }
            if (Keyboard[Key.P])
            {
                // LOAD NEW SCENE
                if (window.WindowState == WindowState.Fullscreen)
                {
                    window.WindowState = WindowState.Normal;
                }

                X3DProgram.Restart();
            }

            if (Keyboard[Key.R])
            {
                // RESET CAMERA POSITION+ORIENTATION
                ActiveCamera.Reset();
            }

            if (NavigationInfo.NavigationType != NavigationType.Examine)
            {
                if (Keyboard[Key.T])
                {
                    ActiveCamera.Fly(playerDirectionMagnitude * movementSpeed);
                }
                if (Keyboard[Key.G])
                {
                    ActiveCamera.Fly(-playerDirectionMagnitude * movementSpeed);
                }

                if (Keyboard[Key.W])
                {
                    ActiveCamera.Walk(playerDirectionMagnitude * movementSpeed);
                    //direction += ActiveCamera.Direction * playerDirectionMagnitude;
                }
                if (Keyboard[Key.S])
                {
                    ActiveCamera.Walk(-playerDirectionMagnitude * movementSpeed);
                    //direction -= ActiveCamera.Direction * playerDirectionMagnitude;
                }
                if (Keyboard[Key.A])
                {
                    ActiveCamera.Strafe(playerDirectionMagnitude * movementSpeed);
                    //ActiveCamera.Right = ActiveCamera.Up.Cross(ActiveCamera.Direction);
                    //direction += ActiveCamera.Right * playerDirectionMagnitude;
                }
                if (Keyboard[Key.D])
                {
                    ActiveCamera.Strafe(-playerDirectionMagnitude * movementSpeed);
                    //ActiveCamera.Right = ActiveCamera.Up.Cross(ActiveCamera.Direction);
                    //direction -= ActiveCamera.Right * playerDirectionMagnitude;
                }

                #region G.3 Emulate pointing device Key Bindings

                if (Keyboard[Key.Left])
                {
                    //ActiveCamera.Horizon();
                    //ActiveCamera.Yaw(-10.0f * 0.007f);
                    ActiveCamera.ApplyYaw(-playerDirectionMagnitude * 0.3f);
                    //ActiveCamera.ApplyRotation();

                    //this.heading += 1.0f;
                    //this.yrot = this.heading;

                    rotated = true;
                }
                if (Keyboard[Key.Right])
                {
                    //ActiveCamera.Horizon();
                    //ActiveCamera.Yaw(10.0f * 0.007f);
                    ActiveCamera.ApplyYaw(playerDirectionMagnitude * 0.3f);
                    //ActiveCamera.ApplyRotation();
                    //this.heading -= 1.0f;
                    //this.yrot = this.heading;

                    rotated = true;
                }
                if (Keyboard[Key.Up])
                {
                    //ActiveCamera.Pitch(10.0f * 0.007f);
                    ActiveCamera.ApplyPitch(-playerDirectionMagnitude * 0.3f);
                    //ActiveCamera.ApplyRotation();

                    //this.xpos += (float)Math.Sin(this.heading * Math.PI / 180.0) * 0.05f;
                    //this.zpos += (float)Math.Cos(this.heading * Math.PI / 180.0) * 0.05f;
                    //if (this.walkbiasangle >= 359.0f)
                    //    this.walkbiasangle = 0.0f;
                    //else
                    //    this.walkbiasangle -= 5.0f;
                    //this.walkbias = (float)Math.Sin(this.walkbiasangle * Math.PI / 180.0) / 10.0f;

                    rotated = true;
                }
                if (Keyboard[Key.Down])
                {
                    //ActiveCamera.Pitch(-10.0f * 0.007f);
                    ActiveCamera.ApplyPitch(playerDirectionMagnitude * 0.3f);
                    //ActiveCamera.ApplyRotation();

                    //this.xpos -= (float)Math.Sin(this.heading * Math.PI / 180.0) * 0.05f;
                    //this.zpos -= (float)Math.Cos(this.heading * Math.PI / 180.0) * 0.05f;
                    //if (this.walkbiasangle >= 359.0f)
                    //    this.walkbiasangle = 0.0f;
                    //else
                    //    this.walkbiasangle += 10.0f;
                    //this.walkbias = (float)Math.Sin(this.walkbiasangle * Math.PI / 180.0) / 10.0f;

                    rotated = true;
                }

                if (Keyboard[Key.Number0])
                {
                    ActiveCamera.ApplyRoll(-0.1f);
                    rotated = true;
                }
                if (Keyboard[Key.Number9])
                {
                    ActiveCamera.ApplyRoll(0.1f);
                    rotated = true;
                }

                #endregion
            }

            if (rotated)
            {
                ActiveCamera.ApplyRotation();
            }
        }
コード例 #8
0
 // Use this for initialization
 void Start()
 {
     _cameraEnum = ActiveCamera.PlayerGrounded;
     _mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
 }
コード例 #9
0
    private void ShowTVQuestions()
    {
        if (gameCycle == GameCycle.FourthStep)
        {
            AlternateInterface(3);
            RandomTestSelection();
            activeCamera = ActiveCamera.TVCamera;
            camMReference.TypesOfCameras(activeCamera);
            animReference.TVAnimations(true);

            timerToLooseQuestion = 20f;
            while (timerToLooseQuestion > 0)
            {
                if (questionState == QuestionState.Answered)
                {
                    AnswerResult(buttonsGame.SendAnswerResult());
                    break;
                }
                else if (questionState == QuestionState.NotAnswered)
                {
                    timerToLooseQuestion -= Time.time;
                    if (timerToLooseQuestion <= 0)
                    {
                        StartCoroutine(TimeToEndTurn(4f));
                    }
                }
            }
        }
        void RandomTestSelection()
        {
            randomQuestion = Random.Range(0, generalCultureQuestions.Length);
            buttonsGame.ReceiveRandomValue(randomQuestion);
            uIGameReference.QuestionAssignation(randomQuestion, 0);
            randomAnswerList  = new List <int>(3);
            randomWrongAnswer = new List <int>(2);
            for (int i = 0; i < randomAnswerList.Capacity; i++)
            {
                randomSelections      = Random.Range(0, randomAnswerList.Capacity);
                randomWrongSelections = Random.Range(0, randomWrongAnswer.Capacity);
                if (randomAnswerList.Capacity != 1)
                {
                    if (randomWrongAnswer.Capacity != 1)
                    {
                        uIGameReference.AnswerAssignations(1, randomSelections, randomQuestion);
                    }
                    else
                    {
                        uIGameReference.AnswerAssignations(2, randomSelections, randomQuestion);
                    }
                    randomAnswerList.Remove(randomSelections);
                    randomWrongAnswer.Remove(randomWrongSelections);
                }
                else
                {
                    uIGameReference.AnswerAssignations(3, randomSelections, randomQuestion);
                }
            }
        }

        void AnswerResult(bool isAcerted)
        {
            platformScript.SendCurrentPlatform(wayPoints[currentTarget].position, platformType);
            if (isAcerted && platformType != PlatformType.Neutral)
            {
                MovingTypeAssignation(true);
                gameCycle = GameCycle.ThirdStep;
            }
            else if (isAcerted == false && platformType != PlatformType.Neutral)
            {
                MovingTypeAssignation(false);
            }

            uIGameReference.QuestionAssignation(randomQuestion, 1);
            if (platformType == PlatformType.Neutral)
            {
                StartCoroutine(TimeToEndTurn(4f));
            }
        }

        void MovingTypeAssignation(bool isAcerted)
        {
            if (isAcerted)
            {
                switch ((int)platformType)
                {
                case 0: movingType = MovingType.Waiting; break;

                case 1: movingType = MovingType.Advancing; break;

                case 2: movingType = MovingType.Waiting; break;

                case 3: movingType = MovingType.Teleporting; break;
                }
            }
            else
            {
                switch ((int)platformType)
                {
                case 0: movingType = MovingType.Waiting; break;

                case 1: movingType = MovingType.Waiting; break;

                case 2: movingType = MovingType.Reversing; break;

                case 3: movingType = MovingType.Teleporting; break;
                }
            }
        }

        void EventLimiter() // funcion que cumple el proposito de limitar el maximo de movimiento
        {
            //if (intAdvanceLimit >= 2)
            //    isLimAdvanceOver = true;
            //else if (intReverseLimit >= 2)
            //    isLimReverseOver = true;
            //else if (intMisteryLimit >= 2)
            //    isLimMisteryOver = true;
            //else
            //{
            //    isLimAdvanceOver = false;
            //    isLimReverseOver = false;
            //    isLimMisteryOver = false;
            //}
        }
    }
コード例 #10
0
ファイル: FContext.cs プロジェクト: Alan-Baylis/frame3Sharp
        void HandleInput_MouseOrGamepad()
        {
            // update mouse/gamepad cursor
            MouseController.Update();

            // have to do this after cursor update in case hotkey uses mouse position
            HandleKeyboardInput();

            // create our super-input object  (wraps all supported input types)
            InputState input = new InputState();

            input.Initialize_MouseGamepad(this);
            lastInputState = input;

            CameraInteractionState eCamState = (MouseCameraController != null)
                ? MouseCameraController.CheckCameraControls(input) : CameraInteractionState.Ignore;

            if (eCamState == CameraInteractionState.BeginCameraAction)
            {
                TerminateHovers(input);

                bInCameraControl = true;
                ActiveCamera.SetTargetVisible(true);
            }
            else if (eCamState == CameraInteractionState.EndCameraAction)
            {
                bInCameraControl = false;
                ActiveCamera.SetTargetVisible(false);
            }
            else if (bInCameraControl)
            {
                ActiveCamera.SetTargetVisible(true);
                MouseCameraController.DoCameraControl(Scene, ActiveCamera, input);
            }
            else
            {
                // run override behaviors
                overrideBehaviors.SendOverrideInputs(input);

                input.MouseGamepadCaptureActive = (captureMouse != null);

                if (InCaptureMouse)
                {
                    Capture cap = captureMouse.element.UpdateCapture(input, captureMouse.data);
                    if (cap.state == CaptureState.Continue)
                    {
                        // (carry on)
                    }
                    else if (cap.state == CaptureState.End)
                    {
                        captureMouse = null;
                    }
                }
                else
                {
                    // this is very simplistic...needs to be rewritten like space controllers

                    List <CaptureRequest> vRequests = new List <CaptureRequest>();
                    inputBehaviors.CollectWantsCapture(input, vRequests);
                    if (vRequests.Count > 0)
                    {
                        // end outstanding hovers
                        TerminateHovers(input);

                        // select one of the capture requests. technically we could end
                        //  up with none successfully Begin'ing, but behaviors should be
                        //  doing those checks in WantCapture, not BeginCapture !!
                        vRequests.OrderBy(x => x.element.Priority);
                        Capture capReq = null;
                        for (int i = 0; i < vRequests.Count && capReq == null; ++i)
                        {
                            if (vRequests[i].side != CaptureSide.Any)
                            {
                                continue;       // not possible in mouse paths...
                            }
                            // before we actually begin capture we will complete any text editing
                            // [RMS] perhaps this should be configurable for behavior? Some behaviors
                            // do not require this (eg view controls...)
                            completeTextEntryOnFocusChange();

                            Capture c = vRequests[i].element.BeginCapture(input, vRequests[i].side);
                            if (c.state == CaptureState.Begin)
                            {
                                capReq = c;
                            }
                        }

                        captureMouse = capReq;
                    }
                }

                // if we don't have a capture, do hover
                if (captureMouse == null)
                {
                    inputBehaviors.UpdateHover(input);
                }
            }
        }
コード例 #11
0
        public void Draw(GameTime gt, SpriteBatch sb)
        {
            if (_laptopFrame == 0)
            {
                return;
            }

            if (_laptopFrame < LAPTOP_FLIPUP_FRAMES - 1)
            {
                laptopAnim.Draw(sb, _laptopFrame - 1, Vector2.Zero);
            }

            if (UI.State != UIState.Laptop)
            {
                return;
            }

            if (Level.LaptopBattery <= 0.0f)
            {
                if (_powerDownFrame < POWERDOWN_FRAMES)
                {
                    powerDownSprites[_powerDownFrame].Draw(sb, Vector2.Zero);
                }
            }
            else if (Level.Monsters.Redman.IsRedScreenOfDeathUp)
            {
                miscScreens["RedScreenOfDeath"].Draw(sb, Vector2.Zero);
            }
            else if (IsRebooting)
            {
                miscScreens["EggOS"].Draw(sb, Vector2.Zero);

                RectangleF sourceRect = new RectangleF(0, 0, REBOOT_BAR_SIZE.X * RebootProgress, REBOOT_BAR_SIZE.Y);
                miscScreens["RebootBar"].Draw(sb, REBOOT_BAR_OFFSET, sourceRect, Color.White);

                miscScreens["LaptopVignette"].Draw(sb, Vector2.Zero);
            }
            else
            {
                if (_isStaticIntermittent && _staticScreensLeft > 0)
                {
                    UI.DrawNoise(sb, 255);
                }
                else
                {
                    Vector2 offset = WINDOW_OFFSET;
                    if (CAMERAS_WITH_PANNING.Contains(ActiveCamera))
                    {
                        offset += Vector2.UnitX * cameraOffsets[ActiveCamera].CameraOffset;
                    }

                    cameraRoomSprites[ActiveCamera.ToString()].Draw(sb, offset);

                    Level.Monsters.DrawOnCamera(sb, offset, ActiveCamera);
                }

                UI.DrawNoise(sb, OnafMain.STATIC_OVERLAY_ALPHA);
                miscScreens["ChillBar"].Draw(sb, new Vector2(0, _chillBarOffset));

                if (_staticScreensLeft > 0)
                {
                    staticBars[_currentStaticScreen].Draw(sb, Vector2.Zero);
                }

                miscScreens["Camera"].Draw(sb, Vector2.Zero);
                miscScreens["LaptopVignette"].Draw(sb, Vector2.Zero);

                gameUI["Map"].Draw(sb, MAP_OFFSET);

                string icon = _roomIconBright ? "CamSelectedLight" : "CamSelectedDark";
                gameUI[icon].Draw(sb, MAP_OFFSET + MAP_CAMERA_OFFSETS[ActiveCamera]);

                icon = _youIconBright ? "YouSmall" : "YouLarge";
                gameUI[icon].Draw(sb, YOU_ICON_OFFSET);

                foreach (KeyValuePair <CameraIndex, Vector2> kvp in MAP_CAMERA_OFFSETS)
                {
                    string str = "CAM\n" + ((int)kvp.Key);
                    sb.DrawString(retroFontSmall, str, kvp.Value + MAP_OFFSET + MAP_TEXT_OFFSET, Color.White);
                }

                Level.Monsters.DrawOnLaptop(sb);
            }
        }
コード例 #12
0
ファイル: FContext.cs プロジェクト: Alan-Baylis/frame3Sharp
        // Use this for initialization
        public void Start(SceneOptions options)
        {
            this.options = options;

            DebugUtil.LogLevel = options.LogLevel;
            FPlatform.InitializeMainThreadID();

            // initialize VR platform if VR is active
            if (gs.VRPlatform.VREnabled)
            {
                if (options.Use2DCockpit)
                {
                    throw new Exception("FContext.Start: cannot use 2D Orthographic Cockpit with VR!");
                }
                if (options.SpatialCameraRig != null)
                {
                    gs.VRPlatform.Initialize(options.SpatialCameraRig);
                }
            }

            InputExtension.Get.Start();

            nextFrameActions = new ActionSet();

            // intialize camera stuff
            camTracker = new CameraTracking();
            camTracker.Initialize(this);

            GetScene();
            if (options.SceneInitializer != null)
            {
                options.SceneInitializer.Initialize(GetScene());
            }

            if (options.DefaultGizmoBuilder != null)
            {
                transformManager = new TransformManager(options.DefaultGizmoBuilder);
            }
            else
            {
                transformManager = new TransformManager(new AxisTransformGizmoBuilder());
            }
            if (options.EnableTransforms)
            {
                transformManager.Initialize(this);
            }

            toolManager = new ToolManager();
            toolManager.Initialize(this);
            toolManager.OnToolActivationChanged += OnToolActivationChanged;

            MouseController.Start();
            SpatialController.Start();

            // [RMS] hardcode starting cam target point to origin
            ActiveCamera.SetTarget(Vector3f.Zero);

            if (options.MouseCameraControls != null)
            {
                MouseCameraController = options.MouseCameraControls;
            }

            // apply initial transformation to scene
            ActiveCamera.Manipulator().SceneTranslate(Scene, SceneGraphConfig.InitialSceneTranslate, true);

            // create behavior sets
            inputBehaviors    = new InputBehaviorSet();
            overrideBehaviors = new InputBehaviorSet();

            // cockpit needs to go last because UI setup may depend on above
            cockpitStack = new Stack <Cockpit>();
            if (options.EnableCockpit)
            {
                PushCockpit(options.CockpitInitializer);
            }


            captureMouse     = null;
            captureTouch     = null;
            captureLeft      = captureRight = null;
            bInCameraControl = false;

            // [RMS] this locks cursor to game unless user presses escape or exits
            if (FPlatform.IsUsingVR() || options.UseSystemMouseCursor == false)
            {
                Cursor.lockState = CursorLockMode.Locked;
            }

            // set hacky hackenstein global
            ActiveContext_HACK = this;

            startup_checks();
        }
コード例 #13
0
 /// <summary>
 /// 보드에서 드레그로 화면을 움직인다
 /// InputManager에서 호출하게됨
 /// </summary>
 public void CameraDragMoving(Vector3 direction)
 {
     ActiveCamera.MovingCamera(direction, cameraState);
 }
コード例 #14
0
 // Use this for initialization
 void Start()
 {
     _cameraEnum = ActiveCamera.PlayerGrounded;
     _mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
 }
コード例 #15
0
 void onMouseScroll()
 {
     ActiveCamera.ZoomScreen(Input.mousePosition, ZoomSpeed * Input.mouseScrollDelta.y);
 }
コード例 #16
0
    private void WaypointDisplacing()
    {
        if (gameCycle == GameCycle.ThirdStep)
        {
            AlternateInterface(2);
            activeCamera = ActiveCamera.ThirdPerson;
            camMReference.TypesOfCameras(activeCamera);
            charCReference.PlayerMove(specificVoidTransform, wayPoints, UpdatingTemporalTarget(), UpdatingCurrentTarget());
            uIGameReference.ShowMovingText(movingType, diceNumber, UpdatingCurrentTarget());
        }
        int UpdatingTemporalTarget()
        {
            if (specificVoidTransform.position == temporalTransform.position && temporalTarget < currentTarget || temporalTarget > currentTarget)
            {
                switch ((int)movingType)
                {
                case 0: break;

                case 1: temporalTarget++; moveAlterateSign = 1; break;

                case 2: temporalTarget--; moveAlterateSign = -1; break;

                case 3: StartCoroutine(TimeToWaitAfterTeleport()); break;
                }
                IEnumerator TimeToWaitAfterTeleport()
                {
                    yield return(new WaitForSeconds(2f));

                    temporalTarget = currentTarget;
                }
            }
            return(temporalTarget);
        }

        int UpdatingCurrentTarget()
        {
            if (specificVoidTransform.position == temporalTransform.position && specificVoidTransform.position == targetTransform.position)
            {
                if (currentTarget + diceNumber <= wayPoints.Length - 1)
                {
                    currentTarget = temporalTarget + (diceNumber * moveAlterateSign);
                }
                else if (temporalTarget + (diceNumber * moveAlterateSign) < 0)
                {
                    currentTarget = 0;
                }
                else
                {
                    currentTarget = wayPoints.Length - 1;
                }
            }
            return(currentTarget);
        }

        if (temporalTarget == currentTarget)
        {
            StartCoroutine(TimeWaitingToTVEvent());
            IEnumerator TimeWaitingToTVEvent()
            {
                yield return(new WaitForSeconds(2f));

                gameCycle = GameCycle.FourthStep;
            }
        }
    }
コード例 #17
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            float delta = (float)gameTime.ElapsedGameTime.TotalSeconds;
            Vector3 moveVector = Vector3.Zero;
            bool step = false;

            KeyboardState keyState = Keyboard.GetState();
            if (lastKey == null)
            {
                lastKey = keyState;
            }
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || keyState.IsKeyDown(Keys.Escape))
                this.Exit();

            // TODO: complete keyboard logic here
            foreach (Keys k in keyState.GetPressedKeys()) {
                switch (k)
                {
                    case Keys.D1:
                    case Keys.D2:
                    case Keys.D3:
                        activeCamera = (ActiveCamera)(k - Keys.D0);
                        break;
                    case Keys.P:
                        if (lastKey.IsKeyUp(Keys.P))
                        {
                            showPIP = !showPIP; //only togle on first key press
                        }
                        break;
                    case Keys.W: //free camera up
                    case Keys.Up:
                        moveVector.X -= 1f;
                        break;
                    case Keys.S: //free camera down
                    case Keys.Down:
                        moveVector.X = 1f;
                        break;
                    case Keys.A: //free camera left
                    case Keys.Left:
                        moveVector.Y -= 1f;
                        break;
                    case Keys.D: //free camera right
                    case Keys.Right:
                        moveVector.Y = 1f;
                        break;
                    case Keys.N: //step scene forward
                        if (pause)
                        {
                            if (lastKey.IsKeyUp(Keys.N))
                            {
                                step = true;
                                Physics.Integrate(delta);
                            }
                        }
                        break;
                    case Keys.Enter: //Reset
                        if (lastKey.IsKeyUp(Keys.Enter))
                        {
                            machine.init();
                        }
                        break;
                    case Keys.Space: //Start/Stop
                        if (lastKey.IsKeyUp(Keys.Space))
                        {
                            pause = !pause;
                            //TODO: also set pause state of physics engine
                            Physics.Enabled = !pause;
                        }
                        break;
                }
            }

            // TODO: compile mouse logic here
            curMouse = Mouse.GetState();
            if (lastMouse == null)
            {
                lastMouse = curMouse;
            }

            Vector2 mouseDelta = new Vector2(
                    captureMouse ? curMouse.X - mouseCenterX : 0,
                    captureMouse ? curMouse.Y - mouseCenterY : 0
                );

            if (activeCamera == ActiveCamera.Free || showPIP)
            {
                this.CaptureMouse = curMouse.RightButton == ButtonState.Pressed;

                FreeMove.Pitch -= mouseDelta.Y * DefaultMouseSensitivity;
                FreeMove.Yaw -= mouseDelta.X * DefaultMouseSensitivity;

                //freemove camera logic
                if (moveVector != Vector3.Zero)
                {
                    moveVector.Normalize();
                    moveVector *= movementSpeed * delta;
                    FreeMove.Move(moveVector);
                }
            }

            if (captureMouse)
            {
                Mouse.SetPosition(mouseCenterX, mouseCenterY);
            }

            if (!pause || step)
            {
                //update animated objects
                machine.Update(gameTime);
                Follow.lookat(machine.TrackedObject.Location, CameraCenter);
                light.update(machine.TrackedObject.Location);
            }

            //TODO consider adding statistic update code here like FPS

            //store last key state
            lastKey = keyState;
            lastMouse = curMouse;

            base.Update(gameTime);
        }
コード例 #18
0
    public static void UpdateCamera()
    {
        if (!externalPositionTarget)
        {
            // Horizontal rotation (rotates playerBody body left and right)
            // Vertical rotation (rotates camera up and down body)
            Quaternion verticalRotation = Quaternion.Euler(currentY, 0, 0);

            // If an external target was recently used, the camera should lerp back
            if (timeToLerp < maxTimeToLerp)
            {
                ActiveCamera.transform.localRotation = Quaternion.Slerp(ActiveCamera.transform.localRotation, verticalRotation, lerpConstantRotation * Time.deltaTime);
            }
            else
            {
                ActiveCamera.transform.localRotation = verticalRotation;
            }

            if (SettingsMenu.settingsData.cameraFirstPerson == 0)
            {
                // Third person

                // Decide position the camera should try to be at
                Vector3 wantedPosition; // local
                // If an external target was recently used, the camera should lerp back
                if (timeToLerp < maxTimeToLerp)
                {
                    float distance = timeToLerp / maxTimeToLerp;
                    wantedPosition = Vector3.Slerp(ActiveCamera.transform.localPosition, verticalRotation * new Vector3(0, 0, -SettingsMenu.settingsData.cameraDistance), lerpConstantPosition * Time.deltaTime);
                    timeToLerp    += Time.deltaTime;
                }
                else
                {
                    wantedPosition = verticalRotation * new Vector3(0, 0, -SettingsMenu.settingsData.cameraDistance);
                }

                ActiveCamera.transform.localPosition = wantedPosition;
                Vector3 pos = Vector3.zero;
                pos.y = playerLookAtTargetHeight;
                playerLookAtTarget.transform.localPosition = pos;

                Vector3[] origins = new Vector3[9];
                origins[0] = ActiveCamera.ViewportToWorldPoint(new Vector3(0, 0, ActiveCamera.nearClipPlane));
                origins[1] = ActiveCamera.ViewportToWorldPoint(new Vector3(0, .5f, ActiveCamera.nearClipPlane));
                origins[2] = ActiveCamera.ViewportToWorldPoint(new Vector3(0, 1, ActiveCamera.nearClipPlane));
                origins[3] = ActiveCamera.ViewportToWorldPoint(new Vector3(.5f, 0, ActiveCamera.nearClipPlane));
                origins[4] = ActiveCamera.ViewportToWorldPoint(new Vector3(.5f, .5f, ActiveCamera.nearClipPlane));
                origins[5] = ActiveCamera.ViewportToWorldPoint(new Vector3(.5f, 1, ActiveCamera.nearClipPlane));
                origins[6] = ActiveCamera.ViewportToWorldPoint(new Vector3(1, 0, ActiveCamera.nearClipPlane));
                origins[7] = ActiveCamera.ViewportToWorldPoint(new Vector3(1, .5f, ActiveCamera.nearClipPlane));
                origins[8] = ActiveCamera.ViewportToWorldPoint(new Vector3(1, 1, ActiveCamera.nearClipPlane));

                Vector3 directionToTarget = playerLookAtTarget.position - origins[4]; // center
                float   distanceToTarget  = directionToTarget.magnitude;

                Vector3[] destinations = new Vector3[9];
                for (int i = 0; i < 9; i++)
                {
                    destinations[i] = origins[i] + directionToTarget;
                }

                // Check if lookAtTarget would be clipping into a ceiling
                Vector3[] playerDestinations = new Vector3[9];
                for (int i = 0; i < 9; i++)
                {
                    playerDestinations[i] = destinations[i] - playerLookAtTarget.localPosition;
                    Debug.DrawLine(playerDestinations[i], destinations[i], Color.white);
                }

                int        smallestIndex    = -1;
                RaycastHit smallestHit      = new RaycastHit();
                float      smallestDistance = playerLookAtTargetReferenceHeight;

                for (int i = 0; i < 9; i++)
                {
                    // Check height of lookAtTarget
                    if (Physics.Raycast(playerDestinations[i], UpsideDown ? Vector3.down : Vector3.up, out RaycastHit hit, (destinations[i] - playerDestinations[i]).magnitude, GameManager.Layer_IgnoreCamera))
                    {
                        float distance = (playerDestinations[i] - hit.point).magnitude;
                        Debug.DrawLine(playerDestinations[i], hit.point, Color.green);
                        if (distance < smallestDistance)
                        {
                            smallestIndex    = i;
                            smallestHit      = hit;
                            smallestDistance = distance;
                        }
                    }
                }

                if (smallestIndex > -1)   // A collision has occured
                {
                    playerLookAtTarget.position = smallestHit.point + (playerLookAtTarget.position - destinations[smallestIndex]) + (UpsideDown ? new Vector3(0, .00001f, 0) : new Vector3(0, -.00001f, 0));
                    Debug.DrawLine(playerDestinations[smallestIndex], smallestHit.point, Color.red);

                    // Recalculate based on new lookAtTarget position
                    ActiveCamera.transform.localPosition = wantedPosition;
                    origins[0] = ActiveCamera.ViewportToWorldPoint(new Vector3(0, 0, ActiveCamera.nearClipPlane));
                    origins[1] = ActiveCamera.ViewportToWorldPoint(new Vector3(0, .5f, ActiveCamera.nearClipPlane));
                    origins[2] = ActiveCamera.ViewportToWorldPoint(new Vector3(0, 1, ActiveCamera.nearClipPlane));
                    origins[3] = ActiveCamera.ViewportToWorldPoint(new Vector3(.5f, 0, ActiveCamera.nearClipPlane));
                    origins[4] = ActiveCamera.ViewportToWorldPoint(new Vector3(.5f, .5f, ActiveCamera.nearClipPlane));
                    origins[5] = ActiveCamera.ViewportToWorldPoint(new Vector3(.5f, 1, ActiveCamera.nearClipPlane));
                    origins[6] = ActiveCamera.ViewportToWorldPoint(new Vector3(1, 0, ActiveCamera.nearClipPlane));
                    origins[7] = ActiveCamera.ViewportToWorldPoint(new Vector3(1, .5f, ActiveCamera.nearClipPlane));
                    origins[8] = ActiveCamera.ViewportToWorldPoint(new Vector3(1, 1, ActiveCamera.nearClipPlane));

                    directionToTarget = playerLookAtTarget.position - origins[4]; // center
                    distanceToTarget  = directionToTarget.magnitude;

                    for (int i = 0; i < 9; i++)
                    {
                        destinations[i] = origins[i] + directionToTarget;
                    }
                }

                smallestIndex    = -1;
                smallestDistance = SettingsMenu.settingsData.cameraDistance;

                for (int i = 0; i < 9; i++)
                {
                    if (Physics.Raycast(destinations[i], -directionToTarget, out RaycastHit hit, distanceToTarget, GameManager.Layer_IgnoreCamera))
                    {
                        float distance = (hit.point - destinations[i]).magnitude;
                        Debug.DrawLine(destinations[i], hit.point, Color.yellow);
                        if (distance < smallestDistance)
                        {
                            smallestIndex    = i;
                            smallestHit      = hit;
                            smallestDistance = distance;
                        }
                    }
                }

                if (smallestIndex > -1)   // A collision has occured
                {
                    ActiveCamera.transform.position = smallestHit.point + (ActiveCamera.transform.position - origins[smallestIndex]);
                    Debug.DrawLine(destinations[smallestIndex], smallestHit.point, Color.red);
                }
            }
            else
            {
                // First person
                // Decide position the camera should try to be at
                Vector3 wantedPosition = Vector3.zero; // local
                // If an external target was recently used, the camera should lerp back
                if (timeToLerp < maxTimeToLerp)
                {
                    float distance = timeToLerp / maxTimeToLerp;
                    wantedPosition = Vector3.Slerp(ActiveCamera.transform.localPosition, Vector3.zero, lerpConstantPosition * Time.deltaTime);
                    timeToLerp    += Time.deltaTime;

                    ActiveCamera.transform.localPosition = wantedPosition;
                }
                else
                {
                }

                Vector3 pos = Vector3.zero;
                pos.y = playerLookAtTargetFirstPersonHeight;
                playerLookAtTarget.transform.localPosition = pos;

                Vector3[] origins = new Vector3[9];
                origins[0] = ActiveCamera.ViewportToWorldPoint(new Vector3(0, 0, ActiveCamera.nearClipPlane));
                origins[1] = ActiveCamera.ViewportToWorldPoint(new Vector3(0, .5f, ActiveCamera.nearClipPlane));
                origins[2] = ActiveCamera.ViewportToWorldPoint(new Vector3(0, 1, ActiveCamera.nearClipPlane));
                origins[3] = ActiveCamera.ViewportToWorldPoint(new Vector3(.5f, 0, ActiveCamera.nearClipPlane));
                origins[4] = ActiveCamera.ViewportToWorldPoint(new Vector3(.5f, .5f, ActiveCamera.nearClipPlane));
                origins[5] = ActiveCamera.ViewportToWorldPoint(new Vector3(.5f, 1, ActiveCamera.nearClipPlane));
                origins[6] = ActiveCamera.ViewportToWorldPoint(new Vector3(1, 0, ActiveCamera.nearClipPlane));
                origins[7] = ActiveCamera.ViewportToWorldPoint(new Vector3(1, .5f, ActiveCamera.nearClipPlane));
                origins[8] = ActiveCamera.ViewportToWorldPoint(new Vector3(1, 1, ActiveCamera.nearClipPlane));

                Vector3 directionToTarget = playerLookAtTarget.position - origins[4]; // center
                float   distanceToTarget  = directionToTarget.magnitude;

                Vector3[] destinations = new Vector3[9];
                for (int i = 0; i < 9; i++)
                {
                    destinations[i] = origins[i] + directionToTarget;
                }

                // Check if lookAtTarget would be clipping into a ceiling
                Vector3[] playerDestinations = new Vector3[9];
                for (int i = 0; i < 9; i++)
                {
                    playerDestinations[i] = destinations[i] - playerLookAtTarget.localPosition;
                }

                int        smallestIndex    = -1;
                RaycastHit smallestHit      = new RaycastHit();
                float      smallestDistance = playerLookAtTargetHeight;

                for (int i = 0; i < 9; i++)
                {
                    // Check height of lookAtTarget
                    if (Physics.Raycast(playerDestinations[i], Vector3.up, out RaycastHit hit, (destinations[i] - playerDestinations[i]).magnitude, GameManager.Layer_IgnoreCamera))
                    {
                        float distance = (playerDestinations[i] - hit.point).magnitude;
                        Debug.DrawLine(playerDestinations[i], hit.point, Color.green);
                        if (distance < smallestDistance)
                        {
                            smallestIndex    = i;
                            smallestHit      = hit;
                            smallestDistance = distance;
                        }
                    }
                }

                if (smallestIndex > -1)   // A collision has occured
                {
                    playerLookAtTarget.position = smallestHit.point + (playerLookAtTarget.position - destinations[smallestIndex]) - new Vector3(0, .00001f, 0);
                }
            }
        }
    }