libgdx 경로 클래스 (CatmullRomSpline 포함)는 2D와 3D 모두에 적합합니다. CatmullRomSpline를 만들 때, 당신은 벡터 (Vector2 또는 Vector3)를 사용할 지정해야합니다
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
Vector2 cp[] = new Vector2[]{
new Vector2(0, 0), new Vector2(w * 0.25f, h * 0.5f), new Vector2(0, h), new Vector2(w*0.5f, h*0.75f),
new Vector2(w, h), new Vector2(w * 0.75f, h * 0.5f), new Vector2(w, 0), new Vector2(w*0.5f, h*0.25f)
};
CatmullRomSpline<Vector2> path = new CatmullRomSpline<Vector2>(cp, true);
지금 당신이 0에 이르기까지의 경로 (의 위치를 얻을 수 있습니다 : 예를 들어
CatmullRomSpline<Vector2> path = new CatmulRomSpline<Vector2> (controlpoints, continuous);
예를 들어
Vector2 position = new Vector2();
float t = a_vulue_between_0_and_1;
path.valueAt(position, t);
:
Vector2 position = new Vector2();
float t = 0;
public void render() {
t = (t + Gdx.graphics.getDeltaTime()) % 1f;
path.valueAt(position, t);
// Now you can use the position vector
}
,174,515 1) valueAt 방법을 이용하여
다음은 예입니다. https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/PathTest.java
Catmull-Rom은 내가 원하지 않는 루프 및 아티팩트를 생성하는 것으로 나타났습니다. 여기에 설명 된 구심력 매개 변수화 된 버전은 더 나은 결과를 제공합니다. http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/19283471#19283471 – Ted