-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoglwidget.cpp
More file actions
149 lines (123 loc) · 4.23 KB
/
oglwidget.cpp
File metadata and controls
149 lines (123 loc) · 4.23 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "oglwidget.h"
//#define _TESTING_CODE_
OGLWidget::OGLWidget(QWidget *parent) :
QOpenGLWidget(parent),
rotX(0)
{}
OGLWidget::~OGLWidget()
{
}
void OGLWidget::setPointCloud(PointCloud *ptr)
{
cloud = ptr;
}
void OGLWidget::initializeGL()
{
#ifndef _TESTING_CODE_
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
// LIGHTS
GLfloat ambient[] = { 1.0, 1.0, 1.0, 0.5 };
GLfloat position[] = { 0.0, 160.0, 10.0, 1.0 };
GLfloat mat_diffuse[] = { 0.6, 0.6, 0.6, 40.0 };
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 100.0 };
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
#else
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
#endif
//Points
glColor3f(1.0, 1.0, 1.0);
glPointSize(1.5);
}
void OGLWidget::resizeGL(int w, int h)
{
int width = 640,
height = 480;
#ifndef _TESTING_CODE_
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-width/2.0, width/2.0, 0.0, height, width/2.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
#else
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glOrtho(-width/2.0, width/2.0, 0.0, height, width/2.0, 0.0);
gluPerspective(40.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
#endif
}
void OGLWidget::paintGL()
{
#ifndef _TESTING_CODE_
// GLfloat ambient[] = { 1.0, 1.0, 1.0, 0.5 };
// GLfloat position[] = { 0.0, 160.0, 480.0, 1.0 };
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glPushMatrix();
// gluLookAt (0.0, 0.0, 150.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
// glPushMatrix();
// glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
// glLightfv(GL_LIGHT0, GL_POSITION, position);
// glPopMatrix();
//Rotation
glRotatef(rotX, 0.0, 1.0, 0.0);
glBegin(GL_POINTS);
for (auto it = cloud->cloud.begin(); it != cloud->cloud.end(); ++it)
glVertex3f(it->x, it->y, it->z);
glEnd();
glBegin(GL_TRIANGLES);
for (auto it = cloud->mesh.begin(); it != cloud->mesh.end(); ++it) {
glVertex3f(it->edge_1->x, it->edge_1->y, it->edge_1->z);
glVertex3f(it->edge_2->x, it->edge_2->y, it->edge_2->z);
glVertex3f(it->edge_4->x, it->edge_4->y, it->edge_4->z);
glVertex3f(it->edge_2->x, it->edge_2->y, it->edge_2->z);
glVertex3f(it->edge_3->x, it->edge_3->y, it->edge_3->z);
glVertex3f(it->edge_4->x, it->edge_4->y, it->edge_4->z);
}
glEnd();
glLoadIdentity();
glPopMatrix(); //GL_MODELVIEW);
glFlush();
#else
GLfloat position[] = { 0.0, 0.0, 1.5, 1.0 };
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix ();
glTranslatef (0.0, 0.0, -5.0);
glPushMatrix ();
glRotated ((GLdouble) 0.0, rotX/360, 0.0, 0.0);
glLightfv (GL_LIGHT0, GL_POSITION, position);
glTranslated (0.0, 0.0, 1.5);
glDisable (GL_LIGHTING);
glColor3f (1.0, 1.0, 1.0);
glBegin(GL_TRIANGLES);
for (auto it = cloud->mesh.begin(); it != cloud->mesh.end(); ++it) {
glVertex3f(it->edge_1->x, it->edge_1->y, it->edge_1->z);
glVertex3f(it->edge_2->x, it->edge_2->y, it->edge_2->z);
glVertex3f(it->edge_4->x, it->edge_4->y, it->edge_4->z);
glVertex3f(it->edge_2->x, it->edge_2->y, it->edge_2->z);
glVertex3f(it->edge_3->x, it->edge_3->y, it->edge_3->z);
glVertex3f(it->edge_4->x, it->edge_4->y, it->edge_4->z);
}
glEnd();
glEnable (GL_LIGHTING);
glPopMatrix ();
glFlush ();
#endif
}