home *** CD-ROM | disk | FTP | other *** search
- // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
- /* $Id: COMTPot.cpp 1.10 1997/06/20 22:35:42 damien Exp $ */
-
- ////////////////////////////////////////////////////////////////////////
- // Geometric Primitive Example : Teapot //
- //--------------------------------------------------------------------//
- // Implementation of the Teapot Interface //
- ////////////////////////////////////////////////////////////////////////
-
-
- #ifndef __COMTPOT__
- #include "COMTPOT.h"
- #endif
-
- #ifndef __TEAPOTD__
- #include "Teapotd.h" // Teapot Data
- #endif
-
- #ifndef __3DCOFAIL__
- #include "3DCoFail.h"
- #endif
-
- NUM3D kTeapotSize=1.0;
-
- // Constructor / Destructor of the C++ Object :
- Teapot::Teapot() {
- fCRef=0; // Reference Counter
- }
-
- Teapot::~Teapot() {
- global_count_Obj--;
- }
-
- // IUnknown Interface :
- HRESULT Teapot::QueryInterface(THIS_ REFIID riid,LPVOID FAR* ppvObj) {
- *ppvObj=NULL;
-
- // The Teapot knows the interfaces of the parent Objects
- if (IsEqualIID(riid, IID_IUnknown))
- *ppvObj=(IUnknown*)(I3DExGeometricPrimitive*)this;
- else if (IsEqualIID(riid, IID_I3DExGeometricPrimitive))
- *ppvObj=(I3DExGeometricPrimitive*)this;
- else if (IsEqualIID(riid, IID_I3DExDataExchanger))
- *ppvObj=(I3DExDataExchanger*)this;
- else if (IsEqualIID(riid, IID_I3DExtension))
- *ppvObj=(I3DExtension*)this;
-
- // we must add reference if we return an interface
- if (*ppvObj!=NULL) {
- ((LPUNKNOWN)*ppvObj)->AddRef();
- return NOERROR;
- }
- else {
- return ResultFromScode(E_NOINTERFACE);
- }
- }
-
- ULONG Teapot::AddRef(THIS) {
- return fCRef++;
- }
-
- ULONG Teapot::Release(THIS) {
- ULONG UnreleaseObject=fCRef--;
-
- if (fCRef==0)
- delete this; // No reference left, so destroy the object
-
- return UnreleaseObject;
- // local variable used, because fCRef can be destroyed before.
- }
-
- // I3DExtension methods :
- I3DExtension* Teapot::Clone(THIS) {
- Teapot* theClone = new Teapot;
- if (theClone) {
- theClone->AddRef();
- }
- return (I3DExtension*)theClone;
- }
-
- HRESULT Teapot::ShellUtilitiesInit(THIS_ IShUtilities* shellUtilities) {
- InitCoFailure(shellUtilities);
- return NOERROR;
- }
-
- // I3DExDataExchanger methods :
- ExtensionDataMap* Teapot::GetExtensionDataMap(THIS) {
- return NULL;
- }
-
- void* Teapot::GetExtensionDataBuffer(THIS) {
- return NULL;
- }
-
- HRESULT Teapot::ExtensionDataChanged(THIS) {
- return NOERROR;
- }
-
- HRESULT Teapot::HandleEvent(THIS_ ULONG SourceID) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- short Teapot::GetResID(THIS) {
- return -1; // always return -1, if you do not have a view
- }
-
- // I3DExGeometricPrimitive methods
- // -- Geometry calls
- HRESULT Teapot::EnumPatches(THIS_ EnumPatchesCallback callback, void* privData) {
- short indexPatch;
- PATCH3D TeapotPatch;
- short uPatchIndex,vPatchIndex;
-
- TeapotPatch.fu[0]=0.0;
- TeapotPatch.fu[1]=0.0;
- TeapotPatch.fv[0]=0.0;
- TeapotPatch.fv[1]=0.0;
- 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);
- }
- return NOERROR;
- }
-
- HRESULT Teapot::EnumFacets(THIS_ EnumFacetsCallback callback, void* privData, NUM3D fidelity) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT Teapot::GetNbrLOD(short &nbrLod) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT Teapot::GetLOD(short lodIndex, NUM3D &lod) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT Teapot::MakeFacetMesh(short index, FacetMesh &amesh) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT Teapot::MakeFacetMesh(NUM3D lod, FacetMesh &amesh) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT Teapot::GetBBox(THIS_ BOX3D* bbox) {
- bbox->fMin[0]=-3.0*kTeapotSize;
- bbox->fMin[1]=-2.0*kTeapotSize;
- bbox->fMin[2]=0.0;
- bbox->fMax[0]=345.0/100.0*kTeapotSize; //3.1
- bbox->fMax[1]=2.0*kTeapotSize;
- bbox->fMax[2]=315.0/100.0*kTeapotSize; //3.15
- return NOERROR;
- }
-
- // -- Shading calls
- ULONG Teapot::GetUVSpaceCount(THIS) {
- return 0;
- }
-
- HRESULT Teapot::GetUVSpace(THIS_ ULONG uvSpaceID, UVSpaceInfo* uvSpaceInfo) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT Teapot::UV2XYZ(THIS_ VECTOR2D* uv, ULONG uvSpaceID, VECTOR3D* resultPosition,BOOLEAN* inUVSpace) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- // -- Ray Tracing calls
- HRESULT Teapot::RayHit(THIS_ BOOLEAN* didHit, Ray3D* aR, RayHitParameters* RayHitParams, RayHit3D* hit) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT Teapot::GetRayHitDetails(THIS_ RayHit3D* hit) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT Teapot::RayAllHits(THIS_ Ray3D* aR, NUM3D tmin, NUM3D tmax, RayHit3D* hit, RayHitCallback callback, void* privData) {
- return ResultFromScode(E_NOTIMPL);
- }
-