2013-09-05 3 views
4

나는 2 차원 평면에서 여러 제어점에 의해 정의 된 부드러운 곡선을 따라 객체를 얻는 방법을 모색 중입니다. 내가 찾은 것 중에서 Catmull-Rom-Spline을 찾고 있습니다.CatmullRomSplines 및 다른 부드러운 경로

내 프로젝트에 LibGDX를 사용하고 있으며 자체 Catmull-Rom-Spline 구현이 있지만 설명서 또는 기타 소스를 찾는 데 어려움이 있으므로 문제 해결에 어려움을 겪고 있습니다. LibGDX를 사용하여 Catmull-Rom-Splines을 구현하는 코드입니다.

Catmull-Rom-Splines 또는 다른 방법을 사용하여 제어점을 구현하는 부드러운 경로를 구현하는 LibGDX Catmull-Rom-Spline 구현 또는 다른 방법에 대한 설명을 찾고 있습니다. 내가 찾고있는 건 경로를 생성하고 그 경로상의 한 점의 x와 y 좌표를 되돌릴 수있는 능력이다. 누구든지 어떤 제안이나 포인터가 있다면, 그것은 인정 될 것이다. 감사.

+1

Catmull-Rom은 내가 원하지 않는 루프 및 아티팩트를 생성하는 것으로 나타났습니다. 여기에 설명 된 구심력 매개 변수화 된 버전은 더 나은 결과를 제공합니다. http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/19283471#19283471 – Ted

답변

10

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

+0

수행 할 수있는 작업 사용 가능한 파생 상품? 이것에 관해 좋은 책을 읽은 곳을 가리킬 수 있습니까? –

+0

This (CatmullRomSpline )가 더 이상 작동하지 않는 것 같습니다. CatmullRomSpline 유형은 일반적이지 않습니다. 인수는 으로 매개 변수화 할 수 없습니다. – Madmenyo

+0

@MennoGouw이 주석의 현재로서는 벡터 클래스에 의해 매개 변수화되었습니다. https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/CatmullRomSpline.html – Jazzepi