Commit 17d7f87b authored by Jan Möbius's avatar Jan Möbius
Browse files

Dennis:

Translationmanipulator node autosize

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5317 383ad7c9-94d9-4d36-a494-682f7c89f535
parent fc152504
......@@ -114,7 +114,8 @@ TranslationManipulatorNode( BaseNode* _parent, const std::string& _name )
any_axis_over_(false),
any_top_over_(false),
origin_over_(false),
outer_ring_over_(false)
outer_ring_over_(false),
auto_size_(false)
{
localTransformation_.identity();
axis_ = gluNewQuadric();
......@@ -160,6 +161,7 @@ update_manipulator_system(GLState& _state)
_state.scale(1.0/scaling()[0], 1.0/scaling()[1], 1.0/scaling()[2]); // Adapt scaling
update_rotation(_state);
updateSize (_state);
}
//----------------------------------------------------------------------------
......@@ -498,6 +500,7 @@ void
TranslationManipulatorNode::draw(GLState& _state, unsigned int /* _drawMode */ )
{
if (draw_manipulator_) {
// Store lighting bits and enable lighting
glPushAttrib(GL_LIGHTING_BIT);
glEnable(GL_LIGHTING);
......@@ -578,6 +581,7 @@ TranslationManipulatorNode::mouseEvent(GLState& _state, QMouseEvent* _event)
Vec3d newPoint3D;
double old_axis_hit, new_axis_hit, new_axis_over;
updateSize (_state);
switch (_event->type()) {
......@@ -1448,6 +1452,8 @@ pick(GLState& _state, PickTarget _target)
if (draw_manipulator_) {
updateSize (_state);
_state.pick_set_maximum(5);
// Enable depth test but store original status
......@@ -1627,7 +1633,40 @@ TranslationManipulatorNode::directionZ() const
return MathTools::sane_normalized(localTransformation_.transform_vector(dirZ_));
}
//----------------------------------------------------------------------------
double TranslationManipulatorNode::get_screen_length (GLState& _state, Vec3d& _point) const
{
Vec3d proj = _state.project (_point);
proj[0] += 1.0;
Vec3d uproj = _state.unproject (proj);
uproj -= _point;
return uproj.length ();
}
//----------------------------------------------------------------------------
void TranslationManipulatorNode::updateSize (GLState& _state)
{
if (auto_size_)
{
Vec3d point = localTransformation_.transform_point(Vec3d (0.0, 0.0, 0.0));
int tmp, width, height;
_state.get_viewport (tmp, tmp, width, height);
double length = get_screen_length (_state, point) * (width + height) * 0.02;
manipulator_radius_ = set_manipulator_radius_ * length;
manipulator_height_ = set_manipulator_height_ * length;
}
else
{
manipulator_radius_ = set_manipulator_radius_;
manipulator_height_ = set_manipulator_height_;
}
}
//=============================================================================
} // namespace SceneGraph
......
......@@ -111,12 +111,18 @@ public:
Vec3d directionZ() const;
/// set cylindersize (height + radius)
void set_size( double _size) { manipulator_height_ = _size;
manipulator_radius_ = _size/10.0;
void set_size( double _size) { set_manipulator_height_ = _size;
set_manipulator_radius_ = _size/10.0;
setDirty (); }
/// get cylindersize
double size() const { return manipulator_height_; }
double size() const { return set_manipulator_height_; }
/// set auto size
void set_autosize (bool _enable) { auto_size_ = _enable; }
/// get autosize
bool autosize () const { return auto_size_; }
void rotate (double _angle, Vec3d _axis)
{
......@@ -175,6 +181,10 @@ private:
void updateTargetColors ();
bool updateCurrentColors (GLState& _state);
double get_screen_length (GLState& _state, Vec3d& _point) const;
void updateSize (GLState& _state);
// ELEMENTS
bool draw_manipulator_;
......@@ -185,6 +195,8 @@ private:
GLUquadricObj* axis_;
double manipulator_radius_;
double manipulator_height_;
double set_manipulator_radius_;
double set_manipulator_height_;
int manipulator_slices_;
int manipulator_stacks_;
......@@ -232,6 +244,8 @@ private:
Vec2i oldPoint2D_;
GLMatrixd localTransformation_;
bool auto_size_;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment