home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sphigs.lha / SPHIGS / examples / SPHDEMO_main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-26  |  8.5 KB  |  344 lines

  1. #include "HEADERS.h"
  2. #include "SPHDEMO.h"
  3. #include "SPHDEMO_struct.h"
  4. #include "SPHDEMO_view.h"
  5.  
  6. /** NOTE TO READER
  7. This program was originally written on the Mac and included dialog boxes
  8. and help windows that taught the concepts of viewing.  That's why there
  9. are stubs and unused variables in this main module, which used to handle
  10. all the Mac-specific user interface widgets.
  11. **/
  12.  
  13.  
  14. static int currenderitem = 4, curchimneymenuitem = 'c';
  15. static int curgridmenuitem = 1, curvpmenuitem = 'A';
  16. static int curCamDialogID = 0;
  17.  
  18. static int curHelpDialogID = 0;
  19.  
  20.  
  21. #define rendermenuID   200
  22. #define cameramenuID   202
  23. #define chimneymenuID  201
  24. #define viewportmenuID 204
  25. #define pickmenuID     205
  26. #define gridmenuID     203
  27. #define modelmenuID    206
  28. #define applemenuID    209
  29.  
  30.  
  31.  
  32. static void InstallCameraDialog (int whichitem)
  33. {
  34.    curCamDialogID = whichitem + 300;
  35.    switch (whichitem) {
  36.     case 1:
  37.       fprintf (stderr, "You are now controlling the VRP along the UVN axes...\n");
  38.       break;
  39.     case 2:
  40.       fprintf (stderr, "You are now controlling the VRP along the XYZ axes...\n");
  41.       break;
  42.     case 3:
  43.       fprintf (stderr, "You are now controlling the VPN...\n\
  44.       You can 'yaw' (rotate about the V axis) by using the S and D keys\n\
  45.       You can 'pitch' (rotate about the U axis) by using the E and X keys\n");
  46.       break;
  47.     case 4:
  48.       fprintf (stderr, "You are now controlling the PRP...\n\
  49.       Move it towards the viewplane (reduce the focal length) using - key\n\
  50.       Move it away from the viewplane (increase focal length) using = key\n");
  51.       break;
  52.     case 5:
  53.       fprintf (stderr, "You are now controlling the Front clipping plane\n\
  54.       Use = to bring it towards eye, - to push away from eye\n");
  55.       break;
  56.     case 6:
  57.       fprintf (stderr, "You are now controlling the Back clipping plane\n\
  58.       Use = to bring it towards eye, - to push away from eye\n");
  59.       break;
  60.    }      
  61. }
  62.  
  63. static void InstallHelpDialog (int whichmenuid)
  64. {
  65. }
  66.  
  67.       
  68. static int motion_granularity = 30;
  69.          
  70. static void DisplayMotionGranularity (void)
  71. {
  72.    fprintf (stderr,  "Current motion granularity is %d\n", motion_granularity);
  73. }
  74.  
  75.  
  76.  
  77. static void AddGridInFrontOfRoot (int structID, int viewID)
  78. {
  79.    SPH_unpostRoot (structID, viewID);
  80.    SPH_postRoot (GRID_STRUCT, viewID);
  81.    SPH_postRoot (structID, viewID);
  82. }
  83.  
  84.  
  85.  
  86.  
  87. static void ChangeCameraOnAxis (int axis, double bias)
  88. {
  89.    double pitch=0.0, yaw=0.0;
  90.    switch (curCamDialogID) {
  91.     case 301:
  92.       ChangeVRP_relativeUVN (bias*motion_granularity, axis); 
  93.       break;
  94.     case 302:
  95.       ChangeVRP_relativeWC (bias*motion_granularity, axis); 
  96.       break;
  97.     case 303:
  98.       switch (axis) {
  99.        case X_AXIS: 
  100.      yaw = bias * motion_granularity; break;
  101.        case Y_AXIS: 
  102.      pitch = bias * motion_granularity; break;
  103.        default:
  104.      return;
  105.       }
  106.       ChangeVPN (pitch, yaw); 
  107.       break;
  108.     case 304:
  109.       if (axis != Z_AXIS) 
  110.      return;
  111.       ChangePRP (bias*motion_granularity);
  112.       break;
  113.     case 305:
  114.       if (axis != Z_AXIS) 
  115.      return;
  116.       ChangeFrontClipPlane (bias*motion_granularity);
  117.       break;
  118.     case 306:
  119.       if (axis != Z_AXIS) 
  120.      return;
  121.       ChangeBackClipPlane (bias*motion_granularity);
  122.       break;
  123.    }
  124.    ShowUsingNewView1 ();
  125. }
  126.  
  127.  
  128.  
  129. static void PrintCorrelationInfo (pickInformation *pinfo)
  130. {
  131.    if (pinfo->pickLevel == 4)
  132.       printf ("You picked the chimney on ");
  133.    else
  134.       printf ("You picked ");
  135.  
  136.    printf ("house #%d ", 1 + (int)((pinfo->path[1].elementIndex-1)/3));
  137.    
  138.    printf ("on street #%d.\n", 1 + (int)(pinfo->path[0].elementIndex/2));
  139. }
  140.  
  141.  
  142.  
  143. main (argc, argv)
  144. int argc;
  145. char **argv;
  146. {
  147.    double bias;
  148.    long result;
  149.    int whichmenu, whichitem, keycode;
  150.    int numplanes=7, numshades=10;
  151.    FILE *debugfile;
  152.    char buffer[100];
  153.    boolean READ_FROM_STDIN = FALSE;
  154.    locator_measure locmeas;
  155.    pickInformation pickinfo;
  156.  
  157.  
  158.    if (argc > 1)
  159.       if ( ! strcmp(argv[1],"-stdin"))
  160.      READ_FROM_STDIN = TRUE;
  161.    
  162.    /* STARTUP SPHIGS */
  163.    if (READ_FROM_STDIN) {
  164.       printf ("\nPlease enter number of framebuffer planes to allocate:\n");
  165.       scanf ("%d", &numplanes);
  166.       printf ("\nPlease enter number of shades per flexicolor:\n");
  167.       printf 
  168.      ("   (Note: this affects how many different flexicolors will be ");
  169.       printf ("available.)\n");
  170.       scanf ("%d", &numshades);
  171.    }
  172.  
  173.    SPH_begin (850,680, numplanes, numshades);
  174.  
  175.    printf ("\nThis is what I was able to provide re: colors...\n");
  176.    printf ("     Number of custom, flexible colors: %d\n", NUM_OF_FLEXICOLORS);
  177.    printf ("     Number of custom, non-flexible colors: %d\n\n", 
  178.        (NUM_OF_APPL_SETTABLE_COLORS-NUM_OF_FLEXICOLORS));
  179.    
  180.    SPH_setImplicitRegenerationMode (SUPPRESSED);
  181.  
  182.    /* We hope there are enough flexicolors for these. */
  183.    SPH_loadCommonColor (2, "yellow");
  184.    SPH_loadCommonColor (3, "green");
  185.    SPH_loadCommonColor (4, "turquoise");
  186.    SPH_loadCommonColor (5, "pink");
  187.    SPH_loadCommonColor (6, "goldenrod");
  188.    SPH_loadCommonColor (7, "firebrick");
  189.  
  190.    /* But these need not be flexicolors. */
  191.    SPH_loadCommonColor (red, "red");
  192.    SPH_loadCommonColor (grey, "lightgrey");
  193.    SPH_loadCommonColor (orange, "orange");
  194.    SPH_loadCommonColor (yellow, "yellow");
  195.    SPH_loadCommonColor (limegreen, "yellowgreen");
  196.    SPH_loadCommonColor (forestgreen, "forestgreen");
  197.    SPH_loadCommonColor (blue, "blue");
  198.    
  199.    InitAllViews();
  200.    BuildEverything ();
  201.    
  202.    DisplayAllViews ();
  203.    ShowUsingNewView1();
  204.    SPH_postRoot (NEIGHBORHOOD_STRUCT, PERSPECTIVE_VIEW);
  205.    
  206.    
  207.    /* INITIALIZE THE GRANULARITY DIALOG BOX */
  208.    DisplayMotionGranularity();
  209.    
  210.    InstallCameraDialog (2);
  211.    
  212.    SRGP_setKeyboardProcessingMode (RAW);
  213.    SRGP_setInputMode (KEYBOARD, EVENT);
  214.    SRGP_setInputMode (LOCATOR, EVENT);
  215.    
  216.  top:
  217.    SPH_setImplicitRegenerationMode (ALLOWED);
  218.  
  219.    if (READ_FROM_STDIN)
  220.       gets(buffer);
  221.    else {
  222.       switch (SRGP_waitEvent (INDEFINITE)) {
  223.        case KEYBOARD:
  224.      SRGP_getKeyboard (buffer, 2);
  225.      break;
  226.        case LOCATOR:
  227.      SPH_getLocator (&locmeas);
  228.      if (locmeas.button_chord[0] == DOWN) 
  229.         if (locmeas.view_index == PERSPECTIVE_VIEW) {
  230.            SPH_pickCorrelate 
  231.           (locmeas.position, locmeas.view_index, &pickinfo);
  232.            if (pickinfo.pickLevel > 0)
  233.           PrintCorrelationInfo (&pickinfo);
  234.         }
  235.      goto top;
  236.       }
  237.    }
  238.    
  239.    SPH_setImplicitRegenerationMode (SUPPRESSED);
  240.  
  241.    bias = 1.0;
  242.     
  243.    switch (buffer[0]) {
  244.  
  245.      case '<':
  246.        if ((motion_granularity -= 5) < 1)  motion_granularity =  1;
  247.        DisplayMotionGranularity(); 
  248.        break;
  249.  
  250.      case '>':
  251.        if ((motion_granularity += 5) > 99) motion_granularity = 99;
  252.        DisplayMotionGranularity(); 
  253.        break;
  254.  
  255.      case 'g':
  256.        sscanf (buffer, "g%d", &motion_granularity);
  257.        DisplayMotionGranularity();
  258.        break;
  259.  
  260.      case '0':
  261.        RestoreCameraToDefault ();
  262.        ShowUsingNewView1 ();
  263.        break;
  264.  
  265.      case '1':
  266.      case '2':
  267.      case '3':
  268.      case '4':
  269.      case '5':
  270.      case '6':
  271.        InstallCameraDialog (buffer[0] - '0');    
  272.        break;
  273.  
  274.      case 's':
  275.        bias = -1.0; /*nobreak*/
  276.      case 'd':
  277.        ChangeCameraOnAxis (X_AXIS, bias);
  278.        break;
  279.  
  280.      case 'x':
  281.        bias = -1.0; /*nobreak*/
  282.      case 'e':
  283.        ChangeCameraOnAxis (Y_AXIS, bias);
  284.        break;
  285.  
  286.      case '-':
  287.        bias = -1.0; /*nobreak*/
  288.      case '=':
  289.        ChangeCameraOnAxis (Z_AXIS, bias);
  290.        break;
  291.  
  292.      case 'C':
  293.      case 'c':
  294.        if (buffer[0] == curchimneymenuitem)
  295.       break;
  296.        if (buffer[0] == 'C') {
  297.       AddChimneyToHouse (HOUSE_STRUCT);
  298.       AddChimneyToHouse (FAKE_HOUSE_TOP_STRUCT);
  299.       AddChimneyToHouse (FAKE_HOUSE_SIDE_STRUCT);
  300.        }
  301.        else {
  302.       TakeChimneyFromHouse (HOUSE_STRUCT);
  303.       TakeChimneyFromHouse (FAKE_HOUSE_TOP_STRUCT);
  304.       TakeChimneyFromHouse (FAKE_HOUSE_SIDE_STRUCT);
  305.        }
  306.        curchimneymenuitem = buffer[0];
  307.        break;
  308.  
  309.      case 'a':
  310.      case 'A':
  311.        if (buffer[0] == curvpmenuitem)
  312.       break; 
  313.        SPH_setImplicitRegenerationMode (SUPPRESSED);
  314.        if (buffer[0] == 'a')
  315.       DisplayOnlyFullRenderView();
  316.        else
  317.       DisplayAllViews();
  318.        ShowUsingNewView1();
  319.        SPH_setImplicitRegenerationMode (ALLOWED);
  320.        curvpmenuitem = buffer[0];
  321.        break;
  322.  
  323.      case 'n':
  324.      case 'N':
  325.        SPH_setRenderingMode (PERSPECTIVE_VIEW, LIT_FLAT); break;
  326.  
  327.      case 'm':
  328.      case 'M':
  329.        SPH_setRenderingMode (PERSPECTIVE_VIEW, WIREFRAME); break;
  330.  
  331.      case '}':
  332.        /* Undocumented */
  333.        ChangePRPforOrtho();
  334.        ShowUsingNewView1 ();
  335.        break;
  336.      case '{':
  337.        /* Undocumented */
  338.        ChangePRPforClosestPerspective();
  339.        ShowUsingNewView1 ();
  340.        break;
  341.     }
  342.    goto top;
  343. }
  344.