예제 #1
0
        // override and return true to get hover events
        public virtual bool FindHoverRayIntersection(Ray3f ray, out UIRayHit hit)
        {
            hit = null;
            if (Enabled == false)
            {
                return(false);
            }

            if (EnableHover == false)
            {
                return(false);
            }

            GameObjectRayHit hitg = null;

            if (FindGORayIntersection(ray, out hitg))
            {
                if (hitg.hitGO != null)
                {
                    hit = new UIRayHit(hitg, this);
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
        public override bool BeginCapture(ITransformable target, Ray3f worldRay, UIRayHit hit)
        {
            // save local and world frames
            rotateFrameL = target.GetLocalFrame(CoordSpace.ObjectCoords);
            rotateFrameW = target.GetLocalFrame(CoordSpace.WorldCoords);
            rotateAxisW  = rotateFrameW.GetAxis(nRotationAxis);

            // save angle of hitpos in 2D plane perp to rotateAxis, so we can find delta-angle later
            Vector3f vWorldHitPos = hit.hitPos;
            Vector3f dv           = vWorldHitPos - rotateFrameW.Origin;
            int      iX           = (nRotationAxis + 1) % 3;
            int      iY           = (nRotationAxis + 2) % 3;
            float    fX           = Vector3f.Dot(dv, rotateFrameW.GetAxis(iX));
            float    fY           = Vector3f.Dot(dv, rotateFrameW.GetAxis(iY));

            fRotateStartAngle = (float)Math.Atan2(fY, fX);

            // construct plane we will ray-intersect with in UpdateCapture()
            raycastFrame = new Frame3f(vWorldHitPos, rotateAxisW);

            if (EnableSnapping)
            {
                enable_circle_indicator(true);
            }

            return(true);
        }
예제 #3
0
 public AnyRayHit(UIRayHit init)
 {
     hitPos   = init.hitPos;
     fHitDist = init.fHitDist;
     hitGO    = init.hitGO;
     eType    = HitType.SceneUIElementHit;
     hitUI    = init.hitUI;
 }
예제 #4
0
 public bool FindHoverRayIntersection(Ray3f ray, out UIRayHit hit)
 {
     if (is_interactive == false)
     {
         hit = null;
         return(false);
     }
     return(HUDUtil.FindNearestHoverRayIntersection(Children, ray, out hit));
 }
예제 #5
0
        Vector3f vInitialHitPos;                        // initial hit position in frame

        public override bool BeginCapture(ITransformable target, Ray3f worldRay, UIRayHit hit)
        {
            // save local and world frames
            translateFrameL = target.GetLocalFrame(CoordSpace.ObjectCoords);
            translateFrameW = target.GetLocalFrame(CoordSpace.WorldCoords);

            // save initial hitpos in translation plane
            vInitialHitPos = translateFrameW.RayPlaneIntersection(worldRay.Origin, worldRay.Direction, nTranslationPlaneNormal);

            return(true);
        }
예제 #6
0
        public bool FindAnyRayIntersection(Ray3f ray, out AnyRayHit hit)
        {
            hit = null;
            UIRayHit bestUIHit = null;

            if (FindUIRayIntersection(ray, out bestUIHit))
            {
                hit = new AnyRayHit(bestUIHit);
            }
            return(hit != null);
        }
예제 #7
0
 public override void UpdateHover(Ray3f ray, UIRayHit hit)
 {
     if (Enabled && HasGO(hit.hitGO))
     {
         buttonMesh.SetMaterial(HoverMaterial, true);
     }
     else
     {
         buttonMesh.SetMaterial(StandardMaterial, true);
     }
 }
예제 #8
0
 public virtual void UpdateHover(Ray3f ray, UIRayHit hit)
 {
     if (hoverWidget != null)
     {
         EndHover(ray);
     }
     if (Widgets.ContainsKey(hit.hitGO))
     {
         hoverWidget = Widgets[hit.hitGO];
         MaterialUtil.SetMaterial(hoverWidget.RootGameObject, hoverWidget.HoverMaterial);
     }
 }
예제 #9
0
        // does not test bounds!
        // [TODO] this is going to be weird... need to test bounds, I think
        public bool FindAnyRayIntersection(Ray3f ray, out AnyRayHit hit)
        {
            hit = null;

            UIRayHit bestUIHit = null;
            SORayHit bestSOHit = null;

            foreach (var ui in vUIElements)
            {
                UIRayHit uiHit;
                if (ui.FindRayIntersection(ray, out uiHit))
                {
                    if (bestUIHit == null || uiHit.fHitDist < bestUIHit.fHitDist)
                    {
                        bestUIHit = uiHit;
                    }
                }
            }
            foreach (var so in VisibleSceneObjects)
            {
                if (!is_selectable(so))
                {
                    continue;
                }
                SORayHit objHit;
                if (so.FindRayIntersection(ray, out objHit))
                {
                    if (bestSOHit == null || objHit.fHitDist < bestSOHit.fHitDist)
                    {
                        bestSOHit = objHit;
                    }
                }
            }
            if (bestUIHit != null)
            {
                if (bestSOHit == null || bestSOHit.fHitDist > bestUIHit.fHitDist)
                {
                    hit = new AnyRayHit(bestUIHit);
                }
                else
                {
                    hit = new AnyRayHit(bestSOHit);
                }
            }
            else if (bestSOHit != null)
            {
                hit = new AnyRayHit(bestSOHit);
            }

            return(hit != null);
        }
예제 #10
0
        // see comment above
        public bool Find2DCockpitUIHoverHit(Ray3f orthoEyeRay, out UIRayHit bestHit)
        {
            if (Use2DCockpit == false)
            {
                throw new Exception("FContext.Find2DUIHit: 2D UI layer is not enabled!");
            }

            bestHit = null;
            if (options.EnableCockpit)
            {
                return(activeCockpit.FindUIHoverRayIntersection(orthoEyeRay, out bestHit));
            }
            return(false);
        }
예제 #11
0
        public virtual bool FindRayIntersection(UnityEngine.Ray ray, out UIRayHit hit)
        {
            hit = null;
            GameObjectRayHit hitg = null;

            if (FindGORayIntersection(ray, out hitg))
            {
                if (hitg.hitGO != null)
                {
                    hit = new UIRayHit(hitg, this);
                    return(true);
                }
            }
            return(false);
        }
예제 #12
0
        virtual public bool FindRayIntersection(Ray3f ray, out UIRayHit hit)
        {
            hit = null;
            GameObjectRayHit hitg = null;

            if (is_interactive && FindGORayIntersection(ray, out hitg))
            {
                if (hitg.hitGO != null)
                {
                    hit = new UIRayHit(hitg, this);
                    return(true);
                }
            }
            return(false);
        }
예제 #13
0
        public bool FindUIRayIntersection(Ray ray, out UIRayHit hit)
        {
            hit = null;

            foreach (var ui in vUIElements)
            {
                UIRayHit uiHit;
                if (ui.FindRayIntersection(ray, out uiHit))
                {
                    if (hit == null || uiHit.fHitDist < hit.fHitDist)
                    {
                        hit = uiHit;
                    }
                }
            }
            return(hit != null);
        }
예제 #14
0
        Vector3f vInitialHitPos;     // initial hit position in frame

        public override bool BeginCapture(ITransformable target, Ray3f worldRay, UIRayHit hit)
        {
            if (target.SupportsScaling == false)
            {
                return(false);
            }

            // save local and world frames
            scaleFrameW  = target.GetLocalFrame(CoordSpace.WorldCoords);
            cameraFrameW = new Frame3f(scaleFrameW.Origin, activeCamera.transform.rotation);
            startScale   = target.GetLocalScale();

            // save initial hitpos in plane
            vInitialHitPos = cameraFrameW.RayPlaneIntersection(worldRay.Origin, worldRay.Direction, 2);

            return(true);
        }
예제 #15
0
        public bool BeginCapture(Ray ray, UIRayHit hit)
        {
            activeWidget = null;

            // if the hit gameobject has a widget attached to it, begin capture & transformation
            // TODO maybe wrapper class should have Begin/Update/End capture functions, then we do not need BeginTransformation/EndTransformation ?
            if (Widgets.ContainsKey(hit.hitGO))
            {
                Widget w = Widgets [hit.hitGO];
                if (w.BeginCapture(targetWrapper, ray, hit))
                {
                    targetWrapper.BeginTransformation();
                    activeWidget = w;
                    return(true);
                }
            }
            return(false);
        }
예제 #16
0
        }          // end Update

        public bool FindUIHit(Ray eyeRay, out UIRayHit bestHit)
        {
            bestHit = new UIRayHit();
            UIRayHit sceneHit = null, cockpitHit = null;

            if (scene.FindUIRayIntersection(eyeRay, out sceneHit))
            {
                bestHit = sceneHit;
            }
            if (cockpit.FindUIRayIntersection(eyeRay, out cockpitHit))
            {
                if (cockpitHit.fHitDist < bestHit.fHitDist)
                {
                    bestHit = cockpitHit;
                }
            }
            return(bestHit.IsValid);
        }
예제 #17
0
        public bool FindAnyRayIntersection(Ray eyeRay, out AnyRayHit anyHit)
        {
            anyHit = new AnyRayHit();
            AnyRayHit sceneHit   = null;
            UIRayHit  cockpitHit = null;

            if (scene.FindAnyRayIntersection(eyeRay, out sceneHit))
            {
                anyHit = sceneHit;
            }
            if (cockpit.FindUIRayIntersection(eyeRay, out cockpitHit))
            {
                if (cockpitHit.fHitDist < anyHit.fHitDist)
                {
                    anyHit = new AnyRayHit(cockpitHit);
                }
            }
            return(anyHit.IsValid);
        }
        float fTranslateStartT;                 // start T-value along translateAxisW

        public bool BeginCapture(ITransformable target, Ray worldRay, UIRayHit hit)
        {
            // save local and world frames
            translateFrameL = target.GetLocalFrame(CoordSpace.ObjectCoords);
            translateFrameW = target.GetLocalFrame(CoordSpace.WorldCoords);
            translateAxisW  = translateFrameW.GetAxis(nTranslationAxis);

            // save t-value of closest point on translation axis, so we can find delta-t
            Vector3 vWorldHitPos = hit.hitPos;

            fTranslateStartT = MathUtil.ClosestPointOnLineT(
                translateFrameW.Origin, translateAxisW, vWorldHitPos);

            // construct plane we will ray-intersect with in UpdateCapture()
            Vector3 vForward = Vector3.Cross(Camera.main.transform.up, translateAxisW);

            raycastFrame = new Frame3(vWorldHitPos, vForward);

            return(true);
        }
예제 #19
0
        // see comment as above
        public bool FindUIHoverHit(Ray eyeRay, out UIRayHit bestHit)
        {
            bestHit = new UIRayHit();
            UIRayHit sceneHit = null, cockpitHit = null;

            bool bCockpitOnly = (options.EnableCockpit && activeCockpit.GrabFocus);

            if (bCockpitOnly == false && scene.FindUIHoverRayIntersection(eyeRay, out sceneHit))
            {
                bestHit = sceneHit;
            }
            if (Use2DCockpit == false && options.EnableCockpit &&
                activeCockpit.FindUIHoverRayIntersection(eyeRay, out cockpitHit))
            {
                if (cockpitHit.fHitDist < bestHit.fHitDist)
                {
                    bestHit = cockpitHit;
                }
            }
            return(bestHit.IsValid);
        }
        float fTranslateStartT;                 // start T-value along translateAxisW

        public override bool BeginCapture(ITransformable target, Ray3f worldRay, UIRayHit hit)
        {
            // save local and world frames
            translateFrameL = target.GetLocalFrame(CoordSpace.ObjectCoords);
            translateFrameW = target.GetLocalFrame(CoordSpace.WorldCoords);
            translateAxisW  = translateFrameW.GetAxis(nTranslationAxis);

            // save t-value of closest point on translation axis, so we can find delta-t
            Vector3f vWorldHitPos = hit.hitPos;

            fTranslateStartT = Distance.ClosestPointOnLineT(
                translateFrameW.Origin, translateAxisW, vWorldHitPos);

            // construct plane we will ray-intersect with in UpdateCapture()
            Vector3f makeUp       = Vector3f.Cross(Camera.main.transform.forward, translateAxisW).Normalized;
            Vector3f vPlaneNormal = Vector3f.Cross(makeUp, translateAxisW).Normalized;

            raycastFrame = new Frame3f(vWorldHitPos, vPlaneNormal);

            return(true);
        }
예제 #21
0
        // currently used to change cursor highlight in VR views. Perhaps the VR input Controllers
        // should do this themselves!
        public bool FindAnyRayIntersection(Ray eyeRay, out AnyRayHit anyHit)
        {
            anyHit = new AnyRayHit();
            AnyRayHit sceneHit   = null;
            UIRayHit  cockpitHit = null;

            bool bCockpitOnly = (options.EnableCockpit && activeCockpit.GrabFocus);

            if (bCockpitOnly == false && scene.FindAnyRayIntersection(eyeRay, out sceneHit))
            {
                anyHit = sceneHit;
            }
            if (Use2DCockpit == false && options.EnableCockpit &&
                activeCockpit.FindUIRayIntersection(eyeRay, out cockpitHit))
            {
                if (cockpitHit.fHitDist < anyHit.fHitDist)
                {
                    anyHit = new AnyRayHit(cockpitHit);
                }
            }
            return(anyHit.IsValid);
        }
예제 #22
0
 public bool FindHoverRayIntersection(Ray3f ray, out UIRayHit hit)
 {
     return(FindRayIntersection(ray, out hit));
 }
예제 #23
0
 public abstract bool BeginCapture(ITransformable target, Ray worldRay, UIRayHit hit);
예제 #24
0
        public static bool FindNearestHoverRayIntersection(IEnumerable <SceneUIElement> vElements, Ray3f ray, out UIRayHit hit)
        {
            hit = null;

            foreach (var ui in vElements)
            {
                UIRayHit uiHit;
                if (ui.EnableHover && ui.FindHoverRayIntersection(ray, out uiHit))
                {
                    if (hit == null || uiHit.fHitDist < hit.fHitDist)
                    {
                        hit = uiHit;
                    }
                }
            }
            return(hit != null);
        }
예제 #25
0
 public virtual bool FindHoverRayIntersection(Ray3f ray, out UIRayHit hit)
 {
     hit = null; return(false);
 }
예제 #26
0
 override public void UpdateHover(Ray3f ray, UIRayHit hit)
 {
     hovering = true;
 }
예제 #27
0
        // [RMS] I don't think we ever actually call these functions, do we??
        //   hover is sent directly to child that is ray-hit via above, right?

        public void UpdateHover(Ray3f ray, UIRayHit hit)
        {
            throw new InvalidOperationException("HUDCollection.UpdateHover: how is this being called?");
        }
예제 #28
0
 public bool FindUIHoverRayIntersection(Ray3f ray, out UIRayHit hit)
 {
     return(HUDUtil.FindNearestHoverRayIntersection(vUIElements, ray, out hit));
 }
예제 #29
0
 public virtual void UpdateHover(Ray3f ray, UIRayHit hit)
 {
 }
예제 #30
0
 public bool FindHoverRayIntersection(Ray3f ray, out UIRayHit hit)
 {
     return(HUDUtil.FindNearestHoverRayIntersection(Children, ray, out hit));
 }