From f4ea42cc410dcc52cca366d0e94056831b011fae Mon Sep 17 00:00:00 2001 From: EndrII Date: Thu, 29 Jul 2021 21:51:31 +0300 Subject: [PATCH] added base group object --- src/Client/languages/de.ts | 2 +- src/Client/languages/en.ts | 2 +- src/Client/languages/es.ts | 2 +- src/Client/languages/fr.ts | 2 +- src/Client/languages/ja.ts | 2 +- src/Client/languages/pl.ts | 2 +- src/Client/languages/ru.ts | 2 +- src/Client/languages/tr.ts | 2 +- src/Client/languages/uk.ts | 2 +- src/Client/languages/zh.ts | 2 +- src/Core/Crawl/day.h | 15 ++--- src/Core/Crawl/groupobject.cpp | 75 +++++++++++++++++++++++++ src/Core/Crawl/groupobject.h | 100 +++++++++++++++++++++++++++++++++ src/Core/Crawl/moon.cpp | 2 +- 14 files changed, 192 insertions(+), 20 deletions(-) create mode 100644 src/Core/Crawl/groupobject.cpp create mode 100644 src/Core/Crawl/groupobject.h diff --git a/src/Client/languages/de.ts b/src/Client/languages/de.ts index 968f86b..053544d 100644 --- a/src/Client/languages/de.ts +++ b/src/Client/languages/de.ts @@ -2,7 +2,7 @@ - AbstractLevel::AbsLvlWorld + AbstractLvl::AbsLvlWorld This a abstract lvl diff --git a/src/Client/languages/en.ts b/src/Client/languages/en.ts index 8184365..948f1f9 100644 --- a/src/Client/languages/en.ts +++ b/src/Client/languages/en.ts @@ -2,7 +2,7 @@ - AbstractLevel::AbsLvlWorld + AbstractLvl::AbsLvlWorld This a abstract lvl diff --git a/src/Client/languages/es.ts b/src/Client/languages/es.ts index 15911d5..726a274 100644 --- a/src/Client/languages/es.ts +++ b/src/Client/languages/es.ts @@ -2,7 +2,7 @@ - AbstractLevel::AbsLvlWorld + AbstractLvl::AbsLvlWorld This a abstract lvl diff --git a/src/Client/languages/fr.ts b/src/Client/languages/fr.ts index 8184365..948f1f9 100644 --- a/src/Client/languages/fr.ts +++ b/src/Client/languages/fr.ts @@ -2,7 +2,7 @@ - AbstractLevel::AbsLvlWorld + AbstractLvl::AbsLvlWorld This a abstract lvl diff --git a/src/Client/languages/ja.ts b/src/Client/languages/ja.ts index 8184365..948f1f9 100644 --- a/src/Client/languages/ja.ts +++ b/src/Client/languages/ja.ts @@ -2,7 +2,7 @@ - AbstractLevel::AbsLvlWorld + AbstractLvl::AbsLvlWorld This a abstract lvl diff --git a/src/Client/languages/pl.ts b/src/Client/languages/pl.ts index 8184365..948f1f9 100644 --- a/src/Client/languages/pl.ts +++ b/src/Client/languages/pl.ts @@ -2,7 +2,7 @@ - AbstractLevel::AbsLvlWorld + AbstractLvl::AbsLvlWorld This a abstract lvl diff --git a/src/Client/languages/ru.ts b/src/Client/languages/ru.ts index 8184365..948f1f9 100644 --- a/src/Client/languages/ru.ts +++ b/src/Client/languages/ru.ts @@ -2,7 +2,7 @@ - AbstractLevel::AbsLvlWorld + AbstractLvl::AbsLvlWorld This a abstract lvl diff --git a/src/Client/languages/tr.ts b/src/Client/languages/tr.ts index 8184365..948f1f9 100644 --- a/src/Client/languages/tr.ts +++ b/src/Client/languages/tr.ts @@ -2,7 +2,7 @@ - AbstractLevel::AbsLvlWorld + AbstractLvl::AbsLvlWorld This a abstract lvl diff --git a/src/Client/languages/uk.ts b/src/Client/languages/uk.ts index 8184365..948f1f9 100644 --- a/src/Client/languages/uk.ts +++ b/src/Client/languages/uk.ts @@ -2,7 +2,7 @@ - AbstractLevel::AbsLvlWorld + AbstractLvl::AbsLvlWorld This a abstract lvl diff --git a/src/Client/languages/zh.ts b/src/Client/languages/zh.ts index 8184365..948f1f9 100644 --- a/src/Client/languages/zh.ts +++ b/src/Client/languages/zh.ts @@ -2,7 +2,7 @@ - AbstractLevel::AbsLvlWorld + AbstractLvl::AbsLvlWorld This a abstract lvl diff --git a/src/Core/Crawl/day.h b/src/Core/Crawl/day.h index ceccfb1..bc20a2b 100644 --- a/src/Core/Crawl/day.h +++ b/src/Core/Crawl/day.h @@ -42,7 +42,7 @@ template }; } * ``` - * @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}; }; diff --git a/src/Core/Crawl/groupobject.cpp b/src/Core/Crawl/groupobject.cpp new file mode 100644 index 0000000..d641dec --- /dev/null +++ b/src/Core/Crawl/groupobject.cpp @@ -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(); + + for (ClasterItem* object: objects()) { + + if (LocalPropertyes *props = getLocalPropertyes(object->guiId())) { + if (!props->_rotation.isNull()) + object->setRatation(_this->ratation() * 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; +} + +} diff --git a/src/Core/Crawl/groupobject.h b/src/Core/Crawl/groupobject.h new file mode 100644 index 0000000..ca14e63 --- /dev/null +++ b/src/Core/Crawl/groupobject.h @@ -0,0 +1,100 @@ +//# +//# 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 +#include + +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 extansion with group object behavior. + * ### Requeried functions: IWorldItem + * + * This class have implementation of the render method that move all child object on selected local positions in parent object. + * + */ +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 _extraPropertyes; + +}; +} +#endif // GROUPOBJECT_H diff --git a/src/Core/Crawl/moon.cpp b/src/Core/Crawl/moon.cpp index 19f38d5..298a185 100644 --- a/src/Core/Crawl/moon.cpp +++ b/src/Core/Crawl/moon.cpp @@ -10,7 +10,7 @@ namespace CRAWL { Moon::Moon(const QVector3D* center): DayItem(center, AUTO_CLASS_NAME) { - setColor("#022648"); + setColor("#6177ff"); }