/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #pragma once #include #include #include namespace AZ { enum class RandomDistributionType : AZ::u32; } namespace AzFramework { class DebugDisplayRequests; } namespace LmbrCentral { struct ShapeDrawParams; class CylinderShape : public ShapeComponentRequestsBus::Handler , public CylinderShapeComponentRequestsBus::Handler , public AZ::TransformNotificationBus::Handler { public: AZ_CLASS_ALLOCATOR(CylinderShape, AZ::SystemAllocator, 0) AZ_RTTI(CylinderShape, "{B45EFEF2-631F-43D3-B538-A3FE68350231}") static void Reflect(AZ::ReflectContext* context); void Activate(AZ::EntityId entityId); void Deactivate(); void InvalidateCache(InvalidateShapeCacheReason reason); // ShapeComponentRequestsBus::Handler AZ::Crc32 GetShapeType() override { return AZ_CRC("Cylinder", 0x9b045bea); } bool IsPointInside(const AZ::Vector3& point) override; float DistanceSquaredFromPoint(const AZ::Vector3& point) override; AZ::Aabb GetEncompassingAabb() override; void GetTransformAndLocalBounds(AZ::Transform& transform, AZ::Aabb& bounds) override; AZ::Vector3 GenerateRandomPointInside(AZ::RandomDistributionType randomDistribution) override; bool IntersectRay(const AZ::Vector3& src, const AZ::Vector3& dir, AZ::VectorFloat& distance) override; // CylinderShapeComponentRequestsBus::Handler CylinderShapeConfig GetCylinderConfiguration() override { return m_cylinderShapeConfig; } void SetHeight(float height) override; void SetRadius(float radius) override; float GetHeight() override; float GetRadius() override; // AZ::TransformNotificationBus::Handler void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override; const CylinderShapeConfig& GetCylinderConfiguration() const { return m_cylinderShapeConfig; } void SetCylinderConfiguration(const CylinderShapeConfig& cylinderShapeConfig) { m_cylinderShapeConfig = cylinderShapeConfig; } const AZ::Transform& GetCurrentTransform() const { return m_currentTransform; } protected: friend class EditorCylinderShapeComponent; CylinderShapeConfig& ModifyConfiguration() { return m_cylinderShapeConfig; } private: /// Runtime data - cache potentially expensive operations. class CylinderIntersectionDataCache : public IntersectionTestDataCache { void UpdateIntersectionParamsImpl( const AZ::Transform& currentTransform, const CylinderShapeConfig& configuration) override; friend class CylinderShape; AZ::Vector3 m_baseCenterPoint; ///< The center point of the cylinder. AZ::Vector3 m_axisVector; ///< A vector along the axis of this cylinder scaled to the height of the cylinder. float m_height = 0.0f; ///< Height of the cylinder (including entity scale). float m_radius = 0.0f; ///< Radius of the cylinder (including entity scale). }; CylinderShapeConfig m_cylinderShapeConfig; ///< Underlying cylinder configuration. CylinderIntersectionDataCache m_intersectionDataCache; ///< Caches transient intersection data. AZ::Transform m_currentTransform; ///< Caches the current World transform. AZ::EntityId m_entityId; ///< The Id of the entity the shape is attached to. }; void DrawCylinderShape( const ShapeDrawParams& shapeDrawParams, const CylinderShapeConfig& cylinderShapeConfig, AzFramework::DebugDisplayRequests& debugDisplay); } // namespace LmbrCentral