Playing around with AR and 3D design in Processing.
code:
import processing.opengl.*; import processing.video.*; import jp.nyatla.nyar4psg.*; import java.io.*; Capture cam; MultiMarker nya; float r = 10; void setup() { size(640, 480, OPENGL); cam = new Capture(this, 640, 480); cam.start(); frameRate(15); nya = new MultiMarker(this, width, height, "camera_para.dat", NyAR4PsgConfig.CONFIG_DEFAULT); nya.addARMarker("patt.hiro", 80); nya.addARMarker("patt.kanji", 80); } void draw() { background(0); cam.read(); image(cam, 0, 0, width, height); // display the image at the width and height of the sketch window nya.detect(cam); // detect markers in the input image at the correct resolution (incorrect resolution will give assertion error) if (nya.isExistMarker(0)) { setMatrix(nya.getMarkerMatrix(0)); //use this marker to translate and rotate the processing drawing //// translate(0, 0, 70); //offset half the size of the cube. fill(0, 255, 0); beginShape(QUAD_STRIP); vertex(r*cos(0), r*sin(0), -20); vertex(r*cos(PI/4), r*sin(PI/4), -20); vertex(r*cos(PI/2), r*sin(PI/2), -20); vertex(r*cos(PI), r*sin(PI), -20); vertex(r*cos(5*PI/4), r*sin(5*PI/4), -20); vertex(r*cos(3*PI/2), r*sin(3*PI/2), -20); vertex(r*cos(7*PI/4), r*sin(7*PI/4), -20); vertex(r*cos(0), r*sin(0), 0); vertex(r*cos(PI/4), r*sin(PI/4), 0); vertex(r*cos(PI/2), r*sin(PI/2), 0); vertex(r*cos(PI), r*sin(PI), 0); vertex(r*cos(5*PI/4), r*sin(5*PI/4), 0); vertex(r*cos(3*PI/2), r*sin(3*PI/2), 0); vertex(r*cos(7*PI/4), r*sin(7*PI/4), 0); endShape(); } perspective(); if (nya.isExistMarker(1)) { setMatrix(nya.getMarkerMatrix(1)); // translate(0, 0, 70); fill(0, 255, 0); beginShape(QUAD_STRIP); vertex(r*cos(0), r*sin(0), -20); vertex(r*cos(PI/4), r*sin(PI/4), -20); vertex(r*cos(PI/2), r*sin(PI/2), -20); vertex(r*cos(PI), r*sin(PI), -20); vertex(r*cos(5*PI/4), r*sin(5*PI/4), -20); vertex(r*cos(3*PI/2), r*sin(3*PI/2), -20); vertex(r*cos(7*PI/4), r*sin(7*PI/4), -20); vertex(r*cos(0), r*sin(0), 0); vertex(r*cos(PI/4), r*sin(PI/4), 0); vertex(r*cos(PI/2), r*sin(PI/2), 0); vertex(r*cos(PI), r*sin(PI), 0); vertex(r*cos(5*PI/4), r*sin(5*PI/4), 0); vertex(r*cos(3*PI/2), r*sin(3*PI/2), 0); vertex(r*cos(7*PI/4), r*sin(7*PI/4), 0); endShape(); } }