home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / PRIMITIV / TPOT / COMTPOT.CPP next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  5.4 KB  |  190 lines

  1. // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
  2. /* $Id: COMTPot.cpp 1.10 1997/06/20 22:35:42 damien Exp $ */
  3.  
  4. ////////////////////////////////////////////////////////////////////////
  5. //   Geometric Primitive Example : Teapot                             //
  6. //--------------------------------------------------------------------//
  7. //   Implementation of the Teapot Interface                           //
  8. //////////////////////////////////////////////////////////////////////// 
  9.  
  10.  
  11. #ifndef __COMTPOT__
  12. #include "COMTPOT.h"
  13. #endif
  14.  
  15. #ifndef __TEAPOTD__
  16. #include "Teapotd.h"  // Teapot Data
  17. #endif
  18.  
  19. #ifndef __3DCOFAIL__
  20. #include "3DCoFail.h"
  21. #endif
  22.  
  23. NUM3D kTeapotSize=1.0;
  24.          
  25. // Constructor / Destructor of the C++ Object :
  26. Teapot::Teapot() {
  27.   fCRef=0; // Reference Counter
  28.   }
  29.   
  30. Teapot::~Teapot() {
  31.   global_count_Obj--; 
  32.   }
  33.   
  34. // IUnknown Interface :
  35. HRESULT Teapot::QueryInterface(THIS_ REFIID riid,LPVOID FAR* ppvObj) {
  36.   *ppvObj=NULL;
  37.   
  38.   // The Teapot knows the interfaces of the parent Objects
  39.   if (IsEqualIID(riid, IID_IUnknown))
  40.     *ppvObj=(IUnknown*)(I3DExGeometricPrimitive*)this;
  41.   else if (IsEqualIID(riid, IID_I3DExGeometricPrimitive))
  42.     *ppvObj=(I3DExGeometricPrimitive*)this;
  43.   else if (IsEqualIID(riid, IID_I3DExDataExchanger))
  44.     *ppvObj=(I3DExDataExchanger*)this;
  45.   else if (IsEqualIID(riid, IID_I3DExtension))
  46.     *ppvObj=(I3DExtension*)this;
  47.     
  48.   // we must add reference if we return an interface
  49.   if (*ppvObj!=NULL) {
  50.         ((LPUNKNOWN)*ppvObj)->AddRef();
  51.     return NOERROR;
  52.     }
  53.   else {
  54.     return ResultFromScode(E_NOINTERFACE);
  55.     }
  56.   }
  57.  
  58. ULONG Teapot::AddRef(THIS) {
  59.   return fCRef++;
  60.   }
  61.   
  62. ULONG Teapot::Release(THIS) {
  63.   ULONG UnreleaseObject=fCRef--;
  64.   
  65.   if (fCRef==0)
  66.      delete this; // No reference left, so destroy the object
  67.   
  68.   return UnreleaseObject;
  69.   // local variable used, because fCRef can be destroyed before.
  70.   }
  71.   
  72. // I3DExtension methods :
  73. I3DExtension* Teapot::Clone(THIS) {
  74.   Teapot* theClone = new Teapot;
  75.   if (theClone) {
  76.     theClone->AddRef();
  77.         }                               
  78.   return (I3DExtension*)theClone;
  79.   }   
  80.  
  81. HRESULT Teapot::ShellUtilitiesInit(THIS_ IShUtilities* shellUtilities) {
  82.   InitCoFailure(shellUtilities);
  83.   return NOERROR;
  84.   }
  85.  
  86. // I3DExDataExchanger methods :
  87. ExtensionDataMap* Teapot::GetExtensionDataMap(THIS) {
  88.   return NULL;
  89.   }               
  90.   
  91. void* Teapot::GetExtensionDataBuffer(THIS) {
  92.   return NULL;
  93.   }
  94.   
  95. HRESULT Teapot::ExtensionDataChanged(THIS) {
  96.   return NOERROR;
  97.   }
  98.  
  99. HRESULT Teapot::HandleEvent(THIS_ ULONG SourceID) {
  100.   return ResultFromScode(E_NOTIMPL);
  101.   }
  102.  
  103. short Teapot::GetResID(THIS) {
  104.   return -1; // always return -1, if you do not have a view
  105.   }
  106.   
  107. // I3DExGeometricPrimitive methods
  108. // -- Geometry calls
  109. HRESULT Teapot::EnumPatches(THIS_ EnumPatchesCallback callback, void* privData) {
  110.     short indexPatch;
  111.   PATCH3D TeapotPatch;
  112.   short uPatchIndex,vPatchIndex;
  113.   
  114.   TeapotPatch.fu[0]=0.0;
  115.   TeapotPatch.fu[1]=0.0;
  116.   TeapotPatch.fv[0]=0.0;
  117.   TeapotPatch.fv[1]=0.0;
  118.   TeapotPatch.fUVSpace=0;
  119.     TeapotPatch.fReserved=0;
  120.   
  121.   
  122.   for (indexPatch=0;indexPatch<NUM_PATCHES;indexPatch++) {
  123.         for (uPatchIndex=0;uPatchIndex<4;uPatchIndex++) {
  124.       for (vPatchIndex=0;vPatchIndex<4;vPatchIndex++) {
  125.         TeapotPatch.fVertices[uPatchIndex][vPatchIndex][0]=vertex[vertex_index[indexPatch][uPatchIndex][vPatchIndex]-1][0] * kTeapotSize;
  126.         TeapotPatch.fVertices[uPatchIndex][vPatchIndex][1]=vertex[vertex_index[indexPatch][uPatchIndex][vPatchIndex]-1][1] * kTeapotSize;
  127.         TeapotPatch.fVertices[uPatchIndex][vPatchIndex][2]=vertex[vertex_index[indexPatch][uPatchIndex][vPatchIndex]-1][2] * kTeapotSize;
  128.                 }
  129.             } 
  130.     callback(&TeapotPatch,privData);
  131.         }
  132.   return NOERROR;
  133.     }
  134.   
  135. HRESULT Teapot::EnumFacets(THIS_ EnumFacetsCallback callback, void* privData, NUM3D fidelity) {
  136.   return ResultFromScode(E_NOTIMPL);
  137.     }
  138.   
  139. HRESULT Teapot::GetNbrLOD(short &nbrLod) {
  140.   return ResultFromScode(E_NOTIMPL);
  141.     }
  142.  
  143. HRESULT Teapot::GetLOD(short lodIndex, NUM3D &lod) {
  144.   return ResultFromScode(E_NOTIMPL);
  145.     }
  146.  
  147. HRESULT Teapot::MakeFacetMesh(short index, FacetMesh &amesh) {
  148.   return ResultFromScode(E_NOTIMPL);
  149.     }
  150.   
  151. HRESULT Teapot::MakeFacetMesh(NUM3D lod, FacetMesh &amesh) {
  152.   return ResultFromScode(E_NOTIMPL);
  153.     }
  154.  
  155. HRESULT Teapot::GetBBox(THIS_ BOX3D* bbox) { 
  156.   bbox->fMin[0]=-3.0*kTeapotSize;
  157.   bbox->fMin[1]=-2.0*kTeapotSize;
  158.   bbox->fMin[2]=0.0;
  159.   bbox->fMax[0]=345.0/100.0*kTeapotSize;    //3.1
  160.   bbox->fMax[1]=2.0*kTeapotSize;
  161.   bbox->fMax[2]=315.0/100.0*kTeapotSize;  //3.15
  162.   return NOERROR;
  163.     }
  164.   
  165. // -- Shading calls
  166. ULONG Teapot::GetUVSpaceCount(THIS) {
  167.   return 0;
  168.     }
  169.  
  170. HRESULT Teapot::GetUVSpace(THIS_ ULONG uvSpaceID, UVSpaceInfo* uvSpaceInfo) {
  171.   return ResultFromScode(E_NOTIMPL);
  172.     }
  173.   
  174. HRESULT Teapot::UV2XYZ(THIS_ VECTOR2D* uv, ULONG uvSpaceID, VECTOR3D* resultPosition,BOOLEAN* inUVSpace) {
  175.   return ResultFromScode(E_NOTIMPL);
  176.     }
  177.  
  178. // -- Ray Tracing calls
  179. HRESULT Teapot::RayHit(THIS_ BOOLEAN* didHit, Ray3D* aR, RayHitParameters* RayHitParams, RayHit3D* hit) {
  180.   return ResultFromScode(E_NOTIMPL);
  181.   }
  182.   
  183. HRESULT Teapot::GetRayHitDetails(THIS_ RayHit3D* hit) {
  184.   return ResultFromScode(E_NOTIMPL);
  185.   }
  186.   
  187. HRESULT Teapot::RayAllHits(THIS_ Ray3D* aR, NUM3D tmin, NUM3D tmax, RayHit3D* hit, RayHitCallback callback, void* privData) {
  188.   return ResultFromScode(E_NOTIMPL);
  189.   }
  190.