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();
}
};
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.
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.
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.