예제 #1
0
        //Mouse drag, calculate rotation
        public void drag(Point NewPt, Quat4f NewRot)
        {
            //Map the point to the sphere
            this.mapToSphere(NewPt, EnVec);

            //Return the quaternion equivalent to the rotation
            if (NewRot != null)
            {
                Vector3f Perp = new Vector3f();

                //Compute the vector perpendicular to the begin and end vectors
                Vector3f.cross(Perp, StVec, EnVec);

                //Compute the length of the perpendicular vector
                if (Perp.length() > Epsilon)
                //if its non-zero
                {
                    //We're ok, so return the perpendicular vector as the transform after all
                    NewRot.x = Perp.x;
                    NewRot.y = Perp.y;
                    NewRot.z = Perp.z;
                    //In the quaternion values, w is cosine (theta / 2), where theta is the rotation angle
                    NewRot.w = Vector3f.dot(StVec, EnVec);
                }
                //if it is zero
                else
                {
                    //The begin and end vectors coincide, so return an identity transform
                    NewRot.x = NewRot.y = NewRot.z = NewRot.w = 0.0f;
                }
            }
        }
예제 #2
0
        private void drag(Point MousePt)
        {
            Quat4f ThisQuat = new Quat4f();

            arcBall.drag(MousePt, ThisQuat); // Update End Vector And Get Rotation As Quaternion

            lock (matrixLock)
            {
                if (isMiddleDrag) //zoom
                {
                    double len = Math.Sqrt(mouseStartDrag.X * mouseStartDrag.X + mouseStartDrag.Y * mouseStartDrag.Y)
                                 / Math.Sqrt(MousePt.X * MousePt.X + MousePt.Y * MousePt.Y);

                    ThisTransformation.Scale    = (float)len;
                    ThisTransformation.Pan      = new Vector3f(0, 0, 0);
                    ThisTransformation.Rotation = new Quat4f();
                    ThisTransformation.MatrixMultiply(ThisTransformation, LastTransformation); // Accumulate Last Rotation Into This One
                }
                else if (isRightDrag)                                                          //pan
                {
                    float x = (float)(MousePt.X - mouseStartDrag.X) / (float)((this.AnT.Width) * 10);
                    float y = (float)(MousePt.Y - mouseStartDrag.Y) / (float)((this.AnT.Height) * 10);
                    float z = 0.0f;
                    trans_x += (double)x;
                    trans_y += (double)y;
                    trans_z += (double)z;
                    RedrawScene(trans_x, -1 * trans_y, trans_z);

                    /* ThisTransformation.Pan = new Vector3f(x, -1*y, z);
                     * ThisTransformation.Scale = 1.0f;
                     * ThisTransformation.Rotation = new Quat4f();
                     * ThisTransformation.MatrixMultiply(ThisTransformation, LastTransformation);*/
                }
                else if (isLeftDrag) //rotate
                {
                    ThisTransformation.Pan      = new Vector3f(0, 0, 0);
                    ThisTransformation.Scale    = 1.0f;
                    ThisTransformation.Rotation = ThisQuat;
                    ThisTransformation.MatrixMultiply(ThisTransformation, LastTransformation);
                }
            }
        }