Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
grapa_alisa
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Alisa Jung
grapa_alisa
Commits
154e4e6c
Commit
154e4e6c
authored
Nov 21, 2015
by
Alisa Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added sphere
parent
6d919e3a
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
196 additions
and
6 deletions
+196
-6
controller.cpp
helloqube/controller.cpp
+15
-0
controller.h
helloqube/controller.h
+4
-0
helloqube.pro
helloqube/helloqube.pro
+4
-2
helloqube.pro.gl3840
helloqube/helloqube.pro.gl3840
+39
-0
helloqube.pro.user
helloqube/helloqube.pro.user
+1
-1
mainwindow.cpp
helloqube/mainwindow.cpp
+25
-1
mainwindow.h
helloqube/mainwindow.h
+4
-0
scenegraph.cpp
helloqube/scenegraph.cpp
+36
-2
scenegraph.h
helloqube/scenegraph.h
+23
-0
sphere.cpp
helloqube/sphere.cpp
+30
-0
sphere.h
helloqube/sphere.h
+15
-0
No files found.
helloqube/controller.cpp
View file @
154e4e6c
...
@@ -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
);
}
helloqube/controller.h
View file @
154e4e6c
...
@@ -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
();
};
};
...
...
helloqube/helloqube.pro
View file @
154e4e6c
...
@@ -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
...
...
helloqube/helloqube.pro.gl3840
0 → 100644
View file @
154e4e6c
#-------------------------------------------------
#
# 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
helloqube/helloqube.pro.user
View file @
154e4e6c
<?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>
...
...
helloqube/mainwindow.cpp
View file @
154e4e6c
...
@@ -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
()));
}
}
...
...
helloqube/mainwindow.h
View file @
154e4e6c
...
@@ -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
(
)
;
...
...
helloqube/scenegraph.cpp
View file @
154e4e6c
...
@@ -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
;
...
...
helloqube/scenegraph.h
View file @
154e4e6c
...
@@ -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
;
...
...
helloqube/sphere.cpp
0 → 100644
View file @
154e4e6c
#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
();
}
helloqube/sphere.h
0 → 100644
View file @
154e4e6c
#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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment