Esempio n. 1
0
        public void PanCamera(DrawContext dc, Vector2 prev, Vector2 current)
        {
            Vector2 d = current - prev;

            double rx = d.X * (Math.PI / 1000);
            double ry = d.Y * (Math.PI / 1000);

            CadQuaternion q;
            CadQuaternion r;
            CadQuaternion qp;

            Vector3d lookv = dc.LookAt - dc.Eye;
            Vector3d upv   = dc.UpVector;

            q = CadQuaternion.RotateQuaternion(upv, rx);
            r = q.Conjugate();

            qp    = CadQuaternion.FromVector(lookv);
            qp    = r * qp;
            qp    = qp * q;
            lookv = qp.ToVector3d();

            Vector3d ev = dc.LookAt - dc.Eye;

            Vector3d a = new Vector3d(ev);
            Vector3d b = new Vector3d(upv);

            Vector3d axis = CadMath.Normal(a, b);

            if (!axis.IsZero())
            {
                q = CadQuaternion.RotateQuaternion(axis, ry);
                r = q.Conjugate();

                qp = CadQuaternion.FromVector(lookv);
                qp = r * qp;
                qp = qp * q;

                lookv = qp.ToVector3d();

                qp  = CadQuaternion.FromVector(upv);
                qp  = r * qp;
                qp  = qp * q;
                upv = qp.ToVector3d();
            }

            dc.SetCamera(dc.Eye, lookv + dc.Eye, upv);
        }
Esempio n. 2
0
        private void MoveCamera(DrawContext dc, Vector2 prev, Vector2 current)
        {
            Vector3d pv = new Vector3d(prev.X, prev.Y, 0);
            Vector3d cv = new Vector3d(current.X, current.Y, 0);

            Vector3d dv = cv - pv;

            dv.X *= -1.0;

            dc.WorldVectorToDevVector(dv);

            Vector3d lookAt = dc.LookAt + dv;
            Vector3d eye    = dc.Eye + dv;

            dc.SetCamera(eye, lookAt, dc.UpVector);
        }