4
1
mirror of https://github.com/QuasarApp/Snake.git synced 2025-05-10 16:39:45 +00:00

added Day object

This commit is contained in:
Andrei Yankovich 2021-07-18 11:50:45 +03:00
parent 207da5f954
commit 25b7d0ff88
22 changed files with 276 additions and 16 deletions

8
src/Core/Crawl/day.cpp Normal file

@ -0,0 +1,8 @@
//#
//# 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 "day.h"

118
src/Core/Crawl/day.h Normal file

@ -0,0 +1,118 @@
//#
//# 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 DAY_H
#define DAY_H
#include "Extensions/claster.h"
#include "dayitem.h"
#include "iworlditem.h"
namespace CRAWL {
template <class Sun, class Moon>
/**
* @brief The Day class is template wrapper for the moon and sun objects.
* The moon and sun objects moving around world center for imitation of the day.
* @note All objects will be moving around this objects with radius. The Radius by default is 10000.
*/
class Day: public IWorldItem, public Claster
{
public:
Day(): IWorldItem(AUTO_CLASS_NAME) {
static_assert(std::is_base_of_v<DayItem, Sun>,
"The Day class can be works only with DayItem child classes");
DayItem* sun = new Sun(position());
DayItem* moon = new Moon(position());
sun->setAnglePosition(0);
moon->setAnglePosition(180);
add(sun);
add(moon);
}
void render(unsigned int ) override {}
void add(ClasterItem *object) override {
if (auto item = dynamic_cast<DayItem*>(object)) {
item->setRadius(radius());
item->setAxis(_axis);
Claster::add(item);
} else {
QuasarAppUtils::Params::log("The Day class can works only with "
" Child classes of the DayItem",
QuasarAppUtils::Error);
}
};
void remove(ClasterItem *object) override {
Claster::remove(object);
};
/**
* @brief radius This method return radius of the motion day objects.
* @return radius of the motions
*/
int radius() const {
return _radius;
}
/**
* @brief setRadius This method sets new value of the motions radius.
* @param newRadius This is new value o fthe motion.
*/
void setRadius(int newRadius) {
if (newRadius == _radius)
return;
_radius = newRadius;
for (auto object: objects()) {
reinterpret_cast<DayItem*>(object)->setRadius(_radius);
}
}
/**
* @brief axis This is sxis of rotation. all objects will be moving around this axis. The axis is general 3d vector object.
* @return rotation axis.
*/
const QVector3D &axis() const {
return _axis;
}
/**
* @brief setAxis This method sets new value of the rotation axis. For get more information see the axis method.
* @param newAxis This is new value of the rotation axis.
*/
void setAxis(const QVector3D &newAxis) {
if (newAxis == _axis)
return;
_axis = newAxis;
for (auto object: objects()) {
reinterpret_cast<DayItem*>(object)->setAxis(_axis);
}
}
protected:
void onIntersects(const IWorldItem *) override {};
private:
int _radius = 10000;
QVector3D _axis;
};
}
#endif // DAY_H

@ -0,0 +1,26 @@
//#
//# 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 "dayitem.h"
namespace CRAWL {
DayItem::DayItem(
const QVector3D* center,
const QString &name,
const QString &viewTempalte,
QObject *ptr):
IWorldLight(name, viewTempalte, ptr),
CircularMotion(center) {
}
void DayItem::render(unsigned int tbfMsec) {
CircularMotion::render(tbfMsec);
}
}

29
src/Core/Crawl/dayitem.h Normal file

@ -0,0 +1,29 @@
//#
//# 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 DAYITEM_H
#define DAYITEM_H
#include "iworldlight.h"
#include "Extensions/circularmotion.h"
namespace CRAWL {
/**
* @brief The DayItem class This is base class of the sun of moon of anther movable around center objects.
*/
class DayItem: public IWorldLight, public CircularMotion {
Q_OBJECT
public:
DayItem(const QVector3D* center,
const QString& name,
const QString& viewTempalte = "qrc:/CrawlModule/Light.qml",
QObject *ptr = nullptr);
void render(unsigned int tbfMsec);
};
}
#endif // DAYITEM_H

@ -16,7 +16,7 @@ DayLight::DayLight():
_curerntTime = new QTime(0,0,0);
_zeroTime = new QTime(0,0,0);
setposition({0, 0, 0});
setposition({0, 0, 00});
setColor("#fff8e7");
setMoonColor("#fff8e7");
setSunLightForce(200);

@ -16,7 +16,7 @@ namespace CRAWL {
/**
* @brief The DayLight class
*/
class CRAWL_EXPORT DayLight final: public IWorldLight
class CRAWL_EXPORT DayLight: public IWorldLight
{
Q_OBJECT
Q_PROPERTY(QString moonColor READ moonColor NOTIFY moonColorChanged)

@ -5,9 +5,9 @@
//# of this license document, but changing it is not allowed.
//#
#include "clasteritem.h"
#include "groundclaster.h"
#include "iworld.h"
#include "clasteritem.h"
namespace CRAWL {
@ -45,7 +45,6 @@ void GroundClaster::render(unsigned int ) {
}
void GroundClaster::add(ClasterItem *object) {
object->setX(newObjectDistance() * _itemsOrder.count());
_itemsOrder.push_back(object);

@ -48,7 +48,7 @@ protected:
virtual int newObjectDistance() const;
private:
QList<IWorldItem*> _itemsOrder;
QList<ClasterItem*> _itemsOrder;
unsigned int _index = 0;
};

@ -9,6 +9,7 @@
#define GROUNDTILE_H
#include "clasteritem.h"
#include "iworlditem.h"
namespace CRAWL {

@ -218,7 +218,8 @@ void IWorld::removeItem(IWorldItem* item, QList<int> *removedObjectsList) {
if (auto claster = dynamic_cast<Claster*>(item)) {
const auto copyOfObjectsList = claster->objects();
for (auto item : copyOfObjectsList) {
if (!item || item->parentClastersCount() > 1)
auto clasterItem = dynamic_cast<ClasterItem*>(item);
if (!clasterItem || clasterItem->parentClastersCount() > 1)
continue;
int id = item->guiId();

@ -11,7 +11,7 @@ namespace CRAWL {
IWorldLight::IWorldLight(const QString &name,
const QString &viewTempalte,
QObject *ptr):
IWorldItem(name, viewTempalte, ptr) {
ClasterItem(name, viewTempalte, ptr) {
}

@ -5,7 +5,7 @@
//# of this license document, but changing it is not allowed.
//#
#include "iworlditem.h"
#include "clasteritem.h"
#ifndef IWORLDLIGHT_H
#define IWORLDLIGHT_H
@ -19,7 +19,7 @@ namespace CRAWL {
*
* @note If you wnat to create a new qml file the you need to inherit from the Light.qml file.
*/
class CRAWL_EXPORT IWorldLight: public IWorldItem
class CRAWL_EXPORT IWorldLight: public ClasterItem
{
Q_OBJECT
Q_PROPERTY(int lightForce READ lightForce WRITE setLightForce NOTIFY lightForceChanged)

@ -5,7 +5,6 @@
//# of this license document, but changing it is not allowed.
//#
#include "clasteritem.h"
#include "snake.h"
#include "snakeitem.h"
#include <QQuaternion>

@ -9,6 +9,7 @@
#ifndef SNAKEITEM_H
#define SNAKEITEM_H
#include "iworlditem.h"
#include "singleclasterworlditem.h"
#include "Extensions/movableobject.h"

@ -14,7 +14,7 @@ Node {
property var model: null
property int guiId: (model) ? model.guiId : -1;
PointLight {
SpotLight {
id : sun
position: Qt.vector3d(0, 0, 100);
@ -25,7 +25,10 @@ Node {
shadowFilter: (model)? model.shadowFilter: 0
shadowMapFar: (model)? model.shadowMapFar: 0
shadowBias: (model)? model.shadowBias: 0
eulerRotation.z: -90
coneAngle: 300
innerConeAngle: 0
}
@ -47,6 +50,6 @@ Node {
rotation: (model)? model.ratation: Qt.quaternion(0, 0, 0, 0)
scale: (model)? model.size: Qt.vector3d(0, 0, 0);
position: /*(model) ? model.position:*/ Qt.vector3d(0,0,0);
position: (model) ? model.position: Qt.vector3d(0,0,0);
}

@ -21,7 +21,7 @@ void AutoGenerateClaster::generateItems() {
return;
}
add(_factory());
add(factory());
}
}

@ -47,11 +47,11 @@ protected:
* @brief factory This method create new item of the claster. See the registerItemType for get more information.
* @return return new item of the claster item. If the object not registered return nullptr.
*/
ClasterItem* factory() const;
ClasterItem *factory() const;
/**
* @brief isClasterItemRegistered
* @return
* @return tru if the class is registered.
*/
bool isClasterItemRegistered() const;

@ -51,4 +51,12 @@ float CircularMotion::radius() const {
void CircularMotion::setRadius(float newRadius) {
_radius = newRadius;
}
double CircularMotion::anglePosition() const {
return _angle;
}
void CircularMotion::setAnglePosition(double newAngle) {
_angle = newAngle;
}
}

@ -63,6 +63,18 @@ public:
*/
void setRadius(float newRadius);
/**
* @brief anglePosition This method return current angel of the item position arountd center.
* @return current angle position around center.
*/
double anglePosition() const;
/**
* @brief setAnglePosition This method sets new angel of the item position arountd center.
* @return newAngle angle position around center.
*/
void setAnglePosition(double newAngle);
private:
float _angularVelocity = 0;
QVector3D _axis;

@ -14,7 +14,8 @@ Claster::Claster() {}
Claster::~Claster() {
for (auto child : qAsConst(_objects)) {
child->removeClaster(this);
if (auto obj = dynamic_cast<ClasterItem*>(child))
obj->removeClaster(this);
}
}

@ -0,0 +1,22 @@
//#
//# 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 "sun.h"
namespace JungleLvl {
Sun::Sun(const QVector3D* center):
CRAWL::DayItem(center, AUTO_CLASS_NAME) {
setColor("#f8d850");
setLightForce(1100);
}
void Sun::onIntersects(const IWorldItem *) {}
void Sun::init() {}
}

@ -0,0 +1,32 @@
//#
//# 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 SUN_H
#define SUN_H
#include "Crawl/dayitem.h"
namespace JungleLvl {
class Sun: public CRAWL::DayItem
{
Q_OBJECT
public:
Sun(const QVector3D* center);
// IWorldItem interface
protected:
void onIntersects(const IWorldItem *item);
// IRender interface
public:
void init();
};
}
#endif // SUN_H