goat3d

view goatview/src/goatview.cc @ 99:d7ab4f13f5af

Merge
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 21 May 2014 05:01:34 +0300
parents 32dccb16678f b43d33f3ba69
children fae6dc0fd462
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->updateGL();
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;
337 }
339 void GoatView::open_anim()
340 {
341 std::string fname = QFileDialog::getOpenFileName(this, "Open animation file", "",
342 "Goat3D Animation (*.goatanm);;All Files (*)").toStdString();
343 if(fname.empty()) {
344 statusBar()->showMessage("Abort: No file selected!");
345 return;
346 }
348 statusBar()->showMessage("opening animation file");
349 if(!load_anim(fname.c_str())) {
350 statusBar()->showMessage("failed to load animation file");
351 return;
352 }
353 statusBar()->showMessage("Successfully loaded animation: " + QString(fname.c_str()));
354 }
357 // ---- OpenGL viewport ----
358 GoatViewport::GoatViewport(QWidget *main_win)
359 : QGLWidget(QGLFormat(QGL::DepthBuffer | QGL::SampleBuffers))
360 {
361 this->main_win = main_win;
362 initialized = false;
363 }
365 GoatViewport::~GoatViewport()
366 {
367 }
369 QSize GoatViewport::sizeHint() const
370 {
371 return QSize(800, 600);
372 }
374 #define CRITICAL(error, detail) \
375 do { \
376 fprintf(stderr, "%s: %s\n", error, detail); \
377 QMessageBox::critical(main_win, error, detail); \
378 abort(); \
379 } while(0)
381 void GoatViewport::initializeGL()
382 {
383 if(initialized) return;
384 initialized = true;
386 init_opengl();
388 if(!GLEW_ARB_transpose_matrix) {
389 CRITICAL("OpenGL initialization failed", "ARB_transpose_matrix extension not found!");
390 }
392 glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
394 glEnable(GL_DEPTH_TEST);
395 glEnable(GL_CULL_FACE);
396 if(use_lighting) {
397 glEnable(GL_LIGHTING);
398 }
399 glEnable(GL_LIGHT0);
401 float ldir[] = {-1, 1, 2, 0};
402 glLightfv(GL_LIGHT0, GL_POSITION, ldir);
404 glEnable(GL_MULTISAMPLE);
405 }
407 void GoatViewport::resizeGL(int xsz, int ysz)
408 {
409 glViewport(0, 0, xsz, ysz);
410 glMatrixMode(GL_PROJECTION);
411 glLoadIdentity();
412 gluPerspective(60.0, (float)xsz / (float)ysz, 0.5, 5000.0);
413 }
415 void GoatViewport::paintGL()
416 {
417 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
419 glMatrixMode(GL_MODELVIEW);
420 glLoadIdentity();
421 glTranslatef(0, 0, -cam_dist);
422 glRotatef(cam_phi, 1, 0, 0);
423 glRotatef(cam_theta, 0, 1, 0);
425 draw_grid();
427 if(!scene) return;
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 void GoatViewport::toggle_lighting()
447 {
448 use_lighting = !use_lighting;
449 if(use_lighting) {
450 glEnable(GL_LIGHTING);
451 } else {
452 glDisable(GL_LIGHTING);
453 }
454 updateGL();
455 }
457 #ifndef GLEW_ARB_transpose_matrix
458 #error "GLEW_ARB_transpose_matrix undefined?"
459 #endif
461 static void draw_grid()
462 {
463 float viewsz_orig = cam_dist * tan(DEG_TO_RAD(fov) / 2.0);
464 float sz1 = next_pow2((int)viewsz_orig);
465 float sz0 = sz1 / 2.0;
466 float t = (viewsz_orig - sz0) / (sz1 - sz0);
467 float alpha = t < 0.333333 ? 0.0 : (t > 0.666666 ? 1.0 : (t - 0.333333) / 0.333333);
469 glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BITS);
471 glEnable(GL_BLEND);
472 glDepthFunc(GL_ALWAYS);
474 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
475 draw_grid(sz0 * 2.0, 10, 1.0 - alpha);
476 draw_grid(sz1 * 2.0, 10, alpha);
478 glPopAttrib();
479 }
481 static void draw_grid(float sz, int nlines, float alpha)
482 {
483 float hsz = sz / 2.0;
484 float offs = sz / (float)nlines;
486 glPushAttrib(GL_ENABLE_BIT);
487 glDisable(GL_LIGHTING);
488 glDisable(GL_TEXTURE_2D);
490 glLineWidth(2.0);
491 glBegin(GL_LINES);
492 glColor4f(1, 0, 0, alpha);
493 glVertex3f(-hsz, 0, 0);
494 glVertex3f(hsz, 0, 0);
495 glColor4f(0, 0, 1, alpha);
496 glVertex3f(0, 0, -hsz);
497 glVertex3f(0, 0, hsz);
498 glEnd();
500 glLineWidth(1.0);
501 glBegin(GL_LINES);
502 glColor4f(0.5, 0.5, 0.5, alpha);
503 for(int i=0; i<nlines / 2; i++) {
504 float dist = (float)(i + 1) * offs;
505 for(int j=0; j<2; j++) {
506 float sign = j > 0 ? -1.0 : 1.0;
507 glVertex3f(-hsz, 0, dist * sign);
508 glVertex3f(hsz, 0, dist * sign);
509 glVertex3f(dist * sign, 0, -hsz);
510 glVertex3f(dist * sign, 0, hsz);
511 }
512 }
513 glEnd();
515 glPopAttrib();
516 }
518 static void draw_node(goat3d_node *node)
519 {
520 SceneNodeData *data = sdata ? sdata->get_node_data(node) : 0;
521 if(!data) return;
523 float xform[16];
524 goat3d_get_node_matrix(node, xform, anim_time);
526 glPushMatrix();
527 glMultTransposeMatrixf(xform);
529 if(data->visible) {
530 if(goat3d_get_node_type(node) == GOAT3D_NODE_MESH) {
531 goat3d_mesh *mesh = (goat3d_mesh*)goat3d_get_node_object(node);
533 draw_mesh(mesh);
535 if(data->selected) {
536 float bmin[3], bmax[3];
537 goat3d_get_mesh_bounds(mesh, bmin, bmax);
539 glPushAttrib(GL_ENABLE_BIT);
540 glDisable(GL_LIGHTING);
542 glColor3f(0.3, 1, 0.2);
544 glBegin(GL_LINE_LOOP);
545 glVertex3f(bmin[0], bmin[1], bmin[2]);
546 glVertex3f(bmax[0], bmin[1], bmin[2]);
547 glVertex3f(bmax[0], bmin[1], bmax[2]);
548 glVertex3f(bmin[0], bmin[1], bmax[2]);
549 glEnd();
550 glBegin(GL_LINE_LOOP);
551 glVertex3f(bmin[0], bmax[1], bmin[2]);
552 glVertex3f(bmax[0], bmax[1], bmin[2]);
553 glVertex3f(bmax[0], bmax[1], bmax[2]);
554 glVertex3f(bmin[0], bmax[1], bmax[2]);
555 glEnd();
556 glBegin(GL_LINES);
557 glVertex3f(bmin[0], bmin[1], bmin[2]);
558 glVertex3f(bmin[0], bmax[1], bmin[2]);
559 glVertex3f(bmin[0], bmin[1], bmax[2]);
560 glVertex3f(bmin[0], bmax[1], bmax[2]);
561 glVertex3f(bmax[0], bmin[1], bmin[2]);
562 glVertex3f(bmax[0], bmax[1], bmin[2]);
563 glVertex3f(bmax[0], bmin[1], bmax[2]);
564 glVertex3f(bmax[0], bmax[1], bmax[2]);
565 glEnd();
567 glPopAttrib();
568 }
569 }
570 }
572 int num_child = goat3d_get_node_child_count(node);
573 for(int i=0; i<num_child; i++) {
574 draw_node(goat3d_get_node_child(node, i));
575 }
577 glPopMatrix();
578 }
580 static void draw_mesh(goat3d_mesh *mesh)
581 {
582 static const float white[] = {1, 1, 1, 1};
583 static const float black[] = {0, 0, 0, 1};
585 const float *color;
586 goat3d_material *mtl = goat3d_get_mesh_mtl(mesh);
588 if(mtl && (color = goat3d_get_mtl_attrib(mtl, GOAT3D_MAT_ATTR_DIFFUSE))) {
589 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
590 glColor3fv(color);
591 } else {
592 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, white);
593 glColor3fv(white);
594 }
595 if(mtl && (color = goat3d_get_mtl_attrib(mtl, GOAT3D_MAT_ATTR_SPECULAR))) {
596 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
597 } else {
598 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
599 }
600 if(mtl && (color = goat3d_get_mtl_attrib(mtl, GOAT3D_MAT_ATTR_SHININESS))) {
601 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, color[0]);
602 } else {
603 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 60.0);
604 }
605 // TODO texture
608 int num_faces = goat3d_get_mesh_face_count(mesh);
609 int num_verts = goat3d_get_mesh_attrib_count(mesh, GOAT3D_MESH_ATTR_VERTEX);
611 glEnableClientState(GL_VERTEX_ARRAY);
612 glVertexPointer(3, GL_FLOAT, 0, goat3d_get_mesh_attribs(mesh, GOAT3D_MESH_ATTR_VERTEX));
614 float *data;
615 if((data = (float*)goat3d_get_mesh_attribs(mesh, GOAT3D_MESH_ATTR_NORMAL))) {
616 glEnableClientState(GL_NORMAL_ARRAY);
617 glNormalPointer(GL_FLOAT, 0, data);
618 }
619 if((data = (float*)goat3d_get_mesh_attribs(mesh, GOAT3D_MESH_ATTR_TEXCOORD))) {
620 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
621 glTexCoordPointer(2, GL_FLOAT, 0, data);
622 }
624 int *indices;
625 if((indices = goat3d_get_mesh_faces(mesh))) {
626 glDrawElements(GL_TRIANGLES, num_faces * 3, GL_UNSIGNED_INT, indices);
627 } else {
628 glDrawArrays(GL_TRIANGLES, 0, num_verts * 3);
629 }
631 glDisableClientState(GL_VERTEX_ARRAY);
632 glDisableClientState(GL_NORMAL_ARRAY);
633 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
634 }
637 static float prev_x, prev_y;
638 void GoatViewport::mousePressEvent(QMouseEvent *ev)
639 {
640 prev_x = ev->x();
641 prev_y = ev->y();
642 }
644 void GoatViewport::mouseMoveEvent(QMouseEvent *ev)
645 {
646 int dx = ev->x() - prev_x;
647 int dy = ev->y() - prev_y;
648 prev_x = ev->x();
649 prev_y = ev->y();
651 if(!dx && !dy) return;
653 if(ev->buttons() & Qt::LeftButton) {
654 cam_theta += dx * 0.5;
655 cam_phi += dy * 0.5;
657 if(cam_phi < -90) cam_phi = -90;
658 if(cam_phi > 90) cam_phi = 90;
659 }
660 if(ev->buttons() & Qt::RightButton) {
661 cam_dist += dy * 0.1;
663 if(cam_dist < 0.0) cam_dist = 0.0;
664 }
665 updateGL();
666 }
668 static const char *about_str =
669 "GoatView - Goat3D scene file viewer<br>"
670 "Copyright (C) 2014 John Tsiombikas &lt;<a href=\"mailto:nuclear@mutantstargoat.com\">nuclear@mutantstargoat.com</a>&gt;<br>"
671 "<br>"
672 "This program is free software: you can redistribute it and/or modify<br>"
673 "it under the terms of the GNU General Public License as published by<br>"
674 "the Free Software Foundation, either version 3 of the License, or<br>"
675 "(at your option) any later version.<br>"
676 "<br>"
677 "This program is distributed in the hope that it will be useful,<br>"
678 "but WITHOUT ANY WARRANTY; without even the implied warranty of<br>"
679 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>"
680 "GNU General Public License for more details.<br>"
681 "<br>"
682 "You should have received a copy of the GNU General Public License<br>"
683 "along with this program. If not, see <a href=\"http://www.gnu.org/licenses/gpl\">http://www.gnu.org/licenses/gpl</a>.";
685 void GoatView::show_about()
686 {
687 QMessageBox::information(this, "About GoatView", about_str);
688 }
691 static int next_pow2(int x)
692 {
693 x--;
694 x = (x >> 1) | x;
695 x = (x >> 2) | x;
696 x = (x >> 4) | x;
697 x = (x >> 8) | x;
698 x = (x >> 16) | x;
699 return x + 1;
700 }