Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

RenderContext.h

00001 /*
00002   File: RenderContext.h
00003 
00004   Copyright(C) C. Kotterink, Computed Graphics
00005 */
00006 #ifndef RENDERCONTEXT_H
00007 #define RENDERCONTEXT_H
00008 
00009 #include<AABoundingBox.h>
00010 #include<Color3.h>
00011 #include<Color4.h>
00012 #include<Matrix4.h>
00013 #include<Quaternion.h>
00014 #include<Vertex3.h>
00015 #include<Vertex4.h>
00016 
00017 #include<render.h>
00018 
00019 class Mesh;
00020 class Material;
00021 
00024 class RenderContext
00025 {
00026 public:
00027     typedef enum Visibility {
00028         NotVisible,
00029         Visible,    
00030         PartlyVisible
00031     };
00032 
00033     RenderContext();
00034 
00035     void init();
00036 
00037     void setFill(bool fill);
00038     bool getFill() {
00039         return solidFill;
00040     }
00041     void setRenderBounds(bool render) {
00042         renderBounds = render;
00043     }
00044     bool getRenderBounds() {
00045         return renderBounds;
00046     }
00047     void setViewport(unsigned short w, unsigned short h);
00048     void printScreen();
00049 
00050     // Matrix operations
00051     void perspective(float fovy, float zNear, float zFar);
00052     void pickMatrix(real x, real y);
00053 
00054     // View Frustrum culling and camera coordinate system
00055     void extractFrustum();
00056     const Vertex3 &getCameraX() {
00057         return cameraX;
00058     }
00059     const Vertex3 &getCameraY() {
00060         return cameraY;
00061     }
00062     void setCameraPosition(const Vertex3 &position) {
00063         cameraPos = position;
00064     }
00065     const Vertex3 &getCameraPosition() {
00066         return cameraPos;
00067     }
00068     Vertex3 transform(const Vertex3 &v) {
00069       return M.applyHomogenous(v);
00070     }
00071     Vertex3 modelTransform(const Vertex3 &v) {
00072       return modelView*v;
00073     }
00074 
00075     bool cull(real x, real y, real z);
00076     Visibility cull(const Vertex3 &v, real radius);
00077     Visibility cull(const AABoundingBox &box) {
00078         return cull(box.getFrom(), box.getTo());
00079     }
00080     Visibility cull(const Vertex3 &from, const Vertex3 &to);
00081 
00082     // Render Geo Objects
00083     RenderContext &operator <<(const Color3 &c) {
00084         glColor3fv((float*)&c);
00085         return *this;
00086     }
00087     RenderContext &operator <<(const Color4 &c) {
00088         glColor4fv((float*)&c);
00089         return *this;
00090     }
00091     RenderContext &operator <<(const Vertex3 &v) {
00092         glVertex3fv((float*)&v);
00093         return *this;
00094     }
00095     RenderContext &operator <<(const Vertex4 &v) {
00096         glVertex4fv((float*)&v);
00097         return *this;
00098     }
00099     RenderContext &operator <<(const Matrix4 &m) {
00100         glLoadMatrixf((float*)&m);
00101         return *this;
00102     }
00103     RenderContext &operator <<(Quaternion &q){
00104         Vertex3 v;
00105         real angle;
00106 
00107         q.getRotation(v, angle);
00108         angle /= DEG2RAD;
00109         glRotatef(angle, v.x, v.y, v.z);
00110         return *this;
00111     }
00112     RenderContext &normal(Vertex3 &v) {
00113         glNormal3fv((float*)&v);
00114         return *this;
00115     }
00116     RenderContext &operator<<(const AABoundingBox &box) {
00117         if (renderBounds) {
00118             boundingBox(box);
00119         }
00120         return *this;
00121     }
00122     // Gfx Objects
00123     RenderContext &operator <<(Material *material);
00124 
00125     // Other renderings
00126     RenderContext &screenQuad(real x, real y, real r);
00127     RenderContext &texturedQuad(const Vertex3 &p, real r);
00128     void boundingBox(const AABoundingBox &box);
00129 
00130 private:
00131     class FrustrumPlane
00132     {
00133     public:
00134         real distance(real x, real y, real z) {
00135             return a*x + b*y + c*z +d;
00136         }
00137         void setParam(real aa, real bb, real cc, real dd) {
00138             real norm = sqrt(aa*aa + bb*bb + cc*cc);
00139             a = aa/norm;
00140             b = bb/norm;
00141             c = cc/norm;
00142             d = dd/norm;
00143         }
00144 
00145     private:
00146         real a, b, c, d;
00147     };
00148 
00149     static real pickSize;
00150     static Material defaultMaterial;
00151 
00152     // Flags
00153     bool solidFill;
00154     bool renderBounds;
00155 
00156     // View info
00157     float aspect;
00158     Vertex3 cameraX;
00159     Vertex3 cameraY;
00160     Vertex3 cameraPos;
00161     Matrix4 M;          // Projection*ModelView
00162     Matrix4 modelView;
00163     FrustrumPlane frustum[6];
00164 
00165     // Render state
00166     Material *currentMaterial;
00167 };
00168 
00169 #endif

This documentation was generated using doxygen. If you have any comments or additions please mail me.