//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; } } }
public void Drag(Point MousePt) { if (isRotating) { Quat4f ThisQuat = new Quat4f(); m_arcBall.drag(MousePt, ThisQuat); ThisTransformation.Pan = new Vector3f(0, 0, 0); ThisTransformation.Scale = 1.0f; ThisTransformation.Rotation = ThisQuat; Matrix4f.MatrixMultiply(ThisTransformation, LastTransformation); ThisTransformation.get_Renamed(matrix); } }