OSG学习笔记2:地形构建和模型加载

一、准备

数据文件:地形数据map.data,模型数据car.ms3d.

float *terrainHeights;
float intervalX = 20;
float intervalY = 20;
float terrainGridLength;	//y方向
float terrainGridWidth;		//x方向
double COLOR[8][3] = {
	{ 0, 0, 0 }, { 0, 38, 255 }, { 38, 127, 0 }, { 127, 160, 0 },
	{ 255, 255, 0 }, { 255, 128, 0 }, { 255, 0, 0 }, { 255, 255, 255 }
};
void GetColor(double height, double &r, double &g, double &b);
bool LoadHeightMap(QString filePath);	//加载地图
bool LoadCarModel(QString filePath);	//加载模型

二、效果

m_viewer = new osgViewer::Viewer();
m_viewer->setUpViewerAsEmbeddedInWindow(0, 0, 800, 600);
//osg::ref_ptr<osg::Group> root = new osg::Group;
m_GroupRoot = new osg::Group;
osg::ref_ptr<osg::Group> lightRoot = new osg::Group();
osg::ref_ptr<osg::StateSet> lightState = new osg::StateSet();
lightState = lightRoot->getOrCreateStateSet();
lightState->setMode(GL_LIGHTING, osg::StateAttribute::ON);	
lightState->setMode(GL_LIGHT0, osg::StateAttribute::ON);	
osg::ref_ptr<osg::Multisample> pms = new osg::Multisample;
lightState->setAttributeAndModes(pms, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
LoadMapModel("G:/map.pnt");
LoadCarModel("G:/car.ms3d");
lightRoot->addChild(m_CarMT);
lightRoot->addChild(m_GeodeMap);
lightRoot->addChild(createLight());
m_viewer->setSceneData(lightRoot);
m_viewer->setCameraManipulator(new osgGA::TrackballManipulator);		
osg::ref_ptr<osg::Camera> camera = m_viewer->getCamera();
camera->setEventCallback(new MoveCarEventCallback());
m_viewer->realize();


三、待总结

1.小错误不断,最可恨的是,设置移动的时候,用了三角函数,然后我忘记了要改成弧度值,当车子转角为a°的时候,我依旧使用cos(a)或者sin(a),结果各种神之位移。还是记录下来吧delt = cos(a/180*PI);

2.按键响应,事件使用Qt的QKeyEvent,但是需要传一个当前窗口的keypress();键盘的事件很容易啊,但是鼠标的没有搞明白。

3.碰撞检测,还没有做,慢慢学习吧。

4.骨骼动画,还没有做,慢慢学习吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值