我正在編寫一個引擎,並使用Light 0作爲場景的「太陽」。太陽是定向光。OpenGL定向照明+定位
我設置了場景的正交視點,然後將光線設置在屏幕的「東側」(和字符)(x/y是平面地形的座標,正z朝向相機並在地形上指示「高度」 - 場景也在x軸上的等軸視圖上旋轉)。
光線似乎正在照亮0,0,0的「東」,但隨着角色的移動,它不會移位(CenterCamera對提供的值的負值做一個glTranslate3f,以便它們可以映射指定世界座標)。意思是,我進一步向西移動,它總是黑暗,沒有光。
Graphics.BeginRenderingLayer();
{
Video.MapRenderingMode();
Graphics.BeginLightingLayer(Graphics.AmbientR, Graphics.AmbientG, Graphics.AmbientB, Graphics.DiffuseR, Graphics.DiffuseG, Graphics.DiffuseB, pCenter.X, pCenter.Y, pCenter.Z);
{
Graphics.BeginRenderingLayer();
{
Graphics.CenterCamera(pCenter.X, pCenter.Y, pCenter.Z);
RenderMap(pWorld, pCenter, pCoordinate);
}
Graphics.EndRenderingLayer();
Graphics.BeginRenderingLayer();
{
Graphics.DrawMan(pCenter);
}
Graphics.EndRenderingLayer();
}
Graphics.EndLightingLayer();
}
Graphics.EndRenderingLayer();
Graphics.BeginRenderingLayer = PushMatrix,EndRenderingLayer = PopMatrix Video.MapRenderingMode =正交投影與場景旋轉/放大CenterCamera確實一個轉換爲X/Y/Z,使得該字符被現在在中心的相反X/Y/Z在屏幕中間。
有什麼想法?也許我已經在這裏混淆了一些我的代碼?
的照明代碼如下:
public static void BeginLightingLayer(float pAmbientRed, float pAmbientGreen, float pAmbientBlue, float pDiffuseRed, float pDiffuseGreen, float pDiffuseBlue, float pX, float pY, float pZ)
{
Gl.glEnable(Gl.GL_LIGHTING);
Gl.glEnable(Gl.GL_NORMALIZE);
Gl.glEnable(Gl.GL_RESCALE_NORMAL);
Gl.glEnable(Gl.GL_LIGHT0);
Gl.glShadeModel(Gl.GL_SMOOTH);
float[] AmbientLight = new float[4] { pAmbientRed, pAmbientGreen, pAmbientBlue, 1.0f };
float[] DiffuseLight = new float[4] { pDiffuseRed, pDiffuseGreen, pDiffuseBlue, 1.0f };
float[] PositionLight = new float[4] { pX + 10.0f, pY, 0, 0.0f };
//Light position of Direction is 5 to the east of the player.
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_AMBIENT, AmbientLight);
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_DIFFUSE, DiffuseLight);
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, PositionLight);
Gl.glEnable(Gl.GL_COLOR_MATERIAL);
Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, Gl.GL_AMBIENT_AND_DIFFUSE);
}
它可能有助於發佈您的代碼,顯示您設置燈光的位置。 – kappamaki 2012-02-29 00:17:37
編輯原件以包含照明代碼。 – Locke 2012-03-01 00:21:00
您是否計算併發送每個頂點的法線? – 2012-03-27 20:45:19