#ifndef CONVEX_H
#define CONVEX_H

	class CollidePolytope;

	class MyPoly
	{
		public:
					MyPoly() : mNbVerts(0), mIndices(NULL)
					{
					}
					~MyPoly()
					{
						if(mIndices)	delete[]mIndices;
					}

		short		mNbVerts;
		char*		mIndices;
		float		mPlane[4];
	};

	class MyConvex
	{
		public:
								MyConvex();
								~MyConvex();

				bool			LoadFromFile(const char* filename);
				void			Render(bool only_wireframe, const btVector3& wire_color) const;
				void			Project(const btVector3& dir, float& min, float& max) const;
				void			ComputeWorldAABB(btVector3& min, btVector3& max)	const;

				int				mNbVerts;
				btVector3*		mVerts;
				int				mNbPolys;
				MyPoly*			mPolys;
				btVector3		mLocalCenter;
				btTransform		mTransform;
#ifdef TEST_INTERNAL_OBJECTS
				float			mRadius;
				float			mExtents[3];
				bool			TestContainment()	const;
#endif
				mutable	btVector3	mC;
				mutable	btVector3	mE;
				void			ComputeAABBNoTransform() const;
	};

	__forceinline void InverseTransformPoint3x3(btVector3& out, const btVector3& in, const btTransform& tr)
	{
		const btMatrix3x3& rot = tr.getBasis();
		const btVector3& r0 = rot[0];
		const btVector3& r1 = rot[1];
		const btVector3& r2 = rot[2];

		const float x = r0.x()*in.x() + r1.x()*in.y() + r2.x()*in.z();
		const float y = r0.y()*in.x() + r1.y()*in.y() + r2.y()*in.z();
		const float z = r0.z()*in.x() + r1.z()*in.y() + r2.z()*in.z();

		out.setValue(x, y, z);
	}

#endif // CONVEX_H
