Files
o3de/Gems/Terrain/Code/Source/TerrainRaycast/TerrainRaycastContext.h
bosnichd f34d3a822e Add a ray cast API to the terrain system, implement it, and use it so entities can be placed on top of terrain. (#6895)
* Add a ray cast API to the terrain system, implement it, and use it so entities can be placed on top of terrain.

Still to do:
- Unit tests
- Profiling/benchmarks
- Optimization (if needed, may not be now after updating to use the iterative approach, but one option could be to use SIMD to ray cast against both triangles at once)

Signed-off-by: bosnichd <bosnichd@amazon.com>

* Fix typos.

Signed-off-by: bosnichd <bosnichd@amazon.com>

* Added a FindNearestIntersectionIterative to use in place of the first-pass FindnearestIntersectionRecursive attempt.

Signed-off-by: bosnichd <bosnichd@amazon.com>

* Remove some functions that are no longer being used.

Signed-off-by: bosnichd <bosnichd@amazon.com>

* Remove a unicode character from a comment to fix the validation build.

Signed-off-by: bosnichd <bosnichd@amazon.com>

* Remove another unicode character from a comment to fix the validation build.

Signed-off-by: bosnichd <bosnichd@amazon.com>

* Update to bail out as soon as t > 1.0f

Signed-off-by: bosnichd <bosnichd@amazon.com>
2022-01-24 13:47:44 -07:00

63 lines
2.8 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 <AzFramework/Render/IntersectorInterface.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace Terrain
{
class TerrainSystem;
////////////////////////////////////////////////////////////////////////////////////////////////
class TerrainRaycastContext : public AzFramework::RenderGeometry::IntersectorBus::Handler
{
public:
////////////////////////////////////////////////////////////////////////////////////////////
//! Constructor
//! \param[in] terrainSystem The terrain system that owns this terrain raycast context
TerrainRaycastContext(TerrainSystem& terrainSystem);
////////////////////////////////////////////////////////////////////////////////////////////
// Disable copying
AZ_DISABLE_COPY_MOVE(TerrainRaycastContext);
////////////////////////////////////////////////////////////////////////////////////////////
//! Destructor
~TerrainRaycastContext();
////////////////////////////////////////////////////////////////////////////////////////////
//! Access to the terrain raycast context's entity context id
//! \return The terrain raycast context's entity context id
inline AzFramework::EntityContextId GetEntityContextId() const { return m_entityContextId; }
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref AzFramework::RenderGeometry::RayIntersect
AzFramework::RenderGeometry::RayResult RayIntersect(const AzFramework::RenderGeometry::RayRequest& ray) override;
protected:
////////////////////////////////////////////////////////////////////////////////////////////
// RenderGeometry::IntersectorBus inherits from RenderGeometry::IntersectionNotifications,
// so we must override the following pure virtual functions. We could potentially implement
// them using TerrainSystem::m_registeredAreas, but right now that would not serve a purpose.
///@{
//! Unused pure virtual override
void OnEntityConnected(AZ::EntityId) override {}
void OnEntityDisconnected(AZ::EntityId) override {}
void OnGeometryChanged(AZ::EntityId) override {}
///@}
private:
////////////////////////////////////////////////////////////////////////////////////////////
// Variables
TerrainSystem& m_terrainSystem; //!< Terrain system that owns this terrain raycast context
AzFramework::EntityContextId m_entityContextId; //!< This object's entity context id
};
} // namespace Terrain