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

Sebastian Messerschmidt sebastian.messerschmidt at gmx.de
Wed Aug 12 02:17:38 PDT 2015


Am 12.08.2015 um 11:05 schrieb Elias Tarasov:
> 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.

  Matrix rotate(rotation);
         Matrix translate = mt->getMatrix();
         Matrix setupTransAndRot = rotate * translate;

-> this will effectively multiply with the previous rotation, as you are 
getting the complete matrix and ADD your rotation by multiplying
Do something like:
setMatrix(mt->getTrans() * rotation);
> 2. It starts clockwise, but ends counter-clockwise.
Sampling artifact/aliasing. It is not turning the other direction, it 
just seems to, du to the sampling rate smaller than the rotation change.
See[0]

Btw: To achieve continuous rotation, you can use osgSim::DOFTransform. 
It can handle continuous rotation apart from other simulation-specific 
moving

[0] https://www.youtube.com/watch?v=7_5M4fnumBw&spfreload=10

Cheers
Sebastian
>
> Thank you!
>
> Cheers,
> Elias
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=64734#64734
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




More information about the osg-users mailing list