home *** CD-ROM | disk | FTP | other *** search
/ VRML Tools for 3D Cyberspace / VRML_Tools_For_3D_Cyberspace.iso / amber / demos / duck / duck.cpp < prev    next >
C/C++ Source or Header  |  1996-07-01  |  4KB  |  151 lines

  1.  
  2.  
  3. #include <windows.h>
  4.  
  5. #include "amber.hpp"
  6. #include "platter.hpp"
  7. #include "demo.hpp"
  8. #include "duck.h"
  9. #include "resource.h"
  10.  
  11. /**************************************************************************\
  12. *
  13. *  function:  WinMain()
  14. *
  15. *  input parameters:  c.f. generic sample
  16. *
  17. \**************************************************************************/
  18. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  19.                          LPSTR lpCmdLine, int nCmdShow)
  20. {
  21.     HANDLE hInst;
  22.      HWND   hwndMain;
  23.     MSG   msg;
  24.     DWORD retVal;
  25.  
  26.     UNREFERENCED_PARAMETER( lpCmdLine );
  27.  
  28.  
  29.     /* Check for previous instance.  If none, then register class. */
  30.     if (!hPrevInstance) {
  31.         WNDCLASS  wc;
  32.  
  33.         wc.style = CS_VREDRAW;
  34.         wc.lpfnWndProc = (WNDPROC)MainWndProc;
  35.  
  36.         wc.cbClsExtra = 0;
  37.         wc.cbWndExtra = 0;
  38.           wc.hInstance = hInstance;
  39.         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  40.         wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  41.           wc.lpszMenuName =  "SIMPLE_MENU";
  42.           wc.lpszClassName = "simple";
  43.  
  44.         if (!RegisterClass(&wc)) {
  45.             retVal = GetLastError();
  46.             return (FALSE);
  47.          }
  48.     }  /* class registered o.k. */
  49.  
  50.  
  51.     /* Create the main window.  Return false if CreateWindow() fails */
  52.     hInst = hInstance;
  53.  
  54.     hwndMain = CreateWindow(
  55.         "simple",
  56.           "Simple",
  57.         WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
  58.         CW_USEDEFAULT,
  59.         CW_USEDEFAULT,
  60.           CW_USEDEFAULT,
  61.           CW_USEDEFAULT,
  62.         NULL,
  63.         NULL,
  64.         hInstance,
  65.         NULL);
  66.  
  67.     if (!hwndMain) {
  68.         retVal = GetLastError();
  69.         return (FALSE);
  70.     }
  71.     ShowWindow(hwndMain, nCmdShow);
  72.     UpdateWindow(hwndMain);
  73.  
  74.  
  75.     /* Loop getting messages and dispatching them. */
  76.     while (GetMessage(&msg,NULL, 0,0)) {
  77.         TranslateMessage(&msg);
  78.           DispatchMessage(&msg);
  79.      }
  80.  
  81.     return (msg.wParam);
  82. }
  83.  
  84.  
  85. LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  86. {
  87. static channelClass *ch;
  88. universeClass *univ;
  89. static platterClass *platter;
  90. V3 pos;
  91. F2 angles = {10.0*DEG_TO_RAD, 0.0};
  92.   switch (message) {
  93.  
  94.  
  95.      /**********************************************************************\
  96.      *  WM_CREATE
  97.      *
  98.      * Initialize the static variables.
  99.      *  Then create three pens for drawing with later.
  100.      \**********************************************************************/
  101.      case WM_CREATE:
  102.           amber = new amberClass();
  103.           univ = new universeClass();
  104.           ch = new channelClass(hwnd);
  105.           V3_set(pos, 0.0, 0.0, 10.0);
  106.           ch->setPosition(pos);
  107.           platter = new platterClass(hwnd, ABSOLUTE_ANGLES, 60.0, angles);
  108.           platter->setLinearScaling(10.0);
  109.           platter->setMinMaxPitch(0.0, HalfPi);
  110.           platter->attachChannel(ch);
  111.           init(ch);
  112.      break;
  113.  
  114.  
  115.     /**********************************************************************\
  116.      *  WM_DESTROY
  117.      *
  118.      * Complement of the WM_CREATE message.  Delete the pens that were
  119.      *  created and then call postquitmessage.
  120.      \**********************************************************************/
  121.      case WM_DESTROY:
  122.         cleanup();
  123.         delete platter;
  124.         delete amber;
  125.         PostQuitMessage(0);
  126.      break;
  127.  
  128.     case WM_KEYDOWN:
  129.            processChar(wParam);
  130.         break;
  131.  
  132.     case WM_SIZE:
  133.         if (!ch || !IsWindowVisible(hwnd)) break;
  134.         ch->resetPerspective();
  135.         break;
  136.  
  137.     case WM_COMMAND:  // message: command from application menu
  138.         switch(wParam)
  139.         {
  140.             case ID_PROGRAM_EXIT:
  141.                 cleanup();
  142.                 delete platter;
  143.                 delete amber;
  144.                 PostQuitMessage(0);
  145.                 break;
  146.         }
  147.         break;
  148.   } /* end switch */
  149.   return (DefWindowProc(hwnd, message, wParam, lParam));
  150. }
  151.