home *** CD-ROM | disk | FTP | other *** search
/ 3D Graphics Programming for Windows 95 / 3D_Graphics_Programming_for_Windows_95_Microsoft_1996.iso / samples / basic / basic.cpp < prev    next >
C/C++ Source or Header  |  1996-07-01  |  3KB  |  126 lines

  1. // Basic.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Basic.h"
  6.  
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CBasicApp
  16.  
  17. BEGIN_MESSAGE_MAP(CBasicApp, CWinApp)
  18.     //{{AFX_MSG_MAP(CBasicApp)
  19.         // NOTE - the ClassWizard will add and remove mapping macros here.
  20.         //    DO NOT EDIT what you see in these blocks of generated code!
  21.     //}}AFX_MSG_MAP
  22.     // Standard file based document commands
  23.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  24.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  25. END_MESSAGE_MAP()
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CBasicApp construction
  29.  
  30. CBasicApp::CBasicApp()
  31. {
  32.     // TODO: add construction code here,
  33.     // Place all significant initialization in InitInstance
  34. }
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // The one and only CBasicApp object
  38.  
  39. CBasicApp theApp;
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CBasicApp initialization
  43.  
  44. BOOL CBasicApp::InitInstance()
  45. {
  46.     // Create the main window
  47.     C3dWnd* pWnd = new C3dWnd;
  48.     pWnd->Create("3D Basics", 
  49.                  WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  50.                  50, 50,
  51.                  400, 350);
  52.     m_pMainWnd = pWnd;
  53.     pWnd->UpdateWindow();
  54.  
  55.     // Create an initial scene we can add objects to
  56.     static C3dScene scene;
  57.     scene.Create();
  58.  
  59.     // Set ambient light level
  60.     scene.SetAmbientLight(0.4, 0.4, 0.4);
  61.  
  62.     // Add directional light to create highlights
  63.     static C3dDirLight dl;
  64.     dl.Create(0.8, 0.8, 0.8);
  65.     scene.AddChild(&dl);
  66.     dl.SetPosition(-2, 2, -5);
  67.     dl.SetDirection(1, -1, 1);
  68.  
  69.     // Create big white sphere
  70.     static C3dShape sh1;
  71.     sh1.CreateSphere(1);
  72.  
  73.     // Add big white sphere to scene
  74.     scene.AddChild(&sh1);
  75.  
  76.     // Create small blue sphere
  77.     static C3dShape sh2;
  78.     sh2.CreateSphere(0.3);
  79.     sh2.SetColor(0, 0, 1);
  80.  
  81.     // Attach blue sphere to white one
  82.     sh1.AddChild(&sh2);
  83.  
  84.     // Set blue sphere's position relative
  85.     // to white sphere
  86.     sh2.SetPosition(0, 0, -2);
  87.  
  88.     // Create small red sphere
  89.     static C3dShape sh3;
  90.     sh3.CreateSphere(0.15);
  91.     sh3.SetColor(1, 0, 0);
  92.  
  93.     // Attach red sphere to white one
  94.     sh1.AddChild(&sh3);
  95.  
  96.     // Set red sphere's position relative
  97.     // to white sphere
  98.     sh3.SetPosition(0, 0, 5);
  99.  
  100.     // Start rotating big sphere slowly around 
  101.     // the 1, 1, 0 axis
  102.     sh1.SetRotation(1, 1, 0, 0.015);
  103.  
  104.     // Attach entire scene to the stage
  105.     pWnd->SetScene(&scene);
  106.  
  107.     return TRUE;
  108. }
  109.  
  110. BOOL CBasicApp::OnIdle(LONG lCount) 
  111. {
  112.     BOOL bMore = CWinApp::OnIdle(lCount);
  113.     
  114.     if (m_pMainWnd) {
  115.         C3dWnd* pWnd = (C3dWnd*) m_pMainWnd;
  116.  
  117.         // Tell 3D window to move scene one unit,
  118.         // and redraw window
  119.         if (pWnd->Update(1)) {
  120.             bMore = TRUE;
  121.         } 
  122.     }
  123.     return bMore;
  124. }
  125.  
  126.