goat3d

view goatview/src/goatview.cc @ 103:45a9d493e98c

fixed the input latency issue by calling QWidget::update() instead of QGLWidget::updateGL() update schedules an update instead of redrawing immediately.
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 12 Sep 2015 17:40:02 +0300
parents 0ea2b355bc96
children
line source
1 #include <stdio.h>
2 #include <limits.h>
3 #include <map>
4 #include "opengl.h"
5 #include <QtOpenGL/QtOpenGL>
6 #include <vmath/vmath.h>
7 #include "goatview.h"
8 #include "goat3d.h"
10 static void draw_grid();
11 static void draw_grid(float sz, int nlines, float alpha = 1.0f);
12 static void draw_node(goat3d_node *node);
13 static void draw_mesh(goat3d_mesh *mesh);
14 static int next_pow2(int x);
16 goat3d *scene;
17 static SceneModel *sdata;
18 static GoatViewport *glview;
20 static long anim_time;
21 static float cam_theta, cam_phi = 25, cam_dist = 8;
22 static float fov = 60.0;
23 static bool use_nodes = true;
24 static bool use_lighting = true;
25 static bool use_textures = true;
27 void post_redisplay()
28 {
29 if(glview) {
30 glview->update();
31 }
32 }
35 GoatView::GoatView()
36 {
37 glview = 0;
38 scene_model = 0;
40 QGLFormat glfmt = QGLFormat::defaultFormat();
41 glfmt.setSampleBuffers(true);
42 QGLFormat::setDefaultFormat(glfmt);
44 QSettings settings;
45 resize(settings.value("main/size", QSize(1024, 768)).toSize());
46 move(settings.value("main/pos", QPoint(100, 100)).toPoint());
47 use_nodes = settings.value("use_nodes", true).toBool();
48 use_lighting = settings.value("use_lighting", true).toBool();
49 use_textures = settings.value("use_textures", true).toBool();
51 make_center(); // must be first
52 make_menu();
53 make_dock();
55 statusBar();
57 setWindowTitle("GoatView");
58 }
60 GoatView::~GoatView()
61 {
62 delete scene_model;
63 sdata = 0;
64 }
66 void GoatView::closeEvent(QCloseEvent *ev)
67 {
68 QSettings settings;
69 settings.setValue("main/size", size());
70 settings.setValue("main/pos", pos());
71 settings.setValue("use_nodes", use_nodes);
72 settings.setValue("use_lighting", use_lighting);
73 }
76 bool GoatView::load_scene(const char *fname)
77 {
78 if(scene) {
79 close_scene();
80 }
81 if(!(scene = goat3d_create()) || goat3d_load(scene, fname) == -1) {
82 QMessageBox::critical(this, "Error", "Failed to load scene file: " + QString(fname));
83 return false;
84 }
86 float bmin[3], bmax[3];
87 if(goat3d_get_bounds(scene, bmin, bmax) != -1) {
88 float bsize = (Vector3(bmax[0], bmax[1], bmax[2]) - Vector3(bmin[0], bmin[1], bmin[2])).length();
89 cam_dist = bsize / tan(DEG_TO_RAD(fov) / 2.0);
90 printf("bounds size: %f, cam_dist: %f\n", bsize, cam_dist);
91 }
93 scene_model->set_scene(scene);
94 treeview->expandAll();
95 treeview->resizeColumnToContents(0);
97 sdata = scene_model; // set the global sdata ptr
98 post_redisplay();
99 return true;
100 }
102 bool GoatView::load_anim(const char *fname)
103 {
104 if(!scene) {
105 QMessageBox::critical(this, "Error", "You must load a scene before loading any animations!");
106 return false;
107 }
109 if(goat3d_load_anim(scene, fname) == -1) {
110 QMessageBox::critical(this, "Error", QString("Failed to load animation: ") + QString(fname));
111 return false;
112 }
115 long tstart = LONG_MAX, tend = LONG_MIN;
116 int num_nodes = goat3d_get_node_count(scene);
117 for(int i=0; i<num_nodes; i++) {
118 goat3d_node *node = goat3d_get_node(scene, i);
119 if(goat3d_get_node_parent(node)) {
120 continue;
121 }
123 long t0, t1;
124 if(goat3d_get_anim_timeline(node, &t0, &t1) != -1) {
125 if(t0 < tstart) tstart = t0;
126 if(t1 > tend) tend = t1;
127 }
128 }
130 if(tstart != LONG_MAX) {
131 grp_anim_ctl->setDisabled(false);
132 grp_anim_time->setDisabled(false);
134 slider_time->setMinimum(tstart);
135 slider_time->setMaximum(tend);
137 spin_time->setMinimum(tstart);
138 spin_time->setMaximum(tend);
140 label_time_start->setText(QString::number(tstart));
141 label_time_end->setText(QString::number(tend));
142 }
144 post_redisplay();
145 return true;
146 }
148 bool GoatView::make_menu()
149 {
150 // file menu
151 QMenu *menu_file = menuBar()->addMenu("&File");
153 QAction *act_open_sce = new QAction("&Open Scene", this);
154 act_open_sce->setShortcuts(QKeySequence::Open);
155 connect(act_open_sce, &QAction::triggered, this, &GoatView::open_scene);
156 menu_file->addAction(act_open_sce);
158 QAction *act_open_anm = new QAction("Open &Animation", this);
159 connect(act_open_anm, &QAction::triggered, this, &GoatView::open_anim);
160 menu_file->addAction(act_open_anm);
162 QAction *act_close = new QAction("&Close", this);
163 connect(act_close, &QAction::triggered, this, &GoatView::close_scene);
164 menu_file->addAction(act_close);
166 menu_file->addSeparator();
168 QAction *act_quit = new QAction("&Quit", this);
169 act_quit->setShortcuts(QKeySequence::Quit);
170 connect(act_quit, &QAction::triggered, [&](){ qApp->quit(); });
171 menu_file->addAction(act_quit);
173 // view menu
174 QMenu *menu_view = menuBar()->addMenu("&View");
176 QAction *act_use_nodes = new QAction("use nodes", this);
177 act_use_nodes->setCheckable(true);
178 act_use_nodes->setChecked(use_nodes);
179 connect(act_use_nodes, &QAction::triggered, this,
180 [&](){ use_nodes = !use_nodes; post_redisplay(); });
181 menu_view->addAction(act_use_nodes);
183 QAction *act_use_lighting = new QAction("lighting", this);
184 act_use_lighting->setCheckable(true);
185 act_use_lighting->setChecked(use_lighting);
186 connect(act_use_lighting, &QAction::triggered, glview, &GoatViewport::toggle_lighting);
187 menu_view->addAction(act_use_lighting);
189 // help menu
190 QMenu *menu_help = menuBar()->addMenu("&Help");
192 QAction *act_about = new QAction("&About", this);
193 connect(act_about, &QAction::triggered, this, &GoatView::show_about);
194 menu_help->addAction(act_about);
195 return true;
196 }
198 bool GoatView::make_dock()
199 {
200 // ---- side-dock ----
201 QWidget *dock_cont = new QWidget;
202 QVBoxLayout *dock_vbox = new QVBoxLayout;
203 dock_cont->setLayout(dock_vbox);
205 QDockWidget *dock = new QDockWidget(this);
206 dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
207 dock->setWidget(dock_cont);
208 addDockWidget(Qt::LeftDockWidgetArea, dock);
210 // make the tree view widget
211 treeview = new QTreeView;
212 treeview->setAlternatingRowColors(true);
213 treeview->setSelectionMode(QAbstractItemView::SingleSelection);
214 dock_vbox->addWidget(treeview);
216 scene_model = new SceneModel;
217 connect(scene_model, &SceneModel::dataChanged, [&](){ post_redisplay(); });
218 treeview->setModel(scene_model);
220 connect(treeview->selectionModel(), &QItemSelectionModel::selectionChanged,
221 [&](){ scene_model->selchange(treeview->selectionModel()->selectedIndexes()); });
223 // misc
224 QPushButton *bn_quit = new QPushButton("quit");
225 dock_vbox->addWidget(bn_quit);
226 connect(bn_quit, &QPushButton::clicked, [&](){ qApp->quit(); });
228 // ---- bottom dock ----
229 dock_cont = new QWidget;
230 QHBoxLayout *dock_hbox = new QHBoxLayout;
231 dock_cont->setLayout(dock_hbox);
233 // animation control box
234 grp_anim_ctl = new QGroupBox("Animation controls");
235 grp_anim_ctl->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred));
236 grp_anim_ctl->setDisabled(true);
237 dock_hbox->addWidget(grp_anim_ctl);
239 QVBoxLayout *anim_ctl_box = new QVBoxLayout;
240 grp_anim_ctl->setLayout(anim_ctl_box);
242 chk_loop = new QCheckBox("loop");
243 chk_loop->setChecked(false);
244 anim_ctl_box->addWidget(chk_loop);
246 QToolBar *toolbar_ctl = new QToolBar;
247 anim_ctl_box->addWidget(toolbar_ctl);
249 act_rewind = new QAction(style()->standardIcon(QStyle::SP_MediaSkipBackward), "Rewind", this);
250 connect(act_rewind, &QAction::triggered, [this](){ slider_time->setValue(slider_time->minimum()); });
251 toolbar_ctl->addAction(act_rewind);
253 act_play = new QAction(style()->standardIcon(QStyle::SP_MediaPlay), "Play", this);
254 toolbar_ctl->addAction(act_play);
256 /* timeline controls
257 * /------------------------------\ grp_anim_time with vbox_timeline layout
258 * | /-------+---------+--------\ |
259 * | | label | spinbox | spacer | <-- hbox_timespin
260 * | \-------+---------+--------/ |
261 * +------------------------------+
262 * | /-------+---------+--------\ |
263 * | | label | slider | label | <-- hbox_timeslider
264 * | \-------+---------+--------/ |
265 * \------------------------------/
266 */
267 grp_anim_time = new QGroupBox("Timeline");
268 grp_anim_time->setDisabled(true);
269 dock_hbox->addWidget(grp_anim_time);
271 QVBoxLayout *vbox_timeline = new QVBoxLayout;
272 grp_anim_time->setLayout(vbox_timeline);
273 QHBoxLayout *hbox_timespin = new QHBoxLayout;
274 vbox_timeline->addLayout(hbox_timespin);
275 QHBoxLayout *hbox_timeslider = new QHBoxLayout;
276 vbox_timeline->addLayout(hbox_timeslider);
278 hbox_timespin->addWidget(new QLabel("msec"));
279 spin_time = new QSpinBox;
280 hbox_timespin->addWidget(spin_time);
281 hbox_timespin->addStretch();
283 label_time_start = new QLabel;
284 hbox_timeslider->addWidget(label_time_start);
286 slider_time = new QSlider(Qt::Orientation::Horizontal);
287 hbox_timeslider->addWidget(slider_time);
289 label_time_end = new QLabel;
290 hbox_timeslider->addWidget(label_time_end);
292 connect(slider_time, &QSlider::valueChanged,
293 [&](){ anim_time = slider_time->value(); spin_time->setValue(anim_time); post_redisplay(); });
295 typedef void (QSpinBox::*ValueChangedIntFunc)(int);
296 connect(spin_time, (ValueChangedIntFunc)&QSpinBox::valueChanged,
297 [&](){ anim_time = spin_time->value(); slider_time->setValue(anim_time); post_redisplay(); });
299 dock = new QDockWidget(this);
300 dock->setAllowedAreas(Qt::BottomDockWidgetArea);
301 dock->setWidget(dock_cont);
302 addDockWidget(Qt::BottomDockWidgetArea, dock);
304 return true;
305 }
307 bool GoatView::make_center()
308 {
309 glview = ::glview = new GoatViewport(this);
310 setCentralWidget(glview);
311 return true;
312 }
314 void GoatView::open_scene()
315 {
316 std::string fname = QFileDialog::getOpenFileName(this, "Open scene file", "",
317 "Goat3D Scene (*.goatsce);;All Files (*)").toStdString();
318 if(fname.empty()) {
319 statusBar()->showMessage("Abort: No file selected!");
320 return;
321 }
323 statusBar()->showMessage("opening scene file");
324 if(!load_scene(fname.c_str())) {
325 statusBar()->showMessage("failed to load scene file");
326 return;
327 }
328 statusBar()->showMessage("Successfully loaded scene: " + QString(fname.c_str()));
329 }
331 void GoatView::close_scene()
332 {
333 scene_model->clear_scene();
334 treeview->reset();
335 goat3d_free(scene);
336 scene = 0;
338 grp_anim_ctl->setDisabled(true);
339 grp_anim_time->setDisabled(true);
340 }
342 void GoatView::open_anim()
343 {
344 std::string fname = QFileDialog::getOpenFileName(this, "Open animation file", "",
345 "Goat3D Animation (*.goatanm);;All Files (*)").toStdString();
346 if(fname.empty()) {
347 statusBar()->showMessage("Abort: No file selected!");
348 return;
349 }
351 statusBar()->showMessage("opening animation file");
352 if(!load_anim(fname.c_str())) {
353 statusBar()->showMessage("failed to load animation file");
354 return;
355 }
356 statusBar()->showMessage("Successfully loaded animation: " + QString(fname.c_str()));
357 }
360 // ---- OpenGL viewport ----
361 GoatViewport::GoatViewport(QWidget *main_win)
362 : QGLWidget(QGLFormat(QGL::DepthBuffer | QGL::SampleBuffers))
363 {
364 this->main_win = main_win;
365 initialized = false;
366 }
368 GoatViewport::~GoatViewport()
369 {
370 }
372 QSize GoatViewport::sizeHint() const
373 {
374 return QSize(800, 600);
375 }
377 #define CRITICAL(error, detail) \
378 do { \
379 fprintf(stderr, "%s: %s\n", error, detail); \
380 QMessageBox::critical(main_win, error, detail); \
381 abort(); \
382 } while(0)
384 void GoatViewport::initializeGL()
385 {
386 if(initialized) return;
387 initialized = true;
389 init_opengl();
391 if(!GLEW_ARB_transpose_matrix) {
392 CRITICAL("OpenGL initialization failed", "ARB_transpose_matrix extension not found!");
393 }
395 glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
397 glEnable(GL_DEPTH_TEST);
398 glEnable(GL_CULL_FACE);
399 if(use_lighting) {
400 glEnable(GL_LIGHTING);
401 }
402 glEnable(GL_LIGHT0);
404 float ldir[] = {-1, 1, 2, 0};
405 glLightfv(GL_LIGHT0, GL_POSITION, ldir);
407 glEnable(GL_MULTISAMPLE);
408 }
410 void GoatViewport::resizeGL(int xsz, int ysz)
411 {
412 glViewport(0, 0, xsz, ysz);
413 glMatrixMode(GL_PROJECTION);
414 glLoadIdentity();
415 gluPerspective(60.0, (float)xsz / (float)ysz, 0.5, 5000.0);
416 }
418 void GoatViewport::paintGL()
419 {
420 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
422 glMatrixMode(GL_MODELVIEW);
423 glLoadIdentity();
424 glTranslatef(0, 0, -cam_dist);
425 glRotatef(cam_phi, 1, 0, 0);
426 glRotatef(cam_theta, 0, 1, 0);
428 if(scene) {
429 if(use_nodes) {
430 int node_count = goat3d_get_node_count(scene);
431 for(int i=0; i<node_count; i++) {
432 goat3d_node *node = goat3d_get_node(scene, i);
433 if(!goat3d_get_node_parent(node)) {
434 draw_node(node); // only draw root nodes, the rest will be drawn recursively
435 }
436 }
437 } else {
438 int mesh_count = goat3d_get_mesh_count(scene);
439 for(int i=0; i<mesh_count; i++) {
440 goat3d_mesh *mesh = goat3d_get_mesh(scene, i);
441 draw_mesh(mesh);
442 }
443 }
444 }
446 draw_grid();
447 }
449 void GoatViewport::toggle_lighting()
450 {
451 use_lighting = !use_lighting;
452 if(use_lighting) {
453 glEnable(GL_LIGHTING);
454 } else {
455 glDisable(GL_LIGHTING);
456 }
457 post_redisplay();
458 }
460 #ifndef GLEW_ARB_transpose_matrix
461 #error "GLEW_ARB_transpose_matrix undefined?"
462 #endif
464 static void draw_grid()
465 {
466 float viewsz_orig = cam_dist * tan(DEG_TO_RAD(fov) / 2.0);
467 float sz1 = next_pow2((int)viewsz_orig);
468 float sz0 = sz1 / 2.0;
469 float t = (viewsz_orig - sz0) / (sz1 - sz0);
470 float alpha = t < 0.333333 ? 0.0 : (t > 0.666666 ? 1.0 : (t - 0.333333) / 0.333333);
472 glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BITS);
474 glEnable(GL_BLEND);
475 glDepthMask(0);
477 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
478 draw_grid(sz0 * 2.0, 10, 1.0 - alpha);
479 draw_grid(sz1 * 2.0, 10, alpha);
481 glDepthMask(1);
482 glPopAttrib();
483 }
485 static void draw_grid(float sz, int nlines, float alpha)
486 {
487 float hsz = sz / 2.0;
488 float offs = sz / (float)nlines;
490 glPushAttrib(GL_ENABLE_BIT);
491 glDisable(GL_LIGHTING);
492 glDisable(GL_TEXTURE_2D);
494 glLineWidth(2.0);
495 glBegin(GL_LINES);
496 glColor4f(1, 0, 0, alpha);
497 glVertex3f(-hsz, 0, 0);
498 glVertex3f(hsz, 0, 0);
499 glColor4f(0, 0, 1, alpha);
500 glVertex3f(0, 0, -hsz);
501 glVertex3f(0, 0, hsz);
502 glEnd();
504 glLineWidth(1.0);
505 glBegin(GL_LINES);
506 glColor4f(0.5, 0.5, 0.5, alpha);
507 for(int i=0; i<nlines / 2; i++) {
508 float dist = (float)(i + 1) * offs;
509 for(int j=0; j<2; j++) {
510 float sign = j > 0 ? -1.0 : 1.0;
511 glVertex3f(-hsz, 0, dist * sign);
512 glVertex3f(hsz, 0, dist * sign);
513 glVertex3f(dist * sign, 0, -hsz);
514 glVertex3f(dist * sign, 0, hsz);
515 }
516 }
517 glEnd();
519 glPopAttrib();
520 }
522 static void draw_node(goat3d_node *node)
523 {
524 SceneNodeData *data = sdata ? sdata->get_node_data(node) : 0;
525 if(!data) return;
527 float xform[16];
528 goat3d_get_node_matrix(node, xform, anim_time);
530 glPushMatrix();
531 glMultTransposeMatrixf(xform);
533 if(data->visible) {
534 if(goat3d_get_node_type(node) == GOAT3D_NODE_MESH) {
535 goat3d_mesh *mesh = (goat3d_mesh*)goat3d_get_node_object(node);
537 draw_mesh(mesh);
539 if(data->selected) {
540 float bmin[3], bmax[3];
541 goat3d_get_mesh_bounds(mesh, bmin, bmax);
543 glPushAttrib(GL_ENABLE_BIT);
544 glDisable(GL_LIGHTING);
546 glColor3f(0.3, 1, 0.2);
548 glBegin(GL_LINE_LOOP);
549 glVertex3f(bmin[0], bmin[1], bmin[2]);
550 glVertex3f(bmax[0], bmin[1], bmin[2]);
551 glVertex3f(bmax[0], bmin[1], bmax[2]);
552 glVertex3f(bmin[0], bmin[1], bmax[2]);
553 glEnd();
554 glBegin(GL_LINE_LOOP);
555 glVertex3f(bmin[0], bmax[1], bmin[2]);
556 glVertex3f(bmax[0], bmax[1], bmin[2]);
557 glVertex3f(bmax[0], bmax[1], bmax[2]);
558 glVertex3f(bmin[0], bmax[1], bmax[2]);
559 glEnd();
560 glBegin(GL_LINES);
561 glVertex3f(bmin[0], bmin[1], bmin[2]);
562 glVertex3f(bmin[0], bmax[1], bmin[2]);
563 glVertex3f(bmin[0], bmin[1], bmax[2]);
564 glVertex3f(bmin[0], bmax[1], bmax[2]);
565 glVertex3f(bmax[0], bmin[1], bmin[2]);
566 glVertex3f(bmax[0], bmax[1], bmin[2]);
567 glVertex3f(bmax[0], bmin[1], bmax[2]);
568 glVertex3f(bmax[0], bmax[1], bmax[2]);
569 glEnd();
571 glPopAttrib();
572 }
573 }
574 }
576 int num_child = goat3d_get_node_child_count(node);
577 for(int i=0; i<num_child; i++) {
578 draw_node(goat3d_get_node_child(node, i));
579 }
581 glPopMatrix();
582 }
584 static void draw_mesh(goat3d_mesh *mesh)
585 {
586 static const float white[] = {1, 1, 1, 1};
587 static const float black[] = {0, 0, 0, 1};
589 const float *color;
590 goat3d_material *mtl = goat3d_get_mesh_mtl(mesh);
592 if(mtl && (color = goat3d_get_mtl_attrib(mtl, GOAT3D_MAT_ATTR_DIFFUSE))) {
593 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
594 glColor3fv(color);
595 } else {
596 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, white);
597 glColor3fv(white);
598 }
599 if(mtl && (color = goat3d_get_mtl_attrib(mtl, GOAT3D_MAT_ATTR_SPECULAR))) {
600 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
601 } else {
602 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
603 }
604 if(mtl && (color = goat3d_get_mtl_attrib(mtl, GOAT3D_MAT_ATTR_SHININESS))) {
605 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, color[0]);
606 } else {
607 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 60.0);
608 }
609 // TODO texture
612 int num_faces = goat3d_get_mesh_face_count(mesh);
613 int num_verts = goat3d_get_mesh_attrib_count(mesh, GOAT3D_MESH_ATTR_VERTEX);
615 glEnableClientState(GL_VERTEX_ARRAY);
616 glVertexPointer(3, GL_FLOAT, 0, goat3d_get_mesh_attribs(mesh, GOAT3D_MESH_ATTR_VERTEX));
618 float *data;
619 if((data = (float*)goat3d_get_mesh_attribs(mesh, GOAT3D_MESH_ATTR_NORMAL))) {
620 glEnableClientState(GL_NORMAL_ARRAY);
621 glNormalPointer(GL_FLOAT, 0, data);
622 }
623 if((data = (float*)goat3d_get_mesh_attribs(mesh, GOAT3D_MESH_ATTR_TEXCOORD))) {
624 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
625 glTexCoordPointer(2, GL_FLOAT, 0, data);
626 }
628 int *indices;
629 if((indices = goat3d_get_mesh_faces(mesh))) {
630 glDrawElements(GL_TRIANGLES, num_faces * 3, GL_UNSIGNED_INT, indices);
631 } else {
632 glDrawArrays(GL_TRIANGLES, 0, num_verts * 3);
633 }
635 glDisableClientState(GL_VERTEX_ARRAY);
636 glDisableClientState(GL_NORMAL_ARRAY);
637 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
638 }
641 static float prev_x, prev_y;
642 void GoatViewport::mousePressEvent(QMouseEvent *ev)
643 {
644 prev_x = ev->x();
645 prev_y = ev->y();
646 }
648 void GoatViewport::mouseMoveEvent(QMouseEvent *ev)
649 {
650 int dx = ev->x() - prev_x;
651 int dy = ev->y() - prev_y;
652 prev_x = ev->x();
653 prev_y = ev->y();
655 if(!dx && !dy) return;
657 if(ev->buttons() & Qt::LeftButton) {
658 cam_theta += dx * 0.5;
659 cam_phi += dy * 0.5;
661 if(cam_phi < -90) cam_phi = -90;
662 if(cam_phi > 90) cam_phi = 90;
663 }
664 if(ev->buttons() & Qt::RightButton) {
665 cam_dist += dy * 0.1;
667 if(cam_dist < 0.0) cam_dist = 0.0;
668 }
669 post_redisplay();
670 }
672 static const char *about_str =
673 "GoatView - Goat3D scene file viewer<br>"
674 "Copyright (C) 2014 John Tsiombikas &lt;<a href=\"mailto:nuclear@mutantstargoat.com\">nuclear@mutantstargoat.com</a>&gt;<br>"
675 "<br>"
676 "This program is free software: you can redistribute it and/or modify<br>"
677 "it under the terms of the GNU General Public License as published by<br>"
678 "the Free Software Foundation, either version 3 of the License, or<br>"
679 "(at your option) any later version.<br>"
680 "<br>"
681 "This program is distributed in the hope that it will be useful,<br>"
682 "but WITHOUT ANY WARRANTY; without even the implied warranty of<br>"
683 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>"
684 "GNU General Public License for more details.<br>"
685 "<br>"
686 "You should have received a copy of the GNU General Public License<br>"
687 "along with this program. If not, see <a href=\"http://www.gnu.org/licenses/gpl\">http://www.gnu.org/licenses/gpl</a>.";
689 void GoatView::show_about()
690 {
691 QMessageBox::information(this, "About GoatView", about_str);
692 }
695 static int next_pow2(int x)
696 {
697 x--;
698 x = (x >> 1) | x;
699 x = (x >> 2) | x;
700 x = (x >> 4) | x;
701 x = (x >> 8) | x;
702 x = (x >> 16) | x;
703 return x + 1;
704 }