var zeichenflaeche, x; let cam1, cam2, locked, carx, carz, carTilt, whichcam, carDirection, carVelocity, carPosition, carAngle, tireTilt; let blau, braun, hellgrau, dunkelgrau, rot; let houses; let grauTexture, blauTexture, grau, sblau; preload = function(){ track = loadImage("animal_crossing_texture.png"); grau = loadShader('grau.vert','grau.frag'); sblau = loadShader('blau.vert','blau.frag'); } function vectorRotateY(vectorin, theta) { return createVector(vectorin.x*cos(theta) - vectorin.z*sin(theta), vectorin.y, vectorin.x*sin(theta) + vectorin.z*cos(theta)) } function mouseClicked() { if (!locked) { locked = true; requestPointerLock(); } else { exitPointerLock(); locked = false; } } function keyPressed() { if (key == "c") { whichcam ^= 1; if (whichcam == 1) { setCamera(cam1); } else { setCamera(cam2); } carVelocity = 0; } } function hochhausBenDieGeileSauXD(vector) { push(); //translate(hausx, hausy-8000, hausz); translate(vector); translate(0, -600, 0); scale(3); //Haus Grundform push(); ambientMaterial(hellgrau); noStroke(); box(200, 400, 200); pop(); push(); translate(0, -200, 95) ambientMaterial(hellgrau); noStroke(); box(200, 20, 10); pop(); push(); translate(0, -200, -95) ambientMaterial(hellgrau); noStroke(); box(200, 20, 10); pop(); push(); translate(-95, -200, 0) rotateY(90) ambientMaterial(hellgrau); noStroke(); box(200, 20, 10); pop(); push(); translate(95, -200, 0) rotateY(90) ambientMaterial(hellgrau); noStroke(); box(200, 20, 10); pop(); //Balkone mit Fenster Seite 1 push(); translate(-50, 150, 110); ambientMaterial(dunkelgrau); noStroke(); box(50, 5, 30); pop(); push(); translate(-73, 140, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-27, 140, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-50, 140, 125); rotateX(90); box(50, 5, 25); pop(); push(); translate(-50, 120, 99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(-50, 70, 110); box(50, 5, 30); pop(); push(); translate(-73, 60, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-27, 60, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-50, 60, 125); rotateX(90); box(50, 5, 25); pop(); push(); translate(-50, 40, 99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(50, 70, 110); box(50, 5, 30); pop(); push(); translate(73, 60, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(27, 60, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(50, 60, 125); rotateX(90); box(50, 5, 25); pop(); push(); translate(50, 40, 99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(50, -10, 110); box(50, 5, 30); pop(); push(); translate(73, -20, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(27, -20, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(50, -20, 125); rotateX(90); box(50, 5, 25); pop(); push(); translate(50, -40, 99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(-50, -10, 110); box(50, 5, 30); pop(); push(); translate(-73, -20, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-27, -20, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-50, -20, 125); rotateX(90); box(50, 5, 25); pop(); push(); translate(-50, -40, 99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(-50, -90, 110); box(50, 5, 30); pop(); push(); translate(-73, -100, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-27, -100, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-50, -100, 125); rotateX(90); box(50, 5, 25); pop(); push(); translate(-50, -120, 99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(50, -90, 110); box(50, 5, 30); pop(); push(); translate(73, -100, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(27, -100, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(50, -100, 125); rotateX(90); box(50, 5, 25); pop(); push(); translate(50, -120, 99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(50, 150, 110); box(50, 5, 30); pop(); push(); translate(73, 140, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(27, 140, 110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(50, 140, 125); rotateX(90); box(50, 5, 25); pop(); push(); translate(50, 120, 99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); //Balkone mit Fenster Seite 2 push(); translate(-50, 150, -110); box(50, 5, 30); pop(); push(); translate(-73, 140, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-27, 140, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-50, 140, -125); rotateX(90); box(50, 5, 25); pop(); push(); translate(-50, 120, -99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(-50, 70, -110); box(50, 5, 30); pop(); push(); translate(-73, 60, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-27, 60, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-50, 60, -125); rotateX(90); box(50, 5, 25); pop(); push(); translate(-50, 40, -99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(50, 70, -110); box(50, 5, 30); pop(); push(); translate(73, 60, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(27, 60, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(50, 60, -125); rotateX(90); box(50, 5, 25); pop(); push(); translate(50, 40, -99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(50, -10, -110); box(50, 5, 30); pop(); push(); translate(73, -20, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(27, -20, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(50, -20, -125); rotateX(90); box(50, 5, 25); pop(); push(); translate(50, -40, -99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(-50, -10, -110); box(50, 5, 30); pop(); push(); translate(-73, -20, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-27, -20, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-50, -20, -125); rotateX(90); box(50, 5, 25); pop(); push(); translate(-50, -40, -99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(-50, -90, -110); box(50, 5, 30); pop(); push(); translate(-73, -100, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-27, -100, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(-50, -100, -125); rotateX(90); box(50, 5, 25); pop(); push(); translate(-50, -120, -99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(50, -90, -110); box(50, 5, 30); pop(); push(); translate(73, -100, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(27, -100, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(50, -100, -125); rotateX(90); box(50, 5, 25); pop(); push(); translate(50, -120, -99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(50, 150, -110); box(50, 5, 30); pop(); push(); translate(73, 140, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(27, 140, -110); rotateZ(90) box(25, 5, 30); pop(); push(); translate(50, 140, -125); rotateX(90); box(50, 5, 25); pop(); push(); translate(50, 120, -99); rotateX(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); //Fenster mit Tür Seite 3 push(); translate(99, 120, -50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(99, 120, 50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(99, 40, 50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(99, 40, -50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(99, -40, -50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(99, -40, 50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(99, -120, 50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(99, -120, -50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(99, 180, 0); rotateZ(90); ambientMaterial(braun); noStroke(); box(40, 5, 35); pop(); //Fenster mit Tür Seite 4 push(); translate(-99, 120, -50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(-99, 120, 50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(-99, 40, 50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(-99, 40, -50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(-99, -40, -50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(-99, -40, 50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(-99, -120, 50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(-99, -120, -50); rotateZ(90); ambientMaterial(blau); noStroke(); box(25, 5, 40); pop(); push(); translate(-99, 180, 0); rotateZ(90); ambientMaterial(braun); noStroke(); box(40, 5, 35); pop(); pop(); } function cybertruckTjorbenDieGeileSauXD() { function rad(cylx, cyly, cylz, tilt) { push(); ambientMaterial(100, 100, 100); //translate(carPosition); translate(cylx, cyly, cylz); rotateY(tilt); rotateX (90); cylinder(18, 15); pop(); } function kot(kotx,koty,kotz) { push(); ambientMaterial(50, 50, 50); noStroke (); translate(kotx,koty,kotz); beginShape(); vertex (kotx, koty, kotz); vertex (kotx + 20, koty - 20, kotz); vertex (kotx + 15, koty - 25, kotz - 5); vertex (kotx - 5, koty - 5, kotz - 5); endShape (CLOSE); beginShape(); vertex (kotx + 20, koty - 20, kotz); vertex (kotx + 15, koty - 25, kotz - 5); vertex (kotx + 45, koty - 25, kotz - 5); vertex (kotx + 40, koty - 20, kotz); endShape(CLOSE); beginShape(); vertex (kotx + 40, koty - 20, kotz); vertex (kotx + 60, koty, kotz); vertex (kotx + 65, koty - 5, kotz - 5); vertex (kotx + 45, koty - 25, kotz - 5); endShape (CLOSE); pop(); } function heck() { push(); ambientMaterial(30, 30, 30); //translate(carPosition); noStroke (); beginShape(); vertex (100.5, -20, -50); vertex (100.5, -20, 50); vertex (100.5, -16, 50); vertex (100.5, -16, -50); endShape (CLOSE); ambientMaterial(200, 0, 0); beginShape(); vertex (101, -18.5, -48); vertex (101, -18.5, 48); vertex (101, -17.5, 48); vertex (101, -17.5, -48); endShape (CLOSE); pop(); } function stoßstangen() { //Stoßstangen //Vorne push(); ambientMaterial(50, 50, 50); noStroke(); //translate(carPosition); beginShape(); vertex (-105, 15, -50); vertex (-105, 15, 50); vertex (-100, 20, 55); vertex (-100, 20, -55); endShape(); beginShape(); vertex (-105, 15, -50); vertex (-105, 15, 50); vertex (-100, 15, 50); vertex (-100, 15, -50); endShape(); //Seiten beginShape(); vertex (20, 15, 50); vertex (-40, 15, 50); vertex (-40, 20, 55); vertex (20, 20, 55); endShape(); beginShape(); vertex (20, 15, -50); vertex (-40, 15, -50); vertex (-40, 20, -55); vertex (20, 20, -55); endShape(); //Hinten beginShape(); vertex (80, 15, -50); vertex (80, 20, -55); vertex (105, 20, -55); vertex (100, 15, -50); endShape(); beginShape(); vertex (80, 15, 50); vertex (80, 20, 55); vertex (105, 20, 55); vertex (100, 15, 50); endShape(); beginShape(); vertex (105, 20, -55); vertex (105, 20, 55); vertex (100, 15, 50); vertex (100, 15, -50); endShape(); beginShape(); vertex (105, 20, -55); vertex (105, 20, 55); vertex (100, 23, 50); vertex (100, 23, -50); endShape(); beginShape(); vertex (105, 20, 55); vertex (100, 23, 50); vertex (80, 23, 50); vertex (80, 20, 55); endShape(); beginShape(); vertex (105, 20, -55); vertex (100, 23, -50); vertex (80, 23, -50); vertex (80, 20, -55); endShape(); pop(); } function kotflügel() { //Kotflügel push(); //translate(carPosition); kot( -50, 10, 27.5); kot( 10, 10, 27.5); rotateY (180); kot( -40, 10, 27.5); kot( 20, 10, 27.5); pop(); } function karosserie() { //Karosserie //Front //O push(); texture(grauTexture); //OR beginShape(); vertex(-100, -20, -50, 0, 0); vertex(-120, -12, -35, 0, 1); vertex(-110, -16, 0, 0.5, 0.5); endShape(CLOSE); //OO beginShape(); vertex(-100, -20, -50, 0, 1); vertex(-100, -20, 50, 0, 0); vertex(-110, -16, 0, 0.5, 0.5); endShape(CLOSE); //OL beginShape(); vertex(-100, -20, 50, 0, 1); vertex(-120, -12, 35, 0, 0); vertex(-110, -16, 0, 0.5, 0.5); endShape(CLOSE) //OU beginShape(); vertex(-120, -12, 35, 0, 1); vertex(-120, -12, -35, 0, 0); vertex(-110, -16, 0, 0.5, 0.5); endShape(CLOSE) //L beginShape(); vertex (-100, -20, 50, 0, 1); vertex (-120, -12, 35, 0, 0); vertex (-115, 15, 35, 1, 0); vertex (-100, 15, 50, 1, 1); endShape(); //R beginShape(); vertex (-100, -20, -50, 0, 1); vertex (-120, -12, -35, 0, 0); vertex (-115, 15, -35, 1, 0); vertex (-100, 15, -50, 1, 1); endShape(); //C beginShape(); vertex (-120, -12, -35, 0, 1); vertex (-115, 15, -35, 1, 1); vertex (-115, 15, 35, 1, 0); vertex (-120, -12, 35, 0, 0); endShape(); //U beginShape(); vertex (-100, 15, -50); vertex (-100, 15, 50); vertex (-115, 15, 35); vertex (-115, 15, -35); endShape(); pop(); } function räder() { rad(50, 20, 50, 0); rad(-70, 20, 50, tireTilt); rad(50, 20, -50, 0); rad(-70, 20, -50, tireTilt); } function fenster() { //Fenster push(); texture(blauTexture); //L beginShape(); vertex (-75, -25, 46, 0, 0); vertex (-25, -45, 30, 1, 0); vertex (25, -32, 42, 1, 1); vertex (25, -25, 47, 0, 1); endShape(CLOSE); //H beginShape(); vertex (95, -21.5, 45, 0, 0); vertex (-17, -48.5, 20, 1, 0); vertex (-17, -48.5, -20, 1, 1); vertex (95, -21.5, -45, 0, 1); endShape(CLOSE); //R beginShape(); vertex (-75, -25, -46, 0, 1); vertex (-25, -45, -30, 1, 1); vertex (25, -32, -42, 1, 0); vertex (25, -25, -47, 0, 0); endShape(CLOSE); //V beginShape(); vertex (-85, -26, -40, 0, 0); vertex (-30, -48.25, -20, 1, 0); vertex (-30, -48.25, 20, 1, 1); vertex (-85, -26, 40, 0, 1); endShape(CLOSE); pop(); } function dach() { //Dach push(); texture(grauTexture); //DL (V1,V2,V3) beginShape(); vertex (-100, -20, 50, 0, 1); vertex (-25, -50, 25, 1, 0); vertex (100, -20, 50, 0, 1); endShape(CLOSE); //TH (V3,V2,V4,V5) beginShape(); vertex (100, -20, 50, 0, 0); vertex (-25, -50, 25, 1, 0); vertex (-25, -50, -25, 1, 1); vertex (100, -20, -50, 0, 1); endShape(CLOSE); //DR (V5,V4,V6) beginShape(); vertex (100, -20, -50, 0, 1); vertex (-25, -50, -25, 1, 0); vertex (-100, -20, -50, 0, 1); endShape(CLOSE); //TV (V6,V4,V2,V1) beginShape(); vertex (-100, -20, -50, 0, 0); vertex (-25, -50, -25, 1, 0); vertex (-25, -50, 25, 1, 1); vertex (-100, -20, 50, 0, 1); endShape(CLOSE); pop(); } function cybox(){ //Cybertruck //Box push(); textureMode(NORMAL); texture(grauTexture); //Links beginShape(); vertex(-100, -20, 50, 0, 1); vertex(-100, 20, 50, 1, 1); vertex(100, 20, 50, 1, 0); vertex(100, -20, 50, 0, 0); endShape(CLOSE); //Rechts beginShape(); vertex(-100, -20, -50, 0, 0); vertex(-100, 20, -50, 1, 0); vertex(100, 20, -50, 1, 1); vertex(100, -20, -50, 0, 1); endShape(CLOSE); //Hinten beginShape(); vertex(100, -20, 50, 0, 1); vertex(100, 20, 50, 1, 1); vertex(100, 20, -50, 1, 0); vertex(100, -20, -50, 0, 0); endShape(CLOSE); pop(); } push(); translate(carPosition); rotateY(180); rotateY(carTilt); cybox(); dach(); fenster(); räder(); karosserie(); kotflügel(); stoßstangen(); heck(); pop(); } function house(vector) { push(); ambientMaterial(200); strokeWeight(1); translate(vector); translate(0, -200, 0); box(400); translate(0, -315, 0); rotateX(90); cylinder(231, 400, 4, 3); pop(); } function houseBen(vector) { push(); translate(vector); scale(3); translate(0, -75, 0); //Haus Grundform push(); box(125, 150, 125); pop(); push(); translate(0, -125, 0); rotateZ(180) rotateY(45) fill(rot); noStroke(); cone(100, 100, 5); pop(); push(); translate(-25, 0, -30); rotateY(45) box(10,30,10); pop(); //Garage push(); translate(100,50,59); fill(hellgrau); noStroke(); box(100,50,5); pop(); push(); translate(148,50,16) fill(hellgrau); noStroke(); rotateY(90) box(90,50,5); pop(); push(); translate(109, 25, 13) fill(dunkelgrau); noStroke(); rotateX(90) box(95,100,5); pop(); pop(); //Fenster und Türen } function houseTjorben(vector) { function dach(){ push(); beginShape(); vertex(100, -51, 100); vertex(-100, -51, 100); vertex(-100, -150, 0); vertex(100, -150, 0); endShape(CLOSE); beginShape(); vertex(100, -51, -100); vertex(-100, -51, -100); vertex(-100, -150, 0); vertex(100, -150, 0); endShape(CLOSE); pop(); } function giebel(){ push(); beginShape(); vertex(100, -70, 80); vertex(100, -70, -80); vertex(100, -150, 0); endShape(CLOSE); beginShape(); vertex(-100, -70, 80); vertex(-100, -70, -80); vertex(-100, -150, 0); endShape(CLOSE); pop(); } function schornstein(){ push(); translate(-25, -110, -40); box(20, 100, 20); translate(0, -50, 0); box(25, 10, 25); pop(); } function tür(){ push(); translate(-100.1, 325, 0); push(); translate(0, -300, 0); rotateY(90); plane(40, 80); pop(); push(); translate(-1, -300, 10); rotateY(90); plane(20, 5); pop(); pop(); } function fenster(){ push(); translate(-100, -40, 50); stroke(0, 0, 200); rotateY(90); plane(30); pop(); push(); translate(-100, -40, -50); stroke(0, 0, 200); rotateY(90); plane(30); pop() } push(); translate(vector); scale(2); translate(0, -70, 0); box(200, 140, 160); giebel(); dach(); schornstein(); tür(); fenster(); pop(); } function garten(vector) { function zaun(x, y, z){ function pole(x, y, z){ push(); translate(x, y, z); ambientMaterial(255); plane(5, 20); pop(); } function segment(x, y, z){ push(); translate(x, y, z); ambientMaterial(255); plane(5, 20); translate(12.5, 0, 0) plane(20, 5); pop(); } push(); translate(x, y, z); pole(0, 0, 0); pole(-200, 0, 0); segment(-25, 0, 0); segment(-50, 0, 0); segment(-75, 0, 0); segment(-100, 0, 0); rotateY(180); segment(100, 0, 0); segment(125, 0, 0); segment(150, 0, 0); segment(175, 0, 0); pop(); } function ground(){ push(); rotateX(90); noStroke(); ambientMaterial(0, 100, 0); plane(200); pop(); } function baum1(x, y, z){ push(); ambientMaterial(250); strokeWeight(1); translate(x, y -49, z); cylinder(25, 150); translate(0, y -100, 0); rotateX(180); cone(105, 120, 8); translate(0, y + 65, 0); cone(85, 120, 8); translate(0, y + 50, 0); cone(65, 100, 8); pop(); } function baum2(x, y, z){ push(); ambientMaterial(250); strokeWeight(1); translate(x, y -49, z); cylinder(25, 150); translate(0, -100, 0); sphere(75, 5); pop(); } push(); translate(vector); scale(3.5); //ground(); push(); zaun(100, -10, 100); zaun(100, -10, -100); rotateY(90); zaun(100, -10, 100); zaun(100, -10, -100); pop(); push(); scale(0.25); baum1(134, 0, -42); baum1(53, 0, 109); scale(1.5); baum1(-150, 0, 23); scale(0.75); baum2(-140, 0, -176); baum2(195, 0, 176) pop(); pop(); } function tree(x, y, z) { push(); ambientMaterial(250); strokeWeight(1); translate(x, -49, z); cylinder(25, 300); translate(0, -200, 0); rotateX(180); cone(105, 120, 8); translate(0, 65, 0); cone(85, 120, 8); translate(0, 50, 0); cone(65, 100, 8); pop(); } function car() { push(); ambientMaterial(250); strokeWeight(1); texture(brok); translate(carPosition); //translate(carDirection.x * carVelocity, 0, carDirection.y * carVelocity); if (carVelocity != 0) { rotateY(-carAngle); } rotateY(carTilt); box(100, 30, 75); translate(100, 0, 0); box(100, 30, 40); translate(30, 0, 50); rotateY(tireTilt); rotateX(90); cylinder(25); rotateX(-90); rotateY(-tireTilt); translate(0, 0, -100); rotateY(tireTilt); rotateX(90); cylinder(25); rotateY(-tireTilt); pop(); } setup = function() { zeichenflaeche = createCanvas(1920, 1080, WEBGL); frameRate(144); setAttributes('antialias', true); angleMode(DEGREES); background("#cccccc"); cam1 = createCamera(); cam2 = createCamera(); x = 0; y = -150/4; z = 0; campan = 0; carTilt = 0; whichcam = 0; carDirection = createVector(1, 0); carPosition = createVector(0, -38, 0); carVelocity = 0; carAngle = 0; tireTilt = 0; blau = color(0, 0, 255); braun = color(139, 69, 19); hellgrau = color(190, 190, 190); dunkelgrau = color(169, 169, 169) rot = color(155,10,0); grauTexture = createGraphics(1000, 1000, WEBGL); grauTexture.noStroke(); blauTexture = createGraphics(1000, 1000, WEBGL); blauTexture.noStroke(); //Shader grauTexture.shader(grau); grau.setUniform("resolution", [width, height]); grauTexture.rect(0,0,width,height); blauTexture.shader(sblau); sblau.setUniform("resolution", [width, height]); blauTexture.rect(0,0,width,height); houses = []; for (let i = 0; i < 4; i++) { for (let j = 0; j < 4; j++) { append(houses, [createVector(-3000+j*2000, 0, -3000+i*2000), random([0, 1, 2, 3, 4, 5, 6, 7])]) } } }; draw = function() { background("#cccccc"); ambientLight(150); directionalLight(80, 80, 80, 1, 1, 0); directionalLight(90, 90, 90, 0, 1, 0); directionalLight(150, 105, 105, 1, 0, 0); // Controls if (whichcam == 1) { if (keyIsDown(65)) { if (carVelocity > 0) { carAngle += 1; carTilt += 1; } else if (carVelocity < 0) { carAngle -= 1; carTilt -= 1; } tireTilt = 10; } else if (keyIsDown(68)) { if (carVelocity > 0) { carAngle -= 1; carTilt -= 1; } else if (carVelocity < 0) { carAngle += 1; carTilt += 1; } tireTilt = -10; } else { tireTilt = 0; } if (keyIsDown(87)) { if (carVelocity < 30) { carVelocity += 0.1; carz -= 20; z -= 20; } } else if (keyIsDown(83)) { if (carVelocity > -10) { carVelocity -= 0.1; z -= 20; carz += 20; } } else { carVelocity *= 0.95; if (carVelocity < 0.1) {carVelocity = 0;} } } else { // CAM 7 if (keyIsDown(65)) { x -= 2; } if (keyIsDown(68)) { x += 2; } if (keyIsDown(87)) { z -= 2; } if (keyIsDown(83)) { z += 2; } if (keyIsDown(32)) { y -= 2; } if (keyIsDown(16)) { y += 2; } // Camera cam2.pan(movedX * -0.4); cam2.tilt(movedY * 0.4); cam2.move(x*4, 0, z*4); cam2.setPosition(cam2.eyeX, y*4, cam2.eyeZ); } // Ground push(); strokeWeight(0); rotateX(90); textureWrap(CLAMP); texture(track); plane(3000 * 5, 3000 * 5); pop(); carDirection.rotate(carAngle); carPosition.x = carPosition.x + carDirection.x * carVelocity; carPosition.z = carPosition.z - carDirection.y * carVelocity; push(); for (let k = 0; k < houses.length; k++) { if (houses[k][1] < 5) { if (houses[k][1] == 0) { hochhausBenDieGeileSauXD(houses[k][0]); } else if (houses[k][1] == 1) { house(houses[k][0]); } else if (houses[k][1] == 2) { houseTjorben(houses[k][0]); } else if (houses[k][1] == 3) { garten(houses[k][0]); } else if (houses[k][1] == 4) { houseBen(houses[k][0]); } } } pop(); // Camera if (carVelocity < 0) { cam1.setPosition(carPosition.x + (carDirection.x * 300), -170, carPosition.z + (-carDirection.y * 300)); cam1.lookAt(carPosition.x, carPosition.y - 110, carPosition.z); } else { cam1.setPosition(carPosition.x + (-carDirection.x * 300), -170, carPosition.z + (carDirection.y * 300)); cam1.lookAt(carPosition.x, carPosition.y - 110, carPosition.z); } cybertruckTjorbenDieGeileSauXD(); carAngle = 0; x = 0; z = 0; };