private void getRotateAroundCamera(Point endPoint) { float adjustPos = (float)Math.Tan(ExtensionGL.Radians(FOV / 2.0f)) * 0.1f / (panelOpenGL.Height / 2.0f); float dx = (endPoint.X - startPoint.X); float dy = (endPoint.Y - startPoint.Y); float dxmin = panelOpenGL.Width / 100f; float dymin = panelOpenGL.Height / 100f; float x = (Math.Abs(dx) >= dxmin) ? dx * adjustPos : 0; float y = (Math.Abs(dy) >= dymin) ? dy * adjustPos : 0; Vector3 perp = new Vector3(-y, -x, 0f); float theta = (float)Math.Atan(perp.Length / 0.1f); //Compute the length of the perpendicular vector if (perp.Length > float.Epsilon) //if its non-zero { // Return the perpendicular vector as the transform after all rotation.X = perp.X; rotation.Y = perp.Y; rotation.Z = perp.Z; //In the quaternion values, w is cosine (theta / 2), where theta is the rotation angle rotation.W = (float)Math.Cos(theta / 2); var trans = new Transform3DGroup(); trans.TranslateBy(-camera.Position); trans.RotateBy(rotation); trans.TranslateBy(camera.Position); currentTrans = trans; updateModelMatricies(); } }