java - Why don't my lines detect when they intersect each other properly (Slick Line Class) -


i've been working on trying find problem , trying alternative loops line intersection work no avail. line class slick , i'm 100% works i've tested outside of class.

here's image showing problem (the vertices in pink rectangles should intersect before getting black square in middle of screen(to honest every vertex @ moment should hit own edge, that's different problem(?))) http://imgur.com/ajj4a5t

here's image showing edges in red , vertices in blue. white line what's being created. every vertex on opposite side of square should not have white line connected it.imgur.com/mgdebii

here light class having problems. (the problems start under "checking line intersections" marked. anytime put helping.

import java.util.arraylist;   import org.newdawn.slick.geom.line; import org.newdawn.slick.geom.point; import org.newdawn.slick.geom.polygon;   public class light extends play{  private arraylist<point> points = new arraylist<point>(); private arraylist<point> points2 = new arraylist<point>(); private arraylist<polygon> polys = new arraylist<polygon>();     public arraylist<polygon> light(players p){      point head = new point(p.getrectangle().getx() + p.getrectangle().getwidth()/2, p.getrectangle().gety()); //players eyes      //=====================//puts vertices & edges 2 groups//=====================//     (int n = 0; n <= bounds.size() - 1; n++){         bounds b = bounds.get(n);          (int c = 0; c <= 3; c++){             edges.add(b.getborder(c)); // edge list not used in class anymore. keeping around render lines testing purposes.             points.add(b.getvertices(c));          }     }      points.add(new point(0,0)); //top left corner of screen     points.add(new point((float) gcx, 0)); //top right corner of screen     points.add(new point(0, (float) gcy)); // bottom left corner of screen     points.add(new point((float) gcx, (float) gcy)); // bottom right corner of screen      //=====================//organizing list smallest angles//=====================//     while(points.size() != 0){         point corner = new point(0,0);// 0,0 point never return null on accident.          for(int q = 0; q < points.size(); q++){             if(q == 0 ){ //if it's first number in list make corner.                 corner = points.get(q);                 if(points.size() > 1)                     q++;                 }              if(mymath.getangle(head.getx(), head.gety(), corner.getx(), corner.gety()) // if new corner less old corner become old corner                     < mymath.getangle(head.getx(), head.gety(), points.get(q).getx(), points.get(q).gety())){             }else                 corner = points.get(q);                  if(q == points.size() - 1){ // corner @ end of list have smallest angle in list                     points2.add(corner);                     points.remove(corner);                  }             }          }      //=====================//checking line intersections//=====================//      (int = 0; <= points2.size() - 1; a++){         point v = points2.get(a);             line poo = new line(v.getx(), v.gety(), head.getx(), head.gety());          (int t = 0; t <= bounds.size() - 1; t++){             bounds b2 = bounds.get(t);              (int c = 0; c <= 3; c++){                 if(b2.getborder(c).intersects(poo)){}                 else points.add(points2.get(a));                  }               }          }  // uses new organized list make polygon.     polygon poly = new polygon();          (int x = 0; x <= points.size() - 1; x++){ //makes list of polygons -- head not included.             point q = points.get(x);             poly.addpoint(q.getx(), q.gety());         }          polys.add(poly);          points.clear();      return polys;  }   } 

and here boundary class:

import org.newdawn.slick.image; import org.newdawn.slick.slickexception; import org.newdawn.slick.geom.line; import org.newdawn.slick.geom.point; import org.newdawn.slick.geom.rectangle;  public class bounds extends editor {      rectangle rect = null;         int id, x, y, w, h; line edge[] = new line[4]; point vertex[] = new point[4];  public bounds(int x, int y,  int id){     this.x = x;     this.y = y;      rect = new rectangle(x,y,ts,ts);     this.id = id;  }   public line getborder(int i){     return edge[i]; }  public point getvertices(int i){     return vertex[i]; }  public int getid(){     return id; }  public void refresh(){     rect = new rectangle(x + camera.getpoint().getx(), y + camera.getpoint().gety(), ts, ts);      vertex[0] = new point(rect.getx(), rect.gety());     vertex[1] = new point(rect.getx() + ts, rect.gety());      vertex[2] = new point(rect.getx() + ts, rect.gety() + ts);     vertex[3] = new point(rect.getx(), rect.gety() + ts);      edge[0] = new line(vertex[0].getx(), vertex[0].gety(), vertex[1].getx(), vertex[1].gety());     edge[1] = new line(vertex[1].getx(), vertex[1].gety(), vertex[2].getx(), vertex[2].gety());      edge[2] = new line(vertex[2].getx(), vertex[2].gety(), vertex[3].getx(), vertex[3].gety());     edge[3] = new line(vertex[3].getx(), vertex[3].gety(), vertex[0].getx(), vertex[0].gety());   }  public rectangle getrectangle(){     return rect; } 

and play class. (and yes did declare poly list in play)

        light l = new light(); // generate light clip     (players p : players){          //g.drawimage(hero, p.getrectangle().getx(), p.getrectangle().gety() - 0);         arraylist<polygon> polys = l.light(p);         g.setcolor(color.white);         (int n = 0; n <= polys.size() - 1; n++){             polygon poly = polys.get(n);                 g.draw(poly);         }         g.setcolor(color.black);         g.draw(p.getrectangle());       } 


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -