IRRLICHT的实现:
1.波浪是如何实现的?
先对每个点计算高度,
void addWave(vector3df& dest, const vector3df source, f32 time)
{
dest.Y = source.Y +
(sinf(((source.X/WaveLength) + time)) * WaveHeight) +
(cosf(((source.Z/WaveLength) + time)) * WaveHeight);
}
然后再计算法线,
recalculateNormals(Mesh);
2.ATMOSphere
太阳嘛,就是个跟随时间移动的BILLBOARD,边缘最好加上雾化效果。
3.地形编辑器代码
if( Terrain && !RightMouseDown && Terrain->getTriangleSelector() )
{
LastMousePosition.set( Device->getCursorControl()->getPosition().X, Device-> getCursorControl()->getPosition().Y );
//计算从鼠标位置到观察点的射线
core::line3df line = CollisionMgr->getRayFromScreenCoordinates(
core::position2d<s32>( LastMousePosition.X, LastMousePosition.Y ) );
//计算以交点为中心,一定半径范围内的点
core::vector3df spherePosition;
if( CollisionMgr->getClosestVertex( line, Terrain->getTriangleSelector(),
spherePosition, CurrentVertexIndex ) )
{
LeftMouseDown = true;
// Get all vertices with the circle
SelectedTerrainVertices.clear();
core::vector3df intersection;
scene::SCollisionTriangle tri;
if( CollisionMgr->getCollisionPoint( line, Terrain->getTriangleSelector(), intersection, tri ) )
{
u32 count = 0;
SelectedTerrainVertices.reallocate( Terrain->getTriangleSelector()->getTriangleCount() );
Terrain->getTriangleSelector()->getVerticesInRadius( SelectedTerrainVertices.pointer(), Terrain->getTriangleSelector()->getTriangleCount(), count, intersection, RedCircleRadius );
SelectedTerrainVertices.set_used( count );
}
return true;
}
}