Skip to content

Commit

Permalink
FIX: Fix speed of model rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzE authored and gabrielbmotta committed Nov 24, 2020
1 parent cacf58e commit c03f79b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void Renderable3DEntity::setRotY(float rotY)
return;
}

// Revert X rotation translation because we are in the set (not apply) function
// Revert Y rotation translation because we are in the set (not apply) function
QMatrix4x4 m = m_pTransform->matrix();
m.rotate(-m_fRotY + rotY, QVector3D(0.0f, 1.0f, 0.0f));
m_pTransform->setMatrix(m);
Expand Down Expand Up @@ -351,7 +351,7 @@ void Renderable3DEntity::setRotZ(float rotZ)
return;
}

// Revert X rotation translation because we are in the set (not apply) function
// Revert Z rotation translation because we are in the set (not apply) function
QMatrix4x4 m = m_pTransform->matrix();
m.rotate(-m_fRotZ + rotZ, QVector3D(0.0f, 0.0f, 1.0f));
m_pTransform->setMatrix(m);
Expand Down
30 changes: 18 additions & 12 deletions libraries/disp3D/engine/view/view3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,14 @@ void View3D::startModelRotationRecursive(QObject* pObject)
{
//TODO this won't work with QEntities
if(Renderable3DEntity* pItem = dynamic_cast<Renderable3DEntity*>(pObject)) {
QPropertyAnimation *anim = new QPropertyAnimation(pItem, QByteArrayLiteral("rotZ"));
anim->setDuration(30000);
anim->setStartValue(QVariant::fromValue(pItem->rotZ()));
anim->setEndValue(QVariant::fromValue(pItem->rotZ() + 360.0f));
anim->setLoopCount(-1);
anim->start();
m_lPropertyAnimations << anim;
if(!dynamic_cast<Renderable3DEntity*>(pItem->parent())) {
QPropertyAnimation *anim = new QPropertyAnimation(pItem, QByteArrayLiteral("rotZ"));
anim->setDuration(30000);
anim->setStartValue(QVariant::fromValue(pItem->rotZ()));
anim->setEndValue(QVariant::fromValue(pItem->rotZ() + 360.0f));
anim->setLoopCount(-1);
m_pParallelAnimationGroup->addAnimation(anim);
}
}

for(int i = 0; i < pObject->children().size(); ++i) {
Expand All @@ -378,7 +379,8 @@ void View3D::startModelRotationRecursive(QObject* pObject)

//=============================================================================================================

void View3D::setCameraRotation(float fAngle) {
void View3D::setCameraRotation(float fAngle)
{
m_pCamera->setPosition(QVector3D(0.0f, -0.4f, -0.25f));
m_pCamera->setViewCenter(QVector3D(0.0f, 0.0f, 0.0f));
m_pCamera->setUpVector(QVector3D(0.0f, 1.0f, 0.0f));
Expand All @@ -398,17 +400,21 @@ void View3D::setCameraRotation(float fAngle) {

void View3D::startStopModelRotation(bool checked)
{
if(!m_pParallelAnimationGroup) {
m_pParallelAnimationGroup = QSharedPointer<QParallelAnimationGroup>::create();
}

if(checked) {
//Start animation
m_lPropertyAnimations.clear();
m_pParallelAnimationGroup->clear();

for(int i = 0; i < m_p3DObjectsEntity->children().size(); ++i) {
startModelRotationRecursive(m_p3DObjectsEntity->children().at(i));
}

m_pParallelAnimationGroup->start();
}
else {
for(int i = 0; i < m_lPropertyAnimations.size(); ++i) {
m_lPropertyAnimations.at(i)->stop();
}
m_pParallelAnimationGroup->stop();
}
}
3 changes: 2 additions & 1 deletion libraries/disp3D/engine/view/view3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ class DISP3DSHARED_EXPORT View3D : public Qt3DExtras::Qt3DWindow
QPointer<Qt3DRender::QRenderCaptureReply> m_pScreenCaptureReply; /**< The capture reply object to save screenshots. */
QPointer<Qt3DRender::QObjectPicker> m_pPicker; /**< The Picker entity. */

QList<QPointer<QPropertyAnimation> > m_lPropertyAnimations; /**< The animations for each 3D object. */
QSharedPointer<QParallelAnimationGroup> m_pParallelAnimationGroup; /**< The animations for each 3D object. */

QList<QPointer<Qt3DRender::QPointLight> > m_lLightSources; /**< The light sources. */

signals:
Expand Down

0 comments on commit c03f79b

Please sign in to comment.