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.
IndexProgramming Questions & HelpPrograms › RGB Cube -> Cube with Images For Faces
Page Index Toggle Pages: 1
RGB Cube -> Cube with Images For Faces? (Read 525 times)
RGB Cube -> Cube with Images For Faces?
Apr 23rd, 2006, 5:10am
 
How would one go about adapting this example:

http://www.processing.org/learning/examples/rgbcube.html

so that the could have a separate image displayed as a texture for each face?

I've seen this attempt:

http://www.britely.com/imagecube/

Which seems to mostly work... except each of the six images don't seem to map to a separate face. Rather, the last image seems to be used as a texture for all faces.

I tried putting a beginShape around each of the vertex sets and texture functions for each face, but when I ran it, I got the Mac OS X spinning beach ball of death, and had to Force-quite processing, so I'm guessing that's not the right road... can someone point me in a better direction?

Thanks!


Re: RGB Cube -> Cube with Images For Faces?
Reply #1 - Apr 23rd, 2006, 8:53am
 
This will need a bit of tweaking to suit your purposes. It's very old and probably a bit mouldy, but I've just modified it to run under Beta for you:

Code:


import processing.video.*;

Capture cam;

float cubeScale=40;
float xmag, ymag = 0;
float newXmag, newYmag = 0;

int nNode = 1;
Node[] node = new Node[nNode];
float rotY, rotX;
int vDimX= 200;
int vDimY= 200;

void setup()
{
size(600,600, P3D);
noStroke();

// beginVideo(vDimX, vDimY, 25);
cam = new Capture (this, vDimX, vDimY, 25);

float j= 0; //-1;
float k= 0; //-1;
float l= 0; //-1;

for (int i=0;i<nNode;i++)
{
node[i] = new Node(j, k, l);
if(j++>= 1) {j=-1; if(k++>=1) {k=-1; l++;}}
}
}

void mouseDragged()
{
newXmag = mouseX/float(width) * TWO_PI;
newYmag = mouseY/float(height) * TWO_PI;
}

void draw()
{
background(255);

translate(width/2,height/2, 0);

float diff = xmag-newXmag;
if (abs(diff) > 0.01) { xmag -= diff/4.0; }

diff = ymag-newYmag;
if (abs(diff) > 0.01) { ymag -= diff/4.0; }

rotateX(-ymag);
rotateY(-xmag);

int i= (int)random(0, nNode);
int j= (int)random(0, 6);
node[i].updateFacet(node[i].facets[j]);

for (int k= 0; k< nNode; k++) {
node[k].draw();
}

if(cubeScale <100) {cubeScale+=0.25;}
}


class Node {
float xpos= 0;
float ypos= 0;
float zpos= 0;

PImage[] facets;

Node(float x, float y, float z) {

xpos = x*100;
ypos = y*100;
zpos = z*100;

facets = new PImage[6];
for(int i=0; i<6; i++) {
facets[i] = new PImage(vDimX, vDimY);
}
}


void updateFacet(PImage facet) {

if (cam.available()) {
cam.read();
}

for(int i=0; i<facet.width*facet.height; i++) {
facet.pixels[i]= cam.pixels[i];
}
}

void draw() {

pushMatrix();
translate(xpos,ypos,zpos);

scale(cubeScale);

fill(128, 230);
beginShape(QUADS);
texture(facets[0]);
vertex(-1, 1, 1, -vDimX, vDimY);
vertex( 1, 1, 1, vDimX, vDimY);
vertex( 1, -1, 1, vDimX, -vDimY);
vertex(-1, -1, 1, -vDimX, -vDimY);
endShape();

fill(128, 210);
beginShape(QUADS);
texture(facets[1]);
vertex( 1, 1, 1, -vDimX, vDimY);
vertex( 1, 1, -1, vDimX, vDimY);
vertex( 1, -1, -1, vDimX, -vDimY);
vertex( 1, -1, 1, -vDimX, -vDimY);
endShape();

beginShape(QUADS);
texture(facets[2]);
vertex( 1, 1, -1, -vDimX, vDimY);
vertex(-1, 1, -1, vDimX, vDimY);
vertex(-1, -1, -1, vDimX, -vDimY);
vertex( 1, -1, -1, -vDimX, -vDimY);
endShape();

beginShape(QUADS);
texture(facets[3]);
vertex(-1, 1, -1, -vDimX, vDimY);
vertex(-1, 1, 1, vDimX, vDimY);
vertex(-1, -1, 1, vDimX, -vDimY);
vertex(-1, -1, -1, -vDimX, -vDimY);
endShape();

beginShape(QUADS);
texture(facets[4]);
vertex(-1, 1, -1, -vDimX, vDimY);
vertex( 1, 1, -1, vDimX, vDimY);
vertex( 1, 1, 1, vDimX, -vDimY);
vertex(-1, 1, 1, -vDimX, -vDimY);
endShape();

beginShape(QUADS);
texture(facets[5]);
vertex(-1, -1, -1, -vDimX, vDimY);
vertex( 1, -1, -1, vDimX, vDimY);
vertex( 1, -1, 1, vDimX, -vDimY);
vertex(-1, -1, 1, -vDimX, -vDimY);
endShape();

popMatrix();

}

}


Page Index Toggle Pages: 1