[osg-users] Rotation of a node starts clockwise and ends counter-clockwise.

Elias Tarasov elias.tarasov at gmail.com
Wed Aug 12 02:05:39 PDT 2015


Hi!

My node which i want to rotate is a propeller, and let say it should rotate 60 times per second (60 rps).
My notebook's screen has 60Hz and i have read somewhere that this leads to call NodeCallback::operator() 60 times per second
(for optimization reason, but it's only my assumption).
Let also say that deltaAngle is an angle i want to rotate my propeller for each time operator() is called (60 Hz -> 60 times per second in my case).
Then for needed 60 rps i have:
Code:

deltaAngle = 2.0 * osg::Pi / (60 * 60) 


rad, is that correct?
If it is, then my callback operator is:

Code:

class UpdateCallback : public NodeCallback {
public:
	UpdateCallback() : angle(0.0), deltaAngle(2.0f * osg::PI / 3600.0f),  rotation() {}
		virtual void operator () (Node* node, NodeVisitor* nv) {
			MatrixTransform* mt = dynamic_cast<MatrixTransform*>( node );
			if ( mt != NULL ) {
				if(angle < 2.0f * osg::PI)
					angle += deltaAngle;
				else
					angle = 0.0;
        rotation.makeRotate(angle, Y_AXIS);
        Matrix rotate(rotation);
        Matrix translate = mt->getMatrix();
        Matrix setupTransAndRot = rotate * translate;
        mt->setMatrix(setupTransAndRot);
      }
      traverse(node,nv);
    }
private:
	double angle;
  const double deltaAngle;
  Quat rotation;
};



The video of running program https://drive.google.com/file/d/0ByDDImhSolf6SS1fREJZTG1aNDA/view?usp=sharing
displays 2 issues:
1. Somehow rotation is not linear, but instead has acceleration.
2. It starts clockwise, but ends counter-clockwise.

Thank you!

Cheers,
Elias

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64734#64734








More information about the osg-users mailing list