Loading...
Logo
Processing Forum

3D Arrow

in General Discussion  •  Other  •  1 year ago  
Can someone (help me) create a 3D arrow using beginShape()?

Replies(7)

Re: 3D Arrow

1 year ago
Like this but better, if there is a better way. I'm assuming there is...
Copy code
  1. float inc = 0;

  2. void setup() {
  3.   size(600, 400, P3D);
  4.   noStroke();
  5. }

  6. void draw() {
  7.   background(0);
  8.   lights();

  9.   fill(255);
  10.   translate(width/2, height/2, 0);
  11.   rotateY(inc);
  12.   rotateX(inc);
  13.   inc += .01;

  14.   beginShape();
  15.   vertex(0, 0, 0);
  16.   vertex(50, -50, 0);
  17.   vertex(100, 0, 0);
  18.   endShape();
  19.   beginShape();
  20.   vertex(25, 0, 0);
  21.   vertex(25, 50, 0);
  22.   vertex(75, 50, 0);
  23.   vertex(75, 0, 0);
  24.   endShape();
  25.   beginShape();
  26.   vertex(0, 0, 50);
  27.   vertex(50, -50, 50);
  28.   vertex(100, 0, 50);
  29.   endShape();
  30.   beginShape();
  31.   vertex(25, 0, 50);
  32.   vertex(25, 50, 50);
  33.   vertex(75, 50, 50);
  34.   vertex(75, 0, 50);
  35.   endShape();
  36.   beginShape();
  37.   vertex(0, 0, 0);
  38.   vertex(0, 0, 50);
  39.   vertex(50, -50, 50);
  40.   vertex(50, -50, 0);
  41.   endShape();
  42.   beginShape();
  43.   vertex(50, -50, 0);
  44.   vertex(50, -50, 50);
  45.   vertex(100, 0, 50);
  46.   vertex(100, 0, 0);
  47.   endShape();
  48.   beginShape();
  49.   vertex(100, 0, 0);
  50.   vertex(100, 0, 50);
  51.   vertex(75, 0, 50);
  52.   vertex(75, 0, 0);
  53.   endShape();
  54.   beginShape();
  55.   vertex(75, 0, 0);
  56.   vertex(75, 0, 50);
  57.   vertex(75, 50, 50);
  58.   vertex(75, 50, 0);
  59.   endShape();
  60.   beginShape();
  61.   vertex(75, 50, 0);
  62.   vertex(75, 50, 50);
  63.   vertex(25, 50, 50);
  64.   vertex(25, 50, 0);
  65.   endShape();
  66.   beginShape();
  67.   vertex(25, 50, 0);
  68.   vertex(25, 50, 50);
  69.   vertex(25, 0, 50);
  70.   vertex(25, 0, 0);
  71.   endShape();
  72.   beginShape();
  73.   vertex(25, 0, 0);
  74.   vertex(25, 0, 50);
  75.   vertex(0, 0, 50);
  76.   vertex(0, 0, 0);
  77.   endShape();
  78. }

Re: 3D Arrow

1 year ago
what do you mean by "better". that already looks quite good. or do you mean "less code" ?
if thats the problem and you plan to use it more often you can create a arrow function and just call that.
if you dont want code like that add all, you can use one of the model loader library and load a 3d model of an arrow. 

Re: 3D Arrow

1 year ago
Yeah I mean less code. I'm sure there must be a more efficient way to draw a simple arrow. I don't fully understand how this vertex stuff works

Re: 3D Arrow

1 year ago
now that i look at it again, i see you are using a lot of begin and endshapes that you actually dont need. you could for example draw the arrow front in one go...

  beginShape();
  vertex(-50,50);
  vertex(0, 0);
  vertex(50, 50);
  vertex(25,50);
  vertex(25,100);
 vertex(-25,100);
 vertex(-25,50);
  endShape(CLOSE);

but i think there is more room for optimization. lets see how far we get

Re: 3D Arrow

1 year ago
I got a better one. Anything else I can do?
Copy code
  1. float inc = 0;

  2. void setup() {
  3.   size(600, 400, P3D);
  4.   noStroke();
  5. }

  6. void draw() {
  7.   background(0);
  8.   lights();

  9.   fill(255);
  10.   translate(width/2, height/2, 0);
  11.   rotateY(inc);
  12.   rotateX(inc);
  13.   inc += .01;

  14.   beginShape();
  15.   vertex(0, 0, 0);
  16.   vertex(50, -50, 0);
  17.   vertex(100, 0, 0);
  18.   vertex(75, 0, 0);
  19.   vertex(75, 50, 0);
  20.   vertex(25, 50, 0);
  21.   vertex(25, 0, 0);
  22.   endShape();
  23.   beginShape();
  24.   vertex(0, 0, 50);
  25.   vertex(50, -50, 50);
  26.   vertex(100, 0, 50);
  27.   vertex(75, 0, 50);
  28.   vertex(75, 50, 50);
  29.   vertex(25, 50, 50);
  30.   vertex(25, 0, 50);
  31.   endShape();
  32.   beginShape(QUAD_STRIP);
  33.   vertex(0, 0, 0);
  34.   vertex(0, 0, 50);
  35.   vertex(50, -50, 0);
  36.   vertex(50, -50, 50);
  37.   vertex(100, 0, 0);
  38.   vertex(100, 0, 50);
  39.   vertex(75, 0, 0);
  40.   vertex(75, 0, 50);
  41.   vertex(75, 50, 0);
  42.   vertex(75, 50, 50);
  43.   vertex(25, 50, 0);
  44.   vertex(25, 50, 50);
  45.   vertex(25, 0, 0);
  46.   vertex(25, 0, 50);
  47.   vertex(0, 0, 0);
  48.   vertex(0, 0, 50);
  49.   endShape();
  50. }

Re: 3D Arrow

1 year ago
Copy code
  1. float inc = 0;
  2.  

  3. void setup() {
  4.   size(600, 400, P3D);
  5.   noStroke();  
  6.  
  7. }

  8. void draw() {
  9.  background(0);
  10.  lights();
  11.  translate(width/2,height/2);
  12.  rotateY(inc);
  13.  rotateX(inc);
  14.  fill(255);
  15.  arrow();
  16.  

  17.   inc += .01;

  18. }



  19. void arrow() {
  20.   int[] x = {-50, 0, 50, 25, 25, -25, -25, -50};
  21.   int[] y = {50, 0, 50, 50, 100, 100, 50, 50};
  22.   beginShape();
  23.   for (int i = 0;i<8;i++)vertex(x[i], y[i]);
  24.   endShape(CLOSE);
  25.   beginShape();
  26.   for (int i = 0;i<8;i++)vertex(x[i], y[i], 25);
  27.   endShape(CLOSE);
  28.   beginShape(QUAD_STRIP);
  29.   for (int i = 0;i<8;i++) {
  30.     vertex(x[i], y[i]);
  31.     vertex(x[i], y[i], 25);
  32.   }
  33.   endShape(CLOSE);
  34. }

Re: 3D Arrow

1 year ago
Now that's efficient. Thanks!