📄 maphorizon3.cpp
字号:
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/
/**
@file
MapHorizon3.cpp
@brief
Utility that pre-calculate horizon mapping for real-time
light mapping of terrain
*/
#include "MapUtil.h"
#include "MapHorizon3.h"
#include "OgrePagingLandScapeOptions.h"
#include <iostream>
namespace Ogre
{
MapHorizon3::MapHorizon3()
{
hMap = 0;
}
MapHorizon3::~MapHorizon3()
{
if (hMap)
delete[] hMap;
}
void MapHorizon3::calcHorizonMap()
{
uint W = MapUtil::getSingleton().getMapWidth ();
uint H = MapUtil::getSingleton().getMapHeight ();
uint size = W*H;
Real *LandZHorizonPos = new Real [size];
Real *LandZHorizonNeg = new Real [size];
memset (LandZHorizonPos, -1.0f, sizeof(Real) * size);
Vector3 scale = PagingLandScapeOptions::getSingleton().scale;
uchar *mHeightMapData = MapUtil::getSingleton().getHeightMapData ();
uint curr_row = 0;
for(uint nX = 0; nX < W; nX++)
{
for(uint nZ = 0; nZ < H; nZ++)
{
uint nVert = curr_row + nZ;
for(uint nZset = 0; nZset < H; nZset++)
{
if(nZset != nZ)
{
uint nVertSet = curr_row + nZset;
Real fDistY = (mHeightMapData[nVert] - mHeightMapData[nVertSet]) * scale.y;
Real fDistZ = (nZ - nZset) * scale.z;
assert(fDistZ != 0);
if(fDistZ > 0)
{
Real fCosAngle = fDistY / Math::Sqrt(fDistY * fDistY + fDistZ * fDistZ);
if(LandZHorizonPos[nVertSet] < fCosAngle)
LandZHorizonPos[nVertSet] = fCosAngle;
}
else
{
Real fCosAngle = fDistY / Math::Sqrt(fDistY * fDistY + fDistZ * fDistZ);
if (LandZHorizonNeg[nVertSet] < fCosAngle)
LandZHorizonNeg[nVertSet] = fCosAngle;
}
}
}
}
curr_row += W;
}
}
}//ogre namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -