Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
G
gltf-viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
Show more breadcrumbs
glTF Viewer Tutorial
gltf-viewer
Commits
d196a38a
Commit
d196a38a
authored
4 years ago
by
celeborn2bealive
Browse files
Options
Downloads
Patches
Plain Diff
Camera: Implement default camera computation
parent
6478b622
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ViewerApplication.cpp
+14
-10
14 additions, 10 deletions
src/ViewerApplication.cpp
with
14 additions
and
10 deletions
src/ViewerApplication.cpp
+
14
−
10
View file @
d196a38a
...
...
@@ -37,9 +37,16 @@ int ViewerApplication::run()
const
auto
normalMatrixLocation
=
glGetUniformLocation
(
glslProgram
.
glId
(),
"uNormalMatrix"
);
tinygltf
::
Model
model
;
if
(
!
loadGltfFile
(
model
))
{
return
-
1
;
}
glm
::
vec3
bboxMin
,
bboxMax
;
computeSceneBounds
(
model
,
bboxMin
,
bboxMax
);
// Build projection matrix
auto
maxDistance
=
500.
f
;
// TODO use scene bounds instead to compute this
maxDistance
=
maxDistance
>
0.
f
?
maxDistance
:
100.
f
;
const
auto
diag
=
bboxMax
-
bboxMin
;
auto
maxDistance
=
glm
::
length
(
diag
)
;
const
auto
projMatrix
=
glm
::
perspective
(
70.
f
,
float
(
m_nWindowWidth
)
/
m_nWindowHeight
,
0.001
f
*
maxDistance
,
1.5
f
*
maxDistance
);
...
...
@@ -51,14 +58,11 @@ int ViewerApplication::run()
if
(
m_hasUserCamera
)
{
cameraController
.
setCamera
(
m_userCamera
);
}
else
{
// TODO Use scene bounds to compute a better default camera
cameraController
.
setCamera
(
Camera
{
glm
::
vec3
(
0
,
0
,
0
),
glm
::
vec3
(
0
,
0
,
-
1
),
glm
::
vec3
(
0
,
1
,
0
)});
}
tinygltf
::
Model
model
;
if
(
!
loadGltfFile
(
model
))
{
return
-
1
;
const
auto
center
=
0.5
f
*
(
bboxMax
+
bboxMin
);
const
auto
up
=
glm
::
vec3
(
0
,
1
,
0
);
const
auto
eye
=
diag
.
z
>
0
?
center
+
diag
:
center
+
2.
f
*
glm
::
cross
(
diag
,
up
);
cameraController
.
setCamera
(
Camera
{
eye
,
center
,
up
});
}
const
auto
bufferObjects
=
createBufferObjects
(
model
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment