3d room

Felix Högner

Dies ist ein frühes Experiment mit Processing 3D und Open GL. Hier noch mit Maussteuerung, später kam dann noch eine Facedetection-Library dazu.


import hypermedia.video.*;
import processing.opengl.*;
import codeanticode.glgraphics.*;
PFont futura;
float z = 1000.0;
float camX = 0;
float camY = 0;
float camCenterY = 0;
float camCenterX = 0;
float a = -500;
boolean changedir = false;
float linerotone = 0;
float linerottwo = 0;
int side = 0;
float tr;
void setup() {
size(640, 480, OPENGL);
futura = createFont("DIN-Bold", 48);
fill(204);
ambientLight(100, 50, 50);
frameRate(30);
smooth();
}
void draw() {
background(0);
lights();
camX = (-width/2+pmouseX)*PI/1.5;
camY = (-height/2+pmouseY)*PI;
camCenterX = -(-width/2+pmouseX);
camCenterY = -height/2+pmouseY;
perspective();
// Change height of the camera with mouseY
camera(camX , camY, z, // eyeX, eyeY, eyeZ
camCenterX, camCenterY, -100, // centerX, centerY, centerZ
0.0 , 1.0, 0.0); // upX, upY, upZ
if(keyPressed){
if(key == 's'){
z = z+10.0;
}
else if(key == 'w'){
z = z-10.0;
}
}
noFill();
pushMatrix();
for(int side = 0; side<2000; side+=200){
//side+=100;
//drawsquare(side);
stroke(125);
strokeWeight(2);
line(-(side),100,-(side),side,100,-(side));
line(side,100,-(side),side,100,side);
line(side,100,side,-(side),100,side);
line(-(side),100,side,-(side),100,-side);
}
popMatrix();
pushMatrix();
line(-2000,100,-2000,2000,100,2000);
line(2000,100,-2000,-2000,100,2000);
popMatrix();
stroke(200,0,0);
strokeWeight(6);
linerotone+=0.005;
pushMatrix();
rotateZ(linerotone);
line(10,10,0,0,180,0);
line(-10,-10,0,0,-180,0);
popMatrix();
pushMatrix();
rotateZ(linerotone*(-PI/2));
line(10,10,0,0,200,-200);
line(-10,-10,0,0,-200,200);
popMatrix();
linerottwo-=0.005;
pushMatrix();
rotateZ(linerotone*(PI/8));
line(10,10,0,0,200,-400);
line(-10,-10,0,0,-200,400);
popMatrix();
pushMatrix();
rotateZ(linerotone*(-PI/16));
line(10,10,0,0,200,-600);
line(-10,-10,0,0,-200,600);
popMatrix();
noStroke();
fill(0,255,0);
if(changedir == false){
a+=5;
}
if(a>=500){
changedir = true;
}
if(changedir == true){
a-=5;
}
if(a<=-500){
changedir = false;
}
tr+=0.005;
rotateY(tr);
textFont(futura);
text("...wir sind im Besitz der Mittel, aber ohne Idee!",-400,0,a);
}