home *** CD-ROM | disk | FTP | other *** search
/ Learn 3D Graphics Programming on the PC / Learn_3D_Graphics_Programming_on_the_PC_Ferraro.iso / rwwin / rwmfcdoc.cp_ / rwmfcdoc.bin
Encoding:
Text File  |  1995-11-14  |  4.1 KB  |  161 lines

  1. // rwmfcdoc.cpp : implementation of the CRwDoc class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "rwmfc.h"
  6.  
  7. #include "rwmfcdoc.h"
  8.  
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char BASED_CODE THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CRwDoc
  16.  
  17. IMPLEMENT_DYNCREATE(CRwDoc, CDocument)
  18.  
  19. BEGIN_MESSAGE_MAP(CRwDoc, CDocument)
  20.     //{{AFX_MSG_MAP(CRwDoc)
  21.         // NOTE - the ClassWizard will add and remove mapping macros here.
  22.         //    DO NOT EDIT what you see in these blocks of generated code!
  23.     //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CRwDoc construction/destruction
  28.  
  29. CRwDoc::CRwDoc()
  30. : m_scene(NULL)
  31. {
  32. }
  33.  
  34. CRwDoc::~CRwDoc()
  35. {
  36. }
  37.  
  38. void CRwDoc::DeleteContents()
  39. {
  40.     if (m_scene != NULL)
  41.     {
  42.         ::RwDestroyScene(m_scene);
  43.         m_scene = NULL;
  44.     }
  45. }
  46.  
  47. BOOL CRwDoc::OnNewDocument()
  48. {
  49.     if (!CDocument::OnNewDocument())
  50.         return FALSE;
  51.         
  52.     m_scene = ::RwCreateScene();
  53.     if (m_scene == NULL)
  54.     {
  55.         // Again, really need proper error checking here.
  56.         AfxMessageBox("Could not create the 3D world", MB_OK | MB_APPLMODAL | MB_ICONSTOP);
  57.         return FALSE;
  58.     }
  59.     
  60.     // Create the default directional light and add it to the scene.
  61.     RwLight *light = ::RwCreateLight(rwDIRECTIONAL,
  62.                                      CREAL(-1.0), CREAL(-1.0), CREAL(-1.0),
  63.                                      CREAL(1.0));
  64.     if (light == NULL)
  65.     {
  66.         // Again, no real error checking. Simply issue a generic message and fail.
  67.         AfxMessageBox("Could not create the 3D light", MB_OK | MB_APPLMODAL | MB_ICONSTOP);
  68.         DeleteContents();
  69.         return FALSE;
  70.     }
  71.     ::RwAddLightToScene(m_scene, light);
  72.  
  73.     return TRUE;
  74. }
  75.  
  76. BOOL CRwDoc::OnOpenDocument(const char* pathName)
  77. {
  78.     if (IsModified())
  79.         TRACE0("Warning: OnOpenDocument replaces an unsaved document\n");
  80.  
  81.     DeleteContents();
  82.     SetModifiedFlag(TRUE);  // dirty during de-serialize
  83.     BeginWaitCursor();
  84.  
  85.     m_scene = ::RwCreateScene();
  86.     if (m_scene == NULL)
  87.     {
  88.         EndWaitCursor();
  89.         // Again, really need proper error checking here.
  90.         AfxMessageBox("Could not create the 3D world", MB_OK | MB_APPLMODAL | MB_ICONSTOP);
  91.         DeleteContents();
  92.         return FALSE;
  93.     }
  94.  
  95.     RwClump* clump = ::RwReadShape((char*)pathName);
  96.     if (clump == NULL)
  97.     {
  98.         char buffer[_MAX_PATH];
  99.         
  100.         EndWaitCursor();
  101.         wsprintf(buffer, "Could not open script file %s", pathName);
  102.         AfxMessageBox(buffer, MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION);
  103.         DeleteContents();
  104.         return FALSE;
  105.     }
  106.     ::RwAddClumpToScene(m_scene, clump);
  107.     
  108.     // Create the default directional light and add it to the scene.
  109.     RwLight *light = ::RwCreateLight(rwDIRECTIONAL,
  110.                                      CREAL(-1.0), CREAL(-1.0), CREAL(-1.0),
  111.                                      CREAL(1.0));
  112.     if (light == NULL)
  113.     {
  114.         EndWaitCursor();
  115.         // Again, no real error checking. Simply issue a generic message and fail.
  116.         AfxMessageBox("Could not create the 3D light", MB_OK | MB_APPLMODAL | MB_ICONSTOP);
  117.         EndWaitCursor();
  118.         return FALSE;
  119.         
  120.     }
  121.     ::RwAddLightToScene(m_scene, light);
  122.  
  123.     EndWaitCursor();
  124.     SetModifiedFlag(FALSE);     // start off with unmodified
  125.     return TRUE;
  126. }
  127.  
  128. /////////////////////////////////////////////////////////////////////////////
  129. // CRwDoc serialization
  130.  
  131. void CRwDoc::Serialize(CArchive& ar)
  132. {
  133.     if (ar.IsStoring())
  134.     {
  135.         // TODO: add storing code here
  136.     }
  137.     else
  138.     {
  139.         // TODO: add loading code here
  140.     }
  141. }
  142.  
  143. /////////////////////////////////////////////////////////////////////////////
  144. // CRwDoc diagnostics
  145.  
  146. #ifdef _DEBUG
  147. void CRwDoc::AssertValid() const
  148. {
  149.     CDocument::AssertValid();
  150. }
  151.  
  152. void CRwDoc::Dump(CDumpContext& dc) const
  153. {
  154.     CDocument::Dump(dc);
  155. }
  156. #endif //_DEBUG
  157.  
  158. /////////////////////////////////////////////////////////////////////////////
  159. // CRwDoc commands
  160.  
  161.