public void Update(double x, double y, double z, string texture, double ambient, double intensity)
{
if (!bValid) return;
try
{
if (this.texture != texture)
{
this.texture = texture;
Type ImageListType = typeof(ImageList);
Dictionary<string, BitmapSource> _savedImages;
BitmapSource img;
_savedImages = (Dictionary<string, BitmapSource>)ImageListType.GetField("_savedImages", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
if (_savedImages.TryGetValue(texture, out img))
{
bTexture = FastPixel.GetBitmap(img);
if (width != bTexture.Width || height != bTexture.Height) bTexture = null;
if (bSaveTexture && null != bTexture)
{
if (null != fpTexture) fpTexture.Unlock(false);
fpTexture = new FastPixel(bTexture);
}
}
else
{
bTexture = null;
}
}
double scale;
byte rgb;
Color c;
Vec3D source = new Vec3D(x, -y, z);
source.Normalize();
if (!bSaveTexture && null != bTexture)
{
fpTexture = new FastPixel(bTexture);
}
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
scale = Vec3D.Dot(source, vectors[i, j]);
if (null != bTexture)
{
scale = ambient + (intensity - ambient) * System.Math.Max(0, scale);
c = fpTexture.GetPixel(i, j);
fpNormal.SetPixel(i, j, Color.FromArgb(c.A, LDImage.range(c.R * scale), LDImage.range(c.G * scale), LDImage.range(c.B * scale)));
}
else
{
scale = 0.5 * (1.0 + scale);
rgb = LDImage.range(255 * scale);
fpNormal.SetPixel(i, j, Color.FromArgb(255, rgb, rgb, rgb));
}
}
}
fpNormal.Update();
if (!bSaveTexture && null != bTexture) fpTexture.Unlock(false);
FastThread.Invoke(Update_Delegate);
}
catch (Exception ex)
{
Utilities.OnError(Utilities.GetCurrentMethod(), ex);
}
}