Advertisement
gr4ph0s

Untitled

Dec 8th, 2017
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1.  
  2. void PolyThread::Main(void)
  3. {
  4. if (Vertices.GetCount() != 3)
  5. return;
  6.  
  7. BoundingBox bb = Helper::GetBoundingBox(_bitmap, Vertices);
  8.  
  9. Vector p1 = Vector(Vertices[0].GetX(), Vertices[0].GetY(), 0);
  10. Vector p2 = Vector(Vertices[1].GetX(), Vertices[1].GetY(), 0);
  11. Vector p3 = Vector(Vertices[2].GetX(), Vertices[2].GetY(), 0);
  12.  
  13. Vector c1 = Vertices[0].GetColor();
  14. Vector c2 = Vertices[1].GetColor();
  15. Vector c3 = Vertices[2].GetColor();
  16.  
  17. Gradient2D g1 = Gradient2D(c1, c2, (p1 - p2).GetLength());
  18.  
  19. Gradient2D g2;
  20. Vector pt, interesect, color;
  21. Bool isIntersected;
  22. Float d1;
  23.  
  24. for (Int32 x = bb.left; x < bb.right; x++)
  25. {
  26. for (Int32 y = bb.top; y < bb.bottom; y++)
  27. {
  28. // check if the thread should be stopped
  29. if (TestBreak())
  30. End(false);
  31.  
  32. // Continue if point is not in path
  33. if (!Helper::IsPointInPath(x, y, Vertices))
  34. continue;
  35.  
  36. pt = Vector(x, y, 0);
  37. isIntersected = Helper::Intersect2D(p1, p2, p3, pt, interesect);
  38.  
  39. // Continue if there is no intersection, should not happen
  40. if (!isIntersected)
  41. continue;
  42.  
  43. d1 = (p3 - interesect).GetLength();
  44. if (d1 == 0.0)
  45. continue;
  46.  
  47. isIntersected = Helper::Intersect2D(p1, p2, p3, pt, interesect);
  48. // Continue if there is no intersection, should not happen
  49. if (!isIntersected)
  50. continue;
  51.  
  52. g2 = Gradient2D(c3, g1.GetColorAt((p1 - interesect).GetLength()), d1);
  53. color = g2.GetColorAt((p3 - pt).GetLength());
  54.  
  55. _bitmap->SetPixel(x, y, color.x, color.y, color.z);
  56. }
  57. }
  58. End(false);
  59. return;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement