Commit fc71d062 by Kai Westerkamp

added Add Actions

parent b9e72246
...@@ -44,7 +44,7 @@ void Camera::setupCamera(GLdouble aspect ) ...@@ -44,7 +44,7 @@ void Camera::setupCamera(GLdouble aspect )
if(persp){ if(persp){
perspective(45.0,aspect,0.01,100.0); perspective(45.0,aspect,0.01,100.0);
} else { } else {
int size = 1; int size = 4;
glOrtho(-size*aspect,size*aspect,-size,size,0.01,100.0); glOrtho(-size*aspect,size*aspect,-size,size,0.01,100.0);
} }
......
...@@ -16,8 +16,10 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -16,8 +16,10 @@ MainWindow::MainWindow(QWidget *parent)
//Views //Views
scene = new Scene(); scene = new Scene();
scene->setTesselation(1);
connect(scene,SIGNAL(activChanged()),this,SLOT(updateStatusBar())); connect(scene,SIGNAL(activChanged()),this,SLOT(updateStatusBar()));
scene->simpleScene(); connect(scene,SIGNAL(activChanged()),this,SLOT(updateGL()));
controler = new Controler(this,scene); controler = new Controler(this,scene);
...@@ -64,6 +66,7 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -64,6 +66,7 @@ MainWindow::MainWindow(QWidget *parent)
fileMenu = new QMenu("&File"); fileMenu = new QMenu("&File");
viewGoup = new QActionGroup(this); viewGoup = new QActionGroup(this);
viewMenu = new QMenu("View",this); viewMenu = new QMenu("View",this);
primitivesMenu = new QMenu("Primitives",this);
interactionGroup = new QActionGroup(this); interactionGroup = new QActionGroup(this);
interactionMenu = new QMenu("Interaction",this); interactionMenu = new QMenu("Interaction",this);
...@@ -125,10 +128,47 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -125,10 +128,47 @@ MainWindow::MainWindow(QWidget *parent)
camHome = new QAction(QIcon(":/img/cam_home.png"),"Cam Home", toolBar); camHome = new QAction(QIcon(":/img/cam_home.png"),"Cam Home", toolBar);
slider = new QSlider(Qt::Horizontal,toolBar);
slider->setMinimum( 0 );
slider->setMaximum( 4 );
connect(slider,SIGNAL(valueChanged(int)),scene,SLOT(setTessellation(int)));
slider->setValue( 1 );
// Add Primitives
spheresAdd = new QAction("Sphere",this);
spheresAdd->setIcon(QIcon(":/img/sphere.png"));
connect(spheresAdd, SIGNAL(triggered()), scene, SLOT(addSphere()));
boxesAdd = new QAction("Box",this);
boxesAdd->setIcon(QIcon(":/img/box.png"));
connect(boxesAdd, SIGNAL(triggered()), scene, SLOT(addCube()));
cylindersAdd = new QAction("Cylinder",this);
cylindersAdd->setIcon(QIcon(":/img/cylinder.png"));
connect(cylindersAdd, SIGNAL(triggered()), scene, SLOT(addCylinder()));
coneAdd = new QAction("Cone",this);
coneAdd->setIcon(QIcon(":/img/cone.png"));
connect(coneAdd, SIGNAL(triggered()), scene, SLOT(addCone()));
torusAdd = new QAction("Torus",this);
torusAdd->setIcon(QIcon(":/img/torus.png"));
connect(torusAdd, SIGNAL(triggered()), scene, SLOT(addTorus()));
primitivesMenu->addAction(spheresAdd);
primitivesMenu->addAction(boxesAdd);
primitivesMenu->addAction(cylindersAdd);
primitivesMenu->addAction(coneAdd);
primitivesMenu->addAction(torusAdd);
// Assemble Menus // Assemble Menus
fileMenu->addAction(exitAction); fileMenu->addAction(exitAction);
menuBar->addMenu(fileMenu); menuBar->addMenu(fileMenu);
menuBar->addMenu(primitivesMenu);
menuBar->addAction(aboutAction); menuBar->addAction(aboutAction);
setMenuBar(menuBar); setMenuBar(menuBar);
...@@ -141,19 +181,56 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -141,19 +181,56 @@ MainWindow::MainWindow(QWidget *parent)
toolBar->addAction(camHome); toolBar->addAction(camHome);
toolBar->addSeparator(); toolBar->addSeparator();
QToolButton* toolButton = new QToolButton(); QToolButton* toolButton = new QToolButton();
toolButton->setIcon(QIcon(":/img/viewports.png")); toolButton->setIcon(QIcon(":/img/viewports.png"));
toolButton->setMenu(viewMenu); toolButton->setMenu(viewMenu);
toolButton->setPopupMode(QToolButton::InstantPopup); toolButton->setPopupMode(QToolButton::InstantPopup);
QWidgetAction* toolButtonAction = new QWidgetAction(this); QWidgetAction* toolButtonAction = new QWidgetAction(this);
toolButtonAction->setDefaultWidget(toolButton); toolButtonAction->setDefaultWidget(toolButton);
toolBar->addAction(toolButtonAction); toolBar->addAction(toolButtonAction);
QToolButton* primitives = new QToolButton();
primitives->setIcon(QIcon(":/img/box.png"));
primitives->setMenu(primitivesMenu);
primitives->setPopupMode(QToolButton::InstantPopup);
QWidgetAction* primitiveActione = new QWidgetAction(this);
primitiveActione->setDefaultWidget(primitives);
toolBar->addAction(primitiveActione);
toolBar->addWidget(slider);
addToolBar( toolBar); addToolBar( toolBar);
scene->simpleScene();
setStatusBar(statusBar); setStatusBar(statusBar);
initDoc();
}
void MainWindow::initDoc()
{
QDockWidget *dock = new QDockWidget("Scene", this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
sceneView = new QTreeView();
sceneView->setSelectionBehavior(QAbstractItemView::SelectRows);
// sceneView->setModel(scene);
QListWidget *customerList = new QListWidget(dock);
customerList->addItems(QStringList()
<< "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton"
<< "Jane Doe, Memorabilia, 23 Watersedge, Beaton"
<< "Tammy Shea, Tiblanka, 38 Sea Views, Carlton"
<< "Tim Sheen, Caraba Gifts, 48 Ocean Way, Deal"
<< "Sol Harvey, Chicos Coffee, 53 New Springs, Eccleston"
<< "Sally Hobart, Tiroli Tea, 67 Long River, Fedula");
dock->setWidget(customerList);
addDockWidget(Qt::RightDockWidgetArea, dock);
} }
......
...@@ -43,8 +43,17 @@ private: ...@@ -43,8 +43,17 @@ private:
QAction *camHome; QAction *camHome;
QMenu *primitivesMenu;
QAction *spheresAdd;
QAction *boxesAdd;
QAction *cylindersAdd;
QAction *coneAdd;
QAction *torusAdd;
QToolBar *toolBar; QToolBar *toolBar;
QStatusBar *statusBar; QStatusBar *statusBar;
QSlider *slider;
Scene* scene; Scene* scene;
Controler *controler; Controler *controler;
...@@ -58,13 +67,17 @@ private: ...@@ -58,13 +67,17 @@ private:
GLView *leftView; GLView *leftView;
GLView *topView; GLView *topView;
QTreeView *sceneView;
void initDoc();
public: public:
MainWindow(QWidget *parent = 0); MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();
void setActiveView(GLView * active); void setActiveView(GLView * active);
void updateGL();
public slots: public slots:
void updateGL();
void updateStatusBar(); void updateStatusBar();
void showAboutBox(); void showAboutBox();
void showSingle(); void showSingle();
......
...@@ -9,40 +9,84 @@ Scene::Scene( ) ...@@ -9,40 +9,84 @@ Scene::Scene( )
int Scene::simpleScene() int Scene::simpleScene()
{ {
addCube();
moveActive(QVector3D(4,0,0));
float red[] = {1.0,0.0,0.0}; addSphere();
float green[] = {0.0,1.0,0.0}; moveActive(QVector3D(1.5,0,0));
float blue[] = {0.0,0.0,1.0};
float cyan[] = {0.0,1.0,1.0};
float magenta[] = {1.0,0.0,1.0};
float yellow[] = {1.0,1.0,0.0};
ScenePrimitive *box = new ScenePrimitive(PrimitiveType::Quader,2,root); addCylinder();
moveActive(QVector3D(0,1.5,-1.5));
box->setMaterial(blue); addTorus();
root->add(box); moveActive(QVector3D(-1.5,0,0));
ScenePrimitive *sphere = new ScenePrimitive(PrimitiveType::Sphere,10,root); addCone();
sphere->move(QVector3D(1.5,0,0)); moveActive(QVector3D(0,-1.5,-1.5));
sphere->setMaterial(green);
root->add(sphere);
ScenePrimitive *cylinder = new ScenePrimitive(PrimitiveType::Cylinder,10,root); return active->getID();
cylinder->move(QVector3D(0,1.5,0));
cylinder->setMaterial(red);
root->add(cylinder);
ScenePrimitive *torus = new ScenePrimitive(PrimitiveType::Torus,10,root); }
torus->move(QVector3D(0,0,1.5));
torus->setMaterial(magenta);
root->add(torus);
active = cylinder; ScenePrimitive *Scene::addCube()
{
float color[] = {0.0,0.0,1.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Quader,tesselation,root);
primitive->setMaterial(color);
root->add(primitive);
active = primitive;
emit activChanged();
return primitive;
}
ScenePrimitive* Scene::addSphere()
{
float color[] = {0.0,1.0,0.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Sphere,tesselation,root);
primitive->setMaterial(color);
root->add(primitive);
active = primitive;
emit activChanged(); emit activChanged();
return primitive;
}
return cylinder->getID(); ScenePrimitive* Scene::addCylinder()
{
float color[] = {1.0,0.0,0.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Cylinder,tesselation,root);
primitive->setMaterial(color);
root->add(primitive);
active = primitive;
emit activChanged();
return primitive;
}
ScenePrimitive* Scene::addTorus()
{
float color[] = {1.0,0.0,1.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Torus,tesselation,root);
primitive->setMaterial(color);
root->add(primitive);
active = primitive;
emit activChanged();
return primitive;
}
ScenePrimitive* Scene::addCone()
{
float color[] = {0.0,1.0,1.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Cone,tesselation,root);
primitive->setMaterial(color);
root->add(primitive);
active = primitive;
emit activChanged();
return primitive;
}
void Scene::setTesselation(int tesselation)
{
this->tesselation = tesselation;
} }
SceneObject *Scene::setActive(int id){ SceneObject *Scene::setActive(int id){
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include <sceneobject.h> #include <sceneobject.h>
#include <sceneprimitive.h> #include <sceneprimitive.h>
class Scene: public QObject class Scene: public QObject // QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
public: public:
...@@ -27,6 +27,25 @@ public: ...@@ -27,6 +27,25 @@ public:
SceneObject *setActive(int id); SceneObject *setActive(int id);
// QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
// Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
// QVariant headerData(int section, Qt::Orientation orientation,
// int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
// QModelIndex index(int row, int column,
// const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
// QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
// int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
// int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
int tesselation;
public slots:
void setTesselation(int tesselation);
ScenePrimitive *addCube();
ScenePrimitive *addSphere();
ScenePrimitive *addCylinder();
ScenePrimitive *addTorus();
ScenePrimitive *addCone();
signals: signals:
void activChanged(); void activChanged();
...@@ -34,6 +53,7 @@ private: ...@@ -34,6 +53,7 @@ private:
SceneNode *root; SceneNode *root;
SceneObject *active; SceneObject *active;
SceneNode *getRoot(); SceneNode *getRoot();
......
...@@ -6,6 +6,7 @@ int ScenePrimitive::quaderCount = 1; ...@@ -6,6 +6,7 @@ int ScenePrimitive::quaderCount = 1;
int ScenePrimitive::sphereCount = 1; int ScenePrimitive::sphereCount = 1;
int ScenePrimitive::cylinderCount = 1; int ScenePrimitive::cylinderCount = 1;
int ScenePrimitive::torusCount = 1; int ScenePrimitive::torusCount = 1;
int ScenePrimitive::coneCount = 1;
ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *parent) ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *parent)
...@@ -22,29 +23,38 @@ ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *par ...@@ -22,29 +23,38 @@ ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *par
this->color[1] = 0.0; this->color[1] = 0.0;
this->color[2] = 0.0; this->color[2] = 0.0;
switch (this->type) { switch (this->type) {
case Quader: case Quader:
name = QString("Quader %1").arg(ScenePrimitive::quaderCount); name = QString("Quader %1").arg(ScenePrimitive::quaderCount);
ScenePrimitive::quaderCount++; ScenePrimitive::quaderCount++;
this->tesselation = pow(2,tesselation);
break; break;
case Sphere: case Sphere:
name = QString("Sphere %1").arg(ScenePrimitive::sphereCount); name = QString("Sphere %1").arg(ScenePrimitive::sphereCount);
ScenePrimitive::sphereCount++; ScenePrimitive::sphereCount++;
this->tesselation = 5*pow(2,tesselation);
break; break;
case Cylinder: case Cylinder:
name = QString("Cylinder %1").arg(ScenePrimitive::cylinderCount); name = QString("Cylinder %1").arg(ScenePrimitive::cylinderCount);
qDebug()<<ScenePrimitive::cylinderCount; qDebug()<<ScenePrimitive::cylinderCount;
ScenePrimitive::cylinderCount++; ScenePrimitive::cylinderCount++;
this->tesselation = 5*pow(2,tesselation);
break; break;
case Torus: case Torus:
name = QString("Torus %1").arg(ScenePrimitive::torusCount); name = QString("Torus %1").arg(ScenePrimitive::torusCount);
ScenePrimitive::torusCount++; ScenePrimitive::torusCount++;
this->tesselation = 5*pow(2,tesselation);
break;
case Cone:
name = QString("Cone %1").arg(ScenePrimitive::coneCount);
ScenePrimitive::coneCount++;
this->tesselation = 5*pow(2,tesselation);
break; break;
default: default:
qDebug()<<"Enum Error"; qDebug()<<"Enum Error";
break; break;
} }
// qDebug()<<"Tesselation"<<this->tesselation<<getName();
} }
void ScenePrimitive::draw(){ void ScenePrimitive::draw(){
...@@ -77,6 +87,11 @@ void ScenePrimitive::draw(){ ...@@ -77,6 +87,11 @@ void ScenePrimitive::draw(){
gluQuadricOrientation(qobj,GLU_OUTSIDE); gluQuadricOrientation(qobj,GLU_OUTSIDE);
gluDisk( qobj, 0.0 , radius, tesselation, 1); gluDisk( qobj, 0.0 , radius, tesselation, 1);
break; break;
case Cone:
gluCylinder(qobj,radius,0,3,tesselation,tesselation);
gluQuadricOrientation(qobj,GLU_INSIDE);
gluDisk( qobj, 0.0, radius, tesselation, 1);
break;
case Torus: case Torus:
// glutSolidTorus(5, 15, 8, 128); // glutSolidTorus(5, 15, 8, 128);
break; break;
...@@ -104,7 +119,7 @@ void ScenePrimitive::setMaterial(float *color ) ...@@ -104,7 +119,7 @@ void ScenePrimitive::setMaterial(float *color )
void ScenePrimitive::drawCube(int tesselation) void ScenePrimitive::drawCube(int tesselation)
{ {
float increment = 1.0/(pow(2,tesselation)); float increment = 1.0/tesselation;
glBegin(GL_QUADS); glBegin(GL_QUADS);
glNormal3f(0,1,0); glNormal3f(0,1,0);
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <sceneobject.h> #include <sceneobject.h>
enum PrimitiveType{Quader=0,Sphere,Cylinder,Torus}; enum PrimitiveType{Quader=0,Sphere,Cylinder,Torus,Cone};
class ScenePrimitive : public SceneObject class ScenePrimitive : public SceneObject
{ {
...@@ -13,6 +13,7 @@ private: ...@@ -13,6 +13,7 @@ private:
static int sphereCount; static int sphereCount;
static int cylinderCount ; static int cylinderCount ;
static int torusCount; static int torusCount;
static int coneCount;
PrimitiveType type; PrimitiveType type;
int tesselation; int tesselation;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment