Commit e334b7ab by Alisa Jung

So. at least this is running without new bugs.

parent 11a73823
#include "controller.h"
#include "myglwidget.h"
#include "scenegraph.h"
#include "primitive.h"
Controller::Controller(QStatusBar* bar)
{
......@@ -254,7 +255,7 @@ void Controller::deletePrimitive(){
void Controller::selectTransform(RigidBodyTransformation *rbt){
currentTransform = rbt;
if (currentTransform){
statusBar->showMessage(currentTransform->getChild()->getName());
statusBar->showMessage(currentTransform->getChildPrimitive()->getName());
}
else {
statusBar->showMessage("None selected");
......
......@@ -16,6 +16,7 @@
#include <QQuaternion>
#include <QGridLayout>
#include <rigidbodytransformation.h>
#include <QStatusBar>
#include <math.h>
......
......@@ -21,7 +21,9 @@ SOURCES += main.cpp\
scenegraph.cpp \
primitive.cpp \
rigidbodytransformation.cpp \
controller.cpp
controller.cpp \
myitemmodel.cpp \
treeitem.cpp
HEADERS += mainwindow.h \
myglwidget.h \
......@@ -29,7 +31,9 @@ HEADERS += mainwindow.h \
primitive.h \
rigidbodytransformation.h \
controller.h \
glut.h
glut.h \
myitemmodel.h \
treeitem.h
RESOURCES += \
helloqube.qrc
......
<?xml version="1.0" encoding="UTF-8"?>
<!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>
<data>
<variable>EnvironmentId</variable>
......
#include "myglwidget.h"
#include "controller.h"
#include "scenegraph.h"
#include "primitive.h""
//QGLShaderProgram *MyGLWidget::phongShader;
......@@ -169,7 +170,7 @@ void MyGLWidget::paintGL(){
glMultMatrixf(m.data());
//draw primitive
Primitive* p = (*i)->getChild();
Primitive* p = (*i)->getChildPrimitive();
int tesselation = p->getTesselation();
Primitive::Type type = p->getType();
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 "rigidbodytransformation.h"
Primitive::Primitive()
{
......
......@@ -2,8 +2,11 @@
#define PRIMITIVE_H
#include <QtOpenGL>
#include "treeitem.h"
class Primitive
class RigidBodyTransformation;
class Primitive : public TreeItem
{
public:
......
#include "rigidbodytransformation.h"
#include "primitive.h"
RigidBodyTransformation::RigidBodyTransformation(Primitive* child)
{
translation = QVector3D(0,0,0);
rotation = QQuaternion();
this->child = child;
// this->child = child;
children.append(child);
// qDebug() << "new rbt " << tx << "," << ty << "," << tz << ", rot " << rotation;
}
RigidBodyTransformation::~RigidBodyTransformation(){
child->~Primitive();
//apparently I do not need to call the baseclass destructor.
}
......@@ -34,6 +37,9 @@ void RigidBodyTransformation::setRotation(QQuaternion newRotation){
rotation = newRotation;
}
Primitive* RigidBodyTransformation::getChild(){
return child;
Primitive* RigidBodyTransformation::getChildPrimitive(){
if (children.length() > 0){
return static_cast<Primitive*>(children[0]);//TODO aufpassen falls höhere tiefe
}
qDebug("WAAAH");
}
......@@ -2,9 +2,11 @@
#define RIGIDBODYTRANSFORMATION_H
#include <QQuaternion>
#include <primitive.h>
#include <QDebug>
#include "treeitem.h"
class Primitive;
class RigidBodyTransformation
class RigidBodyTransformation : public TreeItem
{
public:
RigidBodyTransformation(Primitive* child);
......@@ -16,7 +18,7 @@ public:
const QQuaternion getRotation();
const QVector3D getTranslation();
Primitive* getChild();
Primitive* getChildPrimitive();
void drawChild();
......@@ -27,7 +29,7 @@ private :
QQuaternion rotation;
//child in scene graph
Primitive* child;
Primitive* childPrimitive;
};
#endif // RIGIDBODYTRANSFORMATION_H
#include "scenegraph.h"
#include "myglwidget.h"
#include "primitive.h"
SceneGraph::SceneGraph()
{
......
......@@ -3,6 +3,7 @@
#include <QList>
#include <rigidbodytransformation.h>
#include <QString>
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