Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
KennethVanhoey
CGoGN
Commits
5e641697
Commit
5e641697
authored
Oct 26, 2011
by
Sylvain Thery
Browse files
Minor modification on qtSimple/qtgl for future plugin system
parent
97d7a2de
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/Utils/qtSimple.h
View file @
5e641697
...
...
@@ -126,6 +126,8 @@ public:
/**
* add an entry to popup menu
* @param label label printed in menu
* @param method qt slot (function name)
*/
void
add_menu_entry
(
const
std
::
string
label
,
const
char
*
method
);
...
...
@@ -207,19 +209,19 @@ public:
* get a ray (2 points) from a pick point in GL area
* @param x mouse position
* @param y mouse position
* @param rayA first computed point
* @param rayA second computed point
* @param rayA first computed point
of ray
* @param rayA second computed point
of ray
* @param radius radius on pixel for clicking precision
* @return the distance in modelview world corresponding to radius pixel in screen
*/
GLfloat
getOrthoScreenRay
(
int
x
,
int
y
,
Geom
::
Vec3f
&
rayA
,
Geom
::
Vec3f
&
rayB
,
int
radius
=
4
);
GLfloat
getOrthoScreenRay
(
int
x
,
int
y
,
Geom
::
Vec3f
&
rayA
,
Geom
::
Vec3f
&
rayB
,
int
radius
=
4
)
{
return
m_glWidget
->
getOrthoScreenRay
(
x
,
y
,
rayA
,
rayB
,
radius
);}
/**
* transform a pixel distance on screen in distance in world
* @param pixel_width width on pixel on screen
* @param center reference point on world to use (defaut 0,0,0)
*/
float
getWidthInWorld
(
unsigned
int
pixel_width
,
const
Geom
::
Vec3f
&
center
=
Geom
::
Vec3f
(
0.0
f
,
0.0
f
,
0.0
f
)
);
float
getWidthInWorld
(
unsigned
int
pixel_width
,
const
Geom
::
Vec3f
&
center
)
{
return
m_glWidget
->
getWidthInWorld
(
pixel_width
,
center
);
}
const
glm
::
mat4
&
transfoMatrix
()
const
{
return
m_transfo_matrix
;
}
glm
::
mat4
&
transfoMatrix
()
{
return
m_transfo_matrix
;
}
...
...
@@ -312,9 +314,9 @@ public:
virtual
void
cb_mouseClick
(
int
button
,
int
x
,
int
y
)
{}
/**
* the mouse has been move (with button still pressed)
* the mouse has been move (with button
s
still pressed)
*/
virtual
void
cb_mouseMove
(
int
button
,
int
x
,
int
y
)
{}
virtual
void
cb_mouseMove
(
int
button
s
,
int
x
,
int
y
)
{}
/**
* the mouse has been move (with button still pressed)
...
...
include/Utils/qtgl.h
View file @
5e641697
...
...
@@ -35,6 +35,7 @@
#include
"glm/glm.hpp"
#include
"glm/gtc/matrix_projection.hpp"
#include
"glm/gtc/matrix_transform.hpp"
#include
"Geometry/vector_gen.h"
namespace
CGoGN
{
...
...
@@ -88,6 +89,9 @@ protected:
int
m_state_modifier
;
/// stack for transformation matrix
std
::
stack
<
glm
::
mat4
>
m_stack_trf
;
/**
* met a jour la matrice modelview
*/
...
...
@@ -158,6 +162,56 @@ public:
void
modelModified
()
{
newModel
=
1
;
}
void
glMousePosition
(
int
&
x
,
int
&
y
);
/**
* get a ray (2 points) from a pick point in GL area
* @param x mouse position
* @param y mouse position
* @param rayA first computed point of ray
* @param rayA second computed point of ray
* @param radius radius on pixel for clicking precision
* @return the distance in modelview world corresponding to radius pixel in screen
*/
GLfloat
getOrthoScreenRay
(
int
x
,
int
y
,
Geom
::
Vec3f
&
rayA
,
Geom
::
Vec3f
&
rayB
,
int
radius
=
4
);
/**
* transform a pixel distance on screen in distance in world
* @param pixel_width width on pixel on screen
* @param center reference point on world to use (defaut 0,0,0)
*/
float
getWidthInWorld
(
unsigned
int
pixel_width
,
const
Geom
::
Vec3f
&
center
=
Geom
::
Vec3f
(
0.0
f
,
0.0
f
,
0.0
f
));
/**
* current transfo matrix
*/
const
glm
::
mat4
&
transfoMatrix
()
const
;
glm
::
mat4
&
transfoMatrix
();
/**
* current modelview matrix
*/
const
glm
::
mat4
&
modelViewMatrix
()
const
;
glm
::
mat4
&
modelViewMatrix
();
/**
* current projection matrix
*/
const
glm
::
mat4
&
projectionMatrix
()
const
;
glm
::
mat4
&
projectionMatrix
();
void
transfoRotate
(
float
angle
,
float
x
,
float
y
,
float
z
);
void
transfoTranslate
(
float
tx
,
float
ty
,
float
tz
);
void
transfoScale
(
float
sx
,
float
sy
,
float
sz
);
void
pushTransfoMatrix
();
bool
popTransfoMatrix
();
protected:
/**
* equivalent to old school glRotate
...
...
src/Utils/qtSimple.cpp
View file @
5e641697
...
...
@@ -309,80 +309,80 @@ void SimpleQT::glMousePosition(int& x, int& y)
y
=
m_glWidget
->
getHeight
()
-
xy
.
y
();
}
GLfloat
SimpleQT
::
getOrthoScreenRay
(
int
x
,
int
y
,
Geom
::
Vec3f
&
rayA
,
Geom
::
Vec3f
&
rayB
,
int
radius
)
{
// get Z from depth buffer
int
yy
=
y
;
GLfloat
depth_t
[
25
];
glReadPixels
(
x
-
2
,
yy
-
2
,
5
,
5
,
GL_DEPTH_COMPONENT
,
GL_FLOAT
,
depth_t
);
GLfloat
depth
=
0.0
f
;
unsigned
int
nb
=
0
;
for
(
unsigned
int
i
=
0
;
i
<
25
;
++
i
)
{
if
(
depth_t
[
i
]
!=
1.0
f
)
{
depth
+=
depth_t
[
i
];
nb
++
;
}
}
if
(
nb
>
0
)
depth
/=
float
(
nb
);
else
depth
=
0.5
f
;
glm
::
i32vec4
viewport
;
glGetIntegerv
(
GL_VIEWPORT
,
&
(
viewport
[
0
]));
glm
::
vec3
win
(
x
,
yy
,
0.0
f
);
glm
::
vec3
P
=
glm
::
unProject
(
win
,
m_modelView_matrix
,
m_projection_matrix
,
viewport
);
rayA
[
0
]
=
P
[
0
];
rayA
[
1
]
=
P
[
1
];
rayA
[
2
]
=
P
[
2
];
win
[
2
]
=
depth
;
P
=
glm
::
unProject
(
win
,
m_modelView_matrix
,
m_projection_matrix
,
viewport
);
rayB
[
0
]
=
P
[
0
];
rayB
[
1
]
=
P
[
1
];
rayB
[
2
]
=
P
[
2
];
if
(
depth
==
1.0
f
)
// depth vary in [0-1]
win
[
2
]
=
0.5
f
;
win
[
0
]
+=
radius
;
P
=
glm
::
unProject
(
win
,
m_modelView_matrix
,
m_projection_matrix
,
viewport
);
Geom
::
Vec3f
Q
;
Q
[
0
]
=
P
[
0
];
Q
[
1
]
=
P
[
1
];
Q
[
2
]
=
P
[
2
];
// compute & return distance
Q
-=
rayB
;
return
float
(
Q
.
norm
());
}
float
SimpleQT
::
getWidthInWorld
(
unsigned
int
pixel_width
,
const
Geom
::
Vec3f
&
center
)
{
glm
::
i32vec4
viewport
;
glGetIntegerv
(
GL_VIEWPORT
,
&
(
viewport
[
0
]));
glm
::
vec3
win
=
glm
::
project
(
glm
::
vec3
(
center
[
0
],
center
[
1
],
center
[
2
]),
m_modelView_matrix
,
m_projection_matrix
,
viewport
);
win
[
0
]
-=
pixel_width
/
2
;
glm
::
vec3
P
=
glm
::
unProject
(
win
,
m_modelView_matrix
,
m_projection_matrix
,
viewport
);
win
[
0
]
+=
pixel_width
;
glm
::
vec3
Q
=
glm
::
unProject
(
win
,
m_modelView_matrix
,
m_projection_matrix
,
viewport
);
return
glm
::
distance
(
P
,
Q
);
}
//
GLfloat SimpleQT::getOrthoScreenRay(int x, int y, Geom::Vec3f& rayA, Geom::Vec3f& rayB, int radius)
//
{
//
// get Z from depth buffer
//
int yy = y;
//
GLfloat depth_t[25];
//
glReadPixels(x-2, yy-2, 5, 5, GL_DEPTH_COMPONENT, GL_FLOAT, depth_t);
//
//
GLfloat depth=0.0f;
//
unsigned int nb=0;
//
for (unsigned int i=0; i< 25; ++i)
//
{
//
if (depth_t[i] != 1.0f)
//
{
//
depth += depth_t[i];
//
nb++;
//
}
//
}
//
if (nb>0)
//
depth /= float(nb);
//
else
//
depth = 0.5f;
//
//
glm::i32vec4 viewport;
//
glGetIntegerv(GL_VIEWPORT, &(viewport[0]));
//
//
glm::vec3 win(x, yy, 0.0f);
//
//
glm::vec3 P = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport);
//
//
rayA[0] = P[0];
//
rayA[1] = P[1];
//
rayA[2] = P[2];
//
//
win[2] = depth;
//
//
P = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport);
//
rayB[0] = P[0];
//
rayB[1] = P[1];
//
rayB[2] = P[2];
//
//
if (depth == 1.0f) // depth vary in [0-1]
//
win[2] = 0.5f;
//
//
win[0] += radius;
//
P = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport);
//
Geom::Vec3f Q;
//
Q[0] = P[0];
//
Q[1] = P[1];
//
Q[2] = P[2];
//
//
// compute & return distance
//
Q -= rayB;
//
return float(Q.norm());
//
}
//
//
float SimpleQT::getWidthInWorld(unsigned int pixel_width, const Geom::Vec3f& center)
//
{
//
//
glm::i32vec4 viewport;
//
glGetIntegerv(GL_VIEWPORT, &(viewport[0]));
//
//
glm::vec3 win = glm::project(glm::vec3(center[0],center[1],center[2]), m_modelView_matrix, m_projection_matrix, viewport);
//
//
win[0]-= pixel_width/2;
//
//
glm::vec3 P = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport);
//
//
win[0] += pixel_width;
//
//
glm::vec3 Q = glm::unProject(win, m_modelView_matrix, m_projection_matrix, viewport);
//
//
return glm::distance(P,Q);
//
}
//
...
...
src/Utils/qtgl.cpp
View file @
5e641697
...
...
@@ -380,6 +380,15 @@ void GLWidget::keyReleaseEvent(QKeyEvent *event)
m_cbs
->
cb_keyRelease
(
k
);
}
void
GLWidget
::
glMousePosition
(
int
&
x
,
int
&
y
)
{
QPoint
xy
=
mapFromGlobal
(
QCursor
::
pos
());
x
=
xy
.
x
();
y
=
getHeight
()
-
xy
.
y
();
}
void
GLWidget
::
oglRotate
(
float
angle
,
float
x
,
float
y
,
float
z
)
{
m_cbs
->
modelViewMatrix
()
=
glm
::
rotate
(
m_cbs
->
modelViewMatrix
(),
angle
,
glm
::
vec3
(
x
,
y
,
z
));
...
...
@@ -395,6 +404,128 @@ void GLWidget::oglScale(float sx, float sy, float sz)
m_cbs
->
modelViewMatrix
()
=
glm
::
scale
(
m_cbs
->
modelViewMatrix
(),
glm
::
vec3
(
sx
,
sy
,
sz
));
}
GLfloat
GLWidget
::
getOrthoScreenRay
(
int
x
,
int
y
,
Geom
::
Vec3f
&
rayA
,
Geom
::
Vec3f
&
rayB
,
int
radius
)
{
// get Z from depth buffer
int
yy
=
y
;
GLfloat
depth_t
[
25
];
glReadPixels
(
x
-
2
,
yy
-
2
,
5
,
5
,
GL_DEPTH_COMPONENT
,
GL_FLOAT
,
depth_t
);
GLfloat
depth
=
0.0
f
;
unsigned
int
nb
=
0
;
for
(
unsigned
int
i
=
0
;
i
<
25
;
++
i
)
{
if
(
depth_t
[
i
]
!=
1.0
f
)
{
depth
+=
depth_t
[
i
];
nb
++
;
}
}
if
(
nb
>
0
)
depth
/=
float
(
nb
);
else
depth
=
0.5
f
;
glm
::
i32vec4
viewport
;
glGetIntegerv
(
GL_VIEWPORT
,
&
(
viewport
[
0
]));
glm
::
vec3
win
(
x
,
yy
,
0.0
f
);
glm
::
vec3
P
=
glm
::
unProject
(
win
,
m_cbs
->
modelViewMatrix
(),
m_cbs
->
projectionMatrix
(),
viewport
);
rayA
[
0
]
=
P
[
0
];
rayA
[
1
]
=
P
[
1
];
rayA
[
2
]
=
P
[
2
];
win
[
2
]
=
depth
;
P
=
glm
::
unProject
(
win
,
m_cbs
->
modelViewMatrix
(),
m_cbs
->
projectionMatrix
(),
viewport
);
rayB
[
0
]
=
P
[
0
];
rayB
[
1
]
=
P
[
1
];
rayB
[
2
]
=
P
[
2
];
if
(
depth
==
1.0
f
)
// depth vary in [0-1]
win
[
2
]
=
0.5
f
;
win
[
0
]
+=
radius
;
P
=
glm
::
unProject
(
win
,
m_cbs
->
modelViewMatrix
(),
m_cbs
->
projectionMatrix
(),
viewport
);
Geom
::
Vec3f
Q
;
Q
[
0
]
=
P
[
0
];
Q
[
1
]
=
P
[
1
];
Q
[
2
]
=
P
[
2
];
// compute & return distance
Q
-=
rayB
;
return
float
(
Q
.
norm
());
}
float
GLWidget
::
getWidthInWorld
(
unsigned
int
pixel_width
,
const
Geom
::
Vec3f
&
center
)
{
glm
::
i32vec4
viewport
;
glGetIntegerv
(
GL_VIEWPORT
,
&
(
viewport
[
0
]));
glm
::
vec3
win
=
glm
::
project
(
glm
::
vec3
(
center
[
0
],
center
[
1
],
center
[
2
]),
m_cbs
->
modelViewMatrix
(),
m_cbs
->
projectionMatrix
(),
viewport
);
win
[
0
]
-=
pixel_width
/
2
;
glm
::
vec3
P
=
glm
::
unProject
(
win
,
m_cbs
->
modelViewMatrix
(),
m_cbs
->
projectionMatrix
(),
viewport
);
win
[
0
]
+=
pixel_width
;
glm
::
vec3
Q
=
glm
::
unProject
(
win
,
m_cbs
->
modelViewMatrix
(),
m_cbs
->
projectionMatrix
(),
viewport
);
return
glm
::
distance
(
P
,
Q
);
}
void
GLWidget
::
transfoRotate
(
float
angle
,
float
x
,
float
y
,
float
z
)
{
m_cbs
->
transfoMatrix
()
=
glm
::
rotate
(
m_cbs
->
transfoMatrix
(),
angle
,
glm
::
vec3
(
x
,
y
,
z
));
}
void
GLWidget
::
transfoTranslate
(
float
tx
,
float
ty
,
float
tz
)
{
m_cbs
->
transfoMatrix
()
=
glm
::
translate
(
m_cbs
->
transfoMatrix
(),
glm
::
vec3
(
tx
,
ty
,
tz
));
}
void
GLWidget
::
transfoScale
(
float
sx
,
float
sy
,
float
sz
)
{
m_cbs
->
transfoMatrix
()
=
glm
::
scale
(
m_cbs
->
transfoMatrix
(),
glm
::
vec3
(
sx
,
sy
,
sz
));
}
void
GLWidget
::
pushTransfoMatrix
()
{
m_stack_trf
.
push
(
m_cbs
->
transfoMatrix
());
}
bool
GLWidget
::
popTransfoMatrix
()
{
if
(
m_stack_trf
.
empty
())
return
false
;
m_cbs
->
transfoMatrix
()
=
m_stack_trf
.
top
();
m_stack_trf
.
pop
();
return
true
;
}
/**
* current transfo matrix
*/
const
glm
::
mat4
&
GLWidget
::
transfoMatrix
()
const
{
return
m_cbs
->
transfoMatrix
();
}
glm
::
mat4
&
GLWidget
::
transfoMatrix
()
{
return
m_cbs
->
transfoMatrix
();
}
/**
* current modelview matrix
*/
const
glm
::
mat4
&
GLWidget
::
modelViewMatrix
()
const
{
return
m_cbs
->
modelViewMatrix
();
}
glm
::
mat4
&
GLWidget
::
modelViewMatrix
()
{
return
m_cbs
->
modelViewMatrix
();
}
/**
* current projection matrix
*/
const
glm
::
mat4
&
GLWidget
::
projectionMatrix
()
const
{
return
m_cbs
->
projectionMatrix
();
}
glm
::
mat4
&
GLWidget
::
projectionMatrix
()
{
return
m_cbs
->
projectionMatrix
();
}
}
// namespace QT
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment