Example #1
0
        // in egocentric camera system the "eye" is moving up/down, which means the scene moves in opposite direction
        public void SceneRateControlledEgogentricPan(FScene scene, fCamera cam, Vector2f curPos, RateControlInfo rc)
        {
            float dt = (FPlatform.RealTime() - rc.lastTime);

            rc.lastTime = FPlatform.RealTime();

            float delta_y = (curPos.y - rc.startPos.y);

            rc.curSpeedY =
                rc_update_speed(delta_y, rc.rampUpRadius, rc.deadZoneRadius, rc.maxAccel, rc.maxSpeed, dt, rc.curSpeedY);
            float delta_x = (curPos.x - rc.startPos.x);

            rc.curSpeedX =
                rc_update_speed(delta_x, rc.rampUpRadius, rc.deadZoneRadius, rc.maxAccel, rc.maxSpeed, dt, rc.curSpeedX);


            Frame3f  camFrame = cam.GetWorldFrame();
            Vector3f forward  = camFrame.Z;
            Vector3f up       = camFrame.Y;

            if (rc.StayLevel)
            {
                forward = new Vector3(forward.x, 0.0f, forward.z);
                forward.Normalize();
                up = Vector3.up;
            }
            Vector3f right       = Vector3.Cross(up, forward);
            Vector3f curScenePos = scene.RootGameObject.GetPosition();
            Vector3f newScenePos = curScenePos - dt * (rc.curSpeedY * up + rc.curSpeedX * right);

            scene.RootGameObject.SetPosition(newScenePos);
        }
Example #2
0
 override public bool EndCapture(InputEvent e)
 {
     if (FindHitGO(e.ray))
     {
         if (sent_click == false)
         {
             // on first click we reset timer
             on_clicked();
             sent_click      = true;
             last_click_time = FPlatform.RealTime();
         }
         else
         {
             float delta = FPlatform.RealTime() - last_click_time;
             if (delta < double_click_delay)
             {
                 // if this second click comes fast enough, send doubleclick instead
                 on_double_clicked();
                 sent_click      = false;
                 last_click_time = 0.0f;
             }
             else
             {
                 // send single-click and reset timer
                 on_clicked();
                 sent_click      = true;
                 last_click_time = FPlatform.RealTime();
             }
         }
     }
     return(true);
 }
Example #3
0
        // in egocentric camera system the "eye" is moving up/down, which means the scene moves in opposite direction
        public void SceneRateControlledEgogentricPan(FScene scene, Camera cam, Vector2 curPos, RateControlInfo rc)
        {
            float dt = (FPlatform.RealTime() - rc.lastTime);

            rc.lastTime = FPlatform.RealTime();

            float delta_y = (curPos.y - rc.startPos.y);

            rc.curSpeedY =
                rc_update_speed(delta_y, rc.rampUpRadius, rc.deadZoneRadius, rc.maxAccel, rc.maxSpeed, dt, rc.curSpeedY);
            float delta_x = (curPos.x - rc.startPos.x);

            rc.curSpeedX =
                rc_update_speed(delta_x, rc.rampUpRadius, rc.deadZoneRadius, rc.maxAccel, rc.maxSpeed, dt, rc.curSpeedX);


            Vector3 forward, up;

            if (rc.StayLevel)
            {
                forward = new Vector3(cam.transform.forward.x, 0.0f, cam.transform.forward.z);
                forward.Normalize();
                up = Vector3.up;
            }
            else
            {
                forward = cam.gameObject.transform.forward;
                up      = cam.gameObject.transform.up;
            }
            Vector3 right       = Vector3.Cross(up, forward);
            Vector3 curScenePos = scene.RootGameObject.transform.position;
            Vector3 newScenePos = curScenePos - dt * (rc.curSpeedY * up + rc.curSpeedX * right);

            scene.RootGameObject.transform.position = newScenePos;
        }
Example #4
0
 override public bool EndCapture(InputEvent e)
 {
     if (FindHitGO(e.ray))
     {
         if (sent_click == false)
         {
             // on first click we reset timer
             FUtil.SafeSendEvent(OnClicked, this, e);
             sent_click      = true;
             last_click_time = FPlatform.RealTime();
         }
         else
         {
             float delta = FPlatform.RealTime() - last_click_time;
             if (delta < SceneGraphConfig.ActiveDoubleClickDelay)
             {
                 // if this second click comes fast enough, send doubleclick instead
                 FUtil.SafeSendEvent(OnDoubleClicked, this, e);
                 sent_click      = false;
                 last_click_time = 0.0f;
             }
             else
             {
                 // send single-click and reset timer
                 FUtil.SafeSendEvent(OnClicked, this, e);
                 sent_click      = true;
                 last_click_time = FPlatform.RealTime();
             }
         }
     }
     return(true);
 }
Example #5
0
 public RateControlInfo(Vector2f startPos)
 {
     lastTime       = FPlatform.RealTime();
     maxSpeed       = 5.0f;
     maxAccel       = 10.5f;
     angleMultipler = 4.0f;
     curSpeedX      = curSpeedY = 0.0f;
     rampUpRadius   = 10.0f;
     deadZoneRadius = 1.0f;
     StayLevel      = true;
     this.startPos  = startPos;
 }
Example #6
0
        public bool HandleShortcuts()
        {
            if (Input.GetKeyUp(KeyCode.Escape))
            {
                controller.PopCockpit(true);
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Return))
            {
                if (OnReturn != null)
                {
                    OnReturn();
                }
                return(true);
            }
            else if (Input.GetKeyDown(KeyCode.Backspace))
            {
                deleteTime = FPlatform.RealTime() + 0.5f;
                if (entryField.Text.Length > 0)
                {
                    entryField.Text = entryField.Text.Substring(0, entryField.Text.Length - 1);
                }
                return(true);
            }
            else if (Input.GetKey(KeyCode.Backspace))
            {
                if (entryField.Text.Length > 0 && FPlatform.RealTime() - deleteTime > 0.05f)
                {
                    entryField.Text = entryField.Text.Substring(0, entryField.Text.Length - 1);
                    deleteTime      = FPlatform.RealTime();
                }
                return(true);
            }
            else if (Input.GetKeyDown(KeyCode.V) && Input.GetKey(KeyCode.LeftControl))
            {
                //entryField.Text = "https://www.dropbox.com/s/momif47x1erb2fp/test_bunny.obj?raw=1";
                return(true);
            }
            else if (Input.anyKeyDown)
            {
                if (Input.inputString.Length > 0 && FileSystemUtils.IsValidFilenameString(Input.inputString))
                {
                    entryField.Text += Input.inputString;
                    return(true);
                }
            }

            return(false);
        }
Example #7
0
        public override void PreRender()
        {
            if (IsEditing)
            {
                // cursor blinks every 0.5s
                float dt = FPlatform.RealTime() - start_active_time;
                cursor.SetVisible((int)(2 * dt) % 2 == 0);

                // DO NOT DO THIS EVERY FRAME!!!
                BoxModel.MoveTo(cursor, this.Bounds2D.CenterLeft, -Height * 0.1f);
                Vector2f cursorPos = textMesh.TextObject.GetCursorPosition(cursor_position);
                BoxModel.Translate(cursor, cursorPos);
            }
            else
            {
                cursor.SetVisible(false);
            }
        }
        public override Capture UpdateCapture(InputState input, CaptureData data)
        {
            //CaptureControl.doSurroundCapture = false;
#if false
            if (input.bLeftMenuButtonPressed)
            {
                press_time = FPlatform.RealTime();
                if (input.bLeftShoulderDown)
                {
                    CaptureControl.EnableSurroundCapture = true;
                }
                else
                {
                    CaptureControl.EnableSurroundCapture = false;
                }
            }
            else if (input.bLeftMenuButtonReleased)
            {
                if (in_video_capture)
                {
                    CaptureControl.EndVideoCapture();
                    string s = string.Format("Captured {0} video!", CaptureControl.EnableSurroundCapture ? "360" : "WideAngle");
                    HUDUtil.ShowToastPopupMessage(s, FContext.ActiveContext_HACK.ActiveCockpit);
                    in_video_capture = false;
                    press_time       = 0;
                }
                else if (FPlatform.RealTime() - press_time > 1.0f)
                {
                    CaptureControl.BeginVideoCapture();
                    in_video_capture = true;
                }
                else
                {
                    CaptureControl.CaptureScreen();
                    string s = string.Format("Captured {0} screenshot!", CaptureControl.EnableSurroundCapture ? "360" : "WideAngle");
                    HUDUtil.ShowToastPopupMessage(s, FContext.ActiveContext_HACK.ActiveCockpit);
                }
            }
#endif
            return(Capture.Ignore);
        }
Example #9
0
        public virtual void Update()
        {
            if (deregister == true)
            {
                return;
            }

            float dt = FPlatform.RealTime() - start_time;

            if (dt >= Duration)
            {
                dt         = Duration;
                deregister = true;
            }

            tweenF(dt / Duration);

            if (deregister && OnCompletedF != null)
            {
                OnCompletedF();
            }
        }
Example #10
0
        void begin_editing()
        {
            // start capturing input
            if (OverrideDefaultInputHandling == false)
            {
                HUDTextEntryTarget entry = new HUDTextEntryTarget(this);
                if (Parent.Context.RequestTextEntry(entry))
                {
                    active_entry = entry;
                    FUtil.SafeSendEvent(OnBeginTextEditing, this);
                    bgMesh.SetMaterial(activeBackgroundMaterial);
                    start_active_time = FPlatform.RealTime();
                    cursor_position   = text.Length;

                    entry.OnTextEditingEnded += (s, e) => {
                        bgMesh.SetMaterial(backgroundMaterial);
                        active_entry = null;
                        FUtil.SafeSendEvent(OnEndTextEditing, this);
                    };
                }
            }
        }
Example #11
0
        override public bool EndCapture(InputEvent e)
        {
            if (Parent == null)
            {
                DebugUtil.Log(2, "HUDLabel.EndCapture: our parent went invalid while we were capturing!");
                return(true);
            }

            if (FindHitGO(e.ray))
            {
                if (sent_click == false)
                {
                    // on first click we reset timer
                    FUtil.SafeSendEvent(OnClicked, this, new EventArgs());
                    sent_click      = true;
                    last_click_time = FPlatform.RealTime();
                }
                else
                {
                    float delta = FPlatform.RealTime() - last_click_time;
                    if (delta < double_click_delay)
                    {
                        // if this second click comes fast enough, send doubleclick instead
                        FUtil.SafeSendEvent(OnDoubleClicked, this, new EventArgs());
                        sent_click      = false;
                        last_click_time = 0.0f;
                    }
                    else
                    {
                        // send single-click and reset timer
                        FUtil.SafeSendEvent(OnClicked, this, new EventArgs());
                        sent_click      = true;
                        last_click_time = FPlatform.RealTime();
                    }
                }
            }
            return(true);
        }
        // Use this for initialization
        public void Start()
        {
            fCursorSpeedNormalization = 1.0f;
            fCurPlaneX      = 0;
            fCurPlaneY      = 0;
            vPlaneCursorPos = Vector3.zero;
            vSceneCursorPos = vPlaneCursorPos;

            CursorDefaultMaterial = MaterialUtil.CreateTransparentMaterial(Color.grey, 0.6f);
            //CursorHitMaterial = MaterialUtil.CreateTransparentMaterial (Color.yellow, 0.8f);
            CursorHitMaterial       = MaterialUtil.CreateStandardMaterial(Color.yellow);
            CursorCapturingMaterial = MaterialUtil.CreateTransparentMaterial(Color.yellow, 0.75f);

            CursorVisualAngleInDegrees = 1.5f;

            standardCursorMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 0.5f, 16);
            UnityUtil.TranslateMesh(standardCursorMesh, 0, -2.0f, 0);
            activeToolCursorMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 1.0f, 16);
            UnityUtil.TranslateMesh(activeToolCursorMesh, 0, -2.0f, 0);

            Cursor = UnityUtil.CreateMeshGO("cursor", standardCursorMesh, CursorDefaultMaterial);
            Cursor.SetSharedMesh(standardCursorMesh);
            Cursor.transform.localScale    = new Vector3(0.3f, 0.3f, 0.3f);
            Cursor.transform.localRotation = Quaternion.AngleAxis(45.0f, new Vector3(1, 0, 1).normalized);
            MaterialUtil.DisableShadows(Cursor);

            xformObject = GameObject.CreatePrimitive(PrimitiveType.Plane);
            xformObject.SetName("cursor_plane");
            MaterialUtil.DisableShadows(xformObject);
            xformObject.GetComponent <MeshRenderer>().material
                = MaterialUtil.CreateTransparentMaterial(Color.cyan, 0.2f);
            xformObject.GetComponent <MeshRenderer>().enabled = false;

            lastMouseEventTime = FPlatform.RealTime();
            mouseInactiveState = false;
        }
Example #13
0
 public virtual void Start()
 {
     start_time = FPlatform.RealTime();
 }
 public void ShowCursor()
 {
     Cursor.Show();
     mouseInactiveState = false;
     lastMouseEventTime = FPlatform.RealTime();
 }
        // FixedUpdate is called before any Update
        public void Update()
        {
            if (bFreezeCursor)
            {
                return;
            }

            // if we are in capture we freeze the cursor plane
            if (context.InCaptureMouse == false)
            {
                Vector3 camPos  = camera.gameObject.transform.position;
                Vector3 forward = camera.gameObject.transform.forward;

                // orient Y-up plane so that it is in front of eye, perp to camera direction
                float fCursorDepth = 10.0f;
                fCursorSpeedNormalization = 1.0f;
                if (context.ActiveCockpit != null && context.ActiveCockpit.DefaultCursorDepth > 0)
                {
                    fCursorDepth = context.ActiveCockpit.DefaultCursorDepth;
                    // cursor speed will change depending on cursor plane distance, unless we normalize
                    fCursorSpeedNormalization *= (fCursorDepth / 10.0f);
                }
                xformObject.transform.position = camPos + fCursorDepth * forward;
                xformObject.transform.LookAt(camera.gameObject.transform);
                xformObject.transform.RotateAround(xformObject.transform.position, xformObject.transform.right, 90);

                // that plane is the plane the mouse cursor moves on
                this.vCursorPlaneOrigin = xformObject.transform.position;
                this.vCursorPlaneRight  = xformObject.transform.right;
                this.vCursorPlaneUp     = xformObject.transform.forward;                    // because we rotated? weird...
                this.vRaySourcePosition = camera.transform.position;

                // if we were capturing, then plane was frozen and when we stop capturing, if
                //  head moved, the cursor will pop to a new position (because it is stored in
                //  local plane coords). So raycast through old cursor to hit new plane and figure
                //  out new local coords (fCurPlaneX, fCurPlaneY)
                if (bWasInCaptureFreeze)
                {
                    Frame3f newF      = new Frame3f(vCursorPlaneOrigin, this.camera.transform.forward);
                    Vector3 vPlaneHit = newF.RayPlaneIntersection(this.vRaySourcePosition,
                                                                  (vPlaneCursorPos - vRaySourcePosition).normalized, 2);
                    fCurPlaneX          = Vector3.Dot((vPlaneHit - vCursorPlaneOrigin), vCursorPlaneRight);
                    fCurPlaneY          = Vector3.Dot((vPlaneHit - vCursorPlaneOrigin), vCursorPlaneUp);
                    bWasInCaptureFreeze = false;
                }
            }
            else
            {
                bWasInCaptureFreeze = true;
            }

            Vector2f mousePos  = InputExtension.Get.Mouse.PositionDelta;
            Vector2f leftStick = InputExtension.Get.GamepadLeftStick.Position;
            float    fX        = mousePos.x + leftStick.x;
            float    fY        = mousePos.y + leftStick.y;

            // auto-hide cursor if it doesn't move for a while
            if (fX == 0 && fY == 0 && SceneGraphConfig.MouseCursorHideTimeout > 0)
            {
                if ((FPlatform.RealTime() - lastMouseEventTime) > SceneGraphConfig.MouseCursorHideTimeout)
                {
                    Cursor.SetVisible(false);
                    mouseInactiveState = true;
                }
                if (mouseInactiveState)
                {
                    return;
                }
            }
            else
            {
                lastMouseEventTime = FPlatform.RealTime();
                if (mouseInactiveState)
                {
                    Cursor.SetVisible(true);
                }
                mouseInactiveState = false;
            }

            // update cursor location
            fCurPlaneX     -= 0.3f * fX * fCursorSpeedNormalization;
            fCurPlaneY     -= 0.3f * fY * fCursorSpeedNormalization;
            vPlaneCursorPos =
                vCursorPlaneOrigin + fCurPlaneX * vCursorPlaneRight + fCurPlaneY * vCursorPlaneUp;
            vSceneCursorPos = vPlaneCursorPos;

            // if cursor gets outside of viewpoint it is almost impossible to get it back.
            // So, if it goes too far out of view (45 deg here), we snap it back to the origin
            if (context.InCameraManipulation == false && context.InCaptureMouse == false)
            {
                float fAngle = Vector3.Angle((vPlaneCursorPos - camera.transform.position).normalized, camera.transform.forward);
                if (fAngle > 50.0f)
                {
                    fCurPlaneX      = fCurPlaneY = 0;
                    vPlaneCursorPos =
                        vCursorPlaneOrigin + fCurPlaneX * vCursorPlaneRight + fCurPlaneY * vCursorPlaneUp;
                    vSceneCursorPos = vPlaneCursorPos;
                }
            }


            bool bHit = false;

            // [RMS] boundsHit cursor orientation could be useful for things where you are picking a point
            //   on the ground plane (eg like drawing contours). Not sure how to toggle that though.
            //   Just disabling for now...
            //bool bIsBoundsHit = false;
            if (context != null)
            {
                Ray       r   = new Ray(camera.transform.position, (vPlaneCursorPos - camera.transform.position).normalized);
                AnyRayHit hit = null;
                if (context.FindAnyRayIntersection(r, out hit))
                {
                    vSceneCursorPos = hit.hitPos;
                    bHit            = true;
                }
                else
                {
                    GameObjectRayHit ghit = null;
                    if (context.GetScene().FindWorldBoundsHit(r, out ghit))
                    {
                        vSceneCursorPos = ghit.hitPos;
                        //bIsBoundsHit = true;
                    }
                }
            }

            this.CurrentCursorPosWorld       = vPlaneCursorPos;
            this.CurrentCursorRaySourceWorld = this.vRaySourcePosition;

            Vector3 vEyeToPos = (vPlaneCursorPos - camera.transform.position).normalized;
            //if (bIsBoundsHit) {
            //    Vector3 rotAxis = (vEyeToPos + camera.transform.right).normalized;
            //    Cursor.transform.localRotation = Quaternion.AngleAxis(180.0f-45.0f, rotAxis);
            //} else {
            Quaternion rotAlignUp = Quaternion.FromToRotation(Vector3.up, camera.transform.up);
            Vector3    rotAxis    = (vEyeToPos + camera.transform.right).normalized;

            Cursor.transform.localRotation = Quaternion.AngleAxis(45.0f, rotAxis) * rotAlignUp;
            //}

            Cursor.transform.position = vSceneCursorPos;
            if (context.InCaptureMouse)
            {
                Cursor.GetComponent <MeshRenderer> ().material = CursorCapturingMaterial;
            }
            else if (bHit)
            {
                Cursor.GetComponent <MeshRenderer> ().material = CursorHitMaterial;
            }
            else
            {
                Cursor.GetComponent <MeshRenderer> ().material = CursorDefaultMaterial;
            }

            Cursor.SetLayer(FPlatform.CursorLayer);

            // maintain a consistent visual size for 3D cursor sphere
            float fScaling = VRUtil.GetVRRadiusForVisualAngle(vSceneCursorPos, camera.transform.position, CursorVisualAngleInDegrees);

            Cursor.transform.localScale = new Vector3(fScaling, fScaling, fScaling);

            // update cursor
            Mesh useMesh = context.ToolManager.HasActiveTool(ToolSide.Right) ? activeToolCursorMesh : standardCursorMesh;

            if (Cursor.GetSharedMesh() != useMesh)
            {
                Cursor.SetSharedMesh(useMesh);
            }
        }