Show
Ignore:
Timestamp:
03/21/12 18:36:20 (3 years ago)
Author:
robert
Message:

Ran script to remove trailing spaces and tabs

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgSim/Impostor.cpp

    r11487 r13041  
    1  /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield  
     1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 
    22 * 
    3  * This library is open source and may be redistributed and/or modified under   
    4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or  
     3 * This library is open source and may be redistributed and/or modified under 
     4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
    55 * (at your option) any later version.  The full license is in LICENSE file 
    66 * included with this distribution, and on the openscenegraph.org website. 
    7  *  
     7 * 
    88 * This library is distributed in the hope that it will be useful, 
    99 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
     10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1111 * OpenSceneGraph Public License for more details. 
    1212*/ 
     
    2020// use this cull callback to allow the camera to traverse the Impostor's children without 
    2121// actuall having them assigned as children to the camea itself.  This make the camera a 
    22 // decorator without ever directly being assigned to it.  
     22// decorator without ever directly being assigned to it. 
    2323class ImpostorTraverseNodeCallback : public osg::NodeCallback 
    2424{ 
    2525public: 
    2626 
    27     ImpostorTraverseNodeCallback(osgSim::Impostor* node):_node(node) {}                                                        
     27    ImpostorTraverseNodeCallback(osgSim::Impostor* node):_node(node) {} 
    2828 
    2929    virtual void operator()(osg::Node*, osg::NodeVisitor* nv) 
     
    3131        _node->LOD::traverse(*nv); 
    3232    } 
    33      
     33 
    3434    osgSim::Impostor* _node; 
    3535}; 
     
    7575            Impostor* previous_owner = is->getParent(); 
    7676            ImpostorSpriteList& isl = previous_owner->_impostorSpriteListBuffer[contextID]; 
    77              
     77 
    7878            // find and erase reference to is. 
    7979            for(ImpostorSpriteList::iterator itr=isl.begin(); 
     
    8989        } 
    9090        is->setParent(this); 
    91          
     91 
    9292    } 
    9393} 
     
    120120        return; 
    121121    } 
    122      
     122 
    123123 
    124124    osg::Vec3 eyeLocal = nv.getEyePoint(); 
    125125    const BoundingSphere& bs = getBound(); 
    126      
     126 
    127127    unsigned int contextID = cv->getState() ? cv->getState()->getContextID() : 0; 
    128128 
     
    138138    } 
    139139    else 
    140     {     
     140    { 
    141141 
    142142        // within the impostor distance threshold therefore attempt 
    143143        // to use impostor instead. 
    144          
     144 
    145145        RefMatrix& matrix = *cv->getModelViewMatrix(); 
    146146 
    147147        // search for the best fit ImpostorSprite; 
    148148        ImpostorSprite* impostorSprite = findBestImpostorSprite(contextID,eyeLocal); 
    149          
     149 
    150150        if (impostorSprite) 
    151151        { 
     
    160160            } 
    161161        } 
    162          
     162 
    163163 
    164164// need to think about sprite reuse and support for multiple context's. 
     
    171171            // create the impostor sprite. 
    172172            impostorSprite = createImpostorSprite(cv); 
    173              
     173 
    174174            //if (impostorSprite) impostorSprite->_color.set(0.0f,0.0f,1.0f,1.0f); 
    175175 
    176176        } 
    177177        //else impostorSprite->_color.set(1.0f,1.0f,1.0f,1.0f); 
    178          
     178 
    179179        if (impostorSprite) 
    180180        { 
    181              
     181 
    182182            // update frame number to show that impostor is in action. 
    183183            impostorSprite->setLastFrameUsed(cv->getTraversalNumber()); 
     
    186186 
    187187            StateSet* stateset = impostorSprite->getStateSet(); 
    188              
     188 
    189189            if (stateset) cv->pushStateSet(stateset); 
    190              
     190 
    191191            cv->addDrawableAndDepth(impostorSprite, &matrix, distance(getCenter(),matrix)); 
    192192 
    193193            if (stateset) cv->popStateSet(); 
    194              
    195              
     194 
     195 
    196196        } 
    197197        else 
    198198        { 
    199            // no impostor has been selected or created so default to  
     199           // no impostor has been selected or created so default to 
    200200           // traversing the usual LOD selected child. 
    201201            LOD::traverse(nv); 
    202202        } 
    203                  
     203 
    204204    } 
    205205} 
     
    215215          cv->setUserData(impostorSpriteManager); 
    216216     } 
    217      
    218      
     217 
     218 
    219219    // default to true right now, will dertermine if perspective from the 
    220220    // projection matrix... 
     
    237237    float distance_local = lv_local.length(); 
    238238    lv_local /= distance_local; 
    239     
     239 
    240240    Vec3 sv_local = lv_local^camera_up_local; 
    241241    sv_local.normalize(); 
    242      
     242 
    243243    Vec3 up_local = sv_local^lv_local; 
    244      
    245      
     244 
     245 
    246246    float width = bs.radius(); 
    247247    if (isPerspectiveProjection) 
     
    250250        width *= (distance_local/sqrtf(distance_local*distance_local-bs.radius2())); 
    251251    } 
    252      
     252 
    253253    // scale up and side vectors to sprite width. 
    254254    up_local *= width; 
    255255    sv_local *= width; 
    256      
     256 
    257257    // create the corners of the sprite. 
    258258    Vec3 c00(center_local - sv_local - up_local); 
     
    273273    float s  = c11_win.x()-c00_win.x(); 
    274274    float t  = c11_win.y()-c00_win.y(); 
    275   
     275 
    276276    // may need to reverse sign of width or height if a matrix has 
    277277    // been applied which flips the orientation of this subgraph. 
     
    282282    // the texture dimensions to the nearest power of two. 
    283283    // bias near 0.0 will almost always round down. 
    284     // bias near 1.0 will almost always round up.  
     284    // bias near 1.0 will almost always round up. 
    285285    float bias = 0.7f; 
    286286 
     
    295295    const osg::Viewport& viewport = *(cv->getViewport()); 
    296296 
    297     // if dimension is bigger than window divide it down.     
     297    // if dimension is bigger than window divide it down. 
    298298    while (new_s>viewport.width()) new_s /= 2; 
    299299 
    300     // if dimension is bigger than window divide it down.     
     300    // if dimension is bigger than window divide it down. 
    301301    while (new_t>viewport.height()) new_t /= 2; 
    302302 
    303303    // create the impostor sprite. 
    304     ImpostorSprite* impostorSprite =  
     304    ImpostorSprite* impostorSprite = 
    305305        impostorSpriteManager->createOrReuseImpostorSprite(new_s,new_t,cv->getTraversalNumber()-cv->getNumberOfFrameToKeepImpostorSprites()); 
    306306 
     
    326326        stateset->setRenderBinDetails(10,"DepthSortedBin"); 
    327327    } 
    328      
     328 
    329329    osg::Texture2D* texture = impostorSprite->getTexture(); 
    330330 
     
    339339    Vec3* coords = impostorSprite->getCoords(); 
    340340    Vec2* texcoords = impostorSprite->getTexCoords(); 
    341      
     341 
    342342    coords[0] = c01; 
    343343    texcoords[0].set(0.0f,1.0f); 
     
    351351    coords[3] = c11; 
    352352    texcoords[3].set(1.0f,1.0f); 
    353      
     353 
    354354    impostorSprite->dirtyBound(); 
    355      
     355 
    356356    Vec3* controlcoords = impostorSprite->getControlCoords(); 
    357      
     357 
    358358    if (isPerspectiveProjection) 
    359359    { 
     
    363363        float one_minus_ratio = 1.0f-ratio; 
    364364        Vec3 eye_local_ratio = eye_local*ratio; 
    365          
     365 
    366366        controlcoords[0] = coords[0]*one_minus_ratio + eye_local_ratio; 
    367367        controlcoords[1] = coords[1]*one_minus_ratio + eye_local_ratio; 
     
    387387    Vec3 center_world = bs.center()*matrix; 
    388388 
    389      
     389 
    390390    osg::Camera* camera = impostorSprite->getCamera(); 
    391391    if (!camera) 
     
    396396 
    397397    camera->setCullCallback(new ImpostorTraverseNodeCallback(this)); 
    398      
     398 
    399399    osgUtil::RenderStage* previous_stage = cv->getRenderStage(); 
    400      
     400 
    401401    // set up the background color and clear mask. 
    402402    osg::Vec4 clear_color = previous_stage->getClearColor(); 
     
    404404    camera->setClearColor(clear_color); 
    405405    camera->setClearMask(previous_stage->getClearMask()); 
    406      
    407      
     406 
     407 
    408408// adjust camera left,right,up,down to fit (in world coords) 
    409409 
     
    412412    Vec3 top_local   ( center_local+up_local); 
    413413    Vec3 right_local ( center_local+sv_local); 
    414      
     414 
    415415    Vec3 near_world = near_local * matrix; 
    416416    Vec3 far_world = far_local * matrix; 
    417417    Vec3 top_world = top_local * matrix; 
    418418    Vec3 right_world = right_local * matrix; 
    419      
     419 
    420420    float znear = (near_world-eye_world).length(); 
    421421    float zfar  = (far_world-eye_world).length(); 
    422          
     422 
    423423    float top   = (top_world-center_world).length(); 
    424424    float right = (right_world-center_world).length(); 
     
    445445    Vec3 rotate_to   = cv-> getLookVectorLocal(); 
    446446 
    447     osg::Matrix rotate_matrix =  
    448         osg::Matrix::translate(-eye_local)*         
     447    osg::Matrix rotate_matrix = 
     448        osg::Matrix::translate(-eye_local)* 
    449449        osg::Matrix::rotate(rotate_from,rotate_to)* 
    450450        osg::Matrix::translate(eye_local)* 
     
    453453    camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); 
    454454    camera->setViewMatrix(rotate_matrix); 
    455      
     455 
    456456    camera->setViewport(0,0,new_s,new_t); 
    457457 
     
    467467    // do the cull traversal on the subgraph 
    468468    camera->accept(*cv); 
    469      
     469 
    470470    return impostorSprite; 
    471471