Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void GameRenderer::_RenderLineShrink(Vector2f i_p1, Vector2f i_p2,const Color& i_color, int i_thickness1, int i_thickness2, bool i_rounded){
- //catch the rendering device
- DrawLib* pDrawlib = GameApp::instance()->getDrawLib();
- pDrawlib->setColor(i_color);
- //calculate thickness variables
- float xd=i_p1.x-i_p2.x; float yd=i_p1.y-i_p2.y; //get differences
- float ang=atan2(yd,xd)+(45 / 57.29578f); //calculate angle
- Vector2f p1; Vector2f p2; //declare line draw points
- float v_round_dist;
- int v_thickness1;
- int v_thickness2;
- //here we swap the variables to render nicely to both directions < and >
- if(i_thickness2<i_thickness1){v_thickness1=i_thickness1;v_thickness2=i_thickness2;}else{v_thickness1=i_thickness2;v_thickness2=i_thickness1;}
- for(int i=0; i<v_thickness1; i++){
- //calculate the vector to draw (move in every loop to create thickness)
- if(i>=i_thickness2){
- p1=Vector2f(i_p1.x+cos(ang)*(i)*0.007f,i_p1.y+sin(ang)*(i)*0.007f);
- p2=Vector2f(i_p2.x+cos(ang)*(v_thickness2)*0.007f,i_p2.y+sin(ang)*(v_thickness2)*0.007f);
- }else{
- p1=Vector2f(i_p1.x+cos(ang)*(i)*0.007f,i_p1.y+sin(ang)*(i)*0.007f);
- p2=Vector2f(i_p2.x+cos(ang)*(i)*0.007f,i_p2.y+sin(ang)*(i)*0.007f);
- }
- //round edges
- if(i_rounded==true){
- //calculate the roundness
- if(i<=v_thickness1/2){v_round_dist=i+1;}else{v_round_dist=v_thickness1-i+1;}
- if(i==(int)i_thickness1/2){v_round_dist=v_round_dist-1;}
- //move the end points to round the end/start of the line
- float ang2=ang-(45 / 57.29578f); //-45 degrees converted to radians
- p1=Vector2f(p1.x+cos(ang2)*(v_round_dist)*0.007f,p1.y+sin(ang2)*(v_round_dist)*0.007f);
- p2=Vector2f(p2.x+cos(ang2)*(-v_round_dist)*0.007f,p2.y+sin(ang2)*(-v_round_dist)*0.007f);
- }
- //DRAW!
- pDrawlib->startDraw(DRAW_MODE_LINE_STRIP);
- pDrawlib->glVertex(p1);
- pDrawlib->glVertex(p2);
- pDrawlib->endDraw();
- }
- }
Add Comment
Please, Sign In to add comment