Game Development Reference
In-Depth Information
elements such as world markers that we want visible on screen even if they're behind the
player or a radar that constrains out of range elements at the border of an ellipse.
vector2 GetPointInEllipse(const vector2& position)
{
vector2 p1 = GetPointOnEllipse(position);
vector2 v1 = p1 - m_center;
if (position.LengthSquared() < v1.LengthSquared())
return m_center + position;
return p1;
}
Drawing an Ellipse
Finally, we may want to draw an ellipse, for this we can create a list of points, we can take
advantage of the function GetPointOnEllipse by iterating in the range [0..2π] .
void GetPoints(int count, std::vector<point>& points)
{
for (int angle = 0; angle < 360; angle += 360 / count)
{
point p = GetPointOnEllipse(static_cast<float>(angle));
points.push_back(p);
}
}
This list of points can then be used to render sprites or to connect line segments to form an
ellipse.
Search WWH ::




Custom Search