mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-04-26 01:34:40 +00:00
Merge pull request #112 from QuasarApp/task_110
Added groupobject obstacle red.
This commit is contained in:
commit
8bd9f35132
@ -22,10 +22,14 @@ void GroupObject::render(unsigned int tbfMsec) {
|
||||
for (ClasterItem* object: objects()) {
|
||||
|
||||
if (Localpropertys *props = getLocalpropertys(object->guiId())) {
|
||||
|
||||
if (!props->_rotation.isNull())
|
||||
object->setRotation(_this->rotation() * props->_rotation);
|
||||
|
||||
object->setposition(_this->position() + props->_position);
|
||||
QVector3D reCalcVectorPs = reCalcPos(props->_position,
|
||||
_this->rotation().toEulerAngles());
|
||||
|
||||
object->setposition(_this->position() + reCalcVectorPs);
|
||||
}
|
||||
|
||||
}
|
||||
@ -48,6 +52,31 @@ void GroupObject::updateRotation(int id, const QQuaternion &roatation) {
|
||||
_extrapropertys[id]._rotation = roatation;
|
||||
}
|
||||
|
||||
const QVector3D GroupObject::reCalcPos(const QVector3D& pos, const QVector3D &eulerAngles) const
|
||||
{
|
||||
float alha = eulerAngles.z();
|
||||
float beta = eulerAngles.y();
|
||||
float gamma = eulerAngles.x();
|
||||
|
||||
float x = pos.x();
|
||||
float y = pos.y();
|
||||
float z = pos.z();
|
||||
|
||||
float newX = x*(qCos(alha)*qCos(beta)) +
|
||||
y*(qCos(alha)*qSin(beta)*qSin(gamma) - qSin(alha)*qCos(gamma)) +
|
||||
z*(qCos(alha)*qSin(beta)*qCos(gamma) + qSin(alha)*qSin(gamma));
|
||||
|
||||
float newY = x*(qSin(alha)*qCos(beta)) +
|
||||
y*(qSin(alha)*qSin(beta)*qSin(gamma) + qCos(alha)*qCos(gamma)) +
|
||||
z*(qSin(alha)*qSin(beta)*qCos(gamma) - qCos(alha)*qSin(gamma));
|
||||
|
||||
float newZ = x*(-qSin(beta)) +
|
||||
y*(qCos(beta)*qSin(gamma)) +
|
||||
z*(qCos(beta)*qCos(gamma));
|
||||
|
||||
return QVector3D({newX, newY, newZ});
|
||||
}
|
||||
|
||||
QQuaternion *GroupObject::getLocalrotation(int id) {
|
||||
if (_extrapropertys.contains(id)) {
|
||||
return &_extrapropertys[id]._rotation;
|
||||
|
@ -123,6 +123,8 @@ protected:
|
||||
private:
|
||||
QHash<int, Localpropertys> _extrapropertys;
|
||||
|
||||
const QVector3D reCalcPos(const QVector3D& pos, const QVector3D& eulerAngles) const;
|
||||
|
||||
};
|
||||
}
|
||||
#endif // GROUPOBJECT_H
|
||||
|
@ -89,6 +89,7 @@ void Layout::drawSquare() {
|
||||
}
|
||||
|
||||
int height = qFloor(qSqrt(objects().size()));
|
||||
int width = qFloor(objects().size() / height);
|
||||
|
||||
int indObject = 0;
|
||||
for (auto idObj = objects().keyBegin(); idObj != objects().keyEnd(); idObj++) {
|
||||
@ -96,9 +97,8 @@ void Layout::drawSquare() {
|
||||
float x = indObject % height;
|
||||
float y = qCeil(indObject / height);
|
||||
|
||||
GroupObject::updatePosition(*idObj, {x + _distance,
|
||||
y + _distance,
|
||||
0});
|
||||
GroupObject::updatePosition(*idObj, {(x * _distance) - (height * _distance / 2),
|
||||
(y * _distance) - (width * _distance / 2), 0});
|
||||
indObject++;
|
||||
|
||||
}
|
||||
@ -113,8 +113,10 @@ void Layout::drawLine() {
|
||||
}
|
||||
|
||||
float xObject = 0;
|
||||
for (ClasterItem* object: objects()) {
|
||||
GroupObject::updatePosition(object->guiId(), {xObject + _distance, 0, 0});
|
||||
float height = objects().size() * _distance;
|
||||
for (auto idObj = objects().keyBegin(); idObj != objects().keyEnd(); idObj++) {
|
||||
|
||||
GroupObject::updatePosition(*idObj, {(xObject * _distance) - (height/2 * _distance), 0, 0});
|
||||
|
||||
xObject++;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "abslvlworld.h"
|
||||
#include <abslvlsnake.h>
|
||||
#include "Crawl/iworlditem.h"
|
||||
#include "groupobstaclered.h"
|
||||
|
||||
#include "Crawl/defaultlight.h"
|
||||
|
||||
@ -31,23 +32,23 @@ CRAWL::WorldRule *AbsLvlWorld::initWorldRules() {
|
||||
|
||||
return new CRAWL::WorldRule {
|
||||
|
||||
{0,
|
||||
{
|
||||
{registerObject<Baff>(), 10}, {registerObject<CRAWL::DefaultLight>(), 1}
|
||||
}
|
||||
},
|
||||
|
||||
{20,
|
||||
{200,
|
||||
{
|
||||
{registerObject<ObstacleBlue>(), 10}, {registerObject<CRAWL::DefaultLight>(), 1}
|
||||
}
|
||||
},
|
||||
|
||||
{30,
|
||||
{250,
|
||||
{
|
||||
{registerObject<ObstacleRed>(), 40}, {registerObject<CRAWL::DefaultLight>(), 1}
|
||||
{registerObject<GroupObstacleRed>(), 1}, {registerObject<CRAWL::DefaultLight>(), 1}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// {30,
|
||||
// {
|
||||
// {registerObject<ObstacleRed>(), 40}, {registerObject<CRAWL::DefaultLight>(), 1}
|
||||
// }
|
||||
// }
|
||||
|
||||
};
|
||||
}
|
||||
|
37
src/CrawlAbstractLvl/private/groupobstaclered.cpp
Normal file
37
src/CrawlAbstractLvl/private/groupobstaclered.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
//#
|
||||
//# 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 "obstaclerebitem.h"
|
||||
#include "groupobstaclered.h"
|
||||
|
||||
namespace AbstractLvl {
|
||||
|
||||
GroupObstacleRed::GroupObstacleRed(): CRAWL::IWorldItem(AUTO_CLASS_NAME) {
|
||||
|
||||
QQuaternion rotation =
|
||||
QQuaternion::fromEulerAngles(QVector3D(0,0,90));
|
||||
|
||||
setDistance(7);
|
||||
setRotation(rotation);
|
||||
changeLayout(CRAWL::LayoutType::LINE);
|
||||
|
||||
for(int i(0); i < 10; i++) {
|
||||
add(new ObstacleRebItem);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GroupObstacleRed::render(unsigned int tbfMsec) {
|
||||
Layout::render(tbfMsec);
|
||||
IWorldItem::render(tbfMsec);
|
||||
}
|
||||
|
||||
void GroupObstacleRed::init() {
|
||||
|
||||
}
|
||||
|
||||
}
|
27
src/CrawlAbstractLvl/private/groupobstaclered.h
Normal file
27
src/CrawlAbstractLvl/private/groupobstaclered.h
Normal file
@ -0,0 +1,27 @@
|
||||
//#
|
||||
//# 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 GROUPOBSTACLERED_H
|
||||
#define GROUPOBSTACLERED_H
|
||||
|
||||
#include "Crawl/layout.h"
|
||||
#include "Crawl/clasteritem.h"
|
||||
|
||||
namespace AbstractLvl {
|
||||
|
||||
class GroupObstacleRed: public CRAWL::Layout, public CRAWL::IWorldItem {
|
||||
public:
|
||||
GroupObstacleRed();
|
||||
|
||||
// IRender interface
|
||||
public:
|
||||
void render(unsigned int tbfMsec);
|
||||
void init();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // GROUPOBSTACLERED_H
|
20
src/CrawlAbstractLvl/private/obstaclerebitem.cpp
Normal file
20
src/CrawlAbstractLvl/private/obstaclerebitem.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
//#
|
||||
//# 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 "obstaclerebitem.h"
|
||||
|
||||
namespace AbstractLvl {
|
||||
|
||||
ObstacleRebItem::ObstacleRebItem() {
|
||||
|
||||
}
|
||||
|
||||
void ObstacleRebItem::render(unsigned int tbfMsec) {
|
||||
|
||||
}
|
||||
|
||||
}
|
26
src/CrawlAbstractLvl/private/obstaclerebitem.h
Normal file
26
src/CrawlAbstractLvl/private/obstaclerebitem.h
Normal file
@ -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.
|
||||
//#
|
||||
|
||||
#ifndef OBSTACLEREBITEM_H
|
||||
#define OBSTACLEREBITEM_H
|
||||
|
||||
#include "obstaclered.h"
|
||||
|
||||
namespace AbstractLvl {
|
||||
|
||||
class ObstacleRebItem: public ObstacleRed {
|
||||
public:
|
||||
ObstacleRebItem();
|
||||
|
||||
// IRender interface
|
||||
public:
|
||||
void render(unsigned int tbfMsec);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OBSTACLEREBITEM_H
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace AbstractLvl {
|
||||
|
||||
ObstacleRed::ObstacleRed() : IWorldItem(AUTO_CLASS_NAME) {
|
||||
ObstacleRed::ObstacleRed() : CRAWL::ClasterItem(AUTO_CLASS_NAME) {
|
||||
setMash("qrc:/mesh/meshes/ObstacleRed.mesh");
|
||||
setSize({1,1,1});
|
||||
setColor("#ff1927");
|
||||
|
@ -7,11 +7,11 @@
|
||||
|
||||
#ifndef OBJOBSTACLERED_H
|
||||
#define OBJOBSTACLERED_H
|
||||
#include "Crawl/iworlditem.h"
|
||||
#include "Crawl/clasteritem.h"
|
||||
|
||||
namespace AbstractLvl {
|
||||
|
||||
class ObstacleRed: public CRAWL::IWorldItem {
|
||||
class ObstacleRed: public CRAWL::ClasterItem {
|
||||
public:
|
||||
ObstacleRed();
|
||||
|
||||
|
@ -73,14 +73,16 @@ void GroupObjectTest::testBehavior() const {
|
||||
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.rotation() == (object.rotation() * localRotation));
|
||||
|
||||
object.updatePosition(item.guiId(), localPosition);
|
||||
object.setRotation(QQuaternion::fromEulerAngles(0,0,0));
|
||||
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user