Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

RT_Prim.h

Go to the documentation of this file.
00001 /*
00002     File:           RT_Prim.h
00003     
00004     Function:       Defines raytracing primitives
00005     
00006     Author(s):      Andrew Willmott
00007 
00008     Copyright:      (c) 1997-2000, Andrew Willmott
00009 */
00010 
00011 #ifndef __RT_Prim__
00012 #define __RT_Prim__
00013 
00014 #include "RT_Defs.h"
00015 
00016 // Tri flags...
00017 
00018 const Byte TRI_HIT      = 0x0001;
00019 const Byte GEN_HIT      = 0x0001;
00020 const Byte TRI_INACTIVE = 0x0002;
00021 const Byte TRI_2SIDED_R = 0x0004;   // two-sided for rendering purposes
00022 const Byte TRI_2SIDED_V = 0x0008;   // two-sided for visibility purposes
00023 
00024 class RT_Tri;
00025 class RT_Gen;
00026 typedef RT_Gen *RT_GenPtr;
00027 
00028 // An object is a collection of primitives which share a list of (world space)
00029 // points and normals.
00030 class RT_Object
00031 {
00032 public:
00033     Void        Init(Int numTris, Int numGens = 0);
00034                 // call this, then fill in point & tri data
00035     Void        Setup();
00036                 // call once tri & gen data has been filled in
00037     Void        Free();
00038 
00039     Point*      points;
00040     Int         numPoints;
00041     Vector*     normals;
00042     Int         numNormals;
00043 
00044     RT_Tri*     tris;
00045     Int         numTris;
00046     RT_GenPtr*  gens;
00047     Int         numGens;
00048     Void*       data;           // extra info we might need.
00049 
00050     Int         id;             // per-object id.
00051     Int         tag;            // groups this object belongs to
00052 
00053     Int         stamp;          // local time stamp;
00054     static Int  gStamp;         // global time stamp;
00055 
00056     static Void IncTime()       { gStamp++; };
00057     Void        Stamp()         { stamp = gStamp; };
00058     Bool        IsStamped()     { return(stamp == gStamp); };
00059 };
00060 
00061 
00062 // --- RT primitives ----------------------------------------------------------
00063 
00064 
00065 enum RT_PrimTag 
00066 {
00067     rt_triangle, 
00068     rt_gen,
00069     rt_grid
00070 };
00071 
00072 class RT_Prim
00073 {
00074 protected:
00075     Int         stamp;          // local time stamp;
00076     static Int  gStamp;         // global time stamp;
00077 
00078 public:
00079     RT_Object*  object;
00080     Byte        primType;
00081     Byte        flags;          // See values above
00082     Int         id;
00083     Float       area;           // surface area
00084 #ifdef RT_OPAC
00085     Int         cells;          // number of grid cells covered
00086 #endif
00087 
00088     Bool        IsTrue(Int i)   { return(flags & i); };
00089     static Void IncTime()       { gStamp++; };
00090     Void        Stamp()         { stamp = gStamp; };
00091     Bool        IsStamped()     { return(stamp == gStamp); };
00092 };
00093 
00094 class RT_Tri : public RT_Prim
00095 {
00096 public:
00097     Int         v[3];           // vertex indices
00098 #ifdef RT_NORM
00099     Int         n[3];           // normal indices
00100 #endif
00101 
00102     Vector      normal;         // face normal
00103     Float       d;              // completes the plane equation
00104     Byte        normMajorAxis;  // largest component of normal
00105     
00106     //  Methods
00107 
00108     Void        Init(Int v1, Int v2, Int v3, RT_Object *obj, Int triID);
00109 
00110     Bool        PointIsInside(Point &p);
00111     Void        FindBaryCoords(Point &p, Vector &coords);
00112     Void        UpdateBounds(Point &min, Point &max);
00113     Void        MakeNormal();
00114         
00115     Void        Draw();
00116     
00117     Point&      Vertex(Int i)   { return(object->points[v[i]]); };
00118 #ifdef RT_NORM
00119     Point&      Normal(Int i)   { return(object->normals[n[i]]); }; 
00120 #endif
00121 };  
00122 
00123 class RT_Gen : public RT_Prim
00124 // generic RT object.
00125 {
00126 public:
00127     GCLReal             hitT;
00128         
00129     Void                Init(const Point &centre, GCLReal radius,
00130                              RT_Object *obj, Int genID);
00131         
00132     virtual Bool        Intersect(Point &start, Vector &dir, GCLReal tMin, 
00133                           GCLReal tMax) = 0; 
00134 
00135     virtual Void        UpdateBounds(Point &min, Point &max) = 0;
00136     virtual Void        FindBounds(Point &min, Point &max) = 0;
00137 };
00138 
00139 class RT_Sphere : public RT_Gen
00140 {
00141 public:
00142     Point       centre;
00143     GCLReal     radius;
00144     GCLReal     sqrRad;
00145         
00146     Void        Init(const Point &centre, GCLReal radius, RT_Object *obj,
00147                      Int genID);
00148         
00149     Bool        Intersect(Point &start, Vector &dir, GCLReal tMin, 
00150                           GCLReal tMax); 
00151 
00152     Void        UpdateBounds(Point &min, Point &max);
00153     Void        FindBounds(Point &min, Point &max);
00154 };
00155 
00156 #endif
00157 

Generated at Sat Aug 5 00:26:54 2000 for Radiator by doxygen 1.1.0 written by Dimitri van Heesch, © 1997-2000