Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
f747f5bf
Commit
f747f5bf
authored
Feb 24, 2010
by
Alexander Wiebel
Browse files
[CHANGE] moved unprojectFromScreen function to WGEUtils
parent
9c9b56e7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
41 deletions
+44
-41
src/graphicsEngine/WGEUtils.cpp
src/graphicsEngine/WGEUtils.cpp
+32
-0
src/graphicsEngine/WGEUtils.h
src/graphicsEngine/WGEUtils.h
+9
-0
src/graphicsEngine/WROIBox.cpp
src/graphicsEngine/WROIBox.cpp
+3
-34
src/graphicsEngine/WROIBox.h
src/graphicsEngine/WROIBox.h
+0
-7
No files found.
src/graphicsEngine/WGEUtils.cpp
View file @
f747f5bf
...
...
@@ -26,6 +26,8 @@
#include <osg/Array>
#include <GL/glu.h>
#include "../math/WPosition.h"
#include "WGEUtils.h"
...
...
@@ -40,3 +42,33 @@ osg::ref_ptr< osg::Vec3Array > wge::osgVec3Array( const std::vector< wmath::WPos
}
return
result
;
}
osg
::
Vec3
wge
::
unprojectFromScreen
(
const
osg
::
Vec3
screen
,
osg
::
ref_ptr
<
osg
::
Camera
>
camera
)
{
double
*
modelView
;
double
*
projection
;
double
dviewport
[
4
];
modelView
=
camera
->
getViewMatrix
().
ptr
();
projection
=
camera
->
getProjectionMatrix
().
ptr
();
dviewport
[
0
]
=
camera
->
getViewport
()
->
x
();
dviewport
[
1
]
=
camera
->
getViewport
()
->
y
();
dviewport
[
2
]
=
camera
->
getViewport
()
->
width
();
dviewport
[
3
]
=
camera
->
getViewport
()
->
height
();
double
x
,
y
,
z
;
GLint
viewport
[
4
];
viewport
[
0
]
=
static_cast
<
GLint
>
(
dviewport
[
0
]
);
viewport
[
1
]
=
static_cast
<
GLint
>
(
dviewport
[
1
]
);
viewport
[
2
]
=
static_cast
<
GLint
>
(
dviewport
[
2
]
);
viewport
[
3
]
=
static_cast
<
GLint
>
(
dviewport
[
3
]
);
gluUnProject
(
screen
[
0
],
screen
[
1
],
screen
[
2
],
modelView
,
projection
,
viewport
,
&
x
,
&
y
,
&
z
);
osg
::
Vec3
world
;
world
[
0
]
=
x
;
world
[
1
]
=
y
;
world
[
2
]
=
z
;
return
world
;
}
src/graphicsEngine/WGEUtils.h
View file @
f747f5bf
...
...
@@ -30,6 +30,7 @@
#include <osg/Array>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Camera>
#include "../common/WColor.h"
#include "../math/WPosition.h"
...
...
@@ -69,6 +70,14 @@ namespace wge
* \return Refernce to the same vector but as osg::Vec3Array.
*/
osg
::
ref_ptr
<
osg
::
Vec3Array
>
osgVec3Array
(
const
std
::
vector
<
wmath
::
WPosition
>&
posArray
);
/**
* Converts screen coordinates into Camera coordinates.
*
* \param screen the screen coordinates
* \param camera The matrices of this camera will used for unprojecting.
*/
osg
::
Vec3
unprojectFromScreen
(
const
osg
::
Vec3
screen
,
osg
::
ref_ptr
<
osg
::
Camera
>
camera
);
}
inline
WColor
wge
::
getRGBAColorFromDirection
(
const
wmath
::
WPosition
&
pos1
,
const
wmath
::
WPosition
&
pos2
)
...
...
src/graphicsEngine/WROIBox.cpp
View file @
f747f5bf
...
...
@@ -28,10 +28,9 @@
#include <osg/LineWidth>
#include <osg/LightModel>
#include <GL/glu.h>
#include "WROIBox.h"
#include "WGraphicsEngine.h"
#include "WGEUtils.h"
size_t
WROIBox
::
maxBoxId
=
0
;
...
...
@@ -222,7 +221,7 @@ void WROIBox::updateGFX()
if
(
m_isPicked
)
{
osg
::
Vec3
in
(
newPixelPos
.
first
,
newPixelPos
.
second
,
0.0
);
osg
::
Vec3
world
=
unprojectFromScreen
(
in
);
osg
::
Vec3
world
=
wge
::
unprojectFromScreen
(
in
,
m_viewer
->
getCamera
()
);
wmath
::
WPosition
newPixelWorldPos
(
world
[
0
],
world
[
1
],
world
[
2
]
);
wmath
::
WPosition
oldPixelWorldPos
;
...
...
@@ -233,7 +232,7 @@ void WROIBox::updateGFX()
else
{
osg
::
Vec3
in
(
m_oldPixelPosition
.
first
,
m_oldPixelPosition
.
second
,
0.0
);
osg
::
Vec3
world
=
unprojectFromScreen
(
in
);
osg
::
Vec3
world
=
wge
::
unprojectFromScreen
(
in
,
m_viewer
->
getCamera
()
);
oldPixelWorldPos
=
wmath
::
WPosition
(
world
[
0
],
world
[
1
],
world
[
2
]
);
}
...
...
@@ -290,33 +289,3 @@ void WROIBox::updateGFX()
lock
.
unlock
();
}
osg
::
Vec3
WROIBox
::
unprojectFromScreen
(
const
osg
::
Vec3
screen
)
{
double
*
modelView
;
double
*
projection
;
double
dviewport
[
4
];
modelView
=
m_viewer
->
getCamera
()
->
getViewMatrix
().
ptr
();
projection
=
m_viewer
->
getCamera
()
->
getProjectionMatrix
().
ptr
();
dviewport
[
0
]
=
m_viewer
->
getCamera
()
->
getViewport
()
->
x
();
dviewport
[
1
]
=
m_viewer
->
getCamera
()
->
getViewport
()
->
y
();
dviewport
[
2
]
=
m_viewer
->
getCamera
()
->
getViewport
()
->
width
();
dviewport
[
3
]
=
m_viewer
->
getCamera
()
->
getViewport
()
->
height
();
double
x
,
y
,
z
;
GLint
viewport
[
4
];
viewport
[
0
]
=
static_cast
<
GLint
>
(
dviewport
[
0
]
);
viewport
[
1
]
=
static_cast
<
GLint
>
(
dviewport
[
1
]
);
viewport
[
2
]
=
static_cast
<
GLint
>
(
dviewport
[
2
]
);
viewport
[
3
]
=
static_cast
<
GLint
>
(
dviewport
[
3
]
);
gluUnProject
(
screen
[
0
],
screen
[
1
],
screen
[
2
],
modelView
,
projection
,
viewport
,
&
x
,
&
y
,
&
z
);
osg
::
Vec3
world
;
world
[
0
]
=
x
;
world
[
1
]
=
y
;
world
[
2
]
=
z
;
return
world
;
}
src/graphicsEngine/WROIBox.h
View file @
f747f5bf
...
...
@@ -92,13 +92,6 @@ private:
*/
virtual
void
updateGFX
();
/**
* Get wordl coordinates from screen coordinates.
* \return the world coordinates.
* \param screen the screen coordinates in pixels and z depth.
*/
osg
::
Vec3
unprojectFromScreen
(
const
osg
::
Vec3
screen
);
/**
* Node callback to handle updates properly
*/
...
...
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