home *** CD-ROM | disk | FTP | other *** search
/ Learn 3D Graphics Programming on the PC / Learn_3D_Graphics_Programming_on_the_PC_Ferraro.iso / rwwin / viewdlg.c_ / viewdlg.bin
Text File  |  1995-11-14  |  76KB  |  1,688 lines

  1. /**********************************************************************
  2.  *
  3.  * File :     viewdlg.c
  4.  *
  5.  * Abstract : Dialogs used in rfView mostly taken from rfView 
  6.  *
  7.  *            This application had been written to be compatible with
  8.  *            both the fixed and floating-point versions of the
  9.  *            RenderWare library, i.e., it uses the macros CREAL,
  10.  *            INT2REAL, RAdd, RDiv, RSub etc. If your application is
  11.  *            intended for the floating-point version of the library
  12.  *            only these macros are not necessary.
  13.  *
  14.  *            Please note that this application is intended for
  15.  *            demonstration purposes only. No support will be
  16.  *            provided for this code and it comes with no warranty.
  17.  *
  18.  **********************************************************************
  19.  *
  20.  * This file is a product of Richard F. Ferraro
  21.  *
  22.  * This file is provided as is with no warranties of any kind and is
  23.  * provided without any obligation on Richard F. Ferraro. or Criterion Software or
  24.  * Canon Inc. to assist in its use or modification.
  25.  *
  26.  * Richard F. Ferraro or Criterion Software Ltd. will not, under any
  27.  * circumstances, be liable for any lost revenue or other damages arising
  28.  * from the use of this file.
  29.  *
  30.  * Copyright (c) 1995 Richard F. Ferraro
  31.  * All Rights Reserved.
  32.  *
  33.  * RenderWare is a trademark of Canon Inc.
  34.  *
  35.  **********************************************************************/
  36.  
  37. #include <windows.h>
  38.  
  39. #include <stdlib.h>
  40. #include <stdio.h>
  41. #include <math.h>
  42. #include <string.h>
  43.  
  44. #include <rwlib.h>
  45. #include <rwwin.h>
  46.  
  47. #include "resource.h"
  48. #include "rfview.h"
  49. #include "booksub.h"
  50. #include "viewsub.h"
  51.  
  52.  
  53. /*
  54.  * The RenderWare search path dialog procedure.
  55.  */
  56. BOOL CALLBACK
  57. SearchPathDlgProc(HWND dialog, UINT message, WPARAM wParam, LPARAM lParam)
  58. {
  59.     char searchPath[RWMAXPATHLEN];
  60.     lParam=lParam;
  61.     switch (message)
  62.     {
  63.         case WM_INITDIALOG:
  64.             /*
  65.              * Initialize the edit control with the current RenderWare
  66.              * search path.
  67.              */
  68.             RwGetShapePath(searchPath);
  69.             SetDlgItemText(dialog, IDC_SEARCHPATH_PATH, searchPath);
  70.             SetFocus(GetDlgItem(dialog, IDC_SEARCHPATH_PATH));
  71.             return FALSE;
  72.         
  73.         case WM_COMMAND:
  74. #ifdef WIN32
  75.         switch(LOWORD(wParam))
  76. #else
  77.         switch (wParam)
  78. #endif
  79.             {
  80.                 case IDOK:
  81.                     /*
  82.                      * Set the RenderWare search path to the contents of
  83.                      * the edit control.
  84.                      */
  85.                     GetDlgItemText(dialog, IDC_SEARCHPATH_PATH, searchPath, sizeof(searchPath));
  86.                     RwSetShapePath(searchPath, rwREPLACE);
  87.                     EndDialog(dialog, IDOK);
  88.                     break; 
  89.                     
  90.                 case IDCANCEL:
  91.                     EndDialog(dialog, IDCANCEL);
  92.                     break;
  93.             }
  94.             return TRUE;
  95.     }
  96.     
  97.     return FALSE;
  98. }
  99.  
  100.  
  101. /**********************************************************************/
  102.  
  103. /*
  104.  * The about box dialog procedure.
  105.  */
  106. BOOL  CALLBACK
  107. AboutBoxDlgProc(HWND dialog, UINT message, WPARAM wParam, LPARAM lParam)
  108. {
  109.     char    version[80];
  110.     RwBool  isFixed;
  111.     RwBool  isDebug;
  112.     RwInt32 depth;
  113.     RwBool  usingDIBs;
  114.     RwBool  usingWinG;
  115.     lParam=lParam;
  116.     switch (message)
  117.     {
  118.         case WM_INITDIALOG:
  119.             /*
  120.              * Get information about the RenderWare library being used and
  121.              * set the appropriate fields of the dialog with these values.
  122.              */
  123.             RwGetSystemInfo(rwVERSIONSTRING, &version,   sizeof(version));
  124.             RwGetSystemInfo(rwFIXEDPOINTLIB, &isFixed,   sizeof(isFixed));
  125.             RwGetSystemInfo(rwDEBUGGINGLIB,  &isDebug,   sizeof(isDebug));
  126.             RwGetDeviceInfo(rwRENDERDEPTH,   &depth,     sizeof(depth));
  127.             RwGetDeviceInfo(rwWINUSINGDIBS,  &usingDIBs, sizeof(usingDIBs));
  128.             RwGetDeviceInfo(rwWINUSINGWING,  &usingWinG, sizeof(usingWinG));
  129.         
  130.             SetDlgItemText(dialog, IDC_ABOUT_RENDERWAREVERSION, version);
  131.             SetDlgItemText(dialog, IDC_ABOUT_RENDERWARENUMERICS,
  132.                 (isFixed  ? "Fixed-point" : "Floating-point"));
  133.             SetDlgItemText(dialog, IDC_ABOUT_RENDERWAREKERNEL,
  134.                 (isDebug ? "Debugging" : "Retail"));
  135.             SetDlgItemText(dialog, IDC_ABOUT_RENDERWARERENDERING,
  136.                 ((depth == 8L) ? "8-bit (256 color)" : "16-bit (65536 color)"));
  137.             if (usingDIBs)
  138.             {
  139.                 SetDlgItemText(dialog, IDC_ABOUT_RENDERWAREBITMAPS, "DIBs");
  140.             }
  141.             else if (usingWinG)
  142.             {
  143.                 SetDlgItemText(dialog, IDC_ABOUT_RENDERWAREBITMAPS, "WinG");
  144.             }
  145.             else
  146.             {
  147. #if defined(WIN32)
  148.                 SetDlgItemText(dialog, IDC_ABOUT_RENDERWAREBITMAPS, "DIB Sections");
  149. #else
  150.                 SetDlgItemText(dialog, IDC_ABOUT_RENDERWAREBITMAPS, "DDBs");
  151. #endif
  152.             }
  153.         
  154.             return TRUE;
  155.         
  156.         case WM_COMMAND:
  157. #ifdef WIN32
  158.         switch(LOWORD(wParam))
  159. #else
  160.         switch (wParam)
  161. #endif
  162.             {
  163.                 case IDOK:
  164.                     EndDialog(dialog, IDOK);
  165.                     break; 
  166.             }
  167.             return TRUE;
  168.     }
  169.     
  170.     return FALSE;
  171. }
  172.  
  173. // *******************************************************************************************************
  174. BOOL CALLBACK
  175. CameraDlgProc(HWND dialog, UINT message, WPARAM wParam, LPARAM lParam)
  176. {
  177.     char    buffer[10];
  178.     HWND    scrollBar=NULL;
  179.     int     i,code,pos,newPos=0,channel,id=0,maxs=0;
  180.     float    fvalue;
  181.     RwCamera * retcam;    
  182.   
  183.     switch (message)
  184.     {
  185.         case WM_INITDIALOG:
  186.             RwGetCameraPosition(CurrentCamera,&rfCam.pos);
  187.             //RwGetCameraLookAt(CurrentCamera,&rfCam.point);
  188.             RwGetCameraViewwindow(CurrentCamera,&rfCam.vw_width, &rfCam.vw_height);
  189.  
  190.             // based on the view window and view size, let's find the view angle
  191.             rfViewwindowToAngle();
  192.   
  193.             /* Initialize the scrollbars. */
  194.             SetScrollRange(GetDlgItem(dialog, IDC_CR_SLIDER), SB_CTL, 0, MAX_REPEAT, FALSE);
  195.             SetScrollRange(GetDlgItem(dialog, IDC_CA_SLIDER), SB_CTL, -MAX_CSCROLL/2, MAX_CSCROLL/2, FALSE);
  196.             
  197.             SetScrollRange(GetDlgItem(dialog, IDC_CWX_SLIDER), SB_CTL, 0, MAX_CP_SCROLL/2, FALSE);
  198.             SetScrollRange(GetDlgItem(dialog, IDC_CWY_SLIDER), SB_CTL, 0, MAX_CP_SCROLL/2, FALSE);
  199.  
  200.             SetScrollRange(GetDlgItem(dialog, IDC_CAA_SLIDER), SB_CTL, 0, 1000, FALSE);
  201.             SetScrollRange(GetDlgItem(dialog, IDC_CVA_SLIDER), SB_CTL, 0, 18000, FALSE);
  202.   
  203.             SetScrollRange(GetDlgItem(dialog, IDC_CPX_SLIDER), SB_CTL, -MAX_CP_SCROLL/2, MAX_CP_SCROLL/2, FALSE);
  204.             SetScrollRange(GetDlgItem(dialog, IDC_CPY_SLIDER), SB_CTL, -MAX_CP_SCROLL/2, MAX_CP_SCROLL/2, FALSE);
  205.             SetScrollRange(GetDlgItem(dialog, IDC_CPZ_SLIDER), SB_CTL, -MAX_CP_SCROLL/2, MAX_CP_SCROLL/2, FALSE);
  206.             
  207.             SetScrollRange(GetDlgItem(dialog, IDC_COX_SLIDER), SB_CTL, -MAX_CP_SCROLL/2, MAX_CP_SCROLL/2, FALSE);
  208.             SetScrollRange(GetDlgItem(dialog, IDC_COY_SLIDER), SB_CTL, -MAX_CP_SCROLL/2, MAX_CP_SCROLL/2, FALSE);
  209.             SetScrollRange(GetDlgItem(dialog, IDC_COZ_SLIDER), SB_CTL, -MAX_CP_SCROLL/2, MAX_CP_SCROLL/2, FALSE);
  210.            
  211.             SetScrollPos(GetDlgItem(dialog, IDC_CR_SLIDER),   SB_CTL, rfCam.repeat, FALSE);
  212.             SetScrollPos(GetDlgItem(dialog, IDC_CA_SLIDER),   SB_CTL, (int)(100*rfCam.val), FALSE);
  213.             
  214.             SetScrollPos(GetDlgItem(dialog, IDC_CWX_SLIDER),   SB_CTL, (int)(100*rfCam.vw_width), FALSE);
  215.             SetScrollPos(GetDlgItem(dialog, IDC_CWY_SLIDER),   SB_CTL, (int)(100*rfCam.vw_height), FALSE);
  216.  
  217.             SetScrollPos(GetDlgItem(dialog, IDC_CAA_SLIDER),   SB_CTL, (int)(100*rfCam.aspect), FALSE);
  218.             SetScrollPos(GetDlgItem(dialog, IDC_CVA_SLIDER),   SB_CTL, (int)(100*rfCam.angle), FALSE);
  219.                          
  220.             SetScrollPos(GetDlgItem(dialog, IDC_CPX_SLIDER),   SB_CTL, (int)(100*rfCam.pos.x), FALSE);
  221.             SetScrollPos(GetDlgItem(dialog, IDC_CPY_SLIDER),   SB_CTL, (int)(100*rfCam.pos.y), FALSE);
  222.             SetScrollPos(GetDlgItem(dialog, IDC_CPZ_SLIDER),   SB_CTL, (int)(100*rfCam.pos.z), FALSE);
  223.  
  224.             SetScrollPos(GetDlgItem(dialog, IDC_COX_SLIDER),   SB_CTL, (int)(100*rfCam.point.x), FALSE);
  225.             SetScrollPos(GetDlgItem(dialog, IDC_COY_SLIDER),   SB_CTL, (int)(100*rfCam.point.y), FALSE);
  226.             SetScrollPos(GetDlgItem(dialog, IDC_COZ_SLIDER),   SB_CTL, (int)(100*rfCam.point.z), FALSE);         
  227.             /*
  228.              * Initialize the edit controls.
  229.               */
  230.             sprintf(buffer, "%4d", rfCam.repeat);
  231.             SetDlgItemText(dialog, IDC_CR_EDIT, buffer);
  232.             sprintf(buffer, "%2.1f", rfCam.val);
  233.             SetDlgItemText(dialog, IDC_CA_EDIT, buffer);
  234.             
  235.             sprintf(buffer, "%2.1f", rfCam.vw_width);
  236.             SetDlgItemText(dialog, IDC_CWX_EDIT, buffer);
  237.             sprintf(buffer, "%2.1f",rfCam.vw_height);
  238.             SetDlgItemText(dialog, IDC_CWY_EDIT, buffer);
  239.  
  240.             sprintf(buffer, "%2.1f", rfCam.aspect);
  241.             SetDlgItemText(dialog, IDC_CAA_EDIT, buffer);
  242.             sprintf(buffer, "%2.1f",rfCam.angle);
  243.             SetDlgItemText(dialog, IDC_CVA_EDIT, buffer);
  244.  
  245.             sprintf(buffer, "%2.1f", rfCam.pos.x);
  246.             SetDlgItemText(dialog, IDC_CPX_EDIT, buffer);
  247.             sprintf(buffer, "%2.1f",rfCam.pos.y);
  248.             SetDlgItemText(dialog, IDC_CPY_EDIT, buffer);
  249.             sprintf(buffer, "%2.1f", rfCam.pos.z);
  250.             SetDlgItemText(dialog, IDC_CPZ_EDIT, buffer);
  251.             
  252.             sprintf(buffer, "%2.1f", rfCam.point.x);
  253.             SetDlgItemText(dialog, IDC_COX_EDIT, buffer);
  254.             sprintf(buffer, "%2.1f",rfCam.point.y);
  255.             SetDlgItemText(dialog, IDC_COY_EDIT, buffer);
  256.             sprintf(buffer, "%2.1f", rfCam.point.z);
  257.             SetDlgItemText(dialog, IDC_COZ_EDIT, buffer);
  258.             
  259.             return FALSE;
  260.             
  261.         case WM_HSCROLL:
  262. #if       defined(WIN32)
  263.             code      = (int)LOWORD(wParam);
  264.             newPos    = (int)HIWORD(wParam);
  265.             scrollBar = (HWND)lParam;
  266.             id        = (int)GetWindowLong(scrollBar, GWL_ID);
  267. #else
  268.             code      = (int)wParam;
  269.             newPos    = (int)LOWORD(lParam);
  270.             scrollBar = (HWND)HIWORD(lParam);
  271.             id        = (int)GetWindowWord(scrollBar, GWW_ID);
  272. #endif            
  273.         maxs = MAX_CP_SCROLL;   // assume not repeat or value
  274.          switch (id)
  275.           {
  276.             case IDC_CR_SLIDER: maxs = MAX_REPEAT;  break;
  277.                case IDC_CA_SLIDER:    maxs = MAX_CSCROLL;    break;
  278.             case IDC_CVA_SLIDER: maxs = 32000;      break;
  279.             case IDC_CAA_SLIDER: maxs = 2000;       break;
  280.           }   
  281.             /* 
  282.              * As we preview continuously SB_ENDSCROLL is not important to us.
  283.              */
  284.             if (code == SB_ENDSCROLL) return TRUE;
  285.             
  286.             /* Update the scroll bar. */
  287.   
  288.             pos = GetScrollPos(scrollBar, SB_CTL);
  289.             switch (code)
  290.             {
  291.                 case SB_BOTTOM:        pos =  maxs;    break;
  292.                 case SB_LINEDOWN:      pos += maxs/10;      break;
  293.                 case SB_LINEUP:        pos -= maxs/10;      break;
  294.                 case SB_PAGEDOWN:      pos += maxs/2;     break;
  295.                 case SB_PAGEUP:        pos -= maxs/2;     break;
  296.                 case SB_THUMBTRACK:    pos =  newPos; break;
  297.                 case SB_THUMBPOSITION: pos =  newPos; break;
  298.                 case SB_TOP:           pos =  0;      break;
  299.             }
  300.             
  301.             /*
  302.              * Clamp the position to the valid range.
  303.              */
  304.             if (pos < -maxs/2) pos = -maxs/2; else if (pos > maxs/2) pos = maxs/2;
  305.             SetScrollPos(scrollBar, SB_CTL, pos, TRUE);
  306.             
  307.             /*
  308.              * Compute the new camera(depending on which channel has changed)
  309.              * and update the appropriate edit control.
  310.              */
  311.             switch (id)
  312.             {                             
  313.                 case IDC_CR_SLIDER:
  314.                     sprintf(buffer, "%3d", pos);
  315.                     SetDlgItemText(dialog, IDC_CR_EDIT, buffer);
  316.                     rfCam.repeat = pos;
  317.                 break;
  318.                 case IDC_CA_SLIDER:
  319.                     sprintf(buffer, "%2.1f",(float)pos/100);
  320.                     SetDlgItemText(dialog, IDC_CA_EDIT, buffer);
  321.                     rfCam.val = (float)pos/100;
  322.                 break;
  323.                 case IDC_CWX_SLIDER:
  324.                     sprintf(buffer, "%2.1f", (float)pos/100);
  325.                     SetDlgItemText(dialog, IDC_CWX_EDIT, buffer);
  326.                     rfCam.vw_width = (float)pos/100;
  327.                     rfViewwindowToAngle();
  328.                     sprintf(buffer, "%2.1f", (float)rfCam.aspect);
  329.                     SetDlgItemText(dialog, IDC_CAA_EDIT, buffer);
  330.                     sprintf(buffer, "%3.1f", (float)rfCam.angle);
  331.                     SetDlgItemText(dialog, IDC_CVA_EDIT, buffer);
  332.                     SetScrollPos(GetDlgItem(dialog, IDC_CAA_SLIDER), SB_CTL, (int)(rfCam.aspect*100), TRUE);
  333.                     SetScrollPos(GetDlgItem(dialog, IDC_CVA_SLIDER), SB_CTL, (int)(rfCam.angle*100), TRUE);
  334.                 break;
  335.                 case IDC_CWY_SLIDER:
  336.                     sprintf(buffer, "%2.1f", (float)pos/100);
  337.                     SetDlgItemText(dialog, IDC_CWY_EDIT, buffer);
  338.                     rfCam.vw_height = (float)pos/100;
  339.                     rfViewwindowToAngle();
  340.                     sprintf(buffer, "%2.1f", (float)rfCam.aspect);
  341.                     SetDlgItemText(dialog, IDC_CAA_EDIT, buffer);
  342.                     sprintf(buffer, "%3.1f", (float)rfCam.angle);
  343.                     SetDlgItemText(dialog, IDC_CVA_EDIT, buffer);
  344.                     SetScrollPos(GetDlgItem(dialog, IDC_CAA_SLIDER), SB_CTL, (int)(rfCam.aspect*100), TRUE);
  345.                     SetScrollPos(GetDlgItem(dialog, IDC_CVA_SLIDER), SB_CTL, (int)(rfCam.angle*100), TRUE);
  346.                 break;
  347.                 case IDC_CAA_SLIDER:
  348.                     sprintf(buffer, "%2.1f", (float)pos/100);
  349.                     SetDlgItemText(dialog, IDC_CAA_EDIT, buffer);
  350.                     rfCam.aspect = (float)pos/100;
  351.                     rfAngleToViewwindow();
  352.                     sprintf(buffer, "%2.1f", (float)rfCam.vw_width);
  353.                     SetDlgItemText(dialog, IDC_CWX_EDIT, buffer);
  354.                     sprintf(buffer, "%2.1f", (float)rfCam.vw_height);
  355.                     SetDlgItemText(dialog, IDC_CWY_EDIT, buffer);
  356.                     SetScrollPos(GetDlgItem(dialog, IDC_CWX_SLIDER), SB_CTL, (int)(rfCam.vw_width*100), TRUE);
  357.                     SetScrollPos(GetDlgItem(dialog, IDC_CWY_SLIDER), SB_CTL, (int)(rfCam.vw_height*100), TRUE);
  358.                 break;
  359.                 case IDC_CVA_SLIDER:
  360.                     sprintf(buffer, "%3.1f", (float)pos/100);
  361.                     SetDlgItemText(dialog, IDC_CVA_EDIT, buffer);
  362.                     rfCam.angle = (float)pos/100;
  363.                     rfAngleToViewwindow();
  364.                     sprintf(buffer, "%2.1f", (float)rfCam.vw_width);
  365.                     SetDlgItemText(dialog, IDC_CWX_EDIT, buffer);
  366.                     sprintf(buffer, "%2.1f", (float)rfCam.vw_height);
  367.                     SetDlgItemText(dialog, IDC_CWY_EDIT, buffer);
  368.                     SetScrollPos(GetDlgItem(dialog, IDC_CWX_SLIDER), SB_CTL, (int)(rfCam.vw_width*100), TRUE);
  369.                     SetScrollPos(GetDlgItem(dialog, IDC_CWY_SLIDER), SB_CTL, (int)(rfCam.vw_height*100), TRUE);
  370.                 break;
  371.                 case IDC_CPX_SLIDER:
  372.                     sprintf(buffer, "%2.1f", (float)pos/100);
  373.                     SetDlgItemText(dialog, IDC_CPX_EDIT, buffer);
  374.                     rfCam.pos.x = (float)pos/100;
  375.                 break;
  376.                 case IDC_CPY_SLIDER:
  377.                     sprintf(buffer, "%2.1f", (float)pos/100);
  378.                     SetDlgItemText(dialog, IDC_CPY_EDIT, buffer);
  379.                     rfCam.pos.y = (float)pos/100;
  380.                 break;
  381.                 case IDC_CPZ_SLIDER:
  382.                     sprintf(buffer, "%2.1f", (float)pos/100);
  383.                     SetDlgItemText(dialog, IDC_CPZ_EDIT, buffer);
  384.                     rfCam.pos.z = (float)pos/100;
  385.                break;
  386.                case IDC_COX_SLIDER:
  387.                     sprintf(buffer, "%2.1f", (float)pos/100);
  388.                     SetDlgItemText(dialog, IDC_COX_EDIT, buffer);
  389.                     rfCam.point.x = (float)pos/100;
  390.                 break;
  391.                 case IDC_COY_SLIDER:
  392.                     sprintf(buffer, "%2.1f", (float)pos/100);
  393.                     SetDlgItemText(dialog, IDC_COY_EDIT, buffer);
  394.                     rfCam.point.y = (float)pos/100;
  395.                 break;
  396.                 case IDC_COZ_SLIDER:
  397.                     sprintf(buffer, "%2.1f", (float)pos/100);
  398.                     SetDlgItemText(dialog, IDC_COZ_EDIT, buffer);
  399.                     rfCam.point.z = (float)pos/100;
  400.                 break;
  401.             }
  402.            return TRUE;
  403.                
  404.           case WM_COMMAND:
  405.         {
  406. #ifdef WIN32
  407.              HWND hwndCtl = (HWND) lParam;
  408.             WORD wID = LOWORD(wParam);
  409.             WORD wNotifyCode = HIWORD(wParam);
  410. #else
  411.             HWND hwndCtl = (HWND) LOWORD(lParam);
  412.             WORD wID = wParam;
  413.             WORD wNotifyCode = HIWORD(lParam);
  414. #endif
  415.             switch (wID)
  416.             {
  417.                 case IDC_CPX_EDIT: case IDC_CPY_EDIT:  case IDC_CPZ_EDIT:
  418.                 case IDC_COX_EDIT: case IDC_COY_EDIT:  case IDC_COZ_EDIT:
  419.                 case IDC_CA_EDIT:  case IDC_CR_EDIT:
  420.                 case IDC_CWX_EDIT: case IDC_CWY_EDIT:  case IDC_CAA_EDIT: case IDC_CVA_EDIT:   
  421.                     /*
  422.                      * For the edit controls we only take any notice when the
  423.                      * control loses the input focus.
  424.                      */
  425.                     if (wNotifyCode == EN_KILLFOCUS)
  426.                     {
  427.                       /* Get the edit control's text. */
  428.                       GetDlgItemText(dialog, wID, buffer, sizeof(buffer));
  429.                         
  430.                       /* Build the new current tanslation and update the appropriate slider.*/
  431.                       switch (wID)
  432.                        {
  433.                           case IDC_CA_EDIT:
  434.                             scrollBar = GetDlgItem(dialog, IDC_CA_SLIDER);
  435.                             if( (sscanf(buffer, "%f", &fvalue) == 1) &&
  436.                                          (fvalue >= -MAX_CSCROLL/2) && (fvalue <= MAX_CSCROLL/2))
  437.                              {
  438.                               rfCam.val = fvalue;
  439.                               SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*100), TRUE);
  440.                              }
  441.                             else
  442.                              {
  443.                               channel = GetScrollPos(scrollBar, SB_CTL);
  444.                               sprintf(buffer, "%2.1f", (float)channel/100);
  445.                               SetDlgItemText(dialog, wID, buffer);
  446.                              }
  447.                          break;
  448.                          case IDC_CPX_EDIT:
  449.                                     scrollBar = GetDlgItem(dialog, IDC_CPX_SLIDER);
  450.                                     if( (sscanf(buffer, "%f", &fvalue) == 1) &&
  451.                                          (fvalue >= -MAX_CP_SCROLL/2) && (fvalue <= MAX_CP_SCROLL/2))
  452.                                      {                                
  453.                                       rfCam.pos.x = fvalue;
  454.                                       SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*100), TRUE);
  455.                                      }
  456.                                     else
  457.                                      { 
  458.                                      channel = GetScrollPos(scrollBar, SB_CTL);
  459.                                      sprintf(buffer, "%2.1f", (float)channel/100);
  460.                                      SetDlgItemText(dialog, wID, buffer);
  461.                                      }
  462.                          break;
  463.                          case IDC_CPY_EDIT:
  464.                                     scrollBar = GetDlgItem(dialog, IDC_CPY_SLIDER);
  465.                                     if( (sscanf(buffer, "%f", &fvalue) == 1) &&
  466.                                          (fvalue >= -MAX_CP_SCROLL/2) && (fvalue <= MAX_CP_SCROLL/2))
  467.                                      {                               
  468.                                       rfCam.pos.y = fvalue;
  469.                                       SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*100), TRUE);
  470.                                      }
  471.                                     else
  472.                                     {
  473.                                      channel = GetScrollPos(scrollBar, SB_CTL);
  474.                                      sprintf(buffer, "%2.1f", (float)channel/100);
  475.                                      SetDlgItemText(dialog, wID, buffer);
  476.                                     }
  477.                          break;
  478.                          case IDC_CPZ_EDIT:
  479.                                     scrollBar = GetDlgItem(dialog, IDC_CPZ_SLIDER);
  480.                                     if( (sscanf(buffer, "%f", &fvalue) == 1) &&
  481.                                          (fvalue >= -MAX_CP_SCROLL/2) && (fvalue <= MAX_CP_SCROLL/2))
  482.                                      {                                
  483.                                       rfCam.pos.z = fvalue;
  484.                                       SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*100), TRUE);
  485.                                      }
  486.                                     else
  487.                                     {
  488.                                      channel = GetScrollPos(scrollBar, SB_CTL);
  489.                                      sprintf(buffer, "%2.1f", (float)channel/100);                                    
  490.                                      SetDlgItemText(dialog, wID, buffer);
  491.                                      }
  492.                           break;
  493.                           case IDC_CWX_EDIT:                        
  494.                             scrollBar = GetDlgItem(dialog, IDC_CWX_SLIDER);
  495.                             if ((sscanf(buffer, "%f", &fvalue) == 1) &&
  496.                                 (fvalue >= 0) && (fvalue <= MAX_CP_SCROLL))
  497.                               {
  498.                                rfCam.vw_width = fvalue;
  499.                                SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*100), TRUE);
  500.                     rfViewwindowToAngle();
  501.                     sprintf(buffer, "%2.1f", (float)rfCam.aspect);
  502.                     SetDlgItemText(dialog, IDC_CAA_EDIT, buffer);
  503.                     sprintf(buffer, "%2.1f", (float)rfCam.angle);
  504.                     SetDlgItemText(dialog, IDC_CVA_EDIT, buffer);
  505.                     SetScrollPos(GetDlgItem(dialog, IDC_CAA_SLIDER), SB_CTL, (int)(rfCam.aspect*100), TRUE);
  506.                     SetScrollPos(GetDlgItem(dialog, IDC_CVA_SLIDER), SB_CTL, (int)(rfCam.angle*100), TRUE);
  507.                               }
  508.                             else
  509.                             {
  510.                              channel = GetScrollPos(scrollBar, SB_CTL);
  511.                              sprintf(buffer, "%2.1f", channel);
  512.                              SetDlgItemText(dialog, wID, buffer);
  513.                             }
  514.                           break;
  515.                           case IDC_CWY_EDIT:
  516.                             scrollBar = GetDlgItem(dialog, IDC_CWY_SLIDER);
  517.                             if ((sscanf(buffer, "%f", &fvalue) == 1) &&
  518.                                 (fvalue >= 0) && (fvalue <= MAX_CP_SCROLL))
  519.                               {
  520.                                rfCam.vw_height = fvalue;
  521.                                SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*100), TRUE);
  522.                     rfViewwindowToAngle();
  523.                     sprintf(buffer, "%2.1f", (float)rfCam.aspect);
  524.                     SetDlgItemText(dialog, IDC_CAA_EDIT, buffer);
  525.                     sprintf(buffer, "%2.1f", (float)rfCam.angle);
  526.                     SetDlgItemText(dialog, IDC_CVA_EDIT, buffer);
  527.                     SetScrollPos(GetDlgItem(dialog, IDC_CAA_SLIDER), SB_CTL, (int)(rfCam.aspect*100), TRUE);
  528.                     SetScrollPos(GetDlgItem(dialog, IDC_CVA_SLIDER), SB_CTL, (int)(rfCam.angle*100), TRUE);
  529.                               }
  530.                             else
  531.                             {
  532.                              channel = GetScrollPos(scrollBar, SB_CTL);
  533.                              sprintf(buffer, "%2.1", channel);
  534.                              SetDlgItemText(dialog, wID, buffer);
  535.                             }
  536.                           break;
  537.                           case IDC_CAA_EDIT:                        
  538.                             scrollBar = GetDlgItem(dialog, IDC_CAA_SLIDER);
  539.                             if ((sscanf(buffer, "%f", &fvalue) == 1) &&
  540.                                 (fvalue >= 0) && (fvalue <= 1000))
  541.                               {
  542.                                rfCam.aspect = fvalue;
  543.                                SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*100), TRUE);
  544.                     rfAngleToViewwindow();
  545.                     sprintf(buffer, "%2.1f", (float)rfCam.vw_width);
  546.                     SetDlgItemText(dialog, IDC_CWX_EDIT, buffer);
  547.                     sprintf(buffer, "%2.1f", (float)rfCam.vw_height);
  548.                     SetDlgItemText(dialog, IDC_CWY_EDIT, buffer);
  549.                     SetScrollPos(GetDlgItem(dialog, IDC_CWX_SLIDER), SB_CTL, (int)(rfCam.vw_width*100), TRUE);
  550.                     SetScrollPos(GetDlgItem(dialog, IDC_CWY_SLIDER), SB_CTL, (int)(rfCam.vw_height*100), TRUE);
  551.                               }
  552.                             else
  553.                             {
  554.                              channel = GetScrollPos(scrollBar, SB_CTL);
  555.                              sprintf(buffer, "%2.1f", channel);
  556.                              SetDlgItemText(dialog, wID, buffer);
  557.                             }
  558.                           break;
  559.                           case IDC_CVA_EDIT:
  560.                             scrollBar = GetDlgItem(dialog, IDC_CVA_SLIDER);
  561.                             if ((sscanf(buffer, "%f", &fvalue) == 1) &&
  562.                                 (fvalue >= 0) && (fvalue <= 16000))
  563.                               {
  564.                                rfCam.angle = fvalue;
  565.                                SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*100), TRUE);
  566.                     rfAngleToViewwindow();
  567.                     sprintf(buffer, "%2.1f", (float)rfCam.vw_width);
  568.                     SetDlgItemText(dialog, IDC_CWX_EDIT, buffer);
  569.                     sprintf(buffer, "%2.1f", (float)rfCam.vw_height);
  570.                     SetDlgItemText(dialog, IDC_CWY_EDIT, buffer);
  571.                     SetScrollPos(GetDlgItem(dialog, IDC_CWX_SLIDER), SB_CTL, (int)(rfCam.vw_width*100), TRUE);
  572.                     SetScrollPos(GetDlgItem(dialog, IDC_CWY_SLIDER), SB_CTL, (int)(rfCam.vw_height*100), TRUE);
  573.                               }
  574.                             else
  575.                             {
  576.                              channel = GetScrollPos(scrollBar, SB_CTL);
  577.                              sprintf(buffer, "%2.1", channel);
  578.                              SetDlgItemText(dialog, wID, buffer);
  579.                             }
  580.                             case IDC_COX_EDIT:
  581.                                     scrollBar = GetDlgItem(dialog, IDC_COX_SLIDER);
  582.                                     if( (sscanf(buffer, "%f", &fvalue) == 1) &&
  583.                                          (fvalue >= -MAX_CP_SCROLL/2) && (fvalue <= MAX_CP_SCROLL/2))
  584.                                      {                               
  585.                                       rfCam.point.x = fvalue;
  586.                                       SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*100), TRUE);
  587.                                      }
  588.                                     else
  589.                                     {
  590.                                      channel = GetScrollPos(scrollBar, SB_CTL);
  591.                                      sprintf(buffer, "%2.1f", (float)channel/100);
  592.                                      SetDlgItemText(dialog, wID, buffer);
  593.                                     }
  594.                          break;
  595.                          case IDC_COY_EDIT:
  596.                                     scrollBar = GetDlgItem(dialog, IDC_COY_SLIDER);
  597.                                     if( (sscanf(buffer, "%f", &fvalue) == 1) &&
  598.                                          (fvalue >= -MAX_CP_SCROLL/2) && (fvalue <= MAX_CP_SCROLL/2))
  599.                                      {                               
  600.                                       rfCam.point.y = fvalue;
  601.                                       SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*100), TRUE);
  602.                                      }
  603.                                     else
  604.                                     {
  605.                                      channel = GetScrollPos(scrollBar, SB_CTL);
  606.                                     sprintf(buffer, "%2.1f", (float)channel/100);
  607.                                      SetDlgItemText(dialog, wID, buffer);                                    
  608.                                     } 
  609.                          break;
  610.                          case IDC_COZ_EDIT:
  611.                                     scrollBar = GetDlgItem(dialog, IDC_COZ_SLIDER);
  612.                                     if( (sscanf(buffer, "%f", &fvalue) == 1) &&
  613.                                          (fvalue >= -MAX_CP_SCROLL/2) && (fvalue <= MAX_CP_SCROLL/2))
  614.                                      {                               
  615.                                       rfCam.point.z = fvalue;
  616.                                       SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*100), TRUE);
  617.                                      }
  618.                                     else
  619.                                      {
  620.                                       channel = GetScrollPos(scrollBar, SB_CTL);
  621.                                       sprintf(buffer, "%2.1f", (float)channel/100);
  622.                                       SetDlgItemText(dialog, wID, buffer);
  623.                                       }
  624.                           break;
  625.                           case IDC_CR_EDIT:
  626.                             scrollBar = GetDlgItem(dialog, IDC_CR_SLIDER);
  627.                             if ((sscanf(buffer, "%d", &channel) == 1) &&
  628.                                 (channel >= 0) && (channel <= 1000))
  629.                               {
  630.                               rfCam.repeat = channel;
  631.                               SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*100), TRUE);
  632.                               }
  633.                             else
  634.                               {
  635.                                channel = GetScrollPos(scrollBar, SB_CTL);
  636.                                sprintf(buffer, "%d", channel);
  637.                                SetDlgItemText(dialog, wID, buffer);
  638.                               } 
  639.                           break;
  640.  
  641.                          } // end of case
  642.                       } // end of if
  643.        break;
  644.                                                
  645.        // **************************************     pan, revolve, and tilt   *************************************
  646.        case IDC_CPAN:        // about local Y  UP
  647.         RwPushScratchMatrix(); 
  648.         RwGetCameraPosition(CurrentCamera,&rfRel.pos);
  649.         rfRel.up.x = CREAL(0.0); rfRel.up.y = CREAL(1.0); rfRel.up.z = CREAL(0.0);
  650.         RwGetCameraLTM(CurrentCamera,RwScratchMatrix());
  651.         RwTransformVector(&rfRel.up,RwScratchMatrix());
  652.         RwTranslateMatrix(RwScratchMatrix(),-rfRel.pos.x,-rfRel.pos.y,-rfRel.pos.z,rwREPLACE);
  653.          RwRotateMatrix(RwScratchMatrix(),rfRel.up.x, rfRel.up.y, rfRel.up.z, rfCam.val,rwPOSTCONCAT);    
  654.         RwTranslateMatrix(RwScratchMatrix(),rfRel.pos.x,rfRel.pos.y,rfRel.pos.z,rwPOSTCONCAT);
  655.  
  656.         if(rfCam.repeat!=1) rfRepeatMode = TRUE;
  657.           for (i=0; i<rfCam.repeat; i++) {
  658.               RwTransformCamera(CurrentCamera, RwScratchMatrix(), rwPOSTCONCAT);
  659.               if(i == rfCam.repeat-1) rfRepeatMode = FALSE;
  660.               RenderScene(CurrentWindow);
  661.              }
  662.         RwPopScratchMatrix();
  663.        break;
  664.  
  665.        case IDC_CREVOLVE:          // about local Z  At
  666.         RwPushScratchMatrix(); 
  667.         RwGetCameraPosition(CurrentCamera,&rfRel.pos);       
  668.         rfRel.at.x = CREAL(0.0); rfRel.at.y = CREAL(0.0); rfRel.at.z = CREAL(1.0);
  669.         RwGetCameraLTM(CurrentCamera,RwScratchMatrix());
  670.         RwTransformVector(&rfRel.at,RwScratchMatrix());
  671.         RwTranslateMatrix(RwScratchMatrix(),-rfRel.pos.x,-rfRel.pos.y,-rfRel.pos.z,rwREPLACE); 
  672.         RwRotateMatrix(RwScratchMatrix(),rfRel.at.x, rfRel.at.y, rfRel.at.z, rfCam.val,rwPOSTCONCAT);          
  673.         RwTranslateMatrix(RwScratchMatrix(),rfRel.pos.x,rfRel.pos.y,rfRel.pos.z,rwPOSTCONCAT);
  674.        
  675.         if(rfCam.repeat!=1) rfRepeatMode = TRUE;
  676.           for (i=0; i<rfCam.repeat; i++) {
  677.               RwTransformCamera(CurrentCamera, RwScratchMatrix(), rwPOSTCONCAT);
  678.               if(i == rfCam.repeat-1) rfRepeatMode = FALSE;
  679.               RenderScene(CurrentWindow);
  680.              }      
  681.         RwPopScratchMatrix();
  682.        break;
  683.        
  684.        case IDC_CTILT:         // about local X  Right
  685.         RwPushScratchMatrix(); 
  686.  
  687.         RwGetCameraPosition(CurrentCamera,&rfRel.pos);
  688.         rfRel.right.x = CREAL(1.0); rfRel.right.y = CREAL(0.0); rfRel.right.z = CREAL(0.0);
  689.         RwGetCameraLTM(CurrentCamera,RwScratchMatrix());        
  690.         RwTransformVector(&rfRel.right,RwScratchMatrix());
  691.         RwTranslateMatrix(RwScratchMatrix(),-rfRel.pos.x,-rfRel.pos.y,-rfRel.pos.z,rwREPLACE);
  692.         RwRotateMatrix(RwScratchMatrix(),rfRel.right.x, rfRel.right.y, rfRel.right.z, rfCam.val, rwPOSTCONCAT);
  693.         RwTranslateMatrix(RwScratchMatrix(),rfRel.pos.x,rfRel.pos.y,rfRel.pos.z,rwPOSTCONCAT); 
  694.          
  695.         if(rfCam.repeat!=1) rfRepeatMode = TRUE;
  696.           for (i=0; i<rfCam.repeat; i++) {
  697.               RwTransformCamera(CurrentCamera, RwScratchMatrix(), rwPOSTCONCAT);
  698.               if(i == rfCam.repeat-1) rfRepeatMode = FALSE;
  699.               RenderScene(CurrentWindow);
  700.              }
  701.         RwPopScratchMatrix();
  702.        break;
  703.        
  704.         case IDC_TRYVW:
  705.           retcam=RwSetCameraPosition(CurrentCamera, rfCam.pos.x, rfCam.pos.y, rfCam.pos.z);
  706.           if(retcam==NULL) MessageBox(CurrentWindow, "ERROR Position", WINDOWTITLE,MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION);
  707.           retcam=RwPointCamera(CurrentCamera,rfCam.point.x, rfCam.point.y, rfCam.point.z);
  708.           if(retcam==NULL) MessageBox(CurrentWindow, "ERROR Point Camera", WINDOWTITLE,MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION);
  709.           retcam = RwSetCameraViewwindow(CurrentCamera, rfCam.vw_width, rfCam.vw_height );
  710.           if(retcam==NULL) MessageBox(CurrentWindow, "ERROR ViewWindow", WINDOWTITLE,MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION);
  711.         RenderScene(CurrentWindow);
  712.         break; 
  713.            
  714.         case IDOK:
  715.           retcam=RwSetCameraPosition(CurrentCamera, rfCam.pos.x, rfCam.pos.y, rfCam.pos.z);
  716.           if(retcam==NULL) MessageBox(CurrentWindow, "ERROR Position", WINDOWTITLE,MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION);
  717.           retcam=RwPointCamera(CurrentCamera,rfCam.point.x, rfCam.point.y, rfCam.point.z);
  718.           if(retcam==NULL) MessageBox(CurrentWindow, "ERROR Point Camera", WINDOWTITLE,MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION);
  719.           retcam = RwSetCameraViewwindow(CurrentCamera, rfCam.vw_width, rfCam.vw_height );
  720.           if(retcam==NULL) MessageBox(CurrentWindow, "ERROR ViewWindow", WINDOWTITLE,MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION);
  721.         EndDialog(dialog, IDOK);
  722.        break; 
  723.                     
  724.        case IDCANCEL:
  725.            EndDialog(dialog, IDCANCEL);
  726.        break;
  727.        }
  728.       return TRUE;
  729.     }
  730.     }
  731.     return FALSE;
  732. }
  733.  
  734.  
  735.  
  736.  
  737. BOOL CALLBACK
  738. RotateDlgProc(HWND dialog, UINT message, WPARAM wParam, LPARAM lParam)
  739. {
  740.  
  741.  
  742.     char                buffer[10];
  743.     HWND                scrollBar=NULL;
  744.     int                 code;
  745.     int                 pos=0;
  746.     int                 newPos;
  747.     int                 channel;
  748.     int                 id,maxs=0;
  749.     float    fvalue;
  750.     
  751.     switch (message)
  752.     {
  753.         case WM_INITDIALOG:
  754.  
  755.           switch(rfRot.combine) {
  756.           case rwPRECONCAT:
  757.             CheckRadioButton(dialog,IDR_COMBINE_PRE,IDR_COMBINE_POST,IDR_COMBINE_PRE); 
  758.           break;
  759.           case rwPOSTCONCAT: 
  760.            CheckRadioButton(dialog,IDR_COMBINE_PRE,IDR_COMBINE_POST,IDR_COMBINE_POST);
  761.           break;
  762.           }
  763.             
  764.             SetScrollRange(GetDlgItem(dialog, IDC_RR_SLIDER), SB_CTL, 0, 500, FALSE);
  765.             SetScrollRange(GetDlgItem(dialog, IDC_RX_SLIDER), SB_CTL, -MAX_RSCROLL/2, MAX_RSCROLL/2, FALSE);
  766.             SetScrollRange(GetDlgItem(dialog, IDC_RY_SLIDER), SB_CTL, -MAX_RSCROLL/2, MAX_RSCROLL/2, FALSE);
  767.             SetScrollRange(GetDlgItem(dialog, IDC_RZ_SLIDER), SB_CTL, -MAX_RSCROLL/2, MAX_RSCROLL/2, FALSE);
  768.             SetScrollRange(GetDlgItem(dialog, IDC_RT_SLIDER), SB_CTL, -180,180, FALSE);
  769.             
  770.             SetScrollPos(GetDlgItem(dialog, IDC_RR_SLIDER),   SB_CTL, rfRot.repeat, FALSE);
  771.             SetScrollPos(GetDlgItem(dialog, IDC_RX_SLIDER),   SB_CTL, (int)(10*rfRot.x), FALSE);
  772.             SetScrollPos(GetDlgItem(dialog, IDC_RY_SLIDER),   SB_CTL, (int)(10*rfRot.y), FALSE);
  773.             SetScrollPos(GetDlgItem(dialog, IDC_RZ_SLIDER),   SB_CTL, (int)(10*rfRot.z), FALSE);
  774.             SetScrollPos(GetDlgItem(dialog, IDC_RT_SLIDER),   SB_CTL, (int)rfRot.val, FALSE);
  775.             
  776.             /*
  777.              * Initialize the edit controls.
  778.              */
  779.             sprintf(buffer, "%4d", rfRot.repeat);
  780.             SetDlgItemText(dialog, IDC_RR_EDIT, buffer);
  781.             sprintf(buffer, "%2.1f", rfRot.x);
  782.             SetDlgItemText(dialog, IDC_RX_EDIT, buffer);
  783.             sprintf(buffer, "%2.1f", rfRot.y);
  784.             SetDlgItemText(dialog, IDC_RY_EDIT, buffer);
  785.             sprintf(buffer, "%2.1f", rfRot.z);
  786.             SetDlgItemText(dialog, IDC_RZ_EDIT, buffer);
  787.             sprintf(buffer, "%3d", rfRot.val);
  788.             SetDlgItemText(dialog, IDC_RT_EDIT, buffer);
  789.             return FALSE;
  790.             
  791.         case WM_HSCROLL:
  792. #if       defined(WIN32)
  793.             code     = (int)LOWORD(wParam);
  794.             newPos    = (int)HIWORD(wParam);
  795.             scrollBar = (HWND)lParam;
  796.             id        = (int)GetWindowLong(scrollBar, GWL_ID);
  797. #else
  798.             code      = (int)wParam;
  799.             newPos    = (int)LOWORD(lParam);
  800.             scrollBar = (HWND)HIWORD(lParam);
  801.             id        = (int)GetWindowWord(scrollBar, GWW_ID);
  802. #endif            
  803.   
  804.             /* 
  805.              * As we preview continuously SB_ENDSCROLL is not important to us.
  806.              */
  807.             if (code == SB_ENDSCROLL) return TRUE;
  808.             
  809.             /*
  810.              * Update the scroll bar.
  811.              */
  812.            switch (id)
  813.             {
  814.              case IDC_RX_SLIDER: case IDC_RY_SLIDER:case IDC_RZ_SLIDER:
  815.               maxs = MAX_RSCROLL;
  816.              break;
  817.              case IDC_RT_SLIDER:
  818.               maxs = 1000;
  819.              break;
  820.              case IDC_RR_SLIDER:
  821.               maxs = 360;
  822.              break;
  823.              }
  824.              
  825.             switch (code)
  826.             {
  827.                 case SB_BOTTOM:        pos =  maxs;    break;
  828.                 case SB_LINEDOWN:      pos += maxs/10;      break;
  829.                 case SB_LINEUP:        pos -= maxs/10;      break;
  830.                 case SB_PAGEDOWN:      pos += maxs/2;     break;
  831.                 case SB_PAGEUP:        pos -= maxs/2;     break;
  832.                 case SB_THUMBTRACK:    pos =  newPos; break;
  833.                 case SB_THUMBPOSITION: pos =  newPos; break;
  834.                 case SB_TOP:           pos =  0;      break;
  835.             }
  836.             
  837.             /*
  838.              * Clamp the position to the valid range.
  839.              */
  840.             if (pos < -maxs/2) pos = -maxs/2;
  841.             else if (pos > maxs/2) pos = maxs/2;
  842.             SetScrollPos(scrollBar, SB_CTL, pos, TRUE);
  843.             
  844.             /*
  845.              * Compute the new translation(depending on which channel has changed)
  846.              * and update the appropriate edit control.
  847.              */
  848.             switch (id)
  849.             {
  850.                 case IDC_RR_SLIDER:
  851.                     sprintf(buffer, "%3d", pos);
  852.                     SetDlgItemText(dialog, IDC_RR_EDIT, buffer);
  853.                     rfRot.repeat = pos;
  854.                 break;
  855.                 case IDC_RX_SLIDER:
  856.                     sprintf(buffer, "%2.1f", (float)pos/10);
  857.                     SetDlgItemText(dialog, IDC_RX_EDIT, buffer);
  858.                     rfRot.x = (float)pos/10;
  859.                     break;
  860.                 case IDC_RY_SLIDER:
  861.                     sprintf(buffer, "%2.1f", (float)pos/10);
  862.                     SetDlgItemText(dialog, IDC_RY_EDIT, buffer);
  863.                     rfRot.y = (float)pos/10;
  864.                     break;
  865.                 case IDC_RZ_SLIDER:
  866.                     sprintf(buffer, "%2.1f", (float)pos/10);
  867.                     SetDlgItemText(dialog, IDC_RZ_EDIT, buffer);
  868.                     rfRot.z = (float)pos/10;
  869.                     break;
  870.                 case IDC_RT_SLIDER:
  871.                     sprintf(buffer, "%3d", pos);
  872.                     SetDlgItemText(dialog, IDC_RT_EDIT, buffer);
  873.                     rfRot.val = pos;
  874.                     break;
  875.    
  876.             }
  877.            return TRUE;
  878.                
  879.           case WM_COMMAND:
  880.         {
  881. #ifdef WIN32
  882.              HWND hwndCtl = (HWND) lParam;
  883.             WORD wID = LOWORD(wParam);
  884.             WORD wNotifyCode = HIWORD(wParam);
  885. #else
  886.             HWND hwndCtl = (HWND) LOWORD(lParam);
  887.             WORD wID = wParam;
  888.             WORD wNotifyCode = HIWORD(lParam);
  889. #endif
  890.             switch (wID)
  891.             {
  892.                 case IDC_RX_EDIT:
  893.                 case IDC_RY_EDIT:
  894.                 case IDC_RZ_EDIT:
  895.                        /*
  896.                      * For the edit controls we only take any notice when the
  897.                      * control loses the input focus.
  898.                      */
  899.                     if (wNotifyCode == EN_KILLFOCUS)
  900.                     {
  901.                         /*
  902.                          * Get the edit control's text.
  903.                          */
  904.                         GetDlgItemText(dialog, wID, buffer, sizeof(buffer));
  905.                         
  906.                         /*
  907.                          * Ensure its a valid value.
  908.                          */
  909.                         
  910.                         if( (sscanf(buffer, "%f", &fvalue) == 1) &&
  911.                             (fvalue >= -MAX_RSCROLL/2) && (fvalue <= MAX_RSCROLL/2))
  912.                         {
  913.                             /*
  914.                              * Build the new current tanslation and update the appropriate
  915.                              * slider.
  916.                              */
  917.                             switch (wID)
  918.                             {
  919.                                 case IDC_RX_EDIT:
  920.                                     scrollBar = GetDlgItem(dialog, IDC_RX_SLIDER);
  921.                                     rfRot.x = fvalue;
  922.                                     break;
  923.                                 case IDC_RY_EDIT:
  924.                                     scrollBar = GetDlgItem(dialog, IDC_RY_SLIDER);
  925.                                     rfRot.y = fvalue;
  926.                                     break;
  927.                                 case IDC_RZ_EDIT:
  928.                                     scrollBar = GetDlgItem(dialog, IDC_RZ_SLIDER);
  929.                                     rfRot.z = fvalue;
  930.                                     break;
  931.                             }
  932.                             SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*10), TRUE);
  933.                         }
  934.                         else
  935.                         {
  936.                             /*
  937.                              * Not valid, put the existing value back.
  938.                              */
  939.                             switch (wID)
  940.                             {
  941.                                 case IDC_RX_EDIT: scrollBar = GetDlgItem(dialog, IDC_RX_SLIDER); break;
  942.                                 case IDC_RY_EDIT: scrollBar = GetDlgItem(dialog, IDC_RY_SLIDER); break;
  943.                                 case IDC_RZ_EDIT: scrollBar = GetDlgItem(dialog, IDC_RZ_SLIDER); break;
  944.                             }
  945.                             channel = GetScrollPos(scrollBar, SB_CTL);
  946.                             sprintf(buffer, "%2.1f", (float)channel/10);
  947.                             SetDlgItemText(dialog, wID, buffer);
  948.                         }
  949.                     }
  950.                     break;
  951.                                
  952.                 case IDC_RT_EDIT:     case IDC_RR_EDIT:
  953.                     /*
  954.                      * For the edit controls we only take any notice when the
  955.                      * control loses the input focus.
  956.                      */
  957.                     if (wNotifyCode == EN_KILLFOCUS)
  958.                     {
  959.                         /*
  960.                          * Get the edit control's text.
  961.                          */
  962.                         GetDlgItemText(dialog, wID, buffer, sizeof(buffer));
  963.                         
  964.                         /*
  965.                          * Ensure its a valid value.
  966.                          */
  967.                         if ((sscanf(buffer, "%d", &channel) == 1) &&
  968.                             (channel >= -180) && (channel <= 180))
  969.                         {
  970.     
  971.                             switch(wParam) {
  972.                               case IDC_RT_EDIT:
  973.                                scrollBar = GetDlgItem(dialog, IDC_RT_SLIDER);
  974.                                rfRot.val = channel;
  975.                               break;
  976.                               case IDC_RR_EDIT:
  977.                                scrollBar = GetDlgItem(dialog, IDC_RR_SLIDER);
  978.                                rfRot.repeat = channel;
  979.                               break;
  980.                              }
  981.                            SetScrollPos(scrollBar, SB_CTL, channel, TRUE);
  982.                         }
  983.                         else
  984.                         {
  985.                             switch(wID) {
  986.                               case IDC_RT_EDIT:
  987.                                scrollBar = GetDlgItem(dialog, IDC_RT_SLIDER);
  988.                               break;
  989.                               case IDC_RR_EDIT:
  990.                                scrollBar = GetDlgItem(dialog, IDC_RR_SLIDER);
  991.                               break;
  992.                              }
  993.                             channel = GetScrollPos(scrollBar, SB_CTL);
  994.                             sprintf(buffer, "%d", channel);
  995.                             SetDlgItemText(dialog, wID, buffer);
  996.                         }
  997.                     }
  998.                     break;
  999.                     
  1000.                 case IDOK:
  1001.                  if(IsDlgButtonChecked(dialog,IDR_COMBINE_PRE)) rfRot.combine=rwPRECONCAT;
  1002.                   else if(IsDlgButtonChecked(dialog,IDR_COMBINE_POST)) rfRot.combine=rwPOSTCONCAT;
  1003.                  EndDialog(dialog, IDOK);
  1004.                  break; 
  1005.                     
  1006.                 case IDCANCEL:
  1007.                     EndDialog(dialog, IDCANCEL);
  1008.                     break;
  1009.             }
  1010.             return TRUE;
  1011.  
  1012.         }
  1013.     }
  1014.     return FALSE;
  1015. }
  1016.  
  1017.  
  1018. BOOL CALLBACK
  1019. PRTDlgProc(HWND dialog, UINT message, WPARAM wParam, LPARAM lParam)
  1020. {
  1021.  
  1022.     char                buffer[10];
  1023.     HWND                scrollBar=NULL;
  1024.     int                 code,pos=0,newPos,channel,id,maxs=0;
  1025.     
  1026.     switch (message)
  1027.     {
  1028.         case WM_INITDIALOG:
  1029.  
  1030.             SetScrollRange(GetDlgItem(dialog, IDC_RPRT_SLIDER), SB_CTL, 0, 500, FALSE);
  1031.             SetScrollRange(GetDlgItem(dialog, IDC_APRT_SLIDER), SB_CTL, -180,180, FALSE);
  1032.             
  1033.             SetScrollPos(GetDlgItem(dialog, IDC_RPRT_SLIDER),   SB_CTL, rfLoc.repeat, FALSE);
  1034.             SetScrollPos(GetDlgItem(dialog, IDC_APRT_SLIDER),   SB_CTL, (int)rfLoc.val, FALSE);
  1035.             
  1036.             /* Initialize the edit controls. */
  1037.             sprintf(buffer, "%4d", rfLoc.repeat);
  1038.             SetDlgItemText(dialog, IDC_RPRT_EDIT, buffer);
  1039.             sprintf(buffer, "%3d", rfLoc.val);
  1040.             SetDlgItemText(dialog, IDC_APRT_EDIT, buffer);
  1041.             return FALSE;
  1042.             
  1043.         case WM_HSCROLL:
  1044. #if       defined(WIN32)
  1045.             code      = (int)LOWORD(wParam);
  1046.             newPos    = (int)HIWORD(wParam);
  1047.             scrollBar = (HWND)lParam;
  1048.             id        = (int)GetWindowLong(scrollBar, GWL_ID);
  1049. #else
  1050.             code      = (int)wParam;
  1051.             newPos    = (int)LOWORD(lParam);
  1052.             scrollBar = (HWND)HIWORD(lParam);
  1053.             id        = (int)GetWindowWord(scrollBar, GWW_ID);
  1054. #endif            
  1055.   
  1056.             /*  As we preview continuously SB_ENDSCROLL is not important to us. */
  1057.             if (code == SB_ENDSCROLL) return TRUE;
  1058.             
  1059.             /* Update the scroll bar. */
  1060.            switch (id)
  1061.             {
  1062.              case IDC_RPRT_SLIDER:
  1063.               maxs = 1000;
  1064.              break;
  1065.              case IDC_APRT_SLIDER:
  1066.               maxs = 360;
  1067.              break;
  1068.              }
  1069.              
  1070.             switch (code)
  1071.             {
  1072.                 case SB_BOTTOM:        pos =  maxs;    break;
  1073.                 case SB_LINEDOWN:      pos += maxs/10;      break;
  1074.                 case SB_LINEUP:        pos -= maxs/10;      break;
  1075.                 case SB_PAGEDOWN:      pos += maxs/2;     break;
  1076.                 case SB_PAGEUP:        pos -= maxs/2;     break;
  1077.                 case SB_THUMBTRACK:    pos =  newPos; break;
  1078.                 case SB_THUMBPOSITION: pos =  newPos; break;
  1079.                 case SB_TOP:           pos =  0;      break;
  1080.             }
  1081.             
  1082.             /*
  1083.              * Clamp the position to the valid range.
  1084.              */
  1085.             if (pos < -maxs/2) pos = -maxs/2;
  1086.             else if (pos > maxs/2) pos = maxs/2;
  1087.             SetScrollPos(scrollBar, SB_CTL, pos, TRUE);
  1088.             
  1089.             /*
  1090.              * Compute the new translation(depending on which channel has changed)
  1091.              * and update the appropriate edit control.
  1092.              */
  1093.             switch (id)
  1094.             {
  1095.                 case IDC_RPRT_SLIDER:
  1096.                     sprintf(buffer, "%3d", pos);
  1097.                     SetDlgItemText(dialog, IDC_RPRT_EDIT, buffer);
  1098.                     rfLoc.repeat = pos;
  1099.                 break;
  1100.                 case IDC_APRT_SLIDER:
  1101.                     sprintf(buffer, "%3d", pos);
  1102.                     SetDlgItemText(dialog, IDC_APRT_EDIT, buffer);
  1103.                     rfLoc.val = pos;
  1104.                 break;
  1105.    
  1106.             }
  1107.            return TRUE;
  1108.                
  1109.           case WM_COMMAND:
  1110.           {
  1111. #ifdef WIN32
  1112.              HWND hwndCtl = (HWND) lParam;
  1113.             WORD wID = LOWORD(wParam);
  1114.             WORD wNotifyCode = HIWORD(wParam);
  1115. #else
  1116.             HWND hwndCtl = (HWND) LOWORD(lParam);
  1117.             WORD wID = wParam;
  1118.             WORD wNotifyCode = HIWORD(lParam);
  1119. #endif
  1120.             switch (wID)
  1121.             {
  1122.               case IDC_RPRT_EDIT:     case IDC_APRT_EDIT:
  1123.                     /* For the edit controls we only take any notice when the
  1124.                      * control loses the input focus. */
  1125.                     if (wNotifyCode == EN_KILLFOCUS)
  1126.                     {
  1127.                         /* Get the edit control's text. */
  1128.                         GetDlgItemText(dialog, wID, buffer, sizeof(buffer));
  1129.                         
  1130.                         /* Ensure its a valid value. */
  1131.                         if ((sscanf(buffer, "%d", &channel) == 1) &&
  1132.                             (channel >= -180) && (channel <= 180))
  1133.                         {
  1134.     
  1135.                             switch(wParam) {
  1136.                               case IDC_RPRT_EDIT:
  1137.                                scrollBar = GetDlgItem(dialog, IDC_RPRT_SLIDER);
  1138.                                rfLoc.repeat = channel;
  1139.                               break;
  1140.                               case IDC_APRT_EDIT:
  1141.                                scrollBar = GetDlgItem(dialog, IDC_APRT_SLIDER);
  1142.                                rfLoc.val = channel;
  1143.                               break;
  1144.                              }
  1145.                            SetScrollPos(scrollBar, SB_CTL, channel, TRUE);
  1146.                         }
  1147.                         else
  1148.                         {
  1149.                             switch(wParam) {
  1150.                               case IDC_RPRT_EDIT:
  1151.                                scrollBar = GetDlgItem(dialog, IDC_RPRT_SLIDER);
  1152.                               break;
  1153.                               case IDC_APRT_EDIT:
  1154.                                scrollBar = GetDlgItem(dialog, IDC_APRT_SLIDER);
  1155.                               break;
  1156.                              }
  1157.                             channel = GetScrollPos(scrollBar, SB_CTL);
  1158.                             sprintf(buffer, "%d", channel);
  1159.                             SetDlgItemText(dialog, wID, buffer);
  1160.                         }
  1161.                     }
  1162.                     break;
  1163.                     
  1164.                 case IDOK:
  1165.                    EndDialog(dialog, IDOK);
  1166.                  break; 
  1167.                     
  1168.                 case IDCANCEL:
  1169.                     EndDialog(dialog, IDCANCEL);
  1170.                     break;
  1171.             }
  1172.             return TRUE;
  1173.         }
  1174.     }
  1175.     return FALSE;
  1176. }
  1177.  
  1178.  
  1179. BOOL CALLBACK
  1180. TranslateDlgProc(HWND dialog, UINT message, WPARAM wParam, LPARAM lParam)
  1181. {
  1182.  
  1183.  
  1184.     char                buffer[10];
  1185.     HWND                scrollBar=NULL;
  1186.     int                 code;
  1187.     int                 pos;
  1188.     int                 newPos;
  1189.     int                 channel;
  1190.     int                 id;
  1191.     float    fvalue;
  1192.     
  1193.     switch (message)
  1194.     {
  1195.         case WM_INITDIALOG:
  1196.  
  1197.         switch(rfTran.combine) {
  1198.           case rwPRECONCAT:
  1199.             CheckRadioButton(dialog,IDT_COMBINE_PRE,IDT_COMBINE_POST,IDT_COMBINE_PRE); 
  1200.           break;
  1201.           case rwPOSTCONCAT: 
  1202.            CheckRadioButton(dialog,IDT_COMBINE_PRE,IDT_COMBINE_POST,IDT_COMBINE_POST);
  1203.           break;
  1204.           }
  1205.             
  1206.             /*
  1207.              * Initialize the scrollbars.
  1208.              */
  1209.             SetScrollRange(GetDlgItem(dialog, IDC_TX_SLIDER), SB_CTL, -MAX_SCROLL/2, MAX_SCROLL/2, FALSE);
  1210.             SetScrollRange(GetDlgItem(dialog, IDC_TY_SLIDER), SB_CTL, -MAX_SCROLL/2, MAX_SCROLL/2, FALSE);
  1211.             SetScrollRange(GetDlgItem(dialog, IDC_TZ_SLIDER), SB_CTL, -MAX_SCROLL/2, MAX_SCROLL/2, FALSE);
  1212.             SetScrollPos(GetDlgItem(dialog, IDC_TX_SLIDER),   SB_CTL, (int)(100*rfTran.x), FALSE);
  1213.             SetScrollPos(GetDlgItem(dialog, IDC_TY_SLIDER),   SB_CTL, (int)(100*rfTran.y), FALSE);
  1214.             SetScrollPos(GetDlgItem(dialog, IDC_TZ_SLIDER),   SB_CTL, (int)(100*rfTran.z), FALSE);
  1215.             
  1216.             /*
  1217.              * Initialize the edit controls.
  1218.              */
  1219.             sprintf(buffer, "%2.1f", rfTran.x);
  1220.             SetDlgItemText(dialog, IDC_TX_EDIT, buffer);
  1221.             sprintf(buffer, "%2.1f",rfTran.y);
  1222.             SetDlgItemText(dialog, IDC_TY_EDIT, buffer);
  1223.             sprintf(buffer, "%2.1f", rfTran.z);
  1224.             SetDlgItemText(dialog, IDC_TZ_EDIT, buffer);
  1225.             return FALSE;
  1226.             
  1227.         case WM_HSCROLL:
  1228. #if       defined(WIN32)
  1229.             code      = (int)LOWORD(wParam);
  1230.             newPos    = (int)HIWORD(wParam);
  1231.             scrollBar = (HWND)lParam;
  1232.             id        = (int)GetWindowLong(scrollBar, GWL_ID);
  1233. #else
  1234.             code      = (int)wParam;
  1235.             newPos    = (int)LOWORD(lParam);
  1236.             scrollBar = (HWND)HIWORD(lParam);
  1237.             id        = (int)GetWindowWord(scrollBar, GWW_ID);
  1238. #endif            
  1239.   
  1240.             /* 
  1241.              * As we preview continuously SB_ENDSCROLL is not important to us.
  1242.              */
  1243.             if (code == SB_ENDSCROLL) return TRUE;
  1244.             
  1245.             /*
  1246.              * Update the scroll bar.
  1247.              */
  1248.             pos = GetScrollPos(scrollBar, SB_CTL);
  1249.             switch (code)
  1250.             {
  1251.                 case SB_BOTTOM:        pos =  MAX_SCROLL;    break;
  1252.                 case SB_LINEDOWN:      pos += MAX_SCROLL/10;      break;
  1253.                 case SB_LINEUP:        pos -= MAX_SCROLL/10;      break;
  1254.                 case SB_PAGEDOWN:      pos += MAX_SCROLL/2;     break;
  1255.                 case SB_PAGEUP:        pos -= MAX_SCROLL/2;     break;
  1256.                 case SB_THUMBTRACK:    pos =  newPos; break;
  1257.                 case SB_THUMBPOSITION: pos =  newPos; break;
  1258.                 case SB_TOP:           pos =  0;      break;
  1259.             }
  1260.             
  1261.             /*
  1262.              * Clamp the position to the valid range.
  1263.              */
  1264.             if (pos < -MAX_SCROLL/2) pos = -MAX_SCROLL/2;
  1265.             else if (pos > MAX_SCROLL/2) pos = MAX_SCROLL/2;
  1266.             SetScrollPos(scrollBar, SB_CTL, pos, TRUE);
  1267.             
  1268.             /*
  1269.              * Compute the new translation(depending on which channel has changed)
  1270.              * and update the appropriate edit control.
  1271.              */
  1272.             switch (id)
  1273.             {                             
  1274.                 case IDC_TX_SLIDER:
  1275.                     sprintf(buffer, "%2.1f", (float)pos/100);
  1276.                     SetDlgItemText(dialog, IDC_TX_EDIT, buffer);
  1277.                     rfTran.x = (float)pos/100;
  1278.                     break;
  1279.                 case IDC_TY_SLIDER:
  1280.                     sprintf(buffer, "%2.1f", (float)pos/100);
  1281.                     SetDlgItemText(dialog, IDC_TY_EDIT, buffer);
  1282.                     rfTran.y = (float)pos/100;
  1283.                     break;
  1284.                 case IDC_TZ_SLIDER:
  1285.                     sprintf(buffer, "%2.1f", (float)pos/100);
  1286.                     SetDlgItemText(dialog, IDC_TZ_EDIT, buffer);
  1287.                     rfTran.z = (float)pos/100;
  1288.                     break;
  1289.             }
  1290.            return TRUE;
  1291.                
  1292.           case WM_COMMAND: 
  1293.           {
  1294.  
  1295. #ifdef WIN32
  1296.              HWND hwndCtl = (HWND) lParam;
  1297.             WORD wID = LOWORD(wParam);
  1298.             WORD wNotifyCode = HIWORD(wParam);
  1299. #else
  1300.             HWND hwndCtl = (HWND) LOWORD(lParam);
  1301.             WORD wID = wParam;
  1302.             WORD wNotifyCode = HIWORD(lParam);
  1303. #endif
  1304.             switch (wID)
  1305.             {
  1306.                 case IDC_TX_EDIT:
  1307.                 case IDC_TY_EDIT:
  1308.                 case IDC_TZ_EDIT:
  1309.                     /*
  1310.                      * For the edit controls we only take any notice when the
  1311.                      * control loses the input focus.
  1312.                      */
  1313.                     if (wNotifyCode == EN_KILLFOCUS)
  1314.                     {
  1315.                         /*
  1316.                          * Get the edit control's text.
  1317.                          */
  1318.                         GetDlgItemText(dialog, wID, buffer, sizeof(buffer));
  1319.                         
  1320.                         /*
  1321.                          * Ensure its a valid value.
  1322.                          */
  1323.                         
  1324.                         if( (sscanf(buffer, "%f", &fvalue) == 1) &&
  1325.                             (fvalue >= -MAX_SCROLL/2) && (fvalue <= MAX_SCROLL/2))
  1326.                         {
  1327.                             /*
  1328.                              * Build the new current tanslation and update the appropriate
  1329.                              * slider.
  1330.                              */
  1331.                             switch (wID)
  1332.                             {
  1333.                                 case IDC_TX_EDIT:
  1334.                                     scrollBar = GetDlgItem(dialog, IDC_TX_SLIDER);
  1335.                                     rfTran.x = fvalue;
  1336.                                     break;
  1337.                                 case IDC_TY_EDIT:
  1338.                                     scrollBar = GetDlgItem(dialog, IDC_TY_SLIDER);
  1339.                                     rfTran.y = fvalue;
  1340.                                     break;
  1341.                                 case IDC_TZ_EDIT:
  1342.                                     scrollBar = GetDlgItem(dialog, IDC_TZ_SLIDER);
  1343.                                     rfTran.z = fvalue;
  1344.                                     break;
  1345.                             }
  1346.                             SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*100), TRUE);
  1347.                         }
  1348.                         else
  1349.                         {
  1350.                             /*
  1351.                              * Not valid, put the existing value back.
  1352.                              */
  1353.                             switch (wID)
  1354.                             {
  1355.                                 case IDC_TX_EDIT: scrollBar = GetDlgItem(dialog, IDC_TX_SLIDER); break;
  1356.                                 case IDC_TY_EDIT: scrollBar = GetDlgItem(dialog, IDC_TY_SLIDER); break;
  1357.                                 case IDC_TZ_EDIT: scrollBar = GetDlgItem(dialog, IDC_TZ_SLIDER); break;
  1358.                             }
  1359.                             channel = GetScrollPos(scrollBar, SB_CTL);
  1360.                             sprintf(buffer, "%2.1f", (float)channel/100);
  1361.                             SetDlgItemText(dialog, wID, buffer);
  1362.                         }
  1363.                     }
  1364.                     break;
  1365.                     
  1366.                 case IDOK:
  1367.                  if(IsDlgButtonChecked(dialog,IDT_COMBINE_PRE)) rfTran.combine=rwPRECONCAT;
  1368.                   else if(IsDlgButtonChecked(dialog,IDT_COMBINE_POST)) rfTran.combine=rwPOSTCONCAT;
  1369.                   EndDialog(dialog, IDOK);
  1370.                     break; 
  1371.                     
  1372.                 case IDCANCEL:
  1373.                     EndDialog(dialog, IDCANCEL);
  1374.                     break;
  1375.             }
  1376.             return TRUE;
  1377.         }
  1378.     }
  1379.     return FALSE;
  1380. }
  1381.  
  1382. BOOL CALLBACK
  1383. ScaleDlgProc(HWND dialog, UINT message, WPARAM wParam, LPARAM lParam)
  1384. {
  1385.  
  1386.     char                buffer[10];
  1387.     HWND                scrollBar=NULL;
  1388.     int                 code;
  1389.     int                 pos;
  1390.     int                 newPos;
  1391.     int                 channel;
  1392.     int                 id;
  1393.     float    fvalue;
  1394.     
  1395.     switch (message)
  1396.     {
  1397.         case WM_INITDIALOG:
  1398.  
  1399.         switch(rfScale.combine) {
  1400.           case rwPRECONCAT:
  1401.             CheckRadioButton(dialog,IDS_COMBINE_PRE,IDS_COMBINE_POST,IDS_COMBINE_PRE); 
  1402.           break;
  1403.           case rwPOSTCONCAT: 
  1404.            CheckRadioButton(dialog,IDS_COMBINE_PRE,IDS_COMBINE_POST,IDS_COMBINE_POST);
  1405.           break;
  1406.           }
  1407.             
  1408.             /*
  1409.              * Initialize the scrollbars.
  1410.              */
  1411.             SetScrollRange(GetDlgItem(dialog, IDC_SX_SLIDER), SB_CTL, -MAX_SCROLLS/2, MAX_SCROLLS/2, FALSE);
  1412.             SetScrollRange(GetDlgItem(dialog, IDC_SY_SLIDER), SB_CTL, -MAX_SCROLLS/2, MAX_SCROLLS/2, FALSE);
  1413.             SetScrollRange(GetDlgItem(dialog, IDC_SZ_SLIDER), SB_CTL, -MAX_SCROLLS/2, MAX_SCROLLS/2, FALSE);
  1414.             SetScrollPos(GetDlgItem(dialog, IDC_SX_SLIDER),   SB_CTL, (int)(100*rfScale.x), FALSE);
  1415.             SetScrollPos(GetDlgItem(dialog, IDC_SY_SLIDER),   SB_CTL, (int)(100*rfScale.y), FALSE);
  1416.             SetScrollPos(GetDlgItem(dialog, IDC_SZ_SLIDER),   SB_CTL, (int)(100*rfScale.z), FALSE);
  1417.             
  1418.             /*
  1419.              * Initialize the edit controls.
  1420.              */
  1421.             sprintf(buffer, "%3.2f", rfScale.x);
  1422.             SetDlgItemText(dialog, IDC_SX_EDIT, buffer);
  1423.             sprintf(buffer, "%3.2f",rfScale.y);
  1424.             SetDlgItemText(dialog, IDC_SY_EDIT, buffer);
  1425.             sprintf(buffer, "%3.2f", rfScale.z);
  1426.             SetDlgItemText(dialog, IDC_SZ_EDIT, buffer);
  1427.             return FALSE;
  1428.             
  1429.         case WM_HSCROLL:
  1430. #if       defined(WIN32)
  1431.             code      = (int)LOWORD(wParam);
  1432.             newPos    = (int)HIWORD(wParam);
  1433.             scrollBar = (HWND)lParam;
  1434.             id        = (int)GetWindowLong(scrollBar, GWL_ID);
  1435. #else
  1436.             code      = (int)wParam;
  1437.             newPos    = (int)LOWORD(lParam);
  1438.             scrollBar = (HWND)HIWORD(lParam);
  1439.             id        = (int)GetWindowWord(scrollBar, GWW_ID);
  1440. #endif            
  1441.   
  1442.             /* 
  1443.              * As we preview continuously SB_ENDSCROLL is not important to us.
  1444.              */
  1445.             if (code == SB_ENDSCROLL) return TRUE;
  1446.             
  1447.             /*
  1448.              * Update the scroll bar.
  1449.              */
  1450.             pos = GetScrollPos(scrollBar, SB_CTL);
  1451.             switch (code)
  1452.             {
  1453.                 case SB_BOTTOM:        pos =  MAX_SCROLLS;    break;
  1454.                 case SB_LINEDOWN:      pos += MAX_SCROLLS/10;      break;
  1455.                 case SB_LINEUP:        pos -= MAX_SCROLLS/10;      break;
  1456.                 case SB_PAGEDOWN:      pos += MAX_SCROLLS/2;     break;
  1457.                 case SB_PAGEUP:        pos -= MAX_SCROLLS/2;     break;
  1458.                 case SB_THUMBTRACK:    pos =  newPos; break;
  1459.                 case SB_THUMBPOSITION: pos =  newPos; break;
  1460.                 case SB_TOP:           pos =  0;      break;
  1461.             }
  1462.             
  1463.             /*
  1464.              * Clamp the position to the valid range.
  1465.              */
  1466.             if (pos < -MAX_SCROLLS/2) pos = -MAX_SCROLLS/2;
  1467.             else if (pos > MAX_SCROLLS/2) pos = MAX_SCROLLS/2;
  1468.             SetScrollPos(scrollBar, SB_CTL, pos, TRUE);
  1469.             
  1470.             /*
  1471.              * Compute the new scale depending on which channel has changed)
  1472.              * and update the appropriate edit control.
  1473.              */
  1474.             switch (id)
  1475.             {                             
  1476.                 case IDC_SX_SLIDER:
  1477.                     sprintf(buffer, "%3.2f", (float)pos/100);
  1478.                     SetDlgItemText(dialog, IDC_SX_EDIT, buffer);
  1479.                     rfScale.x = (float)pos/100;
  1480.                     break;
  1481.                 case IDC_SY_SLIDER:
  1482.                     sprintf(buffer, "%3.2f", (float)pos/100);
  1483.                     SetDlgItemText(dialog, IDC_SY_EDIT, buffer);
  1484.                     rfScale.y = (float)pos/100;
  1485.                     break;
  1486.                 case IDC_SZ_SLIDER:
  1487.                     sprintf(buffer, "%3.2f", (float)pos/100);
  1488.                     SetDlgItemText(dialog, IDC_SZ_EDIT, buffer);
  1489.                     rfScale.z = (float)pos/100;
  1490.                     break;
  1491.             }
  1492.            return TRUE;
  1493.                
  1494.           case WM_COMMAND:
  1495.         {
  1496. #ifdef WIN32
  1497.              HWND hwndCtl = (HWND) lParam;
  1498.             WORD wID = LOWORD(wParam);
  1499.             WORD wNotifyCode = HIWORD(wParam);
  1500. #else
  1501.             HWND hwndCtl = (HWND) LOWORD(lParam);
  1502.             WORD wID = wParam;
  1503.             WORD wNotifyCode = HIWORD(lParam);
  1504. #endif
  1505.             switch (wID)
  1506.             {
  1507.                 case IDC_SX_EDIT:
  1508.                 case IDC_SY_EDIT:
  1509.                 case IDC_SZ_EDIT:
  1510.                     /*
  1511.                      * For the edit controls we only take any notice when the
  1512.                      * control loses the input focus.
  1513.                      */
  1514.                     if (wNotifyCode == EN_KILLFOCUS)
  1515.                     {
  1516.                         /*
  1517.                          * Get the edit control's text.
  1518.                          */
  1519.                         GetDlgItemText(dialog, wID, buffer, sizeof(buffer));
  1520.                         
  1521.                         /*
  1522.                          * Ensure its a valid value.
  1523.                          */
  1524.                         
  1525.                         if( (sscanf(buffer, "%f", &fvalue) == 1) &&
  1526.                             (fvalue*100 >= -MAX_SCROLLS/2) && (fvalue*100 <= MAX_SCROLLS/2))
  1527.                         {
  1528.                             /*
  1529.                              * Build the new current tanslation and update the appropriate
  1530.                              * slider.
  1531.                              */
  1532.                             switch (wID)
  1533.                             {
  1534.                                 case IDC_SX_EDIT:
  1535.                                     scrollBar = GetDlgItem(dialog, IDC_SX_SLIDER);
  1536.                                     rfScale.x = fvalue;
  1537.                                     break;
  1538.                                 case IDC_SY_EDIT:
  1539.                                     scrollBar = GetDlgItem(dialog, IDC_SY_SLIDER);
  1540.                                     rfScale.y = fvalue;
  1541.                                     break;
  1542.                                 case IDC_SZ_EDIT:
  1543.                                     scrollBar = GetDlgItem(dialog, IDC_SZ_SLIDER);
  1544.                                     rfScale.z = fvalue;
  1545.                                     break;
  1546.                             }
  1547.                             SetScrollPos(scrollBar, SB_CTL, (int)(fvalue*100), TRUE);
  1548.                         }
  1549.                         else
  1550.                         {
  1551.                             /*
  1552.                              * Not valid, put the existing value back.
  1553.                              */
  1554.                             switch (wID)
  1555.                             {
  1556.                                 case IDC_SX_EDIT: scrollBar = GetDlgItem(dialog, IDC_SX_SLIDER); break;
  1557.                                 case IDC_SY_EDIT: scrollBar = GetDlgItem(dialog, IDC_SY_SLIDER); break;
  1558.                                 case IDC_SZ_EDIT: scrollBar = GetDlgItem(dialog, IDC_SZ_SLIDER); break;
  1559.                             }
  1560.                             channel = GetScrollPos(scrollBar, SB_CTL);
  1561.                             sprintf(buffer, "%3.2f", (float)channel/100);
  1562.                             SetDlgItemText(dialog, wParam, buffer);
  1563.                         }
  1564.                     }
  1565.                     break;
  1566.                     
  1567.                 case IDOK:
  1568.                  if(IsDlgButtonChecked(dialog,IDS_COMBINE_PRE)) rfScale.combine=rwPRECONCAT;
  1569.                   else if(IsDlgButtonChecked(dialog,IDS_COMBINE_POST)) rfScale.combine=rwPOSTCONCAT;
  1570.                   EndDialog(dialog, IDOK);
  1571.                     break; 
  1572.                     
  1573.                 case IDCANCEL:
  1574.                     EndDialog(dialog, IDCANCEL);
  1575.                     break;
  1576.             }
  1577.             return TRUE;
  1578.         }
  1579.     }
  1580.     return FALSE;
  1581. }
  1582.  
  1583.  
  1584. /*
  1585.  * The debug box dialog procedure.
  1586.  */
  1587. BOOL CALLBACK
  1588. DebugDlgProc(HWND dialog, UINT message, WPARAM wParam, LPARAM lParam)
  1589. {
  1590.      lParam = lParam;
  1591.     switch (message)
  1592.     {
  1593.         case WM_INITDIALOG:
  1594.         
  1595.         switch(rfDebug.Severity) {
  1596.           case rwINFORM:
  1597.             CheckRadioButton(dialog,IDC_SEVERITY_INFORM,IDC_SEVERITY_ERROR,IDC_SEVERITY_INFORM); 
  1598.           break;
  1599.           case rwWARNING: 
  1600.            CheckRadioButton(dialog,IDC_SEVERITY_INFORM,IDC_SEVERITY_ERROR,IDC_SEVERITY_WARNING);
  1601.           break;
  1602.           case rwERROR: 
  1603.             CheckRadioButton(dialog,IDC_SEVERITY_INFORM,IDC_SEVERITY_ERROR,IDC_SEVERITY_ERROR); 
  1604.           break;
  1605.           }
  1606.  
  1607.         if(rfDebug.Message == rwDISABLE) CheckDlgButton(dialog,IDC_DEBUG_MESSAGE, 0);
  1608.           else  CheckDlgButton(dialog,IDC_DEBUG_MESSAGE, 1);
  1609.         if(rfDebug.Assertion == rwDISABLE) CheckDlgButton(dialog,IDC_DEBUG_ASSERTION, 0);
  1610.           else  CheckDlgButton(dialog,IDC_DEBUG_ASSERTION, 1); 
  1611.         if(rfDebug.Script == rwDISABLE) CheckDlgButton(dialog,IDC_DEBUG_SCRIPT, 0);
  1612.           else  CheckDlgButton(dialog,IDC_DEBUG_SCRIPT, 1); 
  1613.         if(rfDebug.Trace == rwDISABLE) CheckDlgButton(dialog,IDC_DEBUG_TRACE, 0);
  1614.           else  CheckDlgButton(dialog,IDC_DEBUG_TRACE, 1);
  1615.         if(rfDebug.Output == rwDISABLE) CheckDlgButton(dialog,IDC_DEBUG_OUTPUT, 0);
  1616.           else  CheckDlgButton(dialog,IDC_DEBUG_OUTPUT, 1);
  1617.          return TRUE;
  1618.         
  1619.         case WM_COMMAND:
  1620. #ifdef WIN32
  1621.             switch (LOWORD(wParam))
  1622. #else
  1623.             switch (wParam)
  1624. #endif
  1625.             {
  1626.                 case IDOK:
  1627.                 
  1628.                  if(IsDlgButtonChecked(dialog,IDC_SEVERITY_INFORM)) rfDebug.Severity=rwINFORM;
  1629.                   else if(IsDlgButtonChecked(dialog,IDC_SEVERITY_WARNING)) rfDebug.Severity=rwWARNING;
  1630.                    else if(IsDlgButtonChecked(dialog,IDC_SEVERITY_ERROR)) rfDebug.Severity=rwERROR;
  1631.                  RwSetDebugSeverity(rfDebug.Severity);
  1632.                  
  1633.                  
  1634.                 if(IsDlgButtonChecked(dialog,IDC_DEBUG_MESSAGE))  {
  1635.                  rfDebug.Message=rwENABLE;
  1636.                  RwSetDebugMessageState(rwON);
  1637.                  }
  1638.                   else {
  1639.                    rfDebug.Message=rwDISABLE;
  1640.                    RwSetDebugMessageState(rwOFF);
  1641.                    }
  1642.  
  1643.                 if(IsDlgButtonChecked(dialog,IDC_DEBUG_ASSERTION)) {
  1644.                  rfDebug.Assertion=rwENABLE;
  1645.                  RwSetDebugAssertionState(rwON);
  1646.                  }
  1647.                   else {
  1648.                    rfDebug.Assertion=rwDISABLE;
  1649.                    RwSetDebugAssertionState(rwOFF);
  1650.                    }            
  1651.                 if(IsDlgButtonChecked(dialog,IDC_DEBUG_SCRIPT))  {
  1652.                  rfDebug.Script=rwENABLE;
  1653.                  RwSetDebugScriptState(rwON);
  1654.                  }
  1655.                   else {
  1656.                    rfDebug.Script=rwDISABLE;
  1657.                    RwSetDebugScriptState(rwOFF);
  1658.                    }            
  1659.                 if(IsDlgButtonChecked(dialog,IDC_DEBUG_TRACE))  {
  1660.                  rfDebug.Trace=rwENABLE;
  1661.                  RwSetDebugTraceState(rwON);
  1662.                  }
  1663.                   else {
  1664.                    rfDebug.Trace=rwDISABLE;
  1665.                    RwSetDebugTraceState(rwOFF);
  1666.                    }
  1667.                 if(IsDlgButtonChecked(dialog,IDC_DEBUG_OUTPUT)) {
  1668.                  rfDebug.Output=rwENABLE;
  1669.                  RwSetDebugOutputState(rwON);
  1670.                  }
  1671.                   else {
  1672.                    rfDebug.Output=rwDISABLE;
  1673.                    RwSetDebugOutputState(rwOFF);
  1674.                    }
  1675.                           
  1676.                             
  1677.                     EndDialog(dialog, IDOK);
  1678.                     break; 
  1679.                 case IDCANCEL:
  1680.                     EndDialog(dialog, IDCANCEL);
  1681.                     break;         }
  1682.             return TRUE;
  1683.     }
  1684.     
  1685.     return FALSE;
  1686. }
  1687.  
  1688.