Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void PolyThread::Main(void)
- {
- if (Vertices.GetCount() != 3)
- return;
- BoundingBox bb = Helper::GetBoundingBox(_bitmap, Vertices);
- Vector p1 = Vector(Vertices[0].GetX(), Vertices[0].GetY(), 0);
- Vector p2 = Vector(Vertices[1].GetX(), Vertices[1].GetY(), 0);
- Vector p3 = Vector(Vertices[2].GetX(), Vertices[2].GetY(), 0);
- Vector c1 = Vertices[0].GetColor();
- Vector c2 = Vertices[1].GetColor();
- Vector c3 = Vertices[2].GetColor();
- Gradient2D g1 = Gradient2D(c1, c2, (p1 - p2).GetLength());
- Gradient2D g2;
- Vector pt, interesect, color;
- Bool isIntersected;
- Float d1;
- for (Int32 x = bb.left; x < bb.right; x++)
- {
- for (Int32 y = bb.top; y < bb.bottom; y++)
- {
- // check if the thread should be stopped
- if (TestBreak())
- End(false);
- // Continue if point is not in path
- if (!Helper::IsPointInPath(x, y, Vertices))
- continue;
- pt = Vector(x, y, 0);
- isIntersected = Helper::Intersect2D(p1, p2, p3, pt, interesect);
- // Continue if there is no intersection, should not happen
- if (!isIntersected)
- continue;
- d1 = (p3 - interesect).GetLength();
- if (d1 == 0.0)
- continue;
- isIntersected = Helper::Intersect2D(p1, p2, p3, pt, interesect);
- // Continue if there is no intersection, should not happen
- if (!isIntersected)
- continue;
- g2 = Gradient2D(c3, g1.GetColorAt((p1 - interesect).GetLength()), d1);
- color = g2.GetColorAt((p3 - pt).GetLength());
- _bitmap->SetPixel(x, y, color.x, color.y, color.z);
- }
- }
- End(false);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement