// gglMatrix.h #pragma once /* gglMatrix provides translation from Pixels to OpenGL world coordinates. It links the ModelView and Projection matrices and the ViewPort so you don't have to. Once you've set the ViewPort,Projection and ModelView, you can do things like this: GLdouble x,y,z; gglMatrix Tx; Tx.Pixel2World(CPoint(2,3), x,y,z); CPoint Pixel; Tx.World2Pixel(x,y,z, Pixel); It should be fairly quick to do many translations because the time-consuming bit is in the constructor which calls SetFromGL(). For Ortho projections, though, this class is overkill: I have developed much more efficient methods. */ struct gglMatrix { // Initialised using SetFromGL(); GLint V[ 4]; // V=ViewPort GLdouble M[16]; // M=Projection x ModelView GLdouble I[16]; // I=Inverse of M gglMatrix() {SetFromGL();} virtual ~gglMatrix() {} void Set(const GLdouble Mat[16]); void SetFromInverse(const GLdouble Inv[16]); void SetFromGL(); // Called from Constructor bool Pixel2World(const CPoint& Point, GLdouble& x, GLdouble& y, GLdouble& z); // MUST have SetFromGL(); first!!! bool World2Pixel(GLdouble x, GLdouble y, GLdouble z, CPoint& Point); // MUST have SetFromGL(); first!!! static void Transform(const GLdouble P[4], const GLdouble M[16], GLdouble PxM[4]); static void Multiply(const GLdouble A[16], const GLdouble B[16], GLdouble AxB[16]); static void GetInverse(const GLdouble M[16], GLdouble I[16]); static double GetDeterminant(const GLdouble M[16]); };