|  | @@ -2,13 +2,47 @@
 | 
		
	
		
			
			| 2 | 2 |  #include "GL/gl.h"
 | 
		
	
		
			
			| 3 | 3 |  #include "GL/glu.h"
 | 
		
	
		
			
			| 4 | 4 |  
 | 
		
	
		
			
			| 5 |  | -OpenGLRenderDevice::OpenGLRenderDevice(QObject *parent) :
 | 
		
	
		
			
			| 6 |  | -    AbstractRenderDevice(parent)
 | 
		
	
		
			
			|  | 5 | +OpenGLRenderDevice::OpenGLRenderDevice(QObject *parent)
 | 
		
	
		
			
			|  | 6 | +    : AbstractRenderDevice(parent)
 | 
		
	
		
			
			|  | 7 | +    , _width(0)
 | 
		
	
		
			
			|  | 8 | +    , _height(0)
 | 
		
	
		
			
			|  | 9 | +    , _fov(0)
 | 
		
	
		
			
			| 7 | 10 |  {
 | 
		
	
		
			
			| 8 | 11 |  }
 | 
		
	
		
			
			| 9 | 12 |  
 | 
		
	
		
			
			|  | 13 | +Vector3D OpenGLRenderDevice::get2DFrom3D(const Vector3D &pos)
 | 
		
	
		
			
			|  | 14 | +{
 | 
		
	
		
			
			|  | 15 | +    double gx, gy, gz;
 | 
		
	
		
			
			|  | 16 | +    double modelMatrix[16];
 | 
		
	
		
			
			|  | 17 | +    double projMatrix[16];
 | 
		
	
		
			
			|  | 18 | +    GLint viewport[4];
 | 
		
	
		
			
			|  | 19 | +    glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
 | 
		
	
		
			
			|  | 20 | +    glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
 | 
		
	
		
			
			|  | 21 | +    glGetIntegerv(GL_VIEWPORT, viewport);
 | 
		
	
		
			
			|  | 22 | +
 | 
		
	
		
			
			|  | 23 | +     gluProject(pos.getX(), pos.getY(), pos.getZ(), modelMatrix, projMatrix, viewport, &gx, &gy, &gz);
 | 
		
	
		
			
			|  | 24 | +     return Vector3D(gx, gy, gz);
 | 
		
	
		
			
			|  | 25 | +}
 | 
		
	
		
			
			|  | 26 | +
 | 
		
	
		
			
			|  | 27 | +Vector3D OpenGLRenderDevice::get3DFrom2D(int x, int y)
 | 
		
	
		
			
			|  | 28 | +{
 | 
		
	
		
			
			|  | 29 | +    double gx, gy, gz;
 | 
		
	
		
			
			|  | 30 | +    double modelMatrix[16];
 | 
		
	
		
			
			|  | 31 | +    double projMatrix[16];
 | 
		
	
		
			
			|  | 32 | +    GLint viewport[4];
 | 
		
	
		
			
			|  | 33 | +    glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
 | 
		
	
		
			
			|  | 34 | +    glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
 | 
		
	
		
			
			|  | 35 | +    glGetIntegerv(GL_VIEWPORT, viewport);
 | 
		
	
		
			
			|  | 36 | +
 | 
		
	
		
			
			|  | 37 | +    gluUnProject(x, y, 1, modelMatrix, projMatrix, viewport, &gx, &gy, &gz);
 | 
		
	
		
			
			|  | 38 | +    return Vector3D(gx, gy, gz);
 | 
		
	
		
			
			|  | 39 | +}
 | 
		
	
		
			
			|  | 40 | +
 | 
		
	
		
			
			| 10 | 41 |  void OpenGLRenderDevice::initialize(int fov, int width, int height)
 | 
		
	
		
			
			| 11 | 42 |  {
 | 
		
	
		
			
			|  | 43 | +    _fov = fov;
 | 
		
	
		
			
			|  | 44 | +    _width = width;
 | 
		
	
		
			
			|  | 45 | +    _height = height;
 | 
		
	
		
			
			| 12 | 46 |      glClearColor(_clearColor.redF(), _clearColor.greenF(),
 | 
		
	
		
			
			| 13 | 47 |                   _clearColor.blue(), _clearColor.alpha());
 | 
		
	
		
			
			| 14 | 48 |  
 | 
		
	
	
		
			
			|  | @@ -18,14 +52,16 @@ void OpenGLRenderDevice::initialize(int fov, int width, int height)
 | 
		
	
		
			
			| 18 | 52 |      glEnable(GL_MULTISAMPLE);
 | 
		
	
		
			
			| 19 | 53 |  
 | 
		
	
		
			
			| 20 | 54 |      glMatrixMode(GL_PROJECTION);
 | 
		
	
		
			
			| 21 |  | -    gluPerspective(fov, width / height, 0.1, 100.0);
 | 
		
	
		
			
			|  | 55 | +    gluPerspective(_fov, _width / _height, 0.1, 100.0);
 | 
		
	
		
			
			| 22 | 56 |      glMatrixMode(GL_MODELVIEW);
 | 
		
	
		
			
			| 23 | 57 |  }
 | 
		
	
		
			
			| 24 | 58 |  
 | 
		
	
		
			
			| 25 | 59 |  void OpenGLRenderDevice::resize(int width, int height)
 | 
		
	
		
			
			| 26 | 60 |  {
 | 
		
	
		
			
			| 27 |  | -    int side = qMin(width, height);
 | 
		
	
		
			
			| 28 |  | -    glViewport((width - side) / 2, (height - side) / 2, side, side);
 | 
		
	
		
			
			|  | 61 | +    _width = width;
 | 
		
	
		
			
			|  | 62 | +    _height = height;
 | 
		
	
		
			
			|  | 63 | +    int side = qMin(_width, _height);
 | 
		
	
		
			
			|  | 64 | +    glViewport((_width - side) / 2, (_height - side) / 2, side, side);
 | 
		
	
		
			
			| 29 | 65 |  }
 | 
		
	
		
			
			| 30 | 66 |  
 | 
		
	
		
			
			| 31 | 67 |  void OpenGLRenderDevice::preDraw()
 |