red #88 tmp light

This commit is contained in:
Andrei Yankovich 2021-07-16 15:34:12 +03:00
parent 821311c969
commit 207da5f954
13 changed files with 446 additions and 6 deletions

View File

@ -14,5 +14,6 @@
<file>CrawlModule/DefaultMenu.qml</file>
<file>CrawlModule/AbstractMenuView.qml</file>
<file>CrawlModule/Light.qml</file>
<file>CrawlModule/DayLight.qml</file>
</qresource>
</RCC>

103
src/Core/Crawl/daylight.cpp Normal file
View File

@ -0,0 +1,103 @@
//#
//# 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 "daylight.h"
#include <QTime>
namespace CRAWL {
DayLight::DayLight():
IWorldLight(AUTO_CLASS_NAME, "qrc:/CrawlModule/DayLight.qml") {
_curerntTime = new QTime(0,0,0);
_zeroTime = new QTime(0,0,0);
setposition({0, 0, 0});
setColor("#fff8e7");
setMoonColor("#fff8e7");
setSunLightForce(200);
setMoonLightForce(20);
}
DayLight::~DayLight() {
delete _curerntTime;
delete _zeroTime;
}
void DayLight::render(unsigned int tbfMsec) {
#define ONE_DAY (24 * 60 * 60)
#define DELTA (ONE_DAY / dayLengthSec)
#define TIME (tbfMsec / 1000.f)
*_curerntTime = _curerntTime->addSecs(DELTA * TIME);
#define ANGLE _zeroTime->secsTo(*_curerntTime) / static_cast<float>(ONE_DAY)
// setRatation(QQuaternion::fromEulerAngles({ANGLE, 0, 0}));
}
void DayLight::onIntersects(const IWorldItem *) {
}
int DayLight::sunLightForce() const {
return lightForce();
}
void DayLight::setSunLightForce(int newSunLightForce) {
setLightForce(newSunLightForce);
}
int DayLight::moonLightForce() const {
return _moonLightForce;
}
void DayLight::setMoonLightForce(int newMoonLightForce)
{
if (_moonLightForce == newMoonLightForce)
return;
_moonLightForce = newMoonLightForce;
emit moonLightForceChanged();
}
const QString &DayLight::sunColor() const {
return color();
}
void DayLight::setSunColor(const QString &newSunColor) {
setColor(newSunColor);
}
const QString &DayLight::moonColor() const {
return _moonColor;
}
void DayLight::setMoonColor(const QString &newMoonColor) {
if (_moonColor == newMoonColor)
return;
_moonColor = newMoonColor;
emit moonColorChanged();
}
const QTime &DayLight::curerntTime() const {
return *_curerntTime;
}
int DayLight::getDayLengthSec() const {
return dayLengthSec;
}
void DayLight::setDayLengthSec(int newDayLengthSec) {
dayLengthSec = newDayLengthSec;
}
void DayLight::resetTime() {
_curerntTime->setHMS(0,0,0,0);
}
}

128
src/Core/Crawl/daylight.h Normal file
View 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 DAYLIGHT_H
#define DAYLIGHT_H
#include "iworldlight.h"
namespace CRAWL {
/**
* @brief The DayLight class
*/
class CRAWL_EXPORT DayLight final: public IWorldLight
{
Q_OBJECT
Q_PROPERTY(QString moonColor READ moonColor NOTIFY moonColorChanged)
Q_PROPERTY(int moonLightForce READ moonLightForce NOTIFY moonLightForceChanged)
public:
DayLight();
~DayLight() override;
void render(unsigned int tbfMsec) override;
// IWorldItem interface
/**
* @brief getDayLengthSec This method return current value of the day length. by default one day = 60 sec.
* @return current value of the day length
*/
int getDayLengthSec() const;
/**
* @brief setDayLengthSec This method sets new value of the day length property.
* @param newDayLengthSec This is new value of the day length property.
*/
void setDayLengthSec(int newDayLengthSec);
/**
* @brief resetTime This method reset current day time to 0.
*/
void resetTime();
/**
* @brief curerntTime This method return current time of the day.
* @return current time of the day.
*/
const QTime &curerntTime() const;
/**
* @brief moonColor This method return current color of the moon object.
* @return current color of the moon object.
*/
const QString &moonColor() const;
/**
* @brief setMoonColor This method sets new value for the mool color.
* @param newMoonColor This is new value of the moonColor property
*/
void setMoonColor(const QString &newMoonColor);
/**
* @brief sunColor This method is wrapper of the color method.
* @return return current sun color.
*/
const QString &sunColor() const;
/**
* @brief setSunColor This method is wrapper of the setColor method.
* @param newSunColor sets new value of the color property
*/
void setSunColor(const QString &newSunColor);
/**
* @brief moonLightForce This method return current value of the light force for moon
* @return current value of the light force for moon
*/
int moonLightForce() const;
/**
* @brief setMoonLightForce This method sets new value of the moon light force.
* @param newMoonLightForce this is new value of the moon light force.
*/
void setMoonLightForce(int newMoonLightForce);
/**
* @brief sunLightForce This method is wrapper of the lightForce method
* @return current sun light force.
*/
int sunLightForce() const;
/**
* @brief setSunLightForce This method is wrapper of the setLightForce method.
* @param newSunLightForce this is new value of the sun light force
*/
void setSunLightForce(int newSunLightForce);
signals:
/**
* @brief moonColorChanged This signal emits when color of the moon has been changed.
*/
void moonColorChanged();
/**
* @brief moonColorChanged This signal emits when light force of the moon has been changed.
*/
void moonLightForceChanged();
protected:
void onIntersects(const IWorldItem *) override;
private:
int dayLengthSec = 60;
QTime *_curerntTime = nullptr;
QTime *_zeroTime = nullptr;
QString _moonColor;
int _moonLightForce;
};
}
#endif // DAYLIGHT_H

View File

@ -12,7 +12,7 @@ namespace CRAWL {
DefaultLight::DefaultLight(): IWorldLight(AUTO_CLASS_NAME) {
setColor("#fff8e7");
setposition({10000, 0, 10000});
setRatation(QQuaternion::fromEulerAngles({0,0,-90}));
setRatation(QQuaternion::fromEulerAngles({-90,0,0}));
setLightForce(110);
}

View File

@ -1,3 +1,11 @@
//#
//# 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 "diff.h"
namespace CRAWL {

View File

@ -20,11 +20,11 @@ GuiObject::GuiObject(const QString &name, const QString &viewTempalte, QObject *
setRatation(QQuaternion::fromEulerAngles({0,0,0}));
}
QString GuiObject::color() const {
const QString& GuiObject::color() const {
return _color;
}
void GuiObject::setColor(QString color) {
void GuiObject::setColor(const QString& color) {
if (_color == color)
return;

View File

@ -82,8 +82,8 @@ public:
const QString& viewTempalte = DEFAULT_VIEW_TEMPLATE,
QObject *ptr = nullptr);
QString color() const;
void setColor(QString color);
const QString &color() const;
void setColor(const QString &color);
virtual void reset();
QString viewTemplate() const;

View File

@ -0,0 +1,52 @@
//#
//# 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.
//#
import QtQuick 2.15
import QtQuick3D 1.15
Node {
id: graphicItem
property var model: null
property int guiId: (model) ? model.guiId : -1;
PointLight {
id : sun
position: Qt.vector3d(0, 0, 100);
brightness: (model)? model.lightForce: 100
color: (model)? model.color: "#ffffff"
castsShadow: (model)? model.castsShadow: 0
shadowFactor: (model)? model.shadowFactor: 0
shadowFilter: (model)? model.shadowFilter: 0
shadowMapFar: (model)? model.shadowMapFar: 0
shadowBias: (model)? model.shadowBias: 0
}
// PointLight {
// id: moon
// position: Qt.vector3d(0, 0, -10000);
// brightness: (model)? model.moonLightForce: 100
// color: (model)? model.moonColor: "#ffffff"
// castsShadow: (model)? model.castsShadow: 0
// shadowFactor: (model)? model.shadowFactor: 0
// shadowFilter: (model)? model.shadowFilter: 0
// shadowMapFar: (model)? model.shadowMapFar: 0
// shadowBias: (model)? model.shadowBias: 0
// eulerRotation: Qt.vector3d(90,0,0)
// }
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);
}

View File

@ -0,0 +1,54 @@
//#
//# 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 "circularmotion.h"
#include <Crawl/guiobject.h>
#include "cmath"
namespace CRAWL {
CircularMotion::CircularMotion(const QVector3D *center) {
_center = center;
}
void CircularMotion::render(unsigned int tbfMsec) {
if (auto _this = checkminimumRequariedType<GuiObject>()) {
if (!_center)
return;
double motionCoef = 360 / (2 * M_PI * radius());
_angle += motionCoef * angularVelocity() * (tbfMsec / 1000.f);
_this->setposition(*_center + (QQuaternion().fromAxisAndAngle(_axis, _angle).rotatedVector({0,0,0}).normalized() * radius()));
}
}
float CircularMotion::angularVelocity() const {
return _angularVelocity;
}
void CircularMotion::setAngularVelocity(float newAngularVelocity) {
_angularVelocity = newAngularVelocity;
}
const QVector3D &CircularMotion::axis() const {
return _axis;
}
void CircularMotion::setAxis(const QVector3D &newAxis) {
_axis = newAxis;
}
float CircularMotion::radius() const {
return _radius;
}
void CircularMotion::setRadius(float newRadius) {
_radius = newRadius;
}
}

View File

@ -0,0 +1,76 @@
//#
//# 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 <Crawl/irender.h>
#include <QVector3D>
#ifndef CIRCULARMOTION_H
#define CIRCULARMOTION_H
namespace CRAWL {
/**
* @brief The CircularMotion class. This class contains render function for the moving guiobject by round.
* @note For motion set motion asix and angular velocity
*/
class CRAWL_EXPORT CircularMotion: public IRender
{
public:
CircularMotion(const QVector3D* center);
// IRender interface
public:
void render(unsigned int tbfMsec) override;
/**
* @brief angularVelocity This is property are speed of motion.
* @return current speed of the motion object.
*/
float angularVelocity() const;
/**
* @brief setAngularVelocity This method sets new value of the current speed of the object.
* @param newAngularVelocity This is new value of the motion speed
*/
void setAngularVelocity(float newAngularVelocity);
/**
* @brief axis This method are asix of motion. This object will moving around this axis.
* @return curretn asix value.
*/
const QVector3D &axis() const;
/**
* @brief setAxis This method sets new value of the motion axis.
* @param newAxis This is new value of the motion asix.
*/
void setAxis(const QVector3D &newAxis);
/**
* @brief radius This method return current radius of the circular motion
* @return current radius
*/
float radius() const;
/**
* @brief setRadius This method sets new value of the circular motion radius.
* @param newRadius This is new value of the circular motion radius.
*/
void setRadius(float newRadius);
private:
float _angularVelocity = 0;
QVector3D _axis;
const QVector3D *_center = nullptr;
float _radius;
double _angle = 0;
};
}
#endif // CIRCULARMOTION_H

View File

@ -12,6 +12,7 @@
#include "world.h"
#include <testsnake.h>
#include "Crawl/iworlditem.h"
#include <Crawl/daylight.h>
#include <Crawl/defaultlight.h>
namespace TestLvl {
@ -26,7 +27,7 @@ CRAWL::WorldRule *World::initWorldRules() {
return new CRAWL::WorldRule {
{0, {{registerObject<Box>(), 1000},
{registerObject<Background>(), 1},
{registerObject<CRAWL::DefaultLight>(), 1}}}
{registerObject<CRAWL::DayLight>(), 1}}}
};
}

View File

@ -0,0 +1,6 @@
#include "junglesun.h"
JungleSun::JungleSun()
{
}

View File

@ -0,0 +1,11 @@
#ifndef JUNGLESUN_H
#define JUNGLESUN_H
class JungleSun
{
public:
JungleSun();
};
#endif // JUNGLESUN_H