home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_tools / v_lib205 / vlibdemo.c < prev    next >
C/C++ Source or Header  |  1994-02-20  |  62KB  |  2,110 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM:    Vlibdemo.exe
  4.  
  5.     PURPOSE:    To demonstrate the usage of Visualib(TM) functions.
  6.     
  7.     PROVIDER:   Visual Tech Co.
  8.                 P.O.Box 8735
  9.                 Fort Wayne, IN 46898-8735
  10.                 Tel. (219) 289-0235
  11.                 Fax. (816) 746-6618
  12.     
  13.     DATE:        Januray. 1994
  14.  
  15. ****************************************************************************/
  16.  
  17. #include <windows.h>
  18. #include <math.h>
  19. #include <malloc.h>
  20. #include "visualib.h"
  21. #include "vlibdemo.h"
  22. #include "demoproc.h"
  23. #include "dialogs.h"
  24.  
  25. HINSTANCE    hInst;
  26. short   viewer20 = 0, viewer21 = 0, viewer22 = 0;
  27. short   viewer30 = 0, viewer31 = 0, viewer32 = 0,
  28.         viewer33 = 0, viewer34 = 0, viewer35 = 0;
  29. short   demo_function, animate_length;
  30. short   light0 = 0, light1 = 0, light2 = 0, light3 = 0,
  31.         light4 = 0, light5 = 0, light6 = 0, light7 = 0, light8 = 0;
  32. short   mater0, mater1, mater2, mater3, mater4, mater5, mater6, mater7;
  33. HGLOBAL hdib1 = NULL, hdib2 = NULL, hdib3 = NULL;
  34. COLORREF    backcolor;
  35. BOOL    withframe = FALSE;
  36. HPALETTE    hpal;
  37.  
  38. void    FunctionDemos (HDC hdc); 
  39.  
  40. int PASCAL _export WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR CmdLine, int nCmdShow)
  41. {
  42.     MSG msg;
  43.  
  44.     if (hPrev)
  45.         return (FALSE);
  46.  
  47.     if (!InitApplication (hInst))
  48.         return (FALSE);
  49.     
  50.     if (!InitInstance (hInst, nCmdShow))
  51.         return (FALSE);
  52.     
  53.     while (GetMessage (&msg, NULL, NULL, NULL)) {
  54.         TranslateMessage (&msg);
  55.         DispatchMessage (&msg);
  56.     }
  57.     return (msg.wParam);
  58. }
  59.  
  60. void    ViewerReset ()
  61. {
  62.     RECT    port;
  63.  
  64.     if (viewer21) {
  65.         SetRect (&port, 10, 10, 110, 110);
  66.         SetViewport (viewer21, port);
  67.         SetWindow2D (viewer21, -10, -10, 10, 10);
  68.     }
  69.  
  70.     if (viewer22) {
  71.         SetRect (&port, 10, 10, 410, 227);
  72.         SetViewport (viewer22, port);
  73.         SetWindow2D (viewer22, 0, 0, 1, (REAL) (13.0 / 24.0));
  74.     }
  75.  
  76.     if (viewer31) {
  77.         SetRect (&port, 120, 10, 220, 110);
  78.         SetViewport (viewer31, port);
  79.         SetView3D (viewer31, 100, 100, 100, 0, 0, 0, 0);
  80.         SetPerspective (viewer31, 45, 1, 1, 1000);
  81.     }
  82.  
  83.     if (viewer32) {
  84.         SetRect (&port, 230, 10, 330, 110);
  85.         SetViewport (viewer32, port);
  86.         SetView3D (viewer32, 100, 100, 100, 0, 0, 0, 0);
  87.         SetPerspective (viewer32, 45, 1, 1, 1000);
  88.     }
  89.  
  90.     if (viewer33) {
  91.         SetRect (&port, 230, 130, 330, 230);
  92.         SetViewport (viewer33, port);
  93.         SetPolarView (viewer33, 1, 1, 0, 20, 75, 45, 0);
  94.         SetPerspective (viewer33, 90, 1, 1, 1000);
  95.     }
  96.  
  97.     if (viewer34) {
  98.         SetRect (&port, 120, 130, 220, 230);
  99.         SetViewport (viewer34, port);
  100.         SetPolarView (viewer34, 0, 0, 0, 10, 45, 45, 0);
  101.         SetProjection3D (viewer34, -10, -10, 10, 10, 1, 100, VL_ORTHOGONAL);
  102.     }
  103.  
  104.     if (viewer35) {
  105.         SetRect (&port, 10, 130, 110, 230);
  106.         SetViewport (viewer35, port);
  107.         SetPolarView (viewer35, 0, 0, 0, 20, 75, 45, 0);
  108.         SetPerspective (viewer35, 90, 1, 1, 80);
  109.     }
  110. }
  111.  
  112. /****************************************************************************
  113.  
  114.     FUNCTION: InitApplication (HANDLE)
  115.  
  116. ****************************************************************************/
  117.  
  118. BOOL InitApplication (HINSTANCE hInstance)
  119. {
  120.     WNDCLASS  wc;
  121.     RECT    port;
  122.     VECTOR3    parameter;
  123.     HDC        hdc;
  124.  
  125.     if (!InitializeVisualib ())
  126.         return (FALSE);
  127.  
  128.     hpal = SetRGBPalette ();
  129.  
  130.     light0 = CreateLight (NULL, VL_DISTLIGHT);
  131.     if (light0) {
  132.         SelectLight (light0);
  133.         SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  134.         VSET3 (parameter, 3, 1, 3);
  135.         ShadingParameter (VL_CURRENT, VL_LIGHTDIRECTION, FALSE, parameter);
  136.         ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 255, 255));
  137.     }
  138.  
  139.     light1 = CreateLight (NULL, VL_DISTLIGHT);
  140.     if (light1) {
  141.         SelectLight (light1);
  142.         SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  143.         VSET3 (parameter, 5, 1, 4);
  144.         ShadingParameter (VL_CURRENT, VL_LIGHTDIRECTION, FALSE, parameter);
  145.         ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 255, 255));
  146.         SwitchLight (VL_CURRENT, TRUE);
  147.     }
  148.  
  149.     light2 = CreateLight (NULL, VL_POINTLIGHT);
  150.     if (light2) {
  151.         SelectLight (light2);
  152.         VSET3 (parameter, -50, 0, 0);
  153.         ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  154.         ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (51, 255, 51));
  155.     }
  156.  
  157.     light3 = CreateLight (NULL, VL_POINTLIGHT);
  158.     if (light3) {
  159.         SelectLight (light3);
  160.         VSET3 (parameter, 250, -20, 0);
  161.         ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  162.         ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (51, 51, 255));
  163.     }
  164.  
  165.     light4 = CreateLight (NULL, VL_SPOTLIGHT);
  166.     if (light4) {
  167.         SelectLight (light4);
  168.         SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  169.         VSET3 (parameter, 0, 100, 100);
  170.         ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  171.         VSET3 (parameter, 0, -1, -1);
  172.         ShadingParameter (VL_CURRENT, VL_LIGHTDIRECTION, FALSE, parameter);
  173.         ShadingFactor (VL_CURRENT, VL_SPOTLIGHTANGLE, 20);
  174.         ShadingFactor (VL_CURRENT, VL_SPOTLIGHTSPREAD, 50);
  175.         ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 0, 0));
  176.     }
  177.  
  178.     light5 = CreateLight (NULL, VL_SPOTLIGHT);
  179.     if (light5) {
  180.         SelectLight (light5);
  181.         SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  182.         VSET3 (parameter, 100, 0, 100);
  183.         ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  184.         VSET3 (parameter, -1, 0, -1);
  185.         ShadingParameter (VL_CURRENT, VL_LIGHTDIRECTION, FALSE, parameter);
  186.         ShadingFactor (VL_CURRENT, VL_SPOTLIGHTANGLE, 20);
  187.         ShadingFactor (VL_CURRENT, VL_SPOTLIGHTSPREAD, 50);
  188.         ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (0, 255, 0));
  189.     }
  190.  
  191.     light6 = CreateLight (NULL, VL_SPOTLIGHT);
  192.     if (light6) {
  193.         SelectLight (light6);
  194.         SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  195.         VSET3 (parameter, 100, 100, 100);
  196.         ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  197.         VSET3 (parameter, -1, -1, -1);
  198.         ShadingParameter (VL_CURRENT, VL_LIGHTDIRECTION, FALSE, parameter);
  199.         ShadingFactor (VL_CURRENT, VL_SPOTLIGHTANGLE, 20);
  200.         ShadingFactor (VL_CURRENT, VL_SPOTLIGHTSPREAD, 50);
  201.         ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (0, 0, 255));
  202.     }
  203.  
  204.     light7 = CreateLight (NULL, VL_POINTLIGHT);
  205.     if (light7) {
  206.         SelectLight (light7);
  207.         SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  208.         VSET3 (parameter, 250, 0, 0);
  209.         ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  210.         ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 255, 255));
  211.         ShadingFactor (VL_CURRENT, VL_LIGHTINTENSITY, 1);
  212.     }
  213.  
  214.     light8 = CreateLight (NULL, VL_POINTLIGHT);
  215.     if (light8) {
  216.         SelectLight (light8);
  217.         SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  218.         VSET3 (parameter, 350, 150, 350);
  219.         ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  220.         ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 255, 255));
  221.         ShadingFactor (VL_CURRENT, VL_LIGHTINTENSITY, 1);
  222.     }
  223.  
  224.     hdc = GetDC (NULL);
  225.     if (GetDeviceCaps (hdc, BITSPIXEL) >= 8) {
  226.         ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_PHONGSHADE);
  227.         ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  228.     }
  229.     else {
  230.         ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  231.         ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  232.     }
  233.     ShadingOption (VL_CURRENT, VL_LOCALVIEWER, FALSE);
  234.     ReleaseDC (NULL, hdc);
  235.     
  236.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  237.  
  238.     SelectMaterial (mater0 = CreateMaterial (NULL));
  239.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  240.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, 1);
  241.     ShadingColor (VL_CURRENT, VL_MATERIALAMBIENT, RGB (255, 255, 255));
  242.     ShadingFactor (VL_CURRENT, VL_AMBIENTREFLECT, 0.2f);
  243.     ShadingColor (VL_CURRENT, VL_MATERIALDIFFUSE, RGB (255, 255, 255));
  244.     ShadingFactor (VL_CURRENT, VL_SHININESS, 30);
  245.  
  246.     SelectMaterial (mater1 = CreateMaterial (NULL));
  247.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  248.     ShadingColor (VL_CURRENT, VL_MATERIALAMBIENT, RGB (0, 0, 0));
  249.     ShadingFactor (VL_CURRENT, VL_AMBIENTREFLECT, 0.5f);
  250.     ShadingColor (VL_CURRENT, VL_MATERIALDIFFUSE, RGB (255, 0, 0));
  251.     ShadingFactor (VL_CURRENT, VL_SHININESS, 50);
  252.  
  253.     SelectMaterial (mater2 = CreateMaterial (NULL));
  254.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  255.     ShadingColor (VL_CURRENT, VL_MATERIALAMBIENT, RGB (255, 255, 255));
  256.     ShadingFactor (VL_CURRENT, VL_AMBIENTREFLECT, 0.5f);
  257.     ShadingColor (VL_CURRENT, VL_MATERIALDIFFUSE, RGB (0, 255, 0));
  258.     ShadingFactor (VL_CURRENT, VL_SHININESS, 50);
  259.  
  260.     SelectMaterial (mater3 = CreateMaterial (NULL));
  261.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  262.     ShadingColor (VL_CURRENT, VL_MATERIALAMBIENT, RGB (255, 255, 255));
  263.     ShadingFactor (VL_CURRENT, VL_AMBIENTREFLECT, 0.5f);
  264.     ShadingColor (VL_CURRENT, VL_MATERIALDIFFUSE, RGB (0, 0, 255));
  265.     ShadingFactor (VL_CURRENT, VL_SHININESS, 50);
  266.     mater4 = CreateMaterial (NULL);
  267.     mater5 = CreateMaterial (NULL);
  268.     mater6 = CreateMaterial (NULL);
  269.     mater7 = CreateMaterial (NULL);
  270.     SelectMaterial (mater3);
  271.  
  272.     SetRect (&port, 0, 0, 400, 300);
  273.     viewer20 = CreateViewer (NULL, port, VL_TWOD, VL_HORZFIT);
  274.     SetWindow2D (viewer20, -10, -10, 10, 10); 
  275.     viewer30 = CreateViewer (NULL, port, VL_THREED, VL_HORZFIT);
  276.     SetView3D (viewer30, 100, 100, 100, 0, 0, 0, 0);
  277.     SetPerspective (viewer30, 45, 1, 30, 1000);
  278.     SetDepthBuffer (viewer30);
  279.  
  280.     viewer21 = CreateViewer (NULL, port, VL_TWOD, VL_HORZFIT);
  281.     viewer22 = CreateViewer (NULL, port, VL_TWOD, VL_ALLFIT);
  282.     viewer31 = CreateViewer (NULL, port, VL_THREED, VL_ALLFIT);
  283.     viewer32 = CreateViewer (NULL, port, VL_THREED, VL_ALLFIT);
  284.     viewer33 = CreateViewer (NULL, port, VL_THREED, VL_ALLFIT);
  285.     viewer34 = CreateViewer (NULL, port, VL_THREED, VL_HORZFIT);
  286.     viewer35 = CreateViewer (NULL, port, VL_THREED, VL_ALLFIT);
  287.  
  288.     ViewerReset ();
  289.  
  290.     demo_function = IDM_DEMO_START;
  291.     wc.style = NULL;
  292.     wc.lpfnWndProc = MainWndProc;
  293.     wc.cbClsExtra = 0;
  294.     wc.cbWndExtra = 0;
  295.     wc.hInstance = hInstance;
  296.     wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (VL_LOGO));
  297.     wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  298.     backcolor = RGB (128, 128, 128);
  299.     wc.hbrBackground = GetStockObject(GRAY_BRUSH);
  300.     wc.lpszMenuName = "VlibDemo";
  301.     wc.lpszClassName = "VlibDemoClass";
  302.  
  303.     return (RegisterClass (&wc));
  304.  
  305. }
  306.  
  307. /****************************************************************************
  308.  
  309.     FUNCTION:  InitInstance (HANDLE, int)
  310.  
  311. ****************************************************************************/
  312.  
  313. BOOL InitInstance (HINSTANCE hInstance, int nCmdShow)
  314. {
  315.     HWND    hWnd;
  316.     int     sw, sh, ww, wh;
  317.  
  318.     sw = GetSystemMetrics (0);
  319.     sh = GetSystemMetrics (1);
  320.     hInst = hInstance;
  321.  
  322.     ww = (int) (sw * 0.8f);
  323.     wh = (int) (sh * 0.8f);
  324.     sw = (int) (sw / 10);
  325.     sh = (int) (sh / 10);
  326.     hWnd = CreateWindow ("VlibDemoClass", "Visualib 2.05 Demonstration",
  327.         WS_OVERLAPPEDWINDOW, sw, sh, ww, wh, NULL, NULL, hInstance, NULL);
  328.  
  329.     if (!hWnd)
  330.         return (FALSE);
  331.  
  332.     ShowWindow (hWnd, nCmdShow);
  333.     UpdateWindow (hWnd);
  334.     PostMessage (hWnd, WM_COMMAND, IDM_DEMO_WITHFRAME, 0L);
  335.     return (TRUE);
  336. }
  337.  
  338. POINT3D surf[16] = {
  339.     {-3, 0, 1}, {2, 1, 0}, {5, 0, 0}, {8, 0, 2},
  340.     {-2, 2, 3}, {1, 4, 3}, {6, 4, 1}, {7, 2, 1},
  341.     {-2, 5, 5}, {1, 7, 3}, {5, 5, 2}, {7, 6, 3},
  342.     {-2, 8, 8}, {2, 9, 0}, {4, 7, 4}, {8, 9, 9}
  343. };
  344.  
  345. REAL    sknot[20] = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4};
  346. REAL    tknot[20] = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4};
  347.  
  348. void    ObjectMotion2D (HDC hdc)
  349. {
  350.     short   i;
  351.  
  352.     SelectViewer (viewer21);
  353.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  354.     PenColor (hdc, VL_RED);
  355.     for (i = 0; i < 5 * animate_length; i ++) {
  356.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  357.         BrushColor (hdc, VL_GREEN);
  358.         Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
  359.         BrushColor (hdc, VL_RED);
  360.         Star2D (hdc, 0, 0, 0, 4, 4, 5);
  361.         Rotate2D (6);
  362.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  363.     }
  364.     for (i = 0; i < 5 * animate_length; i ++) {
  365.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  366.         BrushColor (hdc, VL_GREEN);
  367.         Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
  368.         BrushColor (hdc, VL_RED);
  369.         Star2D (hdc, 0, 0, 0, 4, 4, 5);
  370.         MoveViewer2D (VL_CURRENT, 0.25f, 0, TRUE);
  371.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  372.     }
  373.  
  374.     for (i = 0; i < 5 * animate_length; i ++) {
  375.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  376.         BrushColor (hdc, VL_GREEN);
  377.         Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
  378.         BrushColor (hdc, VL_RED);
  379.         Star2D (hdc, 0, 0, 0, 4, 4, 5);
  380.         Scale2D ((REAL)1.06, (REAL)1.06);
  381.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  382.     }
  383.     EndDoubleBuffer (&hdc, VL_CURRENT);
  384.     SetViewerName (VL_CURRENT, "2D Object Motion");
  385. }
  386.  
  387. void    ViewerMotion3D (HDC hdc)
  388. {
  389.     short   i;
  390.  
  391.     SelectViewer (viewer31);
  392.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  393.     SelectMaterial (mater1);
  394.     for (i = 0; i < 3 * animate_length; i ++) {
  395.         MoveViewer3D (VL_CURRENT, 0, 0, -10, TRUE);
  396.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  397.         if (!Cube (hdc, 50, 50, 25))
  398.             goto exit;
  399.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  400.     }
  401.     SelectMaterial (mater2);
  402.     for (i = 0; i < 3 * animate_length; i ++) {
  403.         MoveViewer3D (VL_CURRENT, 0, 5, 0, TRUE);
  404.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  405.         if (!Cube (hdc, 50, 50, 25))
  406.             goto exit;
  407.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  408.     }
  409.     SelectMaterial (mater3);
  410.     for (i = 0; i < 3 * animate_length; i ++) {
  411.         MoveViewer3D (VL_CURRENT, 5, 0, 0, TRUE);
  412.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  413.         if (!Cube (hdc, 50, 50, 25))
  414.             goto exit;
  415.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  416.     }
  417.     SelectMaterial (mater0);
  418.     for (i = 0; i < 5 * animate_length; i ++) {
  419.         RotateViewer3D (VL_CURRENT, 6, 'z', FALSE);
  420.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  421.         if (!Cube (hdc, 50, 50, 25))
  422.             return;
  423.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  424.     }
  425.     SelectMaterial (mater1);
  426.     for (i = 0; i < 5 * animate_length; i ++) {
  427.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  428.         RotateViewer3D (VL_CURRENT, 6, 'y', FALSE);
  429.         if (!Cube (hdc, 50, 50, 25))
  430.             goto exit;
  431.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  432.     }
  433.     SelectMaterial (mater2);
  434.     for (i = 0; i < 5 * animate_length; i ++) {
  435.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  436.         RotateViewer3D (VL_CURRENT, 6, 'x', FALSE);
  437.         if (!Cube (hdc, 50, 50, 25))
  438.             goto exit;
  439.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  440.     }
  441. exit:
  442.     EndDoubleBuffer (&hdc, VL_CURRENT);
  443.     SetViewerName (VL_CURRENT, "Viewer Motion");
  444. }
  445.  
  446. void    ObjectMotion3D (HDC hdc)
  447. {
  448.     short   i;
  449.  
  450.     if (!viewer32)
  451.         return;
  452.  
  453.     SelectViewer (viewer32);
  454.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  455.     SelectMaterial (mater1);
  456.     for (i = 0; i <= 5 * animate_length; i ++) {
  457.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  458.         if (!Cylinder (hdc, 30, 40, 50))
  459.             break;
  460.         Rotate3D (3, 'z');
  461.         Rotate3D (6, 'x');
  462.         Rotate3D (3, 'y');
  463.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  464.     }
  465.     EndDoubleBuffer (&hdc, VL_CURRENT);
  466.     SetViewerName (VL_CURRENT, "Object Motion");
  467. }
  468.  
  469. void    ViewerZoom3D (HDC hdc)
  470. {
  471.     short   i;
  472.     POINT3D p = {0, 0, 0};
  473.  
  474.     SelectViewer (viewer33);
  475.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  476.     SelectMaterial (mater2);
  477.     for (i = 0; i < 5 * animate_length; i ++) {
  478.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  479.         if (!Cone (hdc, 3, 5, 10))
  480.             break;
  481.         ZoomViewer3D (VL_CURRENT, 1.05f);
  482.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  483.     }
  484.     EndDoubleBuffer (&hdc, VL_CURRENT);
  485.     SetViewerName (VL_CURRENT, "Viewer Zoom");
  486. }
  487.  
  488. void    RotateStar (HDC hdc)
  489. {
  490.     short   i;
  491.  
  492.     if (!viewer35)
  493.         return;
  494.     SelectViewer (viewer35);
  495.  
  496.     SelectMaterial (mater1);
  497.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  498.     for (i = 0; i < 5 * animate_length; i ++) {
  499.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  500.         if (!SolidStar (hdc, 5, 20, 20, 5))
  501.             break;
  502.         MoveViewer3D (VL_CURRENT, 0, 0, -0.5f, TRUE);
  503.         Rotate3D (6 * i, 'z');
  504.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  505.     }
  506.     EndDoubleBuffer (&hdc, VL_CURRENT);
  507.     SetViewerName (VL_CURRENT, "Rotate Star");
  508. }
  509.  
  510. void    Object3D (HDC hdc)
  511. {
  512.     short   i;
  513.  
  514.     SelectViewer (viewer31);
  515.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  516.     Scale3D (20, 20, 20);
  517.     for (i = 0; i < 5 * animate_length; i ++) {
  518.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  519.         PenColor (hdc, VL_GREEN);
  520.         Spring (hdc, 3, 2, 0.5f);
  521.         PenColor (hdc, VL_NONE);
  522.         Translate3D (0.05f, 0, 0);
  523.         Rotate3D (-6, 'y');
  524.         PushTransformation3D (NULL);
  525.         SelectMaterial (mater3);
  526.         Rotate3D (6 * i, 'z');
  527.         Translate3D (0, 2, 0);
  528.         Rotate3D (3, 'y');
  529.         if (!Tetrahedron (hdc, 1))
  530.             break;
  531.         PushTransformation3D (NULL);
  532.         SelectMaterial (mater1);
  533.         Rotate3D (6, 'x');
  534.         Translate3D (0, 0, 2);
  535.         Rotate3D (3 * i, 'z');
  536.         if (!Octahedron (hdc, 1))
  537.             break;
  538.         PopTransformation3D (NULL);
  539.         PopTransformation3D (NULL);
  540.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  541.     }
  542.     EndDoubleBuffer (&hdc, VL_CURRENT);
  543.     SetViewerName (VL_CURRENT, "3D Curve");
  544. }
  545.  
  546. void    RotateFrame (HDC hdc)
  547. {
  548.     short   i;
  549.     COORD    point[] = {0, 0, 0, 1, 1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1,
  550.         1, -1, -1, 1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1,
  551.         -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, 1,
  552.         0, 0, 0, 1, -1, 1, -1, -1, -1, 0, 0, 0};
  553.     
  554.     if (!viewer32)
  555.         return;
  556.     SelectViewer (viewer32);
  557.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  558.     Scale3D (30, 30, 30);
  559.     PenColor (hdc, VL_BLUE);
  560.     for (i = 0; i < 5 * animate_length; i++) {
  561.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  562.         Polyline3D (hdc, VL_3D, point, 19);
  563.         Rotate3D (6, 'z');
  564.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  565.     }
  566.     EndDoubleBuffer (&hdc, VL_CURRENT);
  567.     SetViewerName (VL_CURRENT, "Rotate Frame");
  568. }
  569.  
  570. void    RotateSurface (HDC hdc)
  571. {
  572.     short   i;
  573.  
  574.     if (!viewer35)
  575.         return;
  576.  
  577.     SelectViewer (viewer35);
  578.     SetViewerName (VL_CURRENT, "NURBS Surface");
  579.     SelectMaterial (mater2);
  580.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  581.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, TRUE);
  582.     for (i = 0; i < 5 * animate_length; i++) {
  583.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  584.         if (!NURBSSurface (hdc, VL_3D, (LPCOORD) surf, 4, 4, sknot, tknot, 8, 8))
  585.             break;
  586.         Rotate3D (6, 'z');
  587.         Rotate3D (12, 'x');
  588.         Rotate3D (3, 'y');
  589.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  590.     }
  591.     EndDoubleBuffer (&hdc, VL_CURRENT);
  592. }
  593.  
  594. void    RotateDodecahedron (HDC hdc)
  595. {
  596.     short   i;
  597.  
  598.     SelectViewer (viewer33);
  599.     SetViewerName (VL_CURRENT, "Dodecahedron");
  600.     SelectMaterial (mater2);
  601.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  602.     Scale3D (6, 6, 6);
  603.     for (i = 0; i < 5 * animate_length; i ++) {
  604.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  605.         if (!Dodecahedron (hdc, 0.5f))
  606.             break;
  607.         Translate3D (0, 0.1f, 0);
  608.         Rotate3D (6, 'z');
  609.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  610.     }
  611.     EndDoubleBuffer (&hdc, VL_CURRENT);
  612. }
  613.  
  614. void    RotateIcosahedron (HDC hdc)
  615. {
  616.     short   i;
  617.  
  618.     if (!viewer34)
  619.         return;
  620.     SelectViewer (viewer34);
  621.     SetViewerName (VL_CURRENT, "Icosahedron");
  622.     SelectMaterial (mater1);
  623.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  624.     Scale3D (3, 3, 3);
  625.     for (i = 0; i < 5 * animate_length; i ++) {
  626.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  627.         if (!Icosahedron (hdc, 1))
  628.             break;
  629.         Rotate3D (3, 'y');
  630.         Translate3D (0.1f, 0, 0);
  631.         Rotate3D (6, 'z');
  632.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  633.     }
  634.     EndDoubleBuffer (&hdc, VL_CURRENT);
  635. }
  636.  
  637. void    AnimationDemo (HDC hdc, WORD cmd)
  638. {
  639.     short    depthbuffer, shadingmethod, twosideshade, backfaceremoval;
  640.     BOOL    l0, l1, l2, l3;
  641.  
  642.     l0 = SwitchLight (light0, FALSE);
  643.     l1 = SwitchLight (light1, FALSE);
  644.     l2 = SwitchLight (light2, FALSE);
  645.     l3 = SwitchLight (light3, FALSE);
  646.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  647.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  648.     twosideshade = ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  649.     backfaceremoval = ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  650.     SwitchLight (light7, TRUE);
  651.     SwitchLight (light8, TRUE);
  652.     PenColor (hdc, VL_NONE);
  653.     switch (cmd) {
  654.         case IDM_ANIMATE_FRAME:
  655.             animate_length = 10;
  656.             RotateFrame (hdc);
  657.             break;
  658.         case IDM_ANIMATE_OBJECT2D:
  659.             animate_length = 10;
  660.             ObjectMotion2D (hdc);
  661.             break;
  662.         case IDM_ANIMATE_SURFACE:
  663.             animate_length = 10;
  664.             RotateSurface (hdc);
  665.             break;
  666.         case IDM_ANIMATE_ICOSAHEDRON:
  667.             animate_length = 10;
  668.             RotateIcosahedron (hdc);
  669.             break;
  670.         case IDM_ANIMATE_OBJECT3D:
  671.             animate_length = 20;
  672.             Object3D (hdc);
  673.             break;
  674.         case IDM_ANIMATE_STAR3D:
  675.             animate_length = 15;
  676.             RotateStar (hdc);
  677.             break;
  678.         case IDM_ANIMATE_DODECAHEDRON:
  679.             animate_length = 15;
  680.             RotateDodecahedron (hdc);
  681.             break;
  682.         case IDM_ANIMATE_VIEWER3D:
  683.             animate_length = 7;
  684.             ViewerMotion3D (hdc);
  685.             break;
  686.         case IDM_ANIMATE_ZOOM3D:
  687.             animate_length = 15;
  688.             ViewerZoom3D (hdc);
  689.             break;
  690.     }
  691.     SwitchLight (light7, FALSE);
  692.     SwitchLight (light8, FALSE);
  693.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  694.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  695.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, twosideshade);
  696.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, backfaceremoval);
  697.     SwitchLight (light0, l0);
  698.     SwitchLight (light1, l1);
  699.     SwitchLight (light2, l2);
  700.     SwitchLight (light3, l3);
  701. }
  702.  
  703. void CompositeDemo2D (HDC hdc)
  704. {
  705.     RECT    orgport, newport;
  706.  
  707.     SelectViewer (viewer22);
  708.     SetViewerName (VL_CURRENT, "Flag");
  709.     GetViewport (VL_CURRENT, &orgport);
  710.     SetRect (&newport, 350, 230, 410, 260);
  711.     SetViewport (VL_CURRENT, newport);
  712.     USFlag (hdc);
  713.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  714.     DisplayViewerName (hdc, VL_CURRENT, 0);
  715.     SetViewport (VL_CURRENT, orgport);
  716.     USFlag (hdc);
  717. }
  718.  
  719. void    Surfaces (HDC hdc, WORD cmd)
  720. {
  721.     short    twosideshade;
  722.  
  723.     SelectViewer (viewer30);
  724.     ClearDepthBuffer (0xffff);
  725.     twosideshade = ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, TRUE);
  726.     PenColor (hdc, VL_NONE);
  727.  
  728.     PushTransformation3D (NULL);
  729.     switch (cmd) {
  730.         case IDM_SURFACE_BEZIER:
  731.         {
  732.             POINT3D surf[16] = {
  733.                 {0, 6, 3}, {2, 6, 0}, {4, 6, 2}, {6, 6, 0},
  734.                 {0, 4, 0}, {2, 4, 5}, {4, 4, 0}, {6, 4, 6},
  735.                 {0, 2, 5}, {2, 2, 0}, {4, 2, 6}, {6, 2, 0},
  736.                 {0, 0, 0}, {2, 0, 3}, {4, 0, 0}, {6, 0, 3}};
  737.  
  738.             Scale3D (5, 5, 5);
  739.             BezierSurface (hdc, VL_3D, (LPCOORD) surf, 16, 16);
  740.             PenColor (hdc, VL_GREEN);
  741.             Net3D (hdc, VL_3D, (LPCOORD) surf, 4, 4);
  742.             PolyMark3D (hdc, VL_3D, (LPCOORD) surf, 16, 2, 2, VL_CIRCLEMARK);
  743.             SetViewerName (VL_CURRENT, "Bezier Surface");
  744.             break;
  745.         }
  746.         case IDM_SURFACE_HERMIT:
  747.         {
  748.             POINT3D surf[16] = {
  749.                 {0, 0, 0}, {0, 6, 0}, {0, 6, 6}, {0, 6, -2},
  750.                 {6, 0, 0}, {6, 6, 0}, {0, 2, 2}, {0, 6, -2},
  751.                 {2, 0, 2}, {2, 0, 2}, {0, 0, 0}, {0, 0, 0},
  752.                 {2, 0, 2}, {2, 0, 2}, {0, 0, 0}, {0, 0, 0}};
  753.  
  754.             Scale3D (5, 5, 5);
  755.             HermitSurface (hdc, VL_3D, (LPCOORD) surf, 16, 16);
  756.             SetViewerName (VL_CURRENT, "Hermit Surface");
  757.             break;
  758.         }
  759.         case IDM_SURFACE_BSPLINE:
  760.         {
  761.             POINT3D surf[36] = {
  762.                 {0,0,0},{1,0,0},{2,0,0},{3,0,0},{4,0,0},{5,0,0},
  763.                 {0,1,0},{1,1,0},{2,1,0},{3,1,0},{4,1,0},{5,1,0},
  764.                 {0,2,0},{1,2,0},{2,2,9},{3,2,9},{4,2,0},{5,2,0},
  765.                 {0,3,0},{1,3,0},{2,3,9},{3,3,9},{4,3,0},{5,3,0},
  766.                 {0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0},{5,4,0},
  767.                 {0,5,0},{1,5,0},{2,5,0},{3,5,0},{4,5,0},{5,5,0}};
  768.  
  769.             Scale3D (3, 3, 3);
  770.             BSplineSurface (hdc, VL_3D, (LPCOORD) surf, 6, 6, 4, 4);
  771.             SetViewerName (VL_CURRENT, "B-Spline Surface");
  772.             break;
  773.         }
  774.         case IDM_SURFACE_NURBS:
  775.         {
  776.             POINT3D surf[36] = {
  777.                 {0,0,0},{1,0,0},{2,0,0},{3,0,0},{4,0,0},{5,0,0},
  778.                 {0,1,0},{1,1,0},{2,1,0},{3,1,0},{4,1,0},{5,1,0},
  779.                 {0,2,0},{1,2,0},{2,2,9},{3,2,9},{4,2,0},{5,2,0},
  780.                 {0,3,0},{1,3,0},{2,3,9},{3,3,9},{4,3,0},{5,3,0},
  781.                 {0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0},{5,4,0},
  782.                 {0,5,0},{1,5,0},{2,5,0},{3,5,0},{4,5,0},{5,5,0}};
  783.             REAL    sknot[20] = {0,0,0,1,2,3,3,3};
  784.             REAL    tknot[20] = {0,0,0,1,2,3,3,3};
  785.  
  786.             Scale3D (10, 10, 5);
  787.             Translate3D (-3, -2, 0);
  788.             NURBSSurface (hdc, VL_3D, (LPCOORD) surf, 6, 6, sknot, tknot, 4, 4);
  789.             PenColor (hdc, VL_GREEN);
  790.             Net3D (hdc, VL_3D, (LPCOORD) surf, 6, 6);
  791.             PolyMark3D (hdc, VL_3D, (LPCOORD) surf, 36, 2, 2, VL_BOXMARK);
  792.             SetViewerName (VL_CURRENT, "NURBS Surface");
  793.             break;
  794.         }
  795.         case IDM_SURFACE_COONSPATCH:
  796.         {
  797.             POINT3D    point[] = {{0,0,4},{1,-2,3},{2,-2,2},{3,0,1},
  798.                                {4,0,0},{4,1,0},{4,2,0},{4,3,0},
  799.                                {4,4,0},{3,4,0},{2,4,0},{1,4,0},
  800.                                {0,4,0},{0,3,1},{-2,2,2},{-2,1,3}};
  801.             Scale3D (5, 5, 5);
  802.             CoonsPatch (hdc, VL_3D, (LPCOORD) point, 5, 5);
  803.             SetViewerName (VL_CURRENT, "Coons Patch Surface");
  804.             break;
  805.         }
  806.     }
  807.     PopTransformation3D (NULL);
  808.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, twosideshade);
  809. }
  810.  
  811. void    PolyfacetsDemo (HDC hdc)
  812. {
  813.     POLYFACET    polyfacet;
  814.     LPWIRE        wire;
  815.     LPFACET        facet;
  816.     LPINT        vindex, nindex;
  817.     LPVECT3        normal;
  818.     short        i;
  819.     LPPOINT3D    vertex;
  820.  
  821.     polyfacet.nvert = 8;
  822.     polyfacet.nnorm = 4;
  823.     polyfacet.nwire = 12;
  824.     polyfacet.nfacet = 6;
  825.     polyfacet.vertex = NEWLIST (POINT3D, polyfacet.nvert);
  826.     wire = polyfacet.wire = NEWLIST (WIRE, polyfacet.nwire);
  827.     facet = polyfacet.facet = NEWLIST (FACET, polyfacet.nfacet);
  828.     normal = polyfacet.normal = NEWLIST (VECTOR3, 4);
  829.     VSET3 (normal[0], 0.6f, -0.8f, 0);
  830.     VSET3 (normal[1], 0.6f, 0.8f, 0);
  831.     VSET3 (normal[2], 0, 0.6f, 0.8f);
  832.     VSET3 (normal[3], 0, 0.6f, -0.8f);
  833.     vertex = polyfacet.vertex;
  834.     SetPoint3D (&vertex[0], 0, 0, 20);
  835.     SetPoint3D (&vertex[1], 20, 0, 20);
  836.     SetPoint3D (&vertex[2], 20, 20, 20);
  837.     SetPoint3D (&vertex[3], 0, 20, 20);
  838.     SetPoint3D (&vertex[4], 0, 0, 0);
  839.     SetPoint3D (&vertex[5], 20, 0, 0);
  840.     SetPoint3D (&vertex[6], 20, 20, 0);
  841.     SetPoint3D (&vertex[7], 0, 20, 0);
  842.     wire[3].vert2 = wire[0].vert1 = wire[4].vert1 = 0;
  843.     wire[0].vert2 = wire[1].vert1 = wire[5].vert1 = 1;
  844.     wire[1].vert2 = wire[2].vert1 = wire[6].vert1 = 2;
  845.     wire[2].vert2 = wire[3].vert1 = wire[7].vert1 = 3;
  846.     wire[11].vert2 = wire[4].vert2 = wire[8].vert1 = 4;
  847.     wire[8].vert2 = wire[5].vert2 = wire[9].vert1 = 5;
  848.     wire[9].vert2 = wire[6].vert2 = wire[10].vert1 = 6;
  849.     wire[10].vert2 = wire[7].vert2 = wire[11].vert1 = 7;
  850.     facet[0].npts = facet[1].npts = facet[2].npts = facet[3].npts = 4;
  851.     facet[4].npts = facet[5].npts = 4;
  852.     facet[0].nindex = facet[1].nindex = facet[4].nindex = facet[5].nindex = 0;
  853.     nindex = facet[2].nindex = NEWLIST (int, 4);
  854.     VSET4 (nindex, 0, 0, 1, 1);
  855.     nindex = facet[3].nindex = NEWLIST (int, 4);
  856.     VSET4 (nindex, 2, 3, 3, 2);
  857.     vindex = facet[0].vindex = NEWLIST (int, 4);
  858.     VSET4 (vindex, 0, 1, 2, 3);
  859.     VSET3 (facet[0].normal, 0, 0, 1);
  860.     vindex = facet[1].vindex = NEWLIST (int, 4);
  861.     VSET4 (vindex, 0, 4, 5, 1);
  862.     VSET3 (facet[1].normal, 0, -1, 0);
  863.     vindex = facet[2].vindex = NEWLIST (int, 4);
  864.     VSET4 (vindex, 1, 5, 6, 2);
  865.     VSET3 (facet[2].normal, 1, 0, 0);
  866.     vindex = facet[3].vindex = NEWLIST (int, 4);
  867.     VSET4 (vindex, 2, 6, 7, 3);
  868.     VSET3 (facet[3].normal, 0, 1, 0);
  869.     vindex = facet[4].vindex = NEWLIST (int, 4);
  870.     VSET4 (vindex, 3, 7, 4, 0);
  871.     VSET3 (facet[4].normal, -1, 0, 0);
  872.     vindex = facet[5].vindex = NEWLIST (int, 4);
  873.     VSET4 (vindex, 4, 7, 6, 5);
  874.     VSET3 (facet[5].normal, 0, 0, -1);
  875.  
  876.     ClearDepthBuffer (0xffff);
  877.     SelectMaterial (mater2);
  878.     SwitchLight (light7, TRUE);
  879.     SwitchLight (light8, TRUE);
  880.     ShadePolyFacet (hdc, &polyfacet);
  881.     for (i = 0; i < polyfacet.nfacet; i++) {
  882.         _ffree (facet[i].vindex);
  883.         if (facet[i].nindex)
  884.             _ffree (facet[i].nindex);
  885.             
  886.     }
  887.     _ffree (polyfacet.vertex);
  888.     _ffree (polyfacet.normal);
  889.     _ffree (polyfacet.wire);
  890.     _ffree (polyfacet.facet);
  891. }
  892.  
  893. VOIDED    ShowSolidPrimitives (HDC hdc, WORD cmd)
  894. {
  895.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  896.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  897.     ClearDepthBuffer (0xffff);
  898.     PenColor (hdc, VL_NONE);
  899.     switch (cmd) {
  900.         case IDM_SOLID_TUBE:
  901.             SetViewerName (VL_CURRENT, "Tube and Ring");
  902.             Tube (hdc, 15, 20, 2, 30);
  903.             SolidRing (hdc, 40, 40, 3, 10, 115, 335, 1);
  904.             break;
  905.         case IDM_SOLID_TORUS:
  906.             SetViewerName (VL_CURRENT, "Torus and Wedged Torus");
  907.             TranslateTo3D (-20, 20, 0);
  908.             if (!Torus (hdc, 15, 5))
  909.                 break;
  910.             TranslateTo3D (20, -20, 0);
  911.             WedgedTorus (hdc, 15, 5, 90, 360, 180, 90);
  912.             break;
  913.         case IDM_SOLID_SPHERE:
  914.             SetViewerName (VL_CURRENT, "Sphere and Wedged Sphere");
  915.             WedgedSphere (hdc, 20, 20, 30, 90, 0, 45, 135);
  916.             break;
  917.         case IDM_SOLID_ELLIPSOID:
  918.             SetViewerName (VL_CURRENT, "Ellipsoid");
  919.             Ellipsoid (hdc, 20, 40, 30);
  920.             break;
  921.         case IDM_SOLID_CYLINDER:
  922.             SetViewerName (VL_CURRENT, "Cylinder and Solid Pie");
  923.             if (!WedgedCylinder (hdc, 10, 20, 30, 0.7f, 90, 0))
  924.                 break;
  925.             TranslateTo3D (30, -30, 0);
  926.             if (!SolidPie (hdc, 20, 10, 5, 45, 180))
  927.                 break;
  928.             TranslateTo3D (-30, 30, 0);
  929.             SolidPie (hdc, 20, 10, 5, 180, 45);
  930.             break;
  931.         case IDM_SOLID_CONE:
  932.             SetViewerName (VL_CURRENT, "Cone and Wedged Cone");
  933.             if (!WedgedCone (hdc, 10, 20, 30, 90, 0))
  934.                 break;
  935.             TranslateTo3D (30, -30, 0);
  936.             if (!WedgedCone (hdc, 20, 10, 30, 110, 0))
  937.                 break;
  938.             TranslateTo3D (-30, 30, 0);
  939.             WedgedCone (hdc, 20, 10, 30, 180, 45);
  940.             break;
  941.         case IDM_SOLID_TETRAHEDRON:
  942.             SetViewerName (VL_CURRENT, "Tetrahedron (4 facets)");
  943.             Tetrahedron (hdc, 20);
  944.             MarkPosition3D (hdc, 0, 0, 0, 10, VL_CROSSHAIR);
  945.             break;
  946.         case IDM_SOLID_OCTAHEDRON:
  947.             SetViewerName (VL_CURRENT, "Octahedron (8 facets)");
  948.             Octahedron (hdc, 20);
  949.             MarkPosition3D (hdc, 0, 0, 0, 20, VL_ORIGIN);
  950.             break;
  951.         case IDM_SOLID_DODECAHEDRON:
  952.             SetViewerName (VL_CURRENT, "Dodecahedron (12 facets)");
  953.             Dodecahedron (hdc, 20);
  954.             MarkPosition3D (hdc, 0, 0, 0, 10, VL_ORIGIN);
  955.             break;
  956.         case IDM_SOLID_ICOSAHEDRON:
  957.             SetViewerName (VL_CURRENT, "Icosahedron (20 facets)");
  958.             Icosahedron (hdc, 20);
  959.             MarkPosition3D (hdc, 0, 0, 0, 10, VL_ORIGIN);
  960.             break;
  961.         case IDM_SOLID_FRUSTUM:
  962.             SetViewerName (VL_CURRENT, "Frustum");
  963.             Frustum (hdc, 20, 30, 10, 20, 20);
  964.             break;
  965.         case IDM_SOLID_RIDGE:
  966.             SetViewerName (VL_CURRENT, "Ridge");
  967.             Ridge (hdc, 20, 30, 10, 20);
  968.             break;
  969.         case IDM_SOLID_BOX:
  970.             SetViewerName (VL_CURRENT, "Box");
  971.             Cube (hdc, 40, 40, 20);
  972.             break;
  973.         case IDM_SOLID_STAR:
  974.             SetViewerName (VL_CURRENT, "Solid Star");
  975.             SolidStar (hdc, 5, 20, 20, 10);
  976.             break;
  977.         case IDM_SOLID_FLOWER:
  978.             SetViewerName (VL_CURRENT, "Solid Flower");
  979.             SolidFlower (hdc, 8, 0.666f, 30, 30, 10);
  980.             break;
  981.     }
  982. }
  983.  
  984. void    ShadingSettings (HWND hwnd, WORD cmd)
  985. {
  986.     COLORREF    color;
  987.  
  988.     switch (cmd) {
  989.         case IDM_OPTION_PREVIEW:
  990.         {
  991.             RECT rect = {50, 50, 100, 100};
  992.             HDC    hdc;
  993.  
  994.             SelectViewer (viewer30);
  995.             hdc = GetDC (hwnd);
  996.             ShadingPreview (hdc, &rect, 40, 173);
  997.             ReleaseDC (hwnd, hdc);
  998.             break;
  999.         }
  1000.         case IDM_GLOBAL_AMBIENT:
  1001.             color = ShadingColor (VL_CURRENT, VL_GLOBALAMBIENT, VL_INQUIRE);
  1002.             color = SelectColor (color);
  1003.             ShadingColor (VL_CURRENT, VL_GLOBALAMBIENT, color);
  1004.             break;
  1005.         case IDM_OPTION_BACKCOLOR:
  1006.         {
  1007.             HBRUSH    hbrush;
  1008.  
  1009.             backcolor = SelectColor (backcolor);
  1010.             hbrush = GetClassWord (hwnd, GCW_HBRBACKGROUND);
  1011.             DeleteObject (hbrush);
  1012.             hbrush = CreateSolidBrush (backcolor);
  1013.             SetClassWord (hwnd, GCW_HBRBACKGROUND, hbrush);
  1014.             InvalidateRect (hwnd, NULL, TRUE);
  1015.             UpdateWindow (hwnd);
  1016.             break;
  1017.         }
  1018.         case IDM_OPTION_REDRAW:
  1019.             InvalidateRect (hwnd, NULL, TRUE);
  1020.             UpdateWindow (hwnd);
  1021.             break;
  1022.         case IDM_OPTION_SHADEMODE:
  1023.             DialogBox (hInst, MAKEINTRESOURCE(DLGSHADING), hwnd, DlgShading);
  1024.             break;
  1025.         case IDM_SELECT_M1:
  1026.             SelectMaterial (mater0);
  1027.             DialogBox (hInst, MAKEINTRESOURCE(DLGMATERIAL), hwnd, DlgMaterial);
  1028.             break;
  1029.         case IDM_SELECT_M2:
  1030.             SelectMaterial (mater1);
  1031.             DialogBox (hInst, MAKEINTRESOURCE(DLGMATERIAL), hwnd, DlgMaterial);
  1032.             break;
  1033.         case IDM_SELECT_M3:
  1034.             SelectMaterial (mater2);
  1035.             DialogBox (hInst, MAKEINTRESOURCE(DLGMATERIAL), hwnd, DlgMaterial);
  1036.             break;
  1037.         case IDM_SELECT_M4:
  1038.             SelectMaterial (mater3);
  1039.             DialogBox (hInst, MAKEINTRESOURCE(DLGMATERIAL), hwnd, DlgMaterial);
  1040.             break;
  1041.         case IDM_SELECT_L1:
  1042.             SelectLight (light0);
  1043.             DialogBox (hInst, MAKEINTRESOURCE(DLGLIGHTSETUP), hwnd, DlgLightSetup);
  1044.             break;
  1045.         case IDM_SELECT_L2:
  1046.             SelectLight (light1);
  1047.             DialogBox (hInst, MAKEINTRESOURCE(DLGLIGHTSETUP), hwnd, DlgLightSetup);
  1048.             break;
  1049.         case IDM_SELECT_L3:
  1050.             SelectLight (light2);
  1051.             DialogBox (hInst, MAKEINTRESOURCE(DLGLIGHTSETUP), hwnd, DlgLightSetup);
  1052.             break;
  1053.         case IDM_SELECT_L4:
  1054.             SelectLight (light3);
  1055.             DialogBox (hInst, MAKEINTRESOURCE(DLGLIGHTSETUP), hwnd, DlgLightSetup);
  1056.             break;
  1057.         case IDM_OPTION_TEXTURE:
  1058.             DialogBox (hInst, MAKEINTRESOURCE(DLGTEXTURE), hwnd, DlgTexture);
  1059.             break;
  1060.     }
  1061. }
  1062.  
  1063. WORD    halign = TA_CENTER;
  1064. WORD    valign = TA_BASELINE;
  1065.  
  1066. VOIDED    ShowTextPrimitives (HDC hdc, int func)
  1067. {
  1068.     char    str[40];
  1069.  
  1070.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  1071.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  1072.     wsprintf (str, "Visualib\nAdvanced\nTechnology");
  1073.     switch (func) {
  1074.         case IDM_TEXT_2D:
  1075.             SelectViewer (viewer20);
  1076.             TextParameter (VL_TEXT_HEIGHT, 4);
  1077.             BrushColor (hdc, VL_RED);
  1078.             PenColor (hdc, VL_GREEN);
  1079.             SetTextAlign (hdc, halign | valign);
  1080.             Text2D (hdc, 0, 0, 0, str);
  1081.             SetViewerName (VL_CURRENT, "2D Horizontal Text");
  1082.             break;
  1083.         case IDM_TEXT_3D:
  1084.             SelectViewer (viewer30);
  1085.             MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1086.             PushTransformation3D (NULL);
  1087.             TextParameter (VL_TEXT_HEIGHT, 15);
  1088.             BrushColor (hdc, VL_YELLOW);
  1089.             PenColor (hdc, VL_BLUE);
  1090.             SetTextAlign (hdc, TA_LEFT | TA_BOTTOM);
  1091.             Text3D (hdc, 3, 1, 0, str);
  1092.             PushTransformation3D (NULL);
  1093.             Rotate3D (90, 'y');
  1094.             SetTextAlign (hdc, TA_RIGHT | TA_BOTTOM);
  1095.             Text3D (hdc, -3, 1, 0, str);
  1096.             PopTransformation3D (NULL);
  1097.             Rotate3D (-90, 'x');
  1098.             SetTextAlign (hdc, TA_TOP | TA_LEFT);
  1099.             Text3D (hdc, 3, -1, 0, str);
  1100.             PopTransformation3D (NULL);
  1101.             SetViewerName (VL_CURRENT, "3D Horizontal Text");
  1102.             break;
  1103.         case IDM_TEXT_SOLID:
  1104.             SelectViewer (viewer30);
  1105.             TextParameter (VL_TEXT_HEIGHT, 30);
  1106.             ClearDepthBuffer (0xffff);
  1107.             TextParameter (VL_TEXT_THICKNESS, 8);
  1108.             PushTransformation3D (NULL);
  1109.             Rotate3D (135, 'z');
  1110.             Rotate3D (30, 'x');
  1111.             SetTextAlign (hdc, TA_BASELINE | TA_CENTER);
  1112.             SolidText (hdc, str);
  1113.             PopTransformation3D (NULL);
  1114.             SetViewerName (VL_CURRENT, "Solid Text");
  1115.             break;
  1116.     }
  1117.     SelectObject (hdc, GetStockObject (SYSTEM_FONT));
  1118. }
  1119.  
  1120. void    ProcessWindowPaint (HWND hwnd)
  1121. {
  1122.     PAINTSTRUCT ps;
  1123.     HDC         hdc;
  1124.  
  1125.     hdc = BeginPaint (hwnd, &ps);
  1126.     if (hpal) {
  1127.         SelectPalette (hdc, hpal, FALSE);
  1128.         RealizePalette (hdc);
  1129.     }
  1130.     FunctionDemos (hdc);
  1131.     EndPaint (hwnd, &ps);
  1132. }
  1133.  
  1134. void    SpotlightDemo (HDC hdc)
  1135. {
  1136.     SelectViewer (viewer30);
  1137.     SetViewerName (VL_CURRENT, "Spot Lights Demo");
  1138.     ClearDepthBuffer (0xffff);
  1139.     SelectMaterial (mater0);
  1140.     SwitchLight (light4, TRUE);
  1141.     SwitchLight (light5, TRUE);
  1142.     SwitchLight (light6, TRUE);
  1143.     SolidFlower (hdc, 8, 0.666f, 30, 30, 10);
  1144. }
  1145.  
  1146. void    ImageMappingDemo (HDC hdc)
  1147. {
  1148.     COORD    point[12];
  1149.     static BOOL    LoadImage = TRUE;
  1150.  
  1151.     if (LoadImage) {
  1152.         if (GetDeviceCaps (hdc, BITSPIXEL) >= 8) {
  1153.             if (!ReadDIBFile ("deer256.bmp", &hdib1) ||
  1154.                 !ReadDIBFile ("deer256.bmp", &hdib2))
  1155.                 return;
  1156.         }
  1157.         else {
  1158.             if (!ReadDIBFile ("bring16.bmp", &hdib1) ||
  1159.                 !ReadDIBFile ("bring16.bmp", &hdib2))
  1160.                 return;
  1161.         }
  1162.         if (!ReadDIBFile ("c:\\windows\\system\\vgalogo.rle", &hdib3))
  1163.             return;
  1164.         LoadImage = FALSE;
  1165.     }
  1166.  
  1167.     SelectViewer (viewer30);
  1168.     SetViewerName (VL_CURRENT, "Image Mapping");
  1169.     Scale3D (20, 20, 30);
  1170.  
  1171.     point[0] = -1; point[1] = -1; point[2] = 1;
  1172.     point[3] = 1; point[4] = -1; point[5] = 1;
  1173.     point[6] = 1; point[7] = 1; point[8] = 1;
  1174.     point[9] = -1; point[10] = 1; point[11] = 1;
  1175.     if (hdib1) {
  1176.         if (!ImageMap3D (hdc, hdib1, VL_3D, point))
  1177.             return;
  1178.     }
  1179.  
  1180.     point[0] = 1; point[1] = 1; point[2] = 1;
  1181.     point[3] = 1; point[4] = 1; point[5] = -1;
  1182.     point[6] = -1; point[7] = 1; point[8] = -1;
  1183.     point[9] = -1; point[10] = 1; point[11] = 1;
  1184.     if (hdib2) {
  1185.         if (!ImageMap3D (hdc, hdib2, VL_3D, point))
  1186.             return;
  1187.     }
  1188.  
  1189.     point[0] = 1; point[1] = -1; point[2] = -1;
  1190.     point[3] = 1; point[4] = 1; point[5] = -1;
  1191.     point[6] = 1; point[7] = 1; point[8] = 1;
  1192.     point[9] = 1; point[10] = -1; point[11] = 1;
  1193.     if (hdib3) {
  1194.         ImageMap3D (hdc, hdib3, VL_3D, point);
  1195.     }
  1196. }
  1197.  
  1198. void    TranslateTransf2D (HDC hdc)
  1199. {
  1200.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1201.     SetViewerName (VL_CURRENT, "2D Translate Transformation");
  1202.     BrushColor (hdc, VL_RED);
  1203.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1204.     Label2D (hdc, 0, 0, "Original");
  1205.     TranslateTo2D (5, 3);
  1206.     BrushColor (hdc, VL_GREEN);
  1207.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1208.     Label2D (hdc, 0, 0, "Translated To (5,3)");
  1209.     PushTransformation2D (NULL);
  1210.     Translate2D (0, -6);
  1211.     BrushColor (hdc, VL_YELLOW);
  1212.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1213.     Label2D (hdc, 0, 0, "Translated (0,-6) from above");
  1214.     PopTransformation2D (NULL);
  1215.     Translate2D (-10, 0);
  1216.     BrushColor (hdc, VL_BLUE);
  1217.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1218.     Label2D (hdc, 0, 0, "Translated (-10,0) from right");
  1219.     Translate2D (0, -6);
  1220.     BrushColor (hdc, VL_WHITE);
  1221.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1222.     Label2D (hdc, 0, 0, "Translated (0,-6) from above");
  1223. }
  1224.  
  1225. void    MirrorTransf2D (HDC hdc)
  1226. {
  1227.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1228.     SetViewerName (VL_CURRENT, "2D Mirror Transformation");
  1229.     BrushColor (hdc, VL_RED);
  1230.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1231.     Label2D (hdc, 5, 3, "Original");
  1232.     PushTransformation2D (NULL);
  1233.     Mirror2D (0, 0, 0);
  1234.     BrushColor (hdc, VL_GREEN);
  1235.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1236.     Label2D (hdc, 5, 3, "Mirrored along (0,0) with 0 degree");
  1237.     PopTransformation2D (NULL);
  1238.     PushTransformation2D (NULL);
  1239.     Mirror2D (0, 0, 90);
  1240.     BrushColor (hdc, VL_YELLOW);
  1241.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1242.     Label2D (hdc, 5, 3, "Mirrored along (0,0) with 90 degree");
  1243.     PopTransformation2D (NULL);
  1244.     PushTransformation2D (NULL);
  1245.     Mirror2D (0, 0, (REAL)(atan2 (-5, 3) * RTOD));
  1246.     BrushColor (hdc, VL_BLUE);
  1247.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1248.     Label2D (hdc, 5, 3, "Mirrored along (0,0) with radian (-5,3)");
  1249.     PopTransformation2D (NULL);
  1250. }
  1251.  
  1252. void    StretchTransf2D (HDC hdc)
  1253. {
  1254.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1255.     SetViewerName (VL_CURRENT, "2D Stretch Transformation");
  1256.     BrushColor (hdc, VL_RED);
  1257.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1258.     Label2D (hdc, 0, 0, "Original");
  1259.     PushTransformation2D (NULL);
  1260.     Stretch2D (5, 3, 0, 1.5f);
  1261.     BrushColor (hdc, VL_GREEN);
  1262.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1263.     Label2D (hdc, 5, 3, "Stretched along 0 degree");
  1264.     PopTransformation2D (NULL);
  1265.     PushTransformation2D (NULL);
  1266.     Stretch2D (5, -3, 90, 1.5f);
  1267.     BrushColor (hdc, VL_YELLOW);
  1268.     Star2D (hdc, 5, -3, 0, 2, 2, 5);
  1269.     Label2D (hdc, 5, -3, "Stretched along 90 degree");
  1270.     PopTransformation2D (NULL);
  1271.     PushTransformation2D (NULL);
  1272.     Stretch2D (-5, -3, 45, 1.5f);
  1273.     BrushColor (hdc, VL_BLUE);
  1274.     Star2D (hdc, -5, -3, 0, 2, 2, 5);
  1275.     Label2D (hdc, -5, -3, "Stretched along 45 degree");
  1276.     PopTransformation2D (NULL);
  1277.     PushTransformation2D (NULL);
  1278.     Stretch2D (-5, 3, 45, -1.5f);
  1279.     BrushColor (hdc, VL_BROWN);
  1280.     Star2D (hdc, -5, 3, 0, 2, 2, 5);
  1281.     Label2D (hdc, -5, 3, "Stretched and flipped 45 degree");
  1282.     PopTransformation2D (NULL);
  1283. }
  1284.  
  1285. void    ShearTransf2D (HDC hdc)
  1286. {
  1287.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1288.     SetViewerName (VL_CURRENT, "2D Shear Transformation");
  1289.     BrushColor (hdc, VL_RED);
  1290.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1291.     Label2D (hdc, 0, 0, "Original");
  1292.     PushTransformation2D (NULL);
  1293.     Shear2D (5, 3, 0, 0.5f, 0);
  1294.     BrushColor (hdc, VL_GREEN);
  1295.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1296.     Label2D (hdc, 5, 3, "Horizontal shear");
  1297.     PopTransformation2D (NULL);
  1298.     PushTransformation2D (NULL);
  1299.     Shear2D (5, -3, 0, 0, 0.5f);
  1300.     BrushColor (hdc, VL_BLUE);
  1301.     Star2D (hdc, 5, -3, 0, 2, 2, 5);
  1302.     Label2D (hdc, 5, -3, "Vertical shear");
  1303.     PopTransformation2D (NULL);
  1304.     PushTransformation2D (NULL);
  1305.     Shear2D (-5, -3, 0, 0.5f, 0.5f);
  1306.     BrushColor (hdc, VL_YELLOW);
  1307.     Star2D (hdc, -5, -3, 0, 2, 2, 5);
  1308.     Label2D (hdc, -5, -3, "Horizontal and vertical shear");
  1309.     PopTransformation2D (NULL);
  1310.     PushTransformation2D (NULL);
  1311.     Shear2D (-5, 3, 45, 0.5f, 0);
  1312.     BrushColor (hdc, VL_BROWN);
  1313.     Star2D (hdc, -5, 3, 0, 2, 2, 5);
  1314.     Label2D (hdc, -5, 3, "Horizontal shear along 45 degree");
  1315.     PopTransformation2D (NULL);
  1316. }
  1317.  
  1318. void    PointRotateTransf2D (HDC hdc)
  1319. {
  1320.     SetTextAlign (hdc, TA_CENTER | TA_BOTTOM);
  1321.     Label2D (hdc, 5, 3, "(5,3)");
  1322.     SetTextAlign (hdc, TA_RIGHT | TA_BASELINE);
  1323.     Label2D (hdc, -5, 3, "(-5,3)");
  1324.     SetTextAlign (hdc, TA_CENTER | TA_TOP);
  1325.     Label2D (hdc, -5, -3, "(-5,-3)");
  1326.     SetTextAlign (hdc, TA_LEFT | TA_BASELINE);
  1327.     Label2D (hdc, 5, -3, "(5,-3)");
  1328.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1329.     SetViewerName (VL_CURRENT, "2D Point Ratate Transformation");
  1330.     PenColor (hdc, VL_WHITE);
  1331.     BrushColor (hdc, VL_RED);
  1332.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1333.     Label2D (hdc, 0, 0, "Original");
  1334.     Line2D (hdc, 5, 3, 0, 0);
  1335.     PushTransformation2D (NULL);
  1336.     PointRotate2D (5, 3, 90);
  1337.     BrushColor (hdc, VL_GREEN);
  1338.     Label2D (hdc, 0, 0, "Rotate 90 degree around (5,3)");
  1339.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1340.     LineTo2D (hdc, 0, 0);
  1341.     LineTo2D (hdc, 5, 3);
  1342.      PopTransformation2D (NULL);
  1343.     Line2D (hdc, -5, 3, 0, 0);
  1344.     PushTransformation2D (NULL);
  1345.     PointRotate2D (-5, 3, 45);
  1346.     BrushColor (hdc, VL_YELLOW);
  1347.     Label2D (hdc, 0, 0, "Rotate 45 degree around (-5,3)");
  1348.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1349.     LineTo2D (hdc, 0, 0);
  1350.     LineTo2D (hdc, -5, 3);
  1351.     PopTransformation2D (NULL);
  1352.     Line2D (hdc, 5, -3, 0, 0);
  1353.     PushTransformation2D (NULL);
  1354.     PointRotate2D (5, -3, 45);
  1355.     BrushColor (hdc, VL_BLUE);
  1356.     Label2D (hdc, 0, 0, "Rotate 45 degree around (5,-3)");
  1357.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1358.     LineTo2D (hdc, 0, 0);
  1359.     LineTo2D (hdc, 5, -3);
  1360.     PopTransformation2D (NULL);
  1361.     Line2D (hdc, -5, -3, 0, 0);
  1362.     PushTransformation2D (NULL);
  1363.     PointRotate2D (-5, -3, 90);
  1364.     BrushColor (hdc, VL_BROWN);
  1365.     Label2D (hdc, 0, 0, "Rotate 90 degree around (-5,-3)");
  1366.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1367.     LineTo2D (hdc, 0, 0);
  1368.     LineTo2D (hdc, -5, -3);
  1369.     PopTransformation2D (NULL);
  1370. }
  1371.  
  1372. void    PointScaleTransf2D (HDC hdc)
  1373. {
  1374.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1375.     BrushColor (hdc, VL_RED);
  1376.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1377.     Label2D (hdc, 5, 3, "Original");
  1378.     PushTransformation2D (NULL);
  1379.     PointScale2D (0, 0, -1, 1);
  1380.     BrushColor (hdc, VL_GREEN);
  1381.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1382.     Label2D (hdc, 5, 3, "Horizontal flipped");
  1383.     PopTransformation2D (NULL);
  1384.     PushTransformation2D (NULL);
  1385.     PointScale2D (0, 0, 1, -1);
  1386.     BrushColor (hdc, VL_BLUE);
  1387.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1388.     Label2D (hdc, 5, 3, "Vertical flipped");
  1389.     PopTransformation2D (NULL);
  1390.     PushTransformation2D (NULL);
  1391.     PointScale2D (0, 0, -1, -1);
  1392.     BrushColor (hdc, VL_YELLOW);
  1393.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1394.     Label2D (hdc, 5, 3, "Horizontal and vertical flipped");
  1395.     PopTransformation2D (NULL);
  1396. }
  1397.     
  1398. void    Transformation2D (HDC hdc, int func)
  1399. {
  1400.     SetROP2 (hdc, R2_XORPEN);
  1401.     TextColor (hdc, VL_WHITE, VL_BLACK, TRANSPARENT);
  1402.     PushTransformation2D (NULL);
  1403.     switch (func) {
  1404.         case IDM_2DTRANSF_TRANSLATE:
  1405.             TranslateTransf2D (hdc);
  1406.             break;
  1407.         case IDM_2DTRANSF_SCALE:
  1408.             break;
  1409.         case IDM_2DTRANSF_POINTSCALE:
  1410.             PointScaleTransf2D (hdc);
  1411.             break;
  1412.         case IDM_2DTRANSF_ROTATE:
  1413.             break;
  1414.         case IDM_2DTRANSF_POINTROTATE:
  1415.             PointRotateTransf2D (hdc);
  1416.             break;
  1417.         case IDM_2DTRANSF_STRETCH:
  1418.             StretchTransf2D (hdc);
  1419.             break;
  1420.         case IDM_2DTRANSF_SHEAR:
  1421.             ShearTransf2D (hdc);
  1422.             break;
  1423.         case IDM_2DTRANSF_MIRROR:
  1424.             MirrorTransf2D (hdc);
  1425.             break;
  1426.     }
  1427.     PopTransformation2D (NULL);
  1428. }
  1429.  
  1430. void    AxleRotateTransf3D (HDC hdc)
  1431. {
  1432.     short    i;
  1433.     VECTOR3    ref = {0, 0, 0}, dir;
  1434.     char    str[] = "Visualib";
  1435.  
  1436.     SetTextAlign(hdc, TA_LEFT | TA_BOTTOM);
  1437.     TextParameter (VL_TEXT_HEIGHT, 20);
  1438.     MarkPosition3D (hdc, 0, 0, 0, 20, VL_ORIGIN);
  1439.     BrushColor (hdc, VL_RED);
  1440.     Text3D (hdc, 15, 15, 0, str);
  1441.     VSET3 (dir, 1, 0, 0);
  1442.     for (i = 1; i < 4; i++) {
  1443.         PushTransformation3D (NULL);
  1444.         AxleRotate3D (ref, dir, i * 90);
  1445.         BrushColor (hdc, i+1);
  1446.         Text3D (hdc, 15, 15, 0, str);
  1447.         PopTransformation3D (NULL);
  1448.     }
  1449.     VSET3 (dir, 0, 1, 0);
  1450.     for (i = 1; i < 4; i++) {
  1451.         PushTransformation3D (NULL);
  1452.         AxleRotate3D (ref, dir, i * 90);
  1453.         BrushColor (hdc, i+4);
  1454.         Text3D (hdc, 15, 15, 0, str);
  1455.         PopTransformation3D (NULL);
  1456.     }
  1457.     VSET3 (dir, 1, -1, 0);
  1458.     for (i = 1; i < 4; i++) {
  1459.         PushTransformation3D (NULL);
  1460.         AxleRotate3D (ref, dir, i * 90);
  1461.         BrushColor (hdc, i+7);
  1462.         Text3D (hdc, 15, 15, 0, str);
  1463.         PopTransformation3D (NULL);
  1464.     }
  1465. }
  1466.  
  1467. void    StretchTransf3D (HDC hdc)
  1468. {
  1469.     VECTOR3    ref = {0, 0, 0}, dir;
  1470.  
  1471.     TextParameter (VL_TEXT_HEIGHT, 30);
  1472.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1473.     PushTransformation3D (NULL);
  1474.     VSET3 (dir, -1, 1, 1);
  1475.     Stretch3D (ref, dir, 1.5f);
  1476.     Cube (hdc, 20, 20, 20);
  1477.     MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1478.     PopTransformation3D (NULL);
  1479. }
  1480.  
  1481. void    ShearTransf3D (HDC hdc)
  1482. {
  1483.     VECTOR3    origin = {0, 0, 0}, normal = {0, 0, 1};
  1484.  
  1485.     TextParameter (VL_TEXT_HEIGHT, 30);
  1486.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1487.     PushTransformation3D (NULL);
  1488.     Shear3D (origin, normal, -0.5f, 0.5f);
  1489.     Cube (hdc, 20, 20, 20);
  1490.     MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1491.     PopTransformation3D (NULL);
  1492. }
  1493.  
  1494. void    MirrorTransf3D (HDC hdc)
  1495. {
  1496.     VECTOR3    ref = {0, 0, 0}, dir;
  1497.     char    str[] = "Visualib";
  1498.  
  1499.     MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1500.     SetViewerName (VL_CURRENT, "3D Mirror Transformation");
  1501.     SetTextAlign (hdc, TA_LEFT | TA_BOTTOM);
  1502.     TextParameter (VL_TEXT_HEIGHT, 20);
  1503.     BrushColor (hdc, VL_RED);
  1504.     Text3D (hdc, 3, 3, 0, str);
  1505.     PushTransformation3D (NULL);
  1506.     VSET3 (dir, 1, 0, 0);
  1507.     Mirror3D (ref, dir);
  1508.     BrushColor (hdc, VL_GREEN);
  1509.     Text3D (hdc, 3, 3, 0, str);
  1510.     PopTransformation3D (NULL);
  1511.     PushTransformation3D (NULL);
  1512.     VSET3 (dir, 0, 1, 0);
  1513.     Mirror3D (ref, dir);
  1514.     BrushColor (hdc, VL_YELLOW);
  1515.     Text3D (hdc, 3, 3, 0, str);
  1516.     PopTransformation3D (NULL);
  1517.     PushTransformation3D (NULL);
  1518.     VSET3 (dir, -1, -1, 0);
  1519.     Mirror3D (ref, dir);
  1520.     BrushColor (hdc, VL_BLUE);
  1521.     Text3D (hdc, 3, 3, 0, str);
  1522.     PopTransformation3D (NULL);
  1523. }
  1524.  
  1525. void    PointScaleTransf3D (HDC hdc)
  1526. {
  1527.     char    str[] = "Visualib";
  1528.  
  1529.     MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1530.     SetViewerName (VL_CURRENT, "3D PointScale Transformation");
  1531.     SetTextAlign (hdc, TA_LEFT | TA_BOTTOM);
  1532.     TextParameter (VL_TEXT_HEIGHT, 20);
  1533.     BrushColor (hdc, VL_RED);
  1534.     Text3D (hdc, 3, 3, 0, str);
  1535.     PushTransformation3D (NULL);
  1536.     PointScale3D (0, 0, 0, -1, 1, 1);
  1537.     BrushColor (hdc, VL_GREEN);
  1538.     Text3D (hdc, 3, 3, 0, str);
  1539.     PopTransformation3D (NULL);
  1540.     PushTransformation3D (NULL);
  1541.     PointScale3D (0, 0, 0, 1, -1, 1);
  1542.     BrushColor (hdc, VL_YELLOW);
  1543.     Text3D (hdc, 3, 3, 0, str);
  1544.     PopTransformation3D (NULL);
  1545.     PushTransformation3D (NULL);
  1546.     PointScale3D (0, 0, 0, -1, -1, 1);
  1547.     BrushColor (hdc, VL_BLUE);
  1548.     Text3D (hdc, 3, 3, 0, str);
  1549.     PopTransformation3D (NULL);
  1550. }
  1551.  
  1552. void    Transformation3D (HDC hdc, int func)
  1553. {
  1554.     TextColor (hdc, VL_WHITE, VL_BLACK, TRANSPARENT);
  1555.     ClearDepthBuffer (0xffff);
  1556.     switch (func) {
  1557.         case IDM_3DTRANSF_TRANSLATE:
  1558.             break;
  1559.         case IDM_3DTRANSF_SCALE:
  1560.             break;
  1561.         case IDM_3DTRANSF_POINTSCALE:
  1562.             PointScaleTransf3D (hdc);
  1563.             break;
  1564.         case IDM_3DTRANSF_ROTATE:
  1565.             break;
  1566.         case IDM_3DTRANSF_AXLEROTATE:
  1567.             AxleRotateTransf3D (hdc);
  1568.             break;
  1569.         case IDM_3DTRANSF_STRETCH:
  1570.             StretchTransf3D (hdc);
  1571.             break;
  1572.         case IDM_3DTRANSF_SHEAR:
  1573.             ShearTransf3D (hdc);
  1574.             break;
  1575.         case IDM_3DTRANSF_MIRROR:
  1576.             MirrorTransf3D (hdc);
  1577.             break;
  1578.     }
  1579. }
  1580.  
  1581. VOIDED    MaterialPropertyDemo (HDC hdc)
  1582. {
  1583.     short    i, j, n = 1;
  1584.     REAL    ks, kd, orgks, orgkd, orgn;
  1585.     RECT    rect;
  1586.  
  1587.     SwitchLight (light7, TRUE);
  1588.     SwitchLight (light8, TRUE);
  1589.     SelectViewer (viewer30);
  1590.     SetViewerName (VL_CURRENT, "Material Reflection Property");
  1591.     orgks = ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, VL_INQUIRE);
  1592.     orgkd = ShadingFactor (VL_CURRENT, VL_DIFFUSEREFLECT, VL_INQUIRE);
  1593.     orgn = ShadingFactor (VL_CURRENT, VL_SHININESS, VL_INQUIRE);
  1594.     rect.top = 10;
  1595.     ks = 0.1f;
  1596.     for (i = 0; i < 6; i++) {
  1597.         kd = 0.05f;
  1598.         rect.left = 10;
  1599.         rect.bottom = rect.top + 40;
  1600.         for (j = 0; j < 10; j++) {
  1601.             rect.right = rect.left + 40;
  1602.             ShadingFactor (VL_CURRENT, VL_SHININESS, n);
  1603.             ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, ks);
  1604.             ShadingFactor (VL_CURRENT, VL_DIFFUSEREFLECT, kd);
  1605.             if (!ShadingPreview (hdc, &rect, 5, 173))
  1606.                 goto exit;
  1607.             rect.left += 49;
  1608.             kd += 0.1f;
  1609.         }
  1610.         ks += 0.2f;
  1611.         rect.top += 53;
  1612.         n *= 2;
  1613.     }
  1614. exit:
  1615.     ShadingFactor (VL_CURRENT, VL_DIFFUSEREFLECT, orgkd);
  1616.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, orgks);
  1617.     ShadingFactor (VL_CURRENT, VL_SHININESS, orgn);
  1618. }
  1619.  
  1620. void    CompositeDemo3D (HDC hdc)
  1621. {
  1622.     static REAL    r0, r1, r2, t1, t2, h;
  1623.     short    i;
  1624.     BOOL    flag;
  1625.  
  1626.     SelectViewer (viewer30);
  1627.     SetViewerName (VL_CURRENT, "Object Composition");
  1628.     ClearDepthBuffer (0xffff);
  1629.     SwitchLight (light7, TRUE);
  1630.     SwitchLight (light8, TRUE);
  1631.     SelectMaterial (mater0);
  1632.     PushTransformation3D (NULL);
  1633.     r0 = 4; r1 = 30; r2 = 40;
  1634.     t1 = 3; t2 = 2; h = 10;
  1635.  
  1636.     if (!SolidRing (hdc, r2, r2, t2, h, 115, 335, 1))
  1637.         goto exit;
  1638.  
  1639.     PushTransformation3D (NULL);
  1640.     Translate3D (0, 0, h / 2);
  1641.     SelectMaterial (mater1);
  1642.     Rotate3D (135, 'z');
  1643.     for (i = 0; i < 10; i++) {
  1644.         PushTransformation3D (NULL);
  1645.         Translate3D (35, 0, 0);
  1646.         flag = Sphere (hdc, r0);
  1647.         PopTransformation3D (NULL);
  1648.         Rotate3D (20, 'z');
  1649.         if (!flag)
  1650.             goto exit;
  1651.     }
  1652.     PopTransformation3D (NULL);
  1653.     SelectMaterial (mater0);
  1654.     if (!Tube (hdc, r1, r1, t1, h))
  1655.         goto exit;
  1656.     PushTransformation3D (NULL);
  1657.     Translate3D (0, 0, h / 2);
  1658.     SelectMaterial (mater1);
  1659.     Rotate3D (-25, 'z');
  1660.     for (i = 0; i < 8; i++) {
  1661.         PushTransformation3D (NULL);
  1662.         Translate3D (35, 0, 0);
  1663.         flag = Sphere (hdc, r0);
  1664.         PopTransformation3D (NULL);
  1665.         Rotate3D (20, 'z');
  1666.         if (!flag)
  1667.             break;
  1668.     }
  1669.     PopTransformation3D (NULL);
  1670. exit:
  1671.     PopTransformation3D (NULL);
  1672. }
  1673.  
  1674. void    DepthClippingDemo (HDC hdc)
  1675. {
  1676.     SelectViewer (viewer30);
  1677.     SetPerspective (VL_CURRENT, 45, 1, 141, 200);
  1678.     ClearDepthBuffer (0xffff);
  1679.     SwitchLight (light7, TRUE);
  1680.     SwitchLight (light8, TRUE);
  1681.     SelectMaterial (mater1);
  1682.     TranslateTo3D (20, 0, 0);
  1683.     if (!Sphere (hdc, 20))
  1684.         goto exit;
  1685.     SelectMaterial (mater2);
  1686.     TranslateTo3D (0, 20, 0);
  1687.     if (!Sphere (hdc, 20))
  1688.         goto exit;
  1689.     SelectMaterial (mater3);
  1690.     TranslateTo3D (0, 0, 20);
  1691.     if (!Sphere (hdc, 20))
  1692.         return;
  1693.     TranslateTo3D (0, 0, 0);
  1694.     SelectMaterial (mater0);
  1695.     if (!Cube (hdc, 40, 40, 40))
  1696.         goto exit;
  1697.  exit:
  1698.     SetPerspective (VL_CURRENT, 45, 1, 30, 1000);
  1699.     SetViewerName (VL_CURRENT, "Depth Buffer and Clipping");
  1700. }
  1701.  
  1702. void    MarbleRingDemo (hdc)
  1703. {
  1704.     short    texture;
  1705.  
  1706.     SelectViewer (viewer30);
  1707.     SetViewerName (VL_CURRENT, "Marble Ring");
  1708.     ClearDepthBuffer (0xffff);
  1709.     SelectMaterial (mater3);
  1710.     texture = SolidTexture (VL_MARBLE);
  1711.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  1712.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, 1);
  1713.     SwitchLight (light7, TRUE);
  1714.     SwitchLight (light8, TRUE);
  1715.     Torus (hdc, 35, 5);
  1716.     SolidTexture (texture);
  1717. }
  1718.  
  1719. void    WoodSurfaceDemo (HDC hdc)
  1720. {
  1721.     short    texture;
  1722.     
  1723.     POINT3D surf[36] = {
  1724.         {0,0,0},{1,0,0},{2,0,0},{3,0,0},{4,0,0},{5,0,0},
  1725.         {0,1,0},{1,1,0},{2,1,0},{3,1,0},{4,1,0},{5,1,0},
  1726.         {0,2,0},{1,2,0},{2,2,9},{3,2,9},{4,2,0},{5,2,0},
  1727.         {0,3,0},{1,3,0},{2,3,9},{3,3,9},{4,3,0},{5,3,0},
  1728.         {0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0},{5,4,0},
  1729.         {0,5,0},{1,5,0},{2,5,0},{3,5,0},{4,5,0},{5,5,0}};
  1730.     REAL    sknot[20] = {0,0,0,1,2,3,3,3};
  1731.     REAL    tknot[20] = {0,0,0,1,2,3,3,3};
  1732.  
  1733.     SelectViewer (viewer30);
  1734.     SetViewerName (VL_CURRENT, "Wood Surface");
  1735.     ClearDepthBuffer (0xffff);
  1736.     texture = SolidTexture (VL_WOODGRAIN);
  1737.     SwitchLight (light7, TRUE);
  1738.     SwitchLight (light8, TRUE);
  1739.     Translate3D (-15, -15, 5);
  1740.     Scale3D (10, 10, 5);
  1741.     NURBSSurface (hdc, VL_3D, (LPCOORD) surf, 6, 6, sknot, tknot, 4, 4);
  1742.     SolidTexture (texture);
  1743. }
  1744.  
  1745. void    GraniteCubeDemo (HDC hdc)
  1746. {
  1747.     REAL    l8;
  1748.     short    texture;
  1749.  
  1750.     SelectViewer (viewer30);
  1751.     SetViewerName (VL_CURRENT, "Granite Cube");
  1752.     ClearDepthBuffer (0xffff);
  1753.     texture = SolidTexture (VL_GRANITE);
  1754.     SelectMaterial (mater0);
  1755.     l8 = ShadingFactor (light8, VL_LIGHTINTENSITY, 2);
  1756.     SwitchLight (light7, TRUE);
  1757.     SwitchLight (light8, TRUE);
  1758.     Cube (hdc, 30, 30, 30);
  1759.     SolidTexture (texture);
  1760.     ShadingFactor (light8, VL_LIGHTINTENSITY, l8);
  1761. }
  1762.  
  1763. void    StereoTextDemo (HDC hdc)
  1764. {
  1765.     SelectViewer (viewer30);
  1766.     SelectMaterial (mater3);
  1767.     ClearDepthBuffer (0xffff);
  1768.     TextParameter (VL_TEXT_HEIGHT, 40);
  1769.     TextParameter (VL_TEXT_THICKNESS, 8);
  1770.     SwitchLight (light4, TRUE);
  1771.     SwitchLight (light7, TRUE);
  1772.     SelectMaterial (mater0);
  1773.     PushTransformation3D (NULL);
  1774.     Rotate3D (135, 'z');
  1775.     Rotate3D (90, 'x');
  1776.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1777.     SolidText (hdc, "Visualib");
  1778.     PopTransformation3D (NULL);
  1779.     SetViewerName (VL_CURRENT, "Stereo Text");
  1780.     SelectObject (hdc, GetStockObject (SYSTEM_FONT));
  1781. }
  1782.  
  1783. void    Welcome (HDC hdc)
  1784. {
  1785.     char    str[80];
  1786.  
  1787.     SelectViewer (viewer20);
  1788.     PushTransformation2D (NULL);
  1789.     Scale2D (0.1f, 0.1f);
  1790.     SetTextAlign (hdc, TA_BASELINE | TA_CENTER);
  1791.     TextParameter (VL_TEXT_HEIGHT, 40);
  1792.     PenColor (hdc, VL_RED);
  1793.     BrushColor (hdc, VL_YELLOW);
  1794.     wsprintf (str, "Welcome\nto\nVisuaLib");
  1795.     SetFont (NULL);
  1796.     Text2D (hdc, 0, 0, 0, str);
  1797.     PopTransformation2D (NULL);
  1798. }
  1799.  
  1800. void    BumpyDonutDemo (HDC hdc)
  1801. {
  1802.     short    texture;
  1803.  
  1804.     SelectViewer (viewer30);
  1805.     SetViewerName (VL_CURRENT, "Bumpy Donut");
  1806.     SelectMaterial (mater2);
  1807.     ClearDepthBuffer (0xffff);
  1808.     texture = SolidTexture (VL_BUMPY);
  1809.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  1810.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, 1);
  1811. //    SwitchLight (light7, TRUE);
  1812.     SwitchLight (light8, TRUE);
  1813.     Torus (hdc, 35, 10);
  1814.     SolidTexture (texture);
  1815. }
  1816.  
  1817. void    VlibDemo (HDC hdc, int func)
  1818. {
  1819.     BOOL    l0, l1, l2, l3;
  1820.     BOOL    twosideshade, backfaceoff;
  1821.  
  1822.     l0 = SwitchLight (light0, FALSE);
  1823.     l1 = SwitchLight (light1, FALSE);
  1824.     l2 = SwitchLight (light2, FALSE);
  1825.     l3 = SwitchLight (light3, FALSE);
  1826.     twosideshade = ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  1827.     backfaceoff = ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  1828.     switch (func) {
  1829.         case IDM_DEMO_START:
  1830.             Welcome (hdc);
  1831.             break;
  1832.         case IDM_DEMO_SPOTLIGHT:
  1833.             SpotlightDemo (hdc);
  1834.             break;
  1835.         case IDM_DEMO_MATERIALPROPERTY:
  1836.             MaterialPropertyDemo (hdc);
  1837.             break;
  1838.         case IDM_DEMO_IMAGEMAPPING:
  1839.             ImageMappingDemo (hdc);
  1840.             break;
  1841.         case IDM_DEMO_DEPTHCLIPPING:
  1842.             DepthClippingDemo (hdc);
  1843.             break;
  1844.         case IDM_DEMO_MARBLERING:
  1845.             MarbleRingDemo (hdc);
  1846.             break;
  1847.         case IDM_DEMO_BUMPYDONUT:
  1848.             BumpyDonutDemo (hdc);
  1849.             break;
  1850.         case IDM_DEMO_GRANITECUBE:
  1851.             GraniteCubeDemo (hdc);
  1852.             break;
  1853.         case IDM_DEMO_WOODSURFACE:
  1854.             WoodSurfaceDemo (hdc);
  1855.             break;
  1856.         case IDM_DEMO_3DCOMPOSITE:
  1857.             CompositeDemo3D (hdc);
  1858.             break;
  1859.         case IDM_DEMO_STEREOTEXT:
  1860.             StereoTextDemo (hdc);
  1861.             break;
  1862.         case IDM_DEMO_2DCOMPOSITE:
  1863.             CompositeDemo2D (hdc);
  1864.             break;
  1865.         case IDM_DEMO_NURBSCURVE:
  1866.             SelectViewer (viewer20);
  1867.             Primitives2D (hdc, IDM_2DCURVE_NURBS);
  1868.             SelectViewer (viewer30);
  1869.             Primitives3D (hdc, IDM_3DCURVE_NURBS);
  1870.             break;
  1871.         case IDM_DEMO_POLYFACET:
  1872.             SelectViewer (viewer30);
  1873.             SetViewerName (VL_CURRENT, "Poly Facets");
  1874.             PolyfacetsDemo (hdc);
  1875.             break;
  1876.     }
  1877.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, twosideshade);
  1878.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, backfaceoff);
  1879.     SwitchLight (light0, l0);
  1880.     SwitchLight (light1, l1);
  1881.     SwitchLight (light2, l2);
  1882.     SwitchLight (light3, l3);
  1883.     SwitchLight (light4, FALSE);
  1884.     SwitchLight (light5, FALSE);
  1885.     SwitchLight (light6, FALSE);
  1886.     SwitchLight (light7, FALSE);
  1887.     SwitchLight (light8, FALSE);
  1888.     SelectMaterial (mater3);
  1889. }
  1890.  
  1891. void    FunctionDemos (HDC hdc)
  1892. {
  1893.     int        func = demo_function;
  1894.  
  1895.     SetROP2 (hdc, R2_COPYPEN);
  1896.     if (func > IDM_2DPRIME_START && func < IDM_2DPRIME_END) {
  1897.         SelectViewer (viewer20);
  1898.         Prime2D (hdc, func);
  1899.     }
  1900.     else if (func > IDM_3DPRIME_START && func < IDM_3DPRIME_END) {
  1901.         SelectViewer (viewer30);
  1902.         Prime3D (hdc, func);
  1903.     }
  1904.     else if (func >= IDM_SURFACE_START && func < IDM_SURFACE_END) {
  1905.         SelectViewer (viewer30);
  1906.         Surfaces (hdc, func);
  1907.     }
  1908.     else if (func >= IDM_SOLID_START && func < IDM_SOLID_END) {
  1909.         SelectViewer (viewer30);
  1910.         ShowSolidPrimitives (hdc, func);
  1911.     }
  1912.     else if (func > IDM_ANIMATE_START && func < IDM_ANIMATE_END) {
  1913.         AnimationDemo (hdc, func);
  1914.         ViewerReset ();
  1915.         SelectMaterial (mater3);
  1916.     }
  1917.     else if (func > IDM_TEXT_START && func < IDM_TEXT_END) {
  1918.         ShowTextPrimitives (hdc, func);
  1919.     }
  1920.     else if (func > IDM_2DTRANSF_BEGIN && func < IDM_3DTRANSF_BEGIN) {
  1921.         SelectViewer (viewer20);
  1922.         Transformation2D (hdc, func);
  1923.     }
  1924.     else if (func > IDM_3DTRANSF_BEGIN && func < IDM_3DTRANSF_END) {
  1925.         SelectViewer (viewer30);
  1926.         Transformation3D (hdc, func);
  1927.     }
  1928.     else if (func > IDM_2DPRIMIT_START && func < IDM_2DPRIMIT_END) {
  1929.         SelectViewer (viewer20);
  1930.         Primitives2D (hdc, func);
  1931.     }
  1932.     else if (func > IDM_3DPRIMIT_START && func < IDM_3DPRIMIT_END) {
  1933.         SelectViewer (viewer30);
  1934.         Primitives3D (hdc, func);
  1935.     }
  1936.     else if (func > IDM_3DARRAY_BEGIN && func < IDM_3DARRAY_END) {
  1937.         SelectViewer (viewer30);
  1938.         ObjectArray3D (hdc, func);
  1939.     }
  1940.     else if (func > IDM_2DARRAY_BEGIN && func < IDM_2DARRAY_END) {
  1941.         SelectViewer (viewer20);
  1942.         ObjectArray2D (hdc, func);
  1943.     }
  1944.     else {
  1945.         VlibDemo (hdc, func);
  1946.     }
  1947.     PenColor (hdc, VL_BLUE);
  1948.     DisplayViewerFrame (hdc, VL_CURRENT);
  1949.     TextColor (hdc, VL_RED, VL_BLACK, TRANSPARENT);
  1950.     DisplayViewerName (hdc, VL_CURRENT, FALSE);
  1951. }
  1952.  
  1953. void    AdjustViewer (HWND hwnd, int viewid)
  1954. {
  1955.     RECT    rect;
  1956.  
  1957.     GetClientRect (hwnd, &rect);
  1958.     rect.left += 10;
  1959.     rect.right -= 10;
  1960.     rect.top += 10;
  1961.     rect.bottom -= 20;
  1962.     SetViewport (viewid, rect);
  1963. }
  1964.  
  1965. BINARY    SavePicture (HWND hwnd, BOOL withframe)
  1966. {
  1967.     RECT    rect;
  1968.     HANDLE    hdib;
  1969.     BOOL    flag;
  1970.  
  1971.     GetScreenRect (hwnd, withframe, &rect);
  1972.     hdib = ScreenToDIB (&rect);
  1973.     if (!hdib)
  1974.         return (FALSE);
  1975.     flag = WriteDIBFile (NULL, hdib);
  1976.     GlobalUnlock (hdib);
  1977.     GlobalFree (hdib);
  1978.     return (flag);
  1979. }
  1980.  
  1981. BINARY    PrintPicture (HWND hwnd, BOOL withframe)
  1982. {
  1983.     RECT    rect;
  1984.     HANDLE    hdib;
  1985.     BOOL    flag;
  1986.  
  1987.     GetScreenRect (hwnd, withframe, &rect);
  1988.     hdib = ScreenToDIB (&rect);
  1989.     if (!hdib)
  1990.         return (FALSE);
  1991.     flag = PrintImage (hdib,
  1992.         VL_BESTFIT | VL_VERTCENTER | VL_HORZCENTER | VL_MARKCORNER,
  1993.         0, 0, 0, 0);
  1994.     GlobalUnlock (hdib);
  1995.     GlobalFree (hdib);
  1996.     return (flag);
  1997. }
  1998.  
  1999. void    PrintFlag (void)
  2000. {
  2001.     SelectViewer (viewer22);
  2002.     PrintDrawing (USFlag,
  2003.         VL_BESTFIT | VL_HORZCENTER | VL_VERTCENTER | VL_MARKCORNER,
  2004.         0, 0, 0, 0);
  2005. }
  2006.  
  2007. void    ExitVlibDemo (HWND hwnd)
  2008. {
  2009.     DeleteObject (GetClassWord (hwnd, GCW_HBRBACKGROUND));
  2010.     ExitVisualib ();
  2011.     if (hdib1) {
  2012.         GlobalUnlock (hdib1);
  2013.         GlobalFree (hdib1);
  2014.     }
  2015.     if (hdib2) {
  2016.         GlobalUnlock (hdib2);
  2017.         GlobalFree (hdib2);
  2018.     }
  2019.     if (hdib3) {
  2020.         GlobalUnlock (hdib3);
  2021.         GlobalFree (hdib3);
  2022.     }
  2023.     PostQuitMessage (0);
  2024. }
  2025.  
  2026. void    AlterMenuItem (HWND hwnd, WORD entry)
  2027. {
  2028.     short    flag = MF_BYCOMMAND;
  2029.  
  2030.     switch (entry) {
  2031.         case IDM_DEMO_WITHFRAME:
  2032.             withframe = !withframe;
  2033.             flag |= (withframe) ? MF_CHECKED : MF_UNCHECKED;
  2034.             break;
  2035.     }
  2036.     CheckMenuItem (GetMenu (hwnd), entry, flag);
  2037. }
  2038.                         
  2039. /****************************************************************************
  2040.  
  2041.     FUNCTION: MainWndProc (HWND, WORD, WORD, LONG)
  2042.  
  2043. ****************************************************************************/
  2044.  
  2045. long WINAPI MainWndProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
  2046. {
  2047.     switch (msg) {
  2048.         case WM_COMMAND:
  2049.             switch (wparam) {
  2050.                 case IDM_DEMO_EXIT:
  2051.                     PostMessage (hwnd, WM_DESTROY, 0, 0L);
  2052.                     break;
  2053.                 case IDM_HELP_ABOUT:
  2054.                     AboutVisualib ();
  2055.                     SendMessage (hwnd, WM_COMMAND, IDM_DEMO_START, 0L);
  2056.                     break;
  2057.                 case IDM_HELP_LICENSE:
  2058.                     LicenseInfo ();
  2059.                     break;
  2060.                 case IDM_HELP_DEMOPROG:
  2061.                     WinHelp (hwnd, "vlibdemo.hlp", HELP_INDEX, 0);
  2062.                     break;
  2063.                 case IDM_HELP_VISUALIB:
  2064.                     WinHelp (hwnd, "visualib.hlp", HELP_INDEX, 0);
  2065.                     break;
  2066.                 case IDM_DEMO_SAVEPICTURE:
  2067.                     SavePicture (hwnd, withframe);
  2068.                     break;
  2069.                 case IDM_DEMO_PRINTPICTURE:
  2070.                     PrintPicture (hwnd, withframe);
  2071.                     break;
  2072.                 case IDM_DEMO_WITHFRAME:
  2073.                     AlterMenuItem (hwnd, wparam);
  2074.                     break;
  2075.                 case IDM_DEMO_PRINTFLAG:
  2076.                     PrintFlag ();
  2077.                     break;
  2078.                 case IDM_TEXT_SELECTFONT:
  2079.                     SelectFont ();
  2080.                     return (NULL);
  2081.                 default:
  2082.                     if (wparam > 200 && wparam < 300) {
  2083.                         ShadingSettings (hwnd, wparam);
  2084.                         break;
  2085.                     }
  2086.                     demo_function = wparam;
  2087.                     InvalidateRect (hwnd, NULL, TRUE);
  2088.                     return (DefWindowProc (hwnd, msg, wparam, lparam));
  2089.             }
  2090.             break;
  2091.         case WM_DESTROY:
  2092.             ExitVlibDemo (hwnd);
  2093.             break;
  2094.  
  2095.         case WM_PAINT:
  2096.             ProcessWindowPaint (hwnd);
  2097.             break;
  2098.         
  2099.         case WM_SIZE:
  2100.             AdjustViewer (hwnd, viewer20);
  2101.             AdjustViewer (hwnd, viewer30);
  2102.             InvalidateRect (hwnd, NULL, TRUE);
  2103.             break;
  2104.  
  2105.         default:
  2106.             return (DefWindowProc (hwnd, msg, wparam, lparam));
  2107.     }
  2108.     return (NULL);
  2109. }
  2110.