updare resources

This commit is contained in:
Andrei Yankovich 2021-07-11 14:45:30 +03:00
parent c6fb56513d
commit e82ad370a1
11 changed files with 135 additions and 31 deletions

View File

@ -29,6 +29,10 @@ Snake::Snake(const QString &name, const QString &viewTempalte, QObject *ptr):
setScales({{0, 0.8},
{0.4, 1.2},
{1, 0.5}});
setLengthBetwinItemsMap({{0, 0.8},
{0.4, 1.2},
{1, 0.5}});
}
Snake::~Snake( ){
@ -86,43 +90,65 @@ void Snake::onTap() {
setMovableVector(_vectors[_clickIndex++ % 2]);
}
void Snake::generateItems() {
auto scaleIt = _scales.begin();
float CRAWL::Snake::getValueFromMap(const QMap<float, float> &map,
float position,
float defaultValue) {
auto it = map.cbegin();
float from = 0, fromKey = 0;
float to = scaleIt.value(), toKey = scaleIt.key();
float to = it.value(), toKey = it.key();
if (it != _scales.cend()) {
while (position >= it.key() && it != _scales.cend()) {
it++;
if (it != _scales.cend()) {
from = to;
to = it.value();
fromKey = toKey;
toKey = it.key();
}
}
return ((position - fromKey) * toKey / (to - from)) + from;
}
return defaultValue;
}
void Snake::generateItems() {
for(unsigned int i = 0; i < itemsCount(); ++i) {
auto item = factory();
SnakeItem* item = dynamic_cast<SnakeItem*>(factory());
if (!item)
if (!item) {
QuasarAppUtils::Params::log("The snake item class should be child class"
" of the SnakeItem class.",
QuasarAppUtils::Error);
return;
float scale = 1;
if (scaleIt != _scales.end()) {
float position = static_cast<float>(i) / itemsCount();
while (position >= scaleIt.key() && scaleIt != _scales.end()) {
scaleIt++;
if (scaleIt != _scales.end()) {
from = to;
to = scaleIt.value();
fromKey = toKey;
toKey = scaleIt.key();
}
}
scale = ((position - fromKey) * toKey / (to - from)) + from;
}
float scale = getValueFromMap(_scales,
static_cast<float>(i) / itemsCount());
float lengthBIt = getValueFromMap(_lengthBetwinItemsMap,
static_cast<float>(i) / itemsCount());
item->setSize(item->size() * scale);
item->setLengthBetwinItems(lengthBIt);
add(item);
}
}
const QMap<float, float> &Snake::lengthBetwinItemsMap() const {
return _lengthBetwinItemsMap;
}
void Snake::setLengthBetwinItemsMap(const QMap<float, float> &newLengthBetwinItemsMap) {
_lengthBetwinItemsMap = newLengthBetwinItemsMap;
}
float Snake::speed() const {
return _speed;
}

View File

@ -81,6 +81,39 @@ public:
unsigned int itemsCount() const override;
/**
* @brief lengthBetwinItemsMap This method return map with lengths betwin items.
* The key of map are position of snake Body and the value are length betwin this current and parent items.
* The default map of snake are:
* ```
* 0.0 - 0.8
* 0.6 - 1.2
* 1 - 0.5
* ```
* @return length betwin items map of snake body.
*/
const QMap<float, float> &lengthBetwinItemsMap() const;
/**
* @brief setLengthBetwinItemsMap This method sets new valud of the length betwin items map.
* @param newLengthBetwinItemsMap this is new value of the length betwin tems map.
* @note for get more information see the lengthBetwinItemsMap method.
*/
void setLengthBetwinItemsMap(const QMap<float, float> &newLengthBetwinItemsMap);
/**
* @brief getValueFromMap This method return near value from the map by position.
* @param map This is map that contains list of the values.
* @param position This requried position from map.
* @param defaultValue This value will be returned when map are empty.
* @return near value of the requried position.
*
* @note This function works as a gradient.
*/
float getValueFromMap(const QMap<float, float> &map,
float position,
float defaultValue = 1);
protected slots:
void onTap() override;
@ -88,7 +121,9 @@ protected slots:
private:
void generateItems() override;
QMap<float, float> _scales;
QMap<float, float> _lengthBetwinItemsMap;
float _lengthBetwinItems;
const IWorldItem* _lastSnakeItem = nullptr;

View File

@ -32,9 +32,9 @@ void SnakeItem::render(unsigned int tbfMsec) {
if (auto claster = static_cast<Snake*>(parentClaster())) {
float ratationLength = ratationVector.length();
if (ratationLength > claster->lengthBetwinItems() * 10) {
if (ratationLength > lengthBetwinItems() * 10) {
setposition(_prevObject->position());
} else if (ratationLength > claster->lengthBetwinItems()) {
} else if (ratationLength > lengthBetwinItems()) {
setMovableVector(ratationVector.normalized() * claster->currentMovableVector().length());
}
}
@ -45,4 +45,12 @@ void SnakeItem::render(unsigned int tbfMsec) {
const IWorldItem * SnakeItem::prev() const {
return _prevObject;
}
float SnakeItem::lengthBetwinItems() const {
return _lengthBetwinItems;
}
void SnakeItem::setLengthBetwinItems(float newLengthBetwinItems) {
_lengthBetwinItems = newLengthBetwinItems;
}
}

View File

@ -36,8 +36,22 @@ public:
*/
const IWorldItem * prev() const;
/**
* @brief lengthBetwinItems This method return current length betwin current and parew item.
* @return current length betwin current and parew item.
* @note See also the setPrev method.
*/
float lengthBetwinItems() const;
/**
* @brief setLengthBetwinItems This method sets new valeu of the length betwin current and parew item.
* @param newLengthBetwinItems This is new value of the length betwin current and parew item.
*/
void setLengthBetwinItems(float newLengthBetwinItems);
private:
const IWorldItem *_prevObject = nullptr;
float _lengthBetwinItems = 1;
};
}

View File

@ -26,6 +26,7 @@ Model {
PrincipledMaterial {
id: objMaterial
roughness : 1
baseColorMap: Texture {
source: (model)? model.baseColorMap: ""
tilingModeHorizontal: (tilies > 1)? Texture.Repeat : Texture.ClampToEdge

View File

@ -27,11 +27,11 @@ View3D {
}
PointLight {
position: camera.position
DirectionalLight {
position: Qt.vector3d(10000, 0, 10000);
rotation: camera.rotation
brightness: 250
brightness: 120
}
environment: SceneEnvironment {

@ -1 +1 @@
Subproject commit 1f2571634d50dd8791f59b0707cc037a435f9fdb
Subproject commit a2dee2c0f82b7af35d55fbfda903697de02bbb26

View File

@ -15,6 +15,8 @@ GroundPlate::GroundPlate(): CRAWL::GroundTile("JungleGroundTile",
setSize({6, 6, 0.01});
setBaseColorMap("qrc:/mesh/meshes/Other/Terrain_Base.jpg");
setNormalMap("qrc:/mesh/meshes/Other/Terrain_Normal.jpg");
// setRoughnessMap("qrc:/mesh/meshes/Other/Roughness_without.jpg");
// setEmissiveMap("qrc:/mesh/meshes/Other/Emission_without.jpg");
setTiliesCount(6);
}

View File

@ -11,15 +11,31 @@
namespace JungleLvl {
Snake::Snake(): CRAWL::Snake("JungleSnake") {
setBreakingForce(50);
setAngularVelocity(100);
registerItemType<JungleLvl::SnakeItem>();
setMash("qrc:/mesh/meshes/Other/Snake_head.mesh");
setBaseColorMap("qrc:/mesh/meshes/Other/Snake_Base.jpg");
setSize({1.5,1.5,1.5});
setStaticRotation(QQuaternion::fromEulerAngles(0,90,-90));
setSize({1,1,1});
setStaticRotation(QQuaternion::fromEulerAngles(0,0,0));
setScales({{0, 0.9},
{0.4, 1.2},
{1, 0.5}});
setLengthBetwinItemsMap({{0, 4.5},
{0.01, 1},
{0.4, 1.5},
{1, 0.5}});
}
void Snake::onIntersects(const IWorldItem *) {
}
unsigned int Snake::itemsCount() const {
return 35;
}
}

View File

@ -27,6 +27,8 @@ public:
// IWorldItem interface
protected:
void onIntersects(const IWorldItem *) override;
unsigned int itemsCount() const override;
};

View File

@ -12,7 +12,7 @@ namespace JungleLvl {
SnakeItem::SnakeItem(): CRAWL::SnakeItem("JungleSnakeItem") {
setMash("qrc:/mesh/meshes/Other/Snake_body.mesh");
setBaseColorMap("qrc:/mesh/meshes/Other/Snake_Base.jpg");
setSize({2,2,2});
setSize({1.5,1.5,1.5});
}
void SnakeItem::init() {