private void PutPixel(DirectBitmap bitmap, int x, int y) { if (!(x >= 0 && x < bitmap.Width && y >= 0 && y < bitmap.Height)) { return; } int R, G, B; double cos; Vector normal; if (NormalOn && NormalMap != null) { normal = NormalMap[x % NormalMap.GetLength(0), y % NormalMap.GetLength(1)]; } else { normal = new Vector(0, 0, 1); } if (HeightMapOn && HeightMap != null) { normal.Add(HeightMap[x % HeightMap.GetLength(0), y % HeightMap.GetLength(1)]); normal.Normalise(); } cos = LightSettings.GetVectorToPoint(x, y).GetAngle(normal); if (TextureOn && Texture != null) { R = (int)((double)LightSettings.LightColor.R * Texture[x % Texture.GetLength(0), y % Texture.GetLength(1)].R / 255 * cos); G = (int)((double)LightSettings.LightColor.G * Texture[x % Texture.GetLength(0), y % Texture.GetLength(1)].G / 255 * cos); B = (int)((double)LightSettings.LightColor.B * Texture[x % Texture.GetLength(0), y % Texture.GetLength(1)].B / 255 * cos); } else { R = (int)(polygonColor.R * (double)LightSettings.LightColor.R / 255 * cos); G = (int)(polygonColor.G * (double)LightSettings.LightColor.G / 255 * cos); B = (int)(polygonColor.B * (double)LightSettings.LightColor.B / 255 * cos); } bitmap.SetPixel(x, y, Color.FromArgb(Cut(R), Cut(G), Cut(B))); }
private void Timer_Tick(object sender, EventArgs e) { LightSettings.MoveLightSource((double)timer.Interval / 1000); DrawingBox.Invalidate(); }