Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7511 in orxonox.OLD for branches/bsp_model/src


Ignore:
Timestamp:
May 3, 2006, 2:51:12 PM (19 years ago)
Author:
bottac
Message:
 
Location:
branches/bsp_model/src/lib/graphics/importer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/bsp_model/src/lib/graphics/importer/bsp_file.cc

    r7510 r7511  
    11/*
    22   orxonox - the future of 3D-vertical-scrollers
    3 
     3 
    44   Copyright (C) 2006 orx
    5 
     5 
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 2, or (at your option)
    99   any later version.
    10 
     10 
    1111   ### File Specific:
    1212   main-programmer: bottac@ee.ethz.ch
     
    3636{}
    3737
     38/**
     39 *  Loads a quake3 level (*.bsp)
     40 * @param name the Name of the *.bsp file
     41 */
    3842int BspFile::read(char* name)
    3943{
     
    222226      PRINTF(4)("BSP FILE: Texture 0: %s. \n", &this->textures[8+ 72*i]);
    223227    this->load_textures();
    224 
     228   
    225229    // Load the lightMaps
    226230    this->glLightMapTextures = new GLuint[this->numLightMaps];
    227231    for(int i = 0; i < this->numLightMaps; i++)
    228232      this->glLightMapTextures[i] = this->loadLightMapToGL(this->lightMaps[i]);
    229 
     233   
    230234    //Create white texture for if no lightmap specified
    231235    glGenTextures(1, &this->whiteLightMap);
    232236    glBindTexture(GL_TEXTURE_2D, this->whiteLightMap);
    233         //Create texture
     237        //Create texture
    234238    this->whiteTexture[0]=255;
    235239    this->whiteTexture[1]=255;
    236240    this->whiteTexture[2]=255;
    237 
     241   
    238242    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    239243    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
     
    244248
    245249
    246 
     250 
    247251    /* control the mipmap levels */
    248252    glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);
     
    252256    glTexImage2D(GL_TEXTURE_2D,
    253257                 0,
    254                  GL_RGBA8,
     258                 GL_RGB,
    255259                 1,
    256260                 1,
     
    260264                 (const GLvoid *)&(this->whiteTexture));
    261265
    262     gluBuild2DMipmaps(  GL_TEXTURE_2D, GL_RGBA8, 1, 1,
     266    gluBuild2DMipmaps(  GL_TEXTURE_2D, GL_RGB, 1, 1,
    263267                       GL_RGB, GL_FLOAT,(const GLvoid *) &(this->whiteTexture));
    264 
    265 
     268   
     269   
    266270
    267271    // Get the number of patches
     
    313317}
    314318
     319/**
     320 *  Called by BspFile::build_tree() only.
     321 */
    315322BspTreeNode*   BspFile::build_tree_rec(int i)
    316323{
     
    324331  float z1 =(((plane *) this->planes) [planeIndex]).z;
    325332  thisNode->leafIndex = 0;
    326   thisNode->d          = (((plane *) this->planes) [planeIndex]).d;
     333  thisNode->d          = (((plane *) this->planes) [planeIndex]).d;
    327334
    328335  thisNode->plane = Vector(x1,y1,z1);
     
    356363}
    357364
     365/**
     366 *  returns the root node of the bsp-tree
     367 */
    358368BspTreeNode* BspFile::get_root()
    359369{
     
    464474      PRINTF(0)("BSP FILE: gefunden . \n");
    465475      this->Materials[i] =this->loadMat(fileName);
    466 
     476     
    467477    }
    468478
     
    480490      continue;
    481491    }
    482     //  Default Material
     492    //  Default Material
    483493    this->Materials[i].mat = new Material();
    484494    this->Materials[i].mat->setDiffuse(0.1,0.1,0.1);
     
    503513  if(this->testSurf != NULL) {
    504514    if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true;
    505     else                                       tmpAMat.alpha = false;
     515    else                                       tmpAMat.alpha = false;
    506516  } else   tmpAMat.alpha = false;
    507517
     
    510520  tmp->setAmbient(1.0,1.0,1.0 );
    511521  tmp->setSpecular(1.0,1.0,1.0);
    512   //    tmp->setShininess(.5);
    513   //    tmp->setTransparency(1.0);
     522  //    tmp->setShininess(.5);
     523  //    tmp->setTransparency(1.0);
    514524
    515525  tmp->setDiffuseMap(mat);
     
    539549  scale*=255.0;
    540550  sc*=scale;
    541     ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc;
    542 
    543 
     551    ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc; 
     552   
     553 
    544554  }
    545 
     555 
    546556  glGenTextures(1, &lightMap);
    547557  glBindTexture(GL_TEXTURE_2D,  lightMap);
     
    569579                   (const GLvoid *)&lightMapTexture);
    570580
    571 
     581   
    572582   // build the MipMaps automaticaly
    573583   errorCode = gluBuild2DMipmaps(GL_TEXTURE_2D,
     
    579589                                 (const GLvoid *)&lightMapTexture
    580590                                );
    581 
     591   
    582592
    583593
     
    587597}
    588598
     599/**
     600 * Generates a vertex-array, a indice-array and a texture-coordinates-array for iface.
     601 * @param iface integer index of face
     602 * @todo cleanup this function, let the user choose the level of tesselation
     603 */
     604 
     605 
    589606void BspFile::tesselate(int iface)
    590607{
     
    715732
    716733
    717           //Vertice[u*(tesselation+1)+v]=       temp[0]*((1.0f-px)*(1.0f-px))+ temp[1]*((1.0f-px)*px*2)+ temp[2]*(px*px);
     734          //Vertice[u*(tesselation+1)+v]=       temp[0]*((1.0f-px)*(1.0f-px))+ temp[1]*((1.0f-px)*px*2)+ temp[2]*(px*px);
    718735          Vertice[u*(level1)+v].position[0]=temp[0].position[0]*((1.0f-px)*(1.0f-px))+temp[1].position[0]*((1.0f-px)*px*2)+temp[2].position[0]*(px*px);
    719736          Vertice[u*(level1)+v].position[1]=temp[0].position[1]*((1.0f-px)*(1.0f-px))+temp[1].position[1]*((1.0f-px)*px*2)+temp[2].position[1]*(px*px);
     
    750767      // Debug Model
    751768      //***********************************************************************************************************************
     769     
    752770      this->VertexArrayModels[this->patchOffset] = new VertexArrayModel();
    753771      VertexArrayModel*  tmp = this->VertexArrayModels[this->patchOffset];
  • branches/bsp_model/src/lib/graphics/importer/bsp_file.h

    r7507 r7511  
    156156  brushside* brushSides;     //!<
    157157  char* vertice;             //!<
    158   meshvert* meshverts;       //!<
    159   char* visData;             //!<
    160   char* textures;            //!<
     158  meshvert* meshverts;       //!< Buffer to store meshverice
     159  char* visData;             //!< Buffer to store visibility data
     160  char* textures;            //!< Holds all the texture filename strings
    161161  char* patchVertice;        //!<
    162162  char* patchIndexes;
  • branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc

    r7510 r7511  
    11/*
    22   orxonox - the future of 3D-vertical-scrollers
    3 
     3 
    44   Copyright (C) 2006 orx
    5 
     5 
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 2, or (at your option)
    99   any later version.
    10 
     10 
    1111   ### File Specific:
    1212   main-programmer: bottac@ee.ethz.ch
     
    5151  // Draw Debug Terrain
    5252  /*
    53   this->bspFile->Materials[0]->select();
     53  this->bspFile->Materials[0]->select(); 
    5454  for(int i = 0; i <  this->bspFile->numPatches ; i++)
    55         {
    56                 this->bspFile->VertexArrayModels[i]->draw();
    57 
    58         }
     55        {
     56                this->bspFile->VertexArrayModels[i]->draw();
     57   
     58        }
    5959  */
    6060
     
    103103        if (f >=0 && !this->isAlreadyVisible(f)) {
    104104          this->alreadyVisible[f] = true;
    105           /*    if(ActLeaf->leafIndex == i)public final double readLEDouble()
    106                 {
    107                         this->alreadyVisible[i] = false;
    108                         this->draw_debug_face(f);
    109                         this->alreadyVisible[i] = true;
    110                 }
     105          /*    if(ActLeaf->leafIndex == i)public final double readLEDouble()
     106                {
     107                        this->alreadyVisible[i] = false;
     108                        this->draw_debug_face(f);
     109                        this->alreadyVisible[i] = true;
     110                } 
    111111                else */
    112112          addFace(f); // "visibleFaces.append(f)"
     
    131131      leaf& curLeaf =  (this->bspFile->leaves)[i] ;
    132132      cluster =  curLeaf.cluster;
    133 
     133     
    134134      if(cluster <0) continue;
    135135      v = ((viscluster *  ( ((int *)this->bspFile->visData)[1]) ) + (cluster / 8));
    136136      visSet =((unsigned char*) (this->bspFile->visData))[v+8];
    137 
    138 
     137   
     138     
    139139      if( ((visSet) & ((unsigned char)1 <<(unsigned char) (cluster &  7))) == 0 )
    140140      {
     
    194194  //   this->lastTex = curFace.texture;
    195195  //}
    196 
    197     if(curFace.lm_index < 0)
     196   
     197    if(curFace.lm_index < 0) 
    198198    {
    199199      glActiveTextureARB(GL_TEXTURE1_ARB);
    200       glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[this->bspFile->whiteLightMap]);
     200      glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap );
    201201      glEnable(GL_TEXTURE_2D);
    202202    }
     
    207207    glEnable(GL_TEXTURE_2D);
    208208    }
    209 
     209   
    210210    glColor4f(3.0,3.0,3.0,0.9);
    211   glEnableClientState(GL_VERTEX_ARRAY );
     211  glEnableClientState(GL_VERTEX_ARRAY ); 
    212212  //glEnableClientState(GL_TEXTURE_COORD_ARRAY );
    213213  glEnableClientState(GL_NORMAL_ARRAY );
    214214  //  glEnableClientState(GL_COLOR_ARRAY);
    215 
     215 
    216216
    217217  glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0]));
    218 
     218 
    219219  glClientActiveTextureARB(GL_TEXTURE0_ARB);
    220220  glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0]));
    221221  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    222 
     222 
    223223  glClientActiveTextureARB(GL_TEXTURE1_ARB);
    224224  glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1]));
    225225  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    226226
    227 
     227 
    228228  glNormalPointer( GL_FLOAT, stride, &(curVertex[offset].normal[0]));
    229229  // glColorPointer(4, GL_BYTE, stride, &(curVertex[offset].color[0]));
     
    287287void BspManager::draw_patch(face* Face)
    288288{
    289   if(this->lastTex != Face->texture) {
     289  //if(this->lastTex != Face->texture) {
    290290    this->bspFile->Materials[Face->texture].mat->select();
    291     this->lastTex = Face->texture;
    292   }
    293 
    294 
    295 
    296   if(Face->lm_index < 0)
     291    //this->lastTex = Face->texture;
     292  //}
     293 
     294 
     295 
     296  if(Face->lm_index < 0) 
    297297  {
    298298    glActiveTextureARB(GL_TEXTURE1_ARB);
    299     glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[this->bspFile->whiteLightMap]);
     299    glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap);
    300300    glEnable(GL_TEXTURE_2D);
    301301  }
     
    307307}
    308308    glColor4f(3.0,3.0,3.0,0.9);
    309 
     309 
    310310  glEnable( GL_AUTO_NORMAL);
    311311  glEnableClientState(GL_VERTEX_ARRAY );
     
    314314    glFrontFace(GL_CW);
    315315    //PRINTF(0)("BSP Manager: Face->size[0]: %i . \n", Face->size[0]);
    316 
    317 
     316 
     317 
    318318    glEnableClientState(GL_NORMAL_ARRAY );
    319319
    320320    glVertexPointer(3, GL_FLOAT,44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).position[0]));
    321 
    322 
     321   
     322   
    323323    glClientActiveTextureARB(GL_TEXTURE0_ARB);
    324324    glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[0][0]));
    325325    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    326326
    327 
     327   
    328328    glClientActiveTextureARB(GL_TEXTURE1_ARB);
    329329    glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[1][0]));
    330330    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    331331
    332 
     332   
    333333    glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) );
    334334
    335     // We'll need multitexture suport for lightning
    336     //glClientActiveTextureARB(GL_TEXTURE0_ARB);
    337     //glTexCoordPointer(2, GL_FLOAT,0, &vertex[0].textureCoord);
    338     //glClientActiveTextureARB(GL_TEXTURE1_ARB);
    339     //glTexCoordPointer(2, GL_FLOAT, sizeof(BSPVertex), &vertex[0].lightmapCoord);
     335 
    340336
    341337
     
    344340                     & (     (((GLuint*)  (this->bspFile->patchIndexes))[7*8*2*(Face->meshvert+i)+ row*2*8]  ))  );
    345341    }
    346 
     342   
    347343    glFrontFace(GL_CCW);
    348344  }
     
    352348  glDisableClientState(GL_VERTEX_ARRAY );
    353349  glDisableClientState(GL_TEXTURE_COORD_ARRAY );
    354 
     350 
    355351  glBegin(GL_QUADS);
    356 
     352 
    357353  glEnd();
    358354}
     
    406402
    407403    /*
    408         for(int i = 0; i < camLeaf.n_leafbrushes && i < 10; i++ )
    409         {
    410                 brush& curBrush = ((brush*)(this->bspFile->brushes))[(camLeaf.leafbrush_first +i)%this->bspFile->numLeafBrushes];
    411                 if(curBrush.n_brushsides < 0) return;
    412                 for(int j = 0; j < curBrush.n_brushsides; j++)
    413                 {
    414                 float dist = -0.1;
    415                 brushside& curBrushSide = ((brushside*)(this->bspFile->brushSides))[(curBrush.brushside +j)%this->bspFile->numBrushSides];
    416                 plane&      testPlane = ((plane*)(this->bspFile->planes))[curBrushSide.plane % this->bspFile->numPlanes];
    417                 dist = testPlane.x * this->cam.x +  testPlane.y * this->cam.y  +  testPlane.z * this->cam.z   -testPlane.d ;
    418 
    419                 if(dist < -0.01f) dist = -1.0f *dist;
    420                 if(dist < 1.0f){
    421                                 this->drawDebugCube(&this->cam);
    422                                 return;
    423                               }
    424                 }
    425 
    426         } */
     404        for(int i = 0; i < camLeaf.n_leafbrushes && i < 10; i++ )
     405        {
     406                brush& curBrush = ((brush*)(this->bspFile->brushes))[(camLeaf.leafbrush_first +i)%this->bspFile->numLeafBrushes];
     407                if(curBrush.n_brushsides < 0) return;
     408                for(int j = 0; j < curBrush.n_brushsides; j++)
     409                {
     410                float dist = -0.1;
     411                brushside& curBrushSide = ((brushside*)(this->bspFile->brushSides))[(curBrush.brushside +j)%this->bspFile->numBrushSides];
     412                plane&      testPlane = ((plane*)(this->bspFile->planes))[curBrushSide.plane % this->bspFile->numPlanes];
     413                dist = testPlane.x * this->cam.x +  testPlane.y * this->cam.y  +  testPlane.z * this->cam.z   -testPlane.d ;
     414               
     415                if(dist < -0.01f) dist = -1.0f *dist;
     416                if(dist < 1.0f){
     417                                this->drawDebugCube(&this->cam);
     418                                return;
     419                              }
     420                }
     421                       
     422        } */
    427423
    428424  }
Note: See TracChangeset for help on using the changeset viewer.