Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BoundingBox Helper::GetBoundingBox(BaseBitmap* bmp, maxon::BaseArray<Vertex>& Vertices)
- {
- if (Vertices.GetCount() != 3)
- return BoundingBox();
- Float xmax = maxon::Max(Vertices[0].GetX(), maxon::Max(Vertices[1].GetX(), Vertices[2].GetX()));
- Float xmin = maxon::Min(Vertices[0].GetX(), maxon::Min(Vertices[1].GetX(), Vertices[2].GetX()));
- Float ymax = maxon::Max(Vertices[0].GetY(), maxon::Max(Vertices[1].GetY(), Vertices[2].GetY()));
- Float ymin = maxon::Min(Vertices[0].GetY(), maxon::Min(Vertices[1].GetY(), Vertices[2].GetY()));
- if (xmax >= bmp->GetBw())
- xmax = bmp->GetBw();
- if (ymax >= bmp->GetBh())
- ymax = bmp->GetBh();
- return BoundingBox(ymin, xmin, ymax, xmax);
- }
- Bool Helper::Intersect2D(const Vector& p1, const Vector& p2, const Vector& q1, const Vector& q2, Vector& out)
- {
- Float pa = p1.y - p2.y;
- Float pb = p2.x - p1.x;
- Float pc = p2.x * p1.y - p1.x * p2.y;
- Float qa = q1.y - q2.y;
- Float qb = q2.x - q1.x;
- Float qc = q2.x * q1.y - q1.x * q2.y;
- Float d = pa * qb - pb * qa;
- Float dx = pc * qb - pb * qc;
- Float dy = pa * qc - pc * qa;
- // No Intersection
- if (d == 0)
- return false;
- out = Vector(dx / d, dy / d, 0);
- return true;
- };
- Bool Helper::IsPointInPath(const Float x, const Float y, maxon::BaseArray<Vertex>& V)
- {
- if (V.GetCount() != 3)
- return false;
- Int i, j;
- Bool c = false;
- for (Int i = 0, j = V.GetCount() - 1; i < V.GetCount(); j = i++)
- {
- if ((((V[i].GetY() <= y) && (y < V[j].GetY())) ||
- ((V[j].GetY() <= y) && (y < V[i].GetY()))) &&
- (x < (V[j].GetX() - V[i].GetX()) * (y - V[i].GetY()) / (V[j].GetY() - V[i].GetY()) + V[i].GetX()))
- c = !c;
- }
- return c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement