Show
Ignore:
Timestamp:
03/01/10 14:00:04 (4 years ago)
Author:
robert
Message:

Added a ShadowTechnique::computeOrthogonalVector(const osg::Vec3& direction) const method for helping compute an appropriate
up vector to setViewMatrixAsLookAt(..) codes in osgShadow. This will addresses previous issues that occured when look vectors
co-incided with the hard coded up vectors.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgShadow/ShadowMap.cpp

    r10699 r11137  
    409409            osg::Vec3 position(lightpos.x(), lightpos.y(), lightpos.z()); 
    410410            _camera->setProjectionMatrixAsPerspective(fov, 1.0, 0.1, 1000.0); 
    411             _camera->setViewMatrixAsLookAt(position,position+lightDir,osg::Vec3(0.0f,1.0f,0.0f)); 
     411            _camera->setViewMatrixAsLookAt(position,position+lightDir,computeOrthogonalVector(lightDir)); 
    412412        } 
    413413        else 
     
    436436 
    437437                _camera->setProjectionMatrixAsFrustum(-right,right,-top,top,znear,zfar); 
    438                 _camera->setViewMatrixAsLookAt(position,bb.center(),osg::Vec3(0.0f,1.0f,0.0f)); 
     438                _camera->setViewMatrixAsLookAt(position,bb.center(),computeOrthogonalVector(bb.center()-position)); 
    439439            } 
    440440            else    // directional light 
     
    458458 
    459459                _camera->setProjectionMatrixAsOrtho(-right, right, -top, top, znear, zfar); 
    460                 _camera->setViewMatrixAsLookAt(position,bb.center(),osg::Vec3(0.0f,1.0f,0.0f)); 
     460                _camera->setViewMatrixAsLookAt(position,bb.center(),computeOrthogonalVector(lightDir)); 
    461461            } 
    462462