ModelMagic3D.cpp
上传用户:cding2008
上传日期:2007-01-03
资源大小:1812k
文件大小:11k
- /////////////////////////////////////////////////////////////////////////////
- // ModelMagic3D.cpp : Defines the class behaviors for the application.
- //
- // ModelMagic 3D and 'glOOP' (OpenGL Object Oriented Programming library)
- // Copyright (c) Craig Fahrnbach 1997, 1999
- //
- // OpenGL is a registered trademark of Silicon Graphics
- //
- //
- // This program is provided for educational and personal use only and
- // is provided without guarantee or warrantee expressed or implied.
- //
- // Commercial use is strickly prohibited without written permission
- // from ImageWare Development.
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "memory.h"
- #include "ModelMagic3D.h"
- #include "MyTime.h"
- #include "ChildFrm.h"
- #include <afxinet.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMyglApp
- BEGIN_MESSAGE_MAP(CMyglApp, CWinApp)
- //{{AFX_MSG_MAP(CMyglApp)
- ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
- ON_COMMAND(ID_HELP_WEBSITE, OnHelpWebsite)
- ON_COMMAND(ID_HELP_SENDMAIL, OnHelpSendmail)
- ON_COMMAND(ID_ORDER_FORM, OnOrderForm)
- ON_COMMAND(ID_ORDER_ONLINE, OnOrderOnline)
- //}}AFX_MSG_MAP
- // Standard file based document commands
- ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
- ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
- // Standard print setup command
- ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyglApp construction
- CMyglApp::CMyglApp()
- {
- // Initialize our local variables
- m_bConfirmObjectDeletion = TRUE;
- m_bRegistered = TRUE;
- m_iDays = 0;
- }
- CMyglApp::~CMyglApp()
- {
- }
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CMyglApp object
- CMyglApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // Global variables
- //
- GLfloat g_fMouseZMult = 0.01f; // Mouse 'Z'-Axis multiplier
- GLfloat g_fMouseRotateMult = 0.5f; // Mouse 'Rotation' multiplier
- GLfloat g_fMouseScaleMult = 0.01f; // Mouse 'Scale' multiplier
- /////////////////////////////////////////////////////////////////////////////
- // CMyglApp initialization
- BOOL CMyglApp::InitInstance()
- {
- // CG: The following block was added by the Splash Screen component.
{
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
}
- // Standard initialization
- // If you are not using these features and wish to reduce the size
- // of your final executable, you should remove from the following
- // the specific initialization routines you do not need.
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
- // Determine the Registration status
- // GetRegStatus();
- LoadStdProfileSettings(); // Load standard INI file options (including MRU)
- // Register the application's document templates. Document templates
- // serve as the connection between documents, frame windows and views.
- m_pDocTemplate = new CMultiDocTemplate(
- IDR_MYGLVIEW,
- RUNTIME_CLASS(CMyglDoc),
- RUNTIME_CLASS(CChildFrame), // custom MDI child frame
- RUNTIME_CLASS(CMyglView));
- // Add the template
- AddDocTemplate(m_pDocTemplate);
-
- // create main MDI Frame window
- CMainFrame* pMainFrame = new CMainFrame;
- if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
- return FALSE;
- m_pMainWnd = pMainFrame;
- // Parse command line for standard shell commands, DDE, file open
- CCommandLineInfo cmdInfo;
- ParseCommandLine(cmdInfo);
- // Dispatch commands specified on the command line
- if (!ProcessShellCommand(cmdInfo))
- return FALSE;
- // The main window has been created. If we have not
- // restored the window state, lets show and update it.
- if(!pMainFrame->m_bWndInitialized) {
- pMainFrame->ShowWindow(m_nCmdShow);
- pMainFrame->UpdateWindow();
- }
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- virtual BOOL OnInitDialog();
- afx_msg void OnButtonWebsite();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- ON_BN_CLICKED(IDC_BUTTON_WEBSITE, OnButtonWebsite)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- // App command to run the dialog
- void CMyglApp::OnAppAbout()
- {
- CAboutDlg aboutDlg;
- aboutDlg.DoModal();
- }
- BOOL CAboutDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CAboutDlg::OnButtonWebsite()
- {
- // Get a pointer to our application
- CMyglApp* pMyApp = (CMyglApp*)AfxGetApp();
- ASSERT(pMyApp);
- pMyApp->OnHelpWebsite();
- //assumes URL names have been initialized
- // CInternetSession session("My Session");
- // CStdioFile* pFile = NULL;
- //use a URL and display a Web page
- // pFile = session.OpenURL("http://members.home.net/craignan/index.htm");
- // delete pFile;
- // session.Close();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyglApp commands
- BOOL CMyglApp::OnIdle(LONG lCount)
- {
- static BOOL bAnimating = FALSE;
- static BOOL bResetRequired = FALSE;
- static int iFrames;
- static double dLastStatusBarUpdate;
- double dElapsedTime;
- BOOL bMore = CWinApp::OnIdle(lCount);
- // Get a pointer to our MainFrame and determine if we need
- // to Animate our OpenGL window...
- CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
- ASSERT(pFrame);
- if(pFrame->m_pActiveView) {
- // Get a pointer to our CView derived class
- CMyglView* pView = (CMyglView*)pFrame->m_pActiveView;
- ASSERT_VALID(pView);
- if(pFrame->m_pActiveWorld->m_bAnimate)
- {
- bResetRequired = TRUE;
- if(!bAnimating)
- {
- MyTimeBegin(); // Record the high performance counter
- bAnimating = TRUE;
- iFrames = 0;
- }
- // Get the elapsed time since we started animating.
- dElapsedTime = MyTimeElapsed();
- // Get a pointer to our document and save the time index
- CMyglDoc* pDoc = (CMyglDoc*)pFrame->m_pActiveView->GetDocument();
- ASSERT(pDoc);
- pDoc->m_dTime = dElapsedTime;
- // Force a repaint of the window
- pFrame->m_pActiveView->InvalidateRect(NULL, FALSE);
- // Increment the number of frames
- iFrames++;
- // Get the time elapsed since we last updated the
- // status bar.
- double dTime = dElapsedTime-dLastStatusBarUpdate;
- if(dTime > 2.0)
- {
- dLastStatusBarUpdate = dElapsedTime;
- // Calculate the number of frames per second
- float fps = (float)(iFrames/dTime);
- iFrames = 0; // reset frames
- char buf[80];
- sprintf(buf, "Animating at %2.2f fpsn", fps);
- CStatusBar* pStatus = &pFrame->m_wndStatusBar;
- pStatus->SetPaneText(0, buf);
- }
- return TRUE;
- }
- else
- {
- bAnimating = FALSE;
- dLastStatusBarUpdate = 0.0;
- if(bResetRequired)
- {
- // Reset the world Animation variables
- pFrame->m_pActiveWorld->ResetAnimation(&pView->m_Camera);
- bResetRequired = FALSE;
- // Force a repaint of the window
- pFrame->m_pActiveView->InvalidateRect(NULL, FALSE);
- }
- }
- }
- return bMore;
- }
- BOOL CMyglApp::PreTranslateMessage(MSG* pMsg)
- {
- // CG: The following lines were added by the Splash Screen component.
if (CSplashWnd::PreTranslateAppMessage(pMsg))
return TRUE;
return CWinApp::PreTranslateMessage(pMsg);
- }
- int CMyglApp::ExitInstance()
- {
- return CWinApp::ExitInstance();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyglApp procedures/Operations
- void CMyglApp::GetRegStatus()
- {
- CString szWinDir, szRegFile;
- CFile cfile;
- CFileException fe;
- char pBuf[100];
- UINT nBytesWrite;
- DWORD dw = 0;
- struct tm *newtime;
- long ltime;
- // Get the current time
- time( <ime );
- // Obtain coordinated universal time:
- newtime = gmtime( <ime );
- // Get the windows directory
- GetWindowsDirectory(szWinDir.GetBuffer(MAX_PATH), // address of buffer
- MAX_PATH); // size of directory buffer
- szRegFile.Format("%s\%s", szWinDir, "iwdreg.dat"); // Format the name of the file
- // Open the file
- if(!cfile.Open( szRegFile, CFile::modeCreate | CFile::modeNoTruncate |
- CFile::modeReadWrite, &fe))
- {
- // Error! Display message to the user..
- CString buffer;
- buffer.Format("Could not open Regristration status file!n");
- AfxMessageBox(buffer, MB_OK, 0);
- return;
- }
- // Read the data
- if(cfile.Read( pBuf, 100 ))
- {
- int iYear, iDays;
- sscanf( pBuf, "%ld", &dw);
- iYear = dw & 0x000000FF;
- iDays = (dw & 0x0000FF00) >> 8;
- m_bRegistered = (dw & 0x10000000) >> 28;
- m_iDays = ((newtime->tm_year-iYear)*365)+
- (newtime->tm_yday-iDays);
- }
- else
- {
- // File does not exist, or contains no data, so save the data
- dw = newtime->tm_year | (newtime->tm_yday << 8);
- nBytesWrite = sprintf(pBuf, "%ld", dw);
- cfile.Write( pBuf, nBytesWrite );
- }
- }
- void CMyglApp::OnHelpWebsite()
- {
- DisplayWebSite();
- }
- void CMyglApp::DisplayWebSite()
- {
- ShellExecute( NULL, "open", "www.imagewaredev.com", 0,0,1);
- }
- void CMyglApp::OnHelpSendmail()
- {
- SendEmail();
- }
- void CMyglApp::SendEmail()
- {
- ShellExecute( NULL, "open", "mailto:support@imagewaredev.com", 0,0,1);
- }
- void CMyglApp::OnOrderForm()
- {
- AfxGetApp()->WinHelp(0x10000 + ID_ORDER_FORM);
- }
- void CMyglApp::OnOrderOnline()
- {
- ShellExecute( NULL, "open", "www.imagewaredev.com", 0,0,1);
- }
- void CMyglApp::SetPrinterDeviceDefaults(HGLOBAL hDevNames, HGLOBAL hDevMode)
- {
- // Lock the handles to the structures to get pointers
- LPDEVNAMES pDevNames = (LPDEVNAMES)::GlobalLock(hDevNames);
- LPDEVMODE pDevMode = (LPDEVMODE)::GlobalLock(hDevMode);
- // Free the old printer information if it exists
- if (m_hDevNames != NULL)
- ::GlobalFree(m_hDevNames);
- if (m_hDevMode != NULL)
- ::GlobalFree(m_hDevMode);
- // Allocate space for the new printer info structures
- m_hDevNames = ::GlobalAlloc(GPTR, ::GlobalSize(hDevNames));
- m_hDevMode = ::GlobalAlloc(GPTR, ::GlobalSize(hDevMode));
- // Lock the new handles
- LPDEVNAMES m_pDevNames = (LPDEVNAMES)::GlobalLock(m_hDevNames);
- LPDEVMODE m_pDevMode = (LPDEVMODE)::GlobalLock(m_hDevMode);
- // Copy the printer information into the document
- memcpy(m_pDevNames, pDevNames,
- (size_t)::GlobalSize(hDevNames));
- memcpy(m_pDevMode, pDevMode,
- (size_t)::GlobalSize(hDevMode));
- // Unlock the handles
- ::GlobalUnlock(hDevNames);
- ::GlobalUnlock(hDevMode);
- ::GlobalUnlock(m_hDevNames);
- ::GlobalUnlock(m_hDevMode);
- }