Skapa en Robotics simulator med bearbetning (7 / 7 steg)
Steg 7: Sista handen
Med koden ovan är detta redan en fullt fungerande robotics simulator. Men det finns massor av andra saker att göra med bearbetning. För det sista steget lagt jag en effekt som var tänkt att se ut som en sprayburk. Det hamnade lite annorlunda men fortfarande ser bra ut. Jag lade också till en riktad ljus, vilket gör roboten förefaller lite mer realistiska. Om du vill kan du exportera hela projektet till ett körbart program för windows eller något annat operativsystem genom att klicka på "Exportera tillämpning".
PShape bas, axel, upArm, loArm, slutet;
float rotX, rotY;
flyta posX = 1, posY = 50, posZ = 50;
float alfa, beta, gamma;
flyta [] Xsphere = ny float [99].
flyta [] Ysphere = ny float [99].
flyta [] Zsphere = ny float [99].
void setup() {
storlek (1200, 800, OPENGL);
bas = loadShape("r5.obj");
Axel = loadShape("r1.obj");
upArm = loadShape("r2.obj");
loArm = loadShape("r3.obj");
slut = loadShape("r4.obj");
shoulder.disableStyle();
upArm.disableStyle();
loArm.disableStyle();
}
void draw() {
writePos();
Background(32);
Smooth();
Lights();
directionalLight (51, 102, 126, -1, 0, 0);
för (int jag = 0; jag < Xsphere.length - 1; i ++) {
Xsphere [i] = Xsphere [jag + 1];
Ysphere [i] = Ysphere [jag + 1];
Zsphere [i] = Zsphere [jag + 1];
}
Xsphere[Xsphere.length - 1] = posX;
Ysphere[Ysphere.length - 1] = bukett;
Zsphere[Zsphere.length - 1] = posZ;
noStroke();
translate(width/2,height/2);
rotateX(rotX);
rotateY(-rotY);
Scale(-4);
för (int jag = 0; jag < Xsphere.length; i ++) {
pushMatrix();
Översätt (- Ysphere [i], -Zsphere [i] -11, - Xsphere[i]);
fyllning (#D003FF, 25);
sfär (float(i) / 20);
popMatrix();
}
Fill(#FFE308);
translate(0,-40,0);
Shape(base);
Översätt (0, 4, 0);
rotateY(gamma);
Shape(Shoulder);
Översätt (0, 25, 0);
rotateY(PI);
rotateX(alpha);
Shape(upArm);
Översätt (0, 0, 50);
rotateY(PI);
rotateX(beta);
Shape(loArm);
Översätt (0, 0, -50);
rotateY(PI);
Shape(End);
}
void mouseDragged() {
rotY-= (mouseX - pmouseX) * 0,01;
rotX-= (mouseY - pmouseY) * 0,01;
}