-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_widget.cpp
79 lines (63 loc) · 1.78 KB
/
custom_widget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "custom_widget.h"
#include <QApplication>
#include <QTimer>
#include <QKeyEvent>
#include <math.h>
ALfloat CustomWidget::ListenerPos[] = { 0.0, 0.0, 0.0 };
ALfloat CustomWidget::ListenerVel[] = { 0.0, 0.0, 0.0 };
ALfloat CustomWidget::ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };
CustomWidget::CustomWidget( int timerInterval, QWidget *parent ) : QGLWidget( parent )
{
if( timerInterval == 0 )
m_timer = 0;
else
{
m_timer = new QTimer( this );
connect( m_timer, SIGNAL(timeout()), this, SLOT(timeOutSlot()) );
m_timer->start( timerInterval );
}
}
// initializes openGL
void CustomWidget::initializeGL()
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
// gl resize procedure
void CustomWidget::resizeGL( int width, int height )
{
height = height?height:1;
glViewport( 0, 0, (GLint)width, (GLint)height );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
GLfloat fieldOfView = 45.0f;
GLfloat zNear = 0.1f;
GLfloat zFar = 255.0f;
GLfloat aspect = float(width)/float(height);
GLfloat fH = tan( float(fieldOfView / 360.0f * 3.14159f) ) * zNear;
GLfloat fW = fH * aspect;
glFrustum( -fW, fW, -fH, fH, zNear, zFar );
// glOrtho(-10.0f, 10.0f, -10.0f, 10.0f, 0.1f, 255.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void CustomWidget::initializeAL(int argc, char**argv)
{
alutInit (&argc, argv);
alGetError();
}
void CustomWidget::timeOut()
{
rtri += 0.5f;
rquad -= 0.25f;
updateGL();
}
void CustomWidget::timeOutSlot()
{
timeOut();
}