mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-05-11 08:59:46 +00:00
added movable object to engine
This commit is contained in:
parent
9fd228a539
commit
315435916b
src/Core/Crawl
@ -85,7 +85,6 @@ void ClientApp::initLvls() {
|
||||
}
|
||||
|
||||
_menu->setAvailableLvls(_availableWorlds);
|
||||
|
||||
}
|
||||
|
||||
IWorld *ClientApp::getLastWorld() {
|
||||
|
55
src/Core/Crawl/movableobject.cpp
Normal file
55
src/Core/Crawl/movableobject.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include "movableobject.h"
|
||||
|
||||
MovableObject::MovableObject(const QString &name,
|
||||
const QString &viewTempalte,
|
||||
QObject *ptr):
|
||||
IWorldItem(name, viewTempalte, ptr) {
|
||||
|
||||
}
|
||||
|
||||
void MovableObject::render(unsigned int tbfMsec) {
|
||||
|
||||
// get object center position
|
||||
QVector3D currentPosition = position();
|
||||
|
||||
// move object to vector
|
||||
currentPosition += (_currentMovableVector * tbfMsec / 1000);
|
||||
setposition(currentPosition);
|
||||
|
||||
// calc temp vector betvin user moveble vector and real moveble vector
|
||||
QVector3D tempVector = _currentMovableVector - _movableVector;
|
||||
|
||||
// calc change on this iteration for new moveble vector
|
||||
float delta = std::min(_angularVelocity * tbfMsec, tempVector.length());
|
||||
|
||||
// change temp vector
|
||||
tempVector *= delta;
|
||||
|
||||
// recalc new currentMovable vector
|
||||
_currentMovableVector += tempVector;
|
||||
|
||||
}
|
||||
|
||||
const QVector3D &MovableObject::movableVector() const {
|
||||
return _movableVector;
|
||||
}
|
||||
|
||||
void MovableObject::setMovableVector(const QVector3D &newMovableVector) {
|
||||
_movableVector = newMovableVector;
|
||||
}
|
||||
|
||||
float MovableObject::angularVelocity() const {
|
||||
return _angularVelocity;
|
||||
}
|
||||
|
||||
void MovableObject::setAngularVelocity(float newAngularVelocity) {
|
||||
_angularVelocity = newAngularVelocity;
|
||||
}
|
||||
|
||||
float MovableObject::breakingForce() const {
|
||||
return _breakingForce;
|
||||
}
|
||||
|
||||
void MovableObject::setBreakingForce(float newBreakingForce) {
|
||||
_breakingForce = newBreakingForce;
|
||||
}
|
79
src/Core/Crawl/movableobject.h
Normal file
79
src/Core/Crawl/movableobject.h
Normal file
@ -0,0 +1,79 @@
|
||||
#ifndef MOVABLEOBJECT_H
|
||||
#define MOVABLEOBJECT_H
|
||||
|
||||
#include "iworlditem.h"
|
||||
|
||||
/**
|
||||
* @brief The MovableObject class contains functions for moving object on the world.
|
||||
* All moving separate to next properties:
|
||||
*
|
||||
* * **Movable vector** This property sets direction of move
|
||||
* * **Movable vector force** This is force of the movable vector.
|
||||
* * **Angular velocity** This property sets spead of the angle moving.
|
||||
* * **Braking force** This property are delta decriment the Power of the movable vector on time.
|
||||
*/
|
||||
class MovableObject: public IWorldItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MovableObject(const QString& name,
|
||||
const QString& viewTempalte = DEFAULT_VIEW_TEMPLATE,
|
||||
QObject *ptr = nullptr);
|
||||
|
||||
/**
|
||||
* @brief render This impplementation of the render method add simulation of the physics in the vacuum space.
|
||||
* @param tbfMsec This is time betwin frames argument.
|
||||
*/
|
||||
void render(unsigned int tbfMsec) override;
|
||||
|
||||
/**
|
||||
* @brief movableVector This method return current mvable vector.
|
||||
* The movable vector it is second point of line betwin object center and movableVector point.
|
||||
* The movableVector base on own releative asix system wher the object center is vector {0 0 0}
|
||||
* @note So movableVector are 3d angle of the moving of this object.
|
||||
* @return movable vector of object
|
||||
*/
|
||||
const QVector3D &movableVector() const;
|
||||
|
||||
/**
|
||||
* @brief setMovableVector This method sets new value of the mvable vector.
|
||||
* @param newMovableVector - this is a new value ofthe movable vector
|
||||
*/
|
||||
void setMovableVector(const QVector3D &newMovableVector);
|
||||
|
||||
/**
|
||||
* @brief angularVelocity This method return current angular veloscity.
|
||||
* @return angular velosity
|
||||
* @note This property contains speed on angle per second (a/s)
|
||||
*/
|
||||
float angularVelocity() const;
|
||||
|
||||
/**
|
||||
* @brief setAngularVelocity This method sets new value of the angular velacity in angele per second
|
||||
* @param newAngularVelocity This is new value of the angular velacity
|
||||
*/
|
||||
void setAngularVelocity(float newAngularVelocity);
|
||||
|
||||
/**
|
||||
* @brief breakingForce This method return current value of the breaking force.
|
||||
* @return urrent value of the breaking force
|
||||
* @note This is resistance coefficient where 0 do not change movable vector and 1 stop moving on one second.
|
||||
*/
|
||||
float breakingForce() const;
|
||||
|
||||
/**
|
||||
* @brief setBreakingForce This method sets new value of the breaking force
|
||||
* @param newBreakingForce This is new value of the breaking force
|
||||
*/
|
||||
void setBreakingForce(float newBreakingForce);
|
||||
|
||||
private:
|
||||
QVector3D _movableVector;
|
||||
QVector3D _currentMovableVector;
|
||||
|
||||
float _angularVelocity = 0;
|
||||
float _breakingForce = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // MOVABLEOBJECT_H
|
Loading…
x
Reference in New Issue
Block a user