home *** CD-ROM | disk | FTP | other *** search
/ Quark 3 / Quark3.iso / KATALOG / ARCHIV / TOOL / T001.ZIP / SOURCE.ZIP / md3view.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-19  |  4.8 KB  |  197 lines

  1. /*
  2. Copyright (C) Matthew 'pagan' Baranowski & Sander 'FireStorm' van Rossen
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17. */
  18.  
  19. #include "system.h"
  20. #include "ndictionary.h"
  21. #include "md3gl.h"
  22. #include "md3view.h"
  23.  
  24. MDViewState mdview;
  25.  
  26. /*
  27. renders the view which so far is just a model frame
  28. */
  29. void render_mdview()
  30. {
  31.     //draw_view();    
  32.     draw_viewSkeleton();
  33. }
  34.  
  35. /*
  36. initializes the viewer global state data
  37. */
  38. void init_mdview()
  39. {
  40.     mdview.zPos = -2.f;
  41.     mdview.rotAngleX = mdview.rotAngleY = 0;    
  42.     mdview.animSpeed = 5.0;
  43.     mdview.timeStamp1 = getDoubleTime();
  44.     mdview.texMode = TEX_UNFILTERED;
  45.     mdview.faceSide = GL_CCW;
  46.     mdview.animate = false;
  47.     mdview.interpolate = false;
  48.  
  49.     // allocate texture resource manager
  50.     mdview.textureRes = new NodeDictionaryInfo( new StrKeyComparatorInfo() );
  51.     mdview.topTextureBind = 0;
  52.  
  53.     // allocate model list
  54.     mdview.modelList = new NodeSequenceInfo();
  55.  
  56.     strcpy( mdview.basepath, "/");
  57.     SetCurrentDirectory( mdview.basepath );
  58. }
  59.  
  60. void    delete_gl_model( gl_model *model );
  61. bool    loadmd3(gl_model& newModel, char* filename);
  62.  
  63. /* ------------------------------------------------ loading code -------------------------------------------------- */
  64.  
  65. /*
  66. loads up md3 data
  67. */
  68. bool loadmdl( char *filename )
  69. {    
  70.     gl_model* model = new gl_model; memset( model, 0, sizeof(gl_model) );
  71.     if (!loadmd3( *model, filename )) {
  72.         delete_gl_model( model );model = NULL;
  73.         return false;
  74.     }
  75.  
  76.  
  77.     model->modelListPosition = mdview.modelList->insertLast( model );
  78.     mdview.baseModel = (gl_model *)mdview.modelList->first()->element();
  79.  
  80.     tagMenu_seperatorAppend( filename );
  81.     for (unsigned int i=0 ; i<model->tagNum ; i++) {
  82.         tagMenu_append( model->tags[0][i].Name, (GLMODEL_DBLPTR)&model->linkedModels[i] );
  83.     }
  84.  
  85.     return true;
  86. }
  87.  
  88.  
  89.  
  90.  
  91. /*
  92. loads a model into the slot pointed to by dblptr
  93. */
  94. void loadmdl_totag( char *fullName, GLMODEL_DBLPTR dblptr )
  95. {
  96.     gl_model **m_dblptr = (gl_model **)dblptr;
  97.     gl_model *newmodel;
  98.     
  99.     NodePosition pos;
  100.     if (loadmdl( fullName )) {
  101.         pos = mdview.modelList->last();
  102.         newmodel = (gl_model *)pos->element();
  103.         *m_dblptr = newmodel;        
  104.     }
  105.  
  106. }
  107.  
  108.  
  109. /*
  110. loads a new skin
  111. */
  112. void importNewSkin( char *fullName )
  113. {
  114.     GLuint newTexBind = loadTexture( fullName );
  115.     NodePosition pos;
  116.     gl_model *model;
  117.     gl_mesh *mesh;
  118.     int meshNum,i;
  119.     unsigned int j;
  120.  
  121.     for (pos=mdview.modelList->first() ; pos!=NULL ; pos=mdview.modelList->after(pos)) {
  122.         model = (gl_model *)pos->element();
  123.         meshNum = model->meshNum;
  124.         for (i=0 ; i<meshNum ; i++) {
  125.             mesh = &model->meshes[i];
  126.             for (j=0 ; j<mesh->skinNum ; j++) {
  127.                 mesh->bindings[j] = newTexBind;
  128.             }
  129.         }
  130.     }
  131. }
  132.  
  133.  
  134. /* ------------------------------------------ delete code ------------------------------------------------------- */
  135.  
  136.  
  137. /*
  138. frees all mdviewdata, and effectively resets the data state back to init
  139. */
  140. void free_mdviewdata()
  141. {
  142.     NodePosition pos;
  143.     gl_model *model;
  144.  
  145.     /*
  146.     for(pos = mdview.modelList->first() ; pos!=NULL ; pos=next) {        
  147.         model = (gl_model *)pos->element();
  148.         // takes care of removing model from the list and everything, so assume pos is invalid        
  149.         delete_gl_model( model );
  150.  
  151.         // get next after cuz the list might have been changed by delete_gl_model
  152.         next = mdview.modelList->after(pos);
  153.     }
  154.     */
  155.  
  156.  
  157.     if (!mdview.modelList->isEmpty()) {
  158.         do {
  159.             pos = mdview.modelList->first();    
  160.  
  161.             model = (gl_model *)pos->element();
  162.             delete_gl_model( model ); // this removes its own position from the list
  163.  
  164.         } while (mdview.modelList->first()!=NULL);
  165.     }
  166.  
  167.     // if there is anything else left in texture res remove, 
  168.     // though deleting all gl_models in list should make it empty
  169.     freeTextureRes();    
  170. }
  171.  
  172.  
  173. /*
  174. frees a model that has been loaded before by loadmdl_totag into the modelptr slot
  175. */
  176. void freemdl_fromtag( GLMODEL_DBLPTR modelptr )
  177. {
  178.     gl_model **m_dblptr = (gl_model **)modelptr;
  179.     gl_model *model = *m_dblptr;
  180.     
  181.     if (!model) return;
  182.     
  183.     delete_gl_model( model );
  184.     
  185.     *m_dblptr = NULL;        
  186. }
  187.  
  188. /*
  189. frees data as for shutdown, call this only as the last thing before exiting or bad thigns will happen
  190. */
  191. void shutdown_mdviewdata()
  192. {
  193.     free_mdviewdata();
  194.     delete mdview.modelList; mdview.modelList = NULL;
  195.     delete mdview.textureRes; mdview.textureRes = NULL;
  196. }
  197.