mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-05-01 20:19:43 +00:00
commit
42a8035a83
src
Client/languages
Core
Crawl
day.hdefaultlight.cppgroupobject.cppgroupobject.hguiobject.cppguiobject.hiworld.cppiworld.hmoon.cppsnakeitem.cpp
CrawlModule
Extensions
CrawlAbstractLvl/private
CrawlTestLvl/private
JungleLvl/private
tests
@ -2,7 +2,7 @@
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="de">
|
||||
<context>
|
||||
<name>AbstractLevel::AbsLvlWorld</name>
|
||||
<name>AbstractLvl::AbsLvlWorld</name>
|
||||
<message>
|
||||
<source>This a abstract lvl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1">
|
||||
<context>
|
||||
<name>AbstractLevel::AbsLvlWorld</name>
|
||||
<name>AbstractLvl::AbsLvlWorld</name>
|
||||
<message>
|
||||
<source>This a abstract lvl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="ru">
|
||||
<context>
|
||||
<name>AbstractLevel::AbsLvlWorld</name>
|
||||
<name>AbstractLvl::AbsLvlWorld</name>
|
||||
<message>
|
||||
<source>This a abstract lvl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1">
|
||||
<context>
|
||||
<name>AbstractLevel::AbsLvlWorld</name>
|
||||
<name>AbstractLvl::AbsLvlWorld</name>
|
||||
<message>
|
||||
<source>This a abstract lvl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1">
|
||||
<context>
|
||||
<name>AbstractLevel::AbsLvlWorld</name>
|
||||
<name>AbstractLvl::AbsLvlWorld</name>
|
||||
<message>
|
||||
<source>This a abstract lvl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1">
|
||||
<context>
|
||||
<name>AbstractLevel::AbsLvlWorld</name>
|
||||
<name>AbstractLvl::AbsLvlWorld</name>
|
||||
<message>
|
||||
<source>This a abstract lvl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1">
|
||||
<context>
|
||||
<name>AbstractLevel::AbsLvlWorld</name>
|
||||
<name>AbstractLvl::AbsLvlWorld</name>
|
||||
<message>
|
||||
<source>This a abstract lvl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1">
|
||||
<context>
|
||||
<name>AbstractLevel::AbsLvlWorld</name>
|
||||
<name>AbstractLvl::AbsLvlWorld</name>
|
||||
<message>
|
||||
<source>This a abstract lvl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1">
|
||||
<context>
|
||||
<name>AbstractLevel::AbsLvlWorld</name>
|
||||
<name>AbstractLvl::AbsLvlWorld</name>
|
||||
<message>
|
||||
<source>This a abstract lvl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1">
|
||||
<context>
|
||||
<name>AbstractLevel::AbsLvlWorld</name>
|
||||
<name>AbstractLvl::AbsLvlWorld</name>
|
||||
<message>
|
||||
<source>This a abstract lvl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -42,7 +42,7 @@ template <class Sun, class Moon>
|
||||
};
|
||||
}
|
||||
* ```
|
||||
* @note All objects will be moving around this objects with radius. The Radius by default is 2000.
|
||||
* @note All objects will be moving around this objects with radius. The Radius by default is 1000.
|
||||
* @note This class automaticly sets ligth force for the light objects.
|
||||
*
|
||||
*
|
||||
@ -57,16 +57,13 @@ public:
|
||||
"The Day class can be works only with DayItem child classes");
|
||||
|
||||
DayItem* sun = new Sun(&position());
|
||||
DayItem* moon1 = new Moon(&position());
|
||||
DayItem* moon2 = new Moon(&position());
|
||||
DayItem* moon = new Moon(&position());
|
||||
|
||||
sun->setAnglePosition(0);
|
||||
moon1->setAnglePosition(225);
|
||||
moon2->setAnglePosition(135);
|
||||
moon->setAnglePosition(180);
|
||||
|
||||
add(sun);
|
||||
add(moon1);
|
||||
add(moon2);
|
||||
add(moon);
|
||||
|
||||
}
|
||||
|
||||
@ -146,7 +143,7 @@ public:
|
||||
|
||||
/**
|
||||
* @brief dayLengthSec This method return length of the game day in real secs.
|
||||
* @note by default this value is 60 sec
|
||||
* @note by default this value is 360 sec
|
||||
* @return length of the game day in real secs.
|
||||
*/
|
||||
float dayLengthSec() const {
|
||||
@ -187,7 +184,7 @@ private:
|
||||
}
|
||||
|
||||
int _radius = 1000;
|
||||
float _dayLengthSec = 20;
|
||||
float _dayLengthSec = 360;
|
||||
QVector3D _axis = {1,0,0};
|
||||
};
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace CRAWL {
|
||||
DefaultLight::DefaultLight(): IWorldLight(AUTO_CLASS_NAME) {
|
||||
setColor("#fff8e7");
|
||||
setposition({10000, 0, 10000});
|
||||
setRatation(QQuaternion::fromEulerAngles({-90,0,0}));
|
||||
setRotation(QQuaternion::fromEulerAngles({-90,0,0}));
|
||||
setLightForce(110);
|
||||
}
|
||||
|
||||
|
75
src/Core/Crawl/groupobject.cpp
Normal file
75
src/Core/Crawl/groupobject.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
//#
|
||||
//# Copyright (C) 2021-2021 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
#include "clasteritem.h"
|
||||
#include "groupobject.h"
|
||||
|
||||
namespace CRAWL {
|
||||
|
||||
GroupObject::GroupObject() {
|
||||
|
||||
}
|
||||
|
||||
void GroupObject::render(unsigned int tbfMsec) {
|
||||
Q_UNUSED(tbfMsec)
|
||||
|
||||
GuiObject* _this = checkminimumRequariedType<GuiObject>();
|
||||
|
||||
for (ClasterItem* object: objects()) {
|
||||
|
||||
if (LocalPropertyes *props = getLocalPropertyes(object->guiId())) {
|
||||
if (!props->_rotation.isNull())
|
||||
object->setRotation(_this->rotation() * props->_rotation);
|
||||
|
||||
object->setposition(_this->position() + props->_position);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void GroupObject::installObject(ClasterItem *object,
|
||||
const QVector3D &localPosition,
|
||||
const QQuaternion &localRotation) {
|
||||
|
||||
updatePosition(object->guiId(), localPosition);
|
||||
updateRotation(object->guiId(), localRotation);
|
||||
Claster::add(object);
|
||||
}
|
||||
|
||||
void GroupObject::updatePosition(int id, const QVector3D &position) {
|
||||
_extraPropertyes[id]._position = position;
|
||||
}
|
||||
|
||||
void GroupObject::updateRotation(int id, const QQuaternion &roatation) {
|
||||
_extraPropertyes[id]._rotation = roatation;
|
||||
}
|
||||
|
||||
QQuaternion *GroupObject::getLocalrotation(int id) {
|
||||
if (_extraPropertyes.contains(id)) {
|
||||
return &_extraPropertyes[id]._rotation;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QVector3D *GroupObject::getLocalPosition(int id) {
|
||||
if (_extraPropertyes.contains(id)) {
|
||||
return &_extraPropertyes[id]._position;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LocalPropertyes *GroupObject::getLocalPropertyes(int id) {
|
||||
if (_extraPropertyes.contains(id)) {
|
||||
return &_extraPropertyes[id];
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
128
src/Core/Crawl/groupobject.h
Normal file
128
src/Core/Crawl/groupobject.h
Normal file
@ -0,0 +1,128 @@
|
||||
//#
|
||||
//# Copyright (C) 2021-2021 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
#ifndef GROUPOBJECT_H
|
||||
#define GROUPOBJECT_H
|
||||
|
||||
|
||||
|
||||
#include <Crawl/irender.h>
|
||||
#include <Extensions/claster.h>
|
||||
|
||||
namespace CRAWL {
|
||||
|
||||
/**
|
||||
* @brief The LocalPropertyes struct This structure contains local propertyes of the all childs object of a GroupObject class object.
|
||||
*/
|
||||
struct LocalPropertyes {
|
||||
QVector3D _position = {0,0,0};
|
||||
QQuaternion _rotation = {};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The GroupObject class is extension with group object behavior.
|
||||
* ### Requried child classes: IWorldItem
|
||||
*
|
||||
* This class have implementation of the render method that move all child objects on selected local positions on parent object.
|
||||
*
|
||||
* ## Example of use
|
||||
*
|
||||
* ### For what this object uses
|
||||
*This object will be very convenient where you want to create a directly cluster object with multiple sub objects that should contains in the parent root object.
|
||||
* For example : weapon of the player.
|
||||
*
|
||||
* ### Example of use
|
||||
*
|
||||
* 1. create the Player class:
|
||||
*
|
||||
* ```cpp
|
||||
* const QVector3d weaponPosition = {1,0,0};
|
||||
* const QQuaternion weaponRotation = QQuaternion::fromEilorAngle(90,0,0);
|
||||
*
|
||||
* class Player: public IWorldItem, public GroupObject {
|
||||
* //... some implementation
|
||||
* void setWeapon(WeaponObject * weapon) {
|
||||
* installObject(weapon, weaponPosition, weaponRotation);
|
||||
* }
|
||||
* //... some implementation
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* All done. Now the weapon will be static on forward of the Player object.
|
||||
*
|
||||
* You can change the position and rotation of the weapon object using updatePosition and updateRotation methods.
|
||||
*
|
||||
* @note This class requried the GuiObject functions as a parent class.
|
||||
*/
|
||||
class GroupObject: public IRender, public Claster
|
||||
{
|
||||
public:
|
||||
GroupObject();
|
||||
|
||||
void render(unsigned int tbfMsec);
|
||||
|
||||
/**
|
||||
* @brief installObject This method is wrapper of the Claster::add method
|
||||
* but sets local position and local rotation for an @a object releative current object.
|
||||
* @param object This is pointer to the adding object.
|
||||
* @param localPosition This is local position of the @a object. The default value is current object center.
|
||||
* @param localRotation This is local rotation of the @a object. The default value is invalid quaternion and will be ignored..
|
||||
* @note The @a object should be disable own render method of a render method
|
||||
* or @a object should not be change position and rotation propertyes
|
||||
* @note if you want to ignore the local rotation functionality then set the @a localRotation argument to invalid or default value.
|
||||
*/
|
||||
void installObject(ClasterItem* object,
|
||||
const QVector3D& localPosition = {0,0,0},
|
||||
const QQuaternion& localRotation = {});
|
||||
|
||||
/**
|
||||
* @brief updatePosition This method sets new releative position of the child object.
|
||||
* @param id This is id of the object that position need to change.
|
||||
* @param position This is new value of the object position
|
||||
*/
|
||||
void updatePosition(int id, const QVector3D& position);
|
||||
|
||||
/**
|
||||
* @brief updateRotation This method sets new raleative rotation of the object with @a id.
|
||||
* @param id This is id of the object that rotation need to change
|
||||
* @param roatation This is new value of the object with @a id.
|
||||
*/
|
||||
void updateRotation(int id, const QQuaternion& roatation);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief getLocalrotation This method return current local rotation of the object with @a id.
|
||||
* @param id This is id of the object that rotation will be returned.
|
||||
* @return current local rotation ot the object winth @a id. IF the object with id not exists on this classter then return nullptr.
|
||||
* @warning use this return not const pointer and you can change them value without invoke the updatePosition method but this is not thread safe.
|
||||
*/
|
||||
QQuaternion* getLocalrotation(int id);
|
||||
|
||||
/**
|
||||
* @brief getLocalPosition This method return current local position of the object with @a id.
|
||||
* @param id This is id of the object that position will be returned.
|
||||
* @return current local position ot the object winth @a id. IF the object with id not exists on this classter then return nullptr.
|
||||
* @warning use this return not const pointer and you can change them value without invoke the updateRotation method but this is not thread safe.
|
||||
|
||||
*/
|
||||
QVector3D* getLocalPosition(int id);
|
||||
|
||||
/**
|
||||
* @brief getLocalPropertyes This method return all local propertyes of an object with @a id
|
||||
* @param id This is id of the object for getting changes.
|
||||
* @return pointer to structure with local propertyes of the object. IF the object with id not exists on this classter then return nullptr.
|
||||
* @warning use this return not const pointer and you can change them value but this is not thread safe.
|
||||
*/
|
||||
LocalPropertyes* getLocalPropertyes(int id);
|
||||
|
||||
|
||||
private:
|
||||
QHash<int, LocalPropertyes> _extraPropertyes;
|
||||
|
||||
};
|
||||
}
|
||||
#endif // GROUPOBJECT_H
|
@ -17,7 +17,7 @@ GuiObject::GuiObject(const QString &name, const QString &viewTempalte, QObject *
|
||||
_viewTemplate = viewTempalte;
|
||||
_className = name;
|
||||
generateId();
|
||||
setRatation(QQuaternion::fromEulerAngles({0,0,0}));
|
||||
setRotation(QQuaternion::fromEulerAngles({0,0,0}));
|
||||
}
|
||||
|
||||
const QString& GuiObject::color() const {
|
||||
@ -173,15 +173,15 @@ void GuiObject::setSize(const QVector3D &newSize) {
|
||||
emit sizeChanged();
|
||||
}
|
||||
|
||||
const QQuaternion &GuiObject::ratation() const {
|
||||
return _ratation;
|
||||
const QQuaternion &GuiObject::rotation() const {
|
||||
return _rotation;
|
||||
}
|
||||
|
||||
void GuiObject::setRatation(const QQuaternion &newRatation) {
|
||||
if (_ratation == newRatation)
|
||||
void GuiObject::setRotation(const QQuaternion &newRotation) {
|
||||
if (_rotation == newRotation)
|
||||
return;
|
||||
_ratation = newRatation;
|
||||
emit ratationChanged();
|
||||
_rotation = newRotation;
|
||||
emit rotationChanged();
|
||||
}
|
||||
|
||||
const QString &GuiObject::mash() const {
|
||||
|
@ -30,7 +30,7 @@ namespace CRAWL {
|
||||
*
|
||||
* The gui objct contains base properties for drow objects on scane
|
||||
* * position
|
||||
* * ratation
|
||||
* * rotation
|
||||
* * mash
|
||||
* * and map textures
|
||||
*
|
||||
@ -66,7 +66,7 @@ class CRAWL_EXPORT GuiObject: public QObject, virtual public IRender {
|
||||
|
||||
Q_PROPERTY(QVector3D position READ position WRITE setposition NOTIFY positionChanged)
|
||||
Q_PROPERTY(QVector3D size READ size WRITE setSize NOTIFY sizeChanged)
|
||||
Q_PROPERTY(QQuaternion ratation READ ratation WRITE setRatation NOTIFY ratationChanged)
|
||||
Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
|
||||
|
||||
Q_PROPERTY(QString mash READ mash WRITE setMash NOTIFY mashChanged)
|
||||
|
||||
@ -133,8 +133,8 @@ public:
|
||||
const QVector3D &size() const;
|
||||
void setSize(const QVector3D &newSize);
|
||||
|
||||
const QQuaternion &ratation() const;
|
||||
void setRatation(const QQuaternion &newRatation);
|
||||
const QQuaternion &rotation() const;
|
||||
void setRotation(const QQuaternion &newRotation);
|
||||
|
||||
const QString &mash() const;
|
||||
void setMash(const QString &newMash);
|
||||
@ -171,7 +171,7 @@ signals:
|
||||
|
||||
void positionChanged();
|
||||
void sizeChanged();
|
||||
void ratationChanged();
|
||||
void rotationChanged();
|
||||
|
||||
void mashChanged();
|
||||
|
||||
@ -217,7 +217,7 @@ private:
|
||||
|
||||
QVector3D _position;
|
||||
QVector3D _size;
|
||||
QQuaternion _ratation;
|
||||
QQuaternion _rotation;
|
||||
QString _mash;
|
||||
QString _className;
|
||||
bool _visible = true;
|
||||
|
@ -353,15 +353,15 @@ void IWorld::updateWorld() {
|
||||
}
|
||||
}
|
||||
|
||||
const QQuaternion &IWorld::cameraRatation() const {
|
||||
return _cameraRatation;
|
||||
const QQuaternion &IWorld::cameraRotation() const {
|
||||
return _cameraRotation;
|
||||
}
|
||||
|
||||
void IWorld::setCameraRatation(const QQuaternion &newCameraRatation) {
|
||||
if (_cameraRatation == newCameraRatation)
|
||||
void IWorld::setCameraRotation(const QQuaternion &newCameraRotation) {
|
||||
if (_cameraRotation == newCameraRotation)
|
||||
return;
|
||||
_cameraRatation = newCameraRatation;
|
||||
emit cameraRatationChanged();
|
||||
_cameraRotation = newCameraRotation;
|
||||
emit cameraRotationChanged();
|
||||
}
|
||||
|
||||
IAI *IWorld::backgroundAI() const {
|
||||
|
@ -49,7 +49,7 @@ class CRAWL_EXPORT IWorld : public QObject, public IRender
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QVector3D cameraReleativePosition READ cameraReleativePosition NOTIFY cameraReleativePositionChanged)
|
||||
Q_PROPERTY(QQuaternion cameraRatation READ cameraRatation NOTIFY cameraRatationChanged)
|
||||
Q_PROPERTY(QQuaternion cameraRotation READ cameraRotation NOTIFY cameraRotationChanged)
|
||||
Q_PROPERTY(QObject * player READ player WRITE setPlayer NOTIFY playerChanged)
|
||||
Q_PROPERTY(QString hdr READ hdr NOTIFY hdrChanged)
|
||||
|
||||
@ -210,10 +210,10 @@ public:
|
||||
IAI *backgroundAI() const;
|
||||
|
||||
/**
|
||||
* @brief cameraRatation This method return curent camera ratation.
|
||||
* @return Quaternion of camera ratation
|
||||
* @brief cameraRotation This method return curent camera rotation.
|
||||
* @return Quaternion of camera rotation
|
||||
*/
|
||||
const QQuaternion &cameraRatation() const;
|
||||
const QQuaternion &cameraRotation() const;
|
||||
|
||||
/**
|
||||
* @brief player This method return player object
|
||||
@ -263,9 +263,9 @@ signals:
|
||||
void worldStatusChanged();
|
||||
|
||||
/**
|
||||
* @brief cameraRatationChanged This method emited when ratation of the camera cahnged
|
||||
* @brief cameraRotationChanged This method emited when rotation of the camera cahnged
|
||||
*/
|
||||
void cameraRatationChanged();
|
||||
void cameraRotationChanged();
|
||||
|
||||
/**
|
||||
* @brief playerChanged This signal eited when player are changed.
|
||||
@ -320,10 +320,10 @@ protected:
|
||||
void setCameraReleativePosition(const QVector3D &newCameraReleativePosition);
|
||||
|
||||
/**
|
||||
* @brief setCameraRatation This method sets new ratation of the camera.
|
||||
* @param newCameraRatation new ratation of the camera.
|
||||
* @brief setCameraRotation This method sets new rotation of the camera.
|
||||
* @param newCameraRotation new rotation of the camera.
|
||||
*/
|
||||
void setCameraRatation(const QQuaternion &newCameraRatation);
|
||||
void setCameraRotation(const QQuaternion &newCameraRotation);
|
||||
|
||||
/**
|
||||
* @brief targetFps This method return current targetFps;
|
||||
@ -488,7 +488,7 @@ private:
|
||||
mutable QMutex _ItemsMutex;
|
||||
|
||||
QVector3D _cameraReleativePosition;
|
||||
QQuaternion _cameraRatation;
|
||||
QQuaternion _cameraRotation;
|
||||
|
||||
QString _hdrMap;
|
||||
WorldRule *_worldRules = nullptr;
|
||||
|
@ -10,7 +10,7 @@ namespace CRAWL {
|
||||
|
||||
Moon::Moon(const QVector3D* center):
|
||||
DayItem(center, AUTO_CLASS_NAME) {
|
||||
setColor("#022648");
|
||||
setColor("#6177ff");
|
||||
|
||||
}
|
||||
|
||||
|
@ -27,15 +27,15 @@ void SnakeItem::render(unsigned int tbfMsec) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto ratationVector = (_prevObject->position() - position());
|
||||
auto rotationVector = (_prevObject->position() - position());
|
||||
|
||||
if (auto claster = static_cast<Snake*>(parentClaster())) {
|
||||
float ratationLength = ratationVector.length();
|
||||
float rotationLength = rotationVector.length();
|
||||
|
||||
if (ratationLength > lengthBetwinItems() * 10) {
|
||||
if (rotationLength > lengthBetwinItems() * 10) {
|
||||
setposition(_prevObject->position());
|
||||
} else if (ratationLength > lengthBetwinItems()) {
|
||||
setMovableVector(ratationVector.normalized() * claster->currentMovableVector().length());
|
||||
} else if (rotationLength > lengthBetwinItems()) {
|
||||
setMovableVector(rotationVector.normalized() * claster->currentMovableVector().length());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ Node {
|
||||
}
|
||||
}
|
||||
|
||||
rotation: (model)? model.ratation: Qt.quaternion(0, 0, 0, 0)
|
||||
rotation: (model)? model.rotation: Qt.quaternion(0, 0, 0, 0)
|
||||
scale: (model)? model.size: Qt.vector3d(0, 0, 0);
|
||||
position: (model) ? model.position: Qt.vector3d(0,0,0);
|
||||
visible: sun.brightness
|
||||
|
@ -65,7 +65,7 @@ Model {
|
||||
(fMapColor)? objMaterial: defaultMaterial
|
||||
]
|
||||
|
||||
rotation: (model)? model.ratation: Qt.quaternion(0, 0, 0, 0)
|
||||
rotation: (model)? model.rotation: Qt.quaternion(0, 0, 0, 0)
|
||||
scale: (model)? model.size: Qt.vector3d(0, 0, 0);
|
||||
source: (model)? model.mash: "#Cube";
|
||||
position: (model) ? model.position: Qt.vector3d(0,0,0);
|
||||
|
@ -26,7 +26,7 @@ Node {
|
||||
|
||||
}
|
||||
|
||||
rotation: (model)? model.ratation: Qt.quaternion(0, 0, 0, 0)
|
||||
rotation: (model)? model.rotation: Qt.quaternion(0, 0, 0, 0)
|
||||
scale: (model)? model.size: Qt.vector3d(0, 0, 0);
|
||||
position: (model) ? model.position: Qt.vector3d(0,0,0);
|
||||
|
||||
|
@ -23,7 +23,7 @@ View3D {
|
||||
:
|
||||
Qt.vector3d(0,0,100)
|
||||
|
||||
rotation: (privateRoot.world)? privateRoot.world.cameraRatation: Qt.quaternion(0,0,0,0)
|
||||
rotation: (privateRoot.world)? privateRoot.world.cameraRotation: Qt.quaternion(0,0,0,0)
|
||||
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ void BaseMotion::setStaticRotation(const QQuaternion &newStaticRotation) {
|
||||
void BaseMotion::render(unsigned int tbfMsec) {
|
||||
if (auto _this = checkminimumRequariedType<GuiObject>()) {
|
||||
renderPosition(_this, tbfMsec);
|
||||
renderRatation(_this, tbfMsec);
|
||||
renderRotation(_this, tbfMsec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ class GuiObject;
|
||||
* @brief The BaseMotion class contains base functions of the motion.
|
||||
* For Create your own motion alghoritm you need to override two methods:
|
||||
* * renderPosition
|
||||
* * renderRatation
|
||||
* * renderRotation
|
||||
*/
|
||||
class CRAWL_EXPORT BaseMotion : public virtual IRender
|
||||
{
|
||||
@ -49,14 +49,14 @@ public:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief renderRatation This method recalc raration for an @a object. The Default do nothing.
|
||||
* @brief renderRotation This method recalc raration for an @a object. The Default do nothing.
|
||||
* @param object This is provessing object. Usually @a an object is casted pointer of this to GuiObject type.
|
||||
* @param tbfMsec This is time betwin frames argument. soame as in the IRender::render function.
|
||||
*/
|
||||
virtual void renderRatation(GuiObject* object, unsigned int tbfMsec) = 0;
|
||||
virtual void renderRotation(GuiObject* object, unsigned int tbfMsec) = 0;
|
||||
|
||||
/**
|
||||
* @brief renderRatation This method recalc position for an @a object.
|
||||
* @brief renderRotation This method recalc position for an @a object.
|
||||
* @param object This is provessing object. Usually @a an object is casted pointer of this to GuiObject type.
|
||||
* @param tbfMsec This is time betwin frames argument. soame as in the IRender::render function.
|
||||
*/
|
||||
|
@ -20,7 +20,7 @@ void CircularMotion::render(unsigned int tbfMsec) {
|
||||
|
||||
if (auto _this = checkminimumRequariedType<GuiObject>()) {
|
||||
renderPosition(_this, tbfMsec);
|
||||
renderRatation(_this, tbfMsec);
|
||||
renderRotation(_this, tbfMsec);
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,9 +56,9 @@ void CircularMotion::setAnglePosition(double newAngle) {
|
||||
_angle = newAngle;
|
||||
}
|
||||
|
||||
void CircularMotion::renderRatation(GuiObject *object,
|
||||
void CircularMotion::renderRotation(GuiObject *object,
|
||||
unsigned int ) {
|
||||
object->setRatation(QQuaternion::rotationTo({1.0f, 0.0, 0.0}, *_center) * staticRotation());
|
||||
object->setRotation(QQuaternion::rotationTo({1.0f, 0.0, 0.0}, *_center) * staticRotation());
|
||||
}
|
||||
|
||||
void CircularMotion::renderPosition(GuiObject *object,
|
||||
|
@ -80,14 +80,14 @@ public:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief renderRatation This method recalc raration for an @a object. The Default implementation rotate object to center.
|
||||
* @brief renderRotation This method recalc raration for an @a object. The Default implementation rotate object to center.
|
||||
* @param object This is provessing object. Usually @a an object is casted pointer of this to GuiObject type.
|
||||
* @param tbfMsec This is time betwin frames argument. soame as in the IRender::render function.
|
||||
*/
|
||||
void renderRatation(GuiObject* object, unsigned int) override;
|
||||
void renderRotation(GuiObject* object, unsigned int) override;
|
||||
|
||||
/**
|
||||
* @brief renderRatation This method recalc position for an @a object. The Default implementation move the current object around center.
|
||||
* @brief renderRotation This method recalc position for an @a object. The Default implementation move the current object around center.
|
||||
* @param object This is provessing object. Usually @a an object is casted pointer of this to GuiObject type.
|
||||
* @param tbfMsec This is time betwin frames argument. soame as in the IRender::render function.
|
||||
*/
|
||||
|
@ -21,7 +21,7 @@ void MovableObject::render(unsigned int tbfMsec) {
|
||||
|
||||
if (auto _this = checkminimumRequariedType<GuiObject>()) {
|
||||
renderPosition(_this, tbfMsec);
|
||||
renderRatation(_this, tbfMsec);
|
||||
renderRotation(_this, tbfMsec);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,9 +49,9 @@ void MovableObject::setBreakingForce(float newBreakingForce) {
|
||||
_breakingForce = newBreakingForce;
|
||||
}
|
||||
|
||||
void MovableObject::renderRatation(GuiObject *object, unsigned int) {
|
||||
void MovableObject::renderRotation(GuiObject *object, unsigned int) {
|
||||
if (_currentMovableVector.length() > 0) {
|
||||
object->setRatation(QQuaternion::rotationTo({1.0f, 0.0, 0.0}, _currentMovableVector) * staticRotation());
|
||||
object->setRotation(QQuaternion::rotationTo({1.0f, 0.0, 0.0}, _currentMovableVector) * staticRotation());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,14 +89,14 @@ public:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief renderRatation This method recalc raration for an @a object. The Default implementation converts movableVector to ratation of an @a object.
|
||||
* @brief renderRotation This method recalc raration for an @a object. The Default implementation converts movableVector to rotation of an @a object.
|
||||
* @param object This is provessing object. Usually @a an object is casted pointer of this to GuiObject type.
|
||||
* @param tbfMsec This is time betwin frames argument. soame as in the IRender::render function.
|
||||
*/
|
||||
void renderRatation(GuiObject* object, unsigned int tbfMsec) override;
|
||||
void renderRotation(GuiObject* object, unsigned int tbfMsec) override;
|
||||
|
||||
/**
|
||||
* @brief renderRatation This method recalc position for an @a object. The Default implementation move the current movable vector to setts movable vector. For example if you invoke the MovableObject::setMovableVector method then object change current movable vector with spead MovableObject::angularVelocity. If you sets
|
||||
* @brief renderRotation This method recalc position for an @a object. The Default implementation move the current movable vector to setts movable vector. For example if you invoke the MovableObject::setMovableVector method then object change current movable vector with spead MovableObject::angularVelocity. If you sets
|
||||
* @param object This is provessing object. Usually @a an object is casted pointer of this to GuiObject type.
|
||||
* @param tbfMsec This is time betwin frames argument. soame as in the IRender::render function.
|
||||
*/
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace AbstractLvl {
|
||||
|
||||
/**
|
||||
* @brief The AbsLvlControl class This controll support custom camera-ratation functions.
|
||||
* @brief The AbsLvlControl class This controll support custom camera-rotation functions.
|
||||
*/
|
||||
class AbsLvlControl: public CRAWL::DefaultControl
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ namespace AbstractLvl {
|
||||
|
||||
AbsLvlWorld::AbsLvlWorld() {
|
||||
setCameraReleativePosition({20,0,100});
|
||||
setCameraRatation(QQuaternion::fromEulerAngles({0,0,0}));
|
||||
setCameraRotation(QQuaternion::fromEulerAngles({0,0,0}));
|
||||
}
|
||||
|
||||
CRAWL::IPlayer *AbsLvlWorld::initPlayer() const {
|
||||
|
@ -16,7 +16,7 @@ Box::Box(): IWorldItem("Box") {
|
||||
setSize({2,2,2});
|
||||
setColor(QColor::fromRgb(rand()).name());
|
||||
|
||||
setRatation(QQuaternion::fromEulerAngles(
|
||||
setRotation(QQuaternion::fromEulerAngles(
|
||||
rand() % 360 ,
|
||||
rand() % 360,
|
||||
rand() % 360));
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace TestLvl {
|
||||
|
||||
/**
|
||||
* @brief The TestControl class This controll support custom camera-ratation functions.
|
||||
* @brief The TestControl class This controll support custom camera-rotation functions.
|
||||
*/
|
||||
class TestControl: public CRAWL::DefaultControl
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ namespace TestLvl {
|
||||
|
||||
World::World() {
|
||||
setCameraReleativePosition({50,0,100});
|
||||
setCameraRatation(QQuaternion::fromEulerAngles({0,0,0}));
|
||||
setCameraRotation(QQuaternion::fromEulerAngles({0,0,0}));
|
||||
}
|
||||
|
||||
CRAWL::WorldRule *World::initWorldRules() {
|
||||
@ -77,14 +77,14 @@ CRAWL::IAI *World::initBackGroundAI() const {
|
||||
}
|
||||
|
||||
void World::handleXViewChanged(double dx) {
|
||||
auto eilorRatation = cameraRatation().toEulerAngles();
|
||||
eilorRatation.setX(eilorRatation.x() + dx);
|
||||
setCameraRatation(QQuaternion::fromEulerAngles(eilorRatation));
|
||||
auto eilorRotation = cameraRotation().toEulerAngles();
|
||||
eilorRotation.setX(eilorRotation.x() + dx);
|
||||
setCameraRotation(QQuaternion::fromEulerAngles(eilorRotation));
|
||||
}
|
||||
|
||||
void World::handleYViewChanged(double dy) {
|
||||
auto eilorRatation = cameraRatation().toEulerAngles();
|
||||
eilorRatation.setY(eilorRatation.y() + dy );
|
||||
setCameraRatation(QQuaternion::fromEulerAngles(eilorRatation));
|
||||
auto eilorRotation = cameraRotation().toEulerAngles();
|
||||
eilorRotation.setY(eilorRotation.y() + dy );
|
||||
setCameraRotation(QQuaternion::fromEulerAngles(eilorRotation));
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ Egg::Egg(const QString name): CRAWL::IWorldItem(name)
|
||||
setMash(mashes[rand() % mashes.size()]);
|
||||
|
||||
setSize({1,1,1});
|
||||
setRatation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
setRotation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
}
|
||||
|
||||
void Egg::onIntersects(const IWorldItem *) {
|
||||
|
@ -13,7 +13,7 @@ Grees::Grees(): CRAWL::IWorldItem(AUTO_CLASS_NAME) {
|
||||
setMash("qrc:/mesh/meshes/Plant/Grass.mesh");
|
||||
setBaseColorMap("qrc:/mesh/meshes/Plant/Grass_Base.jpg");
|
||||
setSize({1,1,1});
|
||||
setRatation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
setRotation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ Ivy::Ivy(): CRAWL::IWorldItem(AUTO_CLASS_NAME) {
|
||||
|
||||
setBaseColorMap("qrc:/mesh/meshes/Plant/Ivy_Base.jpg");
|
||||
setSize({1,1,1});
|
||||
setRatation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
setRotation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
}
|
||||
|
||||
void Ivy::onIntersects(const IWorldItem *) {
|
||||
|
@ -12,7 +12,7 @@ LongGress::LongGress(): CRAWL::IWorldItem(AUTO_CLASS_NAME) {
|
||||
setMash("qrc:/mesh/meshes/Plant/Long_grass.mesh");
|
||||
setBaseColorMap("qrc:/mesh/meshes/Plant/LongGrass_Base.jpg");
|
||||
setSize({1,1,1});
|
||||
setRatation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
setRotation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
}
|
||||
|
||||
void LongGress::onIntersects(const IWorldItem *) {
|
||||
|
@ -20,7 +20,7 @@ Plant::Plant(): CRAWL::IWorldItem(AUTO_CLASS_NAME) {
|
||||
|
||||
setBaseColorMap("qrc:/mesh/meshes/Plant/Plant_Base.jpg");
|
||||
setSize({1,1,1});
|
||||
setRatation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
setRotation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
}
|
||||
|
||||
void Plant::onIntersects(const IWorldItem *) {
|
||||
|
@ -25,7 +25,7 @@ Stone::Stone(): CRAWL::IWorldItem(AUTO_CLASS_NAME)
|
||||
setNormalMap("qrc:/mesh/meshes/Stone/Stone_Normal.jpg");
|
||||
|
||||
setSize({1,1,1});
|
||||
setRatation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
setRotation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
}
|
||||
|
||||
void Stone::onIntersects(const IWorldItem *) {
|
||||
|
@ -23,7 +23,7 @@ Tree::Tree(): CRAWL::IWorldItem(AUTO_CLASS_NAME) {
|
||||
setMash(mashes[rand() % mashes.size()]);
|
||||
setBaseColorMap("qrc:/mesh/meshes/Plant/Tree_Base.jpg");
|
||||
setSize({1,1,1});
|
||||
setRatation(QQuaternion::fromEulerAngles({static_cast<float>(rand() % 60 - 30),
|
||||
setRotation(QQuaternion::fromEulerAngles({static_cast<float>(rand() % 60 - 30),
|
||||
static_cast<float>(rand() % 60 - 30),
|
||||
static_cast<float>(rand() % 360)}));
|
||||
|
||||
|
@ -28,7 +28,7 @@ Wood::Wood(): CRAWL::IWorldItem(AUTO_CLASS_NAME) {
|
||||
setNormalMap("qrc:/mesh/meshes/Wood/Wood_Normal.jpg");
|
||||
setRoughnessMap("qrc:/mesh/meshes/Wood/Wood_Roughness.jpg");
|
||||
setSize({1,1,1});
|
||||
setRatation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
setRotation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
}
|
||||
|
||||
void Wood::onIntersects(const IWorldItem *) {
|
||||
|
@ -30,7 +30,7 @@ namespace JungleLvl {
|
||||
|
||||
World::World() {
|
||||
setCameraReleativePosition({50,0,100});
|
||||
setCameraRatation(QQuaternion::fromEulerAngles({0,0,0}));
|
||||
setCameraRotation(QQuaternion::fromEulerAngles({0,0,0}));
|
||||
}
|
||||
|
||||
CRAWL::WorldRule *World::initWorldRules() {
|
||||
@ -117,15 +117,15 @@ CRAWL::IAI *World::initBackGroundAI() const {
|
||||
}
|
||||
|
||||
void World::handleXViewChanged(double dx) {
|
||||
auto eilorRatation = cameraRatation().toEulerAngles();
|
||||
eilorRatation.setX(eilorRatation.x() + dx);
|
||||
setCameraRatation(QQuaternion::fromEulerAngles(eilorRatation));
|
||||
auto eilorRotation = cameraRotation().toEulerAngles();
|
||||
eilorRotation.setX(eilorRotation.x() + dx);
|
||||
setCameraRotation(QQuaternion::fromEulerAngles(eilorRotation));
|
||||
}
|
||||
|
||||
void World::handleYViewChanged(double dy) {
|
||||
auto eilorRatation = cameraRatation().toEulerAngles();
|
||||
eilorRatation.setY(eilorRatation.y() + dy );
|
||||
setCameraRatation(QQuaternion::fromEulerAngles(eilorRatation));
|
||||
auto eilorRotation = cameraRotation().toEulerAngles();
|
||||
eilorRotation.setY(eilorRotation.y() + dy );
|
||||
setCameraRotation(QQuaternion::fromEulerAngles(eilorRotation));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <QtTest>
|
||||
#include "clasterstest.h"
|
||||
#include "groupobjecttest.h"
|
||||
|
||||
// Use This macros for initialize your own test classes.
|
||||
// Check exampletests
|
||||
@ -33,6 +34,7 @@ private slots:
|
||||
|
||||
// BEGIN TESTS CASES
|
||||
TestCase(clastersTest, ClastersTest)
|
||||
TestCase(groupObjectTest, GroupObjectTest)
|
||||
|
||||
// END TEST CASES
|
||||
|
||||
|
95
tests/units/groupobjecttest.cpp
Normal file
95
tests/units/groupobjecttest.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
//#
|
||||
//# Copyright (C) 2021-2021 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
|
||||
#include "groupobjecttest.h"
|
||||
#include "Crawl/groupobject.h"
|
||||
|
||||
#include <Crawl/clasteritem.h>
|
||||
|
||||
class TestGroupObject: public CRAWL::IWorldItem, public CRAWL::GroupObject {
|
||||
|
||||
public:
|
||||
|
||||
// IWorldItem interface
|
||||
TestGroupObject(): CRAWL::IWorldItem(AUTO_CLASS_NAME) {
|
||||
|
||||
}
|
||||
protected:
|
||||
void onIntersects(const IWorldItem *) override {};
|
||||
|
||||
// IRender interface
|
||||
void render(unsigned int tbfMsec) override {
|
||||
GroupObject::render(tbfMsec);
|
||||
};
|
||||
|
||||
void init() override {};
|
||||
|
||||
friend GroupObjectTest;
|
||||
};
|
||||
|
||||
class TestGroupObjectItem: public CRAWL::ClasterItem {
|
||||
|
||||
public:
|
||||
// IWorldItem interface
|
||||
|
||||
TestGroupObjectItem(): CRAWL::ClasterItem(AUTO_CLASS_NAME) {
|
||||
|
||||
}
|
||||
protected:
|
||||
void onIntersects(const IWorldItem *) override {};
|
||||
};
|
||||
|
||||
GroupObjectTest::GroupObjectTest() {
|
||||
|
||||
}
|
||||
|
||||
void GroupObjectTest::test() {
|
||||
testBehavior();
|
||||
}
|
||||
|
||||
void GroupObjectTest::testBehavior() const {
|
||||
TestGroupObject object;
|
||||
TestGroupObjectItem item;
|
||||
|
||||
object.setposition({100, 100, 0});
|
||||
object.setRotation(QQuaternion::fromEulerAngles(100,0,0));
|
||||
|
||||
object.installObject(&item);
|
||||
|
||||
// check if added object after install into claster or not
|
||||
QVERIFY(object.objects().size() == 1);
|
||||
|
||||
// The rotation and position of the main and child classes should be defferent
|
||||
QVERIFY(item.position() != object.position());
|
||||
QVERIFY(item.rotation() != object.rotation());
|
||||
|
||||
object.render(0);
|
||||
|
||||
// after invoke the render function all positions and rotations should be changed
|
||||
QVERIFY(item.position() == object.position());
|
||||
QVERIFY(item.rotation() == object.rotation());
|
||||
|
||||
QVector3D localPosition = {10,0,0};
|
||||
QQuaternion localRotation = QQuaternion::fromEulerAngles(0,5,0);
|
||||
|
||||
object.updatePosition(item.guiId(), localPosition);
|
||||
object.updateRotation(item.guiId(), localRotation);
|
||||
|
||||
object.render(0);
|
||||
|
||||
// after invoke the render function all positions and rotations should be changed
|
||||
QVERIFY(item.position() == (object.position() + localPosition));
|
||||
QVERIFY(item.rotation() == (object.rotation() * localRotation));
|
||||
|
||||
|
||||
object.remove(&item);
|
||||
|
||||
QVERIFY(object.objects().size() == 0);
|
||||
|
||||
|
||||
}
|
31
tests/units/groupobjecttest.h
Normal file
31
tests/units/groupobjecttest.h
Normal file
@ -0,0 +1,31 @@
|
||||
//#
|
||||
//# Copyright (C) 2021-2021 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
#include "test.h"
|
||||
#include "testutils.h"
|
||||
|
||||
|
||||
#ifndef GROUPOBJECTTEST_H
|
||||
#define GROUPOBJECTTEST_H
|
||||
|
||||
/**
|
||||
* @brief The GroupObjectTest class will be tests the CRAWL::GroupObject class from the core library.
|
||||
*/
|
||||
class GroupObjectTest: public Test, protected TestUtils
|
||||
{
|
||||
public:
|
||||
GroupObjectTest();
|
||||
void test();
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief testBehavior This method check the install objects on the main object.
|
||||
*/
|
||||
void testBehavior() const;
|
||||
};
|
||||
|
||||
#endif // GROUPOBJECTTEST_H
|
@ -5,6 +5,7 @@
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
#ifndef TEST_H
|
||||
#define TEST_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user