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
06b6dd64
Commit
06b6dd64
authored
Nov 19, 2015
by
Alisa Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
successfully and against all odds added RigidBodyTransformation, Primitive and Box.
parent
58478b68
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
128 deletions
+37
-128
helloqube.pro.user
helloqube/helloqube.pro.user
+1
-1
myglwidget.cpp
helloqube/myglwidget.cpp
+12
-123
myglwidget.h
helloqube/myglwidget.h
+7
-0
rigidbodytransformation.cpp
helloqube/rigidbodytransformation.cpp
+13
-2
rigidbodytransformation.h
helloqube/rigidbodytransformation.h
+4
-2
No files found.
helloqube/helloqube.pro.user
View file @
06b6dd64
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2015-11-19T23:
00:19
. -->
<!-- Written by QtCreator 3.5.1, 2015-11-19T23:
28:44
. -->
<qtcreator>
<data>
<variable>
EnvironmentId
</variable>
...
...
helloqube/myglwidget.cpp
View file @
06b6dd64
...
...
@@ -20,6 +20,10 @@ MyGLWidget::MyGLWidget(int index, Controller* c, bool isPerspective, QQuaternion
controller
=
c
;
this
->
isPerspective
=
isPerspective
;
this
->
isFocused
=
isPerspective
;
//start with focus on perspective view
platzhalter
=
"bla"
;
primitive
=
new
Box
(
0
,
platzhalter
,
1
);
rbt
=
new
RigidBodyTransformation
(
primitive
);
}
MyGLWidget
::~
MyGLWidget
()
...
...
@@ -146,126 +150,7 @@ void MyGLWidget::paintGL(){
glMultMatrixf
(
camRot
.
data
());
glTranslatef
(
camRotCenter
.
x
(),
camRotCenter
.
y
(),
camRotCenter
.
z
());
//for cube rotation
QMatrix4x4
m
=
QMatrix4x4
();
m
.
rotate
(
qubeRotation
);
//for cube translation
QMatrix4x4
translateRot1
=
QMatrix4x4
(
1
,
0
,
0
,
cubeTranslation
.
x
(),
0
,
1
,
0
,
cubeTranslation
.
y
(),
0
,
0
,
1
,
cubeTranslation
.
z
(),
0
,
0
,
0
,
1
);
//stack matrices
glMultMatrixf
(
translateRot1
.
data
());
//Punkte zurück schieben damit rotation um qube zentrum ist
glMultMatrixf
(
m
.
data
());
//tesselation
double
qubeWidth
=
1.0
;
double
dist
=
qubeWidth
/
(
double
)
tesselation
;
//4.1.1 Unit Qube + Tesselation + Diffuse Material
{
GLfloat
specularColor
[]
=
{
1
,
1
,
1
};
GLfloat
shininess
[]
=
{
128
};
//specular exponent
glMaterialfv
(
GL_FRONT
,
GL_SPECULAR
,
specularColor
);
glMaterialfv
(
GL_FRONT
,
GL_SHININESS
,
shininess
);
//vorne // z-Achse
// glColor3f(0,0,1);//blau //alt und doof
GLfloat
blue
[]
=
{
0
,
0
,
1
};
glMaterialfv
(
GL_FRONT
,
GL_DIFFUSE
,
blue
);
glNormal3f
(
0
,
0
,
1
);
glBegin
(
GL_QUADS
);
for
(
int
i
=
0
;
i
<
tesselation
;
i
++
){
for
(
int
j
=
0
;
j
<
tesselation
;
j
++
){
glVertex3f
(
0.5
-
dist
*
i
,
0.5
-
dist
*
j
,
0.5
);
glVertex3f
(
0.5
-
dist
*
(
i
+
1
),
0.5
-
dist
*
j
,
0.5
);
glVertex3f
(
0.5
-
dist
*
(
i
+
1
),
0.5
-
dist
*
(
j
+
1
),
0.5
);
glVertex3f
(
0.5
-
dist
*
i
,
0.5
-
dist
*
(
j
+
1
),
0.5
);
}
}
glEnd
();
//oben // y-Achse
GLfloat
green
[]
=
{
0
,
1
,
0
};
glMaterialfv
(
GL_FRONT
,
GL_DIFFUSE
,
green
);
glNormal3f
(
0
,
1
,
0
);
glBegin
(
GL_QUADS
);
for
(
int
i
=
0
;
i
<
tesselation
;
i
++
){
for
(
int
j
=
0
;
j
<
tesselation
;
j
++
){
glVertex3f
(
0.5
-
dist
*
(
i
+
1
),
0.5
,
0.5
-
dist
*
(
j
+
1
));
glVertex3f
(
0.5
-
dist
*
(
i
+
1
),
0.5
,
0.5
-
dist
*
j
);
glVertex3f
(
0.5
-
dist
*
i
,
0.5
,
0.5
-
dist
*
j
);
glVertex3f
(
0.5
-
dist
*
i
,
0.5
,
0.5
-
dist
*
(
j
+
1
));
}
}
glEnd
();
//rechts //x-Achse
GLfloat
red
[]
=
{
1
,
0
,
0
};
glMaterialfv
(
GL_FRONT
,
GL_DIFFUSE
,
red
);
glNormal3f
(
1
,
0
,
0
);
glBegin
(
GL_QUADS
);
for
(
int
i
=
0
;
i
<
tesselation
;
i
++
){
for
(
int
j
=
0
;
j
<
tesselation
;
j
++
){
glVertex3f
(
0.5
,
0.5
-
dist
*
i
,
0.5
-
dist
*
j
);
glVertex3f
(
0.5
,
0.5
-
dist
*
(
i
+
1
),
0.5
-
dist
*
j
);
glVertex3f
(
0.5
,
0.5
-
dist
*
(
i
+
1
),
0.5
-
dist
*
(
j
+
1
));
glVertex3f
(
0.5
,
0.5
-
dist
*
i
,
0.5
-
dist
*
(
j
+
1
));
}
}
glEnd
();
//hinten // z-Achse
GLfloat
yellow
[]
=
{
1
,
0.9
f
,
0
};
glMaterialfv
(
GL_FRONT
,
GL_DIFFUSE
,
yellow
);
glNormal3f
(
0
,
0
,
-
1
);
glBegin
(
GL_QUADS
);
for
(
int
i
=
0
;
i
<
tesselation
;
i
++
){
for
(
int
j
=
0
;
j
<
tesselation
;
j
++
){
glVertex3f
(
0.5
-
dist
*
i
,
0.5
-
dist
*
(
j
+
1
),
-
0.5
);
//4
glVertex3f
(
0.5
-
dist
*
(
i
+
1
),
0.5
-
dist
*
(
j
+
1
),
-
0.5
);
//3
glVertex3f
(
0.5
-
dist
*
(
i
+
1
),
0.5
-
dist
*
j
,
-
0.5
);
//2
glVertex3f
(
0.5
-
dist
*
i
,
0.5
-
dist
*
j
,
-
0.5
);
//1
}
}
glEnd
();
//links
GLfloat
cyan
[]
=
{
0
,
1
,
1
};
glMaterialfv
(
GL_FRONT
,
GL_DIFFUSE
,
cyan
);
glNormal3f
(
-
1
,
0
,
0
);
glBegin
(
GL_QUADS
);
for
(
int
i
=
0
;
i
<
tesselation
;
i
++
){
for
(
int
j
=
0
;
j
<
tesselation
;
j
++
){
glVertex3f
(
-
0.5
,
0.5
-
dist
*
i
,
0.5
-
dist
*
(
j
+
1
));
glVertex3f
(
-
0.5
,
0.5
-
dist
*
(
i
+
1
),
0.5
-
dist
*
(
j
+
1
));
glVertex3f
(
-
0.5
,
0.5
-
dist
*
(
i
+
1
),
0.5
-
dist
*
j
);
glVertex3f
(
-
0.5
,
0.5
-
dist
*
i
,
0.5
-
dist
*
j
);
}
}
glEnd
();
//unten //-y
GLfloat
magenta
[]
=
{
1
,
0
,
1
};
glMaterialfv
(
GL_FRONT
,
GL_DIFFUSE
,
magenta
);
glNormal3f
(
0
,
-
1
,
0
);
glBegin
(
GL_QUADS
);
for
(
int
i
=
0
;
i
<
tesselation
;
i
++
){
for
(
int
j
=
0
;
j
<
tesselation
;
j
++
){
glVertex3f
(
0.5
-
dist
*
i
,
-
0.5
,
0.5
-
dist
*
(
j
+
1
));
glVertex3f
(
0.5
-
dist
*
i
,
-
0.5
,
0.5
-
dist
*
j
);
glVertex3f
(
0.5
-
dist
*
(
i
+
1
),
-
0.5
,
0.5
-
dist
*
j
);
glVertex3f
(
0.5
-
dist
*
(
i
+
1
),
-
0.5
,
0.5
-
dist
*
(
j
+
1
));
}
}
glEnd
();
}
rbt
->
drawChild
();
//has to be down here or will be overpainted by above code
if
(
isFocused
)
highlightViewport
();
...
...
@@ -360,7 +245,8 @@ void MyGLWidget::translateCamera(double xDiff, double yDiff, double zDiff)
}
void
MyGLWidget
::
translateQube
(
double
xDiff
,
double
yDiff
){
cubeTranslation
+=
cameraRotation
.
conjugate
().
rotatedVector
(
QVector3D
(
xDiff
,
yDiff
,
0
));
// cubeTranslation += cameraRotation.conjugate().rotatedVector(QVector3D(xDiff, yDiff,0));
rbt
->
addTranslation
(
cameraRotation
.
conjugate
().
rotatedVector
(
QVector3D
(
xDiff
,
yDiff
,
0
)));
updateGL
();
}
...
...
@@ -373,8 +259,11 @@ void MyGLWidget::rotateQube(QQuaternion diff){
* in which q′ corresponds to the rotation q1 followed by the rotation q2.
* (Note that quaternion multiplication is not commutative.)
*/
qubeRotation
=
diff
*
qubeRotation
;
qubeRotation
.
normalize
();
rbt
->
addRotation
(
diff
);
// qubeRotation = diff*qubeRotation;
// qubeRotation.normalize();
updateGL
();
...
...
helloqube/myglwidget.h
View file @
06b6dd64
...
...
@@ -14,6 +14,9 @@
#include <QStyleOption>
#include <QStylePainter>
#include <rigidbodytransformation.h>//vorläufig, bis szenengraph steht.
#include <box.h>
class
Controller
;
...
...
@@ -83,6 +86,10 @@ private:
//Phong Shader
QGLShaderProgram
*
phongShader
;
RigidBodyTransformation
*
rbt
;
Primitive
*
primitive
;
char
*
platzhalter
;
void
highlightViewport
();
void
resetProjectionMatrix
();
...
...
helloqube/rigidbodytransformation.cpp
View file @
06b6dd64
#include "rigidbodytransformation.h"
RigidBodyTransformation
::
RigidBodyTransformation
(
Primitive
child
)
RigidBodyTransformation
::
RigidBodyTransformation
(
Primitive
*
child
)
{
tx
=
0
;
ty
=
0
;
...
...
@@ -15,10 +15,21 @@ void RigidBodyTransformation::setTranslation(double x, double y, double z){
tz
=
z
;
}
void
RigidBodyTransformation
::
addTranslation
(
QVector3D
diff
){
tx
+=
diff
.
x
();
ty
+=
diff
.
y
();
tz
+=
diff
.
z
();
}
QQuaternion
RigidBodyTransformation
::
getRotation
(){
return
rotation
;
}
void
RigidBodyTransformation
::
addRotation
(
QQuaternion
diff
){
rotation
=
diff
*
rotation
;
rotation
.
normalize
();
}
void
RigidBodyTransformation
::
setRotation
(
QQuaternion
newRotation
){
rotation
=
newRotation
;
}
...
...
@@ -40,5 +51,5 @@ void RigidBodyTransformation::drawChild(){
//maybe a foreach later on?
child
.
drawPrimitive
();
child
->
drawPrimitive
();
}
helloqube/rigidbodytransformation.h
View file @
06b6dd64
...
...
@@ -7,10 +7,12 @@
class
RigidBodyTransformation
{
public
:
RigidBodyTransformation
(
Primitive
child
);
RigidBodyTransformation
(
Primitive
*
child
);
void
setTranslation
(
double
x
,
double
y
,
double
z
);
void
addTranslation
(
QVector3D
diff
);
void
setRotation
(
QQuaternion
newRotation
);
void
addRotation
(
QQuaternion
diff
);
QQuaternion
getRotation
();
void
drawChild
();
...
...
@@ -22,7 +24,7 @@ private :
QQuaternion
rotation
;
//child in scene graph
Primitive
child
;
Primitive
*
child
;
};
#endif // RIGIDBODYTRANSFORMATION_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