Commit 97021a80 authored by Jan Möbius's avatar Jan Möbius
Browse files

Dennis:

Allow-scaling-if-axes-are-rotated



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5733 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 11537ac2
......@@ -118,7 +118,7 @@ ManipulatorNode::
setup_cylinder_system(GLState& _state)
{
_state.translate(center()[0], center()[1], center()[2]);
_state.scale(1.0/scaling()[0], 1.0/scaling()[1], 1.0/scaling()[2]);
_state.mult_matrix(inverse_scale (), scale ()); // Adapt scaling
// rotation axis & angle
Vec3d z(0.0, 0.0, 1.0);
......@@ -444,7 +444,7 @@ ManipulatorNode::mapToSphere( GLState& _state,
_state.push_modelview_matrix();
_state.translate(center()[0], center()[1], center()[2]);
_state.scale(1.0f/scaling()[0], 1.0f/scaling()[1], 1.0f/scaling()[2]);
_state.mult_matrix(inverse_scale (), scale ());
_state.scale(cylinder_height_ + 4*cylinder_radius_);
_state.viewing_ray(x, y, origin, direction);
......
......@@ -122,7 +122,10 @@ public:
/// override TransformNode::setIdentity() (update radius_)
virtual void setIdentity() {
radius_ *= scaling().max();
Vec3d vec (1.0, 1.0, 1.0);
vec = scale ().transform_point(vec);
radius_ *= vec.max ();
TransformNode::setIdentity();
}
......
......@@ -78,8 +78,10 @@ loadIdentity()
inverse_rotation_matrix_.identity();
quaternion_.identity();
scale_matrix_.identity();
inverse_scale_matrix_.identity();
translation_ = Vec3d(0.0, 0.0, 0.0);
scaling_ = Vec3d(1.0, 1.0, 1.0);
}
......@@ -131,7 +133,22 @@ void
TransformNode::
scale(const Vec3d& _s)
{
scaling_ *= _s;
scale_matrix_.scale(_s);
inverse_scale_matrix_ = scale_matrix_;
inverse_scale_matrix_.invert();
updateMatrix();
}
//----------------------------------------------------------------------------
void
TransformNode::
scale(const GLMatrixd& _m)
{
scale_matrix_ *= _m;
inverse_scale_matrix_ = scale_matrix_;
inverse_scale_matrix_.invert();
updateMatrix();
}
......@@ -148,7 +165,7 @@ updateMatrix()
matrix_.translate(translation_);
matrix_.translate(center_);
matrix_ *= rotation_matrix_;
matrix_.scale(scaling_);
matrix_ *= scale_matrix_;
matrix_.translate(-center_);
......
......@@ -125,6 +125,9 @@ public:
/// Add scaling to the current Transformation.
void scale(const Vec3d& _s);
/// Add scaling to the current Transformation.
void scale(const GLMatrixd& _m);
//--- get values ---
......@@ -152,8 +155,14 @@ public:
/// returns ref. to translation vector
const Vec3d& translation() const { return translation_; }
/// returns scaling factor
const Vec3d& scaling() const { return scaling_; }
/// return scale matrix
const GLMatrixd& scale() const {
return scale_matrix_;
}
/// return inverse scale matrix
const GLMatrixd& inverse_scale() const {
return inverse_scale_matrix_;
}
bool apply_transformation() { return applyTransformation_; }
......@@ -168,10 +177,9 @@ private:
// ELEMENTS
GLMatrixd matrix_, inverse_matrix_;
GLMatrixd rotation_matrix_, inverse_rotation_matrix_;
GLMatrixd rotation_matrix_, inverse_rotation_matrix_, scale_matrix_, inverse_scale_matrix_;
Vec3d center_;
Vec3d translation_;
Vec3d scaling_;
Quaterniond quaternion_;
......
......@@ -153,7 +153,7 @@ TranslationManipulatorNode::
update_manipulator_system(GLState& _state)
{
_state.translate(center()[0], center()[1], center()[2]); // Follow translation of parent node
_state.scale(1.0/scaling()[0], 1.0/scaling()[1], 1.0/scaling()[2]); // Adapt scaling
_state.mult_matrix(inverse_scale (), scale ()); // Adapt scaling
update_rotation(_state);
updateSize (_state);
......@@ -935,15 +935,14 @@ TranslationManipulatorNode::mouseEvent(GLState& _state, QMouseEvent* _event)
xscale[1] = 0.0;
xscale[2] = 0.0;
xscale = localTransformation_.transform_vector(xscale);
GLMatrixd m = localTransformation_;
GLMatrixd mi = localTransformation_;
mi.invert ();
_state.push_modelview_matrix();
_state.translate(center()[0], center()[1], center()[2]);
scale( Vec3d(1.0, 1.0, 1.0) + xscale );
_state.pop_modelview_matrix();
m.scale(Vec3d(1.0, 1.0, 1.0) + xscale);
m *= mi;
scale (m);
}else
//translation
......@@ -980,14 +979,15 @@ TranslationManipulatorNode::mouseEvent(GLState& _state, QMouseEvent* _event)
yscale[1] = positive * ntrans.norm();
yscale[2] = 0.0;
yscale = localTransformation_.transform_vector(yscale);
GLMatrixd m = localTransformation_;
GLMatrixd mi = localTransformation_;
mi.invert ();
_state.push_modelview_matrix();
_state.translate(center()[0], center()[1], center()[2]);
m.scale(Vec3d(1.0, 1.0, 1.0) + yscale);
m *= mi;
scale( Vec3d(1.0, 1.0, 1.0) + yscale );
scale (m);
_state.pop_modelview_matrix();
}else
//translation
translate(ntrans);
......@@ -1023,14 +1023,15 @@ TranslationManipulatorNode::mouseEvent(GLState& _state, QMouseEvent* _event)
zscale[1] = 0.0;
zscale[2] = positive * ntrans.norm();
zscale = localTransformation_.transform_vector(zscale);
GLMatrixd m = localTransformation_;
GLMatrixd mi = localTransformation_;
mi.invert ();
_state.push_modelview_matrix();
_state.translate(center()[0], center()[1], center()[2]);
m.scale(Vec3d(1.0, 1.0, 1.0) + zscale);
m *= mi;
scale( Vec3d(1.0, 1.0, 1.0) + zscale );
scale (m);
_state.pop_modelview_matrix();
}else
//translation
translate(ntrans);
......
Supports Markdown
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