mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Refactor the code for cutting a circle into chords for textured line overlay in Selectable component. Don't compute useless arccos and avoid compound rounding errors. Reviewed by Itms.
Differential Revision: https://code.wildfiregames.com/D673 This was SVN commit r19959.
This commit is contained in:
parent
1f42f65eb0
commit
3a3bcca0c5
5 changed files with 3 additions and 40 deletions
|
|
@ -505,13 +505,11 @@ void CCmpSelectable::UpdateTexturedLineOverlay(const SOverlayDescriptor* overlay
|
|||
else
|
||||
{
|
||||
const float radius = (buildingOverlay ? fpSize0_fixed.ToFloat() : overlayDescriptor->m_Radius) + overlay.m_Thickness / 3.f;
|
||||
float stepAngle;
|
||||
unsigned numSteps;
|
||||
SimRender::AngularStepFromChordLen(TERRAIN_TILE_SIZE / 3.f, radius, stepAngle, numSteps);
|
||||
|
||||
for (unsigned i = 0; i < numSteps; ++i)
|
||||
u32 numSteps = ceilf(float(2 * M_PI) * radius / (TERRAIN_TILE_SIZE / 3.f));
|
||||
for (u32 i = 0; i < numSteps; ++i)
|
||||
{
|
||||
float angle = i * stepAngle;
|
||||
float angle = i * float(2 * M_PI) / numSteps;
|
||||
float px = origin.X + radius * sinf(angle);
|
||||
float pz = origin.Y + radius * cosf(angle);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,11 +31,6 @@ CFixedVector2D Geometry::GetHalfBoundingBox(const CFixedVector2D& u, const CFixe
|
|||
);
|
||||
}
|
||||
|
||||
float Geometry::ChordToCentralAngle(const float chordLength, const float radius)
|
||||
{
|
||||
return acosf(1.f - SQR(chordLength)/(2.f*SQR(radius))); // cfr. law of cosines
|
||||
}
|
||||
|
||||
fixed Geometry::DistanceToSquare(const CFixedVector2D& point, const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize, bool countInsideAsZero)
|
||||
{
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -91,15 +91,6 @@ fixed DistanceToSquareSquared(const CFixedVector2D& point,
|
|||
CFixedVector2D NearestPointOnSquare(const CFixedVector2D& point,
|
||||
const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize);
|
||||
|
||||
/**
|
||||
* Given a circle of radius @p radius, and a chord of length @p chordLength
|
||||
* on this circle, computes the central angle formed by
|
||||
* connecting the chord's endpoints to the center of the circle.
|
||||
*
|
||||
* @param radius Radius of the circle; must be strictly positive.
|
||||
*/
|
||||
float ChordToCentralAngle(const float chordLength, const float radius);
|
||||
|
||||
bool TestRaySquare(const CFixedVector2D& a, const CFixedVector2D& b, const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize);
|
||||
|
||||
bool TestRayAASquare(const CFixedVector2D& a, const CFixedVector2D& b, const CFixedVector2D& halfSize);
|
||||
|
|
|
|||
|
|
@ -561,13 +561,6 @@ void SimRender::ConstructDashedLine(const std::vector<CVector2D>& keyPoints, SDa
|
|||
|
||||
}
|
||||
|
||||
void SimRender::AngularStepFromChordLen(const float maxChordLength, const float radius, float& out_stepAngle, unsigned& out_numSteps)
|
||||
{
|
||||
float maxAngle = Geometry::ChordToCentralAngle(maxChordLength, radius);
|
||||
out_numSteps = ceilf(float(2*M_PI)/maxAngle);
|
||||
out_stepAngle = float(2*M_PI)/out_numSteps;
|
||||
}
|
||||
|
||||
// TODO: this serves a similar purpose to SplitLine above, but is more general. Also, SplitLine seems to be implemented more
|
||||
// efficiently, might be nice to take some cues from it
|
||||
void SimRender::SubdividePoints(std::vector<CVector2D>& points, float maxSegmentLength, bool closed)
|
||||
|
|
|
|||
|
|
@ -179,20 +179,6 @@ void InterpolatePointsRNS(std::vector<CVector2D>& points, bool closed, float off
|
|||
void ConstructDashedLine(const std::vector<CVector2D>& linePoints, SDashedLine& dashedLineOut,
|
||||
const float dashLength, const float blankLength);
|
||||
|
||||
/**
|
||||
* Computes angular step parameters @p out_stepAngle and @p out_numSteps, given a @p maxChordLength on a circle of radius @p radius.
|
||||
* The resulting values satisfy @p out_numSteps * @p out_stepAngle = 2*PI.
|
||||
*
|
||||
* This function is used to find the angular step parameters when drawing a circle outline approximated by several connected chords;
|
||||
* it returns the step angle and number of steps such that the length of each resulting chord is less than or equal to @p maxChordLength.
|
||||
* By stating that each chord cannot be longer than a particular length, a certain level of visual smoothness of the resulting circle
|
||||
* outline can be guaranteed independently of the radius of the outline.
|
||||
*
|
||||
* @param radius Radius of the circle. Must be strictly positive.
|
||||
* @param maxChordLength Desired maximum length of individual chords. Must be strictly positive.
|
||||
*/
|
||||
void AngularStepFromChordLen(const float maxChordLength, const float radius, float& out_stepAngle, unsigned& out_numSteps);
|
||||
|
||||
/**
|
||||
* Subdivides a list of @p points into segments of maximum length @p maxSegmentLength that are of equal size between every two
|
||||
* control points. The resulting subdivided list of points is written back to @p points.
|
||||
|
|
|
|||
Loading…
Reference in a new issue