edu.sdsc.mbt.viewers.GLViewerImpl
Class VirtualSphere2

java.lang.Object
  extended byedu.sdsc.mbt.viewers.GLViewerImpl.VirtualSphere2

public class VirtualSphere2
extends java.lang.Object

Implements a Virtual Sphere algorithm for 3D rotation using a 2D input device. This can be used for manipulating objects or (by reversing the rotation) as part of a camera control/rotation behavior.

Idea based upon the paper "A Study in Interactive 3-D Rotation Using 2-D Control Devices" by Michael Chen, S. Joy Mountford and Abigail Sellen published in the ACM Siggraph '88 proceedings (Volume 22, Number 4, August 1988).

Author:
John L. Moreland
See Also:
edu.sdsc.vis.viewers.GeometryViewer

Constructor Summary
VirtualSphere2()
          Utility constructor creates a virtual sphere controller using default x,y screen coordinates as the center and default r as the radius of the controller's bounding circle.
VirtualSphere2(int x, int y, int r)
          Primary constructor creates a virtual sphere controller using the specified x,y screen coordinate as the center and r as the radius of the controller's bounding circle.
 
Method Summary
 void compute(int px, int py, int qx, int qy, double[] rotation)
          Determine the axis and angle (in radians) of rotation from two screen coordinates and relative to the virtual sphere cue circle.
 void getCircle(int[] circle)
          Get the parameters for the screen-space constraining 2D circle as {x,y,r}.
 int getRadius()
           
 void pointOnUnitSphere(int px, int py, double[] v)
          Project a 2D point on a circle to a 3D point on the +z hemisphere of a unit sphere.
 void setCircle(int[] circle)
          Set the parameters for the screen-space constraining 2D circle as {x,y,r}.
 void setCircle(int x, int y, int r)
          Set the parameters for the screen-space constraining 2D circle.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VirtualSphere2

public VirtualSphere2(int x,
                      int y,
                      int r)
Primary constructor creates a virtual sphere controller using the specified x,y screen coordinate as the center and r as the radius of the controller's bounding circle.

Parameters:
x - Screen x-coordinate for rotation circle.
y - Screen y-coordinate for rotation circle.
r - Screen radius for rotation circle.

VirtualSphere2

public VirtualSphere2()
Utility constructor creates a virtual sphere controller using default x,y screen coordinates as the center and default r as the radius of the controller's bounding circle.

Method Detail

getRadius

public int getRadius()

setCircle

public void setCircle(int x,
                      int y,
                      int r)
Set the parameters for the screen-space constraining 2D circle.

Parameters:
x - Screen x-coordinate for rotation circle.
y - Screen y-coordinate for rotation circle.
r - Screen radius for rotation circle.

setCircle

public void setCircle(int[] circle)
Set the parameters for the screen-space constraining 2D circle as {x,y,r}.

Parameters:
circle - Screen {x,y,radius} for rotation circle.

getCircle

public void getCircle(int[] circle)
Get the parameters for the screen-space constraining 2D circle as {x,y,r}.

Parameters:
circle - Screen {x,y,radius} for rotation circle.

compute

public void compute(int px,
                    int py,
                    int qx,
                    int qy,
                    double[] rotation)
Determine the axis and angle (in radians) of rotation from two screen coordinates and relative to the virtual sphere cue circle.

Parameters:
px - Screen start point, x-coordinate.
py - Screen start point, y-coordinate.
qx - Screen end point, x-coordinate.
qy - Screen end point, y-coordinate.
rotation - Rotation vector {angle,x,y,z} result.

pointOnUnitSphere

public void pointOnUnitSphere(int px,
                              int py,
                              double[] v)
Project a 2D point on a circle to a 3D point on the +z hemisphere of a unit sphere. If the 2D point is outside the circle, it is first mapped to the nearest point on the circle before projection. Orthographic projection is used, though technically the field of view of the camera should be taken into account. But, the discrepancy is neglegible.

Parameters:
px - Screen x-coordinate.
py - Screen y-coordinate.
v - 3D rotation vector {angle,x,y,z} result.