Wednesday, 12 January 2011

My Sketch Code

I am posting my code online via a screen grab that i have merged together, I am pleased with what I have completed my sketch and how it works. by looking at examples and stitching together i have learned a lot more than i thought i would because it seamed like a hard project at the beginning


Here is the code in text form

//Librarys
import processing.video.*;//Video Library
import jp.nyatla.nyar4psg.*;//NyAR2 Library
import processing.opengl.*;//OpenGL Library
import javax.media.opengl.*;//OpenGL Java
import pogg.*;//pogg Library
//END - Librarys

//Classes
Capture cam;//Camera Capture
SingleARTKMarker nya;//AR Marker
TheoraMovie myWMovie;//Win Movie
TheoraMovie myLMovie;//Lose Movie
//END - Classes

//Point Image Setup
PImage img;
//END - Point Image Setup

void setup() {

//Code to make AR work on MAC
try {
quicktime.QTSession.open();
} catch (quicktime.QTException qte) {
qte.printStackTrace();}
//END - Code to make AR work on MAC

//Sketch Size, Color & Frame Rate Setup
size(640,480,OPENGL);
colorMode(RGB, 100);
frameRate(30);
//END - Sketch Size, Color & Frame Rate Setup

//Load Point Image
img = loadImage("point.png");
//END - Load Point Image

//The Camera Capture
cam=new Capture(this,width,height);
//END - The Camera Capture

//Load Point Image
img = loadImage("point.png");
//END - Load Point Image

//Marker Detection Setup
nya=new SingleARTKMarker(this,width,height,"camera_para.dat",SingleARTKMarker.CS_LEFT);
println(nya.VERSION);
String[] marker={"patt.nikew","patt.nikel"};
nya.setARCodes(marker,318);// size of the video that is placed over the marker
nya.setConfidenceThreshold(0.6,0.5);
//END - Marker Detection Setup

//Win Movie Setup
myWMovie= new TheoraMovie(this, "win.ogg");//Loacting the win movie
myWMovie.loop();//Play movie on a loop
//END - Win Movie Setup

//Lose Movie Setup
myLMovie= new TheoraMovie(this, "lose.ogg");//Loacting the lose movie
myLMovie.loop();//Play movie on a loop
//END - Lose Movie Setup

}//END - Void Setup

void draw() {

background(255);
if (cam.available() !=true) {
return;
}
cam.read();

//Draw a background
hint(DISABLE_DEPTH_TEST);
image(cam,0,0);
hint(ENABLE_DEPTH_TEST);
//END - Draw a background

//Marker Detector
switch(nya.detect(cam)){
case SingleARTKMarker.ST_NOMARKER:
break;
case SingleARTKMarker.ST_NEWMARKER:
case SingleARTKMarker.ST_UPDATEMARKER:
//END - Marker Detector

//3D Space Setup
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
nya.beginTransform(pgl);
//END - 3D Space Setup

//Marker coordinate system.
translate(-159,130,0);//x,y,z position of the video
rotate(PI);//rotation of the video
rotateY(PI);//rotate video so the nike logo is the right way round
if(nya.markerid==0){ // If win marker is seen
myWMovie.read(); // Read Process
image(myWMovie, 0, 0); // Load Win Movie
} // This has now linked the Win movie to the win marker
else if(nya.markerid==1){ // If lose marker is seen
myLMovie.read(); // Read Process
image(myLMovie, 0, 0); // Load Lose Movie
} // This has now linked the lose movie to the lose marker
nya.endTransform();
//END - Marker coordinate system.
}

//Point Image Booleans
if(nya.markerid==0==true){ // If Win marker is seen
} // Load nothing
if(nya.markerid==1==true){ // If Lose marker is seen
} // Load nothing
else if(nya.markerid==0==false){ // If Win or Lose marker is removed
image(img, 0, 0); // Load Point Image
} // Close Load Point Image
//END - Point Image Booleans

}//END - Void Draw

No comments:

Post a Comment