Java 类com.badlogic.gdx.math.CatmullRomSpline 实例源码

项目:gdx-cclibs    文件:CatmullRomSplineSerializer.java   
@Override
public CatmullRomSpline read(Kryo kryo, Input input, Class<CatmullRomSpline> type) {
    CatmullRomSpline catmullRomSpline = new CatmullRomSpline();
    Class<? extends Vector> vectorType = kryo.readClass(input).getType();
    int controlPointsLength = input.readInt();
    if (controlPointsLength >= 0){
        Vector<?>[] controlPoints = (Vector<?>[])java.lang.reflect.Array.newInstance(vectorType, controlPointsLength);
        for (int i = 0; i < controlPointsLength; i++) {
            controlPoints[i] = kryo.readObjectOrNull(input, vectorType); // vector type won't be null if control points had a length
        }
        catmullRomSpline.controlPoints = controlPoints;
    }
    catmullRomSpline.continuous = input.readBoolean();
    catmullRomSpline.spanCount = input.readInt(true);
    return catmullRomSpline;
}
项目:old48_30_game    文件:CableRender.java   
public void render(Cable cable) {

        Vector2[] dataSet = new Vector2[cable.getBodyList().size()];
        /* fill dataSet with path points */
        for (int i = 0; i < cable.getBodyList().size(); i++) {
            Vector2 cablePosition = cable.getBodyList().get(i).getPosition();
            dataSet[i] = new Vector2(cablePosition.x * conf.UNIT_SIZE, cablePosition.y * conf.UNIT_SIZE);
        }

        CatmullRomSpline<Vector2> romSpline = new CatmullRomSpline<Vector2>(dataSet, false);

        for (int i = 0; i < Constants.CABLE_STEPS; i++) {
            points[i] = new Vector2();
            romSpline.valueAt(points[i], ((float) i) / ((float) Constants.CABLE_STEPS - 1));
        }

        shapeRenderer.setProjectionMatrix(camera.combined);
        shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
        for(int i = 0; i < Constants.CABLE_STEPS - 1; ++i)
        {
            Gdx.gl20.glLineWidth(Constants.CABLE_THICK);
            shapeRenderer.line(points[i], points[i + 1]);
        }
        shapeRenderer.end();
    }
项目:gdx-cclibs    文件:CatmullRomSplineSerializer.java   
@Override
public void write(Kryo kryo, Output output, CatmullRomSpline catmullRomSpline) {
    Class<? extends Vector> vectorType = null;
    if (catmullRomSpline.controlPoints != null && catmullRomSpline.controlPoints.length > 0)
        vectorType = catmullRomSpline.controlPoints[0].getClass();
    kryo.writeClass(output, vectorType);
    output.writeInt(catmullRomSpline.controlPoints != null ? catmullRomSpline.controlPoints.length : -1); // -1 for null array
    if (catmullRomSpline.controlPoints != null){
        for (int i = 0; i < catmullRomSpline.controlPoints.length; i++) {
            kryo.writeObjectOrNull(output, catmullRomSpline.controlPoints[i], vectorType);
        }
    }
    output.writeBoolean(catmullRomSpline.continuous);
    output.writeInt(catmullRomSpline.spanCount, true);
}
项目:zierfisch    文件:PathFollowSystem.java   
public PathFollowSystem(){
    super(Family.all(PathFollower.class, Pose.class).get());
    Vector3[] controlPoints = new Vector3[]{new Vector3(0,0,1),
                                            new Vector3(0,0,-5),
                                            new Vector3(2,-2.6f,-7.6f),
                                            new Vector3(3.1f,-1.8f,-15.4f),
                                            new Vector3(4.2f,-1.3f,-23.8f),
                                            new Vector3(4.6f,-0.4f,-29.4f),
                                            new Vector3(4.7f,-0.4f,-29.6f),
                                            new Vector3(4.7f,-0.4f,-29.7f)};
    spline = new CatmullRomSpline<Vector3>(controlPoints, false);
}
项目:libgdxcn    文件:PathTest.java   
@Override
public void create () {
    renderer = new ImmediateModeRenderer20(false, false, 0);
    spriteBatch = new SpriteBatch();
    obj = new Sprite(new Texture(Gdx.files.internal("data/badlogicsmall.jpg")));
    obj.setSize(40, 40);
    obj.setOriginCenter();
    obj2 = new Sprite(new Texture(Gdx.files.internal("data/bobrgb888-32x32.png")));
    obj2.setSize(40, 40);
    obj2.setOriginCenter();
    ZIGZAG_SCALE = Gdx.graphics.getDensity() * 96; // 96DP

    float w = Gdx.graphics.getWidth() - obj.getWidth();
    float h = Gdx.graphics.getHeight() - obj.getHeight();

    paths.add(new Bezier<Vector2>(new Vector2(0, 0), new Vector2(w, h)));
    paths.add(new Bezier<Vector2>(new Vector2(0, 0), new Vector2(0, h), new Vector2(w, h)));
    paths.add(new Bezier<Vector2>(new Vector2(0, 0), new Vector2(w, 0), new Vector2(0, h), new Vector2(w, h)));

    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)};
    paths.add(new BSpline<Vector2>(cp, 3, true));

    paths.add(new CatmullRomSpline<Vector2>(cp, true));

    pathLength = paths.get(currentPath).approxLength(500);
    avg_speed = speed * pathLength;

    Gdx.input.setInputProcessor(this);
}
项目:top-down-shooter    文件:Enemy.java   
public void initPath(int appWidth, int appHeight){

        //random values
        float xStart = Util.getRandomNumberBetween(0+sprite.getWidth(), appWidth-sprite.getWidth());
        float xEnd =  Util.getRandomNumberBetween(0+sprite.getWidth(), appWidth-sprite.getWidth());

        //ControlPoint1
        float cp1X =  Util.getRandomNumberBetween(0 + sprite.getWidth(), appWidth - sprite.getWidth());
        float cp1Y =  Util.getRandomNumberBetween(0+sprite.getWidth(), appHeight-sprite.getHeight());

        //ControlPoint2
        float cp2X =  Util.getRandomNumberBetween(0+sprite.getWidth(), appWidth-sprite.getWidth());
        float cp2Y =  Util.getRandomNumberBetween(0, cp1Y);

        Vector2 s = new Vector2(xStart, appHeight);
        Vector2 e = new Vector2(xEnd, -sprite.getHeight());
        Vector2 cp1 = new Vector2(cp1X, cp1Y);
        Vector2 cp2 = new Vector2(cp2X, cp2Y);

        dataSet[0] = s;
        dataSet[1] = cp2;
        dataSet[2] = cp1;
        dataSet[3] = e;

        // enemy path
        myCatmull = new CatmullRomSpline<Vector2>(dataSet, true);
    }
项目:aigraphs    文件:CatmulRomSpline.java   
public void refreshSpline() {
    float[] translated = poly.getTransformedVertices();
    Vector2[] dataSet = new Vector2[numControlls];

    for (int i = 0; i < numControlls; i++) {
        dataSet[i] = new Vector2(translated[i * 2], translated[i * 2 + 1]);
    }

    spline = new CatmullRomSpline<Vector2>(dataSet, false);
}
项目:PlanePilot    文件:Enemy.java   
public void initPath(int appWidth, int appHeight){

        //random values
        float xStart = Util.getRandomNumberBetween(0 + _sprite.getWidth(), appWidth - _sprite.getWidth());
        float xEnd =  Util.getRandomNumberBetween(0 + _sprite.getWidth(), appWidth - _sprite.getWidth());

        //ControlPoint1
        float cp1X =  Util.getRandomNumberBetween(0 + _sprite.getWidth(), appWidth - _sprite.getWidth());
        float cp1Y =  Util.getRandomNumberBetween(0 + _sprite.getWidth(), appHeight - _sprite.getHeight());

        //ControlPoint2
        float cp2X =  Util.getRandomNumberBetween(0 + _sprite.getWidth(), appWidth - _sprite.getWidth());
        float cp2Y =  Util.getRandomNumberBetween(0, cp1Y);

        Vector2 s = new Vector2(xStart, appHeight);
        Vector2 e = new Vector2(xEnd, -_sprite.getHeight());
        Vector2 cp1 = new Vector2(cp1X, cp1Y);
        Vector2 cp2 = new Vector2(cp2X, cp2Y);

        dataSet[0] = s;
        dataSet[1] = cp2;
        dataSet[2] = cp1;
        dataSet[3] = e;

        // enemy path
        myCatmull = new CatmullRomSpline<Vector2>(dataSet, true);
    }
项目:zierfisch    文件:PathFollowSystem.java   
public PathFollowSystem(CatmullRomSpline<Vector3> spline){
    super(Family.all(PathFollower.class, Pose.class).get());
    this.spline = spline;
}
项目:libGDX-Path-Editor    文件:PathSpline.java   
public PathSpline() {
    spline = new CatmullRomSpline();
    controlVertices = new ArrayList<Vector3>();
}