Exemple #1
0
  public Car() {
    /**
     * The car's "body" is this instance itself. That may seem a bit strange at first glance, but
     * it's quite convenient in this case.
     */
    super(Primitives.getBox(8, 0.25f));
    rightFront = Primitives.getSphere(5, 4);
    leftFront = Primitives.getSphere(5, 4);
    rightRear = Primitives.getSphere(5, 4);
    leftRear = Primitives.getSphere(5, 4);

    /** The wheels are parts, i.e. children of the car */
    addChild(rightFront);
    addChild(leftFront);
    addChild(rightRear);
    addChild(leftRear);

    /** Initialize the car and the wheels */
    setTexture("car");
    rightFront.setTexture("car");
    leftFront.setTexture("car");
    rightRear.setTexture("car");
    leftRear.setTexture("car");

    setEnvmapped(Object3D.ENVMAP_ENABLED);
    rightFront.setEnvmapped(Object3D.ENVMAP_ENABLED);
    leftFront.setEnvmapped(Object3D.ENVMAP_ENABLED);
    rightRear.setEnvmapped(Object3D.ENVMAP_ENABLED);
    leftRear.setEnvmapped(Object3D.ENVMAP_ENABLED);

    /** We need to offset the wheels a little... */
    rightFront.translate(new SimpleVector(-8, 4, 8));
    rightRear.translate(new SimpleVector(-8, 4, -8));
    leftFront.translate(new SimpleVector(8, 4, 8));
    leftRear.translate(new SimpleVector(8, 4, -8));

    rightFront.translateMesh();
    rightRear.translateMesh();
    leftFront.translateMesh();
    leftRear.translateMesh();

    rightFront.setTranslationMatrix(new Matrix());
    rightRear.setTranslationMatrix(new Matrix());
    leftFront.setTranslationMatrix(new Matrix());
    leftRear.setTranslationMatrix(new Matrix());

    /** ...the wheels are now in place. We can now build the car. */
    build();
    rightRear.build();
    rightFront.build();
    leftRear.build();
    leftFront.build();
  }