Commit fc71d062 by Kai Westerkamp

added Add Actions

parent b9e72246
......@@ -44,7 +44,7 @@ void Camera::setupCamera(GLdouble aspect )
if(persp){
perspective(45.0,aspect,0.01,100.0);
} else {
int size = 1;
int size = 4;
glOrtho(-size*aspect,size*aspect,-size,size,0.01,100.0);
}
......
......@@ -16,8 +16,10 @@ MainWindow::MainWindow(QWidget *parent)
//Views
scene = new Scene();
scene->setTesselation(1);
connect(scene,SIGNAL(activChanged()),this,SLOT(updateStatusBar()));
scene->simpleScene();
connect(scene,SIGNAL(activChanged()),this,SLOT(updateGL()));
controler = new Controler(this,scene);
......@@ -64,6 +66,7 @@ MainWindow::MainWindow(QWidget *parent)
fileMenu = new QMenu("&File");
viewGoup = new QActionGroup(this);
viewMenu = new QMenu("View",this);
primitivesMenu = new QMenu("Primitives",this);
interactionGroup = new QActionGroup(this);
interactionMenu = new QMenu("Interaction",this);
......@@ -125,10 +128,47 @@ MainWindow::MainWindow(QWidget *parent)
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
fileMenu->addAction(exitAction);
menuBar->addMenu(fileMenu);
menuBar->addMenu(primitivesMenu);
menuBar->addAction(aboutAction);
setMenuBar(menuBar);
......@@ -141,19 +181,56 @@ MainWindow::MainWindow(QWidget *parent)
toolBar->addAction(camHome);
toolBar->addSeparator();
QToolButton* toolButton = new QToolButton();
toolButton->setIcon(QIcon(":/img/viewports.png"));
toolButton->setMenu(viewMenu);
toolButton->setPopupMode(QToolButton::InstantPopup);
QWidgetAction* toolButtonAction = new QWidgetAction(this);
toolButtonAction->setDefaultWidget(toolButton);
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);
scene->simpleScene();
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:
QAction *camHome;
QMenu *primitivesMenu;
QAction *spheresAdd;
QAction *boxesAdd;
QAction *cylindersAdd;
QAction *coneAdd;
QAction *torusAdd;
QToolBar *toolBar;
QStatusBar *statusBar;
QSlider *slider;
Scene* scene;
Controler *controler;
......@@ -58,13 +67,17 @@ private:
GLView *leftView;
GLView *topView;
QTreeView *sceneView;
void initDoc();
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
void setActiveView(GLView * active);
void updateGL();
public slots:
void updateGL();
void updateStatusBar();
void showAboutBox();
void showSingle();
......
......@@ -9,40 +9,84 @@ Scene::Scene( )
int Scene::simpleScene()
{
addCube();
moveActive(QVector3D(4,0,0));
float red[] = {1.0,0.0,0.0};
float green[] = {0.0,1.0,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};
addSphere();
moveActive(QVector3D(1.5,0,0));
ScenePrimitive *box = new ScenePrimitive(PrimitiveType::Quader,2,root);
addCylinder();
moveActive(QVector3D(0,1.5,-1.5));
box->setMaterial(blue);
root->add(box);
addTorus();
moveActive(QVector3D(-1.5,0,0));
ScenePrimitive *sphere = new ScenePrimitive(PrimitiveType::Sphere,10,root);
sphere->move(QVector3D(1.5,0,0));
sphere->setMaterial(green);
root->add(sphere);
addCone();
moveActive(QVector3D(0,-1.5,-1.5));
ScenePrimitive *cylinder = new ScenePrimitive(PrimitiveType::Cylinder,10,root);
cylinder->move(QVector3D(0,1.5,0));
cylinder->setMaterial(red);
root->add(cylinder);
return active->getID();
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();
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){
......
......@@ -10,7 +10,7 @@
#include <sceneobject.h>
#include <sceneprimitive.h>
class Scene: public QObject
class Scene: public QObject // QAbstractItemModel
{
Q_OBJECT
public:
......@@ -27,6 +27,25 @@ public:
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:
void activChanged();
......@@ -34,6 +53,7 @@ private:
SceneNode *root;
SceneObject *active;
SceneNode *getRoot();
......
......@@ -6,6 +6,7 @@ int ScenePrimitive::quaderCount = 1;
int ScenePrimitive::sphereCount = 1;
int ScenePrimitive::cylinderCount = 1;
int ScenePrimitive::torusCount = 1;
int ScenePrimitive::coneCount = 1;
ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *parent)
......@@ -22,29 +23,38 @@ ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *par
this->color[1] = 0.0;
this->color[2] = 0.0;
switch (this->type) {
case Quader:
name = QString("Quader %1").arg(ScenePrimitive::quaderCount);
ScenePrimitive::quaderCount++;
this->tesselation = pow(2,tesselation);
break;
case Sphere:
name = QString("Sphere %1").arg(ScenePrimitive::sphereCount);
ScenePrimitive::sphereCount++;
this->tesselation = 5*pow(2,tesselation);
break;
case Cylinder:
name = QString("Cylinder %1").arg(ScenePrimitive::cylinderCount);
qDebug()<<ScenePrimitive::cylinderCount;
ScenePrimitive::cylinderCount++;
this->tesselation = 5*pow(2,tesselation);
break;
case Torus:
name = QString("Torus %1").arg(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;
default:
qDebug()<<"Enum Error";
break;
}
// qDebug()<<"Tesselation"<<this->tesselation<<getName();
}
void ScenePrimitive::draw(){
......@@ -77,6 +87,11 @@ void ScenePrimitive::draw(){
gluQuadricOrientation(qobj,GLU_OUTSIDE);
gluDisk( qobj, 0.0 , radius, tesselation, 1);
break;
case Cone:
gluCylinder(qobj,radius,0,3,tesselation,tesselation);
gluQuadricOrientation(qobj,GLU_INSIDE);
gluDisk( qobj, 0.0, radius, tesselation, 1);
break;
case Torus:
// glutSolidTorus(5, 15, 8, 128);
break;
......@@ -104,7 +119,7 @@ void ScenePrimitive::setMaterial(float *color )
void ScenePrimitive::drawCube(int tesselation)
{
float increment = 1.0/(pow(2,tesselation));
float increment = 1.0/tesselation;
glBegin(GL_QUADS);
glNormal3f(0,1,0);
......
......@@ -3,7 +3,7 @@
#include <sceneobject.h>
enum PrimitiveType{Quader=0,Sphere,Cylinder,Torus};
enum PrimitiveType{Quader=0,Sphere,Cylinder,Torus,Cone};
class ScenePrimitive : public SceneObject
{
......@@ -13,6 +13,7 @@ private:
static int sphereCount;
static int cylinderCount ;
static int torusCount;
static int coneCount;
PrimitiveType type;
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