torcs - 1.2.2

src/modules/graphic/ssggraph/grssgext.h

Go to the documentation of this file.
00001 /***************************************************************************
00002 
00003     file                 : grssgext.h
00004     created              : Wed Aug 30 01:35:45 CEST 2000
00005     copyright            : (C) 2000 by Eric Espie
00006     email                : torcs@free.fr
00007     version              : $Id: grssgext.h,v 1.4 2002/06/25 21:47:33 torcs Exp $
00008 
00009 ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *   This program is free software; you can redistribute it and/or modify  *
00014  *   it under the terms of the GNU General Public License as published by  *
00015  *   the Free Software Foundation; either version 2 of the License, or     *
00016  *   (at your option) any later version.                                   *
00017  *                                                                         *
00018  ***************************************************************************/
00019  
00027 #ifndef _GRSSGEXT_H_
00028 #define _GRSSGEXT_H_
00029 
00030 
00031 /*
00032  * An ssgBranch with pre and post draw callbacks.
00033  * It must be clear that all the children nodes
00034  * have to be non-transparent in order to be 
00035  * drawn immediately.
00036  */
00037 class ssgBranchCb : public ssgBranch
00038 {
00039 
00040  protected:
00041 
00042   ssgCallback  preDrawCB;
00043   ssgCallback postDrawCB;
00044   
00045  public:
00046 
00047   ssgBranchCb(void):ssgBranch() {
00048     preDrawCB = NULL;
00049     postDrawCB = NULL;
00050   }
00051   
00052   void cull  ( sgFrustum *f, sgMat4 m, int test_needed ) 
00053     {
00054       int cull_result = cull_test ( f, m, test_needed ) ;
00055       
00056       if ( cull_result == SSG_OUTSIDE )
00057         return ;
00058       
00059       if ( preDrawCB != NULL && ! (*preDrawCB)(this) )
00060         return ;
00061       
00062       for ( ssgEntity *e = getKid ( 0 ) ; e != NULL ; e = getNextKid() )
00063         e -> cull ( f, m, cull_result != SSG_INSIDE ) ;
00064       
00065       if ( postDrawCB != NULL )
00066         (*postDrawCB)(this) ;
00067     }
00068 
00069   void setCallback ( int cb_type, ssgCallback cb ) {
00070     if ( cb_type == SSG_CALLBACK_PREDRAW )
00071       preDrawCB = cb ;
00072     else
00073       postDrawCB = cb ;
00074   }
00075 
00076 };
00077 
00078 
00079 /* Use the texture name to select options like mipmap */
00080 class ssgLoaderOptionsEx : public ssgLoaderOptions
00081 {
00082  public:
00083     ssgLoaderOptionsEx()
00084         : ssgLoaderOptions() 
00085         {}
00086 
00087     ssgTexture* createTexture(char* tfname, 
00088                               int wrapu  = TRUE, int wrapv = TRUE, 
00089                               int mipmap = TRUE)
00090         {
00091             char *buf;
00092             char *s;
00093 
00094             buf = (char *)malloc(strlen(tfname)+1);
00095             strcpy(buf, tfname);
00096 
00097             /* find the filename extension */
00098             s = strrchr(buf, '.');
00099             if (s) {
00100                 *s = 0;
00101             }
00102       
00103             /* search for the texture parameters */
00104             s = strrchr(buf, '_');
00105       
00106             if (s) {
00107                 /* no mipmap */
00108                 if (strncmp(s, "_n", 4) == 0) {
00109                     mipmap = FALSE;
00110                 }
00111             }
00112             free(buf);
00113       
00114             return ssgLoaderOptions::createTexture(tfname, wrapu, wrapv, mipmap) ;
00115         }
00116 
00117     virtual void makeModelPath ( char* path, const char *fname ) const
00118         {
00119             ulFindFile ( path, model_dir, fname, NULL ) ;
00120         }
00121     
00122     virtual void makeTexturePath ( char* path, const char *fname ) const
00123         {
00124             ulFindFile ( path, texture_dir, fname, NULL ) ;
00125         }
00126 
00127 };
00128 
00129 
00130 
00131 #endif /* _GRSSGEXT_H_ */ 
00132 
00133 
00134 

Generated at Thu Feb 26 21:52:29 2004 for torcs by doxygen 1.3.3 written by Dimitri van Heesch, © 1997-1999
TORCS © Eric Espié 1999, 2002.