radarboy
Junior Member
Offline
Posts: 53
mapping image onto Cube
Oct 9th , 2008, 9:05am
Hey there been trying to map a texture onto a 3d cube. but kinda stuck. do i need to use vertex points instead of cube to get access to texture. if so the math is above me. basically what i want to do is slice an image (in the end actually video) and then be able to manipulate it in 3d. i've got it to work in flash, but hit deadend in processing. here's my (messy) cube code: import processing.opengl.*; int yy, counter,boxht, boxwidth; Slice [] slice = new Slice[20]; float[] t = new float[20]; float[] speed = new float[20]; float target; void setup() { size(800, 600, OPENGL); noStroke(); yy=0; boxht=30; boxwidth=300; counter=0; for (int i = 180; i <= height-180; i += boxht) { slice[counter] = new Slice(i,counter); counter++; } } void draw() { defineLights(); background(0); for (int i = 0; i <9; i++) { slice[i].updateslice(); } } void defineLights() { // Orange point light on the right pointLight(150, 100, 0, // Color 200, -150, 0); // Position // Blue directional light from the left directionalLight(0, 102, 255, // Color width/2, height/2, -100); // The x-, y-, z-axis direction // Blue directional light from the left directionalLight(0, 202, 0, // Color -1, 0, 0); // The x-, y-, z-axis direction // Yellow spotlight from the front spotLight(255, 255, 109, // Color 0, 40, 200, // Position 0, -0.5, -0.5, // Direction PI / 2, 2); // Angle, concentration } class Slice{ int myx,myy,yy, me; float speed, mytarget, currentpos; Slice(int y, int c) { speed=10; mytarget=currentpos=0; myy=y; me=c; } void updateslice(){ if (mouseY>myy && mouseY<myy+boxht){ mytarget+=(mouseX-pmouseX)*2; } pushMatrix(); translate(width/2, myy); currentpos += (mytarget-currentpos)/(speed); otherspeeds(me); rotateY(map(currentpos, 0, height, 0, PI)); box(boxwidth, boxht, boxwidth); popMatrix(); } void otherspeeds(int blokhit){ for (int i = 0; i <9; i++) { if (i!=blokhit){ // float vx = slice[i].currentpos-slice[blokhit].mytarget; //if (vx>0) { //xaccel = -(vx*vx)/(acceleration); //} else { //xaccel = (vx*vx)/(acceleration); //} //slice[i].speed = (slice[i].speed+xaccel)*friction; slice[i].speed= 10+abs(i-blokhit*2)*5; } } } }