Guest User

Untitled

a guest
Jun 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. void GameRenderer::_RenderLineShrink(Vector2f i_p1, Vector2f i_p2,const Color& i_color, int i_thickness1, int i_thickness2, bool i_rounded){
  2. //catch the rendering device
  3. DrawLib* pDrawlib = GameApp::instance()->getDrawLib();
  4. pDrawlib->setColor(i_color);
  5. //calculate thickness variables
  6. float xd=i_p1.x-i_p2.x; float yd=i_p1.y-i_p2.y; //get differences
  7. float ang=atan2(yd,xd)+(45 / 57.29578f); //calculate angle
  8. Vector2f p1; Vector2f p2; //declare line draw points
  9. float v_round_dist;
  10. int v_thickness1;
  11. int v_thickness2;
  12. //here we swap the variables to render nicely to both directions < and >
  13. if(i_thickness2<i_thickness1){v_thickness1=i_thickness1;v_thickness2=i_thickness2;}else{v_thickness1=i_thickness2;v_thickness2=i_thickness1;}
  14. for(int i=0; i<v_thickness1; i++){
  15. //calculate the vector to draw (move in every loop to create thickness)
  16. if(i>=i_thickness2){
  17. p1=Vector2f(i_p1.x+cos(ang)*(i)*0.007f,i_p1.y+sin(ang)*(i)*0.007f);
  18. p2=Vector2f(i_p2.x+cos(ang)*(v_thickness2)*0.007f,i_p2.y+sin(ang)*(v_thickness2)*0.007f);
  19. }else{
  20. p1=Vector2f(i_p1.x+cos(ang)*(i)*0.007f,i_p1.y+sin(ang)*(i)*0.007f);
  21. p2=Vector2f(i_p2.x+cos(ang)*(i)*0.007f,i_p2.y+sin(ang)*(i)*0.007f);
  22. }
  23. //round edges
  24. if(i_rounded==true){
  25. //calculate the roundness
  26. if(i<=v_thickness1/2){v_round_dist=i+1;}else{v_round_dist=v_thickness1-i+1;}
  27. if(i==(int)i_thickness1/2){v_round_dist=v_round_dist-1;}
  28. //move the end points to round the end/start of the line
  29. float ang2=ang-(45 / 57.29578f); //-45 degrees converted to radians
  30. p1=Vector2f(p1.x+cos(ang2)*(v_round_dist)*0.007f,p1.y+sin(ang2)*(v_round_dist)*0.007f);
  31. p2=Vector2f(p2.x+cos(ang2)*(-v_round_dist)*0.007f,p2.y+sin(ang2)*(-v_round_dist)*0.007f);
  32. }
  33. //DRAW!
  34. pDrawlib->startDraw(DRAW_MODE_LINE_STRIP);
  35. pDrawlib->glVertex(p1);
  36. pDrawlib->glVertex(p2);
  37. pDrawlib->endDraw();
  38. }
  39. }
Add Comment
Please, Sign In to add comment