Commit 154e4e6c by Alisa Jung

added sphere

parent 6d919e3a
...@@ -224,7 +224,22 @@ QQuaternion Controller::computeRotation(QPoint newPosition){ ...@@ -224,7 +224,22 @@ QQuaternion Controller::computeRotation(QPoint newPosition){
return q; return q;
} }
void Controller::addSphere(){
currentTransform = scene->addSphere(tesselation);
}
void Controller::addBox(){ void Controller::addBox(){
currentTransform = scene->addBox(tesselation); currentTransform = scene->addBox(tesselation);
} }
void Controller::addCylinder(){
currentTransform = scene->addCylinder(tesselation);
}
void Controller::addCone(){
currentTransform = scene->addCone(tesselation);
}
void Controller::addTorus(){
currentTransform = scene->addTorus(tesselation);
}
...@@ -81,7 +81,11 @@ public slots: ...@@ -81,7 +81,11 @@ public slots:
void setTessellation(int t); void setTessellation(int t);
void addSphere();
void addBox(); void addBox();
void addCylinder();
void addCone();
void addTorus();
}; };
......
...@@ -19,7 +19,8 @@ SOURCES += main.cpp\ ...@@ -19,7 +19,8 @@ SOURCES += main.cpp\
primitive.cpp \ primitive.cpp \
rigidbodytransformation.cpp \ rigidbodytransformation.cpp \
controller.cpp \ controller.cpp \
box.cpp box.cpp \
sphere.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
myglwidget.h \ myglwidget.h \
...@@ -27,7 +28,8 @@ HEADERS += mainwindow.h \ ...@@ -27,7 +28,8 @@ HEADERS += mainwindow.h \
primitive.h \ primitive.h \
rigidbodytransformation.h \ rigidbodytransformation.h \
controller.h \ controller.h \
box.h box.h \
sphere.h
RESOURCES += \ RESOURCES += \
helloqube.qrc helloqube.qrc
......
#-------------------------------------------------
#
# Project created by QtCreator 2015-10-31T11:34:59
#
#-------------------------------------------------
QT += core gui opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = helloqube
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
myglwidget.cpp \
scenegraph.cpp \
primitive.cpp \
rigidbodytransformation.cpp \
controller.cpp \
box.cpp \
sphere.cpp
HEADERS += mainwindow.h \
myglwidget.h \
scenegraph.h \
primitive.h \
rigidbodytransformation.h \
controller.h \
box.h \
sphere.h
RESOURCES += \
helloqube.qrc
DISTFILES += \
phong.vert \
phong.frag
<?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-19T23:28:44. --> <!-- Written by QtCreator 3.5.1, 2015-11-20T23:02:46. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
......
...@@ -205,12 +205,36 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -205,12 +205,36 @@ MainWindow::MainWindow(QWidget *parent)
//Assignment 2: 3) add boxes etc. //Assignment 2: 3) add boxes etc.
{ {
addSphere = new QAction("Add Sphere", toolBar);
addBox = new QAction("Add Box", toolBar); addBox = new QAction("Add Box", toolBar);
addCylinder = new QAction("Add Cylinder", toolBar);
addCone = new QAction("Add Cone", toolBar);
addTorus = new QAction("Add Torus", toolBar);
addSphere->setIcon(QIcon(":/grapa-a2-iconset/sphere.png"));
addBox->setIcon(QIcon(":/grapa-a2-iconset/box.png")); addBox->setIcon(QIcon(":/grapa-a2-iconset/box.png"));
addCylinder->setIcon(QIcon(":/grapa-a2-iconset/cylinder.png"));
addCone->setIcon(QIcon(":/grapa-a2-iconset/cone.png"));
addTorus->setIcon(QIcon(":/grapa-a2-iconset/torus.png"));
addSphere->setCheckable(false);
addBox->setCheckable(false); addBox->setCheckable(false);
addCylinder->setCheckable(false);
addCone->setCheckable(false);
addTorus->setCheckable(false);
toolBar->addAction(addSphere);
toolBar->insertSeparator(addSphere);
toolBar->addAction(addBox); toolBar->addAction(addBox);
toolBar->insertSeparator(addBox); toolBar->addAction(addCylinder);
toolBar->addAction(addCone);
toolBar->addAction(addTorus);
connect(addSphere, SIGNAL(triggered(bool)),controller, SLOT(addSphere()));
connect(addBox, SIGNAL(triggered(bool)),controller, SLOT(addBox())); connect(addBox, SIGNAL(triggered(bool)),controller, SLOT(addBox()));
connect(addCylinder, SIGNAL(triggered(bool)),controller, SLOT(addCylinder()));
connect(addCone, SIGNAL(triggered(bool)),controller, SLOT(addCone()));
connect(addTorus, SIGNAL(triggered(bool)),controller, SLOT(addTorus()));
} }
......
...@@ -79,7 +79,11 @@ private: ...@@ -79,7 +79,11 @@ private:
Controller* controller; Controller* controller;
QAction* addSphere;
QAction* addBox; QAction* addBox;
QAction* addCylinder;
QAction* addCone;
QAction* addTorus;
public slots : public slots :
void showAboutBox ( ) ; void showAboutBox ( ) ;
......
...@@ -6,20 +6,39 @@ SceneGraph::SceneGraph() ...@@ -6,20 +6,39 @@ SceneGraph::SceneGraph()
nodes = QList<RigidBodyTransformation*>(); nodes = QList<RigidBodyTransformation*>();
views = QList<MyGLWidget*>(); views = QList<MyGLWidget*>();
idCounter = 0; idCounter = 0;
sphereIndex = 1;
boxIndex = 1; boxIndex = 1;
nextBoxName = "Box 1"; cylIndex = 1;
coneIndex = 1;
torusIndex = 1;
} }
void SceneGraph::registerView(MyGLWidget* view){ void SceneGraph::registerView(MyGLWidget* view){
views.append(view); views.append(view);
} }
RigidBodyTransformation* SceneGraph::addSphere(int tesselation){
nextSphereName = "Sphere " + sphereIndex;
//tesselation < 3 makes no sense.
Sphere* s = new Sphere(idCounter, nextSphereName, tesselation+2);
idCounter++;
sphereIndex++;
qDebug() << "New Sphere added in scenegraph." << nextSphereName;
RigidBodyTransformation* r = new RigidBodyTransformation(s);
nodes.append(r);
notifyViews();
return r;
}
RigidBodyTransformation* SceneGraph::addBox(int tesselation){ RigidBodyTransformation* SceneGraph::addBox(int tesselation){
nextBoxName = "Box " + boxIndex;
Box* b = new Box(idCounter,nextBoxName,tesselation); Box* b = new Box(idCounter,nextBoxName,tesselation);
idCounter++; idCounter++;
boxIndex++; boxIndex++;
nextBoxName = "Box " + boxIndex;
qDebug("New box added in scenegraph"); qDebug("New box added in scenegraph");
...@@ -32,6 +51,21 @@ RigidBodyTransformation* SceneGraph::addBox(int tesselation){ ...@@ -32,6 +51,21 @@ RigidBodyTransformation* SceneGraph::addBox(int tesselation){
return r; return r;
} }
RigidBodyTransformation* SceneGraph::addCylinder(int tesselation){
qDebug("TODO add cylinder to scenegraph");
return addBox(1);
}
RigidBodyTransformation* SceneGraph::addCone(int tesselation){
qDebug("TODO add cone to scenegraph");
return addBox(tesselation);
}
RigidBodyTransformation* SceneGraph::addTorus(int tesselation){
qDebug("TODO add torus to scenegraph");
return addBox(1);
}
void SceneGraph::drawAll(){ void SceneGraph::drawAll(){
QList<RigidBodyTransformation*>::iterator i; QList<RigidBodyTransformation*>::iterator i;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <QList> #include <QList>
#include <rigidbodytransformation.h> #include <rigidbodytransformation.h>
#include <sphere.h>
#include <box.h> #include <box.h>
class MyGLWidget; class MyGLWidget;
...@@ -12,18 +13,40 @@ class SceneGraph ...@@ -12,18 +13,40 @@ class SceneGraph
public: public:
SceneGraph(); SceneGraph();
RigidBodyTransformation* addSphere(int tesselation);
RigidBodyTransformation* addBox(int tesselation); RigidBodyTransformation* addBox(int tesselation);
RigidBodyTransformation* addCylinder(int tesselation);
RigidBodyTransformation* addCone(int tesselation);
RigidBodyTransformation* addTorus(int tesselation);
void drawAll(); void drawAll();
void registerView(MyGLWidget* view); void registerView(MyGLWidget* view);
void notifyViews(); void notifyViews();
void addTranslation(RigidBodyTransformation* r, QVector3D diff); void addTranslation(RigidBodyTransformation* r, QVector3D diff);
void addRotation(RigidBodyTransformation* r, QQuaternion diff); void addRotation(RigidBodyTransformation* r, QQuaternion diff);
//Hallo. Todos:
//Log selected name in status bar
//add remaining primitive types
//extract draw method to something more view-like
//delete primitives
private: private:
int idCounter; int idCounter;
int sphereIndex;
int boxIndex; int boxIndex;
int cylIndex;
int coneIndex;
int torusIndex;
QString nextSphereName;
QString nextBoxName; QString nextBoxName;
QString nextCylName;
QString nextConeName;
QString nextTorusName;
QList<RigidBodyTransformation*> nodes; QList<RigidBodyTransformation*> nodes;
QList<MyGLWidget*> views; QList<MyGLWidget*> views;
......
#include "sphere.h"
#include <gl/GLU.h>
Sphere::Sphere(int ID, QString name, int tesselation) : Primitive(ID, name, tesselation)
{
qDebug() << "adding sphere " << ID;
}
Sphere::~Sphere(){
}
void Sphere::drawPrimitive(){
GLfloat specularColor[] = { 0.3, 0.5, 0.5 };
GLfloat shininess[] = { 120 };//specular exponent
glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor);
glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
GLfloat sphereColor[] = { 0, 0.8, 0.8 };
glMaterialfv(GL_FRONT, GL_DIFFUSE, sphereColor);
glNormal3f(0, 0, 1);
glBegin(GL_LINE_LOOP);
GLUquadric* q = gluNewQuadric();
// gluQuadricDrawStyle(q, GLU_FILL);
gluSphere(q, 0.5, tesselation, tesselation);
glEnd();
}
#ifndef SPHERE_H
#define SPHERE_H
#include <primitive.h>
#include <QDebug>
class Sphere : public Primitive
{
public:
Sphere(int ID, QString name, int tesselation);
~Sphere();
void drawPrimitive() override;
};
#endif // SPHERE_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