# HG changeset patch # User John Tsiombikas # Date 1399868572 -10800 # Node ID 57e745dd13c206548396cb84887c715572a677f6 # Parent 70b7c41a4f178032b22f0464ae2c6889fb54a815 almost working diff -r 70b7c41a4f17 -r 57e745dd13c2 goatview/src/goatview.cc --- a/goatview/src/goatview.cc Sun May 11 22:04:54 2014 +0300 +++ b/goatview/src/goatview.cc Mon May 12 07:22:52 2014 +0300 @@ -17,30 +17,44 @@ static float cam_theta, cam_phi, cam_dist = 8; static float fov = 60.0; static bool use_nodes = true; +static bool use_lighting = true; GoatView::GoatView() { glview = 0; + QSettings *settings = new QSettings; + resize(settings->value("main/size", QSize(1024, 768)).toSize()); + move(settings->value("main/pos", QPoint(100, 100)).toPoint()); + use_nodes = settings->value("use_nodes", true).toBool(); + use_lighting = settings->value("use_lighting", true).toBool(); + delete settings; + + make_center(); // must be first make_menu(); make_dock(); - make_center(); statusBar(); setWindowTitle("GoatView"); - - QSettings *settings = new QSettings; - resize(settings->value("main/size", QSize(1024, 768)).toSize()); - move(settings->value("main/pos", QPoint(100, 100)).toPoint()); - delete settings; } GoatView::~GoatView() { } +void GoatView::closeEvent(QCloseEvent *ev) +{ + QSettings *settings = new QSettings; + settings->setValue("main/size", size()); + settings->setValue("main/pos", pos()); + settings->setValue("use_nodes", use_nodes); + settings->setValue("use_lighting", use_lighting); + delete settings; +} + + bool GoatView::load_scene(const char *fname) { if(scene) { @@ -53,7 +67,7 @@ float bmin[3], bmax[3]; if(goat3d_get_bounds(scene, bmin, bmax) != -1) { float bsize = (Vector3(bmax[0], bmax[1], bmax[2]) - Vector3(bmin[0], bmin[1], bmin[2])).length(); - cam_dist = bsize / tan(DEG_TO_RAD(fov) / 2.0) + bsize; + cam_dist = bsize / tan(DEG_TO_RAD(fov) / 2.0); printf("bounds size: %f, cam_dist: %f\n", bsize, cam_dist); } @@ -61,14 +75,6 @@ return true; } -void GoatView::closeEvent(QCloseEvent *ev) -{ - QSettings *settings = new QSettings; - settings->setValue("main/size", size()); - settings->setValue("main/pos", pos()); - delete settings; -} - bool GoatView::make_menu() { // file menu @@ -94,8 +100,22 @@ QAction *act_use_nodes = new QAction("use nodes", this); act_use_nodes->setCheckable(true); act_use_nodes->setChecked(use_nodes); - connect(act_use_nodes, &QAction::triggered, this, [&](){use_nodes = !use_nodes; glview->updateGL();}); + connect(act_use_nodes, &QAction::triggered, this, + [&](){ use_nodes = !use_nodes; glview->updateGL(); }); menu_view->addAction(act_use_nodes); + + QAction *act_use_lighting = new QAction("lighting", this); + act_use_lighting->setCheckable(true); + act_use_lighting->setChecked(use_lighting); + connect(act_use_lighting, &QAction::triggered, glview, &GoatViewport::toggle_lighting); + menu_view->addAction(act_use_lighting); + + // help menu + QMenu *menu_help = menuBar()->addMenu("&Help"); + + QAction *act_about = new QAction("&About", this); + connect(act_about, &QAction::triggered, this, &GoatView::show_about); + menu_help->addAction(act_about); return true; } @@ -246,6 +266,13 @@ glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); + if(use_lighting) { + glEnable(GL_LIGHTING); + } + glEnable(GL_LIGHT0); + + float ldir[] = {-1, 1, 2, 0}; + glLightfv(GL_LIGHT0, GL_POSITION, ldir); } void GoatViewport::resizeGL(int xsz, int ysz) @@ -272,7 +299,9 @@ int node_count = goat3d_get_node_count(scene); for(int i=0; i" + "Copyright (C) 2014 John Tsiombikas <nuclear@mutantstargoat.com>
" + "
" + "This program is free software: you can redistribute it and/or modify
" + "it under the terms of the GNU General Public License as published by
" + "the Free Software Foundation, either version 3 of the License, or
" + "(at your option) any later version.
" + "
" + "This program is distributed in the hope that it will be useful,
" + "but WITHOUT ANY WARRANTY; without even the implied warranty of
" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" + "GNU General Public License for more details.
" + "
" + "You should have received a copy of the GNU General Public License
" + "along with this program. If not, see http://www.gnu.org/licenses/gpl."; + +void GoatView::show_about() +{ + QMessageBox::information(this, "About GoatView", about_str); +} diff -r 70b7c41a4f17 -r 57e745dd13c2 goatview/src/goatview.h --- a/goatview/src/goatview.h Sun May 11 22:04:54 2014 +0300 +++ b/goatview/src/goatview.h Mon May 12 07:22:52 2014 +0300 @@ -11,10 +11,10 @@ class GoatViewport; class GoatView : public QMainWindow { +private: Q_OBJECT -private: + GoatViewport *glview; - QStandardItemModel *sgmodel; // scene graph model QTreeWidget *scntree; void closeEvent(QCloseEvent *ev); @@ -31,6 +31,8 @@ ~GoatView(); bool load_scene(const char *fname); + + void show_about(); }; class GoatViewport : public QGLWidget { @@ -50,6 +52,8 @@ void resizeGL(int xsz, int ysz); void paintGL(); + void toggle_lighting(); + void mousePressEvent(QMouseEvent *ev); void mouseMoveEvent(QMouseEvent *ev); }; diff -r 70b7c41a4f17 -r 57e745dd13c2 src/goat3d.cc --- a/src/goat3d.cc Sun May 11 22:04:54 2014 +0300 +++ b/src/goat3d.cc Mon May 12 07:22:52 2014 +0300 @@ -58,7 +58,7 @@ GOAT3DAPI void goat3d_free(struct goat3d *g) { - delete g->search_path; + delete [] g->search_path; delete g->scn; delete g; } diff -r 70b7c41a4f17 -r 57e745dd13c2 src/goat3d_readxml.cc --- a/src/goat3d_readxml.cc Sun May 11 22:04:54 2014 +0300 +++ b/src/goat3d_readxml.cc Mon May 12 07:22:52 2014 +0300 @@ -286,7 +286,7 @@ if((elem = xml_node->FirstChildElement("pos"))) { const char *val = elem->Attribute("float3"); if(val && sscanf(val, "%f %f %f", vec, vec + 1, vec + 2) == 3) { - node->set_position(Vector3(val[0], val[1], val[2])); + node->set_position(Vector3(vec[0], vec[1], vec[2])); } else { logmsg(LOG_ERROR, "node %s: invalid position tag\n", node->get_name()); }