/****************************************************************************************

		Teapot.cpp

		Copyright (c)1990 - 1999 MetaCreations. All rights reserved.

		Author:	Jerome Bignon
		Date:	05/05/99

		Revision History

		when		who			what & why
		==========	==========	======================================================
		08/20/99	cph			Put in Extension3DInit() and Extension3DCleanup() methods
		05/05/99	Jerome		Creation

*****************************************************************************************/

#include "math.h"
#include "Teapot.h"
#include "TeapotData.h"

real kTeapotSize=3.0f;

const MCGUID CLSID_Teapot(R_CLSID_Teapot);


void Extension3DInit(IMCUnknown* utilities)
{
	// Perform your dll initialization here
}

void Extension3DCleanup()
{
	// Perform any nec clean-up here
}

TBasicUnknown* MakeCOMObject(const MCCLSID& classId)	// This method instanciate
{														// the object Teapot
	TBasicUnknown* res = NULL;

	if (classId == CLSID_Teapot) res = new Teapot;

	return res;
}
         
// Constructor of the C++ Object :
Teapot::Teapot()
{
	// Nothing to do to initialize this object
}
    
// I3DExGeometricPrimitive methods
// -- Geometry calls
MCCOMErr Teapot::EnumPatches( EnumPatchesCallback callback, void* privData, boolean& isClosed)
{
	int16 indexPatch;
	TPatch3D TeapotPatch;
	int16 uPatchIndex,vPatchIndex;
  
	if (callback == NULL) return MC_S_OK;

	TeapotPatch.fu[0]=0.0f;
	TeapotPatch.fu[1]=0.0f;
	TeapotPatch.fv[0]=0.0f;
	TeapotPatch.fv[1]=0.0f;
	TeapotPatch.fUVSpace=0;
	TeapotPatch.fReserved=0;
  
  
	for (indexPatch=0;indexPatch<NUM_PATCHES;indexPatch++)
	{
		for (uPatchIndex=0;uPatchIndex<4;uPatchIndex++)
		{
			for (vPatchIndex=0;vPatchIndex<4;vPatchIndex++)
			{
				TeapotPatch.fVertices[uPatchIndex][vPatchIndex][0]=vertex[vertex_index[indexPatch][uPatchIndex][vPatchIndex]-1][0] * kTeapotSize;
				TeapotPatch.fVertices[uPatchIndex][vPatchIndex][1]=vertex[vertex_index[indexPatch][uPatchIndex][vPatchIndex]-1][1] * kTeapotSize;
				TeapotPatch.fVertices[uPatchIndex][vPatchIndex][2]=vertex[vertex_index[indexPatch][uPatchIndex][vPatchIndex]-1][2] * kTeapotSize;
			}
		} 
    callback(&TeapotPatch,privData);
	}

	isClosed = false; //Teapot is an open primitive.

	return MC_S_OK;
}
  
void Teapot::GetBoundingBox(TBBox3D& bbox)
{ 
	bbox.fMin[0]=-3.0f*kTeapotSize;
	bbox.fMin[1]=-2.0f*kTeapotSize;
	bbox.fMin[2]=0.0f;
	bbox.fMax[0]=345.0f/100.0f*kTeapotSize;    //3.1
	bbox.fMax[1]=2.0f*kTeapotSize;
	bbox.fMax[2]=315.0f/100.0f*kTeapotSize;  //3.15
}


// -- Shading calls
uint32 Teapot::GetUVSpaceCount()
{
	return 0;
}