1
git-svn-id: svn://db.shs.com.ru/libs@1 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
225
qglview/mainwindow.cpp
Normal file
225
qglview/mainwindow.cpp
Normal file
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
Stanley Designer
|
||||
Copyright (C) 2012 Ivan Pelipenko peri4ko@gmail.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/>.
|
||||
*/
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include <QGraphicsRectItem>
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow() {
|
||||
setupUi(this);
|
||||
colorHalo->setColor(view->selectionHaloColor());
|
||||
sel_obj = 0;
|
||||
treeProperties->assignObject(view);
|
||||
//spinSliderShine->setDecimals(2);
|
||||
view->setFrameShape(QFrame::NoFrame);
|
||||
view->setRenderer(new RendererDeferredShading(view));
|
||||
view->setMouseSelectionEnabled(true);
|
||||
view->setMouseRotateEnabled(true);
|
||||
view->setBackColor(Qt::lightGray);
|
||||
//view->setLightingMode(QGLView::PerPixel);
|
||||
/*MaterialEditor * o = new MaterialEditor();
|
||||
o->setWindowOpacity(.666);
|
||||
view->addObject(o, Qt::Window);*/
|
||||
view->start(-1);
|
||||
obj = loadFrom3DSFile("data/test.3DS", 0.15);
|
||||
m.reflectivity = 1;
|
||||
m.reflection.loadPathesFromDirectory("data/e");
|
||||
obj->child("sphere001")->setMaterial(m);
|
||||
|
||||
|
||||
//m.shine = 40;
|
||||
//m.shine_strength = 1;
|
||||
//m.diffuse.bitmap_path = "celtic_010.jpg";
|
||||
//m.bump.bitmap_path = "celtic_010n.jpg";
|
||||
/*obj->child("cone")->setMaterial(m);
|
||||
m.diffuse.bitmap_path = "proj_plane_d.tga";
|
||||
m.bump.bitmap_path = "proj_plane_n.tga";
|
||||
obj->child("tor")->setMaterial(m);
|
||||
m.reflectivity = 1.;
|
||||
obj->child("sphere")->setMaterial(m);*/
|
||||
//obj->child("teapot")->setRenderMode(GLObjectBase::Point);
|
||||
//obj->child("teapot")->setLineWidth(2.);
|
||||
//obj->child("cone")->setRenderMode(GLObjectBase::Line);
|
||||
view->addObject(obj);
|
||||
view->camera().setAim(obj->child("sphere001")->pos());
|
||||
view->camera().setPos(QVector3D(10, -20, 20));
|
||||
view->camera().flyToDistance(10);
|
||||
//view->light(0)->light_type = Light::Omni;
|
||||
//obj = loadFrom3DSFile("34.3DS", 0.03);
|
||||
//view->addObject(obj);
|
||||
//view->camera().moveUp(5, true);
|
||||
|
||||
ps = new GLParticlesSystem(QVector3D(0,0,5));
|
||||
ps->setEmitterType(GLParticlesSystem::Box);
|
||||
ps->setBirthRate(5);
|
||||
ps->setSize(1.);
|
||||
ps->setLifeDuration(5.);
|
||||
ps->setInitialSpeed(.5);
|
||||
ps->setFadeTime(1.);
|
||||
ps->setSpeedDirectionJitter(1);
|
||||
//ps->setTextureScale(2, 2);
|
||||
ps->setAddVerticalFaceEnabled(true);
|
||||
ps->addForce(QVector3D(0,0,-0.98/20));
|
||||
//ps->material().diffuse.bitmap_path = "expl_07.png";
|
||||
//view->addObject(ps);
|
||||
|
||||
box = new GLPrimitiveCube();
|
||||
box->setSelectable(false);
|
||||
box->setRenderMode(GLObjectBase::Line);
|
||||
box->setLineWidth(2.);
|
||||
view->addObject(box);
|
||||
box->hide();
|
||||
while (view->lightsCount() >= 3) view->removeLight(view->lightsCount() - 1);
|
||||
//view->addObject(box);
|
||||
|
||||
//obj = obj->clone(true);
|
||||
//obj->move(QVector3D(10,10,0));
|
||||
//view->addObject(obj);
|
||||
|
||||
//view->addObject(obj);
|
||||
//obj = obj->clone(true);
|
||||
//obj->move(QVector3D(10,10,0));
|
||||
//view->addObject(obj);
|
||||
/*int h = 0, dh = 360 / view->lights().size();
|
||||
foreach (Light * i, view->lights()) {
|
||||
i->setColor(QColor::fromHsv(h, 255, 255));
|
||||
i->intensity *= 2;
|
||||
h += dh;
|
||||
}*/
|
||||
startTimer(1000/60);
|
||||
|
||||
connect(view, SIGNAL(hoverChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(hoverChanged(GLObjectBase*,GLObjectBase*)));
|
||||
connect(view, SIGNAL(selectionChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(selectionChanged(GLObjectBase*,GLObjectBase*)));
|
||||
connect(view, SIGNAL(glInitializeDone()), this, SLOT(glInit()));
|
||||
connect(matEditor, SIGNAL(changed()), this, SLOT(materialChanged()));
|
||||
//view->addObject(new Light(view->camera().pos()));
|
||||
|
||||
//show();
|
||||
}
|
||||
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
delete ps;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::changeEvent(QEvent * e) {
|
||||
QMainWindow::changeEvent(e);
|
||||
/*if (e->type() == QEvent::LanguageChange) {
|
||||
retranslateUi(this);
|
||||
return;
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::timerEvent(QTimerEvent * ) {
|
||||
static double t = 0.;
|
||||
/*obj->child("tor")->rotateX(0.5);
|
||||
obj->child("tor")->rotateZ(0.1);
|
||||
obj->child("cone")->rotateZ(1);
|
||||
obj->child("teapot")->rotateY(sin(t));
|
||||
obj->child("sphere")->setPosZ(fabs(sin(t)*5)-0.75);*/
|
||||
t += 0.1;
|
||||
setWindowTitle(QString::number(view->currentFPS(), 'f', 2));
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_view_glKeyPressEvent(QKeyEvent * e) {
|
||||
if (e->key() != Qt::Key_F11) return;
|
||||
if (view->windowState().testFlag(Qt::WindowFullScreen)) {
|
||||
centralwidget->layout()->addWidget(view);
|
||||
} else {
|
||||
view->setParent(0);
|
||||
view->showFullScreen();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::glInit() {
|
||||
//view->bindTexture(QImage("e/bottom.jpg"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::loadFile(const QString & path) {
|
||||
prev_path = path;
|
||||
QCursor pcur = cursor();
|
||||
setCursor(Qt::WaitCursor);
|
||||
|
||||
setCursor(pcur);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::selectionChanged(GLObjectBase * cur, GLObjectBase * prev) {
|
||||
sel_obj = cur;
|
||||
//qDebug() << "selected" << (cur != 0 ? cur->name() : "0");
|
||||
labelName->setText(cur != 0 ? cur->name() : "");
|
||||
if (cur == 0) box->hide();
|
||||
else {
|
||||
box->setScale(cur->boundingBox().size());
|
||||
box->setPos(cur->boundingBox().pos());
|
||||
Box3D b = cur->boundingBox().movedTo(-cur->boundingBox().center());
|
||||
b.z = -b.z - b.height;
|
||||
ps->setEmitterRect(b);
|
||||
cur->addChild(box);
|
||||
box->show();
|
||||
}
|
||||
objectEditor->setObject(sel_obj);
|
||||
if (sel_obj == 0) return;
|
||||
matEditor->setMaterial(sel_obj->material());
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::materialChanged() {
|
||||
if (sel_obj == 0) return;
|
||||
sel_obj->setMaterial(matEditor->material());
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_3_clicked() {
|
||||
QList<GLObjectBase * > ol = view->objects(true);
|
||||
qDebug() << ol.size();
|
||||
foreach (GLObjectBase * i, ol) {
|
||||
i->VBO().rebuffer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_comboBox_currentIndexChanged(int val) {
|
||||
GLRendererBase * pr = 0;
|
||||
switch (val) {
|
||||
case 0: view->setRenderer(new RendererSimple(view), &pr); break;
|
||||
case 2: view->setRenderer(new RendererDeferredShading(view), &pr); break;
|
||||
}
|
||||
if (pr != 0) delete pr;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m) {
|
||||
//qDebug() << k;
|
||||
double spd = 0.2;
|
||||
if (m.testFlag(Qt::ShiftModifier))
|
||||
spd = 0.5;
|
||||
switch (k) {
|
||||
case Qt::Key_W: view->camera().moveForward(spd); break;
|
||||
case Qt::Key_S: view->camera().moveBackward(spd); break;
|
||||
case Qt::Key_A: view->camera().moveLeft(spd); break;
|
||||
case Qt::Key_D: view->camera().moveRight(spd); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user