Example #1
0
        public override ManipulatorPickResult Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == ManipulatorPickResult.Miss)
            {
                return(ManipulatorPickResult.Miss);
            }

            m_node = GetManipulatorNode(TransformationTypes.Pivot);

            Camera   camera = vc.Camera;
            Matrix4F view   = camera.ViewMatrix;
            Matrix4F vp     = view * camera.ProjectionMatrix;
            Matrix4F wvp    = HitMatrix * vp;

            Ray3F rayL = vc.GetRay(scrPt, wvp);

            m_hitRegion = m_translatorControl.Pick(vc, HitMatrix, view, rayL, HitRayV);
            bool picked = m_hitRegion != HitRegion.None;

            if (picked)
            {
                return(ManipulatorPickResult.DeferredBeginDrag);
            }
            return(ManipulatorPickResult.Miss);
        }
Example #2
0
        public ViewControl()
        {
            // this control will be painted using some 3d API
            // no need for double buffering
            // also no need for the OS to paint it.
            this.ResizeRedraw   = false;
            this.DoubleBuffered = false;
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.Opaque, true);
            AllowDrop = true;
            m_camera  = new Camera();


            m_camera.SetPerspective((float)(Math.PI / 4), 1.0f, 0.1f, 2048);
            m_cameraController        = new MayaStyleCameraController();
            m_cameraController.Camera = m_camera;

            Sphere3F sphere = new Sphere3F(new Vec3F(0, 0, 0), 25.0f);
            float    nearZ  = m_camera.PerspectiveNearZ;

            m_camera.ZoomOnSphere(sphere);
            m_camera.PerspectiveNearZ = nearZ;
            m_camera.CameraChanged   += new EventHandler(CameraChanged);
        }
Example #3
0
        public override void Render(ViewControl vc)
        {
            Matrix4F normWorld = GetManipulatorMatrix();

            if (normWorld == null)
            {
                return;
            }

            Camera camera = vc.Camera;
            float  s;

            Util.CalcAxisLengths(camera, normWorld.Translation, out s);
            m_translatorControl.Render(normWorld, s);

            Matrix4F sc  = new Matrix4F();
            Vec3F    pos = normWorld.Translation;

            s /= 12.0f;
            sc.Scale(s);

            Matrix4F bl = new Matrix4F();

            Util.CreateBillboard(bl, pos, camera.WorldEye, camera.Up, camera.LookAt);

            Matrix4F recXform = new Matrix4F();

            Matrix4F.Multiply(sc, bl, recXform);

            Util3D.DrawPivot(recXform, Color.Yellow);
        }
Example #4
0
        public override bool Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == false)
            {
                return(false);
            }

            m_node = GetManipulatorNode(TransformationTypes.Pivot);

            Camera camera = vc.Camera;
            float  s;

            Util.CalcAxisLengths(camera, HitMatrix.Translation, out s);
            Matrix4F view = camera.ViewMatrix;
            Matrix4F vp   = view * camera.ProjectionMatrix;
            Matrix4F wvp  = HitMatrix * vp;

            Ray3F rayL = vc.GetRay(scrPt, wvp);

            m_hitRegion = m_translatorControl.Pick(HitMatrix, view, rayL, HitRayV, s);
            bool picked = m_hitRegion != HitRegion.None;

            return(picked);
        }
        /// <summary>
        /// Synchronizes the camera to the controller's current state</summary>
        /// <param name="camera">Camera</param>
        protected override void ControllerToCamera(Camera camera)
        {
            Vec3F lookAt = camera.LookAt;
            Vec3F right  = camera.Right;
            Vec3F up     = camera.Up;

            if (camera.ViewType == ViewTypes.Perspective)
            {
                // override the camera's frame of reference
                float sinPhi   = (float)Math.Sin(m_elevation);
                float cosPhi   = (float)Math.Cos(m_elevation);
                float sinTheta = (float)Math.Sin(m_azimuth);
                float cosTheta = (float)Math.Cos(m_azimuth);

                lookAt = new Vec3F(-cosPhi * sinTheta, -sinPhi, -cosPhi * cosTheta);
                right  = new Vec3F(cosTheta, 0, -sinTheta);
                up     = Vec3F.Cross(right, lookAt); // TODO compute from sin/cos values
            }

            float lookAtOffset = 0;

            if (m_distanceFromLookAt < m_dollyThreshold) // do we need to start dollying?
            {
                lookAtOffset = m_distanceFromLookAt - m_dollyThreshold;
            }

            float eyeOffset = m_distanceFromLookAt;

            Camera.Set(m_lookAtPoint - (eyeOffset * lookAt),    // eye point
                       m_lookAtPoint - (lookAtOffset * lookAt), // look-at point
                       up);                                     // up vector

            base.ControllerToCamera(camera);
        }
        /// <summary>
        /// Synchronizes the controller to the camera's current state</summary>
        /// <param name="camera">Camera</param>
        protected override void CameraToController(Camera camera)
        {
            m_lookAtPoint        = Camera.LookAtPoint;
            m_distanceFromLookAt = Camera.DistanceFromLookAt;
            m_dollyThreshold     = Camera.FocusRadius * 0.1f;

            Vec3F lookAtDir = Camera.LookAt;
            Vec3F up        = Camera.Up;

            m_elevation = (float)Math.Asin(-lookAtDir.Y);
            if (up.Y < 0)
            {
                if (lookAtDir.Y > 0)
                {
                    m_elevation = -PI - m_elevation;
                }
                else
                {
                    m_elevation = PI - m_elevation;
                }
                m_azimuth = (float)Math.Atan2(lookAtDir.X, lookAtDir.Z);
            }
            else
            {
                m_azimuth = (float)Math.Atan2(-lookAtDir.X, -lookAtDir.Z);
            }

            base.CameraToController(camera);
        }
Example #7
0
        public ViewControl()
        {           
            // this control will be painted using some 3d API
            // no need for double buffering
            // also no need for the OS to paint it.
            this.ResizeRedraw = false;
            this.DoubleBuffered = false;
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.Opaque, true);
            AllowDrop = true;
            m_camera = new Camera();


            m_camera.SetPerspective((float)(Math.PI / 4), 1.0f, 0.1f, 2048);
            m_cameraController = new MayaStyleCameraController();
            m_cameraController.Camera = m_camera;

            Sphere3F sphere = new Sphere3F(new Vec3F(0, 0, 0), 25.0f);
            float nearZ = m_camera.PerspectiveNearZ;
            m_camera.ZoomOnSphere(sphere);
            m_camera.PerspectiveNearZ = nearZ;
            m_camera.CameraChanged += new EventHandler(CameraChanged);

        }
Example #8
0
        public override bool Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == false)
            {
                return(false);
            }

            Camera camera = vc.Camera;
            float  rad;

            Util.CalcAxisLengths(camera, HitMatrix.Translation, out rad);
            float tolerance = rad / 10.0f;

            // compute ray in object space  space.
            Matrix4F vp   = camera.ViewMatrix * camera.ProjectionMatrix;
            Matrix4F wvp  = HitMatrix * vp;
            Ray3F    rayL = vc.GetRay(scrPt, wvp);

            Plane3F xplane = new Plane3F(Vec3F.XAxis, Vec3F.ZeroVector);
            Plane3F yplane = new Plane3F(Vec3F.YAxis, Vec3F.ZeroVector);
            Plane3F zplane = new Plane3F(Vec3F.ZAxis, Vec3F.ZeroVector);

            Vec3F pt;
            float xdelta = float.MaxValue;
            float ydelta = float.MaxValue;
            float zdelta = float.MaxValue;

            if (rayL.IntersectPlane(xplane, out pt))
            {
                xdelta = Math.Abs(pt.Length - rad);
            }

            if (rayL.IntersectPlane(yplane, out pt))
            {
                ydelta = Math.Abs(pt.Length - rad);
            }

            if (rayL.IntersectPlane(zplane, out pt))
            {
                zdelta = Math.Abs(pt.Length - rad);
            }

            if (xdelta < tolerance && xdelta < ydelta && xdelta < zdelta)
            {
                m_hitRegion = HitRegion.XAxis;
            }
            else if (ydelta < tolerance && ydelta < zdelta)
            {
                m_hitRegion = HitRegion.YAxis;
            }
            else if (zdelta < tolerance)
            {
                m_hitRegion = HitRegion.ZAxis;
            }

            return(m_hitRegion != HitRegion.None);
        }
Example #9
0
        public override bool MouseMove(object sender, MouseEventArgs e)
        {
            if (m_dragging &&
                InputScheme.ActiveControlScheme.IsControllingCamera(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
            {
                Control c  = sender as Control;
                float   dx = e.X - m_lastMousePointX;
                float   dy = e.Y - m_lastMousePointY;

                if (InputScheme.ActiveControlScheme.IsRotating(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)) &&
                    (Camera.ViewType == ViewTypes.Perspective || LockOrthographic == false))
                {
                    var orbitRotationSpeed = .0005f * (float)Math.PI;

                    // just do this orbitting calculation in spherical coords...
                    // it's much easier than any other method
                    var orbitCenter = Camera.LookAtPoint;
                    var spherical   = CartesianToSphericalYUp(orbitCenter - Camera.Eye);
                    spherical[0] += dy * orbitRotationSpeed;
                    spherical[0]  = Clamp(spherical[0], (float)Math.PI * 0.02f, (float)Math.PI * 0.98f);
                    spherical[1] += dx * orbitRotationSpeed;

                    var defaultUp = new Vec3F(0.0f, 1.0f, 0.0f);    // (geometry gets hopelessly unnormalized if we don't reset default-up here)
                    Camera.Set(orbitCenter - SphericalToCartesianYUp(spherical), orbitCenter, defaultUp);
                    if (Camera.ViewType != ViewTypes.Perspective)
                    {
                        Camera.ViewType = ViewTypes.Perspective;
                    }
                }
                else if (InputScheme.ActiveControlScheme.IsZooming(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
                {
                    float zoom = (-dy - dx);

                    float adj       = Camera.DistanceFromLookAt;
                    var   zoomSpeed = 0.01f * adj;
                    var   lookAtDir = Vec3F.Normalize(Camera.LookAt);
                    var   movement  = Math.Min(zoom * zoomSpeed, Camera.DistanceFromLookAt - 0.1f);
                    Camera.Set(Camera.Eye + lookAtDir * movement, Camera.LookAtPoint, Camera.Up);
                }
                else if (InputScheme.ActiveControlScheme.IsPanning(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
                {
                    float adj         = Camera.DistanceFromLookAt;
                    var   panSpeed    = 0.001f * adj;
                    var   lookAtPoint = Camera.LookAtPoint;
                    var   translation = (Camera.Up * dy * panSpeed) + (Camera.Right * -dx * panSpeed);
                    Camera.Set(Camera.Eye + translation, lookAtPoint + translation, Camera.Up);
                }

                m_lastMousePointX = e.Location.X;
                m_lastMousePointY = e.Location.Y;
                return(true);
            }

            return(base.MouseMove(sender, e));
        }
Example #10
0
        public override bool MouseDown(object sender, MouseEventArgs e)
        {
            if (InputScheme.ActiveControlScheme.IsControllingCamera(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
            {
                m_lastMousePointX = e.Location.X;
                m_lastMousePointY = e.Location.Y;
                m_dragging        = true;
                return(true);
            }

            if (Control.ModifierKeys.HasFlag(Keys.Control) && !Control.ModifierKeys.HasFlag(Keys.Shift) && e.Button == MouseButtons.Left)
            {
                // "control + l click" repositions the "focus" point of the camera
                //      -- it's just incredibly useful to be able to manually set the point, because it
                //          allows the user to specify both the speed of the movement of the camera and
                //          the orbit of the camera in a natural way
                //
                // We could expand "ActiveControlScheme" to allow this key binding to be rebound...
                // but just using fixed binding for now.
                // This is a very important key combination (it's just really useful to be able to move
                // the focus around quickly) -- so it should be accessable with any easy combination from
                // anywhere!

                ViewControl           c  = sender as ViewControl;
                GUILayer.IViewContext vc = sender as GUILayer.IViewContext;
                if (c != null && vc != null)
                {
                    // We can use XLEBridgeUtils to do the ray test. This will
                    // execute the native code (which in turn performs the intersection
                    // on the GPU)
                    // Note that we're using the more complex picking interface because
                    // we want to use explicitly pass "Camera" (rather than
                    // getting it from the view control)
                    var hit = XLEBridgeUtils.Picking.RayPick(
                        GUILayer.EngineDevice.GetInstance(),
                        vc.SceneManager, vc.TechniqueContext,
                        c.GetWorldRay(e.Location), XLEBridgeUtils.Utils.AsCameraDesc(Camera), c.ClientSize,
                        XLEBridgeUtils.Picking.Flags.AllWorldObjects);
                    if (hit != null && hit.Length > 0)
                    {
                        Vec3F transformedPt;
                        Camera.AxisSystem.Transform(hit[0].hitPt, out transformedPt);
                        Camera.Set(Camera.Eye, transformedPt, Camera.Up);
                    }
                }

                return(true);
            }

            return(base.MouseDown(sender, e));
        }
Example #11
0
        public override bool MouseWheel(object sender, MouseEventArgs e)
        {
            if (!InputScheme.ActiveControlScheme.IsZooming(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
            {
                return(true);
            }

            float adj       = Camera.DistanceFromLookAt;
            var   zoomSpeed = .1f / 120.0f * adj;
            var   lookAtDir = Vec3F.Normalize(Camera.LookAt);
            var   movement  = Math.Min(e.Delta * zoomSpeed, Camera.DistanceFromLookAt - 0.1f);

            Camera.Set(Camera.Eye + lookAtDir * movement, Camera.LookAtPoint, Camera.Up);
            return(true);
        }
        public override bool Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == false)
            {
                return(false);
            }

            Camera camera = vc.Camera;

            Matrix4F view = camera.ViewMatrix;
            Matrix4F vp   = view * camera.ProjectionMatrix;
            Matrix4F wvp  = HitMatrix * vp;

            Ray3F rayL = vc.GetRay(scrPt, wvp);

            float s = Util.CalcAxisScale(vc.Camera, HitMatrix.Translation, AxisLength, vc.Height);

            // There's only one hot-spot for this manipulator:
            //      a square at the manipulator origin.
            Vec3F min = new Vec3F(-0.5f, -0.5f, -0.5f);
            Vec3F max = new Vec3F(0.5f, 0.5f, 0.5f);
            AABB  box = new AABB(min, max);

            float    centerCubeScale = s * CenterCubeSize;
            Matrix4F centerCubeXform = new Matrix4F();

            centerCubeXform.Scale(centerCubeScale);
            centerCubeXform.Invert(centerCubeXform);
            Ray3F ray = rayL;

            ray.Transform(centerCubeXform);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.XYSquare;
                return(true);
            }

            m_hitRegion = HitRegion.None;
            return(false);
        }
Example #13
0
        public override bool Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == false)
            {
                return(false);
            }

            Camera camera = vc.Camera;

            Matrix4F view = camera.ViewMatrix;
            Matrix4F vp   = view * camera.ProjectionMatrix;
            Matrix4F wvp  = HitMatrix * vp;

            Ray3F rayL = vc.GetRay(scrPt, wvp);

            m_hitRegion = m_translatorControl.Pick(vc, HitMatrix, view, rayL, HitRayV);

            bool picked = m_hitRegion != HitRegion.None;

            return(picked);
        }
Example #14
0
        public override void Render(ViewControl vc)
        {
            BasicRendererFlags solid = BasicRendererFlags.Solid
                                       | BasicRendererFlags.DisableDepthTest;
            BasicRendererFlags wire = BasicRendererFlags.WireFrame
                                      | BasicRendererFlags.DisableDepthTest;

            Matrix4F normWorld = GetManipulatorMatrix();

            if (normWorld == null)
            {
                return;
            }
            Camera camera = vc.Camera;

            int axis = (int)m_hitRegion;

            // axis colors
            Color saveColor = m_axisColor[axis];

            m_axisColor[axis] = m_highlightColor;
            Color xcolor  = m_axisColor[(int)HitRegion.XAxis];
            Color ycolor  = m_axisColor[(int)HitRegion.YAxis];
            Color zcolor  = m_axisColor[(int)HitRegion.ZAxis];
            Color nxcolor = m_axisColor[(int)HitRegion.NegXAxis];
            Color nycolor = m_axisColor[(int)HitRegion.NegYAxis];
            Color nzcolor = m_axisColor[(int)HitRegion.NegZAxis];

            m_axisColor[axis] = saveColor;

            Vec3F deltaTrans = Vec3F.ZeroVector;

            if (m_hitRegion != HitRegion.None)
            {
                normWorld.Translation = HitMatrix.Translation;
            }

            Vec3F pos = normWorld.Translation;
            float s;

            Util.CalcAxisLengths(vc.Camera, pos, out s);

            Vec3F sv           = new Vec3F(s, s, s);
            Vec3F axscale      = new Vec3F(s, s, s);
            Vec3F negAxscale   = new Vec3F(-s, -s, -s);
            bool  negativeAxis = m_hitRegion == HitRegion.NegXAxis || m_hitRegion == HitRegion.NegYAxis || m_hitRegion == HitRegion.NegZAxis;

            if (negativeAxis)
            {
                negAxscale.X *= Math.Abs(m_scale.X);
                negAxscale.Y *= Math.Abs(m_scale.Y);
                negAxscale.Z *= Math.Abs(m_scale.Z);
            }
            else
            {
                axscale.X *= Math.Abs(m_scale.X);
                axscale.Y *= Math.Abs(m_scale.Y);
                axscale.Z *= Math.Abs(m_scale.Z);
            }

            Matrix4F scale = new Matrix4F();

            scale.Scale(axscale);
            Matrix4F xform = scale * normWorld;

            Util3D.RenderFlag = wire;

            Util3D.DrawX(xform, xcolor);
            Util3D.DrawY(xform, ycolor);
            Util3D.DrawZ(xform, zcolor);

            scale.Scale(negAxscale);
            xform = scale * normWorld;

            Util3D.DrawX(xform, nxcolor);
            Util3D.DrawY(xform, nycolor);
            Util3D.DrawZ(xform, nzcolor);

            Vec3F handle      = sv * HandleRatio;
            float handleWidth = handle.X / 2;

            scale.Scale(handle);
            Matrix4F trans = new Matrix4F();



            Util3D.RenderFlag = solid;

            // X handle
            trans.Translation = new Vec3F(axscale.X - handleWidth, 0, 0);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(xform, xcolor);

            // y handle
            trans.Translation = new Vec3F(0, axscale.Y - handleWidth, 0);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(xform, ycolor);

            // z handle
            trans.Translation = new Vec3F(0, 0, axscale.Z - handleWidth);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(xform, zcolor);


            // -x handle
            trans.Translation = new Vec3F(negAxscale.X + handleWidth, 0, 0);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(xform, nxcolor);

            // -y handle
            trans.Translation = new Vec3F(0, negAxscale.Y + handleWidth, 0);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(xform, nycolor);

            // -z handle
            trans.Translation = new Vec3F(0, 0, negAxscale.Z + handleWidth);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(xform, nzcolor);
        }
Example #15
0
 private void RenderCallback(DesignView designView, Sce.Atf.Rendering.Camera camera)
 {
 }
Example #16
0
            // render the scene.
            public void Render()
            {
                if (GameEngine.IsInError ||
                    SurfaceId == 0 ||
                    Visible == false ||
                    Width == 0 ||
                    Height == 0 ||
                    Game == null)
                {
                    return;
                }


                NativeObjectAdapter gameLevel = GameEngine.GetGameLevel();

                try
                {
                    NativeObjectAdapter game = Game.As <NativeObjectAdapter>();
                    GameEngine.SetGameLevel(game);
                    GameEngine.SetRenderState(m_renderState);
                    if (Game.RootGameObjectFolder.GameObjects.Count > 0)
                    {
                        GameEngine.Update(0, 0, true);
                    }

                    if (ResetCamera)
                    {
                        // save view type
                        ViewTypes viewtype = this.ViewType;
                        ViewType = ViewTypes.Perspective;
                        Size       sz        = ClientSize;
                        float      aspect    = (float)sz.Width / (float)sz.Height;
                        IBoundable boundable = Game.RootGameObjectFolder.Cast <IBoundable>();
                        Sce.Atf.VectorMath.Sphere3F sphere = boundable.BoundingBox.ToSphere();
                        float nearZ = sphere.Radius * 0.01f;
                        nearZ = Math.Min(0.1f, nearZ);
                        Camera.SetPerspective(
                            (float)Math.PI / 4,
                            aspect,
                            nearZ,
                            sphere.Radius * 10.0f);

                        Vec3F camPos = sphere.Center + new Vec3F(sphere.Radius, sphere.Radius, sphere.Radius) * 1.2f;
                        Camera.Set(camPos, sphere.Center, new Vec3F(0, 1, 0));
                        ViewType    = viewtype;
                        ResetCamera = false;
                    }

                    GameEngine.Begin(SurfaceId, Camera.ViewMatrix, Camera.ProjectionMatrix);
                    if (Game.RootGameObjectFolder.GameObjects.Count > 0)
                    {
                        GameEngine.RenderGame();
                    }
                    string str = "View Type: " + ViewType.ToString();
                    GameEngine.DrawText2D(str, Util3D.CaptionFont, 1, 1, Color.White);
                    GameEngine.End();
                }
                finally
                {
                    GameEngine.SetGameLevel(gameLevel);
                }
            }
Example #17
0
        public override void OnDragging(ViewControl vc, Point scrPt)
        {
            if (m_hitRegion == HitRegion.None || NodeList.Count == 0)
            {
                return;
            }
            Camera cam = vc.Camera;

            Matrix4F view = cam.ViewMatrix;
            Matrix4F mtrx = cam.ProjectionMatrix;

            Matrix4F axisMtrx = HitMatrix * view;
            Ray3F    hitRay   = HitRayV;
            Ray3F    dragRay  = vc.GetRay(scrPt, mtrx);

            Vec3F xAxis  = axisMtrx.XAxis;
            Vec3F yAxis  = axisMtrx.YAxis;
            Vec3F zAxis  = axisMtrx.ZAxis;
            Vec3F origin = axisMtrx.Translation;

            Vec3F rotAxis = new Vec3F();
            float theta   = 0;

            float snapAngle = ((ISnapSettings)DesignView).SnapAngle;

            switch (m_hitRegion)
            {
            case HitRegion.XAxis:
            {
                Plane3F xplane = new Plane3F(xAxis, origin);
                theta   = CalcAngle(origin, xplane, hitRay, dragRay, snapAngle);
                rotAxis = HitMatrix.XAxis;
            }
            break;

            case HitRegion.YAxis:
            {
                Plane3F yplane = new Plane3F(yAxis, origin);
                theta   = CalcAngle(origin, yplane, hitRay, dragRay, snapAngle);
                rotAxis = HitMatrix.YAxis;
            }
            break;

            case HitRegion.ZAxis:
            {
                Plane3F zplane = new Plane3F(zAxis, origin);
                theta   = CalcAngle(origin, zplane, hitRay, dragRay, snapAngle);
                rotAxis = HitMatrix.ZAxis;
            }
            break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            AngleAxisF axf       = new AngleAxisF(-theta, rotAxis);
            Matrix4F   deltaMtrx = new Matrix4F(axf);
            Matrix4F   rotMtrx   = new Matrix4F();

            for (int i = 0; i < NodeList.Count; i++)
            {
                ITransformable node = NodeList[i];
                rotMtrx.Mul(m_rotations[i], deltaMtrx);
                float ax, ay, az;
                rotMtrx.GetEulerAngles(out ax, out ay, out az);
                node.Rotation = new Vec3F(ax, ay, az);
            }
        }
Example #18
0
        public override bool Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == false)
            {
                return(false);
            }

            Camera camera = vc.Camera;
            float  s;

            Util.CalcAxisLengths(camera, HitMatrix.Translation, out s);

            Matrix4F vp  = camera.ViewMatrix * camera.ProjectionMatrix;
            Matrix4F wvp = HitMatrix * vp;

            // get ray in object space  space.
            Ray3F rayL = vc.GetRay(scrPt, wvp);

            m_scale    = new Vec3F(1, 1, 1);
            m_hitScale = s;

            float    rectScale   = s * FreeRectRatio;
            Vec3F    topRight    = rectScale * (new Vec3F(1, 1, 0));
            Vec3F    topLeft     = rectScale * (new Vec3F(-1, 1, 0));
            Vec3F    bottomLeft  = rectScale * (new Vec3F(-1, -1, 0));
            Vec3F    bottomRight = rectScale * (new Vec3F(1, -1, 0));
            Matrix4F planeXform  = Util.CreateBillboard(HitMatrix.Translation, camera.WorldEye, camera.Up, camera.LookAt);
            Matrix4F wvpPlane    = planeXform * vp;

            // create ray in plane's local space.
            Ray3F rayP = vc.GetRay(scrPt, wvpPlane);

            Plane3F plane = new Plane3F(topRight, topLeft, bottomLeft);
            Vec3F   p;

            bool intersect = rayP.IntersectPlane(plane, out p);

            if (intersect)
            {
                bool inside = p.X > topLeft.X &&
                              p.X <topRight.X &&
                                   p.Y> bottomLeft.Y &&
                              p.Y < topLeft.Y;
                if (inside)
                {
                    m_hitRegion = HitRegion.FreeRect;
                    return(true);
                }
            }

            Vec3F    min      = new Vec3F(-0.5f, -0.5f, -0.5f);
            Vec3F    max      = new Vec3F(0.5f, 0.5f, 0.5f);
            AABB     box      = new AABB(min, max);
            Matrix4F boxScale = new Matrix4F();
            Matrix4F boxTrans = new Matrix4F();
            Matrix4F BoxMtrx  = new Matrix4F();

            float handleScale = s * HandleRatio;

            // X axis

            boxScale.Scale(new Vec3F(s, handleScale, handleScale));
            boxTrans.Translation = new Vec3F(s / 2, 0, 0);
            BoxMtrx = boxScale * boxTrans;
            Ray3F ray = rayL;

            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);

            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.XAxis;
                return(true);
            }

            // y axis
            boxScale.Scale(new Vec3F(handleScale, s, handleScale));
            boxTrans.Translation = new Vec3F(0, s / 2, 0);
            BoxMtrx = boxScale * boxTrans;
            ray     = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.YAxis;
                return(true);
            }

            // z axis
            boxScale.Scale(new Vec3F(handleScale, handleScale, s));
            boxTrans.Translation = new Vec3F(0, 0, s / 2);
            BoxMtrx = boxScale * boxTrans;

            ray = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.ZAxis;
                return(true);
            }

            return(false);
        }
Example #19
0
        public void Render(Camera cam)
        {
            GameEngine.SetRendererFlag(BasicRendererFlags.WireFrame);
            IGrid grid = this.As<IGrid>();

            if (grid.Visible == false)
                return;

            float s = grid.Size;

            Matrix4F scale = new Matrix4F();
            scale.Scale(new Vec3F(s, s, s));

            Matrix4F gridXform = new Matrix4F();
            if (cam.Frustum.IsOrtho)
            {
                float dist = cam.ViewMatrix.Translation.Z;
                ViewTypes vt = cam.ViewType;
                if (vt == ViewTypes.Top)
                {
                    gridXform.Translation
                        = new Vec3F(0, dist, 0);
                }
                else if (vt == ViewTypes.Bottom)
                {
                    gridXform.Translation
                        = new Vec3F(0, -dist, 0);
                }
                else if (vt == ViewTypes.Right)
                {
                    gridXform.RotZ(MathHelper.PiOver2);
                    gridXform.Translation
                        = new Vec3F(dist, 0, 0);
                }
                else if (vt == ViewTypes.Left)
                {
                    gridXform.RotZ(MathHelper.PiOver2);
                    gridXform.Translation
                        = new Vec3F(-dist, 0, 0);

                }
                else if (vt == ViewTypes.Front)
                {
                    gridXform.RotX(MathHelper.PiOver2);
                    gridXform.Translation
                        = new Vec3F(0, 0, dist);

                }
                else if (vt == ViewTypes.Back)
                {
                    gridXform.RotX(MathHelper.PiOver2);
                    gridXform.Translation
                        = new Vec3F(0, 0, -dist);

                }
                gridXform.Mul(scale, gridXform);
            }
            else
            {
                Matrix4F trans = new Matrix4F();
                trans.Translation = new Vec3F(0, grid.Height, 0);
                gridXform = Matrix4F.Multiply(scale, trans);
            }

            GameEngine.DrawPrimitive(PrimitiveType.LineList, m_gridVBId, 0, m_gridVertexCount, Color.LightGray,
                                     Matrix4F.Multiply(gridXform, cam.AxisSystem));

            GameEngine.DrawPrimitive(PrimitiveType.LineList, m_basisAxesVBId, 0, m_basisAxesVertexCount, Color.White,
                                     gridXform);
        }
Example #20
0
        public override bool Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == false)
            {
                return(false);
            }

            Camera camera = vc.Camera;

            float s = Util.CalcAxisScale(vc.Camera, HitMatrix.Translation, AxisLength, vc.Height);

            Matrix4F vp  = camera.ViewMatrix * camera.ProjectionMatrix;
            Matrix4F wvp = HitMatrix * vp;

            // get ray in object space  space.
            Ray3F rayL = vc.GetRay(scrPt, wvp);

            m_scale    = new Vec3F(1, 1, 1);
            m_hitScale = s;

            Vec3F min = new Vec3F(-0.5f, -0.5f, -0.5f);
            Vec3F max = new Vec3F(0.5f, 0.5f, 0.5f);
            AABB  box = new AABB(min, max);

            float    centerCubeScale = s * CenterCubeSize;
            Matrix4F centerCubeXform = new Matrix4F();

            centerCubeXform.Scale(centerCubeScale);
            centerCubeXform.Invert(centerCubeXform);
            Ray3F ray = rayL;

            ray.Transform(centerCubeXform);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.CenterCube;
                return(true);
            }

            Matrix4F boxScale = new Matrix4F();
            Matrix4F boxTrans = new Matrix4F();
            Matrix4F BoxMtrx  = new Matrix4F();

            float handleScale = s * AxisHandle;

            // X axis

            boxScale.Scale(new Vec3F(s, handleScale, handleScale));
            boxTrans.Translation = new Vec3F(s / 2, 0, 0);
            BoxMtrx = boxScale * boxTrans;
            ray     = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);

            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.XAxis;
                return(true);
            }

            // y axis
            boxScale.Scale(new Vec3F(handleScale, s, handleScale));
            boxTrans.Translation = new Vec3F(0, s / 2, 0);
            BoxMtrx = boxScale * boxTrans;
            ray     = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.YAxis;
                return(true);
            }

            // z axis
            boxScale.Scale(new Vec3F(handleScale, handleScale, s));
            boxTrans.Translation = new Vec3F(0, 0, s / 2);
            BoxMtrx = boxScale * boxTrans;

            ray = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.ZAxis;
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Synchronizes the camera to the controller's current state</summary>
        /// <param name="camera">Camera</param>
        protected override void ControllerToCamera(Camera camera)
        {
            Vec3F lookAt = camera.LookAt;
            Vec3F right = camera.Right;
            Vec3F up = camera.Up;

            if (camera.ViewType == ViewTypes.Perspective)
            {
                
                // override the camera's frame of reference
                float sinPhi = (float)Math.Sin(m_elevation);
                float cosPhi = (float)Math.Cos(m_elevation);
                float sinTheta = (float)Math.Sin(m_azimuth);
                float cosTheta = (float)Math.Cos(m_azimuth);

                lookAt = new Vec3F(-cosPhi * sinTheta, -sinPhi, -cosPhi * cosTheta);
                right = new Vec3F(cosTheta, 0, -sinTheta);
                up = Vec3F.Cross(right, lookAt); // TODO compute from sin/cos values
            }

            float lookAtOffset = 0;
            if (m_distanceFromLookAt < m_dollyThreshold) // do we need to start dollying?
                lookAtOffset = m_distanceFromLookAt - m_dollyThreshold;

            float eyeOffset = m_distanceFromLookAt;

            Camera.Set(m_lookAtPoint - (eyeOffset * lookAt),       // eye point
                m_lookAtPoint - (lookAtOffset * lookAt),    // look-at point
                up);                                        // up vector

            base.ControllerToCamera(camera);
        }
Example #22
0
 protected override void CameraToController(Camera camera)
 {
     base.CameraToController(camera);
 }
Example #23
0
 protected override void CameraToController(Camera camera)
 {
     base.CameraToController(camera);
 }
Example #24
0
 protected override void ControllerToCamera(Camera camera)
 {
     base.ControllerToCamera(camera);
 }
Example #25
0
        public override ManipulatorPickResult Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == ManipulatorPickResult.Miss)
            {
                return(ManipulatorPickResult.Miss);
            }

            Camera camera = vc.Camera;
            float  s      = Util.CalcAxisScale(vc.Camera, HitMatrix.Translation, AxisLength, vc.Height);

            Matrix4F vp  = camera.ViewMatrix * camera.ProjectionMatrix;
            Matrix4F wvp = HitMatrix * vp;

            // get ray in object space  space.
            Ray3F rayL = vc.GetRay(scrPt, wvp);

            m_scale    = new Vec3F(1, 1, 1);
            m_hitScale = s;


            Vec3F    min      = new Vec3F(-0.5f, -0.5f, -0.5f);
            Vec3F    max      = new Vec3F(0.5f, 0.5f, 0.5f);
            AABB     box      = new AABB(min, max);
            Matrix4F boxScale = new Matrix4F();
            Matrix4F boxTrans = new Matrix4F();
            Matrix4F BoxMtrx  = new Matrix4F();

            float handleScale = s * AxisHandle;

            // +X axis
            boxScale.Scale(new Vec3F(s, handleScale, handleScale));
            boxTrans.Translation = new Vec3F(s / 2, 0, 0);
            BoxMtrx = boxScale * boxTrans;

            Ray3F ray = rayL;

            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);

            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.XAxis;
                return(ManipulatorPickResult.DeferredBeginDrag);
            }

            // -X
            boxTrans.Translation = new Vec3F(-s / 2, 0, 0);
            BoxMtrx = boxScale * boxTrans;

            ray = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);

            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.NegXAxis;
                return(ManipulatorPickResult.DeferredBeginDrag);
            }

            // y axis
            boxScale.Scale(new Vec3F(handleScale, s, handleScale));
            boxTrans.Translation = new Vec3F(0, s / 2, 0);
            BoxMtrx = boxScale * boxTrans;

            ray = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.YAxis;
                return(ManipulatorPickResult.DeferredBeginDrag);
            }

            // -Y
            boxTrans.Translation = new Vec3F(0, -s / 2, 0);
            BoxMtrx = boxScale * boxTrans;
            ray     = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.NegYAxis;
                return(ManipulatorPickResult.DeferredBeginDrag);
            }


            // z axis
            boxScale.Scale(new Vec3F(handleScale, handleScale, s));
            boxTrans.Translation = new Vec3F(0, 0, s / 2);
            BoxMtrx = boxScale * boxTrans;

            ray = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.ZAxis;
                return(ManipulatorPickResult.DeferredBeginDrag);
            }

            // -Z
            boxTrans.Translation = new Vec3F(0, 0, -s / 2);
            BoxMtrx = boxScale * boxTrans;

            ray = rayL;
            BoxMtrx.Invert(BoxMtrx);
            ray.Transform(BoxMtrx);
            if (box.Intersect(ray))
            {
                m_hitRegion = HitRegion.NegZAxis;
                return(ManipulatorPickResult.DeferredBeginDrag);
            }

            return(ManipulatorPickResult.Miss);
        }
Example #26
0
        public override void Render(ViewControl vc)
        {
            BasicRendererFlags solid = BasicRendererFlags.Solid
                                       | BasicRendererFlags.DisableDepthTest;
            BasicRendererFlags wire = BasicRendererFlags.WireFrame
                                      | BasicRendererFlags.DisableDepthTest;


            Matrix4F normWorld = GetManipulatorMatrix();

            if (normWorld == null)
            {
                return;
            }

            Camera camera = vc.Camera;
            Vec3F  pos    = normWorld.Translation;
            float  s;

            Util.CalcAxisLengths(vc.Camera, pos, out s);

            Vec3F sv      = new Vec3F(s, s, s);
            Vec3F axscale = new Vec3F(Math.Abs(s * m_scale.X), Math.Abs(s * m_scale.Y), Math.Abs(s * m_scale.Z));

            Color xcolor   = (m_hitRegion == HitRegion.XAxis || m_hitRegion == HitRegion.FreeRect) ? Color.Gold : Color.Red;
            Color ycolor   = (m_hitRegion == HitRegion.YAxis || m_hitRegion == HitRegion.FreeRect) ? Color.Gold : Color.Green;
            Color Zcolor   = (m_hitRegion == HitRegion.ZAxis || m_hitRegion == HitRegion.FreeRect) ? Color.Gold : Color.Blue;
            Color freeRect = (m_hitRegion == HitRegion.FreeRect) ? Color.Gold : Color.White;


            Matrix4F scale = new Matrix4F();

            scale.Scale(axscale);
            Matrix4F xform = scale * normWorld;

            Util3D.RenderFlag = wire;
            Util3D.DrawX(xform, xcolor);
            Util3D.DrawY(xform, ycolor);
            Util3D.DrawZ(xform, Zcolor);

            Vec3F rectScale = sv * FreeRectRatio;

            scale.Scale(rectScale);
            Matrix4F b        = Util.CreateBillboard(pos, camera.WorldEye, camera.Up, camera.LookAt);
            Matrix4F recXform = Matrix4F.Multiply(scale, b);

            Util3D.DrawRect(recXform, freeRect);

            Vec3F handle      = sv * HandleRatio;
            float handleWidth = handle.X / 2;

            scale.Scale(handle);
            Matrix4F trans = new Matrix4F();

            trans.Translation = new Vec3F(axscale.X - handleWidth, 0, 0);
            xform             = scale * trans * normWorld;

            Util3D.RenderFlag = solid;

            Util3D.DrawCube(xform, xcolor);

            trans.Translation = new Vec3F(0, axscale.Y - handleWidth, 0);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(xform, ycolor);

            trans.Translation = new Vec3F(0, 0, axscale.Z - handleWidth);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(xform, Zcolor);
        }
Example #27
0
 protected override void ControllerToCamera(Camera camera)
 {
     base.ControllerToCamera(camera);
 }
Example #28
0
        public override bool Pick(ViewControl vc, Point scrPt)
        {
            m_hitRegion = HitRegion.None;
            if (base.Pick(vc, scrPt) == false)
            {
                return(false);
            }

            Camera camera       = vc.Camera;
            float  RingDiameter = 2 * AxisLength;
            float  s            = Util.CalcAxisScale(vc.Camera, HitMatrix.Translation, RingDiameter, vc.Height);

            float rad       = s * Util3D.RingCenterRadias;
            float lrad      = rad * LookRingScale;
            float tolerance = s * Util3D.RingThickness;

            Matrix4F billboard
                = Util.CreateBillboard(HitMatrix.Translation, vc.Camera.WorldEye, vc.Camera.Up, vc.Camera.LookAt);

            m_lookAxisHitMtrx = billboard;
            // compute ray in object space  space.
            Matrix4F vp   = camera.ViewMatrix * camera.ProjectionMatrix;
            Matrix4F wvp  = HitMatrix * vp;
            Ray3F    rayL = vc.GetRay(scrPt, wvp);

            Matrix4F wvp2  = billboard * vp;
            Ray3F    rayL2 = vc.GetRay(scrPt, wvp2);

            Plane3F xplane = new Plane3F(Vec3F.XAxis, Vec3F.ZeroVector);
            Plane3F yplane = new Plane3F(Vec3F.YAxis, Vec3F.ZeroVector);
            Plane3F zplane = new Plane3F(Vec3F.ZAxis, Vec3F.ZeroVector);


            Vec3F pt;
            float xdelta    = float.MaxValue;
            float ydelta    = float.MaxValue;
            float zdelta    = float.MaxValue;
            float lookdelta = float.MaxValue;

            if (rayL.IntersectPlane(xplane, out pt))
            {
                xdelta = Math.Abs(pt.Length - rad);
            }

            if (rayL.IntersectPlane(yplane, out pt))
            {
                ydelta = Math.Abs(pt.Length - rad);
            }

            if (rayL.IntersectPlane(zplane, out pt))
            {
                zdelta = Math.Abs(pt.Length - rad);
            }

            if (rayL2.IntersectPlane(zplane, out pt))
            {
                lookdelta = Math.Abs(pt.Length - lrad);
            }

            if (xdelta < tolerance && xdelta < ydelta && xdelta < zdelta &&
                xdelta < lookdelta)
            {
                m_hitRegion = HitRegion.XAxis;
            }
            else if (ydelta < tolerance && ydelta < zdelta &&
                     ydelta < lookdelta)
            {
                m_hitRegion = HitRegion.YAxis;
            }
            else if (zdelta < tolerance && zdelta < lookdelta)
            {
                m_hitRegion = HitRegion.ZAxis;
            }
            else if (lookdelta < tolerance)
            {
                m_hitRegion = HitRegion.LookAxis;
            }

            return(m_hitRegion != HitRegion.None);
        }
Example #29
0
        public void Render(Camera cam)
        {
            GameEngine.SetRendererFlag(BasicRendererFlags.WireFrame);
            IGrid grid = this.As <IGrid>();

            if (grid.Visible == false)
            {
                return;
            }

            float s = grid.Size;

            Matrix4F scale = new Matrix4F();

            scale.Scale(new Vec3F(s, s, s));

            Matrix4F gridXform = new Matrix4F();

            if (cam.Frustum.IsOrtho)
            {
                float     dist = cam.ViewMatrix.Translation.Z;
                ViewTypes vt   = cam.ViewType;
                if (vt == ViewTypes.Top)
                {
                    gridXform.Translation
                        = new Vec3F(0, dist, 0);
                }
                else if (vt == ViewTypes.Bottom)
                {
                    gridXform.Translation
                        = new Vec3F(0, -dist, 0);
                }
                else if (vt == ViewTypes.Right)
                {
                    gridXform.RotZ(MathHelper.PiOver2);
                    gridXform.Translation
                        = new Vec3F(dist, 0, 0);
                }
                else if (vt == ViewTypes.Left)
                {
                    gridXform.RotZ(MathHelper.PiOver2);
                    gridXform.Translation
                        = new Vec3F(-dist, 0, 0);
                }
                else if (vt == ViewTypes.Front)
                {
                    gridXform.RotX(MathHelper.PiOver2);
                    gridXform.Translation
                        = new Vec3F(0, 0, dist);
                }
                else if (vt == ViewTypes.Back)
                {
                    gridXform.RotX(MathHelper.PiOver2);
                    gridXform.Translation
                        = new Vec3F(0, 0, -dist);
                }
                gridXform.Mul(scale, gridXform);
            }
            else
            {
                Matrix4F trans = new Matrix4F();
                trans.Translation = new Vec3F(0, grid.Height, 0);
                gridXform         = Matrix4F.Multiply(scale, trans);
            }

            GameEngine.DrawPrimitive(PrimitiveType.LineList, m_gridVBId, 0, m_gridVertexCount, Color.LightGray,
                                     gridXform);
        }
        /// <summary>
        /// Synchronizes the controller to the camera's current state</summary>
        /// <param name="camera">Camera</param>
        protected override void CameraToController(Camera camera)
        {
            m_lookAtPoint = Camera.LookAtPoint;
            m_distanceFromLookAt = Camera.DistanceFromLookAt;
            m_dollyThreshold = Camera.FocusRadius * 0.1f;

            Vec3F lookAtDir = Camera.LookAt;
            Vec3F up = Camera.Up;

            m_elevation = (float)Math.Asin(-lookAtDir.Y);
            if (up.Y < 0)
            {
                if (lookAtDir.Y > 0)
                    m_elevation = -PI - m_elevation;
                else
                    m_elevation = PI - m_elevation;
                m_azimuth = (float)Math.Atan2(lookAtDir.X, lookAtDir.Z);
            }
            else
            {
                m_azimuth = (float)Math.Atan2(-lookAtDir.X, -lookAtDir.Z);
            }

            base.CameraToController(camera);
        }
Example #31
0
 public CameraEditingContext(Sce.Atf.Rendering.Camera cam)
 {
     m_items[0] = new Helper(cam);
 }
Example #32
0
 public Helper(Camera cam)
 {
     m_cam = cam;
 }