Files
John Jones-Steele 817f8ce4c1 Terrain/jjjoness/3172 axis aligned box shape component (#3981)
* CHanges to Push/Pop Matrix

Signed-off-by: John Jones-Steele <jjjoness@amazon.com>

* Fixed bad commit

Signed-off-by: John Jones-Steele <jjjoness@amazon.com>

* REmoved the AxisAlignedBoxShapeComponentBux and AxisAlignedBoxShapeConfig

Signed-off-by: John Jones-Steele <jjjoness@amazon.com>

* Fixed derivation of AxisAlignedBoxShape

Signed-off-by: John Jones-Steele <jjjoness@amazon.com>

* Added ShowChildrenOnly to Component

Signed-off-by: John Jones-Steele <jjjoness@amazon.com>

* Fixed cmake file

Signed-off-by: John Jones-Steele <jjjoness@amazon.com>

* Changes from review

Signed-off-by: John Jones-Steele <jjjoness@amazon.com>

* Added tests for AxisAlignedBoxShape

Signed-off-by: John Jones-Steele <jjjoness@amazon.com>

* Addressed PR comments and added one further test.

Signed-off-by: John Jones-Steele <jjjoness@amazon.com>

* Removed dead code.

Signed-off-by: John Jones-Steele <jjjoness@amazon.com>

* Changes from review

Signed-off-by: John Jones-Steele <jjjoness@amazon.com>

* Spelling fix and changed link to docs

Signed-off-by: John Jones-Steele <jjjoness@amazon.com>

* Fixed profile bug in Linux

Signed-off-by: John Jones-Steele <jjjoness@amazon.com>

* Fixed problem with Unity Profile Build in Tests

Signed-off-by: John Jones-Steele <jjjoness@amazon.com>
2021-09-08 10:50:29 -05:00

104 lines
4.6 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzCore/Component/TransformBus.h>
#include <AzCore/Math/Aabb.h>
#include <AzCore/Math/Obb.h>
#include <AzCore/Component/NonUniformScaleBus.h>
#include <LmbrCentral/Shape/ShapeComponentBus.h>
#include <LmbrCentral/Shape/BoxShapeComponentBus.h>
namespace AzFramework
{
class DebugDisplayRequests;
}
namespace LmbrCentral
{
struct ShapeDrawParams;
class BoxShape
: public ShapeComponentRequestsBus::Handler
, public BoxShapeComponentRequestsBus::Handler
, public AZ::TransformNotificationBus::Handler
{
public:
AZ_CLASS_ALLOCATOR(BoxShape, AZ::SystemAllocator, 0)
AZ_RTTI(BoxShape, "{36D1BA94-13CF-433F-B1FE-28BEBBFE20AA}")
BoxShape();
static void Reflect(AZ::ReflectContext* context);
virtual void Activate(AZ::EntityId entityId);
void Deactivate();
void InvalidateCache(InvalidateShapeCacheReason reason);
// ShapeComponentRequestsBus::Handler
AZ::Crc32 GetShapeType() override { return AZ_CRC("Box", 0x08a9483a); }
AZ::Aabb GetEncompassingAabb() override;
void GetTransformAndLocalBounds(AZ::Transform& transform, AZ::Aabb& bounds) override;
bool IsPointInside(const AZ::Vector3& point) override;
float DistanceSquaredFromPoint(const AZ::Vector3& point) override;
AZ::Vector3 GenerateRandomPointInside(AZ::RandomDistributionType randomDistribution) override;
bool IntersectRay(const AZ::Vector3& src, const AZ::Vector3& dir, float& distance) override;
// BoxShapeComponentRequestBus::Handler
BoxShapeConfig GetBoxConfiguration() override { return m_boxShapeConfig; }
AZ::Vector3 GetBoxDimensions() override { return m_boxShapeConfig.m_dimensions; }
void SetBoxDimensions(const AZ::Vector3& dimensions) override;
// AZ::TransformNotificationBus::Handler
void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override;
void OnNonUniformScaleChanged(const AZ::Vector3& scale);
const AZ::Vector3& GetCurrentNonUniformScale() const { return m_currentNonUniformScale; }
const BoxShapeConfig& GetBoxConfiguration() const { return m_boxShapeConfig; }
void SetBoxConfiguration(const BoxShapeConfig& boxShapeConfig) { m_boxShapeConfig = boxShapeConfig; }
const AZ::Transform& GetCurrentTransform() const { return m_currentTransform; }
void SetDrawColor(const AZ::Color& color) { m_boxShapeConfig.SetDrawColor(color); }
BoxShapeConfig& ModifyConfiguration() { return m_boxShapeConfig; }
protected:
/// Runtime data - cache potentially expensive operations.
class BoxIntersectionDataCache
: public IntersectionTestDataCache<BoxShapeConfig>
{
void UpdateIntersectionParamsImpl(
const AZ::Transform& currentTransform, const BoxShapeConfig& configuration,
const AZ::Vector3& currentNonUniformScale = AZ::Vector3::CreateOne()) override;
friend BoxShape;
friend class AxisAlignedBoxShape;
AZ::Aabb m_aabb; ///< Aabb representing this Box (including the effects of scale).
AZ::Obb m_obb; ///< Obb representing this Box (including the effects of scale).
AZ::Vector3 m_currentPosition; ///< Position of the Box.
AZ::Vector3 m_scaledDimensions; ///< Dimensions of Box (including entity scale and non-uniform scale).
bool m_axisAligned = true; ///< Indicates whether the box is axis or object aligned.
};
BoxIntersectionDataCache m_intersectionDataCache; ///< Caches transient intersection data.
AZ::Transform m_currentTransform; ///< Caches the current transform for the entity on which this component lives.
AZ::EntityId m_entityId; ///< Id of the entity the box shape is attached to.
AZ::NonUniformScaleChangedEvent::Handler m_nonUniformScaleChangedHandler; ///< Responds to changes in non-uniform scale.
AZ::Vector3 m_currentNonUniformScale = AZ::Vector3::CreateOne(); ///< Caches the current non-uniform scale.
BoxShapeConfig m_boxShapeConfig; ///< Underlying box configuration.
};
void DrawBoxShape(
const ShapeDrawParams& shapeDrawParams, const BoxShapeConfig& boxShapeConfig,
AzFramework::DebugDisplayRequests& debugDisplay, const AZ::Vector3& nonUniformScale = AZ::Vector3::CreateOne());
} // namespace LmbrCentral