2
0
Эх сурвалжийг харах

Applied comments

Signed-off-by: Michał Pełka <[email protected]>
Michał Pełka 2 жил өмнө
parent
commit
e26fcb80b3

+ 0 - 1
Project/Gem/CMakeLists.txt

@@ -37,7 +37,6 @@ ly_add_target(
     BUILD_DEPENDENCIES
         PRIVATE
             AZ::AzGameFramework
-            AZ::AzToolsFramework
             Gem::LmbrCentral.API
             Gem::AtomLyIntegration_CommonFeatures.Editor.Static
             Gem::Atom_AtomBridge.Static

+ 12 - 10
Project/Gem/Source/ApplePicker/ApplePickerComponent.cpp

@@ -14,10 +14,10 @@
 
 #include <AtomLyIntegration/CommonFeatures/Mesh/MeshComponentBus.h>
 #include <AtomLyIntegration/CommonFeatures/Mesh/MeshComponentConstants.h>
+#include <AzCore/Component/ComponentApplicationBus.h>
 #include <AzCore/Component/TransformBus.h>
 #include <AzFramework/Physics/PhysicsSystem.h>
 #include <AzFramework/Physics/Shape.h>
-#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
 
 namespace AppleKraken
 {
@@ -186,17 +186,16 @@ namespace AppleKraken
             }
 
             AzPhysics::OverlapRequest request = AzPhysics::OverlapRequestHelpers::CreateBoxOverlapRequest(
-                    2.0f * globalBox.GetHalfLengths(),
-                AZ::Transform::CreateFromQuaternionAndTranslation(
-                    globalBox.GetRotation(), globalBox.GetPosition()));
+                2.0f * globalBox.GetHalfLengths(),
+                AZ::Transform::CreateFromQuaternionAndTranslation(globalBox.GetRotation(), globalBox.GetPosition()));
             // we want maximum overlap buffer set in `physxsystemconfiguration.setreg`
             request.m_maxResults = physicsSystem->GetConfiguration()->m_overlapBufferSize;
             AzPhysics::SceneQueryHits results = physicScene->QueryScene(&request);
-            for (auto& r : results.m_hits)
+            for (const auto& r : results.m_hits)
             {
-                auto* entity = AzToolsFramework::GetEntity(r.m_entityId);
-                AZ_Printf("ApplePickerComponent", "hit to %s : %s", r.m_entityId.ToString().c_str(), entity->GetName().c_str());
-                if (entity->GetName() != "Apple")
+                AZStd::string entity_name;
+                AZ::ComponentApplicationBus::BroadcastResult(entity_name, &AZ::ComponentApplicationRequests::GetEntityName, r.m_entityId);
+                if (entity_name != "Apple")
                 {
                     continue;
                 }
@@ -211,14 +210,17 @@ namespace AppleKraken
                 {
                     continue;
                 }
+                AZ::Transform targetTM = AZ::Transform::CreateIdentity();
+                AZ::TransformBus::EventResult(targetTM, r.m_entityId, &AZ::TransformBus::Events::GetWorldTM);
                 PickAppleTask t;
                 t.m_appleEntityId = r.m_entityId;
-                t.m_appleBoundingBox = r.m_shape->GetAabb(entity->GetTransform()->GetWorldTM());
+                t.m_appleBoundingBox = r.m_shape->GetAabb(targetTM);
+                t.m_middle = targetTM.GetTranslation(); /// TODO consider `r.m_position` here
                 m_currentAppleTasks.push(t);
                 found_apples.emplace(r.m_entityId);
             }
-
         }
+        m_initialTasksSize = m_currentAppleTasks.size();
         AZ_Printf("ApplePickerComponent", "There are %d apples in reach box \n", m_currentAppleTasks.size());
     }
 

+ 28 - 24
Project/Gem/Source/ApplePicker/KrakenEffectorComponent.cpp

@@ -180,33 +180,37 @@ namespace AppleKraken
         {
             AZ::Transform targetTM = AZ::Transform::CreateIdentity();
             AZ::TransformBus::EventResult(targetTM, m_reachEntity, &AZ::TransformBus::Events::GetWorldTM);
-            AZ::Vector3 dimensions = AZ::Vector3{ 0, 0, 0 };
+            AZ::Vector3 dimensions = AZ::Vector3{ 0.f };
             LmbrCentral::BoxShapeComponentRequestsBus::EventResult(
                 dimensions, m_reachEntity, &LmbrCentral::BoxShapeComponentRequests::GetBoxDimensions);
-
-            AZ_Printf("KrakenEffectorComponent", "OurEffectorReachArea :");
-            AZ_Printf("KrakenEffectorComponent", "  local dimensions : %f %f %f", dimensions.GetX(), dimensions.GetY(), dimensions.GetZ());
-            AZ_Printf(
-                "KrakenEffectorComponent",
-                "  transform - rot  : %f %f %f %f",
-                targetTM.GetRotation().GetX(),
-                targetTM.GetRotation().GetY(),
-                targetTM.GetRotation().GetZ(),
-                targetTM.GetRotation().GetW());
-            AZ_Printf(
-                "KrakenEffectorComponent",
-                "  transform - pos  : %f %f %f",
-                targetTM.GetTranslation().GetX(),
-                targetTM.GetTranslation().GetY(),
-                targetTM.GetTranslation().GetZ());
-
-            reachArea.SetHalfLengths(dimensions / 2);
-            reachArea.SetPosition(targetTM.GetTranslation());
-            reachArea.SetRotation(targetTM.GetRotation());
-
-            return reachArea;
+            if (!dimensions.IsZero())
+            {
+                AZ_Printf("KrakenEffectorComponent", "OurEffectorReachArea :");
+                AZ_Printf(
+                    "KrakenEffectorComponent", "  local dimensions : %f %f %f", dimensions.GetX(), dimensions.GetY(), dimensions.GetZ());
+                AZ_Printf(
+                    "KrakenEffectorComponent",
+                    "  transform - rot  : %f %f %f %f",
+                    targetTM.GetRotation().GetX(),
+                    targetTM.GetRotation().GetY(),
+                    targetTM.GetRotation().GetZ(),
+                    targetTM.GetRotation().GetW());
+                AZ_Printf(
+                    "KrakenEffectorComponent",
+                    "  transform - pos  : %f %f %f",
+                    targetTM.GetTranslation().GetX(),
+                    targetTM.GetTranslation().GetY(),
+                    targetTM.GetTranslation().GetZ());
+
+                reachArea.SetHalfLengths(dimensions / 2);
+                reachArea.SetPosition(targetTM.GetTranslation());
+                reachArea.SetRotation(targetTM.GetRotation());
+
+                return reachArea;
+            }
+            AZ_Warning(
+                "KrakenEffectorComponent", true, "Reach entity %s does not have BoxShapeComponent!", m_reachEntity.ToString().c_str());
         }
-
         AZ_Warning("KrakenEffectorComponent", true, "GetEffectorReachArea - returning invalid reach");
         reachArea.SetHalfLengths(AZ::Vector3{ 0, 0, 0 });
         reachArea.SetPosition(AZ::Vector3{ 0, 0, 0 }); /// TODO - get it from entity With box

+ 1 - 0
Project/Gem/Source/ApplePicker/PickingStructs.h

@@ -35,6 +35,7 @@ namespace AppleKraken
     {
         AZ::EntityId m_appleEntityId; //!< EntityId of the apple. Can be Invalid if the information is not available (check IsValid()).
         AZ::Aabb m_appleBoundingBox; //!< Bounding box of the apple to pick.
+        AZ::Vector3 m_middle; //!< Middle point of Apple
     };
 
     using StateTransition = std::pair<EffectorState, EffectorState>;