Filling a vertex shape

Hi im attempting to create complex shapes using a ray casting and the vertex function to fill the space that the light touches as opposed to simply drawing the lines. At the moment the code works fine but requires me to add a vertex for the mouse coordinates so the shape will fill. Is there an alternative to this.

soz about formating (hardware constraints ATM)

void superVertex(){
  ArrayList<Line> arr = new ArrayList<Line>();
  
  for (int i=1;i<light.size()-1;i++){
    float a = light.get(i-1).line_id;
    float b = light.get(i).line_id;
    float c = light.get(i+1).line_id;
    
    if(a!=c||i==0){
    arr.add(light.get(i));
    }
  }
  if(arr.size()>0){
  arr.add(arr.get(0));
  
  }
    
   for(int i=0;i<arr.size()-1;i++){
     float x = arr.get(i).intx;
     float y = arr.get(i).inty;
     
     float x2 = arr.get(i+1).intx;
     float y2 = arr.get(i+1).inty;
     
     //stroke(255,50);
     noStroke();
     beginShape();
     fill(255,50);
     vertex(x,y);
     vertex(mouseX,mouseY);
     vertex(x2,y2);
     endShape();
   }
    
};
1 Like

Maybe endShape(CLOSE);

2 points give you a line, 3 points a triangle

That’s my understanding too, a shape needs more than 2 vertices, however close doesn’t solve the issue.

Can’t you make 2 additional points next to those you got?

Then you have a rectangle

There is a fancy 3D line function that is easy to handle. (I think 1 or 2 things are not correct but it looks cool)

see: https://github.com/Kango/Processing-snippets/blob/master/ThreeDLine/ThreeDLine.pde

Not exactly, the points are extracted from the 360 light rays cast. The rays for a shape with the static lines they are interacting with and this shape will have n sides depending on how many lines the rays have intersected. The mouse approach solves this nicely, but I’m not sure whether a whole shape is quicker to render than lots of little ones. If there’s no real speed advantage then this question is moot.

1 Like

Actually after further experimentation the mouse approach is also insufficient. It works fine providing the mouse is not going to fast, but then sometimes it will draw random triangles. I

when you just want to have a fancy 3D effect you could calculate the light rays and store the points in an ArrayList and when you have 5 points, make a shape using vertex.

Add this to 2nd ArrayList and display it throughout.

Clear the first ArrayList after making a new shape

Not sure I completely understand what your suggesting. I’m creating one array at the moment, which checks to see if the line the ray is intersecting with is the different to the ray on its left and the ray on its right. if it is it becomes a point in and array in the supervertex function. I understand that a shape needs more than 2 vertices, but I don’t understand how your suggestion applies, genuinely love the feedback, just don’t understand it.

I think however i would run into the same problem i was having using 3 vertices. Note i currently have three vertices but one of them is the center point of the light. If i remove the centerpoint and utilize another ray intersection point as a vertex the shape filled looks like this.

.

as opposed to this,

the problem with my current version is it causes some “glitches” which may be due to an error in my code (I know I make a lot), but i can’t seem to identify it.

As you can see some of the shapes are overlapping and the light effect looses its appeal, this only happens occasionally especially, if the light has passed through one of the bounding wall, and wrapped back round.

Here hamoid does a similar thing with random vertexes.

He‘s sorting it prior to make a shape. Bam!

2 Likes

Remember to use lights(); in draw() after background() when in P3D mode

Oh Wow, thank-you, I was over-complicating it. There was no need for multiple vertex call in the for loop, just one vertex call was needed. Face-palm.

1 Like