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
138ce86d
Commit
138ce86d
authored
Nov 16, 2015
by
Kai Westerkamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Camera & Controler
parent
9af11d94
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
243 additions
and
82 deletions
+243
-82
.gitignore
.gitignore
+4
-0
camera.cpp
A2/camera.cpp
+69
-0
camera.h
A2/camera.h
+36
-0
controler.cpp
A2/controler.cpp
+10
-0
controler.h
A2/controler.h
+17
-0
glview.cpp
A2/glview.cpp
+42
-52
glview.h
A2/glview.h
+12
-14
hellocube.pro
A2/hellocube.pro
+6
-2
mainwindow.cpp
A2/mainwindow.cpp
+33
-9
mainwindow.h
A2/mainwindow.h
+5
-2
phong.frag
A2/phong.frag
+6
-2
scene.h
A2/scene.h
+3
-1
No files found.
.gitignore
View file @
138ce86d
/A1/build-hellocube-Desktop_Qt_5_4_2_MSVC2013_OpenGL_64bit-Debug
/A1/build-hellocube-Desktop_Qt_5_4_2_MSVC2013_OpenGL_64bit-Debug
/A1/hellocube/*.user
/A1/hellocube/*.user
/build-hellocube-Desktop_Qt_5_4_2_MSVC2013_OpenGL_64bit-Debug
/build-hellocube-Desktop_Qt_5_5_1_MinGW_32bit-Debug
/build-hellocube-Desktop_Qt_5_5_1_MSVC2013_64bit-Debug
/A2/*.user
A2/camera.cpp
0 → 100644
View file @
138ce86d
#include "camera.h"
Camera
::
Camera
(
bool
persp
)
{
this
->
persp
=
persp
;
setHome
(
new
QQuaternion
(),
new
QVector3D
(
0.0
,
0.0
,
-
3.0
));
}
void
Camera
::
home
()
{
this
->
rotation
=
homeRotation
;
this
->
translation
=
homeTranslation
;
}
void
Camera
::
setHome
(
QQuaternion
*
rotation
,
QVector3D
*
translation
)
{
//qDebug()<<*rotation<<" trans:"<<*translation;
this
->
homeRotation
=
rotation
;
this
->
homeTranslation
=
translation
;
home
();
}
void
Camera
::
rotate
(
QQuaternion
*
newPos
)
{
// rotation *= *newPos;
}
void
Camera
::
move
(
QVector3D
*
newPos
)
{
// translation+=newPos;
}
void
Camera
::
setupCamera
(
GLdouble
aspect
)
{
glMatrixMode
(
GL_PROJECTION
);
glLoadIdentity
();
if
(
persp
){
perspective
(
45.0
,
aspect
,
0.01
,
100.0
);
}
else
{
int
size
=
1
;
glOrtho
(
-
size
*
aspect
,
size
*
aspect
,
-
size
,
size
,
0.01
,
100.0
);
}
glMatrixMode
(
GL_MODELVIEW
);
glLoadIdentity
();
//Camera Tranforations
QMatrix4x4
mat
=
QMatrix4x4
();
mat
.
translate
(
*
translation
);
glMultMatrixf
(
mat
.
data
());
mat
=
QMatrix4x4
();
mat
.
rotate
(
*
rotation
);
glMultMatrixf
(
mat
.
data
());
}
void
Camera
::
perspective
(
GLdouble
fovy
,
GLdouble
aspect
,
GLdouble
zNear
,
GLdouble
zFar
)
{
GLdouble
xmin
,
xmax
,
ymin
,
ymax
;
ymax
=
zNear
*
tan
(
fovy
*
M_PI
/
360.0
);
ymin
=
-
ymax
;
xmin
=
ymin
*
aspect
;
xmax
=
ymax
*
aspect
;
glFrustum
(
xmin
,
xmax
,
ymin
,
ymax
,
zNear
,
zFar
);
}
A2/camera.h
0 → 100644
View file @
138ce86d
#ifndef CAMERA_H
#define CAMERA_H
#include <QtGui>
#include <QtOpenGL>
#include <QQuaternion>
#include <QVector3D>
class
Camera
:
public
QObject
{
Q_OBJECT
private
:
bool
persp
;
QQuaternion
*
rotation
;
QVector3D
*
translation
;
QQuaternion
*
homeRotation
;
QVector3D
*
homeTranslation
;
void
perspective
(
GLdouble
fovy
,
GLdouble
aspect
,
GLdouble
zNear
,
GLdouble
zFar
);
public
slots
:
void
home
();
public
:
Camera
(
bool
persp
);
void
setHome
(
QQuaternion
*
rotation
,
QVector3D
*
translation
);
void
rotate
(
QQuaternion
*
newPos
);
void
move
(
QVector3D
*
newPos
);
void
setupCamera
(
GLdouble
aspect
);
};
#endif // CAMERA_H
A2/controler.cpp
0 → 100644
View file @
138ce86d
#include "controler.h"
#include "camera.h"
#include "glview.h"
#include "scene.h"
Controler
::
Controler
()
{
}
A2/controler.h
0 → 100644
View file @
138ce86d
#ifndef CONTROLER_H
#define CONTROLER_H
#include <QObject>
class
camera
;
class
GLView
;
class
Scene
;
class
Controler
:
public
QObject
{
Q_OBJECT
public
:
Controler
();
};
#endif // CONTROLER_H
A2/glview.cpp
View file @
138ce86d
#include "glview.h"
#include "glview.h"
GLView
::
GLView
(
Scene
*
scene
,
bool
perspective
)
GLView
::
GLView
(
Scene
*
scene
,
Camera
*
camera
,
Controler
*
controler
)
{
{
this
->
persp
=
perspective
;
this
->
camera
=
camera
;
this
->
scene
=
scene
;
this
->
scene
=
scene
;
this
->
controler
=
controler
;
setHome
(
new
QQuaternion
(),
new
QVector3D
(
0.0
,
0.0
,
-
3.0
));
}
}
QSize
GLView
::
minimumSizeHint
()
const
QSize
GLView
::
minimumSizeHint
()
const
...
@@ -26,7 +26,7 @@ void GLView::initializeGL ( ) {
...
@@ -26,7 +26,7 @@ void GLView::initializeGL ( ) {
glEnable
(
GL_LIGHTING
);
glEnable
(
GL_LIGHTING
);
glEnable
(
GL_LIGHT0
);
glEnable
(
GL_LIGHT0
);
static
GLfloat
lightPosition
[
4
]
=
{
0.
5
,
0.0
,
2.0
,
1.0
};
static
GLfloat
lightPosition
[
4
]
=
{
0.
0
,
0.0
,
2.0
,
1.0
};
glLightfv
(
GL_LIGHT0
,
GL_POSITION
,
lightPosition
);
glLightfv
(
GL_LIGHT0
,
GL_POSITION
,
lightPosition
);
//Shader Setup
//Shader Setup
...
@@ -52,73 +52,63 @@ void GLView::initShader()
...
@@ -52,73 +52,63 @@ void GLView::initShader()
}
}
void
GLView
::
setHome
(
QQuaternion
*
rotation
,
QVector3D
*
translation
)
{
//qDebug()<<*rotation<<" trans:"<<*translation;
this
->
homeRotation
=
rotation
;
this
->
homeTranslation
=
translation
;
home
();
}
void
GLView
::
home
()
{
this
->
rotation
=
homeRotation
;
this
->
translation
=
homeTranslation
;
}
void
GLView
::
paintGL
()
void
GLView
::
paintGL
()
{
{
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
//set Projection
resizeGL
(
0
,
0
);
glLoadIdentity
();
//Camera Tranforations
glViewport
(
0
,
0
,
this
->
width
(),
this
->
height
());
QMatrix4x4
mat
=
QMatrix4x4
();
mat
.
translate
(
*
translation
);
glMatrixMode
(
GL_MODELVIEW
);
glMultMatrixf
(
mat
.
data
());
glLoadIdentity
();
glMatrixMode
(
GL_PROJECTION
);
glLoadIdentity
();
if
(
isActive
){
shader
->
setUniformValue
(
"shaded"
,
false
);
glLineWidth
(
10
);
GLfloat
color
[]
=
{
1.0
,
1.0
,
0.0
};
glMaterialfv
(
GL_FRONT
,
GL_AMBIENT
,
color
);
glMaterialfv
(
GL_FRONT
,
GL_DIFFUSE
,
color
);
glMaterialfv
(
GL_FRONT
,
GL_SPECULAR
,
color
);
glMaterialf
(
GL_FRONT
,
GL_SHININESS
,
128
);
glBegin
(
GL_LINE_LOOP
);
glVertex3i
(
-
1
,
-
1
,
0
);
glVertex3i
(
1
,
-
1
,
0
);
glVertex3i
(
1
,
1
,
0
);
glVertex3i
(
-
1
,
1
,
0
);
glEnd
();
}
// glRotated(45,0,1,0
);
shader
->
setUniformValue
(
"shaded"
,
true
);
mat
=
QMatrix4x4
();
mat
.
rotate
(
*
rotation
);
//set Projection and Camera Rotation
glMultMatrixf
(
mat
.
data
()
);
camera
->
setupCamera
(
aspect
);
//draw Scene
//draw Scene
scene
->
draw
();
scene
->
draw
();
}
}
void
GLView
::
resizeGL
(
int
width
,
int
height
)
void
GLView
::
resizeGL
(
int
width
,
int
height
)
{
{
glViewport
(
0
,
0
,
this
->
width
(),
this
->
height
());
aspect
=
1.0
*
width
/
height
;
GLdouble
aspect
=
1.0
*
this
->
width
()
/
this
->
height
();
glMatrixMode
(
GL_PROJECTION
);
glLoadIdentity
();
if
(
persp
){
perspective
(
45.0
,
aspect
,
0.01
,
100.0
);
}
else
{
int
size
=
1
;
glOrtho
(
-
size
*
aspect
,
size
*
aspect
,
-
size
,
size
,
0.01
,
100.0
);
}
glMatrixMode
(
GL_MODELVIEW
);
}
}
void
GLView
::
perspective
(
GLdouble
fovy
,
GLdouble
aspect
,
GLdouble
zNear
,
GLdouble
zFar
)
{
GLdouble
xmin
,
xmax
,
ymin
,
ymax
;
ymax
=
zNear
*
tan
(
fovy
*
M_PI
/
360.0
);
ymin
=
-
ymax
;
xmin
=
ymin
*
aspect
;
xmax
=
ymax
*
aspect
;
glFrustum
(
xmin
,
xmax
,
ymin
,
ymax
,
zNear
,
zFar
);
void
GLView
::
setAcive
(
bool
active
)
{
this
->
isActive
=
active
;
}
}
Camera
*
GLView
::
getCamera
()
{
return
this
->
camera
;
}
void
GLView
::
mousePressEvent
(
QMouseEvent
*
event
)
{}
void
GLView
::
mousePressEvent
(
QMouseEvent
*
event
)
{}
...
...
A2/glview.h
View file @
138ce86d
...
@@ -3,8 +3,10 @@
...
@@ -3,8 +3,10 @@
#include <QtGui>
#include <QtGui>
#include <QtOpenGL>
#include <QtOpenGL>
#include <scene.h>
#include <controler.h>
#include <camera.h>
#include <scene.h>
class
GLView
:
public
QGLWidget
class
GLView
:
public
QGLWidget
{
{
...
@@ -17,33 +19,29 @@ protected :
...
@@ -17,33 +19,29 @@ protected :
void
mouseMoveEvent
(
QMouseEvent
*
event
)
;
void
mouseMoveEvent
(
QMouseEvent
*
event
)
;
void
wheelEvent
(
QWheelEvent
*
event
)
;
void
wheelEvent
(
QWheelEvent
*
event
)
;
public
:
public
:
GLView
(
Scene
*
scene
,
bool
perspective
=
true
);
GLView
(
Scene
*
scene
,
Camera
*
camera
,
Controler
*
controler
);
void
setHome
(
QQuaternion
*
rotation
,
QVector3D
*
translation
);
void
setHome
(
QQuaternion
*
rotation
,
QVector3D
*
translation
);
QSize
minimumSizeHint
()
const
;
QSize
minimumSizeHint
()
const
;
QSize
sizeHint
()
const
;
QSize
sizeHint
()
const
;
void
rotate
(
QVector3D
*
newPos
);
void
move
(
QPointF
*
newPos
);
public
slots
:
void
setAcive
(
bool
active
);
void
home
();
Camera
*
getCamera
();
private
:
private
:
bool
persp
;
QGLShaderProgram
*
shader
;
QQuaternion
*
rotation
;
Scene
*
scene
;
QVector3D
*
translation
;
QQuaternion
*
homeRotation
;
Controler
*
controler
;
QVector3D
*
homeTranslation
;
Camera
*
camera
;
bool
isActive
;
QGLShaderProgram
*
shader
;
GLdouble
aspect
;
Scene
*
scene
;
void
initShader
();
void
initShader
();
void
perspective
(
GLdouble
fovy
,
GLdouble
aspect
,
GLdouble
zNear
,
GLdouble
zFar
);
};
};
#endif // GLVIEW_H
#endif // GLVIEW_H
A2/hellocube.pro
View file @
138ce86d
...
@@ -15,12 +15,16 @@ SOURCES += main.cpp\
...
@@ -15,12 +15,16 @@ SOURCES += main.cpp\
mainwindow
.
cpp
\
mainwindow
.
cpp
\
cubewidget
.
cpp
\
cubewidget
.
cpp
\
glview
.
cpp
\
glview
.
cpp
\
scene
.
cpp
scene
.
cpp
\
controler
.
cpp
\
camera
.
cpp
HEADERS
+=
mainwindow
.
h
\
HEADERS
+=
mainwindow
.
h
\
cubewidget
.
h
\
cubewidget
.
h
\
glview
.
h
\
glview
.
h
\
scene
.
h
scene
.
h
\
controler
.
h
\
camera
.
h
RESOURCES
+=
\
RESOURCES
+=
\
hellocube
.
qrc
hellocube
.
qrc
...
...
A2/mainwindow.cpp
View file @
138ce86d
...
@@ -12,22 +12,33 @@ MainWindow::MainWindow(QWidget *parent)
...
@@ -12,22 +12,33 @@ MainWindow::MainWindow(QWidget *parent)
toolBar
=
new
QToolBar
(
"Shading"
,
this
);
toolBar
=
new
QToolBar
(
"Shading"
,
this
);
statusBar
=
new
QStatusBar
(
this
);
statusBar
=
new
QStatusBar
(
this
);
controler
=
new
Controler
;
//Views
//Views
scene
=
new
Scene
();
scene
=
new
Scene
();
perspectiveView
=
new
GLView
(
scene
,
true
);
Camera
*
perspectiveCam
=
new
Camera
(
true
);
frontView
=
new
GLView
(
scene
,
false
);
perspectiveView
=
new
GLView
(
scene
,
perspectiveCam
,
controler
);
frontView
->
setHome
(
new
QQuaternion
(),
new
QVector3D
(
0.0
,
0.0
,
-
3.0
));
leftView
=
new
GLView
(
scene
,
false
);
Camera
*
frontCam
=
new
Camera
(
false
);
leftView
->
setHome
(
new
QQuaternion
(
QQuaternion
::
fromAxisAndAngle
(
0.0
,
1.0
,
0.0
,
90.0
).
toVector4D
()),
new
QVector3D
(
0.0
,
0.0
,
-
3.0
));
frontCam
->
setHome
(
new
QQuaternion
(),
new
QVector3D
(
0.0
,
0.0
,
-
3.0
));
topView
=
new
GLView
(
scene
,
false
);
frontView
=
new
GLView
(
scene
,
frontCam
,
controler
);
topView
->
setHome
(
new
QQuaternion
(
QQuaternion
::
fromAxisAndAngle
(
1.0
,
0.0
,
0.0
,
90.0
).
toVector4D
()),
new
QVector3D
(
0.0
,
0.0
,
-
3.0
));
Camera
*
leftCam
=
new
Camera
(
false
);
leftCam
->
setHome
(
new
QQuaternion
(
QQuaternion
::
fromAxisAndAngle
(
0.0
,
1.0
,
0.0
,
90.0
).
toVector4D
()),
new
QVector3D
(
0.0
,
0.0
,
-
3.0
));
leftView
=
new
GLView
(
scene
,
leftCam
,
controler
);
Camera
*
topCam
=
new
Camera
(
false
);
topCam
->
setHome
(
new
QQuaternion
(
QQuaternion
::
fromAxisAndAngle
(
1.0
,
0.0
,
0.0
,
90.0
).
toVector4D
()),
new
QVector3D
(
0.0
,
0.0
,
-
3.0
));
topView
=
new
GLView
(
scene
,
topCam
,
controler
);
topSplit
=
new
QSplitter
(
Qt
::
Horizontal
,
this
);
topSplit
=
new
QSplitter
(
Qt
::
Horizontal
,
this
);
bottomSplit
=
new
QSplitter
(
Qt
::
Horizontal
,
this
);
bottomSplit
=
new
QSplitter
(
Qt
::
Horizontal
,
this
);
verticalSplit
=
new
QSplitter
(
Qt
::
Vertical
,
this
);
verticalSplit
=
new
QSplitter
(
Qt
::
Vertical
,
this
);
activeView
=
perspectiveView
;
setActiveView
(
perspectiveView
)
;
topSplit
->
addWidget
(
perspectiveView
);
topSplit
->
addWidget
(
perspectiveView
);
topSplit
->
addWidget
(
frontView
);
topSplit
->
addWidget
(
frontView
);
...
@@ -107,7 +118,7 @@ MainWindow::MainWindow(QWidget *parent)
...
@@ -107,7 +118,7 @@ MainWindow::MainWindow(QWidget *parent)
connect
(
aboutAction
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
showAboutBox
()));
connect
(
aboutAction
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
showAboutBox
()));
camHome
=
new
QAction
(
QIcon
(
":/img/cam_home.png"
),
"Cam Home"
,
toolBar
);
camHome
=
new
QAction
(
QIcon
(
":/img/cam_home.png"
),
"Cam Home"
,
toolBar
);
connect
(
camHome
,
SIGNAL
(
triggered
(
bool
)),
activeView
,
SLOT
(
home
()));
// Assemble Menus
// Assemble Menus
...
@@ -164,6 +175,19 @@ void MainWindow::showQuad(){
...
@@ -164,6 +175,19 @@ void MainWindow::showQuad(){
leftView
->
show
();
leftView
->
show
();
topView
->
show
();
topView
->
show
();
}
void
MainWindow
::
setActiveView
(
GLView
*
active
)
{
activeView
=
active
;
perspectiveView
->
setAcive
(
false
);
frontView
->
setAcive
(
false
);
leftView
->
setAcive
(
false
);
topView
->
setAcive
(
false
);
activeView
->
setAcive
(
true
);
Camera
*
cam
=
activeView
->
getCamera
();
connect
(
camHome
,
SIGNAL
(
triggered
(
bool
)),
cam
,
SLOT
(
home
()));
}
}
...
...
A2/mainwindow.h
View file @
138ce86d
...
@@ -14,7 +14,9 @@
...
@@ -14,7 +14,9 @@
#include <QSplitter>
#include <QSplitter>
#include <glview.h>
#include <glview.h>
#include <scene.h>
#include <camera.h>
#include <controler.h>
class
MainWindow
:
public
QMainWindow
class
MainWindow
:
public
QMainWindow
{
{
...
@@ -45,6 +47,7 @@ private:
...
@@ -45,6 +47,7 @@ private:
QStatusBar
*
statusBar
;
QStatusBar
*
statusBar
;
Scene
*
scene
;
Scene
*
scene
;
Controler
*
controler
;
QSplitter
*
topSplit
;
QSplitter
*
topSplit
;
QSplitter
*
bottomSplit
;
QSplitter
*
bottomSplit
;
...
@@ -57,7 +60,7 @@ private:
...
@@ -57,7 +60,7 @@ private:
GLView
*
topView
;
GLView
*
topView
;
void
setActiveView
();
void
setActiveView
(
GLView
*
active
);
public
:
public
:
MainWindow
(
QWidget
*
parent
=
0
);
MainWindow
(
QWidget
*
parent
=
0
);
...
...
A2/phong.frag
View file @
138ce86d
uniform
bool
shaded
;
varying
vec3
position
;
varying
vec3
position
;
varying
vec3
normal
;
varying
vec3
normal
;
...
@@ -27,6 +29,8 @@ void main(void)
...
@@ -27,6 +29,8 @@ void main(void)
+
Ispec
+
Ispec
);
);
gl_FragColor
=
vec4
(
specular
);
if
(
shaded
)
gl_FragColor
=
color
;
gl_FragColor
=
color
;
else
gl_FragColor
=
vec4
(
1
,
1
,
0
,
1
);
}
}
A2/scene.h
View file @
138ce86d
#ifndef SCENE_H
#ifndef SCENE_H
#define SCENE_H
#define SCENE_H
#include <QObject>
#include <QtOpenGL>
#include <QtOpenGL>
#include <QGLFunctions>
#include <QGLFunctions>
#include <QOpenGLFunctions>
#include <QOpenGLFunctions>
class
Scene
class
Scene
:
public
QObject
{
{
Q_OBJECT
public
:
public
:
Scene
();
Scene
();
void
draw
();
void
draw
();
...
...
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