LCG_cg  1.0
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes


Arcball is a method to manipulate and rotate objects in 3D intuitively. More...

#include <Arcball.hpp>

Public Member Functions

 Arcball ()
 Default constructor, it sets the ballRadius to 600. More...
 
void setWidthHeight (int w, int h)
 Set width and height of the current windows, it's needed every time you resize the window. More...
 
void startRotation (int x, int y)
 Start the rotation. More...
 
void updateRotation (int x, int y)
 Update the rotation. More...
 
void stopRotation ()
 Stop the current rotation and prepare for a new click-then-drag event. More...
 
void applyTranslationMatrix (bool reverse=false)
 Apply the translation matrix to the current transformation (zoom factor) More...
 
void applyRotationMatrix ()
 Apply the computed rotation matrix This method must be invoked inside the. More...
 
void setRadius (float newRadius)
 Set the radius of the ball (a typical radius for a 1024x768 window is 600. More...
 
void reset ()
 Reset the current transformation to the identity. More...
 
void setViewMatrix (GLMatrix matrix)
 Set the current transformation to the given rotation matrix. More...
 

Private Member Functions

Vector3d convertXY (int x, int y)
 Maps the mouse coordinates to points on a sphere, if the points lie outside the sphere, the z is 0, otherwise is \( \sqrt{r^2 - (x^2+y^2)} \) where \( x,y \) are the window centric coordinates of the mouse. More...
 

Private Attributes

float fov
 
int fovStartY
 
int fovCurrentY
 
float transX
 
float transY
 
float currentTransX
 
float currentTransY
 
float startTransX
 
float startTransY
 
GLMatrix startMatrix
 
GLMatrix currentMatrix
 
Vector3d startRotationVector
 
Vector3d currentRotationVector
 
bool isRotating
 
float ballRadius
 
double residualSpin
 
int width
 
int height
 

Static Private Attributes

static const float INITIAL_FOV = 30
 
static const float MINIMAL_FOV
 
static const float TRANSLATION_FACTOR = 0.01f
 

Detailed Description


Arcball is a method to manipulate and rotate objects in 3D intuitively.

The motivation behind the trackball (aka arcball) is to provide an intuitive user interface for complex 3D object rotation via a simple, virtual sphere - the screen space analogy to the familiar input device bearing the same name.

The sphere is a good choice for a virtual trackball because it makes a good enclosure for most any object; and its surface is smooth and continuous, which is important in the generation of smooth rotations in response to smooth mouse movements. Any smooth, continuous shape, however, could be used, so long as points on its surface can be generated in a consistent way. The algorithm for accomplishing this, needs to perform the following steps (not neseccarily in order).

ArcBall Algorithm made easy

An example of the code for using successfully this class is the following: First set the radius of the arcball by using the appropriate method when you call the handle to the GLUT resize method (this is usually accomplished with a

void handleResize(int w, int h)

function in GLUT (if you are using Qt or other, please refer to the relative API ). An example of a

handleResize(int w, int h)

function is the following:

void handleResize(int w, int h)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(viewAngle, (float)w / (float)w, zNear, zFar );
glMatrixMode(GL_MODELVIEW);
}

These are the two functions (GLUT) that control the mouse events:

void mouseFunc(int state, int button, int _x , int _y)
{
if ( button == GLUT_LEFT_BUTTON )
else
glutPostRedisplay();
}
void mouseDrag(int _x, int _y)
{
glutPostRedisplay();
}

Definition at line 124 of file Arcball.hpp.

Field Documentation

◆ ballRadius

float Arcball::ballRadius
private

Definition at line 140 of file Arcball.hpp.

◆ currentMatrix

GLMatrix Arcball::currentMatrix
private

Definition at line 136 of file Arcball.hpp.

◆ currentRotationVector

Vector3d Arcball::currentRotationVector
private

Definition at line 138 of file Arcball.hpp.

◆ currentTransX

float Arcball::currentTransX
private

Definition at line 132 of file Arcball.hpp.

◆ currentTransY

float Arcball::currentTransY
private

Definition at line 132 of file Arcball.hpp.

◆ fov

float Arcball::fov
private

Definition at line 127 of file Arcball.hpp.

◆ fovCurrentY

int Arcball::fovCurrentY
private

Definition at line 129 of file Arcball.hpp.

◆ fovStartY

int Arcball::fovStartY
private

Definition at line 128 of file Arcball.hpp.

◆ height

int Arcball::height
private

Definition at line 147 of file Arcball.hpp.

◆ INITIAL_FOV

const float Arcball::INITIAL_FOV = 30
staticprivate

Definition at line 142 of file Arcball.hpp.

◆ isRotating

bool Arcball::isRotating
private

Definition at line 139 of file Arcball.hpp.

◆ MINIMAL_FOV

const float Arcball::MINIMAL_FOV
staticprivate

Definition at line 143 of file Arcball.hpp.

◆ residualSpin

double Arcball::residualSpin
private

Definition at line 141 of file Arcball.hpp.

◆ startMatrix

GLMatrix Arcball::startMatrix
private

Definition at line 135 of file Arcball.hpp.

◆ startRotationVector

Vector3d Arcball::startRotationVector
private

Definition at line 137 of file Arcball.hpp.

◆ startTransX

float Arcball::startTransX
private

Definition at line 133 of file Arcball.hpp.

◆ startTransY

float Arcball::startTransY
private

Definition at line 133 of file Arcball.hpp.

◆ TRANSLATION_FACTOR

const float Arcball::TRANSLATION_FACTOR = 0.01f
staticprivate

Definition at line 144 of file Arcball.hpp.

◆ transX

float Arcball::transX
private

Definition at line 131 of file Arcball.hpp.

◆ transY

float Arcball::transY
private

Definition at line 131 of file Arcball.hpp.

◆ width

int Arcball::width
private

Definition at line 147 of file Arcball.hpp.


The documentation for this class was generated from the following files: