- 즉 더, 작은 라인을 가지고있다. 이는 달성하기가 쉽고 사용 사례에 적합 할 수 있습니다.
for (float x = -50.0f; x < 50.0f; x += .25f)
{
curve.append(Vertex(Vector2f(x,- sin(x))));
}
당신은 다음 쉽게 범위 및 단계를 일반화 값으로 주위를 재생할 수 있습니다 :
float min_range = -200.f;
float max_range = 200.f;
float step = 0.5f;
for (float x = min_range; x < max_range ; x += step)
{
curve.append(Vertex(Vector2f(x,- sin(x))));
}
코멘트에
Sean Cline의 예는 좋은 출발점이되어야한다
마지막으로 멋진 인터페이스 뒤에서이를 추상화 할 수 있습니다.
using precision = float;
struct plot_params
{
precision _min_range;
precision _max_range;
precision _step;
};
template <typename TFunction>
auto plot(const plot_params pp, TFunction&& f)
{
assert(pp._min_range <= pp._max_range);
assert(pp._step > 0.f);
VertexArray curve(PrimitiveType::LineStrip,
std::ceil((pp._max_range - pp._min_range)/pp._step);
for (auto x = pp._min_range; x < pp._max_range; x += pp._step)
{
curve.append(Vertex(f(x)));
}
}
그리고 다음과 같이 plot
를 사용할 수 있습니다
const auto my_params = []
{
plot_params pp;
pp._min_range = -200.f;
pp._max_range = 200.f;
pp._step = 0.5f;
return pp;
})();
auto curve = plot(my_params,
[](auto x){ return Vector2f(x,- sin(x)); });
가 (당신이 ['ContextSettings']를 통해 윈도우 antialising 수 있도록하는 것을 시도했다 https://www.sfml-dev.org/documentation/2.0/ structsf_1_1ContextSettings.php)? –
당신은 단지 '1'단위로 플롯하고 있습니다. 곡선에서 더 많은 점을 얻기 위해 더 작은 숫자로 증가 시키십시오. 빠른 시험으로서 루프를'for (float x = -50.0f; x <50.0f; x + =. 25f)'로 변경할 수 있습니다. –
@SimonKraemer 방금 시도했지만 효과가없는 것 같습니다. – billy606