fazzuk
YaBB Newbies
Offline
Posts: 2
need help on tracking ur position/playing a movie
May 22nd , 2007, 12:41pm
Hi everyone, I'm an Artist and still quite new to processing. I need some help with my code. My vision is having a room in which a web cam tracks where you are and acording to your position plays a movie. Im using Myron for the tracking device. The idea is when the green ellipse moves over the rect it changes the background image/movie. Heres the code, pleeassse help I have deadlines soon eeekk -------------------------------------------------- import processing.video.*; import JMyron.*; Movie myMovie, yourMovie; JMyron m;//a camera object //variables to maintain the floating green circle float objx = 160; float objy = 120; float objdestx = 160; float objdesty = 120; PImage construct; boolean rectOver = false; boolean rectOver2 = false; void setup(){ size(352,288); m = new JMyron();//make a new instance of the object m.start(width,height);//start a capture at 320x240 m.trackColor(255,255,255,256*3-100);//track white m.update(); m.adaptivity(5); m.adapt();// immediately take a snapshot of the background for differencing println("Myron " + m.version() ); rectMode(CENTER); noStroke(); myMovie = new Movie(this, "station.mov"); yourMovie = new Movie(this, "station2.mov"); construct = loadImage("construct.jpg"); myMovie.play(); yourMovie.play(); myMovie.loop(); yourMovie.loop(); rect(0, 0, 50, 50); rect(80, 100, 80, 80); } void movieEvent(Movie myMovie) { myMovie.read(); } void draw(){ m.update();//update the camera view int[][] centers = m.globCenters();//get the center points //draw all the dots while calculating the average. float avX=0; float avY=0; for(int i=0;i<centers.length;i++){ fill(80); avX += centers[i][0]; avY += centers[i][1]; } if(centers.length-1>0){ avX/=centers.length-1; avY/=centers.length-1; } //update the location of the thing on the screen. if(!(avX==0&&avY==0)&¢ers.length>0){ objdestx = avX; objdesty = avY; } objx += (objdestx-objx)/10.0f; objy += (objdesty-objy)/10.0f; { fill(30,100,0); ellipseMode(CENTER); ellipse(objx,objy,20,20); if (rectOver) { tint(255, 20); image(myMovie, 0, 0); } else if (rectOver2) { tint(255, 20); image(yourMovie, 0, 0); } else { tint(255, 20); image(construct, 0, 0); } } } void update(int x, int y) { if ( overRect(0, 0, 50, 50) ) { rectOver = true; rectOver2 = false; } else if ( overRect2(80, 100, 80, 80) ) { rectOver = false; rectOver2 = true; } else { rectOver = false; rectOver2 = false; } } boolean overRect(int x, int y, int width, int height) { if (objx >= x && objx <= x+width && objy >= y && objy <= y+height) { return true; } else { return false; } } boolean overRect2(int x, int y, int width, int height) { if (objx >= x && objx <= x+width && objy >= y && objy <= y+height) { return true; } else { return false; } } void drawCamera(){ int[] img = m.differenceImage(); //get the normal image of the camera loadPixels(); for(int i=0;i<width*height;i++){ //loop through all the pixels pixels[i] = img[i]; //draw each pixel to the screen } updatePixels(); } public void stop(){ m.stop();//stop the object super.stop(); } -------------------------------------------------- faz_z@hotmail.com