Hi. I'm having some problems using the 3D library, and am hoping someone can point me in the right direction.
What I want to do is pull in an image from the webcam, display it, and then superimpose another image that I can rotate in 3D. Basically, it's like this texture example (http://processing.org/learning/3d/texture1.html), but with an additional texture (a fixed one taken from the webcam).
I've gotten really close, but for some reason, when I superimpose the smaller image, it gets cut in half. If I comment out the section that draws the webcam image, the superimposed image works fine. So, I'm thinking there's something I'm missing.
Any help greatly appreciated!!!
Code:
import processing.opengl.*;
import processing.video.*;
Capture cam; //Set up the camera
int WIDTH = 640;
int HEIGHT = 480;
PImage img, camCapture;
int imgX = WIDTH/2;
int imgY = HEIGHT/2;
int imgH, imgW;
void setup() {
size(WIDTH, HEIGHT, P3D);
img = loadImage("http://covers.oreilly.com/images/0636920000617/cat.gif");
imgW = img.width;
imgH = img.height;
cam = new Capture(this, WIDTH, HEIGHT);
noStroke();
}
void draw() {
if (cam.available() == true) {
cam.read();
}
//
background(0);
//Draw the webcam pic
pushMatrix();
beginShape();
texture(cam);
vertex(0,0,0,0,0);
vertex(WIDTH,0,0,WIDTH,0);
vertex(WIDTH,HEIGHT,0,WIDTH,HEIGHT);
vertex(0,HEIGHT,0,0,HEIGHT);
endShape();
popMatrix();
// Now superimpose the image
pushMatrix();
translate(imgX, imgY);
rotateY(map(mouseX, 0, width, -PI, PI));
// rotateX(map(mouseY, 0, height, -PI, PI));
beginShape();
texture(img);
vertex(-imgW/2, -imgH/2, 0, 0, 0);
vertex(imgW/2, -imgH/2, 0, imgW, 0);
vertex(imgW/2, imgH/2, 0, imgW, imgH);
vertex(-imgW/2, imgH/2, 0, 0, imgH);
endShape();
popMatrix();
}