package io.measures.passage;

import joons.JoonsRenderer;
import io.measures.passage.geometry.SphericalPoint;
import io.measures.passage.shapes.Rock;
import processing.event.KeyEvent;

/**
 * JoonsSketch
 * @author Dietrich Featherston
 */
public class JoonsSketch extends Sketch {

    protected JoonsRenderer jr;
    protected boolean triggerRender = false;
    protected boolean waitingForRender = false;

    @Override
    public void setup() {
        initSize(P3D);
        jr = new JoonsRenderer(this);
        jr.setSampler("bucket");
        jr.setSizeMultiplier(1);
        jr.setAA(0, 2, 4);
        noiseDetail(3, 0.5f);
        randomSeed(0);
        noiseSeed(1);
        frameRate(1);
    }

    @Override
    public void beforeFrame() {
        super.beforeFrame();
    }

    @Override
    public void afterFrame() {
        super.afterFrame();
        if(triggerRender && !jr.isRendering()) {
            triggerRender = false;
            waitingForRender = true;
            jr.render();
        }
        else if(jr.isRendered() && waitingForRender) {
            waitingForRender = false;
            snapshot();
        }
    }

    @Override
    public void keyPressed(KeyEvent event) {
        super.keyPressed(event);
        if (key == 'r' || key == 'R') {
            triggerRender = true;
        }
    }

    /**
     * default lights
     */
    @Override
    public void lights() {
        jr.fill("light", 30, 30, 30, 64);
        pushMatrix();
        translate(100, -50, 300);
        sphere(80);
        popMatrix();
    }

    /**
     * default camera
     */
    @Override
    public void camera() {
        //Camera Setting.
        float eyeX = 0;
        float eyeY = 0;
        float eyeZ = 70;
        float centerX = 0;
        float centerY = -1;
        float centerZ = 0;

        float upX = 0;
        float upY = 0;
        float upZ = -1;
        float fov = PI/3;
        float zNear = 1;
        float zFar = 10000;

        camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
        perspective(fov, getAspectRatio(), zNear, zFar);
    }

    public void panelXY(float w, float h) {
        beginShape(QUADS);
        vertex(-w/2, -h/2, 0);
        vertex(-w/2,  h/2, 0);
        vertex( w/2,  h/2, 0);
        vertex( w/2, -h/2, 0);
        endShape();
    }

    public void panelYZ(float w, float h) {
        beginShape(QUADS);
        vertex(0, -w/2, -h/2);
        vertex(0, -w/2,  h/2);
        vertex(0,  w/2,  h/2);
        vertex(0,  w/2, -h/2);
        endShape();
    }
}

@@ -1332,784 +1332,8 @@
  %7D%0A%0A
-    /**%0A     * default lights%0A     */%0A    @Override%0A    public void lights() %7B%0A        jr.fill(%22light%22, 30, 30, 30, 64);%0A        pushMatrix();%0A        translate(100, -50, 300);%0A        sphere(80);%0A        popMatrix();%0A    %7D%0A%0A    /**%0A     * default camera%0A     */%0A    @Override%0A    public void camera() %7B%0A        //Camera Setting.%0A        float eyeX = 0;%0A        float eyeY = 0;%0A        float eyeZ = 70;%0A        float centerX = 0;%0A        float centerY = -1;%0A        float centerZ = 0;%0A%0A        float upX = 0;%0A        float upY = 0;%0A        float upZ = -1;%0A        float fov = PI/3;%0A        float zNear = 1;%0A        float zFar = 10000;%0A%0A        camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);%0A        perspective(fov, getAspectRatio(), zNear, zFar);%0A    %7D%0A%0A
     

remove overrides that broke renders