[Interest] Rotating leaves

Igor Mironchik igor.mironchik at gmail.com
Sat Mar 31 10:00:03 CEST 2018


The task is simple on one side and complicated on another. I need to 
rotate a leaf around a branch to make leaf perpendicular to branch.

In theory all is simple...


Great. In the code I have...

const QVector3D branch(...);
const QVector3D leaf( 0.0f, 1.0f, 0.0f );
const QVector3D axis = QVector3D::crossProduct( branch, leaf );
const float cosPlainAngle = QVector3D::dotProduct( branch, leaf );
const float plainAngle = qRadiansToDegrees( std::acos( cosPlainAngle ) );
const QQuaternion quat = Qt3DCore::QTransform::fromAxisAndAngle( axis, 
plainAngle );
m_transform->setRotation( quat );

But it works correctly not in all situations. In some cases I need to 
increment plainAngle by 90.0 degrees.

So my question is what should I care in the code to handle all 
situations correctly?

Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180331/e0b5521a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20180331_104936.jpg
Type: image/jpeg
Size: 125570 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180331/e0b5521a/attachment.jpg>

More information about the Interest mailing list