/***********************************************************
* EXAMPLE PROVIDED WITH SURFACEMAPPER LIBRARY DEVELOPED BY *
* IXAGON AB. *
* This example shows you how to setup the library and *
* and display a movie to multiple surfaces. *
* Check the keyPressed method to see how to access *
* different settings *
***********************************************************/
void setup(){
size(1600,1050, GLConstants.GLGRAPHICS);
glos = new GLGraphicsOffScreen(this, width, height, false);
tex = new GLTexture(this);
img = new GLTexture(this, "test1.jpg");
name = new GLTexture(this, "test2.jpg");
//Create new instance of SurfaceMapper
sm = new SurfaceMapper(this, width, height);
//Creates one surface with subdivision 3, at center of screen
sm.createQuadSurface(3,width/2,height/2);
//set the name of the surface
sm.getSurfaces().get(0).setSurfaceName("name");
movie = new GSMovie(this, "test.mp4");
movie.setPixelDest(tex);
movie.loop();
}
void draw(){
background(0);
glos.beginDraw();
glos.clear(0);
glos.hint(ENABLE_DEPTH_TEST);
glos.endDraw();
//get movie frame
if(tex.putPixelsIntoTexture())
//Updates the shaking of the surfaces in render mode
sm.shake();
//render all surfaces in calibration mode
if(sm.getMode() == sm.MODE_CALIBRATE)sm.render(glos);
//render all surfaces in render mode
if(sm.getMode() == sm.MODE_RENDER){
for(SuperSurface ss : sm.getSurfaces()){
//render this surface to GLOS, use name as texture if the surfaces name is 'name'
if(ss.getSurfaceName().equals("name")){
ss.render(glos, name);
}else{
//use the movie as texture is the surfaces id is an even number, use the image if it's odd.
if(ss.getId() % 2 == 0) ss.render(glos,tex);
else ss.render(glos, img);
}
}
}
//display the GLOS to screen
image(glos.getTexture(),0,0,width,height);
}
void movieEvent(GSMovie movie) {
movie.read();
}
void keyPressed(){
//create a new QUAD surface at mouse pos
if(key == 'a')sm.createQuadSurface(3,mouseX,mouseY);
//create new BEZIER surface at mouse pos
if(key == 'z')sm.createBezierSurface(3,mouseX,mouseY);
//switch between calibration and render mode
if(key == 'c')sm.toggleCalibration();
//increase subdivision of surface
if(key == 'p'){
for(SuperSurface ss : sm.getSelectedSurfaces()){
ss.increaseResolution();
}
}
//decrease subdivision of surface
if(key == 'o'){
for(SuperSurface ss : sm.getSelectedSurfaces()){
ss.decreaseResolution();
}
}
//save layout to xml
if(key == 's')sm.save("bla.xml");
//load layout from xml
if(key == 'l')sm.load("bla.xml");
//rotate how the texture is mapped in the QUAD (clockwise)
if(key == 'j'){
for(SuperSurface ss : sm.getSelectedSurfaces()){
ss.rotateCornerPoints(0);
}
}
//rotate how the texture is mapped in the QUAD (counter clockwise)
if(key == 'k'){
for(SuperSurface ss : sm.getSelectedSurfaces()){
ss.rotateCornerPoints(1);
}
}
//increase the horizontal force on a BEZIER surface
if(key == 't'){
for(SuperSurface ss : sm.getSelectedSurfaces()){
ss.increaseHorizontalForce();
}
}
//decrease the horizontal force on a BEZIER surface
if(key == 'y'){
for(SuperSurface ss : sm.getSelectedSurfaces()){
ss.decreaseHorizontalForce();
}
}
//increase the vertical force on a BEZIER surface
if(key == 'g'){
for(SuperSurface ss : sm.getSelectedSurfaces()){
ss.increaseVerticalForce();
}
}
//decrease the vertical force on a BEZIER surface
if(key == 'h'){
for(SuperSurface ss : sm.getSelectedSurfaces()){
ss.decreaseVerticalForce();
}
}
//shake all surfaces with strength (max z displacement) and speed
if(key == 'q'){
sm.setShakeAll(50, 850);
}
//shake all surfaces with strength (max z displacement) and speed
if(key == 'w'){
sm.setShakeAll(75, 650);
}
//shake all surfaces with strength (max z displacement) and speed
if(key == 'e'){
sm.setShakeAll(100, 450);
}
//shake only the selected surfaces with strength (max z displacement) and speed
if(key == 'r'){
for(SuperSurface ss : sm.getSelectedSurfaces()){
ss.setShake(200,400);
}
}
}
I'm fairly new to Processing so please forgive my ignorance in advance. I'm trying to use the system variables mouseX and mouseY to navigate through a number of quicktime movies, 9 movies in total. The plan is use mouseX to switch between movie clips and mouseY to jump to a specific frame within the clip. It's been a long process to get to this point but to cut a long story short I'm using an array to preload the movie clips as discussed in this forum entry:
http://processing.org/discourse/yabb2/YaBB.pl?board=Video;action=display;num=1221263317
Prior to using an array I was using the mouseY variable to successfully jump to a specific frame within a movie clip:
float ratio = mouseY/ (float) height;
myMovie.jump(ratio*myMovie.duration());
myMovie.read();
image(myMovie, 0, 0);
Unfortunately now I get the following error message: "Cannot invoke duration() on the array type Movie[]"
This is just slightly beyond my knowledge level, so if someone would be kind enough to point me in the right direction I'd be very grateful. The eventual plan with this sketch is to use JMyron/motion detection in place of mouseX/mouseY and then link to a separate Pure Data sound patch (fingers crossed). The full code so far is as follows:
import processing.video.*;
//the film array, the films will be pre loaded
Movie[] phoneFilm = new Movie[9]; //array of movies
void setup() {
size(640,480); //the application window will measure 640px x 480px
background(255);
//create the film array, "testFilm0.mov" to "testFilm11.mov"
for (int i = 0; i < phoneFilm.length; i ++ ) {
phoneFilm[i] = new Movie(this, "testFilm" + i + ".mov");
phoneFilm[i].loop();
}
}
void draw() {
//work out the zones, X axis switches between movie clips
int zRange = (width/9);
int zone0 = 0;
int zone1 = (zRange * 1);
int zone2 = (zRange * 2);
int zone3 = (zRange * 3);
int zone4 = (zRange * 4);
int zone5 = (zRange * 5);
int zone6 = (zRange * 6);
int zone7 = (zRange * 7);
int zone8 = (zRange * 8);
int Xaxis = mouseX;
image(phoneFilm[5],0,0);
//pick which movie clip to switch to
if ((Xaxis > zone0) && (Xaxis < zone1)) { //if the cursor is in the first zone (zone0)
image(phoneFilm[0],0,0);
}
//using the Y axis mouse cursor location to move through the frames of the film
float ratio = mouseY/ (float) height;
phoneFilm.jump(ratio*phoneFilm.duration());
phoneFilm.read();
image(phoneFilm, 0, 0);
I recently started working through the Processing examples in a book called "Programming Interactivity" by Joshua Noble. It's an excellent book but unfortunately there seem to be a lot of typos (the errata is rapidly becoming as long as the book).
The code example reads as follows:
class Point{
float x;
float y;
Point(float _x, float _y){
x = _x;
y = _y;
}
Point[] pts = new Point[6];
int count = 0;
void setup(){
size(500, 500);
}
void draw(){
background(255);
fill(0);
beginShape();
for(int i = 0; i<pts.length; i++){
if(pts[i] != null{
vertex(pts[i].x, pts[i].y);
}
}
endShape();
}
void mousePressed(){
if(count > 5){
count = 0;
}
Point newPoint = new Point(mouseX, mouseY);
pts[count] = newPoint;
count++;
}
class Point{
float x;
float y;
Point(float _x, float _y){
x = _x;
y = _y;
}
}
The error Processing throws up is "unexpected token: null".