![]() |
|
|
Tutorial 08 - The Big Calm大量的计算 This tutorial demonstrates usage of special effects and complex lighting simulation. 这个指南示范了特别效果的使用和综合光照模拟。 Shades of the Sky天空的渐变 To render the sky we use a sprite without texture: 我们使用一个不带有材质的精灵来描绘天空 hgeSprite *sky; sky=new hgeSprite(0, 0, 0, SCREEN_WIDTH, SKY_HEIGHT); It's top and bottom vertices are tinted into different colors, resulting in smooth transition: 他的上下顶点是不断的色彩变化的,平滑的过渡作为结果。 hgeColor colSkyTop; hgeColor colSkyBtm; sky->SetColor(colSkyTop.GetHWColor(), 0); sky->SetColor(colSkyTop.GetHWColor(), 1); sky->SetColor(colSkyBtm.GetHWColor(), 2); sky->SetColor(colSkyBtm.GetHWColor(), 3); sky->Render(0, 0); The sky colors depend on time of day and are calculated by interpolation between several constant tints: 天空颜色依赖于一天的时间和在几个固定的颜色中通过插值计算而得出的结果。 hgeColor col1, col2; col1.SetHWColor(skyTopColors[seq[seq_id]]); col2.SetHWColor(skyTopColors[seq[seq_id+1]]); colSkyTop=col2*seq_residue + col1*(1.0f-seq_residue); col1.SetHWColor(skyBtmColors[seq[seq_id]]); col2.SetHWColor(skyBtmColors[seq[seq_id+1]]); colSkyBtm=col2*seq_residue + col1*(1.0f-seq_residue); The Sea and Waves海和波浪 The same coloring technique is used for the sea. But this time we use hgeDistortionMesh class instead of hgeSprite to allow waves simulation: 同样的色彩方法被使用在海上。但是这次我们使用hgeDistortionMesh类替代hgeSprite去允许波浪模拟。 hgeDistortionMesh *sea; sea=new hgeDistortionMesh(SEA_SUBDIVISION, SEA_SUBDIVISION); sea->SetTextureRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-SKY_HEIGHT); To create waves we set a displacement and tint for every distortion mesh node (we skip first and last line for now as we don't want them to move): 创建波浪我们设置一个位移和色彩为每一个扭曲网点(我们跳过开始和最后行,我们不想他们去移动) for(i=1; i<SEA_SUBDIVISION-1; i++) { // these are constants for each vertices line a=float(i)/(SEA_SUBDIVISION-1); col1=colSeaTop*(1-a)+colSeaBtm*a; dwCol1=col1.GetHWColor(); fTime=2.0f*hge->Timer_GetTime(); a*=20; for(j=0; j<SEA_SUBDIVISION; j++) { sea->SetColor(j, i, dwCol1); dy=a*sinf(seaP[i]+ // precalculated phase shift (float(j)/(SEA_SUBDIVISION-1)-0.5f)*M_PI*16.0f-fTime); sea->SetDisplacement(j, i, 0.0f, dy, HGEDISP_NODE); } } Now we set tints for previously skipped first and last lines of distortion mesh nodes: 现在我们为先前跳过的的扭曲网点前后行设置颜色属性 dwCol1=colSeaTop.GetHWColor(); dwCol2=colSeaBtm.GetHWColor(); for(j=0; j<SEA_SUBDIVISION; j++) { sea->SetColor(j, 0, dwCol1); sea->SetColor(j, SEA_SUBDIVISION-1, dwCol2); } The sea is ready now and we render it with just one call: 海已经准备好了,我们仅使用一个调用就可以描绘他 sea->Render(0, SKY_HEIGHT); In actual source code a light path from moon and sun is also simulated. To do this we just add a bit of white tint into distortion mesh nodes that are currently under the sun/moon. 在目前的源代码中从月亮到太阳的一个光通道也是模拟出来的。要做到这些我们只需要加一点白色到当前太阳或者月亮下面的扭曲网点 Celestial Bodies天体 Stars, moon and sun are just scaled and tinted sprites: 开始,月亮和太阳只是有斑点和色彩的精灵 上一页12 下一页
|