mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-05-08 23:49:42 +00:00
fix render fucntion of movable objects
This commit is contained in:
parent
cccea19ee3
commit
b9f213b4a2
src
@ -1,4 +1,5 @@
|
||||
#include "movableobject.h"
|
||||
#include <QDebug>
|
||||
|
||||
MovableObject::MovableObject(const QString &name,
|
||||
const QString &viewTempalte,
|
||||
@ -13,14 +14,14 @@ void MovableObject::render(unsigned int tbfMsec) {
|
||||
QVector3D currentPosition = position();
|
||||
|
||||
// move object to vector
|
||||
currentPosition += (_currentMovableVector * tbfMsec / 1000);
|
||||
currentPosition += (_currentMovableVector * (tbfMsec / 1000.0));
|
||||
setposition(currentPosition);
|
||||
|
||||
// calc temp vector betvin user moveble vector and real moveble vector
|
||||
QVector3D tempVector = _currentMovableVector - _movableVector;
|
||||
QVector3D tempVector = _movableVector - _currentMovableVector ;
|
||||
|
||||
// calc change on this iteration for new moveble vector
|
||||
float delta = std::min(_angularVelocity * tbfMsec, tempVector.length());
|
||||
float delta = std::min(_angularVelocity * (tbfMsec / 1000.0), static_cast<double>(tempVector.length()));
|
||||
|
||||
// resize temp vector for calc changes of the movableVector
|
||||
tempVector = tempVector.normalized() * delta;
|
||||
@ -29,7 +30,7 @@ void MovableObject::render(unsigned int tbfMsec) {
|
||||
_currentMovableVector += tempVector;
|
||||
|
||||
// update movable vector
|
||||
_movableVector *= _breakingForce;
|
||||
_movableVector *= 1 - (_breakingForce * (tbfMsec / 1000.0));
|
||||
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ private:
|
||||
QVector3D _currentMovableVector;
|
||||
|
||||
float _angularVelocity = 0;
|
||||
float _breakingForce = 1;
|
||||
float _breakingForce = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit d23bfac78fa12f38aafaffc99955bcaea35e59a9
|
||||
Subproject commit de7d1fad23fea1ae447c3e499845d1dfe6bd9b40
|
Loading…
x
Reference in New Issue
Block a user