Hello,
I’m trying to map a video image from a webcam on a PShape.
It seems that colors are changing but the video image don’t appear…
See my code below.
Thank you for your help.
import processing.video.*;
import processing.opengl.*;
import peasy.PeasyCam;
int nbObjets = 10;
int nbVectors = nbObjets*4;
PVector[] v = new PVector[nbVectors];
PImage monImage;
color GREEN = color(0, 255, 0);
color RED = color(255, 0, 0);
color BLACK = color(0, 0, 0);
PeasyCam cam;
Capture video;
MyShape [] tabMyShape = new MyShape[nbObjets];
void setup() {
size(600, 600, P3D);
cam = new PeasyCam(this, 400);
for (int i=0; i<nbVectors; i++) {
v[i] = new PVector(int(random(width)), int(random(height)), int(random(-1000, 1000)));
}
for (int i=0; i<nbObjets; i++) {
tabMyShape[i] = new MyShape(GREEN, BLACK, v, i+1);
}
video = new Capture(this, 320, 240);
video.start();
//frameRate(20);
}
void captureEvent(Capture video) {
video.read();
}
void draw() {
background(0);
for (int i = 0; i < nbVectors; i++) {
v[i].x += random(-10, 10);
v[i].y += random(-10, 10);
v[i].z += random(-10, 10);
}
for (int i=0; i<nbObjets; i++) {
//tabMyShape[i].shapeColor = color(random(255), random(255));
tabMyShape[i].strokeColor = color(255);
tabMyShape[i].display(video);
}
}
class MyShape {
color shapeColor;
color strokeColor;
int index;
int U, V;
//Constructor
MyShape(color inColor, color inStroke, PVector[] vectorArray, int unIndex) {
shapeColor = inColor;
strokeColor = inStroke;
v = vectorArray;
index = unIndex;
}
void display(PImage uneVideo) {
strokeWeight(int(random(4)));
//fill(shapeColor);
stroke(strokeColor);
beginShape();
textureMode(NORMAL);
texture(uneVideo);
tint(255, 60);//transparency
for (int i=0; i<4; i++) {//mapping video image on the 4 corners
switch(i) {
case 0 :
U = 0 ;
V = 0;
case 1 :
U = 1;
V = 0;
case 2 :
U = 1;
V = 1;
case 3 :
U = 0;
V = 1;
}
texture(uneVideo);//texture video
vertex(v[i+(4*(index-1))].x, v[i+(4*(index-1))].y, v[i+(4*(index-1))].z, U, V);
}
endShape(CLOSE);
}
}