Commit b9e72246 by Kai Westerkamp

scene Graph update

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