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

KX_BlenderRenderTools.h

Go to the documentation of this file.
00001 #ifndef __KX_BLENDERRENDERTOOLS
00002 #define __KX_BLENDERRENDERTOOLS
00003 
00004 
00005 #include "RAS_IRenderTools.h"
00006 
00007 #include "RAS_IRasterizer.h"
00008 
00009 #include "KX_BlenderPolyMaterial.h"
00010 
00011 #include "KX_GameObject.h"
00012 #include "KX_BlenderGL.h" // for text printing
00013 
00014 #include "KX_BlenderClientObject.h"
00015 
00016 #include "StdString.h"
00017 
00018 #include "RAS_BucketManager.h" // for polymaterial (needed for textprinting)
00019 
00020 
00021 class KX_BlenderRenderTools  : public RAS_IRenderTools
00022 {
00023         bool    m_lastblenderlights;
00024         void*   m_lastblenderobject;
00025         int             m_lastlayer;
00026         bool    m_lastlighting;
00027 public:
00028         
00029         
00030         KX_BlenderRenderTools() {
00031                 
00032         };
00033         virtual ~KX_BlenderRenderTools() {
00034                 
00035         };
00036         
00037         
00038         virtual void    EndFrame(RAS_IRasterizer* rasty)

00039         {
00040                 
00041         }
00042         
00043         virtual void BeginFrame(RAS_IRasterizer* rasty)

00044         {
00045                 m_clientobject=NULL;
00046                 m_lastblenderobject=NULL;
00047                 m_lastblenderlights = false;
00048                 m_lastlayer = -1;
00049                 m_lastlighting=false;
00050                 m_modified=true;
00051                 DisableOpenGLLights();
00052         }
00053         void DisableOpenGLLights()

00054         {
00055                 glDisable(GL_LIGHTING);
00056                 glDisable(GL_COLOR_MATERIAL);
00057                 glDisableClientState(GL_NORMAL_ARRAY);
00058         }
00059         void EnableOpenGLLights()

00060         {
00061                 glEnable(GL_LIGHTING);
00062                 
00063                 glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
00064                 glEnable(GL_COLOR_MATERIAL);
00065                 glEnableClientState(GL_NORMAL_ARRAY);
00066                 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, false);
00067         }
00068         
00069         int             ProcessLighting(int layer) {
00070                 
00071                 
00072                 if (m_clientobject)
00073                 {
00074                         
00075                         if (BL_set_gl_light(layer,m_viewmat,0))
00076                         {
00077                                 EnableOpenGLLights();
00078                                 return true;
00079                         } else
00080                         {
00081                                 DisableOpenGLLights();
00082                                 return false;
00083                         }
00084                         
00085                 }
00086                 return true;
00087                 
00088                 
00089         }
00090         
00091         virtual void RenderText2D(const char* text,int xco,int yco)

00092         {
00093                 CCString tmpstr(text);
00094                 BL_print_gamedebug_line(tmpstr.Ptr(),xco,yco);
00095         }
00096         
00097         virtual void    RenderText(int mode,RAS_IPolyMaterial* polymat,float v1[3],float v2[3],float v3[3],float v4[3])

00098         {
00099                 
00100                 CCString mytext = ((KX_GameObject*)m_clientobject)->GetPropertyText("Text");
00101                 
00102                 KX_BlenderPolyMaterial* blenderpoly = (KX_BlenderPolyMaterial*)polymat;
00103                 struct TFace* tface = blenderpoly->GetTFace();
00104                 
00105                 BL_RenderText( mode,mytext,mytext.Length(),tface,v1,v2,v3,v4);
00106                 
00107         }
00108         
00109         
00110         void applyTransform(RAS_IRasterizer* rasty,double* oglmatrix,int objectdrawmode )

00111         {
00112                 
00113                 glPopMatrix();
00114                 glPushMatrix();
00115                 
00116                 if (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED ||
00117                         objectdrawmode & RAS_IPolyMaterial::BILLBOARD_AXISALIGNED)
00118                 {
00119                         // rotate the billboard/halo
00120                         //page 360/361 3D Game Engine Design, David Eberly for a discussion
00121                         // on screen aligned and axis aligned billboards
00122                         // assumed is that the preprocessor transformed all billboard polygons
00123                         // so that their normal points into the positive x direction (1.0 , 0.0 , 0.0)
00124                         // when new parenting for objects is done, this rotation
00125                         // will be moved into the object
00126                         
00127                         MT_Point3 objpos (oglmatrix[12],oglmatrix[13],oglmatrix[14]);
00128                         MT_Point3 campos = rasty->GetCameraPosition();
00129                         MT_Vector3 dir = (campos - objpos).normalized();
00130                         MT_Vector3 up(0,0,1.0);
00131                         bool screenaligned = (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED)!=0;//false; //either screen or axisaligned
00132                         if (screenaligned)
00133                         {
00134                                 up = (up - up.dot(dir) * dir).normalized();
00135                         } else
00136                         {
00137                                 dir = (dir - up.dot(dir)*up).normalized();
00138                         }
00139                         MT_Vector3 left  = dir.normalized();
00140                         dir = (left.cross(up)).normalized();
00141                         double maat[16]={
00142                                 left[0], left[1],left[2], 0,
00143                                         dir[0], dir[1],dir[2],0,
00144                                         up[0],up[1],up[2],0,
00145                                         0,0,0,1};
00146                                 glTranslated(objpos[0],objpos[1],objpos[2]);
00147                                 glMultMatrixd(maat);
00148                                 
00149                 } else
00150                 {
00151                         glMultMatrixd(oglmatrix);
00152                 }
00153         }
00154 };
00155 
00156 
00157 #endif //__KX_BLENDERRENDERTOOLS

Generated at Thu Feb 1 13:03:04 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000