예제 #1
0
  // Setup the whole thing
  public SimpleTextureExample() {
    // Create controller
    IController controller = new DefaultController();

    // Create view
    ICamera camera = new Camera();
    new DefaultView(controller, 100, 100, 500, 500, IView.INTERACTIVE_VIEW, "Test", camera);

    // Create scene and add triangle
    IScene scene = new DefaultScene(controller);
    controller.setScene(scene);

    IMesh mesh = makeTexturedTriangle();
    scene.add3DObject(mesh);

    // Animate (Using event timer)
    controller
        .getScheduler()
        .animate(
            new IScheduler.IAnimationAction() {
              private int c = 0;

              @Override
              public boolean run(double time, double interval) {

                // make some heavy animation calculation
                c += 4;
                if (c >= 360) c = 0;
                float f = 0.4f + 0.6f * (float) (Math.sin(Math.toRadians(c)) * 0.5 + 1);

                // apply changes to geometry
                mesh.setTransform(Mat4.scale(f, f, f));
                mesh.getGeometry()
                    .modify(
                        1,
                        (IGeometryAttribute id, float[] vertices) -> {
                          for (int i = 0; i < vertices.length; ++i) {
                            if (i % 4 == 3) continue;
                            vertices[i] -= 0.2f * (1 - f);
                            if (vertices[i + 0] <= 0) vertices[i + 0] = 1;
                          }
                        });
                mesh.requestUpdate(null);
                return true;
              }
            });
  }
예제 #2
0
 private void ensureSceneThread() {
   if (controller != null) controller.ensureSceneThread();
 }