Exemple #1
0
        public static Color GetColor(int x, int y, Triangle t)
        {
            SettingsFactory settingsFactory = new SettingsFactory();
            double          kd          = settingsFactory.GetCoefficients().Kd;
            double          ks          = settingsFactory.GetCoefficients().Ks;
            int             m           = settingsFactory.GetCoefficients().M;
            MyVector        L           = settingsFactory.GetLight(x, y, GetAnimationPoint(Triller.iteration, 20, 1000, new Point(400, 250))).L;
            Color           objectColor = settingsFactory.GetObjectColor(x, y, t).ObjectColor;
            Color           lightColor  = settingsFactory.GetLightColor();
            MyVector        N           = settingsFactory.GetVectorN(x, y, t).N;
            MyVector        V           = new MyVector(0, 0, 1);
            double          NL          = N.X * L.X + N.Y * L.Y + N.Z * L.Z;
            MyVector        R           = new MyVector(2 * NL * N.X - L.X, 2 * NL * N.Y - L.Y, 2 * NL * N.Z - L.Z);

            var IR = kd * ((double)lightColor.R / 255) * ((double)objectColor.R / 255) * MyVector.MyCos(N, L) +
                     ks * ((double)lightColor.R / 255) * ((double)objectColor.R / 255) * Math.Abs(Math.Pow(MyVector.MyCos(V, R), m));
            var IG = kd * ((double)lightColor.G / 255) * ((double)objectColor.G / 255) * MyVector.MyCos(N, L) +
                     ks * ((double)lightColor.G / 255) * ((double)objectColor.G / 255) * Math.Abs(Math.Pow(MyVector.MyCos(V, R), m));
            var IB = kd * ((double)lightColor.B / 255) * ((double)objectColor.B / 255) * MyVector.MyCos(N, L) +
                     ks * ((double)lightColor.B / 255) * ((double)objectColor.B / 255) * Math.Abs(Math.Pow(MyVector.MyCos(V, R), m));

            return(Color.FromArgb(255, (int)(IR * 255) > 255 ? 255 : (int)(IR * 255), (int)(IG * 255) > 255 ? 255 : (int)(IG * 255),
                                  (int)(IB * 255) > 255 ? 255 : (int)(IB * 255)));
        }
Exemple #2
0
 public static double MyCos(MyVector v1, MyVector v2)
 {
     return(v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z);
 }