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
194f25be
Commit
194f25be
authored
Nov 15, 2015
by
Alisa Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shaderauswahl spinnt, rest funktioniert grade.
parent
b06d9373
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
130 additions
and
49 deletions
+130
-49
controller.cpp
helloqube/controller.cpp
+32
-2
controller.h
helloqube/controller.h
+14
-0
mainwindow.cpp
helloqube/mainwindow.cpp
+25
-19
myglwidget.cpp
helloqube/myglwidget.cpp
+53
-28
myglwidget.h
helloqube/myglwidget.h
+6
-0
No files found.
helloqube/controller.cpp
View file @
194f25be
...
...
@@ -10,6 +10,20 @@ Controller::~Controller(){
}
void
Controller
::
initActions
(
QAction
*
cam
,
QAction
*
manipulate
){
modeCameraAction
=
cam
;
modeManipulateAction
=
manipulate
;
}
void
Controller
::
initWidget
(
MyGLWidget
*
w
){
currentWidget
=
w
;
}
void
Controller
::
setCtrlPressed
(
bool
isCtrlPressed
){
ctrlPressed
=
isCtrlPressed
;
}
void
Controller
::
switchToModeCamera
(){
qDebug
(
"Bla"
);
modeCamera
=
true
;
...
...
@@ -22,6 +36,17 @@ void Controller::switchToModeManipulate(){
void
Controller
::
processMousePressEvent
(
QMouseEvent
*
event
,
MyGLWidget
*
widget
){
rightButtonPressed
=
false
;
leftButtonPressed
=
false
;
if
(
ctrlPressed
){
if
(
modeCamera
){
modeCamera
=
false
;
modeCameraAction
->
setChecked
(
false
);
modeManipulateAction
->
setChecked
(
true
);
}
else
{
modeCamera
=
true
;
modeCameraAction
->
setChecked
(
true
);
modeManipulateAction
->
setChecked
(
false
);
}
}
if
(
event
->
button
()
==
Qt
::
RightButton
){
rightButtonPressed
=
true
;
lastClickPosition
=
event
->
pos
();
...
...
@@ -30,8 +55,7 @@ void Controller::processMousePressEvent(QMouseEvent *event, MyGLWidget *widget){
leftButtonPressed
=
true
;
lastClickPosition
=
event
->
pos
();
}
//TODO if widget was not selected before, set active.
currentWidget
=
widget
;
}
void
Controller
::
processMouseMoveEvent
(
QMouseEvent
*
event
,
MyGLWidget
*
widget
){
...
...
@@ -57,6 +81,12 @@ void Controller::processMouseMoveEvent(QMouseEvent *event, MyGLWidget *widget){
}
}
void
Controller
::
resetCamera
(){
if
(
currentWidget
){
currentWidget
->
resetCamera
();
}
}
void
Controller
::
setScreenScenter
(
QPoint
center
){
screenCenter
=
center
;
}
...
...
helloqube/controller.h
View file @
194f25be
...
...
@@ -12,6 +12,7 @@
#include <QGLShader>
#include <QDebug>
#include <QObject>
#include <QAction>
class
MyGLWidget
;
...
...
@@ -23,6 +24,9 @@ public:
Controller
();
~
Controller
();
void
initActions
(
QAction
*
cam
,
QAction
*
manipulate
);
void
initWidget
(
MyGLWidget
*
w
);
//processes input and might call follow up functions in widget
void
processMousePressEvent
(
QMouseEvent
*
event
,
MyGLWidget
*
widget
);
...
...
@@ -31,9 +35,18 @@ public:
void
processMouseMoveEvent
(
QMouseEvent
*
event
,
MyGLWidget
*
widget
);
void
setScreenScenter
(
QPoint
center
);
void
setCtrlPressed
(
bool
isCtrlPressed
);
private
:
QAction
*
modeCameraAction
;
QAction
*
modeManipulateAction
;
MyGLWidget
*
currentWidget
;
bool
modeCamera
;
bool
ctrlPressed
=
false
;
bool
rightButtonPressed
;
bool
leftButtonPressed
;
QPoint
screenCenter
;
//Center of screen in pixel coordinates
...
...
@@ -45,6 +58,7 @@ private:
public
slots
:
void
switchToModeCamera
();
void
switchToModeManipulate
();
void
resetCamera
();
};
...
...
helloqube/mainwindow.cpp
View file @
194f25be
...
...
@@ -76,16 +76,15 @@ MainWindow::MainWindow(QWidget *parent)
setStatusBar
(
statusBar
);
//4.0 Widget //Assignment 2: Multiple Widgets.
qDebug
(
"widgets..."
);
controller
=
new
Controller
();
myGLWidget
=
new
MyGLWidget
(
controller
,
true
,
QQuaternion
(),
this
);
setCentralWidget
(
myGLWidget
);
controller
->
initWidget
(
myGLWidget
);
viewFront
=
new
MyGLWidget
(
controller
,
false
,
QQuaternion
(
0
,
1
,
0
,
0
),
this
);
double
costhetahalf
=
cos
(
45
);
viewLeft
=
new
MyGLWidget
(
controller
,
true
,
QQuaternion
(
costhetahalf
,
1
,
0
,
0
),
this
);
//TODO check rotations.
viewTop
=
new
MyGLWidget
(
controller
,
false
,
QQuaternion
(
costhetahalf
,
0
,
1
,
0
),
this
);
viewLayout
=
new
QGridLayout
(
this
);
viewFront
=
new
MyGLWidget
(
controller
,
false
,
QQuaternion
(),
this
);
viewLeft
=
new
MyGLWidget
(
controller
,
false
,
QQuaternion
::
fromAxisAndAngle
(
0
,
1
,
0
,
90
),
this
);
//TODO check rotations.
viewTop
=
new
MyGLWidget
(
controller
,
false
,
QQuaternion
::
fromAxisAndAngle
(
1
,
0
,
0
,
90
),
this
);
viewSplitter1
=
new
QSplitter
;
viewSplitter1
->
addWidget
(
myGLWidget
);
...
...
@@ -95,24 +94,19 @@ MainWindow::MainWindow(QWidget *parent)
viewSplitter2
->
addWidget
(
viewLeft
);
viewSplitter2
->
addWidget
(
viewTop
);
viewSplitter3
=
new
QSplitter
;
viewSplitter3
->
setOrientation
(
Qt
::
Vertical
);
viewSplitter3
->
addWidget
(
viewSplitter1
);
viewSplitter3
->
addWidget
(
viewSplitter2
);
view
Splitter3
=
new
QSplitter
;
view
Layout
=
new
QGridLayout
(
this
)
;
viewLayout
->
addWidget
(
viewSplitter3
);
QWidget
*
central_widget
=
new
QWidget
(
this
);
central_widget
->
setLayout
(
viewLayout
);
setCentralWidget
(
central_widget
);
//4.1.1 connect shading actions to slot
connect
(
shadeWireframeAction
,
SIGNAL
(
triggered
(
bool
)),
myGLWidget
,
SLOT
(
shadeWireframeSlot
()));
connect
(
shadeFlatAction
,
SIGNAL
(
triggered
(
bool
)),
myGLWidget
,
SLOT
(
shadeFlatSlot
()));
connect
(
shadeGouraudAction
,
SIGNAL
(
triggered
(
bool
)),
myGLWidget
,
SLOT
(
shadeGouraudSlot
()));
connect
(
shadePhongAction
,
SIGNAL
(
triggered
(
bool
)),
myGLWidget
,
SLOT
(
shadePhongSlot
()));
qDebug
(
"tesselation..."
);
//tesselation slider
tesselationSlider
=
new
QSlider
(
Qt
::
Horizontal
,
this
);
...
...
@@ -122,19 +116,29 @@ MainWindow::MainWindow(QWidget *parent)
tesselationSlider
->
setMinimum
(
1
);
tesselationSlider
->
setMaximum
(
16
);
tesselationSlider
->
setValue
(
1
);
connect
(
tesselationSlider
,
SIGNAL
(
valueChanged
(
int
)),
myGLWidget
,
SLOT
(
setTessellation
(
int
)));
toolBar
->
addWidget
(
tesselationSlider
);
//4.1.1 connect shading actions to slot
MyGLWidget
*
allWidgets
[
4
]
=
{
myGLWidget
,
viewFront
,
viewLeft
,
viewTop
};
for
(
int
i
=
0
;
i
<
4
;
i
++
){
connect
(
shadeWireframeAction
,
SIGNAL
(
triggered
(
bool
)),
allWidgets
[
i
],
SLOT
(
shadeWireframeSlot
()));
connect
(
shadeFlatAction
,
SIGNAL
(
triggered
(
bool
)),
allWidgets
[
i
],
SLOT
(
shadeFlatSlot
()));
connect
(
shadeGouraudAction
,
SIGNAL
(
triggered
(
bool
)),
allWidgets
[
i
],
SLOT
(
shadeGouraudSlot
()));
connect
(
shadePhongAction
,
SIGNAL
(
triggered
(
bool
)),
allWidgets
[
i
],
SLOT
(
shadePhongSlot
()));
connect
(
tesselationSlider
,
SIGNAL
(
valueChanged
(
int
)),
allWidgets
[
i
],
SLOT
(
setTessellation
(
int
)));
}
//reset Camera button
resetCameraAction
=
new
QAction
(
"Reset Camera"
,
toolBar
);
resetCameraAction
->
setIcon
(
QIcon
(
":/img/cam_home.png"
));
connect
(
resetCameraAction
,
SIGNAL
(
triggered
(
bool
)),
myGLWidget
,
SLOT
(
resetCamera
()));
connect
(
resetCameraAction
,
SIGNAL
(
triggered
(
bool
)),
controller
,
SLOT
(
resetCamera
()));
toolBar
->
addAction
(
resetCameraAction
);
toolBar
->
insertSeparator
(
resetCameraAction
);
/* Assignment 2*/
qDebug
(
"Camera / Object Manipulation..."
);
//2 Camera Mode, Object Manipulation Mode
modeCameraAction
=
new
QAction
(
"Camera Mode"
,
toolBar
);
modeCameraAction
->
setIcon
(
QIcon
(
":/grapa-a2-iconset/camera.png"
));
...
...
@@ -152,12 +156,14 @@ MainWindow::MainWindow(QWidget *parent)
toolBar
->
addAction
(
modeManipulateAction
);
connect
(
modeManipulateAction
,
SIGNAL
(
triggered
(
bool
)),
controller
,
SLOT
(
switchToModeManipulate
()));
controller
->
initActions
(
modeCameraAction
,
modeManipulateAction
);
modeSwitchGroup
=
new
QActionGroup
(
toolBar
);
modeSwitchGroup
->
addAction
(
modeCameraAction
);
modeSwitchGroup
->
addAction
(
modeManipulateAction
);
qDebug
(
"View switch..."
);
//2 Switch view modes
viewButton
=
new
QToolButton
(
toolBar
);
...
...
@@ -194,7 +200,7 @@ MainWindow::MainWindow(QWidget *parent)
viewMenu
->
addAction
(
quadViewAction
);
viewGroup
->
addAction
(
quadViewAction
);
qDebug
(
"Done initializing"
);
}
...
...
helloqube/myglwidget.cpp
View file @
194f25be
#include "myglwidget.h"
#include "controller.h"
//QGLShaderProgram *MyGLWidget::phongShader;
MyGLWidget
::
MyGLWidget
(
Controller
*
c
,
bool
isPerspective
,
QQuaternion
initialRotation
,
QWidget
*
parent
)
:
QGLWidget
(
QGLFormat
(
QGL
::
SampleBuffers
),
parent
)
{
...
...
@@ -8,6 +10,7 @@ MyGLWidget::MyGLWidget(Controller* c, bool isPerspective, QQuaternion initialRot
tesselation
=
1
;
qubeRotation
=
QQuaternion
();
cameraRotation
=
initialRotation
;
cameraStartRotation
=
initialRotation
;
translatex
=
0
;
translatey
=
0
;
camRotCenter
=
QVector3D
(
0
,
0
,
0
);
...
...
@@ -53,32 +56,13 @@ void MyGLWidget::initializeGL()
{
glClearColor
(
0.0
,
0.0
,
0.0
,
0.0
);
glEnable
(
GL_DEPTH_TEST
);
//Phong Shader:
QGLShader
*
vert
=
new
QGLShader
(
QGLShader
::
Vertex
);
qDebug
()
<<
"new vert shader"
;
QGLShader
*
frag
=
new
QGLShader
(
QGLShader
::
Fragment
);
qDebug
()
<<
"new frag shader"
;
bool
e
=
QFile
::
exists
(
":/phong.vert"
);
qDebug
()
<<
"vert exists"
<<
e
;
bool
successVertex
=
vert
->
compileSourceFile
(
":/phong.vert"
);
if
(
!
successVertex
)
qDebug
()
<<
"Vertex compilation failed."
;
else
qDebug
()
<<
"Vertex compiled."
;
bool
successFragment
=
frag
->
compileSourceFile
(
":/phong.frag"
);
if
(
!
successFragment
)
qDebug
()
<<
"Frag failed"
;
else
qDebug
()
<<
"frag success"
;
phongShader
=
new
QGLShaderProgram
(
this
);
phongShader
->
addShader
(
vert
);
phongShader
->
addShader
(
frag
);
phongShader
->
link
();
shadeFlatSlot
();
//set up flat shading
qDebug
()
<<
"flat done"
;
qDebug
(
"InitGPL"
);
// if (!phongShader){
qDebug
(
"Init shader stuff"
);
initShaderStuff
();
// }else {
// qDebug() << " phong not null: " << phongShader;
// }
// glEnable(GL_CULL_FACE);//backface culling.
...
...
@@ -110,8 +94,36 @@ example, the background color.
glLightfv
(
GL_LIGHT0
,
GL_POSITION
,
lightPosition
);
//set Position of light source.
}
void
MyGLWidget
::
paintGL
(){
void
MyGLWidget
::
initShaderStuff
(){
//Phong Shader:
QGLShader
*
vert
=
new
QGLShader
(
QGLShader
::
Vertex
);
qDebug
()
<<
"new vert shader"
;
QGLShader
*
frag
=
new
QGLShader
(
QGLShader
::
Fragment
);
qDebug
()
<<
"new frag shader"
;
bool
e
=
QFile
::
exists
(
":/phong.vert"
);
qDebug
()
<<
"vert exists"
<<
e
;
bool
successVertex
=
vert
->
compileSourceFile
(
":/phong.vert"
);
if
(
!
successVertex
)
qDebug
()
<<
"Vertex compilation failed."
;
else
qDebug
()
<<
"Vertex compiled."
;
bool
successFragment
=
frag
->
compileSourceFile
(
":/phong.frag"
);
if
(
!
successFragment
)
qDebug
()
<<
"Frag failed"
;
else
qDebug
()
<<
"frag success"
;
phongShader
=
new
QGLShaderProgram
(
this
);
phongShader
->
addShader
(
vert
);
phongShader
->
addShader
(
frag
);
phongShader
->
link
();
shadeFlatSlot
();
//set up flat shading
qDebug
()
<<
"FlatSlot setup."
;
}
void
MyGLWidget
::
paintGL
(){
qDebug
(
"paint gl"
);
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
glLoadIdentity
();
...
...
@@ -280,6 +292,19 @@ void MyGLWidget:: mouseMoveEvent(QMouseEvent *event){
controller
->
processMouseMoveEvent
(
event
,
this
);
}
void
MyGLWidget
::
keyPressEvent
(
QKeyEvent
*
event
){
if
(
event
->
key
()
==
Qt
::
Key_Control
){
controller
->
setCtrlPressed
(
true
);
}
}
void
MyGLWidget
::
keyReleaseEvent
(
QKeyEvent
*
event
){
if
(
event
->
key
()
==
Qt
::
Key_Control
){
controller
->
setCtrlPressed
(
false
);
qDebug
(
"ctrl released"
);
}
}
void
MyGLWidget
::
translateCamera
(
double
xDiff
,
double
yDiff
,
double
zDiff
)
{
//in order to "move parallel to image plane", we have to rotate the image coordinates xDiff and yDiff by our current camera rotation.
...
...
@@ -372,6 +397,6 @@ void MyGLWidget::resetCamera(){
translatey
=
0
;
camRotCenter
=
QVector3D
(
0
,
0
,
0
);
cameraZoom
=
cameraZoomDefault
;
cameraRotation
=
QQuaternion
()
;
cameraRotation
=
cameraStartRotation
;
updateGL
();
}
helloqube/myglwidget.h
View file @
194f25be
...
...
@@ -14,6 +14,7 @@
class
Controller
;
class
MyGLWidget
:
public
QGLWidget
{
Q_OBJECT
//from HelloGL Example
...
...
@@ -35,6 +36,8 @@ class MyGLWidget : public QGLWidget
void
rotateCamera
(
QQuaternion
diff
);
void
rotateQube
(
QQuaternion
diff
);
void
initShaderStuff
();
protected
:
//4.1 Core Functionality
void
initializeGL
();
...
...
@@ -43,6 +46,8 @@ protected:
void
mousePressEvent
(
QMouseEvent
*
event
);
void
mouseMoveEvent
(
QMouseEvent
*
event
);
void
wheelEvent
(
QWheelEvent
*
event
);
void
keyPressEvent
(
QKeyEvent
*
event
);
void
keyReleaseEvent
(
QKeyEvent
*
event
);
Controller
*
controller
;
...
...
@@ -55,6 +60,7 @@ private:
const
double
cameraZoomDefault
=
-
5
;
double
cameraZoom
;
QQuaternion
cameraRotation
;
QQuaternion
cameraStartRotation
;
QVector3D
camRotCenter
;
//translate camera
...
...
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