Package toxi.test

Source Code of toxi.test.PlaneIsecTest

package toxi.test;

import processing.core.PApplet;
import toxi.geom.Plane;
import toxi.geom.Ray3D;
import toxi.geom.Vec3D;
import toxi.processing.ToxiclibsSupport;
import toxi.util.DateUtils;

public class PlaneIsecTest extends PApplet {

    public static void main(String[] args) {
        PApplet.main(new String[] {
            "toxi.test.PlaneIsecTest"
        });
    }

    private ToxiclibsSupport gfx;

    private boolean doSave;

    private Plane p1, p2;

    public void draw() {
        background(255);
        lights();
        strokeWeight(1);
        translate(width / 2, height / 2);
        rotateX(mouseY * 0.01f);
        rotateY(mouseX * 0.01f);
        gfx.origin(300);
        stroke(0);
        fill(128);
        gfx.plane(p1, 300);
        fill(192);
        gfx.plane(p2, 300);
        stroke(255, 0, 255);
        strokeWeight(2);
        Ray3D ray = p1.intersectsPlane(p2);
        if (ray != null) {
            gfx.ray(ray, 300);
            gfx.ray(ray, -300);
        }
        if (doSave) {
            saveFrame("PlaneIsecTest-" + DateUtils.timeStamp() + ".png");
            doSave = false;
        }
    }

    public void keyPressed() {
        switch (key) {
            case ' ':
                doSave = true;
                break;
            case 'r':
                p2.normal = Vec3D.randomVector();
                break;
        }
    }

    public void setup() {
        size(1280, 720, OPENGL);
        gfx = new ToxiclibsSupport(this);
        p1 = new Plane(new Vec3D(100, 100, 100), new Vec3D(0, 1, 0));
        p2 = new Plane(new Vec3D(100, 200, 100),
                new Vec3D(1, 0, 0).rotateY(0.5f));
        p2.normal = p1.normal.copy();
    }
}
TOP

Related Classes of toxi.test.PlaneIsecTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.