Commit e334b7ab by Alisa Jung

So. at least this is running without new bugs.

parent 11a73823
#include "controller.h" #include "controller.h"
#include "myglwidget.h" #include "myglwidget.h"
#include "scenegraph.h" #include "scenegraph.h"
#include "primitive.h"
Controller::Controller(QStatusBar* bar) Controller::Controller(QStatusBar* bar)
{ {
...@@ -254,7 +255,7 @@ void Controller::deletePrimitive(){ ...@@ -254,7 +255,7 @@ void Controller::deletePrimitive(){
void Controller::selectTransform(RigidBodyTransformation *rbt){ void Controller::selectTransform(RigidBodyTransformation *rbt){
currentTransform = rbt; currentTransform = rbt;
if (currentTransform){ if (currentTransform){
statusBar->showMessage(currentTransform->getChild()->getName()); statusBar->showMessage(currentTransform->getChildPrimitive()->getName());
} }
else { else {
statusBar->showMessage("None selected"); statusBar->showMessage("None selected");
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <QQuaternion> #include <QQuaternion>
#include <QGridLayout> #include <QGridLayout>
#include <rigidbodytransformation.h> #include <rigidbodytransformation.h>
#include <QStatusBar>
#include <math.h> #include <math.h>
......
...@@ -21,7 +21,9 @@ SOURCES += main.cpp\ ...@@ -21,7 +21,9 @@ SOURCES += main.cpp\
scenegraph.cpp \ scenegraph.cpp \
primitive.cpp \ primitive.cpp \
rigidbodytransformation.cpp \ rigidbodytransformation.cpp \
controller.cpp controller.cpp \
myitemmodel.cpp \
treeitem.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
myglwidget.h \ myglwidget.h \
...@@ -29,7 +31,9 @@ HEADERS += mainwindow.h \ ...@@ -29,7 +31,9 @@ HEADERS += mainwindow.h \
primitive.h \ primitive.h \
rigidbodytransformation.h \ rigidbodytransformation.h \
controller.h \ controller.h \
glut.h glut.h \
myitemmodel.h \
treeitem.h
RESOURCES += \ RESOURCES += \
helloqube.qrc helloqube.qrc
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2015-11-21T21:18:46. --> <!-- Written by QtCreator 3.5.1, 2015-11-22T14:19:27. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
......
#include "myglwidget.h" #include "myglwidget.h"
#include "controller.h" #include "controller.h"
#include "scenegraph.h" #include "scenegraph.h"
#include "primitive.h""
//QGLShaderProgram *MyGLWidget::phongShader; //QGLShaderProgram *MyGLWidget::phongShader;
...@@ -169,7 +170,7 @@ void MyGLWidget::paintGL(){ ...@@ -169,7 +170,7 @@ void MyGLWidget::paintGL(){
glMultMatrixf(m.data()); glMultMatrixf(m.data());
//draw primitive //draw primitive
Primitive* p = (*i)->getChild(); Primitive* p = (*i)->getChildPrimitive();
int tesselation = p->getTesselation(); int tesselation = p->getTesselation();
Primitive::Type type = p->getType(); Primitive::Type type = p->getType();
qDebug() << "draw type " << type; qDebug() << "draw type " << type;
......
#include "myitemmodel.h"
MyItemModel::MyItemModel()
{
}
#ifndef MYITEMMODEL_H
#define MYITEMMODEL_H
#include <QAbstractItemModel>
class MyItemModel : public QAbstractItemModel
{
public:
MyItemModel();
};
#endif // MYITEMMODEL_H
#include "primitive.h" #include "primitive.h"
#include "rigidbodytransformation.h"
Primitive::Primitive() Primitive::Primitive()
{ {
......
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
#define PRIMITIVE_H #define PRIMITIVE_H
#include <QtOpenGL> #include <QtOpenGL>
#include "treeitem.h"
class Primitive class RigidBodyTransformation;
class Primitive : public TreeItem
{ {
public: public:
......
#include "rigidbodytransformation.h" #include "rigidbodytransformation.h"
#include "primitive.h"
RigidBodyTransformation::RigidBodyTransformation(Primitive* child) RigidBodyTransformation::RigidBodyTransformation(Primitive* child)
{ {
translation = QVector3D(0,0,0); translation = QVector3D(0,0,0);
rotation = QQuaternion(); rotation = QQuaternion();
this->child = child; // this->child = child;
children.append(child);
// qDebug() << "new rbt " << tx << "," << ty << "," << tz << ", rot " << rotation; // qDebug() << "new rbt " << tx << "," << ty << "," << tz << ", rot " << rotation;
} }
RigidBodyTransformation::~RigidBodyTransformation(){ RigidBodyTransformation::~RigidBodyTransformation(){
child->~Primitive(); //apparently I do not need to call the baseclass destructor.
} }
...@@ -34,6 +37,9 @@ void RigidBodyTransformation::setRotation(QQuaternion newRotation){ ...@@ -34,6 +37,9 @@ void RigidBodyTransformation::setRotation(QQuaternion newRotation){
rotation = newRotation; rotation = newRotation;
} }
Primitive* RigidBodyTransformation::getChild(){ Primitive* RigidBodyTransformation::getChildPrimitive(){
return child; if (children.length() > 0){
return static_cast<Primitive*>(children[0]);//TODO aufpassen falls höhere tiefe
}
qDebug("WAAAH");
} }
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
#define RIGIDBODYTRANSFORMATION_H #define RIGIDBODYTRANSFORMATION_H
#include <QQuaternion> #include <QQuaternion>
#include <primitive.h> #include <QDebug>
#include "treeitem.h"
class Primitive;
class RigidBodyTransformation class RigidBodyTransformation : public TreeItem
{ {
public: public:
RigidBodyTransformation(Primitive* child); RigidBodyTransformation(Primitive* child);
...@@ -16,7 +18,7 @@ public: ...@@ -16,7 +18,7 @@ public:
const QQuaternion getRotation(); const QQuaternion getRotation();
const QVector3D getTranslation(); const QVector3D getTranslation();
Primitive* getChild(); Primitive* getChildPrimitive();
void drawChild(); void drawChild();
...@@ -27,7 +29,7 @@ private : ...@@ -27,7 +29,7 @@ private :
QQuaternion rotation; QQuaternion rotation;
//child in scene graph //child in scene graph
Primitive* child; Primitive* childPrimitive;
}; };
#endif // RIGIDBODYTRANSFORMATION_H #endif // RIGIDBODYTRANSFORMATION_H
#include "scenegraph.h" #include "scenegraph.h"
#include "myglwidget.h" #include "myglwidget.h"
#include "primitive.h"
SceneGraph::SceneGraph() SceneGraph::SceneGraph()
{ {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <QList> #include <QList>
#include <rigidbodytransformation.h> #include <rigidbodytransformation.h>
#include <QString>
class MyGLWidget; class MyGLWidget;
......
#include "treeitem.h"
TreeItem::TreeItem()
{
children = QList<TreeItem*>();
}
TreeItem::~TreeItem(){
while(children.length() > 0){
TreeItem* t = children[0];
children.removeAt(0);
t->~TreeItem();
}
}
void TreeItem::setParent(TreeItem *parent){
this->parent = parent;
}
TreeItem* TreeItem::getParent(){
return parent;
}
int TreeItem::getChildrenCount(){
return children.length();
}
//adds to child list AND sets itself as parent.
void TreeItem::addChild(TreeItem *item){
children.append(item);
item->setParent(this);
}
//removes from children list. Does NOT delet child.
bool TreeItem::removeChild(TreeItem *item){
return children.removeOne(item);
}
QList<TreeItem*> TreeItem::getChildren(){
return children;
}
TreeItem* TreeItem::getChild(int index){
if (index < children.length()){
return children[index];
}
return 0;
}
#ifndef TREEITEM_H
#define TREEITEM_H
#include <QList>
#include <QDebug>
class TreeItem
{
public:
TreeItem();
~TreeItem();
TreeItem* getParent();
QList<TreeItem*> getChildren();
TreeItem* getChild(int index);//return 0 if index too large
int getChildrenCount();
void addChild(TreeItem* item);
bool removeChild(TreeItem* item);
void setParent(TreeItem* parent);
protected:
TreeItem* parent;
QList<TreeItem*> children;
};
#endif // TREEITEM_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