home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / Drone.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-01-22  |  15.7 KB  |  558 lines

  1. #include "Drone.h"
  2.  
  3. #include "Game.h"
  4. #include "Renderer.h"
  5. #include "log.h"
  6. #include "matrixmath.h"
  7.  
  8. #include <math.h>
  9.  
  10. Drone::Drone(Client* client): Vehicle(client){
  11.  
  12.     bodyModel = NULL;
  13.     bodyAnimator = NULL;
  14.     jetsModel = NULL;
  15.     jetsAnimator = NULL;
  16.     jetsFrame = 1.0f;
  17.  
  18.     dlpcs.clear();
  19.     jetsModelSecondaryColors = NULL;
  20.     bodyModelSecondaryColors = NULL;
  21.     for(int i=0;i<4;i++){
  22.         weaponModelSecondaryColors[i] = NULL;
  23.     }
  24. }
  25.  
  26. Drone::~Drone(){
  27.     int i, j;
  28.  
  29.     if( jetsModelSecondaryColors != NULL ){
  30.         for(i=0;i<jetsModel->numMeshes;i++){
  31.             delete[] jetsModelSecondaryColors[i];
  32.         }
  33.         delete[] jetsModelSecondaryColors;
  34.     }
  35.     if( bodyModelSecondaryColors != NULL ){
  36.         for(i=0;i<bodyModel->numMeshes;i++){
  37.             delete[] bodyModelSecondaryColors[i];
  38.         }
  39.         delete[] bodyModelSecondaryColors;
  40.     }
  41.     for(i=0;i<4;i++){
  42.         if( weaponModelSecondaryColors[i] != NULL ){
  43.             for(j=0;j<weapons[i]->model->numMeshes;j++){
  44.                 delete[] weaponModelSecondaryColors[i][j];
  45.             }
  46.             delete[] weaponModelSecondaryColors[i];
  47.         }
  48.     }
  49.  
  50.     if( bodyAnimator != NULL )
  51.         delete bodyAnimator;
  52.     if( jetsAnimator != NULL )
  53.         delete jetsAnimator;
  54.  
  55.     for(unsigned int k=0;k<dlpcs.size();k++){
  56.         dlpcs[k].dlpc->vehicles.remove(this);
  57.  
  58.         if( jetsModel != NULL ){
  59.             for(j=0;j<jetsModel->numMeshes;j++){
  60.                 delete[] dlpcs[k].jetsModel_colors[j];
  61.             }
  62.             delete[] dlpcs[k].jetsModel_colors;
  63.         }
  64.  
  65.         if( bodyModel != NULL ){
  66.             for(j=0;j<bodyModel->numMeshes;j++){
  67.                 delete[] dlpcs[k].bodyModel_colors[j];
  68.             }
  69.             delete[] dlpcs[k].bodyModel_colors;
  70.         }
  71.     }
  72.     dlpcs.clear();
  73. }
  74.  
  75.  
  76. void Drone::moveForward(float deltaT){
  77.     vectorMA3d(vel_inp, deltaT*moveSpeed, dir, vel_inp);
  78. }
  79. void Drone::moveBackward(float deltaT){
  80.     vectorMA3d(vel_inp, -deltaT*moveSpeed, dir, vel_inp);
  81. }
  82. void Drone::moveLeft(float deltaT){
  83.     vectorMA3d(vel_inp, deltaT*moveSpeed, left, vel_inp);
  84. }
  85. void Drone::moveRight(float deltaT){
  86.     vectorMA3d(vel_inp, -deltaT*moveSpeed, left, vel_inp);
  87. }
  88. void Drone::moveUp(float deltaT){
  89.     vectorMA3d(vel_inp, deltaT*moveSpeed, e2, vel_inp);
  90. }
  91. void Drone::moveDown(float deltaT){
  92.     vectorMA3d(vel_inp, -deltaT*moveSpeed, e2, vel_inp);
  93. }
  94.  
  95.  
  96. void Drone::move(){
  97.     unsigned int currentMillis = SDL_GetTicks();
  98.     
  99.     if( lastMoveMillis >= currentMillis )    // sanity check
  100.         return;
  101.         
  102.     float deltaT = (currentMillis - lastMoveMillis)/1000.0f;
  103.     lastMoveMillis = currentMillis;
  104.     
  105.     reconstructVectors();    // make sure local COSystem is orthonormal
  106.     anglesFromVectors();
  107.  
  108.     // calc recovery
  109.     calcRecovery();
  110.  
  111.     // set animation
  112.     if( jetsAnimator != NULL ){
  113.         vec3_t tmp1;
  114.         vectorInit3d((float)(cos(yaw)), 0.0f, (float)(sin(yaw)), tmp1);
  115.  
  116.         float dp = vectorDotP3d(tmp1, vel_inp);
  117.         float mod = 0.0f;
  118.         float maxMod = 1.0;
  119.  
  120.         if( fabs(dp) > 0.001 ){
  121.             mod = dp * deltaT * 3.0f;
  122.             maxMod = (float)( 1.0 - fabs(pitch - PI/2.0)*2.0/PI );
  123.         }else{
  124.             if( jetsFrame > 1.01f ){
  125.                 mod = -1.5f * deltaT;    // backforce
  126.             }else if( jetsFrame < 0.99f ){
  127.                 mod = 1.5f * deltaT;    // backforce
  128.             }else{
  129.                 mod = 0.0;
  130.             }
  131.             maxMod = 1.0;
  132.         }
  133.         
  134.         jetsFrame += mod;
  135.  
  136.         if( jetsFrame > 1.0f + maxMod ){
  137.             jetsFrame = 1.0f + maxMod;
  138.         }
  139.         if( jetsFrame < 1.0f - maxMod){
  140.             jetsFrame = 1.0f - maxMod;
  141.         }
  142.         jetsAnimator->setCurrentFrame(jetsFrame);
  143.     }
  144.  
  145.  
  146.     // do physics
  147.     vectorScale3d(600.0f, vel_inp, physicsInfo.F_i);
  148.     vectorCopy3d(vel, physicsInfo.v);
  149.     physicsInfo.r = 50.0f;
  150.     physicsInfo.g = 0.0f;
  151.     physicsInfo.calcAcceleration();
  152.     vectorMA3d(vel, deltaT, physicsInfo.a, vel);
  153.     if( vectorLength3d(vel) > moveSpeed ){
  154.         vectorNormalize3d(vel, vel);
  155.         vectorScale3d(moveSpeed, vel, vel);
  156.     }
  157.  
  158.  
  159.     vec3_t displacement;
  160.     vectorScale3d(deltaT, vel, displacement);
  161.  
  162.     if( collisionDetection(displacement) ){        // check if move is save
  163.         vectorAdd3d(pos, displacement, pos);    // ...and move
  164.     }
  165.  
  166.     vectorScale3d(1.0f/deltaT, displacement, vel);
  167. }
  168.  
  169.  
  170. void Drone::addDynamicLightParticleCluster(DynamicLightParticleCluster* dlpc){
  171.     int i, j, k;
  172.     drone_dlpcCombo_t c;
  173.  
  174.     c.dlpc = dlpc;
  175.  
  176.     // JETS
  177.     if( jetsModel != NULL ){
  178.         int frame = (int)jetsAnimator->getCurrentFrame();
  179. //        printf("frame: %i\n", frame);
  180.  
  181.         vec3_t tmp;
  182.         vectorInit3d((float)(cos(yaw)), 0.0f, (float)(sin(yaw)), tmp);
  183.         float m[] = {    left[0], left[1], left[2], 0.0f,
  184.                         e2[0], e2[1], e2[2], 0.0f,
  185.                         tmp[0], tmp[1], tmp[2], 0.0f,
  186.                         pos[0], pos[1], pos[2], 1.0f
  187.                     };
  188.  
  189.         float im[16];
  190.         float cm[16];
  191.         vec4_t transformedPos;
  192.  
  193.         c.jetsModel_colors = new GLfloat*[jetsModel->numMeshes];
  194.         for(i=0;i<jetsModel->numMeshes;i++){
  195.             Mesh* mesh = jetsModel->meshes[i];
  196.             c.jetsModel_colors[i] = new GLfloat[mesh->numVertices*3];
  197.         
  198.             matrixMultMatrix(m, jetsModel->matrices[frame][i], 4, cm);
  199.             matrixInvert(cm, 4, im);
  200.             vectorInit4d(dlpc->pos[0], dlpc->pos[1], dlpc->pos[2], 1.0f, transformedPos);
  201.             matrixMultVector(im, transformedPos, 4, transformedPos);
  202.             float transformedRadius = dlpc->radius;// * (float)(fabs(im[0]);
  203.     
  204.             for(j=0;j<mesh->numVertices;j++){
  205.                 float f = vectorPointDistance3d(transformedPos, &mesh->vertices[j*3]) / transformedRadius;
  206.                 if( f < 0.0f ){        // most likely matrix was not inverted correctly...
  207. //                    printf("jets: f: %f;  tr: %f\n", f, transformedRadius);
  208.                     f = 0.0f;
  209.                 }
  210.                 if( f > 1.0f ){
  211. //                    printf("jets: f: %f;  tr: %f\n", f, transformedRadius);
  212.                     f = 1.0f;
  213.                 }
  214.                 //f = f > 1.0f ? 1.0f : f;
  215.                 vectorScale3d(1.0f - f, dlpc->col, &c.jetsModel_colors[i][j*3]);
  216.                 vectorAdd3d(&jetsModelSecondaryColors[i][j*3], &c.jetsModel_colors[i][j*3], &jetsModelSecondaryColors[i][j*3]);
  217.             }
  218.         }
  219.     }
  220.  
  221.     // BODY
  222.     if( bodyModel != NULL ){
  223.         int frame = 0;//(int)jetsAnimator->getCurrentFrame();
  224. //        printf("frame: %i\n", frame);
  225.  
  226. //        vec3_t tmp;
  227. //        vectorInit3d((float)(cos(yaw)), 0.0f, (float)(sin(yaw)), tmp);
  228.         float m[] = {    left[0], left[1], left[2], 0.0f,
  229.                         up[0], up[1], up[2], 0.0f,
  230.                         dir[0], dir[1], dir[2], 0.0f,
  231.                         pos[0], pos[1], pos[2], 1.0f
  232.                     };
  233.  
  234.         float im[16];
  235.         float cm[16];
  236.         vec4_t transformedPos;
  237.  
  238.         c.bodyModel_colors = new GLfloat*[bodyModel->numMeshes];
  239.         for(i=0;i<bodyModel->numMeshes;i++){
  240.             Mesh* mesh = bodyModel->meshes[i];
  241.             c.bodyModel_colors[i] = new GLfloat[mesh->numVertices*3];
  242.         
  243.             matrixMultMatrix(m, bodyModel->matrices[frame][i], 4, cm);
  244.             matrixInvert(cm, 4, im);
  245.             vectorInit4d(dlpc->pos[0], dlpc->pos[1], dlpc->pos[2], 1.0f, transformedPos);
  246.             matrixMultVector(im, transformedPos, 4, transformedPos);
  247.             float transformedRadius = dlpc->radius;// * (float)fabs(im[0]);
  248.     
  249.             for(j=0;j<mesh->numVertices;j++){
  250.                 float f = vectorPointDistance3d(transformedPos, &mesh->vertices[j*3]) / transformedRadius;
  251.                 if( f < 0.0f ){        // most likely matrix was not inverted correctly...
  252. //                    printf("body: f: %f;  tr: %f\n", f, transformedRadius);
  253.                     f = 0.0f;
  254.                 }
  255.                 if( f > 1.0f ){
  256. //                    printf("body: f: %f;  tr: %f\n", f, transformedRadius);
  257.                     f = 1.0f;
  258.                 }
  259. //                f = f > 1.0f ? 1.0f : f;
  260.                 vectorScale3d(1.0f - f, dlpc->col, &c.bodyModel_colors[i][j*3]);
  261.                 vectorAdd3d(&bodyModelSecondaryColors[i][j*3], &c.bodyModel_colors[i][j*3], &bodyModelSecondaryColors[i][j*3]);
  262.             }
  263.         }
  264.     }
  265.  
  266.     // WEAPONS
  267.     for(k=0;k<4;k++){
  268.         if( weapons[k] != NULL ){
  269.             int frame = 0;
  270.             float m[] = {    left[0], left[1], left[2], 0.0f,
  271.                             up[0], up[1], up[2], 0.0f,
  272.                             dir[0], dir[1], dir[2], 0.0f,
  273.                             pos[0], pos[1], pos[2], 1.0f
  274.                         };
  275.     
  276.             float transM[] =    {    1.0f, 0.0f, 0.0f, 0.0f, 
  277.                                     0.0f, 1.0f, 0.0f, 0.0f,
  278.                                     0.0f, 0.0f, 1.0f, 0.0f,
  279.                                     weapons[k]->mountPoint[0], weapons[k]->mountPoint[1], weapons[k]->mountPoint[2], 1.0f
  280.                                 };
  281.  
  282.             float im[16];
  283.             float cm[16];
  284.             vec4_t transformedPos;
  285.  
  286.             c.weaponModel_colors[k] = new GLfloat*[weapons[k]->model->numMeshes];
  287.             for(i=0;i<weapons[k]->model->numMeshes;i++){
  288.                 Mesh* mesh = weapons[k]->model->meshes[i];
  289.                 c.weaponModel_colors[k][i] = new GLfloat[mesh->numVertices*3];
  290.         
  291.                 matrixMultMatrix(m, transM, 4, cm);
  292.                 matrixMultMatrix(cm, weapons[k]->model->matrices[frame][i], 4, cm);
  293.                 matrixInvert(cm, 4, im);
  294.                 vectorInit4d(dlpc->pos[0], dlpc->pos[1], dlpc->pos[2], 1.0f, transformedPos);
  295.                 matrixMultVector(im, transformedPos, 4, transformedPos);
  296.                 float transformedRadius = dlpc->radius;// * (float)fabs(im[0]);
  297.     
  298.                 for(j=0;j<mesh->numVertices;j++){
  299.                     float f = vectorPointDistance3d(transformedPos, &mesh->vertices[j*3]) / transformedRadius;
  300.                     if( f < 0.0f ){        // most likely matrix was not inverted correctly...
  301.                         f = 0.0f;
  302.                     }
  303.                     if( f > 1.0f ){
  304.                         f = 1.0f;
  305.                     }
  306.                     vectorScale3d(1.0f - f, dlpc->col, &c.weaponModel_colors[k][i][j*3]);
  307.                     vectorAdd3d(&weaponModelSecondaryColors[k][i][j*3], &c.weaponModel_colors[k][i][j*3], &weaponModelSecondaryColors[k][i][j*3]);
  308.                 }
  309.             }
  310.         }
  311.     }
  312.  
  313.     dlpcs.push_back(c);
  314. //    printf("dlpc added!\n");
  315. }
  316. void Drone::removeDynamicLightParticleCluster(DynamicLightParticleCluster* dlpc){
  317.     int i,j;
  318.  
  319.     for( vector<drone_dlpcCombo_t>::iterator iter = dlpcs.begin(); iter != dlpcs.end(); iter++ ){
  320.         if( iter->dlpc == dlpc ){
  321.             if( jetsModel != NULL ){
  322.                 for(i=0;i<jetsModel->numMeshes;i++){
  323.                     Mesh* m = jetsModel->meshes[i];
  324.                     for(j=0;j<m->numVertices;j++){
  325.                         vectorSub3d(&jetsModelSecondaryColors[i][j*3], &iter->jetsModel_colors[i][j*3], &jetsModelSecondaryColors[i][j*3]);
  326.                     }
  327.                     delete[] iter->jetsModel_colors[i];
  328.                 }
  329.                 delete[] iter->jetsModel_colors;
  330.             }
  331.  
  332.             if( bodyModel != NULL ){
  333.                 for(i=0;i<bodyModel->numMeshes;i++){
  334.                     Mesh* m = bodyModel->meshes[i];
  335.                     for(j=0;j<m->numVertices;j++){
  336.                         vectorSub3d(&bodyModelSecondaryColors[i][j*3], &iter->bodyModel_colors[i][j*3], &bodyModelSecondaryColors[i][j*3]);
  337.                     }
  338.                     delete[] iter->bodyModel_colors[i];
  339.                 }
  340.                 delete[] iter->bodyModel_colors;
  341.             }
  342.  
  343.             for(int k=0;k<4;k++){
  344.                 if( weapons[k] != NULL ){
  345.                     for(i=0;i<weapons[k]->model->numMeshes;i++){
  346.                         Mesh* m = weapons[k]->model->meshes[i];
  347.                         for(j=0;j<m->numVertices;j++){
  348.                             vectorSub3d(&weaponModelSecondaryColors[k][i][j*3], &iter->weaponModel_colors[k][i][j*3], &weaponModelSecondaryColors[k][i][j*3]);
  349.                         }
  350.                         delete[] iter->weaponModel_colors[k][i];
  351.                     }
  352.                     delete[] iter->weaponModel_colors[k];
  353.                 }
  354.             }
  355.  
  356.             dlpcs.erase(iter);
  357.             break;
  358.         }
  359.     }
  360.  
  361. //    printf("dlpc removed!\n");
  362. }
  363.  
  364.  
  365.  
  366. void Drone::render(){
  367.     int i, j, k;
  368.  
  369.     int lm_sav = Renderer::info.var.lightingMode;
  370.  
  371.     // calc the shading color
  372.     if( Renderer::info.var.shadeVehicles &&
  373.         (Renderer::info.var.lightingMode == LIGHTING_MODE_VERTEX || Renderer::info.var.lightingMode == LIGHTING_MODE_LIGHTMAP) ){
  374.  
  375.         Renderer::info.var.lightingMode = LIGHTING_MODE_VERTEX;    // set to vertex lighting because we need vertex colors
  376.  
  377.         vec3_t col, absMin, absMax;
  378.         vectorInit3d(0.0f, 0.0f, 0.0f, col);
  379.         float w_sum = 0.0f;
  380.         float maxDistance = 7.0f;
  381.  
  382.         vectorInit3d(pos[0]-maxDistance, pos[1]-maxDistance, pos[2]-maxDistance, absMin);
  383.         vectorInit3d(pos[0]+maxDistance, pos[1]+maxDistance, pos[2]+maxDistance, absMax);
  384.         vector<SpacePartitioningTreeNode*> nodes = Game::arena->sptree->getLeafNodesIntersectingAABB(absMin, absMax);
  385.  
  386.         for(i=0;i<(signed int)nodes.size();i++){
  387. //            nodes[i]->drawBorders();
  388.             Mesh* m = nodes[i]->mesh;
  389.             if( m != NULL ){
  390.  
  391.                 for(j=0;j<m->numVertices;j++){
  392.                     float d = vectorPointDistance3d(pos, &m->vertices[j*3]);
  393. //                    vec3_t tmp;
  394. //                    vectorSub3d(&m->vertices[j*3], pos, tmp);
  395. //                    float d = vectorLength3d(tmp);
  396.                     if( d < maxDistance /*&& vectorDotP3d(tmp, &m->normals[j*3]) < 0.0f*/ ){
  397.                         float w = 1.0f - d/maxDistance;
  398.                         w_sum += w;
  399.                         vectorMA3d(col, w, &m->colors[j*3], col);
  400. //                        Renderer::debug_renderLinesegment(pos, &m->vertices[j*3]);
  401.                     }
  402.                 }
  403.  
  404. //                if( nearestIndex != -1 ){
  405. //                    vectorCopy3d(&m->colors[nearestIndex*3], col);
  406. //                    Renderer::debug_renderLinesegment(pos, &m->vertices[nearestIndex*3]);
  407. //                }
  408.             }
  409.         }
  410.         
  411.         if( w_sum > 0.0f ){    // assign new colors
  412.             vectorScale3d(1.0f/w_sum, col, col);
  413.  
  414.             if( bodyModel != NULL ){
  415.                 for(i=0;i<bodyModel->numMeshes;i++){
  416.                     for(j=0;j<bodyModel->meshes[i]->numColors;j++){
  417.                         vectorCopy3d(col, &bodyModel->meshes[i]->colors[j*3]);
  418.                     }
  419.                 }    
  420.             }
  421.             if( jetsModel != NULL ){
  422.                 for(i=0;i<jetsModel->numMeshes;i++){
  423.                     for(j=0;j<jetsModel->meshes[i]->numColors;j++){
  424.                         vectorCopy3d(col, &jetsModel->meshes[i]->colors[j*3]);
  425.                     }
  426.                 }
  427.             }
  428.             for(k=0;k<4;k++){
  429.                 if( weapons[k] ==  NULL )
  430.                     continue;
  431.  
  432.                 for(i=0;i<weapons[k]->model->numMeshes;i++){
  433.                     for(j=0;j<weapons[k]->model->meshes[i]->numColors;j++){
  434.                         vectorCopy3d(col, &weapons[k]->model->meshes[i]->colors[j*3]);
  435.                     }
  436.                 }
  437.             }
  438.         }else{    // keep old colors
  439.         }
  440.  
  441.     }
  442.  
  443.     // jets
  444.     if( jetsModel != NULL ){
  445.  
  446.         if( Renderer::info.var.useDynamicLighting && jetsModelSecondaryColors != NULL ){    // setup dyn lighting
  447.             for(i=0;i<jetsModel->numMeshes;i++){
  448.                 jetsModel->meshes[i]->secondaryColors = jetsModelSecondaryColors[i];
  449.             }
  450.  
  451.         }
  452.  
  453.         glPushMatrix();
  454.  
  455.         vec3_t tmp;
  456.         vectorInit3d((float)(cos(yaw)), 0.0f, (float)(sin(yaw)), tmp);
  457.         float m[] = {    left[0], left[1], left[2], 0.0f,
  458.                         e2[0], e2[1], e2[2], 0.0f,
  459.                         tmp[0], tmp[1], tmp[2], 0.0f,
  460.                         pos[0], pos[1], pos[2], 1.0f
  461.                     };
  462.         glMultMatrixf(m);
  463.  
  464.         float frame = 0.0f;
  465.         if( jetsAnimator != NULL ){
  466.             frame = jetsAnimator->getCurrentFrame();
  467.         }
  468.         Renderer::renderModel(jetsModel, frame);
  469.  
  470.         glPopMatrix();
  471.  
  472.         if( Renderer::info.var.useDynamicLighting && jetsModelSecondaryColors != NULL ){
  473.             for(i=0;i<jetsModel->numMeshes;i++){
  474.                 jetsModel->meshes[i]->secondaryColors = NULL;
  475.             }
  476.         }
  477.     }
  478.  
  479.  
  480.     // body
  481.     if( bodyModel != NULL &&
  482.             !(Game::cam.mode == CAMERA_MODE_FIRST_PERSON && Game::cam.target == this) ){
  483.  
  484.         if( Renderer::info.var.useDynamicLighting && bodyModelSecondaryColors != NULL ){    // setup dyn lighting
  485.             for(i=0;i<bodyModel->numMeshes;i++){
  486.                 bodyModel->meshes[i]->secondaryColors = bodyModelSecondaryColors[i];
  487.             }
  488.         }
  489.  
  490.  
  491.         
  492.         glPushMatrix();
  493.         float m[] = {    left[0], left[1], left[2], 0.0f,
  494.                     up[0], up[1], up[2], 0.0f,
  495.                     dir[0], dir[1], dir[2], 0.0f,
  496.                     pos[0], pos[1], pos[2], 1.0f
  497.                 };
  498.         glMultMatrixf(m);
  499.         Renderer::renderModel(bodyModel);
  500.  
  501.         glPopMatrix();
  502.  
  503.         if( Renderer::info.var.useDynamicLighting && bodyModelSecondaryColors != NULL ){
  504.             for(i=0;i<bodyModel->numMeshes;i++){
  505.                 bodyModel->meshes[i]->secondaryColors = NULL;
  506.             }
  507.         }
  508.  
  509.     }
  510.  
  511.     // weapons
  512.     for( k=0; k<4; k++ ){
  513.         if( weapons[k] == NULL )
  514.             continue;
  515.  
  516.         if( Renderer::info.var.useDynamicLighting && weaponModelSecondaryColors[k] != NULL ){    // setup dyn lighting
  517.             for(i=0;i<weapons[k]->model->numMeshes;i++){
  518.                 weapons[k]->model->meshes[i]->secondaryColors = weaponModelSecondaryColors[k][i];
  519.             }
  520.         }
  521.         
  522.         glPushMatrix();
  523.         float m[] = {    left[0], left[1], left[2], 0.0f,
  524.                     up[0], up[1], up[2], 0.0f,
  525.                     dir[0], dir[1], dir[2], 0.0f,
  526.                     pos[0], pos[1], pos[2], 1.0f
  527.                 };
  528.         glMultMatrixf(m);
  529.  
  530.         glTranslatef(weapons[k]->mountPoint[0], weapons[k]->mountPoint[1], weapons[k]->mountPoint[2]);
  531.  
  532.         float frame = 0.0f;
  533.         if( weapons[k]->animator != NULL ){    // setup animation
  534.             frame = weapons[k]->animator->calcCurrentFrame();
  535. //            printf("frame: %f\n", frame);
  536.         }
  537.         Renderer::renderModel(weapons[k]->model, frame);
  538.  
  539.         glPopMatrix();
  540.  
  541.         if( Renderer::info.var.useDynamicLighting && weaponModelSecondaryColors[k] != NULL ){
  542.             for(i=0;i<weapons[k]->model->numMeshes;i++){
  543.                 weapons[k]->model->meshes[i]->secondaryColors = NULL;
  544.             }
  545.         }
  546.     }
  547.  
  548.     if( Renderer::info.var.shadeVehicles &&
  549.         (Renderer::info.var.lightingMode == LIGHTING_MODE_VERTEX || Renderer::info.var.lightingMode == LIGHTING_MODE_LIGHTMAP) ){
  550.  
  551.         Renderer::info.var.lightingMode = lm_sav;    // restore lm if we did vehcile shading
  552.     }
  553.  
  554.     Vehicle::render();
  555.  
  556. }
  557.  
  558.