public Brush PerceivedColor(LightSource light, _Point CamPosition) { _Point LightVector = VectMath.Subtract(this.Position, light.Position); _Point PercVector = this.Position; _Point Rvector = VectMath.RotateByAngle(VectMath.Negate(LightVector), Normal, 180); double whitefactor = Math.Abs(.5 * Math.Sin(VectMath.AngleBetween(Normal, LightVector)) + .5); double colorfactor = Math.Abs(Math.Cos(VectMath.AngleBetween(Normal, LightVector))); double Total = Math.Pow(Math.Sin(VectMath.AngleBetween(PercVector, Rvector)), 2); SolidBrush brush = new SolidBrush(Color.FromArgb(Convert.ToInt32(255 * Total * colorfactor * whitefactor), Convert.ToInt32(255 * Total * whitefactor), Convert.ToInt32(255 * Total * whitefactor))); return(brush); }
public static _Point RotateByAngle(_Point pnt, _Point Axis, double Angle) { if (VectMath.IsParallel(pnt, Axis) == true) { return(pnt); } Angle = (Angle * Math.PI) / 180; _Point Avector = VectMath.Subtract(pnt, VectMath.Project(pnt, Axis)); double MagAvector = VectMath.Magnitude(Avector); _Point V1 = VectMath.Unit(VectMath.Cross(Axis, Avector)); _Point V2 = (VectMath.Negate(Avector)); _Point TransVector = VectMath.Add(VectMath.Scale(V1, MagAvector * Math.Sin(Angle)), VectMath.Scale(V2, (-1 * Math.Cos(Angle) + 1))); return(VectMath.Add(TransVector, pnt)); }