4
1
mirror of https://github.com/QuasarApp/Snake.git synced 2025-05-04 05:29:45 +00:00

ref 74 "fix snake body"

This commit is contained in:
Andrei Yankovich 2021-07-11 01:10:46 +03:00
parent 66c3fd78d1
commit c6fb56513d
4 changed files with 28 additions and 3 deletions

@ -51,7 +51,7 @@ void MovableObject::setBreakingForce(float newBreakingForce) {
void MovableObject::renderRatation(GuiObject *object, unsigned int) {
if (_currentMovableVector.length() > 0) {
object->setRatation(QQuaternion::rotationTo({1.0f, 0.0, 0.0}, _currentMovableVector));
object->setRatation(QQuaternion::rotationTo({1.0f, 0.0, 0.0}, _currentMovableVector) * staticRotation());
}
}
@ -87,6 +87,14 @@ void MovableObject::renderPosition(GuiObject *object, unsigned int tbfMsec) {
}
const QQuaternion &MovableObject::staticRotation() const {
return _staticRotation;
}
void MovableObject::setStaticRotation(const QQuaternion &newStaticRotation) {
_staticRotation = newStaticRotation;
}
const QVector3D &MovableObject::currentMovableVector() const {
return _currentMovableVector;
}

@ -10,6 +10,7 @@
#define MOVABLEOBJECT_H
#include "Crawl/irender.h"
#include <QQuaternion>
#include <QVector3D>
namespace CRAWL {
@ -85,6 +86,20 @@ public:
*/
const QVector3D &currentMovableVector() const;
/**
* @brief staticRotation This method retur nstatic rotation in quaternion. The static rotation rotate object to setted value independet then movable vector.
* @return quterion of the static rotation
*/
const QQuaternion &staticRotation() const;
/**
* @brief setStaticRotation This metho sets new value of the static rotation of this object.
* @param newStaticRotation new value of the static rotation.
* @note if you want use eilor angles then use the QQuaternion::fromEulerAngles method.
* @note See the staticRotation method for get more information.
*/
void setStaticRotation(const QQuaternion &newStaticRotation);
protected:
/**
@ -104,6 +119,7 @@ protected:
private:
QVector3D _movableVector;
QVector3D _currentMovableVector;
QQuaternion _staticRotation = QQuaternion::fromEulerAngles(0,0,0);
float _angularVelocity = 0;
float _breakingForce = 0;

@ -14,7 +14,8 @@ Snake::Snake(): CRAWL::Snake("JungleSnake") {
registerItemType<JungleLvl::SnakeItem>();
setMash("qrc:/mesh/meshes/Other/Snake_head.mesh");
setBaseColorMap("qrc:/mesh/meshes/Other/Snake_Base.jpg");
setSize({1,1,1});
setSize({1.5,1.5,1.5});
setStaticRotation(QQuaternion::fromEulerAngles(0,90,-90));
}

@ -12,7 +12,7 @@ namespace JungleLvl {
SnakeItem::SnakeItem(): CRAWL::SnakeItem("JungleSnakeItem") {
setMash("qrc:/mesh/meshes/Other/Snake_body.mesh");
setBaseColorMap("qrc:/mesh/meshes/Other/Snake_Base.jpg");
setSize({1,1,1});
setSize({2,2,2});
}
void SnakeItem::init() {