コード例 #1
0
  public void draw() {
    /*---Update---*/
    world.update();
    worm.update();
    for (int i = 0; i < extraNum; i++) {
      extraWorms[i].update();
    }

    /*---Draw--*/
    // Lights
    lights();
    /*
    ambientLight(128f, 128f, 128f);
    directionalLight(128f, 128f, 128f, 0f, 0f, -1f);
    lightFalloff(1f, 0f, 0f);
    lightSpecular(0f, 0f, 0f);
    */

    // Camera
    perspective(fov, aspect, near, far);
    // Calculate camera position
    if (PVector.dist(worm.getPosition(), eye) > eyeDist) {
      eye = PVector.sub(eye, worm.getPosition());
      eye.normalize();
      eye.mult(eyeDist);
      eye.add(worm.getPosition());
    }
    camera(
        eye.x,
        eye.y,
        eye.z, // eyeX, eyeY, eyeZ (camera position)
        worm.getPosition().x,
        worm.getPosition().y,
        worm.getPosition().z, // centerX, centerY, centerZ (look at)
        0f,
        1f,
        0f); // upX, upY, upZ

    // Action
    world.draw();
    worm.draw();
    for (int i = 0; i < extraNum; i++) {
      extraWorms[i].draw();
    }
    // Drama!
  }
コード例 #2
0
  public void setup() {
    size(WIDTH, HEIGHT, OPENGL);
    noStroke();

    // Instantiate world
    // world = new SimpleWorld();
    world = new IslandWorld();
    world.init(this);

    // Instantiate worm movement
    IWormMovement movement = new MouseMovement(); // Mouse setup
    // IWormMovement movement = new SimpleNoiseMovement(); //'Random' movement
    // IWormMovement movement = new SinusMovement(); //Oscillating in world
    movement.init(this, world.getSize(), world.getCenter());

    // Instantiate worm
    // worm = new SimpleWorm3D(); //Drawn with ellipse
    // worm = new StickWorm(); //Draw worm as lines
    worm = new TriangleWorm();
    worm.init(this, movement);

    // Extra worms
    for (int i = 0; i < extraNum; i++) {
      // setup behavior for extra worms
      IWormMovement extraMovement = new SinusMovement(); // Oscillating in world
      extraMovement.init(this, world.getSize(), world.getCenter());
      // Initiate worms
      extraWorms[i] = new TriangleWorm();
      extraWorms[i].init(this, extraMovement);
    }

    // Setup eye for camera
    eyeDist += worm.getLength() * 3f;
    eyeZ = worm.getPosition().z - eyeDist;
    eye = new PVector(eyeX, eyeY, eyeZ);
  }