home *** CD-ROM | disk | FTP | other *** search
/ Cutting-Edge 3D Game Programming with C++ / CE3DC++.ISO / BOOK / CHAP11 / MORPH / PANEL3D.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-27  |  3.5 KB  |  130 lines

  1. //
  2. // File name: Panel3D.HPP
  3. //
  4. // Description: Header file for a 3D panel class
  5. //
  6. // Author: John De Goes
  7. //
  8. // Project: Cutting Edge 3D Game Programming
  9. //
  10.  
  11. #ifndef POINT3DHPP
  12.   #define POINT3DHPP
  13.   #include "Point3D.HPP"
  14. #endif
  15.  
  16. #ifndef POINT2DHPP
  17.   #define POINT2DHPP
  18.   #include "Point2D.HPP"
  19. #endif
  20.  
  21. #ifndef VECTOR3DHPP
  22.   #define VECTOR3DHPP
  23.   #include "Vector3D.HPP"
  24. #endif
  25.  
  26. #ifndef DETAIL3DHPP
  27.   #define DETAIL3DHPP
  28.   #include "Detail3D.HPP"
  29. #endif
  30.  
  31. #ifndef ATYPESHPP
  32.   #define ATYPESHPP
  33.   #include "ATypes.HPP"
  34. #endif
  35.  
  36. #ifndef POLYEDGEHPP
  37.   #define POLYEDGEHPP
  38.   #include "PolyEdge.HPP"
  39. #endif
  40.  
  41. #ifndef MATRIX3DHPP
  42.   #define MATRIX3DHPP
  43.   #include "Matrix3D.HPP"
  44. #endif
  45.  
  46. #ifndef TEXTTYPEHPP
  47.   #define TEXTTYPEHPP
  48.   #include "TextType.HPP"
  49. #endif
  50.  
  51. #include <Dos.H>
  52.  
  53. // Forward declaration:
  54. class PanelObject;
  55.  
  56. // The panel class:
  57. class Panel3D {
  58. protected:                 // Data is protected
  59.   // Functions:
  60.   void CalcRadius ();      // Calculates panel radius
  61.   long CalcCenterZ ();     // Calculates center Z  
  62.   int inline CalcBFace (); // Determines if panel is backface
  63.   void CalcNormal ();      // Calculates the panel normal
  64.   int CheckExtents ();     // Determines if panel lies within
  65.                            // the Z extents
  66.   int CalcVisible3D ();    // Determines panel's visibility 
  67.                            // in 3D
  68.   int CalcVisible2D ();    // Determines panel's visibility
  69.                            // in 2D
  70.   void DisplaySel ( unsigned char *Dest );
  71.   void DisplayNorm ( unsigned char *Dest );
  72.   // Data:
  73.   Point3D *VPoint [ 4 ];   // 4 pointers to a vertex list
  74.   Detail3D Attrib [ 4 ];   // The panel's detail attributes
  75.   Vector Normal;           // The panel normal
  76.   Point2D SPoint [ 5 ];    // Maximum of 5 on-screen points
  77.   WORD SPCount, Invis;     // Screen point count & invisible flag
  78.   BYTE Color, TextHan;     // The panel color * texture handle
  79.   BYTE A, Pad1;
  80.   double Radius;           // The panel's radius
  81. public:                    // Data is public
  82.   Panel3D () { A = Color = Invis = 0; } // Constructor:
  83.   void Update ( Matrix3D &M );          // Update normal and misc. information
  84.   void Display ( unsigned char *Dest )
  85.      {
  86.      if ( A )
  87.         DisplaySel ( Dest );
  88.      else 
  89.      DisplayNorm ( Dest );
  90.      }
  91.   void Project ();                      // Project panel onto screen
  92.   void InitPosition () { CalcNormal (); CalcRadius (); } // Performs initialization
  93.   void CalcInten ();                    // Calculates panel's intensity
  94.   int Invisible () { return Invis; }    // Determine invisibility
  95.   int IsVisible2D () { return CalcVisible2D (); } // Determine visibility in 3D
  96.   int IsVisible3D () { return CalcVisible3D (); } // Determine visibility in 2D
  97.   
  98.   friend class PanelObject;   // Declare a friend class
  99.  
  100.   int HasVert ( Point3D &P )
  101.     {
  102.     if ( ( *VPoint [ 0 ] ) == P )
  103.        return 1;
  104.     if ( ( *VPoint [ 1 ] ) == P )
  105.        return 1;
  106.     if ( ( *VPoint [ 2 ] ) == P )
  107.        return 1;
  108.     if ( ( *VPoint [ 3 ] ) == P )
  109.        return 1;
  110.     return 0;
  111.     }
  112.  
  113.   void Select () { A = 10; }
  114.   void Deselect () { A = 0; }
  115.   BYTE GetState () { return A; }
  116.   void NexText ()
  117.      {
  118.      TextHan = ( BYTE ) ( ( TextHan + 1 ) % TextDat.TCount );
  119.      }
  120.   void RotText ()
  121.      {
  122.      Detail3D Temp;
  123.      Temp = Attrib [ 0 ];
  124.      Attrib [ 0 ] = Attrib [ 1 ];
  125.      Attrib [ 1 ] = Attrib [ 2 ];
  126.      Attrib [ 2 ] = Attrib [ 3 ];
  127.      Attrib [ 3 ] = Temp;
  128.      }
  129. };
  130.