Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
OpenGL
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
C-Fu
OpenGL
Commits
c4444bce
Commit
c4444bce
authored
Jan 21, 2017
by
Anakin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed background bug,
support directional light, zoom speed can be adjust via +/-
parent
5ea90723
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
12 deletions
+49
-12
QtMeshViewer/Header/OglViewerWidget.h
QtMeshViewer/Header/OglViewerWidget.h
+6
-1
QtMeshViewer/Resources/about.txt
QtMeshViewer/Resources/about.txt
+1
-0
QtMeshViewer/Resources/fshader.glsl
QtMeshViewer/Resources/fshader.glsl
+20
-6
QtMeshViewer/Source/MainWindow.cpp
QtMeshViewer/Source/MainWindow.cpp
+1
-0
QtMeshViewer/Source/OglViewerWidget.cpp
QtMeshViewer/Source/OglViewerWidget.cpp
+21
-5
No files found.
QtMeshViewer/Header/OglViewerWidget.h
View file @
c4444bce
...
...
@@ -38,7 +38,7 @@ private:
}
m_rotDirections
;
struct
{
QVector
3D
position
=
{
1
,
1
,
1
};
QVector
4D
position
=
{
1
,
1
,
1
,
0
};
QVector3D
intensities
=
{
1.0
,
1.0
,
1.0
};
float
attenuationFactor
=
0.2
f
;
float
ambientCoefficient
=
0.005
f
;
...
...
@@ -56,6 +56,8 @@ private:
bool
m_wireframe
=
false
;
bool
m_lightOn
=
false
;
double
m_zSpeed
=
1.0
;
protected:
void
mousePressEvent
(
QMouseEvent
*
e
)
Q_DECL_OVERRIDE
;
void
mouseReleaseEvent
(
QMouseEvent
*
e
)
Q_DECL_OVERRIDE
;
...
...
@@ -81,5 +83,8 @@ public slots:
void
changeDirection
(
int
direction
);
void
toggleWireframe
();
void
toggleLight
();
signals:
void
sendMessage
(
QString
message
,
int
severity
);
};
QtMeshViewer/Resources/about.txt
View file @
c4444bce
...
...
@@ -8,6 +8,7 @@ left mouse - rotate
right mouse - move
scroll - zoom
space - reset view
+/- - adjust zoom speed
L - set light to current position
esc - close
...
...
QtMeshViewer/Resources/fshader.glsl
View file @
c4444bce
...
...
@@ -15,7 +15,7 @@ uniform bool b_transparent;
uniform
bool
b_light
;
uniform
struct
Light
{
vec
3
position
;
vec
4
position
;
vec3
intensities
;
float
attenuationFactor
;
float
ambientCoefficient
;
...
...
@@ -31,11 +31,29 @@ void main()
{
// some values
vec3
normalWorld
=
normalize
(
n_matrix
*
v_surfaceNormal
);
vec4
surfaceColor
=
vec4
(
texture2D
(
texture
,
v_surfaceUV
));
surfaceColor
.
rgb
=
pow
(
surfaceColor
.
rgb
,
vec3
(
2
.
2
));
if
(
!
b_transparent
)
surfaceColor
.
a
=
1
.
0
f
;
vec3
surfaceToLight
=
normalize
(
light
.
position
-
v_surfacePosition
);
vec3
surfaceToLight
;
float
attenuation
;
// directional light
if
(
light
.
position
.
w
==
0
)
{
surfaceToLight
=
normalize
(
light
.
position
.
xyz
);
attenuation
=
1
;
}
// point light
else
{
surfaceToLight
=
normalize
(
light
.
position
.
xyz
-
v_surfacePosition
);
float
distanceToLight
=
length
(
light
.
position
.
xyz
-
v_surfacePosition
);
attenuation
=
1
.
0
/
(
1
.
0
+
light
.
attenuationFactor
*
pow
(
distanceToLight
,
2
));
}
vec3
surfaceToCamera
=
normalize
(
cameraPosition
-
v_surfacePosition
);
// ambient
...
...
@@ -51,10 +69,6 @@ void main()
specularCoefficient
=
pow
(
max
(
0
.
0
,
dot
(
surfaceToCamera
,
reflect
(
-
surfaceToLight
,
normalWorld
))),
materialShininess
);
vec3
specular
=
specularCoefficient
*
materialSpecularColor
*
light
.
intensities
;
// attenuation
float
distanceToLight
=
length
(
light
.
position
-
v_surfacePosition
);
float
attenuation
=
1
.
0
/
(
1
.
0
+
light
.
attenuationFactor
*
pow
(
distanceToLight
,
2
));
// linear color before gamma correction)
vec3
linearColor
=
ambient
+
attenuation
*
(
diffuse
+
specular
);
...
...
QtMeshViewer/Source/MainWindow.cpp
View file @
c4444bce
...
...
@@ -55,6 +55,7 @@ void MainWindow::setupWidgets()
{
OglViewerWidget
*
viewer
=
new
OglViewerWidget
(
this
);
setCentralWidget
(
viewer
);
connect
(
viewer
,
&
OglViewerWidget
::
sendMessage
,
this
,
&
MainWindow
::
printMessage
);
QAction
*
openFile
=
new
QAction
(
QIcon
(
":/images/toolbar/open.png"
),
"Open file"
,
this
);
connect
(
openFile
,
&
QAction
::
triggered
,
this
,
&
MainWindow
::
openFile
);
...
...
QtMeshViewer/Source/OglViewerWidget.cpp
View file @
c4444bce
...
...
@@ -145,7 +145,7 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
void
OglViewerWidget
::
wheelEvent
(
QWheelEvent
*
e
)
{
m_translation
+=
{
0.0
,
0.0
,
(
float
)
e
->
angleDelta
().
y
()
/
240
};
m_translation
+=
{
0.0
,
0.0
,
(
float
)
m_zSpeed
*
e
->
angleDelta
().
y
()
/
240
};
update
();
}
...
...
@@ -178,6 +178,17 @@ void OglViewerWidget::keyPressEvent(QKeyEvent *e)
updateLightPosition
();
update
();
}
else
if
(
e
->
key
()
==
Qt
::
Key_Minus
)
{
m_zSpeed
-=
0.1
;
m_zSpeed
<
0.09
?
m_zSpeed
=
0
:
NULL
;
emit
sendMessage
(
QString
(
"Zoom speed = %1%"
).
arg
(
m_zSpeed
*
100
),
0
);
}
else
if
(
e
->
key
()
==
Qt
::
Key_Plus
)
{
m_zSpeed
+=
0.1
;
emit
sendMessage
(
QString
(
"Zoom speed = %1%"
).
arg
(
m_zSpeed
*
100
),
0
);
}
}
void
OglViewerWidget
::
initializeGL
()
...
...
@@ -219,15 +230,15 @@ void OglViewerWidget::resizeGL(int w, int h)
void
OglViewerWidget
::
paintGL
()
{
// Clear color and depth buffer
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
if
(
m_backgroundColor
[
3
]
==
1.0
)
{
glClearColor
(
m_backgroundColor
[
0
],
m_backgroundColor
[
1
],
m_backgroundColor
[
2
],
0.0000
f
);
m_backgroundColor
[
3
]
=
0.0
;
}
// Clear color and depth buffer
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
// Calculate model view transformation
QMatrix4x4
view
;
view
.
translate
(
m_translation
);
...
...
@@ -290,7 +301,11 @@ void OglViewerWidget::updateLightPosition()
{
QMatrix4x4
rotateBack
;
rotateBack
.
rotate
(
m_rotation
.
inverted
());
m_light
.
position
=
rotateBack
*
(
-
m_translation
);
QVector3D
cameraPosition
=
rotateBack
*
(
-
m_translation
);
m_light
.
position
.
setX
(
cameraPosition
.
x
());
m_light
.
position
.
setY
(
cameraPosition
.
y
());
m_light
.
position
.
setZ
(
cameraPosition
.
z
());
}
...
...
@@ -301,6 +316,7 @@ void OglViewerWidget::resetView()
{
m_rotation
=
QQuaternion
();
m_translation
=
{
0.0
,
0.0
,
DEFAULT_Z_DISTANCE
};
m_zSpeed
=
1
;
update
();
}
...
...
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