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

View File

@ -51,7 +51,7 @@ void MovableObject::setBreakingForce(float newBreakingForce) {
void MovableObject::renderRatation(GuiObject *object, unsigned int) { void MovableObject::renderRatation(GuiObject *object, unsigned int) {
if (_currentMovableVector.length() > 0) { 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 { const QVector3D &MovableObject::currentMovableVector() const {
return _currentMovableVector; return _currentMovableVector;
} }

View File

@ -10,6 +10,7 @@
#define MOVABLEOBJECT_H #define MOVABLEOBJECT_H
#include "Crawl/irender.h" #include "Crawl/irender.h"
#include <QQuaternion>
#include <QVector3D> #include <QVector3D>
namespace CRAWL { namespace CRAWL {
@ -85,6 +86,20 @@ public:
*/ */
const QVector3D &currentMovableVector() const; 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: protected:
/** /**
@ -104,6 +119,7 @@ protected:
private: private:
QVector3D _movableVector; QVector3D _movableVector;
QVector3D _currentMovableVector; QVector3D _currentMovableVector;
QQuaternion _staticRotation = QQuaternion::fromEulerAngles(0,0,0);
float _angularVelocity = 0; float _angularVelocity = 0;
float _breakingForce = 0; float _breakingForce = 0;

View File

@ -14,7 +14,8 @@ Snake::Snake(): CRAWL::Snake("JungleSnake") {
registerItemType<JungleLvl::SnakeItem>(); registerItemType<JungleLvl::SnakeItem>();
setMash("qrc:/mesh/meshes/Other/Snake_head.mesh"); setMash("qrc:/mesh/meshes/Other/Snake_head.mesh");
setBaseColorMap("qrc:/mesh/meshes/Other/Snake_Base.jpg"); 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));
} }

View File

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