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
546c71b8
Commit
546c71b8
authored
Oct 28, 2015
by
Kai Westerkamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
broken Rotation and some clipping bugs
parent
229da88d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
4 deletions
+77
-4
cubewidget.cpp
A1/hellocube/cubewidget.cpp
+70
-3
cubewidget.h
A1/hellocube/cubewidget.h
+7
-1
No files found.
A1/hellocube/cubewidget.cpp
View file @
546c71b8
...
...
@@ -43,13 +43,16 @@ void CubeWidget::paintGL ( )
{
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
glLoadIdentity
();
glTranslatef
(
0.0
f
,
0.0
f
,
-
zoom
);
QMatrix4x4
mat
=
QMatrix4x4
();
mat
.
rotate
(
*
rotation
);
glMultMatrixf
(
mat
.
data
());
GLfloat
red
[]
=
{
1.0
,
0.0
,
0.0
};
GLfloat
green
[]
=
{
0.0
,
1.0
,
0.0
};
GLfloat
blue
[]
=
{
0.0
,
0.0
,
1.0
};
...
...
@@ -123,6 +126,8 @@ void CubeWidget::paintGL ( )
glEnd
();
}
void
CubeWidget
::
resizeGL
(
int
width
,
int
height
)
{
glMatrixMode
(
GL_PROJECTION
);
...
...
@@ -153,7 +158,7 @@ void CubeWidget::showWireframe()
qDebug
(
"show Wireframe"
);
glShadeModel
(
GL_FLAT
);
glDisable
(
GL_CULL_FACE
);
//
glDisable(GL_CULL_FACE);
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_LINE
);
updateGL
();
...
...
@@ -163,7 +168,7 @@ void CubeWidget::showFlat()
{
qDebug
(
"show Flat"
);
glShadeModel
(
GL_FLAT
);
glEnable
(
GL_CULL_FACE
);
//
glEnable(GL_CULL_FACE);
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_FILL
);
updateGL
();
}
...
...
@@ -172,7 +177,7 @@ void CubeWidget::showGouraut()
{
qDebug
(
"show Gouraut"
);
glShadeModel
(
GL_SMOOTH
);
glEnable
(
GL_CULL_FACE
);
//
glEnable(GL_CULL_FACE);
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_FILL
);
updateGL
();
}
...
...
@@ -201,11 +206,73 @@ void CubeWidget::home()
void
CubeWidget
::
mousePressEvent
(
QMouseEvent
*
event
)
{
// if (event->isAccepted())
// return;
if
(
event
->
buttons
()
&
Qt
::
LeftButton
)
{
qDebug
(
"press"
);
lastPos
=
trackballPoint
(
event
->
pos
().
x
(),
event
->
pos
().
y
());
event
->
accept
();
}
else
{
}
}
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
)
{
qDebug
(
"move"
);
move
(
trackballPoint
(
event
->
pos
().
x
(),
event
->
pos
().
y
()));
//m_trackBalls[0].move(pixelPosToViewPos(event->scenePos()), m_trackBalls[2].rotation().conjugate());
event
->
accept
();
}
else
{
//m_trackBalls[0].release(pixelPosToViewPos(event->scenePos()), m_trackBalls[2].rotation().conjugate());
}
}
void
CubeWidget
::
move
(
QVector3D
*
newPos
)
{
QVector3D
axis
=
QVector3D
::
crossProduct
(
*
lastPos
,
*
newPos
);
//warum so besser
float
angle
=
180
/
M_PI
*
std
::
asin
(
std
::
sqrt
(
QVector3D
::
dotProduct
(
axis
,
axis
)));
axis
.
normalize
();
axis
=
rotation
->
conjugate
().
rotatedVector
(
axis
);
QQuaternion
newRot
=
QQuaternion
::
fromAxisAndAngle
(
axis
,
angle
)
*
*
rotation
;
rotation
=
new
QQuaternion
(
newRot
.
toVector4D
());
lastPos
=
newPos
;
updateGL
();
}
QVector3D
*
CubeWidget
::
trackballPoint
(
int
x
,
int
y
){
float
xo
,
yo
,
zo
;
qDebug
()
<<
"x:"
<<
x
<<
" y:"
<<
y
;
xo
=
((
2.0
*
x
)
-
width
())
/
height
();
yo
=
(
height
()
-
(
2.0
*
y
))
/
width
();
float
d
=
sqrt
(
xo
*
xo
+
yo
*
yo
);
zo
=
qMax
(
qCos
(
M_PI_2
*
d
),
qreal
(
0.0
));
//qMin(d,1.0f)
QVector3D
*
pos
=
new
QVector3D
(
xo
,
yo
,
zo
);
pos
->
normalize
();
qDebug
()
<<
"x:"
<<
xo
<<
" y:"
<<
yo
<<
" z:"
<<
zo
;
return
pos
;
}
void
CubeWidget
::
wheelEvent
(
QWheelEvent
*
event
)
...
...
A1/hellocube/cubewidget.h
View file @
546c71b8
...
...
@@ -8,6 +8,8 @@
#include <math.h>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QVector3D>
#include <algorithm>
...
...
@@ -41,9 +43,13 @@ private:
int
tesselation
;
int
zoom
;
QQuaternion
*
rotation
;
QPoint
*
lastPos
;
QVector3D
*
lastPos
;
bool
mousDown
=
false
;
void
perspective
(
GLdouble
fovy
,
GLdouble
aspect
,
GLdouble
zNear
,
GLdouble
zFar
);
void
setMaterial
(
GLfloat
*
color
);
void
move
(
QVector3D
*
newPos
);
QVector3D
*
trackballPoint
(
int
x
,
int
y
);
};
#endif // CUBEWIDGET_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