Public Member Functions
| ||zpr ()|
| ||Look at the origin from (0.0,0.0,2.0) with up as (0.0,1.0,0.0) and the field of view 30 degrees. |
|void ||readModelView ()|
| ||Read the model view matrix from OpenGL. |
|void ||readProjection ()|
| ||Read the projection matrix from OpenGL and calculate left, right, bottom, top, zNear and zFar. |
|void ||readScreenDimensions ()|
| ||Read the current screen size from OpenGL. |
|void ||update ()|
| ||Read in the current OpenGL state. |
|void ||write ()|
| ||Write the current projection from zpr's parameters. |
|void ||writeDefault ()|
| ||Write a default projection from zpr. |
|void ||writefromXaxis ()|
| ||Draw having the x and y axes with equal scales, zpr::top needs to be re-calculated. |
|void ||readMouse (GLdouble *px, GLdouble *py, GLdouble *pz, intc x, intc y) const |
| ||Get the world mouse co-ordinates. |
|void ||printInfo () const |
| ||Print the frustrum values. |
Static Public Member Functions
|static void ||motion (int x, int y)|
| ||Glut motion call back function. |
|static void ||mouse (int button, int state, int x, int y)|
| ||Glut mouse call back function. |
|static void ||reshape (int width_, int height_)|
| ||Glut reshape call back function. |
|static double ||vlen (GLdouble x, GLdouble y, GLdouble z)|
| ||Distance function. |
| ||The minimum x screen coordinate. |
| ||The maximum x screen coordinate. |
| ||The minimum y screen coordinate. |
| ||The maximum y screen coordinate. |
| ||The closest z clipping plane. |
| ||The farthest z clipping plane. |
| ||Screen pixel width. |
| ||Screen pixel height. |
| ||The mouse X position in pixeles. |
| ||The mouse Y position in pixeles. |
| ||Was the left mouse button pressed? |
| ||Was the middle mouse button pressed? |
| ||Was the right mouse button pressed? |
| ||The mouse X position in world coordinates. |
| ||The mouse Y position in world coordinates. |
| ||The mouse Z position in world coordinates. |
|GLdouble ||matrix |
| ||The model view matrix. |
|GLdouble ||matrixI |
| ||The inverse of the model view matrix. |
|fnobj0< void > * ||mousecallback|
| ||If not zero callback after mousezpr(..) when a mouse click occures. |
3D Mouse support for OpenGL.
- Mouse Functionality. The left mouse button rotates about the global origin. The right mouse button pans. The third mouse button (hold down left and right for 2 button mouse) zooms.
- Acknowledgements: Thanks to Nigel Stewart at nigels.com for zpr.h and zpr.cpp. I requested permission to use the code as mouse support is great. For the original version see http://www.nigels.com/glt/gltzpr/ .
I have modified the code from C to C++. Additional functionality was added along with a minor optimization.
zpr is currently a singleton class. An instance initializes OpenGL with a reasonable default projection and model view.
You can make direct OpenGL calls yourself and then have this class read in the new state with zpr::update(). ie
zpr works correctly when its state mirrors that of OpenGL. For example a call to glFrustrum or gluLookAt will change the viewing frustrum and zpr's values will not be the same as OpenGL's, hence zpr will break. Call zpr::update() to update zpr after a change.
Definition at line 74 of file zpr.h.
Read the projection matrix from OpenGL and calculate left, right, bottom, top, zNear and zFar.
Definition at line 480 of file zpr.cpp.
References zprGLmatrix::access(), and glerrordisplay().
Referenced by zprtest::test03().
static GLdouble pmatrix;
a = mat.access(0,0);
a = mat.access(1,1);
a = mat.access(0,2);
a = mat.access(1,2);
a = mat.access(2,2);
a = mat.access(2,3);
GLdouble c0 = (1.0-a)/(1.0+a);
GLdouble z0 = a*(1.0+1.0/c0)*-0.50;
GLdouble z1 = -c0*z0;
GLdouble x0 = z0*(a-1.0)/a;
GLdouble x1 = (z0*2.0+a*x0)/a;
GLdouble y0 = z0*(a-1.0)/a;
GLdouble y1 = (z0*2.0+a*y0)/a;