added base group object

This commit is contained in:
Andrei Yankovich 2021-07-29 21:51:31 +03:00
parent c635561d92
commit f4ea42cc41
14 changed files with 192 additions and 20 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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};
};

View 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->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;
}
}

View File

@ -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 <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 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<int, LocalPropertyes> _extraPropertyes;
};
}
#endif // GROUPOBJECT_H

View File

@ -10,7 +10,7 @@ namespace CRAWL {
Moon::Moon(const QVector3D* center):
DayItem(center, AUTO_CLASS_NAME) {
setColor("#022648");
setColor("#6177ff");
}