simple drawing/sketchup like-tool - arrays, classes? help!
in
Contributed Library Questions
•
2 years ago
Hi!
I'm a total beginner,
I'm trying to program a sketchup-like tool. this is how far i got:
r= reset shape
c= orbit cam (peasy cam)
i don't know how i can make it so u can draw multiple shapes. as is now u can only draw one.
do i have to use classes in connection with arrays? every 4th point creates a new shape? can someone pls show me an example how to do that? help much appreciated
I'm a total beginner,
I'm trying to program a sketchup-like tool. this is how far i got:
r= reset shape
c= orbit cam (peasy cam)
- // r : Reset
- // c : Orbit-Cam
-
-
- import processing.opengl.*;
-
- import peasy.test.*;
- import peasy.org.apache.commons.math.*;
- import peasy.*;
- import peasy.org.apache.commons.math.geometry.*;
- import controlP5.*;
-
-
- public int Hoehe = 1;
-
-
- ControlWindow controlWindow;
- ControlP5 controlP5;
- PeasyCam cam;
-
- PImage bild;
- int[] coordsx = new int [5]; // array für die x koordinaten
- int[] coordsy = new int [5]; // für die y koordinaten
- int i = 0;
- int a = 1;
- int kameraaktiv = 0;
-
-
- void setup () {
- bild = loadImage("stadtplanung_1.jpg");
-
-
- cam = new PeasyCam(this, 500);
-
-
- cam.setActive (false); //
- cam.setWheelScale(3.0); //
-
-
- controlP5 = new ControlP5(this);
- controlP5.setAutoDraw(false);
- controlWindow = controlP5.addControlWindow("controlP5window", 100, 100, 450, 100);
- controlWindow.hideCoordinates();
-
- controlWindow.setBackground(color(40));
- Controller mySlider = controlP5.addSlider("Hoehe", 0, 500, 40, 40, 350, 10);
- mySlider.setWindow(controlWindow);
-
- controlWindow.setTitle("Höhe verstellen");
-
-
-
-
- size(1000, 700, OPENGL);
- }
-
-
- void mousePressed () {
-
- coordsx[i] = mouseX;
- coordsy[i] = mouseY;
- i = i + a;
- if (i == 4) {
- a = 0;
- }
- }
-
-
- void keyPressed() {
-
- if (key=='c') {
- cam.setActive (true); //
-
- kameraaktiv = 1;
- }
- if (key=='r') {
- i = 0;
- a = 1;
- kameraaktiv = 0;
- cam.reset(500);
- }
- }
-
-
- void draw() {
- if (kameraaktiv == 0) {
- cam.beginHUD(); //
- background (210, 200, 200);
- //image(bild, 0, 0);
- ellipse(coordsx[0], coordsy[0], 5, 5); // ellipses to start with
- ellipse(coordsx[1], coordsy[1], 5, 5);
- ellipse(coordsx[2], coordsy[2], 5, 5);
- ellipse(coordsx[3], coordsy[3], 5, 5);
- cam.endHUD();
-
-
- if (i == 4) { //
- cam.beginHUD();
- beginShape(QUADS);
- vertex(coordsx[0], coordsy[0], 0); /// bottom face for 2d view
- vertex(coordsx[1], coordsy[1], 0);
- vertex(coordsx[2], coordsy[2], 0);
- vertex(coordsx[3], coordsy[3], 0);
- endShape(CLOSE);
- cam.endHUD();
- }
- }
-
-
- if (kameraaktiv == 1) { //
-
- background (200, 200, 200);
- // image(bild, 0, 0);
- beginShape(QUADS);
- vertex(coordsx[0], coordsy[0], 1); // bottom face
- vertex(coordsx[1], coordsy[1], 1);
- vertex(coordsx[2], coordsy[2], 1);
- vertex(coordsx[3], coordsy[3], 1);
-
-
- vertex(coordsx[0], coordsy[0], 1); // face 1
- vertex(coordsx[1], coordsy[1], 1);
- vertex(coordsx[1], coordsy[1], Hoehe);
- vertex(coordsx[0], coordsy[0], Hoehe);
-
- vertex(coordsx[2], coordsy[2], 1); // face 2
- vertex(coordsx[3], coordsy[3], 1);
- vertex(coordsx[3], coordsy[3], Hoehe);
- vertex(coordsx[2], coordsy[2], Hoehe);
-
- vertex(coordsx[1], coordsy[1], 1); // face 3
- vertex(coordsx[2], coordsy[2], 1);
- vertex(coordsx[2], coordsy[2], Hoehe);
- vertex(coordsx[1], coordsy[1], Hoehe);
-
- vertex(coordsx[0], coordsy[0], 1); // face 4
- vertex(coordsx[3], coordsy[3], 1);
- vertex(coordsx[3], coordsy[3], Hoehe);
- vertex(coordsx[0], coordsy[0], Hoehe);
-
-
-
- vertex(coordsx[0], coordsy[0], Hoehe); // top face
- vertex(coordsx[1], coordsy[1], Hoehe);
- vertex(coordsx[2], coordsy[2], Hoehe);
- vertex(coordsx[3], coordsy[3], Hoehe);
-
-
- endShape(CLOSE);
- }
- }
-
i don't know how i can make it so u can draw multiple shapes. as is now u can only draw one.
do i have to use classes in connection with arrays? every 4th point creates a new shape? can someone pls show me an example how to do that? help much appreciated
1