Commit 49ce7bd6 by Kai Westerkamp

basic scene graph

parent 9a9bd4f3
...@@ -64,9 +64,8 @@ void GLView::paintGL () ...@@ -64,9 +64,8 @@ void GLView::paintGL ()
// format.setSamples(); // format.setSamples();
// format.setAttachment(QGLFramebufferObject::); // format.setAttachment(QGLFramebufferObject::);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glViewport(0,0,this->width(),this->height()); glViewport(0,0,this->width(),this->height());
...@@ -75,7 +74,22 @@ void GLView::paintGL () ...@@ -75,7 +74,22 @@ void GLView::paintGL ()
glMatrixMode (GL_PROJECTION); glMatrixMode (GL_PROJECTION);
glLoadIdentity (); glLoadIdentity ();
shader->setUniformValue("shaded",true);
//set Projection and Camera Rotation
camera->setupCamera(aspect);
//draw Scene
scene->draw();
if(isActive){ if(isActive){
glDisable(GL_DEPTH_TEST);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
shader->setUniformValue("shaded",false); shader->setUniformValue("shaded",false);
glLineWidth(10); glLineWidth(10);
GLfloat color[] = {1.0,1.0,0.0}; GLfloat color[] = {1.0,1.0,0.0};
...@@ -92,16 +106,6 @@ void GLView::paintGL () ...@@ -92,16 +106,6 @@ void GLView::paintGL ()
glEnd (); glEnd ();
} }
shader->setUniformValue("shaded",true);
//set Projection and Camera Rotation
camera->setupCamera(aspect);
//draw Scene
scene->draw();
} }
void GLView::resizeGL(int width , int height ) void GLView::resizeGL(int width , int height )
......
...@@ -17,5 +17,6 @@ ...@@ -17,5 +17,6 @@
<file>img/view-dual.png</file> <file>img/view-dual.png</file>
<file>img/viewports.png</file> <file>img/viewports.png</file>
<file>img/view-single.png</file> <file>img/view-single.png</file>
<file>img/delete.png</file>
</qresource> </qresource>
</RCC> </RCC>
...@@ -6,22 +6,19 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -6,22 +6,19 @@ MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
{ {
setWindowTitle("Hello Cube"); setWindowTitle("Hello Cube");
menuBar = new QMenuBar(); menuBar = new QMenuBar();
toolBar = new QToolBar("Shading",this); toolBar = new QToolBar("Shading",this);
statusBar = new QStatusBar(this); statusBar = new QStatusBar(this);
//Views //Views
scene = new Scene(); scene = new Scene();
scene->setTesselation(1); scene->setTesselation(1);
connect(scene,SIGNAL(activChanged()),this,SLOT(updateStatusBar())); connect(scene,SIGNAL(activChanged()),this,SLOT(updateStatusBar()));
connect(scene,SIGNAL(activChanged()),this,SLOT(updateGL())); connect(scene,SIGNAL(activChanged()),this,SLOT(updateGL()));
controler = new Controler(this,scene); controler = new Controler(this,scene);
Camera *perspectiveCam = new Camera(true); Camera *perspectiveCam = new Camera(true);
...@@ -31,6 +28,7 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -31,6 +28,7 @@ MainWindow::MainWindow(QWidget *parent)
frontCam->setHome(new QQuaternion(), new QVector3D(0.0,0.0,-4.0)); frontCam->setHome(new QQuaternion(), new QVector3D(0.0,0.0,-4.0));
frontView = new GLView(scene,frontCam,controler); frontView = new GLView(scene,frontCam,controler);
Camera *leftCam = new Camera(false); Camera *leftCam = new Camera(false);
leftCam->setHome(new QQuaternion(QQuaternion::fromAxisAndAngle(0.0,1.0,0.0,90.0).toVector4D()), leftCam->setHome(new QQuaternion(QQuaternion::fromAxisAndAngle(0.0,1.0,0.0,90.0).toVector4D()),
new QVector3D(0.0,0.0,-4.0)); new QVector3D(0.0,0.0,-4.0));
...@@ -45,8 +43,10 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -45,8 +43,10 @@ MainWindow::MainWindow(QWidget *parent)
bottomSplit = new QSplitter(Qt::Horizontal,this); bottomSplit = new QSplitter(Qt::Horizontal,this);
verticalSplit = new QSplitter(Qt::Vertical,this); verticalSplit = new QSplitter(Qt::Vertical,this);
camHome = new QAction(QIcon(":/img/cam_home.png"),"Cam Home", toolBar);
setActiveView(perspectiveView); setActiveView(perspectiveView);
topSplit->addWidget(perspectiveView); topSplit->addWidget(perspectiveView);
topSplit->addWidget(frontView); topSplit->addWidget(frontView);
...@@ -55,6 +55,8 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -55,6 +55,8 @@ MainWindow::MainWindow(QWidget *parent)
verticalSplit->addWidget(topSplit); verticalSplit->addWidget(topSplit);
verticalSplit->addWidget(bottomSplit); verticalSplit->addWidget(bottomSplit);
setCentralWidget(verticalSplit); setCentralWidget(verticalSplit);
showQuad(); showQuad();
...@@ -125,18 +127,17 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -125,18 +127,17 @@ MainWindow::MainWindow(QWidget *parent)
aboutAction = new QAction("About",menuBar); aboutAction = new QAction("About",menuBar);
connect(aboutAction,SIGNAL(triggered()),this,SLOT(showAboutBox())); connect(aboutAction,SIGNAL(triggered()),this,SLOT(showAboutBox()));
camHome = new QAction(QIcon(":/img/cam_home.png"),"Cam Home", toolBar);
slider = new QSlider(Qt::Horizontal,toolBar); slider = new QSlider(Qt::Horizontal,toolBar);
slider->setMinimum( 0 ); slider->setMinimum( 0 );
slider->setMaximum( 4 ); slider->setMaximum( 4 );
connect(slider,SIGNAL(valueChanged(int)),scene,SLOT(setTessellation(int))); connect(slider,SIGNAL(valueChanged(int)),scene,SLOT(setTesselation(int)));
slider->setValue( 1 ); slider->setValue( 1 );
// Add Primitives // Add Primitives
spheresAdd = new QAction("Sphere",this); spheresAdd = new QAction("Sphere",this);
spheresAdd->setIcon(QIcon(":/img/sphere.png")); spheresAdd->setIcon(QIcon(":/img/sphere.png"));
connect(spheresAdd, SIGNAL(triggered()), scene, SLOT(addSphere())); connect(spheresAdd, SIGNAL(triggered()), scene, SLOT(addSphere()));
...@@ -157,12 +158,23 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -157,12 +158,23 @@ MainWindow::MainWindow(QWidget *parent)
torusAdd->setIcon(QIcon(":/img/torus.png")); torusAdd->setIcon(QIcon(":/img/torus.png"));
connect(torusAdd, SIGNAL(triggered()), scene, SLOT(addTorus())); connect(torusAdd, SIGNAL(triggered()), scene, SLOT(addTorus()));
qDebug()<<"Test";
groupAdd = new QAction("Group",this);
groupAdd->setIcon(QIcon(":/img/wireframe.png"));
connect(groupAdd, SIGNAL(triggered()), scene, SLOT(addNode()));
activeDelete = new QAction("Delete",this);
activeDelete->setIcon(QIcon(":/img/delete.png"));
connect(activeDelete, SIGNAL(triggered()), scene, SLOT(deletActive()));
primitivesMenu->addAction(spheresAdd); primitivesMenu->addAction(spheresAdd);
primitivesMenu->addAction(boxesAdd); primitivesMenu->addAction(boxesAdd);
primitivesMenu->addAction(cylindersAdd); primitivesMenu->addAction(cylindersAdd);
primitivesMenu->addAction(coneAdd); primitivesMenu->addAction(coneAdd);
primitivesMenu->addAction(torusAdd); primitivesMenu->addAction(torusAdd);
primitivesMenu->addAction(groupAdd);
primitivesMenu->addAction(activeDelete);
// Assemble Menus // Assemble Menus
...@@ -214,20 +226,13 @@ void MainWindow::initDoc() ...@@ -214,20 +226,13 @@ void MainWindow::initDoc()
QDockWidget *dock = new QDockWidget("Scene", this); QDockWidget *dock = new QDockWidget("Scene", this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
sceneView = new QTreeView(); sceneView = new QTreeView(this);
sceneView->setSelectionBehavior(QAbstractItemView::SelectRows); sceneView->setSelectionBehavior(QAbstractItemView::SelectRows);
// sceneView->setModel(scene); sceneView->expandAll();
sceneView->setModel(scene);
connect(sceneView,SIGNAL(clicked(QModelIndex)),scene, SLOT(objectSelected(QModelIndex)));
QListWidget *customerList = new QListWidget(dock); dock->setWidget(sceneView);
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); addDockWidget(Qt::RightDockWidgetArea, dock);
...@@ -276,10 +281,10 @@ void MainWindow::updateGL() ...@@ -276,10 +281,10 @@ void MainWindow::updateGL()
void MainWindow::setActiveView(GLView * active) void MainWindow::setActiveView(GLView * active)
{ {
perspectiveView->setAcive((perspectiveView == active)); perspectiveView->setAcive((perspectiveView == active));
frontView->setAcive((frontView == active)); frontView->setAcive((frontView == active));
leftView->setAcive((leftView == active)); leftView->setAcive((leftView == active));
topView->setAcive((topView == active)); topView->setAcive((topView == active));
disconnect(camHome, SIGNAL(triggered(bool)),perspectiveView,SLOT(home())); disconnect(camHome, SIGNAL(triggered(bool)),perspectiveView,SLOT(home()));
disconnect(camHome, SIGNAL(triggered(bool)),frontView,SLOT(home())); disconnect(camHome, SIGNAL(triggered(bool)),frontView,SLOT(home()));
disconnect(camHome, SIGNAL(triggered(bool)),leftView,SLOT(home())); disconnect(camHome, SIGNAL(triggered(bool)),leftView,SLOT(home()));
......
...@@ -49,6 +49,8 @@ private: ...@@ -49,6 +49,8 @@ private:
QAction *cylindersAdd; QAction *cylindersAdd;
QAction *coneAdd; QAction *coneAdd;
QAction *torusAdd; QAction *torusAdd;
QAction *groupAdd;
QAction *activeDelete;
QToolBar *toolBar; QToolBar *toolBar;
......
...@@ -4,7 +4,15 @@ ...@@ -4,7 +4,15 @@
Scene::Scene( ) Scene::Scene( )
{ {
root = new SceneNode(this); root = new SceneNode();
root->setName("ROOT");
active = root;
activeIndex = QModelIndex();
}
Scene::~Scene( )
{
delete root;
} }
int Scene::simpleScene() int Scene::simpleScene()
...@@ -18,6 +26,8 @@ int Scene::simpleScene() ...@@ -18,6 +26,8 @@ int Scene::simpleScene()
addCylinder(); addCylinder();
moveActive(QVector3D(0,1.5,-1.5)); moveActive(QVector3D(0,1.5,-1.5));
addNode();
addTorus(); addTorus();
moveActive(QVector3D(0,0,-3)); moveActive(QVector3D(0,0,-3));
...@@ -28,61 +38,97 @@ int Scene::simpleScene() ...@@ -28,61 +38,97 @@ int Scene::simpleScene()
} }
ScenePrimitive *Scene::addCube() void Scene::addSceneObjectTaActive(SceneObject *obj){
SceneNode* parent;
QModelIndex parentIndex;
if(active->isNode()){
// qDebug()<<"Active is Node "<<active->getName();
parent = static_cast<SceneNode*>(active);
parentIndex = activeIndex;
} else {
parent = static_cast<SceneNode*>(active->getParent());
parentIndex = activeIndex.parent();
// qDebug()<<"Active is Primitve "<<active->getName()<<"Parent"<<parent->getName();
}
beginInsertRows(parentIndex, parent->childCount(), parent->childCount());
parent->add(obj);
obj->setParent(parent);
endInsertRows();
activeIndex = index(parent->childCount()-1,0,parentIndex);
active = obj;
qDebug()<<"Adding"<<obj->getName()<<" to "<<getItem(parentIndex)->getName()<<" Active"<<getItem(activeIndex)->getName();
emit activChanged();
}
void Scene::addCube()
{ {
float color[] = {0.0,0.0,1.0}; float color[] = {0.0,0.0,1.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Quader,tesselation,root); ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Quader,tesselation);
primitive->setMaterial(color); primitive->setMaterial(color);
root->add(primitive); addSceneObjectTaActive(primitive);
active = primitive;
emit activChanged();
return primitive;
} }
ScenePrimitive* Scene::addSphere() void Scene::addSphere()
{ {
float color[] = {0.0,1.0,0.0}; float color[] = {0.0,1.0,0.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Sphere,tesselation,root); ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Sphere,tesselation);
primitive->setMaterial(color); primitive->setMaterial(color);
root->add(primitive); addSceneObjectTaActive(primitive);
active = primitive;
emit activChanged();
return primitive;
} }
ScenePrimitive* Scene::addCylinder() void Scene::addCylinder()
{ {
float color[] = {1.0,0.0,0.0}; float color[] = {1.0,0.0,0.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Cylinder,tesselation,root); ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Cylinder,tesselation);
primitive->setMaterial(color); primitive->setMaterial(color);
root->add(primitive); addSceneObjectTaActive(primitive);
active = primitive;
emit activChanged();
return primitive;
} }
ScenePrimitive* Scene::addTorus() void Scene::addTorus()
{ {
float color[] = {1.0,0.0,1.0}; float color[] = {1.0,0.0,1.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Torus,tesselation,root); ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Torus,tesselation);
primitive->setMaterial(color); primitive->setMaterial(color);
root->add(primitive); addSceneObjectTaActive(primitive);
active = primitive;
emit activChanged();
return primitive;
} }
ScenePrimitive* Scene::addCone() void Scene::addCone()
{ {
float color[] = {0.0,1.0,1.0}; float color[] = {0.0,1.0,1.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Cone,tesselation,root); ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Cone,tesselation);
primitive->setMaterial(color); primitive->setMaterial(color);
root->add(primitive); addSceneObjectTaActive(primitive);
active = primitive;
emit activChanged();
return primitive;
} }
void Scene::addNode()
{
SceneNode *node = new SceneNode();
node->setName("Graph Node");
addSceneObjectTaActive(node);
}
void Scene::deletActive()
{
QModelIndex parentIndex = activeIndex.parent();
SceneNode *parent = static_cast<SceneNode*>(active->getParent());
active->childNumber();
int number = active->childNumber();
beginRemoveColumns(parentIndex, number, number);
parent->remove(number);
endRemoveColumns();
}
void Scene::setTesselation(int tesselation) void Scene::setTesselation(int tesselation)
{ {
...@@ -122,4 +168,99 @@ void Scene::rotateActive(QQuaternion rot) ...@@ -122,4 +168,99 @@ void Scene::rotateActive(QQuaternion rot)
active->rotate(rot); active->rotate(rot);
} }
//Model funktions
SceneObject *Scene::getItem(const QModelIndex &index) const
{
if (index.isValid()) {
SceneObject *item = static_cast<SceneObject*>(index.internalPointer());
if (item)
return item;
}
return root;
}
int Scene::rowCount(const QModelIndex &parent) const
{
SceneObject *parentItem = getItem(parent);
// qDebug()<<"ChildCount:"<<parentItem->childCount();
return parentItem->childCount();
}
int Scene::columnCount(const QModelIndex & parent ) const
{
SceneObject *item = getItem(parent);
// qDebug()<<"ColumnCount:"<<item->columnCount();
return item->columnCount();
}
Qt::ItemFlags Scene::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
return Qt::ItemIsEditable | QAbstractItemModel::flags(index);
}
QModelIndex Scene::index(int row, int column, const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() != 0)
return QModelIndex();
SceneObject *parentItem = getItem(parent);
SceneObject *childItem = parentItem->children(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
QModelIndex Scene::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
SceneObject *childItem = getItem(index);
SceneObject *parentItem = childItem->getParent();
if (parentItem == root)
return QModelIndex();
return createIndex(parentItem->childNumber(), 0, parentItem);
}
QVariant Scene::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role != Qt::DisplayRole && role != Qt::EditRole)
return QVariant();
SceneObject *item = getItem(index);
return item->data(index.column());
}
QVariant Scene::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return root->data(section);
return QVariant();
}
void Scene::objectSelected(QModelIndex index)
{
activeIndex = index;
active = getItem(index);
emit activChanged();
}
...@@ -10,11 +10,12 @@ ...@@ -10,11 +10,12 @@
#include <sceneobject.h> #include <sceneobject.h>
#include <sceneprimitive.h> #include <sceneprimitive.h>
class Scene: public QObject // QAbstractItemModel class Scene: public QAbstractItemModel // QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
public: public:
Scene(); Scene();
~Scene();
void draw(); void draw();
int simpleScene(); int simpleScene();
...@@ -23,28 +24,36 @@ public: ...@@ -23,28 +24,36 @@ public:
void moveActive(QVector3D dir); void moveActive(QVector3D dir);
void rotateActive(QQuaternion rot); void rotateActive(QQuaternion rot);
void addSceneObjectTaActive(SceneObject *obj);
SceneObject *getActive(); SceneObject *getActive();
SceneObject *setActive(int id); SceneObject *setActive(int id);
// QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; 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,
// QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
// int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
// QModelIndex index(int row, int column, QModelIndex index(int row, int column,
// const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
// QModelIndex parent(const QModelIndex &index) 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 rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
int tesselation; int tesselation;
public slots: public slots:
void setTesselation(int tesselation); void objectSelected(QModelIndex index);
ScenePrimitive *addCube(); void setTesselation(int tesselation);
ScenePrimitive *addSphere(); void addCube();
ScenePrimitive *addCylinder(); void addSphere();
ScenePrimitive *addTorus(); void addCylinder();
ScenePrimitive *addCone(); void addTorus();
void addCone();
void addNode();
void deletActive();
signals: signals:
void activChanged(); void activChanged();
...@@ -52,6 +61,8 @@ signals: ...@@ -52,6 +61,8 @@ signals:
private: private:
SceneNode *root; SceneNode *root;
SceneObject *active; SceneObject *active;
QModelIndex activeIndex;
SceneObject *getItem(const QModelIndex &index) const;
SceneNode *getRoot(); SceneNode *getRoot();
......
#include "scenenode.h" #include "scenenode.h"
SceneNode::SceneNode(QObject *parent) SceneNode::SceneNode()
:SceneObject(parent) :SceneObject()
{ {
childs = QList<SceneObject*>(); childs = QList<SceneObject*>();
} }
SceneNode::~SceneNode()
{
qDeleteAll(childs);
}
SceneObject *SceneNode::children(int number)
{
return childs.value(number);
}
int SceneNode::childCount() const
{
return childs.count();
}
void SceneNode::add(SceneObject *child) void SceneNode::add(SceneObject *child)
{ {
childs.append(child); childs.append(child);
} }
void SceneNode::remove(int number)
{
delete childs.takeAt(number);
}
SceneObject *SceneNode::find(int id) SceneObject *SceneNode::find(int id)
{ {
foreach (SceneObject *obj, childs) { foreach (SceneObject *obj, childs) {
...@@ -30,7 +52,6 @@ void SceneNode::draw() ...@@ -30,7 +52,6 @@ void SceneNode::draw()
{ {
glPushMatrix(); glPushMatrix();
applyTransformation(); applyTransformation();
foreach (SceneObject *obj, childs) { foreach (SceneObject *obj, childs) {
obj->draw(); obj->draw();
} }
......
...@@ -11,10 +11,19 @@ private: ...@@ -11,10 +11,19 @@ private:
QList<SceneObject*> childs; QList<SceneObject*> childs;
public: public:
SceneNode(QObject *parent); SceneNode();
~SceneNode();
SceneObject *children(int number);
int childCount() const;
QList<SceneObject*> getChildren(){return childs;}
virtual bool isNode(){return true;qDebug()<<"isNode";}
SceneObject *find(int id); SceneObject *find(int id);
void draw(); void draw();
void add(SceneObject *child); void add(SceneObject *child);
void remove(int number);
}; };
#endif // SCENENODE_H #endif // SCENENODE_H
#include "sceneobject.h" #include "sceneobject.h"
#include "scenenode.h"
SceneObject::SceneObject(QObject *parent) SceneObject::SceneObject()
:QObject(parent)
{ {
id = 3; id = 3;
name = QString("Scene Object "+id); name = QString("Scene Object "+id);
...@@ -10,6 +10,57 @@ SceneObject::SceneObject(QObject *parent) ...@@ -10,6 +10,57 @@ SceneObject::SceneObject(QObject *parent)
} }
SceneObject *SceneObject::getParent()
{
return parent;
}
SceneObject *SceneObject::children(int /* number*/)
{
return NULL;
}
int SceneObject::childCount() const
{
return 0;
}
int SceneObject::childNumber() const
{
if (parent && parent->isNode()){
SceneNode* node = static_cast<SceneNode*>(parent);
node->getChildren().indexOf(const_cast<SceneObject*>(this));
}
return 0;
}
int SceneObject::columnCount() const
{
return 1+itemData.count();
}
QVariant SceneObject::data(int column) const
{
//qDebug()<<"Data "<<column<<"="<<name;
if(column == 0) return name;
return itemData.value(column);
}
bool SceneObject::setData(int column, const QVariant &value)
{
if (column < 0 || column >= itemData.size())
return false;
itemData[column] = value;
return true;
}
int SceneObject::getID(){return id;} int SceneObject::getID(){return id;}
QString SceneObject::getName(){return name;} QString SceneObject::getName(){return name;}
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <QObject> #include <QObject>
#include <QQuaternion> #include <QQuaternion>
#include <QVector3D> #include <QVector3D>
#include <QVector>
#include <QtOpenGL> #include <QtOpenGL>
#include <gl/GLU.h> #include <gl/GLU.h>
...@@ -17,13 +18,30 @@ protected: ...@@ -17,13 +18,30 @@ protected:
QString name; QString name;
void applyTransformation(); void applyTransformation();
QVector<QVariant> itemData;
SceneObject *parent;
public: public:
SceneObject(QObject *parent = 0); SceneObject();
void setParent(SceneObject *parent){this->parent = parent;}
SceneObject *getParent();
virtual SceneObject *children(int number);
virtual bool isNode(){return false;}
int childNumber() const;
virtual int childCount() const;
int columnCount() const;
QVariant data(int column) const;
bool setData(int column, const QVariant &value);
virtual void draw(); virtual void draw();
virtual SceneObject *find(int id); virtual SceneObject *find(int id);
int getID(); int getID();
QString getName(); QString getName();
void setName(QString name){this->name = name;}
void move(QVector3D dir); void move(QVector3D dir);
void rotate(QQuaternion rot); void rotate(QQuaternion rot);
......
...@@ -9,8 +9,8 @@ int ScenePrimitive::torusCount = 1; ...@@ -9,8 +9,8 @@ int ScenePrimitive::torusCount = 1;
int ScenePrimitive::coneCount = 1; int ScenePrimitive::coneCount = 1;
ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *parent) ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation)
:SceneObject(parent) :SceneObject()
{ {
this->type = type; this->type = type;
this->tesselation = tesselation; this->tesselation = tesselation;
...@@ -36,7 +36,6 @@ ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *par ...@@ -36,7 +36,6 @@ ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *par
break; break;
case Cylinder: case Cylinder:
name = QString("Cylinder %1").arg(ScenePrimitive::cylinderCount); name = QString("Cylinder %1").arg(ScenePrimitive::cylinderCount);
qDebug()<<ScenePrimitive::cylinderCount;
ScenePrimitive::cylinderCount++; ScenePrimitive::cylinderCount++;
this->tesselation = 5*pow(2,tesselation); this->tesselation = 5*pow(2,tesselation);
break; break;
...@@ -54,13 +53,13 @@ ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *par ...@@ -54,13 +53,13 @@ ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *par
qDebug()<<"Enum Error"; qDebug()<<"Enum Error";
break; break;
} }
// qDebug()<<"Tesselation"<<this->tesselation<<getName(); // qDebug()<<"Tesselation"<<this->tesselation<<getName();
} }
void ScenePrimitive::draw(){ void ScenePrimitive::draw(){
glPushMatrix(); glPushMatrix();
applyTransformation(); applyTransformation();
// qDebug()<<this->getName()<<"Matrial"<<*color<<"Trans"<<translation<<"Rot"<<rotation;
glMaterialfv(GL_FRONT,GL_AMBIENT,color); glMaterialfv(GL_FRONT,GL_AMBIENT,color);
GLfloat white[] = {1.0,1.0,1.0}; GLfloat white[] = {1.0,1.0,1.0};
glMaterialfv(GL_FRONT,GL_DIFFUSE,color); glMaterialfv(GL_FRONT,GL_DIFFUSE,color);
......
...@@ -28,8 +28,9 @@ public: ...@@ -28,8 +28,9 @@ public:
void draw(); void draw();
void setMaterial(float *color); void setMaterial(float *color);
ScenePrimitive(PrimitiveType type, int tesselation, QObject *parent); ScenePrimitive(PrimitiveType type, int tesselation);
}; };
#endif // SCENEPRIMITIVE_H #endif // SCENEPRIMITIVE_H
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