void TexturedQuadUIDrawObject::getBounds(Pnt2f& TopLeft, Pnt2f& BottomRight) const
{
   TopLeft.setValues(
       osgMin(osgMin(osgMin(getPoint1().x(), getPoint2().x()),getPoint3().x()),getPoint4().x()),
       osgMin(osgMin(osgMin(getPoint1().y(), getPoint2().y()),getPoint3().y()),getPoint4().y()));
   
   BottomRight.setValues(
       osgMax(osgMax(osgMax(getPoint1().x(), getPoint2().x()),getPoint3().x()),getPoint4().x()),
       osgMax(osgMax(osgMax(getPoint1().y(), getPoint2().y()),getPoint3().y()),getPoint4().y()));
}
void ColDetect::addPolygon(std::vector<Triangle3D> triangles, VCollide& vc)
{
	int id;
	double v1[3], v2[3], v3[3];
	vc.NewObject(&id);
	for (int j = 0; j < triangles.size(); j++) {
		auto tri = triangles[j];
		auto p1 = tri.getPoint1();
		v1[0] = p1.getX();
		v1[1] = p1.getY();
		v1[2] = p1.getZ();

		auto p2 = tri.getPoint2();
		v2[0] = p2.getX();
		v2[1] = p2.getY();
		v2[2] = p2.getZ();

		auto p3 = tri.getPoint3();
		v3[0] = p3.getX();
		v3[1] = p3.getY();
		v3[2] = p3.getZ();
		vc.AddTri(v1, v2, v3, j);
	}
	vc.EndObject();
}
void TexturedQuadUIDrawObject::draw(const GraphicsWeakPtr Graphics, Real32 Opacity) const
{
    //TODO: add Color Field to TexturedQuadUIDrawObject
	Graphics->drawQuad(getPoint1(),getPoint2(),getPoint3(),getPoint4(),
                       getTexCoord1(), getTexCoord2(), getTexCoord3(), getTexCoord4(),
                       Color4f(1.0f,1.0f,1.0f,1.0f), getTexture(),
                       getOpacity()*Opacity);
}
Vec2f TriDistribution2D::generate(void) const
{
    Vec2f Result;

    switch(getSurfaceOrEdge())
    {
    case EDGE:
        {
            Vec2f Side1(getPoint2() - getPoint1()),
                  Side2(getPoint3() - getPoint2()),
                  Side3(getPoint1() - getPoint3());

            Real32 Side1Length(Side1.length()),
                   Side2Length(Side2.length()),
                   Side3Length(Side3.length());

            Real32 TotalLength(Side1Length + Side2Length + Side3Length);

            Real32 Rand(RandomPoolManager::getRandomReal32(0.0,1.0));

            Real32 PickEdge(RandomPoolManager::getRandomReal32(0.0,1.0));
            if(Rand < Side1Length/TotalLength)
            {
                Result = getPoint1().subZero() + RandomPoolManager::getRandomReal32(0.0,1.0)*Side1;
            }
            else if(Rand < (Side1Length+Side2Length)/TotalLength)
            {
                Result = getPoint2().subZero() + RandomPoolManager::getRandomReal32(0.0,1.0)*Side2;
            }
            else
            {
                Result = getPoint3().subZero() + RandomPoolManager::getRandomReal32(0.0,1.0)*Side3;
            }
            break;
        }
    case SURFACE:
    default:
        {
            Real32 s(RandomPoolManager::getRandomReal32(0.0,1.0)),
                   t(RandomPoolManager::getRandomReal32(0.0,1.0));

            if(s+t > 1.0)
            {
                s = 1.0f - s;
                t = 1.0f - t;
            }

            Result = getPoint1().subZero()
                   + s*(getPoint2() - getPoint1())
                   + t*(getPoint3() - getPoint1());
            break;
        }
    }

    return Result;
}
void MultiColoredQuadUIDrawObject::draw(Graphics* const Graphics, Real32 Opacity) const
{
	Graphics->drawQuad(getPoint1(),getPoint2(),getPoint3(),getPoint4(),
                       getColor1(), getColor2(), getColor3(), getColor4(),
                       getOpacity()*Opacity);
}