Cover
 This is the archive Discourse for the Processing (ALPHA) software. Please visit the new Processing forum for current information.
 Processing 1.0 _ALPHA_    Programming Questions & Help    Programs (Moderators: fry, REAS)    transparency display order « Previous topic | Next topic »

 Pages: 1
 Author Topic: transparency display order  (Read 343 times)
Mark Hill

 transparency display order « on: Oct 26th, 2004, 1:49pm »

Hi, I'm new to processing and have encountered a problem I can't solve.

I need some help with this as my graphics programming is pretty thin and very outdated.

Using the alpha channel to display semi-transparent cubes highlights the need for a method to display cube facets according to their current orientation, otherwise the normal display order affects how the transparency will work.

Here's some basic code that highlights the problem (it uses a webcam)

The screen rotation affects the display order making certain frontal planes opaque when they should be semi-transparent in order to reveal the hidden facets (the cubes need to be drawn from the back in my estimation). Does anyone have a way of producing a display order buffer for each plane?

Mark.

code...

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);
noStroke();

beginVideo(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 loop()
{
background(0);

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;

BImage[] facets;

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

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

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

void updateFacet(BImage facet) {

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

void draw() {

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

scale(cubeScale);

fill(128, 128, 0, 210);
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);
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();

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();

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();

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();

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();

pop();

}

}
 Pages: 1

 Forum Jump: ----------------------------- Discussion -----------------------------  - Community, Collaboration, Status   - Events, Publications, Propaganda   - General Processing Discussion ----------------------------- Programming Questions & Help -----------------------------  - Syntax => Programs   - Integration ----------------------------- Topics & Contributions -----------------------------  - Tools   - Responsive Form, Games   - Information Visualization   - Simulation, Artificial Life   - Tangible Computing   - Automated Systems   - Sound   - Video, Camera   - Beyond Categories ----------------------------- Suggestions -----------------------------  - Software Suggestions   - Website, Reference, Example Suggestions ----------------------------- Bugs -----------------------------  - Software Bugs   - Website, Reference, Example Bugs   - Bug Fixes, Implemented Suggestions ----------------------------- Teaching -----------------------------  - Course Blueprints   - Theory and Practice « Previous topic | Next topic »