I've the next code:
Code:import processing.video.*;
import jp.nyatla.nyar4psg.*;
import processing.opengl.*;
import processing.core.*;
public class prueba extends PApplet {
/**
*
*/
private static final long serialVersionUID = 1L;
private final String CARCODE_FILE = "/resources/data/1.patt";
private final String PARAM_FILE = "/resources/data/camera_para.dat";
Capture cam;
NyARBoard nya;
PFont font;
public void setup() {
//size(640, 480, OPENGL);
size(640, 480);
colorMode(RGB, 100);
font = createFont("FFScala", 32);
cam = new Capture(this, width, height);
// Left hand projection matrix
nya = new NyARBoard(this, this.width, this.height, "camera_para.dat", "1.patt",80);
// //Right hand projection matrix
//nya = new NyARBoard(this,width,height,"camera_para.dat","patt.hiro",80,NyARBoard.CS_RIGHT);
print(nya.VERSION);
nya.gsThreshold = 120; // (0<n<255) default=110
nya.cfThreshold = 0.4;// (0.0<n<1.0) default=0.4
// nya.lostDelay=10;//(0<n) default=10
}
void drawMarkerPos(int[][] points) {
//textFont(font, 10.0);
stroke(100, 0, 0);
fill(100, 0, 0);
for (int i = 0; i < 4; i++) {
ellipse(nya.pos2d[i][0], nya.pos2d[i][1], 5, 5);
}
fill(0, 0, 0);
for (int i = 0; i < 4; i++) {
text("(" + nya.pos2d[i][0] + "," + nya.pos2d[i][1] + ")",
nya.pos2d[i][0], nya.pos2d[i][1]);
}
}
String angle2text(float a) {
int i = (int) degrees(a);
i = (i > 0 ? i : i + 360);
return (i < 100 ? " " : i < 10 ? " " : "") + Integer.toString(i);
}
String trans2text(float i) {
return (i < 100 ? " " : i < 10 ? " " : "") + Integer.toString((int) i);
}
public void draw() {
background(255);
if (cam.available() !=true) {
return;
}
cam.read();
image(cam,0,0);
if(nya.detect(cam)){
//textFont(font,25.0);
fill((int)((1.0-nya.confidence)*100),(int)(nya.confidence*100),0);
text((int)(nya.confidence*100)+"%",width-60,height-20);
pushMatrix();
//textFont(font,10.0);
fill(0,100,0,80);
translate((nya.pos2d[0][0]+nya.pos2d[1][0]+nya.pos2d[2][0]+nya.pos2d[3][0])/4+50,(nya.pos2d[0][1]+nya.pos2d[1][1]+nya.pos2d[2][1]+nya.pos2d[3][1])/4+50);
text("TRANS "+trans2text(nya.trans.x)+","+trans2text(nya.trans.y)+","+trans2text(nya.trans.z),0,0);
text("ANGLE "+angle2text(nya.angle.x)+","+angle2text(nya.angle.y)+","+angle2text(nya.angle.z),0,15);
popMatrix();
drawMarkerPos(nya.pos2d);
//PGraphicsOpenGL pgl = new PGraphicsOpenGL();
PGraphicsOpenGL pgl = ((PGraphicsOpenGL) g);
nya.beginTransform(pgl);
stroke(255,200,0);
translate(0,0,20);
box(40);
nya.endTransform();
}
}
public static void main(String args[]) {
// PApplet.main(new String[]
// {"com.jarventure.client.graphics3D.prueba"});
new prueba().setVisible(true);
}
}
And the next error occur:
NyAR4psg/0.2.2;NyARToolkit for java/2.2.0;ARToolKit/2.72.1Exception in thread "Animation Thread" java.lang.ClassCastException: processing.core.PGraphicsJava2D cannot be cast to processing.opengl.PGraphicsOpenGL
at com.jarventure.client.graphics3D.prueba.draw(prueba.java:97)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Some Idea??'
Thx