From e82ad370a1f392b50e74d07fb64b96cd892742fe Mon Sep 17 00:00:00 2001
From: EndrII <EndrIIMail@gmail.com>
Date: Sun, 11 Jul 2021 14:45:30 +0300
Subject: [PATCH] updare resources

---
 src/Core/Crawl/snake.cpp              | 70 ++++++++++++++++++---------
 src/Core/Crawl/snake.h                | 35 ++++++++++++++
 src/Core/Crawl/snakeitem.cpp          | 12 ++++-
 src/Core/Crawl/snakeitem.h            | 14 ++++++
 src/Core/CrawlModule/GraphicItem.qml  |  1 +
 src/Core/CrawlModule/Scene.qml        |  6 +--
 src/JungleLvl/CrawlJungleLvlAssests   |  2 +-
 src/JungleLvl/private/groundplate.cpp |  2 +
 src/JungleLvl/private/snake.cpp       | 20 +++++++-
 src/JungleLvl/private/snake.h         |  2 +
 src/JungleLvl/private/snakeitem.cpp   |  2 +-
 11 files changed, 135 insertions(+), 31 deletions(-)

diff --git a/src/Core/Crawl/snake.cpp b/src/Core/Crawl/snake.cpp
index 0d277c2..f10d499 100644
--- a/src/Core/Crawl/snake.cpp
+++ b/src/Core/Crawl/snake.cpp
@@ -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;
 }
diff --git a/src/Core/Crawl/snake.h b/src/Core/Crawl/snake.h
index 2b4936f..7a32877 100644
--- a/src/Core/Crawl/snake.h
+++ b/src/Core/Crawl/snake.h
@@ -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;
diff --git a/src/Core/Crawl/snakeitem.cpp b/src/Core/Crawl/snakeitem.cpp
index 822ba9b..e3b39e3 100644
--- a/src/Core/Crawl/snakeitem.cpp
+++ b/src/Core/Crawl/snakeitem.cpp
@@ -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;
+}
 }
diff --git a/src/Core/Crawl/snakeitem.h b/src/Core/Crawl/snakeitem.h
index 878c8ef..42996a6 100644
--- a/src/Core/Crawl/snakeitem.h
+++ b/src/Core/Crawl/snakeitem.h
@@ -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;
 };
 
 }
diff --git a/src/Core/CrawlModule/GraphicItem.qml b/src/Core/CrawlModule/GraphicItem.qml
index 82467d9..3d31ca7 100644
--- a/src/Core/CrawlModule/GraphicItem.qml
+++ b/src/Core/CrawlModule/GraphicItem.qml
@@ -26,6 +26,7 @@ Model {
 
     PrincipledMaterial {
         id:  objMaterial
+        roughness : 1
         baseColorMap: Texture {
             source: (model)? model.baseColorMap: ""
             tilingModeHorizontal: (tilies > 1)? Texture.Repeat : Texture.ClampToEdge
diff --git a/src/Core/CrawlModule/Scene.qml b/src/Core/CrawlModule/Scene.qml
index 60429a1..2a0bb42 100644
--- a/src/Core/CrawlModule/Scene.qml
+++ b/src/Core/CrawlModule/Scene.qml
@@ -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 {
diff --git a/src/JungleLvl/CrawlJungleLvlAssests b/src/JungleLvl/CrawlJungleLvlAssests
index 1f25716..a2dee2c 160000
--- a/src/JungleLvl/CrawlJungleLvlAssests
+++ b/src/JungleLvl/CrawlJungleLvlAssests
@@ -1 +1 @@
-Subproject commit 1f2571634d50dd8791f59b0707cc037a435f9fdb
+Subproject commit a2dee2c0f82b7af35d55fbfda903697de02bbb26
diff --git a/src/JungleLvl/private/groundplate.cpp b/src/JungleLvl/private/groundplate.cpp
index c972b3e..130e72a 100644
--- a/src/JungleLvl/private/groundplate.cpp
+++ b/src/JungleLvl/private/groundplate.cpp
@@ -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);
 
 }
diff --git a/src/JungleLvl/private/snake.cpp b/src/JungleLvl/private/snake.cpp
index 0e4c149..180cf07 100644
--- a/src/JungleLvl/private/snake.cpp
+++ b/src/JungleLvl/private/snake.cpp
@@ -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;
+}
 }
diff --git a/src/JungleLvl/private/snake.h b/src/JungleLvl/private/snake.h
index dc60237..e357550 100644
--- a/src/JungleLvl/private/snake.h
+++ b/src/JungleLvl/private/snake.h
@@ -27,6 +27,8 @@ public:
     // IWorldItem interface
 protected:
     void onIntersects(const IWorldItem *) override;
+    unsigned int itemsCount() const override;
+
 };
 
 
diff --git a/src/JungleLvl/private/snakeitem.cpp b/src/JungleLvl/private/snakeitem.cpp
index cd836e1..b5f6a07 100644
--- a/src/JungleLvl/private/snakeitem.cpp
+++ b/src/JungleLvl/private/snakeitem.cpp
@@ -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() {