Files
o3de/Gems/Terrain/Code/Source/Components/TerrainPhysicsColliderComponent.h
T
John Jones-Steele 3d67be162c Terrain Physics Heightfield support
* New Heightfield Components

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

* Misc PR fixes
* Fixed linux build failure from bad #include
* Renamed "Terrain Physics Collider" to "Terrain Physics Heightfield Collider" per physics team feedback
* Fixed 1/5 -> 1/4 typo in a comment
* Added missing member copies in HeightfieldShapeConfiguration

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Addressed PR feedback

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Changes from review

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

* Remove tabs accidently added

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

* Fixed overly complicated scaling math.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Added comments to make it more obvious what's happening on CreateEnd / DestroyBegin.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Moved Heightfield CreatePxGeometryFromConfig into its own function

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

Co-authored-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
2021-10-22 10:19:36 -05:00

92 lines
3.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/Component.h>
#include <AzFramework/Physics/HeightfieldProviderBus.h>
#include <AzFramework/Physics/Material.h>
#include <TerrainSystem/TerrainSystemBus.h>
#include <LmbrCentral/Shape/ShapeComponentBus.h>
namespace LmbrCentral
{
template<typename, typename>
class EditorWrappedComponentBase;
}
namespace Terrain
{
class TerrainPhysicsColliderConfig
: public AZ::ComponentConfig
{
public:
AZ_CLASS_ALLOCATOR(TerrainPhysicsColliderConfig, AZ::SystemAllocator, 0);
AZ_RTTI(TerrainPhysicsColliderConfig, "{E9EADB8F-C3A5-4B9C-A62D-2DBC86B4CE59}", AZ::ComponentConfig);
static void Reflect(AZ::ReflectContext* context);
};
class TerrainPhysicsColliderComponent
: public AZ::Component
, public Physics::HeightfieldProviderRequestsBus::Handler
, protected LmbrCentral::ShapeComponentNotificationsBus::Handler
, protected AzFramework::Terrain::TerrainDataNotificationBus::Handler
{
public:
template<typename, typename>
friend class LmbrCentral::EditorWrappedComponentBase;
AZ_COMPONENT(TerrainPhysicsColliderComponent, "{33C20287-1D37-44D0-96A0-2C3766E23624}");
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services);
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services);
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services);
static void Reflect(AZ::ReflectContext* context);
TerrainPhysicsColliderComponent(const TerrainPhysicsColliderConfig& configuration);
TerrainPhysicsColliderComponent();
~TerrainPhysicsColliderComponent() = default;
// HeightfieldProviderRequestsBus
AZ::Vector2 GetHeightfieldGridSpacing() const override;
void GetHeightfieldGridSize(int32_t& numColumns, int32_t& numRows) const override;
void GetHeightfieldHeightBounds(float& minHeightBounds, float& maxHeightBounds) const override;
AZ::Aabb GetHeightfieldAabb() const override;
AZ::Transform GetHeightfieldTransform() const override;
AZStd::vector<Physics::MaterialId> GetMaterialList() const override;
AZStd::vector<float> GetHeights() const override;
AZStd::vector<Physics::HeightMaterialPoint> GetHeightsAndMaterials() const override;
protected:
//////////////////////////////////////////////////////////////////////////
// AZ::Component interface implementation
void Activate() override;
void Deactivate() override;
bool ReadInConfig(const AZ::ComponentConfig* baseConfig) override;
bool WriteOutConfig(AZ::ComponentConfig* outBaseConfig) const override;
void GenerateHeightsInBounds(AZStd::vector<float>& heights) const;
void GenerateHeightsAndMaterialsInBounds(AZStd::vector<Physics::HeightMaterialPoint>& heightMaterials) const;
void NotifyListenersOfHeightfieldDataChange();
// ShapeComponentNotificationsBus
void OnShapeChanged(ShapeChangeReasons changeReason) override;
void OnTerrainDataCreateEnd() override;
void OnTerrainDataDestroyBegin() override;
void OnTerrainDataChanged(const AZ::Aabb& dirtyRegion, TerrainDataChangedMask dataChangedMask) override;
private:
TerrainPhysicsColliderConfig m_configuration;
};
}