Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
KennethVanhoey
CGoGN
Commits
1dad7e0b
Commit
1dad7e0b
authored
Jul 19, 2011
by
Sylvain Thery
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add locking in frame_manipulator
parent
8836ff92
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
251 additions
and
57 deletions
+251
-57
Apps/Examples/frame_manip.cpp
Apps/Examples/frame_manip.cpp
+10
-1
Apps/Examples/frame_manip.h
Apps/Examples/frame_manip.h
+2
-2
include/Topology/generic/genericmap.hpp
include/Topology/generic/genericmap.hpp
+1
-0
include/Utils/frameManipulator.h
include/Utils/frameManipulator.h
+44
-2
src/Utils/frameManipulator.cpp
src/Utils/frameManipulator.cpp
+194
-52
No files found.
Apps/Examples/frame_manip.cpp
View file @
1dad7e0b
...
...
@@ -47,6 +47,7 @@
#include "glm/gtc/type_precision.hpp"
#include "glm/gtc/type_ptr.hpp"
#include "Utils/textures.h"
using
namespace
CGoGN
;
...
...
@@ -297,12 +298,20 @@ void MyQT::cb_keyPress(int code)
if
(
m_lastPickedObject
)
m_frame
->
setTransformation
(
m_lastPickedObject
->
transfo
());
break
;
case
'x'
:
if
(
m_frame
->
locked
(
Utils
::
FrameManipulator
::
Xt
))
m_frame
->
unlock
(
Utils
::
FrameManipulator
::
Xt
);
else
m_frame
->
lock
(
Utils
::
FrameManipulator
::
Xt
);
break
;
case
'w'
:
if
(
m_frame
->
locked
(
Utils
::
FrameManipulator
::
Xt
))
m_frame
->
unlock
(
Utils
::
FrameManipulator
::
Translations
);
else
m_frame
->
lock
(
Utils
::
FrameManipulator
::
Translations
);
break
;
case
'y'
:
if
(
m_frame
->
locked
(
Utils
::
FrameManipulator
::
Yt
))
m_frame
->
unlock
(
Utils
::
FrameManipulator
::
Yt
);
...
...
@@ -370,7 +379,7 @@ int main(int argc, char **argv)
sqt
.
NBP
=
atoi
(
argv
[
1
]);
sqt
.
setHelpMsg
(
"Param :size of grid (number of objects)
\n
Mpuse:
\n
"
sqt
.
setHelpMsg
(
"Param :size of grid (number of objects)
\n
Mpuse
(with shift)
:
\n
"
" -click on object: selection
\n
-left click on frame: constraint 3d Rotation/Translation/Scale
\n
"
" -right click on frame :free 2D Rotation/Translation
\n
Keys:
\n
x/y/z lock/unlock translation
\n
a/b/c lock/unlock rotation
\n
s/t/u lock/unlock scaling"
);
...
...
Apps/Examples/frame_manip.h
View file @
1dad7e0b
...
...
@@ -21,8 +21,8 @@
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef
POLYHEDRONSVIEW
_H_
#define
POLYHEDRONSVIEW
_H_
#ifndef
FRAME_MANIP_EX
_H_
#define
FRAME_MANIP_EX
_H_
#include <iostream>
...
...
include/Topology/generic/genericmap.hpp
View file @
1dad7e0b
...
...
@@ -120,6 +120,7 @@ inline void GenericMap::embedOrbit(unsigned int orbit, Dart d, unsigned int em)
{
assert
(
isOrbitEmbedded
(
orbit
)
||
!
"Invalid parameter: orbit not embedded"
);
FunctorSetEmb
<
GenericMap
>
fsetemb
(
*
this
,
orbit
,
em
);
std
::
cout
<<
"EMBEDORBIT"
<<
std
::
endl
;
foreach_dart_of_orbit
(
orbit
,
d
,
fsetemb
);
}
...
...
include/Utils/frameManipulator.h
View file @
1dad7e0b
...
...
@@ -308,7 +308,7 @@ namespace Utils
class
FrameManipulator
//: public Pickable
{
public:
enum
AXIS
{
NONE
=
0
,
CENTER
,
Xt
,
Yt
,
Zt
,
Xr
,
Yr
,
Zr
,
Xs
,
Ys
,
Zs
};
enum
AXIS
{
NONE
=
0
,
CENTER
,
Xt
,
Yt
,
Zt
,
Xr
,
Yr
,
Zr
,
Xs
,
Ys
,
Zs
,
Translations
,
Rotations
,
Scales
};
protected:
...
...
@@ -325,6 +325,11 @@ protected:
*/
bool
m_locked_axis
[
11
];
/**
* pinking only locking table
*/
bool
m_lockedPicking_axis
[
11
];
/**
* VBO for position
*/
...
...
@@ -389,6 +394,8 @@ protected:
*/
glm
::
mat4
transfoRenderFrame
();
bool
axisPickable
(
unsigned
int
a
)
{
return
(
!
m_locked_axis
[
a
])
&&
(
!
m_lockedPicking_axis
[
a
]);}
public:
FrameManipulator
();
...
...
@@ -419,20 +426,55 @@ public:
/**
* lock an axis
* lock an axis (drawing & picking are disabled)
* @param axis the axis Xt/Yt/Zt/Xs/Yx/Zs/Xr/Yr/Zr or group Translations/Scales/Rotations)
*/
void
lock
(
unsigned
int
axis
);
/**
* unlock an axis
* @param axis the axis Xt/Yt/Zt/Xs/Yx/Zs/Xr/Yr/Zr or group Translations/Scales/Rotations)
*/
void
unlock
(
unsigned
int
axis
);
/**
* is an axis locked
* @param axis the axis to test
*/
bool
locked
(
unsigned
int
axis
);
/**
* lock an axis only for pinking
*/
void
lockPicking
(
unsigned
int
axis
);
/// lock translations for picking only
void
lockPickingTranslations
();
/// lock rotations for picking only
void
lockPickingRotations
();
/// lock scales for picking only
void
lockPickingScales
();
/**
* unlock an axis (only for pinking)
*/
void
unlockPicking
(
unsigned
int
axis
);
/// unlock translations for picking only
void
unlockPickingTranslations
();
/// unlock rotations for picking only
void
unlockPickingRotations
();
/// unlock scales for picking only
void
unlockPickingScales
();
/**
* is an axis locked (only for pinking)
*/
bool
lockedPicking
(
unsigned
int
axis
);
/**
* higlight an axis (change width rendering).
* To unhighlight, just highlight NONE or highlight a already highlighted axis
...
...
src/Utils/frameManipulator.cpp
View file @
1dad7e0b
...
...
@@ -32,7 +32,7 @@
//#include "glm/gtc/type_precision.hpp"
//#include "glm/gtc/type_ptr.hpp"
#include <cmath>
//
#include <cmath>
namespace
CGoGN
{
...
...
@@ -49,7 +49,10 @@ FrameManipulator::FrameManipulator():
{
for
(
unsigned
int
i
=
0
;
i
<
11
;
++
i
)
{
m_locked_axis
[
i
]
=
false
;
m_lockedPicking_axis
[
i
]
=
false
;
}
m_vboPos
=
new
VBO
();
m_vboPos
->
setDataSize
(
3
);
...
...
@@ -315,7 +318,8 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV
// click on center
if
(
dist2
<
0.02
f
*
0.02
f
)
{
if
(
!
m_locked_axis
[
CENTER
])
// if (! m_locked_axis[CENTER])
if
(
axisPickable
(
CENTER
))
return
CENTER
;
else
return
NONE
;
...
...
@@ -335,74 +339,90 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV
Geom
::
Vec3f
Qx
;
Geom
::
Intersection
inter
=
Geom
::
intersectionLinePlane
<
Geom
::
Vec3f
>
(
P
,
V
,
origin
,
Geom
::
Vec3f
(
1.0
f
,
0.0
f
,
0.0
f
),
Qx
);
if
(
inter
==
Geom
::
FACE_INTERSECTION
)
dist_target
[
3
]
=
Qx
.
norm
()
-
1.0
f
;
else
if
(
inter
==
Geom
::
EDGE_INTERSECTION
)
dist_target
[
3
]
=
sqrtf
(
dist2
)
-
1.0
f
;
if
(
axisPickable
(
Xr
))
{
if
(
inter
==
Geom
::
FACE_INTERSECTION
)
dist_target
[
3
]
=
Qx
.
norm
()
-
1.0
f
;
else
if
(
inter
==
Geom
::
EDGE_INTERSECTION
)
dist_target
[
3
]
=
sqrt
(
dist2
)
-
1.0
f
;
if
(
fabs
(
dist_target
[
3
])
<
ring_half_width
)
dist_cam
[
3
]
=
(
P
-
Qx
)
*
(
P
-
Qx
);
if
(
fabs
(
dist_target
[
3
])
<
ring_half_width
)
dist_cam
[
3
]
=
(
P
-
Qx
)
*
(
P
-
Qx
);
}
// plane Y=0
Geom
::
Vec3f
Qy
;
inter
=
Geom
::
intersectionLinePlane
<
Geom
::
Vec3f
>
(
P
,
V
,
origin
,
Geom
::
Vec3f
(
0.0
f
,
1.0
f
,
0.0
f
),
Qy
);
if
(
inter
==
Geom
::
FACE_INTERSECTION
)
dist_target
[
4
]
=
Qy
.
norm
()
-
1.0
f
;
else
if
(
inter
==
Geom
::
EDGE_INTERSECTION
)
dist_target
[
4
]
=
sqrtf
(
dist2
)
-
1.0
f
;
if
(
axisPickable
(
Yr
))
{
if
(
inter
==
Geom
::
FACE_INTERSECTION
)
dist_target
[
4
]
=
Qy
.
norm
()
-
1.0
f
;
else
if
(
inter
==
Geom
::
EDGE_INTERSECTION
)
dist_target
[
4
]
=
sqrt
(
dist2
)
-
1.0
f
;
if
(
fabs
(
dist_target
[
4
])
<
ring_half_width
)
dist_cam
[
4
]
=
(
P
-
Qy
)
*
(
P
-
Qy
);
if
(
fabs
(
dist_target
[
4
])
<
ring_half_width
)
dist_cam
[
4
]
=
(
P
-
Qy
)
*
(
P
-
Qy
);
}
// plane Z=0
Geom
::
Vec3f
Qz
;
inter
=
Geom
::
intersectionLinePlane
<
Geom
::
Vec3f
>
(
P
,
V
,
origin
,
Geom
::
Vec3f
(
0.0
f
,
0.0
f
,
1.0
f
),
Qz
);
if
(
inter
==
Geom
::
FACE_INTERSECTION
)
dist_target
[
5
]
=
Qz
.
norm
()
-
1.0
f
;
else
if
(
inter
==
Geom
::
EDGE_INTERSECTION
)
dist_target
[
5
]
=
sqrtf
(
dist2
)
-
1.0
f
;
if
(
fabs
(
dist_target
[
5
])
<
ring_half_width
)
dist_cam
[
5
]
=
(
P
-
Qz
)
*
(
P
-
Qz
);
if
(
axisPickable
(
Zr
))
{
if
(
inter
==
Geom
::
FACE_INTERSECTION
)
dist_target
[
5
]
=
Qz
.
norm
()
-
1.0
f
;
else
if
(
inter
==
Geom
::
EDGE_INTERSECTION
)
dist_target
[
5
]
=
sqrt
(
dist2
)
-
1.0
f
;
if
(
fabs
(
dist_target
[
5
])
<
ring_half_width
)
dist_cam
[
5
]
=
(
P
-
Qz
)
*
(
P
-
Qz
);
}
// axes:
Geom
::
Vec3f
PX
(
1.0
f
,
0.0
f
,
0.0
f
);
dist_target
[
0
]
=
sqrtf
(
Geom
::
squaredDistanceLine2Seg
(
P
,
V
,
V
*
V
,
origin
,
PX
))
;
if
(
fabs
(
dist_target
[
0
])
<
0.02
f
)
if
(
axisPickable
(
Xt
)
||
axisPickable
(
Xs
))
{
if
(
(
Qz
-
origin
).
norm
()
>
m_lengthAxes
[
0
])
dist_cam
[
0
]
=
(
P
-
PX
)
*
(
P
-
PX
);
else
dist_cam
[
6
]
=
(
P
-
origin
)
*
(
P
-
origin
);
}
Geom
::
Vec3f
PX
(
1.0
f
,
0.0
f
,
0.0
f
);
dist_target
[
0
]
=
sqrt
(
Geom
::
squaredDistanceLine2Seg
(
P
,
V
,
V
*
V
,
origin
,
PX
))
;
if
(
fabs
(
dist_target
[
0
])
<
0.02
f
)
{
if
(
(
Qz
-
origin
).
norm
()
>
m_lengthAxes
[
0
])
dist_cam
[
0
]
=
(
P
-
PX
)
*
(
P
-
PX
);
else
dist_cam
[
6
]
=
(
P
-
origin
)
*
(
P
-
origin
);
}
}
Geom
::
Vec3f
PY
(
0.0
f
,
1.0
f
,
0.0
f
);
dist_target
[
1
]
=
sqrtf
(
Geom
::
squaredDistanceLine2Seg
(
P
,
V
,
V
*
V
,
origin
,
PY
))
;
if
(
fabs
(
dist_target
[
1
])
<
0.02
f
)
if
(
axisPickable
(
Yt
)
||
axisPickable
(
Ys
))
{
if
((
Qz
-
origin
).
norm
()
>
m_lengthAxes
[
1
])
dist_cam
[
1
]
=
(
P
-
PY
)
*
(
P
-
PY
);
else
dist_cam
[
7
]
=
(
P
-
origin
)
*
(
P
-
origin
);
Geom
::
Vec3f
PY
(
0.0
f
,
1.0
f
,
0.0
f
);
dist_target
[
1
]
=
sqrt
(
Geom
::
squaredDistanceLine2Seg
(
P
,
V
,
V
*
V
,
origin
,
PY
))
;
if
(
fabs
(
dist_target
[
1
])
<
0.02
f
)
{
if
((
Qz
-
origin
).
norm
()
>
m_lengthAxes
[
1
])
dist_cam
[
1
]
=
(
P
-
PY
)
*
(
P
-
PY
);
else
dist_cam
[
7
]
=
(
P
-
origin
)
*
(
P
-
origin
);
}
}
Geom
::
Vec3f
PZ
(
0.0
f
,
0.0
f
,
1.0
f
);
dist_target
[
2
]
=
sqrtf
(
Geom
::
squaredDistanceLine2Seg
(
P
,
V
,
V
*
V
,
origin
,
PZ
));
if
(
fabs
(
dist_target
[
2
])
<
0.02
f
)
if
(
axisPickable
(
Zt
)
||
axisPickable
(
Zs
))
{
if
((
Qx
-
origin
).
norm
()
>
m_lengthAxes
[
2
])
dist_cam
[
2
]
=
(
P
-
PZ
)
*
(
P
-
PZ
);
else
dist_cam
[
8
]
=
(
P
-
origin
)
*
(
P
-
origin
);
Geom
::
Vec3f
PZ
(
0.0
f
,
0.0
f
,
1.0
f
);
dist_target
[
2
]
=
sqrt
(
Geom
::
squaredDistanceLine2Seg
(
P
,
V
,
V
*
V
,
origin
,
PZ
));
if
(
fabs
(
dist_target
[
2
])
<
0.02
f
)
{
if
((
Qx
-
origin
).
norm
()
>
m_lengthAxes
[
2
])
dist_cam
[
2
]
=
(
P
-
PZ
)
*
(
P
-
PZ
);
else
dist_cam
[
8
]
=
(
P
-
origin
)
*
(
P
-
origin
);
}
}
// find min dist_cam value;
unsigned
int
min_index
=
0
;
float
min_val
=
dist_cam
[
0
];
...
...
@@ -417,7 +437,8 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV
if
(
min_val
<
std
::
numeric_limits
<
float
>::
max
())
{
if
(
!
m_locked_axis
[
Xt
+
min_index
])
// if (! m_locked_axis[Xt+min_index])
if
(
axisPickable
(
Xt
+
min_index
))
return
Xt
+
min_index
;
}
...
...
@@ -454,13 +475,17 @@ void FrameManipulator::setLengthAxes()
float
sc1
=
m_scale
[
1
]
/
avgScale
;
float
sc2
=
m_scale
[
2
]
/
avgScale
;
positions
[
ind
]
=
0.23
f
*
sc0
;
ind
+=
7
;
positions
[
ind
]
=
0.23
f
*
sc1
;
ind
+=
7
;
positions
[
ind
]
=
0.23
f
*
sc2
;
ind
++
;
positions
[
ind
]
=
0.27
f
*
sc0
;
if
(
m_locked_axis
[
Xs
])
positions
[
ind
]
=
0.0
f
;
else
positions
[
ind
]
=
0.27
f
*
sc0
;
ind
+=
3
;
positions
[
ind
]
=
0.75
f
*
sc0
;
ind
+=
3
;
...
...
@@ -478,7 +503,10 @@ void FrameManipulator::setLengthAxes()
positions
[
ind
]
=
le
;
ind
+=
4
;
positions
[
ind
]
=
0.27
f
*
sc1
;
if
(
m_locked_axis
[
Ys
])
positions
[
ind
]
=
0.0
f
;
else
positions
[
ind
]
=
0.27
f
*
sc1
;
ind
+=
3
;
positions
[
ind
]
=
0.75
f
*
sc1
;
ind
+=
3
;
...
...
@@ -496,7 +524,10 @@ void FrameManipulator::setLengthAxes()
positions
[
ind
]
=
le
;
ind
+=
4
;
positions
[
ind
]
=
0.27
f
*
sc2
;
if
(
m_locked_axis
[
Zs
])
positions
[
ind
]
=
0.0
f
;
else
positions
[
ind
]
=
0.27
f
*
sc2
;
ind
+=
3
;
positions
[
ind
]
=
0.75
f
*
sc2
;
ind
+=
3
;
...
...
@@ -620,20 +651,131 @@ void FrameManipulator::setTransformation( const glm::mat4& transfo)
void
FrameManipulator
::
lock
(
unsigned
int
axis
)
{
m_locked_axis
[
axis
]
=
true
;
assert
(
axis
<=
Scales
);
switch
(
axis
)
{
case
Translations
:
m_locked_axis
[
Xt
]
=
true
;
m_locked_axis
[
Yt
]
=
true
;
m_locked_axis
[
Zt
]
=
true
;
break
;
case
Rotations
:
m_locked_axis
[
Xr
]
=
true
;
m_locked_axis
[
Yr
]
=
true
;
m_locked_axis
[
Zr
]
=
true
;
break
;
case
Scales
:
m_locked_axis
[
Xs
]
=
true
;
m_locked_axis
[
Ys
]
=
true
;
m_locked_axis
[
Zs
]
=
true
;
break
;
default:
m_locked_axis
[
axis
]
=
true
;
break
;
}
setLengthAxes
();
}
void
FrameManipulator
::
unlock
(
unsigned
int
axis
)
{
m_locked_axis
[
axis
]
=
false
;
assert
(
axis
<=
Scales
);
switch
(
axis
)
{
case
Translations
:
m_locked_axis
[
Xt
]
=
false
;
m_locked_axis
[
Yt
]
=
false
;
m_locked_axis
[
Zt
]
=
false
;
break
;
case
Rotations
:
m_locked_axis
[
Xr
]
=
false
;
m_locked_axis
[
Yr
]
=
false
;
m_locked_axis
[
Zr
]
=
false
;
break
;
case
Scales
:
m_locked_axis
[
Xs
]
=
false
;
m_locked_axis
[
Ys
]
=
false
;
m_locked_axis
[
Zs
]
=
false
;
break
;
default:
m_locked_axis
[
axis
]
=
false
;
break
;
}
setLengthAxes
();
}
bool
FrameManipulator
::
locked
(
unsigned
int
axis
)
{
assert
(
axis
<=
Zs
);
return
m_locked_axis
[
axis
];
}
void
FrameManipulator
::
lockPicking
(
unsigned
int
axis
)
{
assert
(
axis
<=
Scales
);
switch
(
axis
)
{
case
Translations
:
m_lockedPicking_axis
[
Xt
]
=
true
;
m_lockedPicking_axis
[
Yt
]
=
true
;
m_lockedPicking_axis
[
Zt
]
=
true
;
break
;
case
Rotations
:
m_lockedPicking_axis
[
Xr
]
=
true
;
m_lockedPicking_axis
[
Yr
]
=
true
;
m_lockedPicking_axis
[
Zr
]
=
true
;
break
;
case
Scales
:
m_lockedPicking_axis
[
Xs
]
=
true
;
m_lockedPicking_axis
[
Ys
]
=
true
;
m_lockedPicking_axis
[
Zs
]
=
true
;
break
;
default:
m_lockedPicking_axis
[
axis
]
=
true
;
break
;
}
setLengthAxes
();
}
void
FrameManipulator
::
unlockPicking
(
unsigned
int
axis
)
{
assert
(
axis
<=
Scales
);
switch
(
axis
)
{
case
Translations
:
m_lockedPicking_axis
[
Xt
]
=
false
;
m_lockedPicking_axis
[
Yt
]
=
false
;
m_lockedPicking_axis
[
Zt
]
=
false
;
break
;
case
Rotations
:
m_lockedPicking_axis
[
Xr
]
=
false
;
m_lockedPicking_axis
[
Yr
]
=
false
;
m_lockedPicking_axis
[
Zr
]
=
false
;
break
;
case
Scales
:
m_lockedPicking_axis
[
Xs
]
=
false
;
m_lockedPicking_axis
[
Ys
]
=
false
;
m_lockedPicking_axis
[
Zs
]
=
false
;
break
;
default:
m_lockedPicking_axis
[
axis
]
=
false
;
break
;
}
setLengthAxes
();
}
bool
FrameManipulator
::
lockedPicking
(
unsigned
int
axis
)
{
return
m_lockedPicking_axis
[
axis
];
}
Geom
::
Vec3f
FrameManipulator
::
getAxis
(
unsigned
int
ax
)
{
unsigned
int
i
=
(
ax
-
Xt
)
%
3
;
...
...
@@ -726,7 +868,7 @@ void FrameManipulator::rotateInScreen(int dx, int dy)
Geom
::
Vec3f
axisRotation
(
P
[
0
]
-
m_trans
[
0
],
P
[
1
]
-
m_trans
[
1
],
P
[
2
]
-
m_trans
[
2
]);
axisRotation
.
normalize
();
glm
::
mat4
tr
=
glm
::
rotate
(
glm
::
mat4
(
1.0
f
),
float
(
sqrt
f
(
dx
*
dx
+
dy
*
dy
))
/
2.0
f
,
glm
::
vec3
(
axisRotation
[
0
],
axisRotation
[
1
],
axisRotation
[
2
]));
glm
::
mat4
tr
=
glm
::
rotate
(
glm
::
mat4
(
1.0
f
),
float
(
sqrt
(
dx
*
dx
+
dy
*
dy
))
/
2.0
f
,
glm
::
vec3
(
axisRotation
[
0
],
axisRotation
[
1
],
axisRotation
[
2
]));
m_rotations
=
tr
*
m_rotations
;
}
...
...
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