Пример #1
0
        public bool UpdateCapture(ITransformable target, Ray worldRay)
        {
            // ray-hit with plane perpendicular to rotateAxisW
            Vector3 planeHit = raycastFrame.RayPlaneIntersection(worldRay.origin, worldRay.direction, 2);

            // find angle of hitpos in 2D plane perp to rotateAxis, and compute delta-angle
            Vector3 dv          = planeHit - rotateFrameW.Origin;
            int     iX          = (nRotationAxis + 1) % 3;
            int     iY          = (nRotationAxis + 2) % 3;
            float   fX          = Vector3.Dot(dv, rotateFrameW.GetAxis(iX));
            float   fY          = Vector3.Dot(dv, rotateFrameW.GetAxis(iY));
            float   fNewAngle   = (float)Math.Atan2(fY, fX);
            float   fDeltaAngle = (fNewAngle - fRotateStartAngle);

            // construct new frame for target that is rotated around axis
            Vector3    rotateAxisL = rotateFrameL.GetAxis(nRotationAxis);
            Quaternion q           = Quaternion.AngleAxis(fDeltaAngle * Mathf.Rad2Deg, rotateAxisL);
            Frame3     newFrame    = rotateFrameL;

            newFrame.Rotation = q * newFrame.Rotation;                          // order matters here!

            // update target
            target.SetLocalFrame(newFrame, CoordSpace.ObjectCoords);

            return(true);
        }
Пример #2
0
        public void SetLocalFrame(Frame3 newFrame, CoordSpace eSpace)
        {
            Debug.Assert(eSpace == CoordSpace.ObjectCoords);

            Frame3 updateFrame = objectFrame;

            curRotation          = newFrame.Rotation;
            updateFrame.Rotation = curRotation * objectFrame.Rotation;
            updateFrame.Origin   = newFrame.Origin;
            target.SetLocalFrame(updateFrame, eSpace);
        }
Пример #3
0
        Vector3 vInitialHitPos;                 // initial hit position in frame

        public bool BeginCapture(ITransformable target, Ray 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);
        }
Пример #4
0
        static public void EmitDebugFrame(string name, Frame3 f, float fAxisLength, float diameter = 0.05f)
        {
            GameObject frame = new GameObject(name);
            GameObject x     = EmitDebugLine(name + "_x", f.Origin, f.Origin + fAxisLength * f.X, diameter, Color.red);

            x.transform.parent = frame.transform;
            GameObject y = EmitDebugLine(name + "_y", f.Origin, f.Origin + fAxisLength * f.Y, diameter, Color.green);

            y.transform.parent = frame.transform;
            GameObject z = EmitDebugLine(name + "_z", f.Origin, f.Origin + fAxisLength * f.Z, diameter, Color.blue);

            z.transform.parent = frame.transform;
        }
Пример #5
0
        public bool EndCapture(Ray ray)
        {
            if (activeWidget != null)
            {
                // update widget frame in case we want to do something like stay scene-aligned...
                targetWrapper.DoneTransformation();
                Frame3 widgetFrame = targetWrapper.GetLocalFrame(CoordSpace.ObjectCoords);
                gizmo.transform.localPosition = widgetFrame.Origin;
                gizmo.transform.localRotation = widgetFrame.Rotation;

                activeWidget = null;
            }
            return(true);
        }
Пример #6
0
 public bool UpdateCapture(Ray worldRay)
 {
     // update capture if we have an active widget
     if (activeWidget != null)
     {
         if (activeWidget.UpdateCapture(targetWrapper, worldRay))
         {
             // keep widget synced with object frame of target
             Frame3 widgetFrame = targetWrapper.GetLocalFrame(CoordSpace.ObjectCoords);
             gizmo.transform.localPosition = widgetFrame.Origin;
             gizmo.transform.localRotation = widgetFrame.Rotation;
         }
         return(true);
     }
     return(false);
 }
Пример #7
0
        public Frame3 GetLocalFrame(CoordSpace eSpace)
        {
            Frame3 targetFrame = target.GetLocalFrame(eSpace);

            if (eSpace == CoordSpace.WorldCoords)
            {
                return(new Frame3(targetFrame.Origin, parentScene.RootGameObject.transform.rotation));
            }
            else if (eSpace == CoordSpace.SceneCoords)
            {
                return(new Frame3(targetFrame.Origin, parentScene.RootGameObject.transform.localRotation));
            }
            else
            {
                return(new Frame3(targetFrame.Origin, curRotation * Quaternion.identity));
            }
        }
Пример #8
0
        void SetActiveFrame(FrameType eFrame)
        {
            if (eFrame == FrameType.LocalFrame)
            {
                targetWrapper = new PassThroughWrapper(target);
            }
            else
            {
                targetWrapper = new SceneFrameWrapper(parentScene, target);
            }

            // update gizmo transform to match target frame
            Frame3 widgetFrame = targetWrapper.GetLocalFrame(CoordSpace.ObjectCoords);

            gizmo.transform.localPosition = widgetFrame.Origin;
            gizmo.transform.localRotation = widgetFrame.Rotation;
        }
Пример #9
0
        public void Initialize(Cockpit cockpit)
        {
            Frame3 cockpitF = cockpit.GetLocalFrame(CoordSpace.WorldCoords);

            float fHUDRadius = 0.7f;
            Color bgColor    = new Color(0.7f, 0.7f, 1.0f);

            Material bgMaterial   = MaterialUtil.CreateTransparentMaterial(bgColor, 0.7f);
            Material primMaterial = MaterialUtil.CreateStandardMaterial(Color.yellow);

            HUDButton addCylinderButton = new HUDButton()
            {
                Radius = 0.08f
            };

            addCylinderButton.Create(PrimitiveType.Cylinder, bgMaterial, primMaterial);
            Frame3 cylFrame    = addCylinderButton.GetObjectFrame();
            Frame3 cylHUDFrame = make_hud_sphere_frame(fHUDRadius, -45.0f, 0.0f);

            addCylinderButton.SetObjectFrame(
                cylFrame.Translated(cylHUDFrame.Origin)
                .Rotated(Quaternion.FromToRotation(cylFrame.Z, cylHUDFrame.Z)));
            addCylinderButton.OnClicked += (s, e) => {
                cockpit.Parent.Scene.AddCylinder();
            };
            cockpit.AddUIElement(addCylinderButton, true);


            HUDButton addBoxButton = new HUDButton()
            {
                Radius = 0.08f
            };

            addBoxButton.Create(PrimitiveType.Cube, bgMaterial, primMaterial);
            Frame3 boxFrame    = addBoxButton.GetObjectFrame();
            Frame3 boxHUDFrame = make_hud_sphere_frame(fHUDRadius, -45.0f, -15.0f);

            addBoxButton.SetObjectFrame(
                boxFrame.Translated(boxHUDFrame.Origin)
                .Rotated(Quaternion.FromToRotation(boxFrame.Z, boxHUDFrame.Z)));
            addBoxButton.OnClicked += (s, e) => {
                cockpit.Parent.Scene.AddBox();
            };
            cockpit.AddUIElement(addBoxButton, true);
        }
Пример #10
0
 public static void SetGameObjectFrame(GameObject go, Frame3 newFrame, CoordSpace eSpace)
 {
     if (eSpace == CoordSpace.WorldCoords)
     {
         go.transform.position = newFrame.Origin;
         go.transform.rotation = newFrame.Rotation;
     }
     else if (eSpace == CoordSpace.ObjectCoords)
     {
         go.transform.localPosition = newFrame.Origin;
         go.transform.localRotation = newFrame.Rotation;
     }
     else
     {
         // [RMS] cannot do this w/o handle to scene...
         Debug.Log("[MathUtil.SetGameObjectFrame] unsupported!\n");
         throw new ArgumentException("not possible without refernce to scene!");
     }
 }
        public bool UpdateCapture(ITransformable target, Ray worldRay)
        {
            // ray-hit with plane that contains translation axis
            Vector3 planeHit = raycastFrame.RayPlaneIntersection(worldRay.origin, worldRay.direction, 2);

            // figure out new T-value along axis, then our translation update is delta-t
            float fNewT   = MathUtil.ClosestPointOnLineT(translateFrameW.Origin, translateAxisW, planeHit);
            float fDeltaT = (fNewT - fTranslateStartT);

            // construct new frame translated along axis (in local space)
            Frame3 newFrame = translateFrameL;

            newFrame.Origin += fDeltaT * translateFrameL.GetAxis(nTranslationAxis);

            // update target
            target.SetLocalFrame(newFrame, CoordSpace.ObjectCoords);

            return(true);
        }
        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);
        }
Пример #13
0
        public bool BeginCapture(ITransformable target, Ray 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
            Vector3 vWorldHitPos = hit.hitPos;
            Vector3 dv           = vWorldHitPos - rotateFrameW.Origin;
            int     iX           = (nRotationAxis + 1) % 3;
            int     iY           = (nRotationAxis + 2) % 3;
            float   fX           = Vector3.Dot(dv, rotateFrameW.GetAxis(iX));
            float   fY           = Vector3.Dot(dv, rotateFrameW.GetAxis(iY));

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

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

            return(true);
        }
Пример #14
0
        public bool UpdateCapture(ITransformable target, Ray worldRay)
        {
            // ray-hit with world-space translation plane
            Vector3 planeHit = translateFrameW.RayPlaneIntersection(worldRay.origin, worldRay.direction, nTranslationPlaneNormal);
            int     e0       = (nTranslationPlaneNormal + 1) % 3;
            int     e1       = (nTranslationPlaneNormal + 2) % 3;

            // construct delta in world space and project into frame coordinates
            Vector3 delta = (planeHit - vInitialHitPos);
            float   dx    = Vector3.Dot(delta, translateFrameW.GetAxis(e0));
            float   dy    = Vector3.Dot(delta, translateFrameW.GetAxis(e1));

            // construct new local frame translated along plane axes
            Frame3 newFrame = translateFrameL;

            newFrame.Origin += dx * translateFrameL.GetAxis(e0) + dy * translateFrameL.GetAxis(e1);

            // update target
            target.SetLocalFrame(newFrame, CoordSpace.ObjectCoords);

            return(true);
        }
Пример #15
0
 public void SetLocalFrame(Frame3 newFrame, CoordSpace eSpace)
 {
     // note: SceneCoords not supported!
     MathUtil.SetGameObjectFrame(RootGameObject, newFrame, eSpace);
 }
Пример #16
0
 public Frame3 SceneToWorldF(Frame3 sceneFrame)
 {
     return(new Frame3(
                sceneo.transform.TransformPoint(sceneFrame.Origin),
                sceneo.transform.rotation * sceneFrame.Rotation));
 }
Пример #17
0
 public Frame3 WorldToSceneF(Frame3 worldFrame)
 {
     return(new Frame3(
                worldFrame.Origin - sceneo.transform.localPosition,
                Quaternion.Inverse(sceneo.transform.localRotation) * worldFrame.Rotation));
 }
Пример #18
0
 public virtual void SetLocalFrame(Frame3 newFrame, CoordSpace eSpace)
 {
     MathUtil.SetGameObjectFrame(gameobject, newFrame, eSpace);
 }
Пример #19
0
 public void SetObjectFrame(Frame3 value)
 {
     MathUtil.SetGameObjectFrame(RootGameObject, value, CoordSpace.ObjectCoords);
 }
Пример #20
0
 public void SetLocalFrame(Frame3 newFrame, CoordSpace eSpace)
 {
     target.SetLocalFrame(newFrame, eSpace);
 }
Пример #21
0
 public void BeginTransformation()
 {
     objectFrame = target.GetLocalFrame(CoordSpace.ObjectCoords);
     curRotation = Quaternion.identity;
 }
Пример #22
0
 public Frame3(Frame3 copy)
 {
     this.rotation = copy.rotation;
     this.origin   = copy.origin;
 }