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 & HelpSyntax Questions › Question about photo cube
Page Index Toggle Pages: 1
Question about photo cube (Read 748 times)
Question about photo cube
Nov 12th, 2009, 12:29am
 
I'm trying to make a cube with a different photo on each side. I found a couple of sketches that are good starts.

This one is all fills:

[ugh, the site won't let me post links since I have under 5 posts, but this one is called RGBcube from the tutorials]

And this one is sooo close, but only shows one image:

[if you google search for "texturecube site:processing.org" you'll find this link, sorry about this]

I understand the principle of using an image for a texture(), and that texture() must be called before setting any of the vertices, but given that, how would I set a different picture for each side of the cube? Do I build 6 different rectangles and then map them to a cube?

Thanks for any hints.
Re: Question about photo cube
Reply #1 - Nov 12th, 2009, 2:06am
 
Alomost all the work is already done. As you can see the cube is already seperated in the different faces. What you have to do now is to define 6 different textures and put the beginShape, endShape arround every single shape and then apply the different textures to it.
Re: Question about photo cube
Reply #2 - Nov 12th, 2009, 3:24am
 
So I'd be defining 6 different shapes, each with a different texture (picture), and then laying those different shapes onto this 3d cube?
Re: Question about photo cube
Reply #3 - Nov 12th, 2009, 3:26am
 
these shapes are the sides of the cube. just see how beginshape and texture is already used and do this not to all the sides but to every single one.
Re: Question about photo cube
Reply #4 - Nov 12th, 2009, 4:59am
 
I'm sure I'm just doing something dumb, but I still don't understand. I'm trying to define a new shape using beginshape inside my other shape, but having no luck.

Here's a code sample that I'm trying:

Code:
PImage tex;
PImage tex2;
float rotx = PI/4;
float roty = PI/4;

void setup()
{
size(1024, 768, P3D);
tex = loadImage("pic4.jpg");
tex2 = loadImage("pic2.jpg");
textureMode(NORMALIZED);
fill(255);
stroke(color(44,48,32));
}

void draw()
{
background(0);
noStroke();
translate(width/2.0, height/2.0, -100);
rotateX(rotx);
rotateY(roty);
scale(160);
TexturedCube(tex);


}

void TexturedCube(PImage tex) {



// attempting to draw a new shape that will become one of the sides of the cube
beginShape();
texture(tex2);
vertex(30, 20);
vertex(285, 20);
vertex(285, 375);
vertex(30, 375);
endShape(CLOSE);


// the main 3d cube
beginShape(QUADS);

texture(tex);

// Given one texture and six faces, we can easily set up the uv coordinates
// such that four of the faces tile "perfectly" along either u or v, but the other
// two faces cannot be so aligned. This code tiles "along" u, "around" the X/Z faces
// and fudges the Y faces - the Y faces are arbitrarily aligned such that a
// rotation along the X axis will put the "top" of either texture at the "top"
// of the screen, but is not otherwised aligned with the X/Z faces. (This
// just affects what type of symmetry is required if you need seamless
// tiling all the way around the cube)



// +Z "front" face
vertex(-1, -1, 1, 0, 0);
vertex( 1, -1, 1, 1, 0);
vertex( 1, 1, 1, 1, 1);
vertex(-1, 1, 1, 0, 1);

// -Z "back" face
vertex( 1, -1, -1, 0, 0);
vertex(-1, -1, -1, 1, 0);
vertex(-1, 1, -1, 1, 1);
vertex( 1, 1, -1, 0, 1);

// +Y "bottom" face
vertex(-1, 1, 1, 0, 0);
vertex( 1, 1, 1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex(-1, 1, -1, 0, 1);

// -Y "top" face
vertex(-1, -1, -1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, -1, 1, 1, 1);
vertex(-1, -1, 1, 0, 1);

// +X "right" face
vertex( 1, -1, 1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex( 1, 1, 1, 0, 1);

// -X "left" face
vertex(-1, -1, -1, 0, 0);
vertex(-1, -1, 1, 1, 0);
vertex(-1, 1, 1, 1, 1);
vertex(-1, 1, -1, 0, 1);

endShape();

}

void mouseDragged() {
float rate = 0.01;
rotx += (pmouseY-mouseY) * rate;
roty += (mouseX-pmouseX) * rate;
}
Re: Question about photo cube
Reply #5 - Nov 12th, 2009, 6:34am
 
was my explaination so bad?
this is what i ment


Code:
PImage tex,tex2;
float rotx = PI/4;
float roty = PI/4;

void setup()
{
size(640, 360, P3D);
tex = loadImage("image1.jpg");
tex2 = loadImage("image2.jpg");
tex3 = loadImage("image3.jpg");
tex4 = loadImage("image4.jpg");
tex5 = loadImage("image5.jpg");
tex6 = loadImage("image6.jpg");

textureMode(NORMALIZED);
fill(255);
stroke(color(44,48,32));
}

void draw()
{
background(0);
noStroke();
translate(width/2.0, height/2.0, -100);
rotateX(rotx);
rotateY(roty);
scale(90);
TexturedCube(tex);
}

void TexturedCube(PImage tex) {

beginShape(QUADS);
texture(tex);
// +Z "front" face
vertex(-1, -1, 1, 0, 0);
vertex( 1, -1, 1, 1, 0);
vertex( 1, 1, 1, 1, 1);
vertex(-1, 1, 1, 0, 1);
endShape();

beginShape(QUADS);
texture(tex2);
// -Z "back" face
vertex( 1, -1, -1, 0, 0);
vertex(-1, -1, -1, 1, 0);
vertex(-1, 1, -1, 1, 1);
vertex( 1, 1, -1, 0, 1);
endShape();

beginShape(QUADS);
texture(tex3);
// +Y "bottom" face
vertex(-1, 1, 1, 0, 0);
vertex( 1, 1, 1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex(-1, 1, -1, 0, 1);
endShape();

beginShape(QUADS);
texture(tex4);
// -Y "top" face
vertex(-1, -1, -1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, -1, 1, 1, 1);
vertex(-1, -1, 1, 0, 1);
endShape();

beginShape(QUADS);
texture(tex5);
// +X "right" face
vertex( 1, -1, 1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex( 1, 1, 1, 0, 1);
endShape();

beginShape(QUADS);
texture(tex6);
// -X "left" face
vertex(-1, -1, -1, 0, 0);
vertex(-1, -1, 1, 1, 0);
vertex(-1, 1, 1, 1, 1);
vertex(-1, 1, -1, 0, 1);
endShape();

}

void mouseDragged() {
float rate = 0.01;
rotx += (pmouseY-mouseY) * rate;
roty += (mouseX-pmouseX) * rate;
}

Page Index Toggle Pages: 1