beginner_processing
YaBB Newbies
Offline
Posts: 41
Re: for everyone? here easy, for me impossible.. help?
Reply #2 - May 25th , 2010, 7:31am
if someone is interested in what I did and could help me to make it work better.. it would be nice..
Code: import napplet.*; NAppletManager nappletManager; void setup() { size(600, 600); nappletManager = new NAppletManager(this); nappletManager.createNApplet("Menu", 0,0); nappletManager.createNApplet("Zeichnen", 0,100); } void draw() { background(0); } public class Menu extends NApplet { public void setup() { size(600, 100); } public void draw() { background(0, 100, 0); stroke(255); fill(255); } } public class Zeichnen extends NApplet { float rotx=.1, roty=.1; int achl=600; int a=100, offx=0, offy=0,offz=0; int transx, transy, transz=-300; int lastWidth, lastHeight; int pfeil=6; public void setup() { size(600, 500,P3D); stroke(0); strokeWeight(1); strokeJoin(MITER); transx=width/2; transy=height/2; } public void draw() { background(255); pushMatrix(); translate(transx,transy,transz); rotateX(rotx); rotateY(roty); koordinatensystem(); popMatrix(); } public void koordinatensystem(){ strokeWeight(1.5); beginShape(LINES); stroke(255,0,0); //z-achse rot vertex(0,0,-achl); vertex(0,0,achl); vertex(0,0,-achl); // Pfeil 1 vertex(pfeil,0,-achl+pfeil); vertex(0,0,-achl); vertex(-pfeil,0,-achl+pfeil); vertex(0,0,achl); //Pfeil 2 vertex(pfeil,0,achl-pfeil); vertex(0,0,achl); vertex(-pfeil,0,achl-pfeil); stroke(0,255,0); //y-achse grün vertex(0,-achl,0); vertex(0,achl,0); vertex(0,achl,0); // Pfeil 1 vertex(0,achl-pfeil,pfeil); vertex(0,achl,0); vertex(0,achl-pfeil,-pfeil); vertex(0,-achl,0); // Pfeil 2 vertex(pfeil,-achl+pfeil,0); vertex(0,-achl,0); vertex(-pfeil,-achl+pfeil,0); stroke(0,0,255); //x-achse blau vertex(-achl,0,0); vertex(achl,0,0); vertex(-achl,0,0); // Pfeil 1 vertex(-achl+pfeil,0,pfeil); vertex(-achl,0,0); vertex(-achl+pfeil,0,-pfeil); vertex(achl,0,0); // Pfeil 2 vertex(achl-pfeil,0,pfeil); vertex(achl,0,0); vertex(achl-pfeil,0,-pfeil); endShape();} public void mouseDragged() { float factor = 0.01; if (key==CODED){ // Alt + Maus --> Rotation if(keyCode==ALT){ rotx += (pmouseY-mouseY) * factor; roty += (mouseX-pmouseX) * factor; } if(keyCode==CONTROL){ // Ctrl + Maus --> Translation transx+=(mouseX-pmouseX); transy+=(mouseY-pmouseY); } }} public void keyPressed(){ if(key!=CODED){ if (key=='1'){ rotx=0; roty=0; transx=width/2; transy=height/2; transz=-300; } if (key=='3'){ rotx=0; roty=radians(-90); transx=width/2; transy=height/2; transz=-300; } if (key=='7'){ rotx=radians(-90); roty=0; transx=width/2; transy=height/2; transz=-300; } } if (key == CODED) { if(keyCode==CONTROL){ if(key=='1'){ rotx=0; roty=PI; } if(key=='3'){ rotx=0; roty=radians(90); } if(key=='7'){ rotx=radians(90); roty=0; } } } } }