Commit b9e72246 by Kai Westerkamp

scene Graph update

active Objects
parent 640cd99a
...@@ -104,7 +104,7 @@ void Controler::move(QPointF * newPos){ ...@@ -104,7 +104,7 @@ void Controler::move(QPointF * newPos){
if((viewMode == CAMERA) ^ ctrlPressed){ if((viewMode == CAMERA) ^ ctrlPressed){
activeView->getCamera()->move(QVector3D(dx,dy,0.0)); activeView->getCamera()->move(QVector3D(dx,dy,0.0));
} else if((viewMode == EDIT) ^ ctrlPressed){ } else if((viewMode == EDIT) ^ ctrlPressed){
scene->move(0,activeView->getCamera()->rotation->rotatedVector(QVector3D(dx,dy,0.0))); scene->moveActive(activeView->getCamera()->rotation->rotatedVector(QVector3D(dx,dy,0.0)));
} else{ } else{
qDebug()<<"möp"<<viewMode<<" "<<CAMERA<<" "<<EDIT; qDebug()<<"möp"<<viewMode<<" "<<CAMERA<<" "<<EDIT;
} }
......
...@@ -60,6 +60,12 @@ void GLView::home(){ ...@@ -60,6 +60,12 @@ void GLView::home(){
void GLView::paintGL () void GLView::paintGL ()
{ {
// QGLFramebufferObjectFormat format;
// format.setSamples();
// format.setAttachment(QGLFramebufferObject::);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0,0,this->width(),this->height()); glViewport(0,0,this->width(),this->height());
......
...@@ -16,7 +16,10 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -16,7 +16,10 @@ MainWindow::MainWindow(QWidget *parent)
//Views //Views
scene = new Scene(); scene = new Scene();
connect(scene,SIGNAL(activChanged()),this,SLOT(updateStatusBar()));
scene->simpleScene(); scene->simpleScene();
controler = new Controler(this,scene); controler = new Controler(this,scene);
Camera *perspectiveCam = new Camera(true); Camera *perspectiveCam = new Camera(true);
...@@ -150,10 +153,13 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -150,10 +153,13 @@ MainWindow::MainWindow(QWidget *parent)
addToolBar( toolBar); addToolBar( toolBar);
statusBar->showMessage("Hello");
setStatusBar(statusBar); setStatusBar(statusBar);
}
void MainWindow::updateStatusBar()
{
statusBar->showMessage(scene->getActive()->getName());
} }
void MainWindow::showSingle(){ void MainWindow::showSingle(){
......
...@@ -65,6 +65,7 @@ public: ...@@ -65,6 +65,7 @@ public:
void updateGL(); void updateGL();
public slots: public slots:
void updateStatusBar();
void showAboutBox(); void showAboutBox();
void showSingle(); void showSingle();
void showDual(); void showDual();
......
#include "scene.h" #include "scene.h"
Scene::Scene()
Scene::Scene( )
{ {
root = new SceneNode(this); root = new SceneNode(this);
} }
void Scene::simpleScene() int Scene::simpleScene()
{ {
float red[] = {1.0,0.0,0.0}; float red[] = {1.0,0.0,0.0};
...@@ -35,29 +37,45 @@ void Scene::simpleScene() ...@@ -35,29 +37,45 @@ void Scene::simpleScene()
torus->setMaterial(magenta); torus->setMaterial(magenta);
root->add(torus); root->add(torus);
active = cylinder;
emit activChanged();
return cylinder->getID();
} }
SceneObject *Scene::setActive(int id){
active = root->find(id);
emit activChanged();
return active;
}
SceneObject *Scene::getActive(){
return active;
}
void Scene::draw() void Scene::draw()
{ {
root->draw(); root->draw();
} }
SceneObject *Scene::getRoot() SceneNode *Scene::getRoot()
{ {
return root; return root;
} }
void Scene::move(int id, QVector3D dir) void Scene::moveActive(QVector3D dir)
{ {
if(active != NULL)
active->move(dir);
} }
void Scene::rotate(int id, QQuaternion rot) void Scene::rotateActive(QQuaternion rot)
{ {
if(active != NULL)
active->rotate(rot);
} }
...@@ -17,16 +17,24 @@ public: ...@@ -17,16 +17,24 @@ public:
Scene(); Scene();
void draw(); void draw();
void simpleScene(); int simpleScene();
void move(int id, QVector3D dir); void moveActive(QVector3D dir);
void rotate(int id, QQuaternion rot); void rotateActive(QQuaternion rot);
SceneObject *getActive();
SceneObject *setActive(int id);
signals:
void activChanged();
private: private:
SceneNode *root; SceneNode *root;
SceneObject *active;
SceneObject *getRoot(); SceneNode *getRoot();
}; };
......
...@@ -13,6 +13,18 @@ void SceneNode::add(SceneObject *child) ...@@ -13,6 +13,18 @@ void SceneNode::add(SceneObject *child)
childs.append(child); childs.append(child);
} }
SceneObject *SceneNode::find(int id)
{
foreach (SceneObject *obj, childs) {
SceneObject *temp = obj->find(id);
if(temp != NULL)
return temp;
}
return NULL;
}
void SceneNode::draw() void SceneNode::draw()
{ {
......
...@@ -12,6 +12,7 @@ private: ...@@ -12,6 +12,7 @@ private:
public: public:
SceneNode(QObject *parent); SceneNode(QObject *parent);
SceneObject *find(int id);
void draw(); void draw();
void add(SceneObject *child); void add(SceneObject *child);
}; };
......
...@@ -4,15 +4,16 @@ SceneObject::SceneObject(QObject *parent) ...@@ -4,15 +4,16 @@ SceneObject::SceneObject(QObject *parent)
:QObject(parent) :QObject(parent)
{ {
id = 3; id = 3;
name = QString("Scene Object "+id);
rotation = QQuaternion(); rotation = QQuaternion();
translation = QVector3D(); translation = QVector3D();
} }
int SceneObject::getID() int SceneObject::getID(){return id;}
{
return id; QString SceneObject::getName(){return name;}
}
void SceneObject::move(QVector3D dir) void SceneObject::move(QVector3D dir)
{ {
...@@ -25,6 +26,16 @@ void SceneObject::rotate(QQuaternion rot) ...@@ -25,6 +26,16 @@ void SceneObject::rotate(QQuaternion rot)
void SceneObject::draw(){qDebug()<<"Drawing abstract Scene Element";} void SceneObject::draw(){qDebug()<<"Drawing abstract Scene Element";}
SceneObject *SceneObject::find(int id)
{
if(this->id == id){
return this;
} else{
return NULL;
}
}
void SceneObject::applyTransformation() void SceneObject::applyTransformation()
{ {
......
...@@ -21,7 +21,9 @@ public: ...@@ -21,7 +21,9 @@ public:
SceneObject(QObject *parent = 0); SceneObject(QObject *parent = 0);
virtual void draw(); virtual void draw();
virtual SceneObject *find(int id);
int getID(); int getID();
QString getName();
void move(QVector3D dir); void move(QVector3D dir);
void rotate(QQuaternion rot); void rotate(QQuaternion rot);
......
#include "sceneprimitive.h" #include "sceneprimitive.h"
#include "algorithm" #include "algorithm"
int ScenePrimitive::quaderCount = 1;
int ScenePrimitive::sphereCount = 1;
int ScenePrimitive::cylinderCount = 1;
int ScenePrimitive::torusCount = 1;
ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *parent) ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *parent)
:SceneObject(parent) :SceneObject(parent)
{ {
...@@ -14,6 +21,30 @@ ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *par ...@@ -14,6 +21,30 @@ ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation, QObject *par
this->color[0] = 0.0; this->color[0] = 0.0;
this->color[1] = 0.0; this->color[1] = 0.0;
this->color[2] = 0.0; this->color[2] = 0.0;
switch (this->type) {
case Quader:
name = QString("Quader %1").arg(ScenePrimitive::quaderCount);
ScenePrimitive::quaderCount++;
break;
case Sphere:
name = QString("Sphere %1").arg(ScenePrimitive::sphereCount);
ScenePrimitive::sphereCount++;
break;
case Cylinder:
name = QString("Cylinder %1").arg(ScenePrimitive::cylinderCount);
qDebug()<<ScenePrimitive::cylinderCount;
ScenePrimitive::cylinderCount++;
break;
case Torus:
name = QString("Torus %1").arg(ScenePrimitive::torusCount);
ScenePrimitive::torusCount++;
break;
default:
qDebug()<<"Enum Error";
break;
}
} }
void ScenePrimitive::draw(){ void ScenePrimitive::draw(){
......
...@@ -9,6 +9,11 @@ class ScenePrimitive : public SceneObject ...@@ -9,6 +9,11 @@ class ScenePrimitive : public SceneObject
{ {
Q_OBJECT Q_OBJECT
private: private:
static int quaderCount;
static int sphereCount;
static int cylinderCount ;
static int torusCount;
PrimitiveType type; PrimitiveType type;
int tesselation; int tesselation;
GLUquadric *qobj; GLUquadric *qobj;
...@@ -17,6 +22,8 @@ private: ...@@ -17,6 +22,8 @@ private:
void drawCube(int tesselation); void drawCube(int tesselation);
public: public:
void draw(); void draw();
void setMaterial(float *color); void setMaterial(float *color);
......
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