您的位置:首页 > 其它

天龙的地形实现技术 1

2009-02-17 00:57 267 查看
天龙的场景主文件为.Scene文件,其中定义了一个场景的灯光,天空,地面,以及所有的实体

偷了两张图片来说明文件格式:





scene文件的实际格式





terrain是由和Scene文件同名扩展名为.Terrain的文件定义的





地形的信息保存在heightmao中,实际上是一个193X193的raw格式的文件;前八位标识版本号,后八位中,前四位为宽,后四位为高;

FILE *pFile= fopen("F://OgreSDK//media//Scene//shaolin.Heightmap", "rb" );
if( pFile == NULL )
{
MessageBox(NULL, "加载天龙八部高度图文件%s失败, 文件不存在.","",MB_OK );
return ;
}

size_t uWidth, uHeight;
fseek( pFile, 8, SEEK_CUR );

fread( &uWidth, 1, sizeof(size_t), pFile );
fread( &uHeight, 1, sizeof(size_t), pFile );

size_t uSize=uWidth;
size_t i, uCount = uSize * uSize;
std::vectorheightMap(uCount);

for( i = 0; i < uCount; ++i )
{
float fValue = 0;
fread( &fValue, 1, sizeof(float), pFile );
heightMap[i]=fValue;
}

读取场景的实体时要注意一点,场景文件中记录的四元数是w在前的和平常的习惯不太一样。。。

Ogre::String str = value;
size_t pos = str.find_first_of(' ',0);
size_t pos2 = str.find_first_of(' ',pos+1);
size_t pos3 = str.find_first_of(' ',pos2+1);
quat.w = Ogre::StringConverter::parseReal(str.substr(0,pos));
quat.x = Ogre::StringConverter::parseReal(str.substr(pos+1,pos2));
quat.y = Ogre::StringConverter::parseReal(str.substr(pos2+1,pos3));
quat.z = Ogre::StringConverter::parseReal(str.substr(pos3+1,str.length()));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: