Пример #1
0
  @Override
  public void create() {
    Arrays.fill(heights, defaultHeight);

    Core.interval(.0005).onEvent(this::step).addChild(this);

    //        onUpdate(dt -> {
    //            Util.repeat(detail, i -> heights[i] += dt * speeds[i]);
    //            Util.repeat(detail - 1, i -> {
    //                deltas[i] = heights[i + 1] - heights[i];
    //                speeds[i] += deltas[i] * dt * 3000;
    //                speeds[i + 1] -= deltas[i] * dt * 3000;
    //            });
    //            Util.repeat(detail, i -> speeds[i] = speeds[i] * Math.pow(.1, dt * dt) + dt * 10 *
    // (defaultHeight - heights[i]));
    //            Util.repeat(detail - 1, i -> {
    //                heights[i] += deltas[i] * dt;
    //                heights[i + 1] -= deltas[i] * dt;
    //            });
    //        });
    onRender(
        () -> {
          glDisable(GL_TEXTURE_2D);
          glBegin(GL_TRIANGLE_STRIP);
          Util.repeat(
              detail,
              i -> {
                double x = position.x + width * (2. * i / detail - 1);
                new Color4(0, 0, .6).glColor();
                new Vec2(x, bottom).glVertex();
                new Color4(0, .2, 1).glColor();
                new Vec2(x, heights[i]).glVertex();
              });
          glEnd();
        });
    Core.renderLayer(1)
        .onEvent(
            () -> {
              glDisable(GL_TEXTURE_2D);
              glBegin(GL_TRIANGLE_STRIP);
              Util.repeat(
                  detail,
                  i -> {
                    double x = position.x + width * (2. * i / detail - 1);
                    new Color4(0, 0, .6, .5).glColor();
                    new Vec2(x, bottom).glVertex();
                    new Color4(0, .2, 1, .5).glColor();
                    new Vec2(x, heights[i]).glVertex();
                  });
              glEnd();
            })
        .addChild(this);
  }
Пример #2
0
  @Override
  public void createInner() {
    List<Particle> particles = new LinkedList();
    for (int i = 0; i < 2500; i++) {
      particles.add(
          new Particle(Window3D.pos.add(Vec3.randomSquare(MAX_DIST)), Math.random() * .04 + .06));
    }
    onUpdate(
        dt -> {
          Iterator<Particle> it = particles.iterator();
          while (it.hasNext()) {
            Particle p = it.next();
            p.pos = p.pos.add(Vec3.randomSquare(dt / 5).add(new Vec3(0, 0, -dt)));
            p.pos =
                Window3D.pos.add(
                    p.pos
                        .subtract(Window3D.pos)
                        .perComponent(d -> (d + 3 * MAX_DIST) % (2 * MAX_DIST) - MAX_DIST));
          }
        });

    Sprite s = new Sprite("snowflake2");
    Core.renderLayer(.2)
        .onEvent(
            () -> {
              glEnable(GL_TEXTURE_2D);
              s.getTexture().bind();
              WHITE.glColor();
              glBegin(GL_QUADS);
              particles.forEach(
                  p -> {
                    if (CubeMap.rayCastStream(p.pos, new Vec3(0, 0, 1))
                        .anyMatch(cd -> cd.c != null)) {
                      return;
                    }
                    ;
                    Vec3 towards = p.pos.subtract(Window3D.pos);
                    Vec3 side = towards.cross(Window3D.UP).withLength(p.size / 2);
                    Vec3 snowUp = towards.cross(side).withLength(p.size / 2);
                    Graphics3D.drawQuadFastT(
                        p.pos.add(side).add(snowUp),
                        p.pos.subtract(side).add(snowUp),
                        p.pos.subtract(side).subtract(snowUp),
                        p.pos.add(side).subtract(snowUp));
                  });
              glEnd();
            })
        .addChild(this);
  }