Files
o3de/Code/Legacy/CryCommon/Cry_GeoDistance.h
T
Artur K 45b2336dce Legacy cleanup (#3383)
* WIP - small legacy cleanup

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* More cleanups + build fixes

Use AZstd instead of std types in a few places.
Remove m_nameTable.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Legacy code cleanups

Remove unused methods using legacy functionality

* EditorViewportWidget::AdjustObjectPosition
* DisplayContext - remove `renderer` pointer
* DisplayContext - log errors when functions using `renderer` are called
* CTrackGizmo::DrawAxis - log errors when function uses `renderer`.
* Legacy CCamera - remove Project, Unproject and CalcScreenBounds
* Remove all unused methods from Cry_GeoDistance.h/Cry_GeoIntersect.h
* Remove Lineseg_Triangle from Cry_GeoOverlap.h
* IEntityRenderState.h - remove unused types
* SMeshColor remove Lerp method and associated constructor.
* IMaterial.h - remove unused types and a few methods
* IRenderMesh.h - remove a few unused methods and use int8 instead of
byte
* IRender.h - remove almost all of the contents
* IShader.h - remove unused types and a few methods
* IStatObj.h - remove unused types and a few methods
* SSystemGlobalEnvironment - remove `renderer` pointer
* IRenderGraph - remove 2 unused methods
* physinterface.h - remove almost all of the contents
* CXmlUtils no longer inherits ISystemEventListener
* CXmlNode no longer has custom new/delete
* Remove IRenderer from some test mocks.

Removed files:
* CryName.h
* Cry_MatrixDiag.h
* Cry_XOptimise.h
* HeapAllocator.h
* IRendererMock.h
* PoolAllocator.h

Things to consider:
* Remove GetMemoryUsage & friends.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Apply review suggestions

IMovieSystem.h - remove unused includes.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Move unreachable code to `#if 0` block

This is hopefully temporary measure until the original functionality is
re-implemented

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Fix bad merge I messed up.

Fix bad merge I messed up, by re-removing FrameProfiler.h from crycommon_files.cmake (this was removed in an earlier commit this morning: https://github.com/o3de/o3de/pull/3394).

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

* Update Code/Framework/AzCore/AzCore/std/string/string_view.h

Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* implement review suggestion

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* following review, using LYSHINE_ATOM_TODO to guard

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove commented out include

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* EditorViewportWidget.cpp: Convert commented out code to  guarded one

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

Co-authored-by: bosnichd <bosnichd@amazon.com>
Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
2021-08-25 15:04:38 -06:00

129 lines
4.4 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
*
*/
// Description : Common distance-computations
#pragma once
#include <Cry_Geo.h>
#include <AzCore/Math/Vector3.h>
#ifdef max
#undef max
#endif
namespace Distance {
//----------------------------------------------------------------------------------
/// Returns squared distance from a point to a line segment and also the "t value" (from 0 to 1) of the
/// closest point on the line segment
//----------------------------------------------------------------------------------
template<typename F>
ILINE F Point_LinesegSq(const Vec3_tpl<F>& p, const Lineseg& lineseg, F& fT)
{
Vec3_tpl<F> diff = p - lineseg.start;
Vec3_tpl<F> dir = lineseg.end - lineseg.start;
fT = diff.Dot(dir);
if (fT <= 0.0f)
{
fT = 0.0f;
}
else
{
F fSqrLen = dir.GetLengthSquared();
if (fT >= fSqrLen)
{
fT = 1.0f;
diff -= dir;
}
else
{
fT /= fSqrLen;
diff -= fT * dir;
}
}
return diff.GetLengthSquared();
}
/// Returns distance from a point to a line segment and also the "t value" (from 0 to 1) of the
/// closest point on the line segment
template<typename F>
ILINE F Point_Lineseg(const Vec3_tpl<F>& p, const Lineseg& lineseg, F& fT)
{
return sqrt_tpl(Point_LinesegSq(p, lineseg, fT));
}
//! \brief Get the distance squared from a Point to a Cylinder.
//! \param point AZ::Vector3 The point to test distance against the cylinder
//! \param cylinderAxisEndA AZ::Vector3 One end of the cylinder axis (centered in the circle)
//! \param cylinderAxisEndB AZ::Vector3 Other end of the cylinder axis (centered in the circle)
//! \param radius float Radius of the cylinder
//! \return float Closest distance squared from the point to the cylinder.
AZ_INLINE float Point_CylinderSq(
const AZ::Vector3& point,
const AZ::Vector3& cylinderAxisEndA,
const AZ::Vector3& cylinderAxisEndB,
float radius
)
{
// Use the cylinder axis' center point to determine distance by
// splitting into Voronoi regions and using symmetry.
// The regions are:
// - Inside
// - Beyond cylinder radius but between two disc ends.
// - Within cylinder radius but beyond two disc ends.
// - Beyond cylinder radius and beyond two disc ends.
const AZ::Vector3 cylinderAxis = cylinderAxisEndB - cylinderAxisEndA;
float halfLength = cylinderAxis.GetLength() * 0.5f;
const AZ::Vector3 cylinderAxisUnit = cylinderAxis.GetNormalized();
// get the center of the axis and the vector from center to the test point
const AZ::Vector3 centerPoint = (cylinderAxis * 0.5) + cylinderAxisEndA;
const AZ::Vector3 pointToCenter = point - centerPoint;
// distance point is from center (projected onto axis)
// the abs here takes advantage of symmetry.
float x = fabsf(pointToCenter.Dot(cylinderAxisUnit));
// squared distance from point to center (hypotenuse)
float n2 = pointToCenter.GetLengthSq();
// squared distance from point to center perpendicular to axis (pythagorean)
float y2 = n2 - sqr(x);
float distanceSquared = 0.f;
if (x < halfLength) // point is between the two ends
{
if (y2 > sqr(radius)) // point is outside of radius
{
distanceSquared = sqr(sqrtf(y2) - radius);
}
// else point is inside cylinder, distance is zero.
}
else if (y2 < sqr(radius))
{
// point is within radius
// point projects into a disc at either end, grab the "parallel" distance only
distanceSquared = sqr(x - halfLength);
}
else
{
// point is outside of radius
// point projects onto the edge of the disc, grab distance in two directions,
// combine "parallel" and "perpendicular" distances.
distanceSquared = sqr(sqrtf(y2) - radius) + sqr(x - halfLength);
}
return distanceSquared;
}
} //namespace Distance