home *** CD-ROM | disk | FTP | other *** search
- // MainFrm.cpp : implementation of the CMainFrame class
- //
-
- #include "stdafx.h"
- #include "Stage.h"
- #include "clock.h"
- #include "MainFrm.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
-
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
-
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_WM_DESTROY()
- ON_WM_ACTIVATEAPP()
- ON_WM_PALETTECHANGED()
- ON_WM_MOVE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
-
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
-
- CMainFrame::CMainFrame()
- {
- m_pScene = NULL;
- }
-
- CMainFrame::~CMainFrame()
- {
- }
-
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- // Create the 3D window
- if (!m_wnd3d.Create(this, IDC_3DWND)) {
- return -1;
- }
-
- SetScene();
- ASSERT(m_pScene);
-
- return 0;
- }
-
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- // Make the initial window a fixed size
- cs.cx = 300;
- cs.cy = 350;
-
- return CFrameWnd::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
-
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CFrameWnd::AssertValid();
- }
-
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CFrameWnd::Dump(dc);
- }
-
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
-
- void CMainFrame::RecalcLayout(BOOL bNotify)
- {
- // Rearrange the control bars and fit the 3D window in the middle
- // Let the frame rearrange the control bars
- CFrameWnd::RecalcLayout(bNotify);
-
- // Find the space that's left over
- CRect rc;
- RepositionBars(0,
- 0xFFFF,
- IDC_3DWND,
- CWnd::reposQuery,
- &rc);
- if (IsWindow(m_wnd3d.GetSafeHwnd())) {
- m_wnd3d.MoveWindow(&rc, FALSE);
- }
- }
-
-
- void CMainFrame::OnDestroy()
- {
- CFrameWnd::OnDestroy();
-
- // Delete any scene we might have
- m_wnd3d.SetScene(NULL);
- if (m_pScene) {
- delete m_pScene;
- m_pScene = NULL;
- }
- }
-
- void CMainFrame::OnActivateApp(BOOL bActive, HTASK hTask)
- {
- CFrameWnd::OnActivateApp(bActive, hTask);
-
- // Tell the 3D window about the new state
- m_wnd3d.SendMessage(WM_ACTIVATEAPP,
- (WPARAM)bActive,
- (LPARAM)hTask);
- }
-
- void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd)
- {
- // Let the 3D window know
- m_wnd3d.SendMessage(WM_PALETTECHANGED,
- pFocusWnd ? (WPARAM)pFocusWnd->GetSafeHwnd() : 0);
- }
-
- void CMainFrame::OnMove(int x, int y)
- {
- CFrameWnd::OnMove(x, y);
-
- // Let the 3D window know the frame has moved
- m_wnd3d.SendMessage(WM_MOVE, 0, MAKELPARAM(0, 0));
- }
-
- BOOL CMainFrame::SetScene()
- {
- // Create an initial scene
- m_pScene = new C3dScene;
- if (!m_pScene->Create()) return FALSE;
- m_wnd3d.SetScene(m_pScene);
-
- // Set up the lighting
- C3dDirLight dl;
- dl.Create(0.8, 0.4, 0.4);
- m_pScene->AddChild(&dl);
- dl.SetPosition(-2, 2, -5);
- dl.SetDirection(1, -1, 1);
- m_pScene->SetAmbientLight(0.4, 0.4, 0.4);
-
- // Build clock
- C3dFrame clock;
- clock.Create(m_pScene);
- double dSpin = -0.1;
-
- // Create the minute hand shaft
- C3dFrame s1;
- s1.Create(&clock);
- C3dShape r1;
- r1.CreateRod(0, 0, -0.5, 0, 0, 10, 0.4, 16);
- r1.SetColor(0, 0, 1);
- s1.AddChild(&r1);
-
- // Add big hand
- CHand bighand(10);
- s1.AddChild(&bighand);
- bighand.SetPosition(0, 0, 0);
-
- // Add gear
- CGear g1(1.5, 1.5, 8);
- s1.AddChild(&g1);
- g1.SetPosition(0, 0, 5.5);
-
- // Make shaft rotate
- s1.SetRotation(0, 0, 1, dSpin);
-
- // Create the little hand shaft
- C3dFrame s2;
- s2.Create(&clock);
- C3dShape r2;
- r2.CreateRod(0, 0, 1.5, 0, 0, 4, 0.8, 16);
- r2.SetColor(0, 0.7, 0);
- s2.AddChild(&r2);
-
- // Add the big hand
- CHand smhand(5);
- s2.AddChild(&smhand);
- smhand.SetPosition(0, 0, 1);
-
- // Add the gear
- CGear g2(3, 0.5, 16);
- s2.AddChild(&g2);
- g2.SetPosition(0, 0, 3);
-
- // Make the shaft rotate
- s2.SetRotation(0, 0, 1, dSpin/4);
-
- // Create the idler shaft
- C3dFrame s3;
- s3.Create(&clock);
- C3dShape r3;
- r3.CreateRod(0, 0, 2, 0, 0, 7, 0.4, 16);
- r3.SetColor(0, 0, 1);
- s3.AddChild(&r3);
-
- // Add the big gear
- CGear g4(3, 0.5, 16);
- s3.AddChild(&g4);
- g4.SetPosition(0, 0, 6);
-
- // Add the small gear
- CGear g3(1.5, 1.5, 8);
- s3.AddChild(&g3);
- g3.SetPosition(0, 0, 2.5);
-
- // Make the shaft rotate
- s3.SetRotation(0, 0, 1, -dSpin/2);
- s3.SetPosition(0, 4.5, 0);
-
-
-
-
-
-
-
- m_pScene->SetBackground(0.75, 0.75, 0.75);
- m_pScene->SetCameraPosition(C3dVector(0, 0, -25));
- clock.SetRotation(0, 1, 0, dSpin/10);
-
- return TRUE;
- }
-
- BOOL CMainFrame::Update(double d)
- {
- return m_wnd3d.Update(TRUE);
- }