We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
3D drawing problem (Read 1219 times)
3D drawing problem
Apr 23rd, 2010, 7:47am
 
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();
}

Re: 3D drawing problem
Reply #1 - Apr 24th, 2010, 12:14pm
 
This Topic was moved here from Programs by antiplastik.
Page Index Toggle Pages: 1