Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qtquick3d
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andy Nichols
qtquick3d
Commits
685cce6e
Commit
685cce6e
authored
5 years ago
by
Richard Gustavsen
Browse files
Options
Downloads
Patches
Plain Diff
QDemonView3D: add viewToWorld()
parent
3f5f0167
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#3687
passed
5 years ago
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/quick3d/qdemonview3d.cpp
+21
-2
21 additions, 2 deletions
src/quick3d/qdemonview3d.cpp
src/quick3d/qdemonview3d.h
+1
-0
1 addition, 0 deletions
src/quick3d/qdemonview3d.h
with
22 additions
and
2 deletions
src/quick3d/qdemonview3d.cpp
+
21
−
2
View file @
685cce6e
...
...
@@ -430,12 +430,12 @@ QSurfaceFormat QDemonView3D::idealSurfaceFormat()
* the position is not visible in the viewport, a position of [-1, -1, -1] is
* returned. This function requires that a camera is assigned to the view.
*
* \sa QDemonCamera::worldToViewport
* \sa QDemonCamera::worldToViewport
QDemonView3D::viewToWorld
*/
QVector3D
QDemonView3D
::
worldToView
(
const
QVector3D
&
worldPos
)
const
{
if
(
!
m_camera
)
{
qmlWarning
(
this
)
<<
"Cannot resolve position
in view
without a camera assigned!"
;
qmlWarning
(
this
)
<<
"Cannot resolve
view
position without a camera assigned!"
;
return
QVector3D
(
-
1
,
-
1
,
-
1
);
}
...
...
@@ -445,6 +445,25 @@ QVector3D QDemonView3D::worldToView(const QVector3D &worldPos) const
return
normalizedPos
*
QVector3D
(
float
(
width
()),
float
(
height
()),
1
);
}
/*!
* Transforms \a viewportPos from view space into world space. \a The x-, and y
* values of \l viewportPos should be within the width and height of the view.
* The z value should be the distance from the camera into the world in world units. If
* \a viewportPos cannot be mapped to a position, a position of [-1, -1, -1] is returned.
*
* \sa QDemonCamera::viewportToWorld QDemonView3D::worldToView
*/
QVector3D
QDemonView3D
::
viewToWorld
(
const
QVector3D
&
viewportPos
)
const
{
if
(
!
m_camera
)
{
qmlWarning
(
this
)
<<
"Cannot resolve world position without a camera assigned!"
;
return
QVector3D
(
-
1
,
-
1
,
-
1
);
}
const
QVector3D
normalizedPos
=
viewportPos
/
QVector3D
(
float
(
width
()),
float
(
height
()),
1
);
return
m_camera
->
viewportToWorld
(
normalizedPos
);
}
void
QDemonView3D
::
invalidateSceneGraph
()
{
m_node
=
nullptr
;
...
...
This diff is collapsed.
Click to expand it.
src/quick3d/qdemonview3d.h
+
1
−
0
View file @
685cce6e
...
...
@@ -58,6 +58,7 @@ public:
static
QSurfaceFormat
idealSurfaceFormat
();
Q_INVOKABLE
QVector3D
worldToView
(
const
QVector3D
&
worldPos
)
const
;
Q_INVOKABLE
QVector3D
viewToWorld
(
const
QVector3D
&
viewportPos
)
const
;
protected
:
void
geometryChanged
(
const
QRectF
&
newGeometry
,
const
QRectF
&
oldGeometry
)
override
;
...
...
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