Show
Ignore:
Timestamp:
10/06/05 22:02:18 (9 years ago)
Author:
robert
Message:

Improved the UpdateCameraAndTexGenCallback? so it properly handles rotation and
translations within the reflector nodepath.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgprerendercubemap/osgprerendercubemap.cpp

    r4553 r4579  
    1818#include <osg/Material> 
    1919#include <osg/RefNodePath> 
     20#include <osg/PositionAttitudeTransform> 
    2021 
    2122#include <osgUtil/TransformCallback> 
     
    8990osg::RefNodePath createReflector() 
    9091{ 
    91   ref_ptr<Group> scene = new Group; 
     92  ref_ptr<osg::PositionAttitudeTransform> pat = new osg::PositionAttitudeTransform; 
     93  pat->setPosition(osg::Vec3(0.0f,0.0f,0.0f)); 
     94  pat->setAttitude(osg::Quat(osg::inDegrees(0.0f),osg::Vec3(0.0f,0.0f,1.0f))); 
     95   
    9296  ref_ptr<Geode> geode_1 = new Geode; 
    93   scene->addChild(geode_1.get()); 
     97  pat->addChild(geode_1.get()); 
    9498 
    9599  const float radius = 0.8f; 
     
    101105   
    102106  osg::RefNodePath refNodeList; 
    103   refNodeList.push_back(scene.get()); 
     107  refNodeList.push_back(pat.get()); 
    104108  refNodeList.push_back(geode_1.get()); 
    105109   
     
    123127            // first update subgraph to make sure objects are all moved into postion 
    124128            traverse(node,nv); 
    125              
     129 
    126130            // compute the position of the center of the reflector subgraph 
    127             osg::Matrixd matrix = osg::computeLocalToWorld(_reflectorNodePath); 
     131            osg::Matrixd worldToLocal = osg::computeWorldToLocal(_reflectorNodePath); 
    128132            osg::BoundingSphere bs = _reflectorNodePath.back()->getBound(); 
    129             osg::Vec3 position = bs.center() * matrix; 
     133            osg::Vec3 position = bs.center(); 
    130134 
    131135            typedef std::pair<osg::Vec3, osg::Vec3> ImageData; 
     
    144148                ++i) 
    145149            { 
     150                osg::Matrix localOffset; 
     151                localOffset.makeLookAt(position,position+id[i].first,id[i].second); 
     152                 
     153                osg::Matrix viewMatrix = worldToLocal*localOffset; 
     154             
    146155                _cameraNodes[i]->setReferenceFrame(osg::CameraNode::ABSOLUTE_RF); 
    147156                _cameraNodes[i]->setProjectionMatrixAsFrustum(-1.0,1.0,-1.0,1.0,1.0,10000.0); 
    148                 _cameraNodes[i]->setViewMatrixAsLookAt(position,position+id[i].first,id[i].second); 
     157                _cameraNodes[i]->setViewMatrix(viewMatrix); 
    149158            } 
    150              
    151159        } 
    152160         
     
    204212    for(unsigned int i=0; i<6; ++i) 
    205213    { 
    206  
    207214        // create the camera 
    208215        osg::CameraNode* camera = new osg::CameraNode;