home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Book Chapters / 09 - QuickDraw 3D / Box / Box.c next >
Encoding:
C/C++ Source or Header  |  1995-03-21  |  4.2 KB  |  169 lines  |  [TEXT/MPCC]

  1. /****************************/
  2. /*               BOX.C            */
  3. /****************************/
  4.  
  5.  
  6. /****************************/
  7. /*    EXTERNALS             */
  8. /****************************/
  9.  
  10. #include <qd3d.h>
  11. #include <QD3DGeometry.h>
  12. #include <QD3DSet.h>
  13. #include <QD3DView.h>
  14. #include <QD3DShader.h>
  15. #include <QD3DGroup.h>
  16. #include <QD3DRenderer.h>
  17. #include <QD3DAcceleration.h>
  18. #include <QD3DDrawContext.h>
  19.  
  20. extern    TQ3ViewObject        gMyViewObject;
  21. extern    TQ3StyleObject        gMyStyleObject_Interpolation;
  22. extern    TQ3StyleObject        gMyStyleObject_Backfacing;
  23. extern    TQ3StyleObject        gMyStyleObject_Fillstyle;
  24. extern    TQ3ShaderObject        gMyShaderObject_IlluminationShader;
  25.  
  26.  
  27.  
  28. /****************************/
  29. /*    PROTOTYPES            */
  30. /****************************/
  31.  
  32. extern    void DoFatalAlert(Str255 s);
  33.  
  34. void CreateMyBoxObject(void);
  35. void DrawMyObjects(void);
  36.  
  37.  
  38. /****************************/
  39. /*    CONSTANTS             */
  40. /****************************/
  41.  
  42.  
  43. /*********************/
  44. /*    VARIABLES      */
  45. /*********************/
  46.  
  47. TQ3GeometryObject    gMyBoxObject;
  48.  
  49.  
  50. /****************** CREATE MY BOX OBJECT ******************/
  51. //
  52. // Creates and returns a box geometry object.
  53. //
  54. // INPUT    : none
  55. // OUTPUT    : box object
  56. //
  57.  
  58. void CreateMyBoxObject(void)
  59. {
  60. TQ3ColorRGB            color = {1.0,1.0,1.0};        // make it white
  61. TQ3AttributeSet        attribs;
  62. float                ambient = 1.0;
  63. TQ3Point3D            origin = {0,0,0};
  64. TQ3Vector3D            orientation = {0,2,0};
  65. TQ3Vector3D            majorAxis = {0,0,2};
  66. TQ3Vector3D            minorAxis = {2,0,0};
  67. TQ3BoxData            boxData;
  68. TQ3Status            myStatus;
  69.  
  70.  
  71.             /* CREATE ATTRIBUTES FOR BOX */
  72.             
  73.     attribs = Q3AttributeSet_New();                    // make new attrib object
  74.     if (attribs == nil)
  75.         DoFatalAlert("\pUnable to create new attribute Set!");
  76.     
  77.                                                     // add color attribute
  78.     myStatus = Q3AttributeSet_Add(attribs, kQ3AttributeTypeDiffuseColor, &color);
  79.     if ( myStatus == kQ3Failure )
  80.         DoFatalAlert("\p Q3AttributeSet_Add Failed!");
  81.     
  82.                                                     // add ambient attribute
  83.     myStatus = Q3AttributeSet_Add(attribs, kQ3AttributeTypeAmbientCoefficient, &ambient);
  84.     if ( myStatus == kQ3Failure )
  85.         DoFatalAlert("\p Q3AttributeSet_Add Failed!");
  86.  
  87.  
  88.             /* SET BOX INITIALIZE DATA */
  89.                     
  90.     boxData.origin = origin;                        // set box origin coords
  91.     boxData.orientation = orientation;                // set orientation vector
  92.     boxData.majorAxis = majorAxis;                    // set major axis vector
  93.     boxData.minorAxis = minorAxis;                    // set minor axis vector
  94.     boxData.faceAttributeSet = nil;                    // faces will inherit attribs...
  95.     boxData.boxAttributeSet = attribs;                // ... from entire box's attribs
  96.  
  97.     gMyBoxObject = Q3Box_New(&boxData);                // make new box object from data
  98.     if (gMyBoxObject == nil)
  99.         DoFatalAlert("\pError creating new Box geometry");
  100.     
  101.     
  102.             /* DISPOSE OF OUR REFERENCE TO THE ATTRIBUTES */
  103.     
  104.     Q3Object_Dispose(attribs);
  105. }
  106.  
  107.  
  108. /******************* DRAW MY OBJECTS *********************/
  109. //
  110. // Draws a frame of animation for the FlyThru window.
  111. //
  112.  
  113. void DrawMyObjects(void)
  114. {
  115. TQ3Status                myStatus;
  116. TQ3ViewStatus            myViewStatus;
  117.  
  118.                 /* START RENDERING */
  119.                                 
  120.     myStatus = Q3View_StartRendering(gMyViewObject);            // start rendering
  121.     if ( myStatus == kQ3Failure )
  122.         DoFatalAlert("\p Q3View_StartRendering Failed!");
  123.  
  124.     do
  125.     {
  126.                 /* SET INTERPOLATION STYLE */
  127.  
  128.         myStatus = Q3Style_Submit(gMyStyleObject_Interpolation,gMyViewObject);
  129.         if ( myStatus == kQ3Failure )
  130.             DoFatalAlert("\p Q3Style_Submit Failed!");
  131.             
  132.                 /* SET BACKFACING STYLE */
  133.                     
  134.         myStatus = Q3Style_Submit(gMyStyleObject_Backfacing,gMyViewObject);
  135.         if ( myStatus == kQ3Failure )
  136.             DoFatalAlert("\p Q3Style_Submit Failed!");
  137.             
  138.             
  139.                     /* SET FILL STYLE */
  140.                     
  141.         myStatus = Q3Style_Submit(gMyStyleObject_Fillstyle, gMyViewObject);
  142.         if ( myStatus == kQ3Failure )
  143.             DoFatalAlert("\p Q3Style_Submit Failed!");
  144.             
  145.             
  146.                     /* SET SHADER TO USE */
  147.                     
  148.         myStatus = Q3Shader_Submit(gMyShaderObject_IlluminationShader, gMyViewObject);
  149.         if ( myStatus == kQ3Failure )
  150.             DoFatalAlert("\p Q3Shader_Submit Failed!");
  151.             
  152.             
  153.                     /* DRAW THE BOX OBJECT */
  154.                 
  155.         myStatus = Q3Geometry_Submit(gMyBoxObject,gMyViewObject);
  156.         if ( myStatus == kQ3Failure )
  157.             DoFatalAlert("\p Drawing box Failed!");
  158.         
  159.                     /* SEE IF DONE */
  160.                     
  161.         myViewStatus = Q3View_EndRendering(gMyViewObject);
  162.         
  163.     } while ( myViewStatus == kQ3ViewStatusRetraverse );
  164.         
  165. }
  166.  
  167.  
  168.  
  169.