 |
Author |
Topic: Voxels (Read 717 times) |
|
madmerv Guest

|
Voxels
« on: Nov 12th, 2003, 7:26pm » |
|
// Crude Voxel Renderer (Example 2) // by merv // http://www.madmerv.com // Load and display an image texture-mapped on a voxel surface. // Bump map and image map must be same dimensions. Preferably divisible by 2. // Created 10 November 2003 float xmag, ymag = 0; float newXmag, newYmag = 0; float xyzscale = 1; float delta = 0.01; int xRes = 640; int yRes = 480; int xcount; int ycount; color xy2; BImage img; BImage bump; float vsize = .05; // scale of the voxels void svertex( float x, float y, float z ) { vertex( x*xyzscale, y*xyzscale, z*xyzscale ); } // // Draws a cubic prism of color c. // void prism2( float ofsx, float ofsy, float ofsz, float w, float h, float l ) { svertex(-w+ofsx, h+ofsy, l+ofsz); svertex( w+ofsx, h+ofsy, l+ofsz); svertex( w+ofsx, -h+ofsy, l+ofsz); svertex(-w+ofsx, -h+ofsy, l+ofsz); svertex( w+ofsx, h+ofsy, l+ofsz); svertex( w+ofsx, h+ofsy, -l+ofsz); svertex( w+ofsx, -h+ofsy, -l+ofsz); svertex( w+ofsx, -h+ofsy, l+ofsz); svertex( w+ofsx, h+ofsy, -l+ofsz); svertex(-w+ofsx, h+ofsy, -l+ofsz); svertex(-w+ofsx, -h+ofsy, -l+ofsz); svertex( w+ofsx, -h+ofsy, -l+ofsz); svertex(-w+ofsx, h+ofsy, -l+ofsz); svertex(-w+ofsx, h+ofsy, l+ofsz); svertex(-w+ofsx, -h+ofsy, l+ofsz); svertex(-w+ofsx, -h+ofsy, -l+ofsz); svertex(-w+ofsx, h+ofsy, -l+ofsz); svertex( w+ofsx, h+ofsy, -l+ofsz); svertex( w+ofsx, h+ofsy, l+ofsz); svertex(-w+ofsx, h+ofsy, l+ofsz); svertex(-w+ofsx, -h+ofsy, -l+ofsz); svertex( w+ofsx, -h+ofsy, -l+ofsz); svertex( w+ofsx, -h+ofsy, l+ofsz); svertex(-w+ofsx, -h+ofsy, l+ofsz); } void setup() { size(xRes, yRes); noStroke(); colorMode(RGB, 1); } void loop() { int count; background(0, 0, .2); // Load the image // img = loadImage("voxeltest.jpg"); // bump = loadImage("voxeltest.jpg"); // img = loadImage("texture.gif"); // bump = loadImage("bump.gif"); img = loadImage("marsfacetex.jpg"); bump = loadImage("marsfacebmp.gif"); push(); translate(width/2, height/2, -30); newXmag = mouseX/float(width) * TWO_PI; newYmag = mouseY/float(height) * TWO_PI; 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); scale(50); if ((xyzscale >= 3) || (xyzscale <= 0.4)) { delta = -delta; } xyzscale = xyzscale + delta; // beginShape(QUADS); // prism( 0, 0, 0, 1, 1, 1 ); // endShape(); for ( xcount = -(img.width/2); xcount < img.width/2; xcount++ ) { for ( ycount = -(img.height/2); ycount < img.height/2; ycount++ ) { // if (xcount%2>0 && ycount%2>0 && xcount*ycount != 0) { beginShape(QUADS); float vheight; fill( img.pixels[(xcount+img.width/2)+(img.width*(ycount+img.height/2))] ); // if i use this next line instead of the following, also does not work: // xy2 = red(bump.pixels[(xcount+bump.width/2)+(bump.width*(ycount+bump.height/2))]); xy2 = bump.pixels[(xcount+bump.width/2)+(bump.width*(ycount+bump.height/2))]; vheight = ((xy2 % 256)/32); vheight = min(vsize,vheight); // prism2( vsize*xcount, vsize*ycount, (-vsize*vheight)/2, vsize, vsize, vsize*vheight);//*vheight ); prism2( vsize*xcount, vsize*ycount, (-vsize*vheight)/2, vsize, vsize, vsize*vheight);//*vheight ); endShape(); // } } } pop(); }
|
« Last Edit: Nov 12th, 2003, 7:26pm by madmerv » |
|
|
|
|
rgovostes
|
Re: Voxels
« Reply #1 on: Nov 13th, 2003, 12:54am » |
|
Your projects look interesting, but I don't have the images they require. Do you have somewhere online that you could upload them? Edit: I see that you do - could you put them up with the corresponding image files?
|
« Last Edit: Nov 13th, 2003, 12:58am by rgovostes » |
|
|
|
|
toxi
|
Re: Voxels
« Reply #3 on: Nov 14th, 2003, 12:27pm » |
|
madmerv, load your images only in the setup() method, else they'll be reloaded every frame and the thing is unwatchable, ie. i'm only seeing the dark blue background. also, as said before, a bit more info about the code would be nice... don't be a stranger!
|
http://toxi.co.uk/
|
|
|
madmerv Guest

|
Re: Voxels
« Reply #4 on: Nov 14th, 2003, 4:22pm » |
|
oh wow! will fix thanks! of course, you could do animated landscapes based on video *woopwoop* ;p
|
« Last Edit: Nov 14th, 2003, 4:24pm by madmerv » |
|
|
|
|
|