查看: 2030|回复: 7

付费求一个追踪的程序~

[复制链接]

该用户从未签到

发表于 2011-5-31 11:00:16 | 显示全部楼层 |阅读模式
付费求一个追踪的程序~
付费求一个追踪的程序~
付费求一个追踪的程序~

该用户从未签到

 楼主| 发表于 2011-5-31 15:14:14 | 显示全部楼层
我现在把物体运动这块已经编好了,就是不会追踪。。。
毕业设计马上就要交东西了。。。求哪位大哥帮忙编下。。。。
可以付费。。。。

该用户从未签到

 楼主| 发表于 2011-5-31 15:15:15 | 显示全部楼层
#include <osg/AnimationPath>
#include <osg/GraphicsContext>
#include <osg/MatrixTransform>
#include <osgDB/ReadFile>
#include <osgShadow/ShadowedScene>
#include <osgShadow/ShadowMap>
#include <osgViewer/Viewer>
osg::AnimationPath* createAnimationPath( float radius,float time)
{
osg::ref_ptr<osg::AnimationPath> path = new osg::AnimationPath;
path->setLoopMode( osg::AnimationPath::NO_LOOPING);
unsigned int numSamples = 320;
float delta_yaw = 3.0f * osg:I / ((float)numSamples - 1.0f);
float delta_time = time / (float)numSamples;
for ( unsigned int i=0; i<numSamples; i++ )
{
if (i<10)
{
osg::Vec3 pos( 0.0f,0.0f, i*10.0f-100.0f);
path->insert( delta_time * (float)i,osg::AnimationPath::ControlPoint(pos));
}
else
{
float yaw = delta_yaw * (float)(i-10);
osg::Vec3 pos( cosf(yaw)*radius-300.0f,0.0f ,sinf(yaw)*radius );
osg:uat rot( -yaw, osg::Y_AXIS );
path->insert( delta_time * (float)i,
osg::AnimationPath::ControlPoint(pos, rot));
}
}
return path.release();
}

unsigned int rcvShadowMask = 0x1;
unsigned int castShadowMask = 0x2;
int main(int argc, char** argv)
{
osg::ref_ptr<osg::GraphicsContext::Traits> traits =new osg::GraphicsContext::Traits;
traits->x = 50;
traits->y = 50;
traits->width = 800;
traits->height = 600;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->samples = 4;
osg::ref_ptr<osg::GraphicsContext> gc =osg::GraphicsContext::createGraphicsContext( traits.get() );
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext( gc );
camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height) );
camera->setClearMask( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
camera->setClearColor( osg::Vec4f(0.2f, 0.2f, 0.4f, 1.0f) );
camera->setProjectionMatrixAsPerspective(30.0f,(double)traits->width/(double)traits->height,1.0,1000.0 );
osg::ref_ptr<osg::MatrixTransform> groundNode =new osg::MatrixTransform;
groundNode->addChild( osgDB::readNodeFile("lz.osg") );
groundNode->setMatrix( osg::Matrix::translate(0.0f, 0.0f,-200.0f));
groundNode->setNodeMask( rcvShadowMask );

osg::ref_ptr<osg::MatrixTransform> cessnaNode =new osg::MatrixTransform;
cessnaNode->addChild( osgDB::readNodeFile("SZ5.flt.0,0,90.rot"));
cessnaNode->setNodeMask( castShadowMask );
osg::ref_ptr<osg::AnimationPathCallback> apcb =new osg::AnimationPathCallback;
apcb->setAnimationPath( createAnimationPath(300.0f,100.0f) );
cessnaNode->setUpdateCallback( apcb.get() );
osg::ref_ptr<osg::MatrixTransform> truckNode =new osg::MatrixTransform;
osg::ref_ptr<osg:ightSource> source = new osg::LightSource;
source->getLight()->setPosition( osg::Vec4(4.0, 4.0, 10.0,0.0) );
source->getLight()->setAmbient( osg::Vec4(0.2, 0.2, 0.2, 1.0));
source->getLight()->setDiffuse( osg::Vec4(0.8, 0.8, 0.8, 1.0));
osg::ref_ptr<osgShadow::ShadowMap> sm = new osgShadow::ShadowMap;
sm->setLight( source.get() );
sm->setTextureSize( osg::Vec2s(1024, 1024) );
sm->setTextureUnit( 1 );
osg::ref_ptr<osgShadow::ShadowedScene> root =new osgShadow::ShadowedScene;
root->setShadowTechnique( sm.get() );
root->setReceivesShadowTraversalMask( rcvShadowMask );
root->setCastsShadowTraversalMask( castShadowMask );
root->addChild( groundNode.get() );
root->addChild( cessnaNode.get() );
root->addChild( source.get() );
osgViewer::Viewer viewer;
viewer.setCamera( camera.get() );
viewer.setSceneData( root.get() );
return viewer.run();
}

该用户从未签到

发表于 2011-6-1 09:48:25 | 显示全部楼层
追踪什么,追踪飞行物体?

该用户从未签到

发表于 2011-6-2 13:47:12 | 显示全部楼层
NodeTrackManipulator就可以了

该用户从未签到

发表于 2011-6-2 13:48:11 | 显示全部楼层
不过这个需要在跟踪和漫游之间切换漫游器,还有一种方式就是直接用osgEarth的漫游器,setTetherNode就行,更简单

该用户从未签到

发表于 2011-6-2 13:49:16 | 显示全部楼层
不是必须贴大片代码的情况尽量不要贴,没人会看这么长的代码,个人建议

该用户从未签到

发表于 2013-3-23 15:09:45 来自手机 | 显示全部楼层
给我你的qq号,我告你,我在做模拟飞行的游戏
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表