|
楼主 |
发表于 2010-7-7 10:18:53
|
显示全部楼层
//主要处理代码如下
osg::Node* Scenenode =osgDB::readNodeFile("ceep.ive");
osg::Node* skyNode = osgDB::readNodeFile("sky.ive");
osg::Node* carNode =osgDB::readNodeFile("car.IVE");
osg:ositionAttitudeTransform* pat = new osg::PositionAttitudeTransform;//定义一个节点
pat->setPosition(osg::Vec3(0,-10.0,3.5));
carNode->asGroup()->addChild(pat);
transformAccumulator* tankWorldCoords = new transformAccumulator();
tankWorldCoords->attachToGroup(pat);//绑定到该节点
followNodeMatrixManipulator* followcar = new followNodeMatrixManipulator(tankWorldCoords);//跟随相机
//////////////////////////////////////////////////////////////////////////
osg::Texture2D* mirrorTexture = new osg::Texture2D;
osg::Group* parent =new osg::Group;
osg::CameraNode* camera = new osg::CameraNode;
const osg::BoundingSphere& bs =Scenenode->getBound();
float znear = 1.0f*bs.radius();
float zfar = 3.0f*bs.radius();
// 2:1 aspect ratio as per flag geomtry below.
float proj_top = 0.25f*znear;
float proj_right = 0.5f*znear;
znear *= 0.9f;
zfar *= 1.1f;
camera->addChild(Scenenode);//加入场景
// set up projection.
camera->setProjectionMatrixAsFrustum(-proj_right,proj_right,-proj_top,proj_top,znear,zfar);
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
camera->setReferenceFrame(osg::Transform::RELATIVE_RF);//???我觉得这里的设置应该是使其实时变化的。
camera->setViewMatrixAsLookAt(osg::Vec3(-1.174,0.644,1.302),osg::Vec3(-1.151,-
2.883,0.955),osg::Vec3(0.0f,0.0f,1.0f));
// set viewporttex_heighttex_widthtex_height
camera->setViewMatrix(osg::Matrix::identity());
//set the camera to render before the main camera.
camera->setRenderOrder(osg::CameraNode::PRE_RENDER);
//FBO
osg::CameraNode::RenderTargetImplementation renderImplementation = osg::CameraNode::FRAME_BUFFER_OBJECT;
camera->setRenderTargetImplementation(renderImplementation);
camera->attach(osg::CameraNode::COLOR_BUFFER, mirrorTexture );
////////////////////////////////////////////左视镜/////////////////////////////////
osg::Node* leftGeode =carNode->asGroup()->getChild(1);//左后视镜
osg::TexGen* texgen =new osg::TexGen;
texgen->setMode(osg::TexGen::SPHERE_MAP);
mirrorTexture->setDataVariance(osg::Object:YNAMIC);
mirrorTexture->setInternalFormat(GL_RGBA);
mirrorTexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D:INEAR);
mirrorTexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
osg::StateSet* stateset = new osg::StateSet;
stateset->setTextureAttributeAndModes(1, mirrorTexture ,osg::StateAttribute::ON);
stateset->setTextureAttributeAndModes (1,texgen,osg::StateAttribute::ON);
leftGeode->setStateSet(stateset);
//add subgraph to render
parent->addChild(camera);
////////////////////////////////////////////////////////////////////////////////////
root->addChild(parent);
root->addChild(Scenenode);
root->addChild(carNode);
viewer.setSceneData(root);
4# array |
|