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
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
242 additions
and
81 deletions
+242
-81
.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
+5
-1
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/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"
GLView
::
GLView
(
Scene
*
scene
,
bool
perspective
)
GLView
::
GLView
(
Scene
*
scene
,
Camera
*
camera
,
Controler
*
controler
)
{
this
->
persp
=
perspective
;
this
->
camera
=
camera
;
this
->
scene
=
scene
;
setHome
(
new
QQuaternion
(),
new
QVector3D
(
0.0
,
0.0
,
-
3.0
));
this
->
controler
=
controler
;
}
QSize
GLView
::
minimumSizeHint
()
const
...
...
@@ -26,7 +26,7 @@ void GLView::initializeGL ( ) {
glEnable
(
GL_LIGHTING
);
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
);
//Shader Setup
...
...
@@ -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
()
{
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
//set Projection
resizeGL
(
0
,
0
);
glLoadIdentity
();
//Camera Tranforations
QMatrix4x4
mat
=
QMatrix4x4
();
mat
.
translate
(
*
translation
);
glMultMatrixf
(
mat
.
data
());
glViewport
(
0
,
0
,
this
->
width
(),
this
->
height
());
glMatrixMode
(
GL_MODELVIEW
);
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
);
glMultMatrixf
(
mat
.
data
()
);
//set Projection and Camera Rotation
camera
->
setupCamera
(
aspect
);
//draw Scene
scene
->
draw
();
}
void
GLView
::
resizeGL
(
int
width
,
int
height
)
{
glViewport
(
0
,
0
,
this
->
width
(),
this
->
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
);
aspect
=
1.0
*
width
/
height
;
}
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
)
{}
...
...
A2/glview.h
View file @
138ce86d
...
...
@@ -3,8 +3,10 @@
#include <QtGui>
#include <QtOpenGL>
#include <scene.h>
#include <controler.h>
#include <camera.h>
#include <scene.h>
class
GLView
:
public
QGLWidget
{
...
...
@@ -17,33 +19,29 @@ protected :
void
mouseMoveEvent
(
QMouseEvent
*
event
)
;
void
wheelEvent
(
QWheelEvent
*
event
)
;
public
:
GLView
(
Scene
*
scene
,
bool
perspective
=
true
);
GLView
(
Scene
*
scene
,
Camera
*
camera
,
Controler
*
controler
);
void
setHome
(
QQuaternion
*
rotation
,
QVector3D
*
translation
);
QSize
minimumSizeHint
()
const
;
QSize
sizeHint
()
const
;
void
rotate
(
QVector3D
*
newPos
);
void
move
(
QPointF
*
newPos
);
public
slots
:
void
home
();
void
setAcive
(
bool
active
);
Camera
*
getCamera
();
private
:
bool
persp
;
QQuaternion
*
rotation
;
QVector3D
*
translation
;
QGLShaderProgram
*
shader
;
Scene
*
scene
;
QQuaternion
*
homeRotation
;
QVector3D
*
homeTranslation
;
Controler
*
controler
;
Camera
*
camera
;
bool
isActive
;
QGLShaderProgram
*
shader
;
Scene
*
scene
;
GLdouble
aspect
;
void
initShader
();
void
perspective
(
GLdouble
fovy
,
GLdouble
aspect
,
GLdouble
zNear
,
GLdouble
zFar
);
};
#endif // GLVIEW_H
A2/hellocube.pro
View file @
138ce86d
...
...
@@ -15,12 +15,16 @@ SOURCES += main.cpp\
mainwindow
.
cpp
\
cubewidget
.
cpp
\
glview
.
cpp
\
scene
.
cpp
scene
.
cpp
\
controler
.
cpp
\
camera
.
cpp
HEADERS
+=
mainwindow
.
h
\
cubewidget
.
h
\
glview
.
h
\
scene
.
h
scene
.
h
\
controler
.
h
\
camera
.
h
RESOURCES
+=
\
hellocube
.
qrc
...
...
A2/mainwindow.cpp
View file @
138ce86d
...
...
@@ -12,22 +12,33 @@ MainWindow::MainWindow(QWidget *parent)
toolBar
=
new
QToolBar
(
"Shading"
,
this
);
statusBar
=
new
QStatusBar
(
this
);
controler
=
new
Controler
;
//Views
scene
=
new
Scene
();
perspectiveView
=
new
GLView
(
scene
,
true
);
frontView
=
new
GLView
(
scene
,
false
);
frontView
->
setHome
(
new
QQuaternion
(),
new
QVector3D
(
0.0
,
0.0
,
-
3.0
));
leftView
=
new
GLView
(
scene
,
false
);
leftView
->
setHome
(
new
QQuaternion
(
QQuaternion
::
fromAxisAndAngle
(
0.0
,
1.0
,
0.0
,
90.0
).
toVector4D
()),
new
QVector3D
(
0.0
,
0.0
,
-
3.0
));
topView
=
new
GLView
(
scene
,
false
);
topView
->
setHome
(
new
QQuaternion
(
QQuaternion
::
fromAxisAndAngle
(
1.0
,
0.0
,
0.0
,
90.0
).
toVector4D
()),
new
QVector3D
(
0.0
,
0.0
,
-
3.0
));
Camera
*
perspectiveCam
=
new
Camera
(
true
);
perspectiveView
=
new
GLView
(
scene
,
perspectiveCam
,
controler
);
Camera
*
frontCam
=
new
Camera
(
false
);
frontCam
->
setHome
(
new
QQuaternion
(),
new
QVector3D
(
0.0
,
0.0
,
-
3.0
));
frontView
=
new
GLView
(
scene
,
frontCam
,
controler
);
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
);
bottomSplit
=
new
QSplitter
(
Qt
::
Horizontal
,
this
);
verticalSplit
=
new
QSplitter
(
Qt
::
Vertical
,
this
);
activeView
=
perspectiveView
;
setActiveView
(
perspectiveView
)
;
topSplit
->
addWidget
(
perspectiveView
);
topSplit
->
addWidget
(
frontView
);
...
...
@@ -107,7 +118,7 @@ MainWindow::MainWindow(QWidget *parent)
connect
(
aboutAction
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
showAboutBox
()));
camHome
=
new
QAction
(
QIcon
(
":/img/cam_home.png"
),
"Cam Home"
,
toolBar
);
connect
(
camHome
,
SIGNAL
(
triggered
(
bool
)),
activeView
,
SLOT
(
home
()));
// Assemble Menus
...
...
@@ -164,6 +175,19 @@ void MainWindow::showQuad(){
leftView
->
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 @@
#include <QSplitter>
#include <glview.h>
#include <scene.h>
#include <camera.h>
#include <controler.h>
class
MainWindow
:
public
QMainWindow
{
...
...
@@ -45,6 +47,7 @@ private:
QStatusBar
*
statusBar
;
Scene
*
scene
;
Controler
*
controler
;
QSplitter
*
topSplit
;
QSplitter
*
bottomSplit
;
...
...
@@ -57,7 +60,7 @@ private:
GLView
*
topView
;
void
setActiveView
();
void
setActiveView
(
GLView
*
active
);
public
:
MainWindow
(
QWidget
*
parent
=
0
);
...
...
A2/phong.frag
View file @
138ce86d
uniform
bool
shaded
;
varying
vec3
position
;
varying
vec3
normal
;
...
...
@@ -27,6 +29,8 @@ void main(void)
+
Ispec
);
gl_FragColor
=
vec4
(
specular
);
if
(
shaded
)
gl_FragColor
=
color
;
else
gl_FragColor
=
vec4
(
1
,
1
,
0
,
1
);
}
A2/scene.h
View file @
138ce86d
#ifndef SCENE_H
#define SCENE_H
#include <QObject>
#include <QtOpenGL>
#include <QGLFunctions>
#include <QOpenGLFunctions>
class
Scene
class
Scene
:
public
QObject
{
Q_OBJECT
public
:
Scene
();
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