Thursday, April 5, 2012

New "line" class

Prototype for new "line" class.

 class line  
 {  

      intPoint Org;  
      intPoint Dis;  
      float M;  

 public:  

      //Intersection Stuff  
      bool SlideTo( intPoint* OUTPUT , line CD );  
      bool IntersectPoint( intPoint* OUTPUT , line CD );  

      //change values  
      void Shift( intPoint ShiftBy );  
      void SetOrg( intPoint MoveTo );  
      void SetDis( intPoint NewEnd );  

      //Constructors  
      line( line LineWith , intPoint newSlope );  
      line( intPoint Origin , intPoint Displacement );  

      //Draw!  
      void Draw();  

 };  

This new version has two primary changes.

  • I added a float for the slope (M).
  • I converted the definition to be a point relative to the Origin and a Displacement relative to the first point.

I did both of these (and created the new constructors) to make polygon collision faster. My method of detecting if two polygons collide is based on drawing a line from each point of polygon A that represent the displacement, then you detect if those lines intersect with any line of polygon B. This means you are calculating the same slope (each displacement line) several times. If you make slope part of the line and build constructors that let you shift the point of origin you only have to calculate the slope once.

It doesn't make it easier, but it does make it faster. (I still don't know, however, if "faster" will even be relevant)

(ohyeah, and renamed Point to be intPoint because I might make a floatPoint someday)

No comments:

Post a Comment