Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GraPa
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kai Westerkamp
GraPa
Commits
25092db6
Commit
25092db6
authored
Nov 02, 2015
by
Kai Westerkamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
addet translation
parent
026bab16
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
31 deletions
+37
-31
cubewidget.cpp
A1/hellocube/cubewidget.cpp
+30
-29
cubewidget.h
A1/hellocube/cubewidget.h
+7
-2
No files found.
A1/hellocube/cubewidget.cpp
View file @
25092db6
...
@@ -72,7 +72,7 @@ void CubeWidget::paintGL ( )
...
@@ -72,7 +72,7 @@ void CubeWidget::paintGL ( )
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
glLoadIdentity
();
glLoadIdentity
();
gl
Translatef
(
0.0
f
,
0.0
f
,
-
zoom
);
gl
MultMatrixf
(
translation
->
data
()
);
QMatrix4x4
mat
=
QMatrix4x4
();
QMatrix4x4
mat
=
QMatrix4x4
();
mat
.
rotate
(
*
rotation
);
mat
.
rotate
(
*
rotation
);
...
@@ -238,49 +238,35 @@ void CubeWidget::setTessellation(int t)
...
@@ -238,49 +238,35 @@ void CubeWidget::setTessellation(int t)
void
CubeWidget
::
home
()
void
CubeWidget
::
home
()
{
{
zoom
=
3
;
translation
=
new
QMatrix4x4
();
translation
->
translate
(
0.0
,
0.0
,
-
3.0
);
rotation
=
new
QQuaternion
();
rotation
=
new
QQuaternion
();
updateGL
();
updateGL
();
}
}
void
CubeWidget
::
mousePressEvent
(
QMouseEvent
*
event
)
void
CubeWidget
::
mousePressEvent
(
QMouseEvent
*
event
)
{
{
lastSpeherePos
=
trackballPoint
(
event
->
pos
().
x
(),
event
->
pos
().
y
());
// if (event->isAccepted())
lastScreenPos
=
new
QPointF
(
event
->
screenPos
());
// return;
if
(
event
->
buttons
()
&
Qt
::
LeftButton
)
{
lastPos
=
trackballPoint
(
event
->
pos
().
x
(),
event
->
pos
().
y
());
event
->
accept
();
event
->
accept
();
}
else
{
}
}
}
void
CubeWidget
::
mouseMoveEvent
(
QMouseEvent
*
event
)
void
CubeWidget
::
mouseMoveEvent
(
QMouseEvent
*
event
)
{
{
//http://web.cse.ohio-state.edu/~hwshen/781/Site/Slides_files/trackball.pdf
//http://doc.qt.io/qt-5/qtwidgets-graphicsview-boxes-example.html
// if (event->isAccepted())
// return;
if
(
event
->
buttons
()
&
Qt
::
LeftButton
)
{
if
(
event
->
buttons
()
&
Qt
::
LeftButton
)
{
move
(
trackballPoint
(
event
->
pos
().
x
(),
event
->
pos
().
y
()));
rotate
(
trackballPoint
(
event
->
pos
().
x
(),
event
->
pos
().
y
()));
event
->
accept
();
//m_trackBalls[0].move(pixelPosToViewPos(event->scenePos()), m_trackBalls[2].rotation().conjugate());
}
else
if
(
event
->
buttons
()
&
Qt
::
RightButton
)
{
move
(
new
QPointF
(
event
->
screenPos
()));
event
->
accept
();
event
->
accept
();
}
else
{
//m_trackBalls[0].release(pixelPosToViewPos(event->scenePos()), m_trackBalls[2].rotation().conjugate());
}
}
}
}
void
CubeWidget
::
mov
e
(
QVector3D
*
newPos
)
void
CubeWidget
::
rotat
e
(
QVector3D
*
newPos
)
{
{
QVector3D
axis
=
QVector3D
::
crossProduct
(
*
lastPos
,
*
newPos
);
QVector3D
axis
=
QVector3D
::
crossProduct
(
*
last
Spehere
Pos
,
*
newPos
);
//warum so besser
//warum so besser
float
angle
=
180
/
M_PI
*
asin
(
sqrt
(
QVector3D
::
dotProduct
(
axis
,
axis
)));
float
angle
=
180
/
M_PI
*
asin
(
sqrt
(
QVector3D
::
dotProduct
(
axis
,
axis
)));
...
@@ -290,11 +276,25 @@ void CubeWidget::move(QVector3D *newPos )
...
@@ -290,11 +276,25 @@ void CubeWidget::move(QVector3D *newPos )
QQuaternion
newRot
=
QQuaternion
::
fromAxisAndAngle
(
axis
,
angle
)
*
*
rotation
;
QQuaternion
newRot
=
QQuaternion
::
fromAxisAndAngle
(
axis
,
angle
)
*
*
rotation
;
rotation
=
new
QQuaternion
(
newRot
.
toVector4D
());
rotation
=
new
QQuaternion
(
newRot
.
toVector4D
());
lastPos
=
newPos
;
last
Spehere
Pos
=
newPos
;
updateGL
();
updateGL
();
}
}
void
CubeWidget
::
move
(
QPointF
*
newPos
){
QPointF
dt
=
*
newPos
;
dt
-=
*
lastScreenPos
;
dt
*=
0.01
f
;
float
dx
=
dt
.
x
();
float
dy
=
dt
.
y
()
*-
1.0
;
translation
->
translate
(
dx
,
dy
,
0.0
);
lastScreenPos
=
newPos
;
updateGL
();
}
QVector3D
*
CubeWidget
::
trackballPoint
(
int
x
,
int
y
){
QVector3D
*
CubeWidget
::
trackballPoint
(
int
x
,
int
y
){
float
xo
,
yo
,
zo
;
float
xo
,
yo
,
zo
;
...
@@ -316,9 +316,10 @@ QVector3D* CubeWidget::trackballPoint(int x, int y){
...
@@ -316,9 +316,10 @@ QVector3D* CubeWidget::trackballPoint(int x, int y){
void
CubeWidget
::
wheelEvent
(
QWheelEvent
*
event
)
void
CubeWidget
::
wheelEvent
(
QWheelEvent
*
event
)
{
{
if
(
event
->
delta
()
<
0
)
if
(
event
->
delta
()
<
0
)
zoom
++
;
//TODO
translation
->
translate
(
0.0
,
0.0
,
1.0
);
else
else
zoom
--
;
translation
->
translate
(
0.0
,
0.0
,
-
1.0
)
;
updateGL
();
updateGL
();
}
}
A1/hellocube/cubewidget.h
View file @
25092db6
...
@@ -42,8 +42,12 @@ public slots:
...
@@ -42,8 +42,12 @@ public slots:
private
:
private
:
int
tesselation
;
int
tesselation
;
int
zoom
;
int
zoom
;
QVector3D
*
lastSpeherePos
;
QPointF
*
lastScreenPos
;
QQuaternion
*
rotation
;
QQuaternion
*
rotation
;
Q
Vector3D
*
lastPos
;
Q
Matrix4x4
*
translation
;
QGLShaderProgram
*
shader
;
QGLShaderProgram
*
shader
;
...
@@ -51,7 +55,8 @@ private:
...
@@ -51,7 +55,8 @@ private:
void
perspective
(
GLdouble
fovy
,
GLdouble
aspect
,
GLdouble
zNear
,
GLdouble
zFar
);
void
perspective
(
GLdouble
fovy
,
GLdouble
aspect
,
GLdouble
zNear
,
GLdouble
zFar
);
void
setMaterial
(
GLfloat
*
color
);
void
setMaterial
(
GLfloat
*
color
);
void
move
(
QVector3D
*
newPos
);
void
rotate
(
QVector3D
*
newPos
);
void
move
(
QPointF
*
newPos
);
QVector3D
*
trackballPoint
(
int
x
,
int
y
);
QVector3D
*
trackballPoint
(
int
x
,
int
y
);
};
};
...
...
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