home *** CD-ROM | disk | FTP | other *** search
- // rwmfcdoc.cpp : implementation of the CRwDoc class
- //
-
- #include "stdafx.h"
- #include "rwmfc.h"
-
- #include "rwmfcdoc.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CRwDoc
-
- IMPLEMENT_DYNCREATE(CRwDoc, CDocument)
-
- BEGIN_MESSAGE_MAP(CRwDoc, CDocument)
- //{{AFX_MSG_MAP(CRwDoc)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CRwDoc construction/destruction
-
- CRwDoc::CRwDoc()
- : m_scene(NULL)
- {
- }
-
- CRwDoc::~CRwDoc()
- {
- }
-
- void CRwDoc::DeleteContents()
- {
- if (m_scene != NULL)
- {
- ::RwDestroyScene(m_scene);
- m_scene = NULL;
- }
- }
-
- BOOL CRwDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
-
- m_scene = ::RwCreateScene();
- if (m_scene == NULL)
- {
- // Again, really need proper error checking here.
- AfxMessageBox("Could not create the 3D world", MB_OK | MB_APPLMODAL | MB_ICONSTOP);
- return FALSE;
- }
-
- // Create the default directional light and add it to the scene.
- RwLight *light = ::RwCreateLight(rwDIRECTIONAL,
- CREAL(-1.0), CREAL(-1.0), CREAL(-1.0),
- CREAL(1.0));
- if (light == NULL)
- {
- // Again, no real error checking. Simply issue a generic message and fail.
- AfxMessageBox("Could not create the 3D light", MB_OK | MB_APPLMODAL | MB_ICONSTOP);
- DeleteContents();
- return FALSE;
- }
- ::RwAddLightToScene(m_scene, light);
-
- return TRUE;
- }
-
- BOOL CRwDoc::OnOpenDocument(const char* pathName)
- {
- if (IsModified())
- TRACE0("Warning: OnOpenDocument replaces an unsaved document\n");
-
- DeleteContents();
- SetModifiedFlag(TRUE); // dirty during de-serialize
- BeginWaitCursor();
-
- m_scene = ::RwCreateScene();
- if (m_scene == NULL)
- {
- EndWaitCursor();
- // Again, really need proper error checking here.
- AfxMessageBox("Could not create the 3D world", MB_OK | MB_APPLMODAL | MB_ICONSTOP);
- DeleteContents();
- return FALSE;
- }
-
- RwClump* clump = ::RwReadShape((char*)pathName);
- if (clump == NULL)
- {
- char buffer[_MAX_PATH];
-
- EndWaitCursor();
- wsprintf(buffer, "Could not open script file %s", pathName);
- AfxMessageBox(buffer, MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION);
- DeleteContents();
- return FALSE;
- }
- ::RwAddClumpToScene(m_scene, clump);
-
- // Create the default directional light and add it to the scene.
- RwLight *light = ::RwCreateLight(rwDIRECTIONAL,
- CREAL(-1.0), CREAL(-1.0), CREAL(-1.0),
- CREAL(1.0));
- if (light == NULL)
- {
- EndWaitCursor();
- // Again, no real error checking. Simply issue a generic message and fail.
- AfxMessageBox("Could not create the 3D light", MB_OK | MB_APPLMODAL | MB_ICONSTOP);
- EndWaitCursor();
- return FALSE;
-
- }
- ::RwAddLightToScene(m_scene, light);
-
- EndWaitCursor();
- SetModifiedFlag(FALSE); // start off with unmodified
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CRwDoc serialization
-
- void CRwDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CRwDoc diagnostics
-
- #ifdef _DEBUG
- void CRwDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
-
- void CRwDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CRwDoc commands
-
-