Ejemplo n.º 1
0
        public bool[] occultation(V3 R, List<Objet3D> objList, List<Lampe> lampList)
        {
            V3 Rd;
            float t;
            bool[] occs = new bool[lampList.Count];
            // créer un rayon de R vers chaque Lampe
            for (int i = 0; i < lampList.Count; i++ )
            {
                Lumiere L = (Lumiere)lampList.ElementAt(i);
                if (L.getType() == 0)
                { // directional : direction L.getDirection();
                    Rd = L.getDirection();
                }
                else
                {
                    Rd = L.getPosition() - R;
                }
                Rd.Normalize();

                occs[i] = false;
                foreach (Objet3D obj in objList)
                {
                    t = obj.getIntersect(Rd, R);
                    //if (t != -1f && t != 0f) // si il y a une intersection
                    if(t > 0.01f)
                    {
                        occs[i] = true; // on occulte la lampe
                    }
                }

            }

            return occs;
        }
Ejemplo n.º 2
0
        /*public override void Draw(Couleur C_ambiant, Lumiere L, V3 camera)
        {
            //float cosln;
            //Couleur final_ambiant, final_diff, final_spec;
            //Couleur C_lampe = L.getClampe();

            //L1 = (new V3(0.0f, 1.0f, 0.0f)) ^ (L1 ^ (new V3(0.0f, 1.0f, 0.0f)));
            //L2 = (new V3(0.0f, 1.0f, 0.0f)) ^ (L2 ^ (new V3(0.0f, 1.0f, 0.0f)));
            // 4 sommets : origin, origin + L1, origin + L2, origin + L1 + L2
            for (V3 u = new V3(0.0f, 0.0f, 0.0f); (u.x < Math.Abs(L1.x) || L1.x == 0) && (u.y < Math.Abs(L1.y) || L1.y == 0) && (u.z < Math.Abs(L1.z) || L1.z == 0); u += (L1 * (float)pas))
            {
                for (V3 v = new V3(0.0f, 0.0f, 0.0f); (v.x < Math.Abs(L2.x) || L2.x == 0) && (v.y < Math.Abs(L2.y) || L2.y == 0) && (v.z < Math.Abs(L2.z) || L2.z == 0); v += (L2 * (float)pas))
                {
                    float dhdu, dhdv;
                    float x = u.x + v.x + origin.x;
                    float y = u.y + v.y + origin.y;
                    float z = u.z + v.z + origin.z;

                    int x_ecran = (int)x;
                    int z_ecran = (int)z;

                    Couleur C_obj = T.LireCouleur((float)(u.Norm() / L1.Norm()), (float)(v.Norm() / L2.Norm()));
                    //final_ambiant = C_obj * C_ambiant;

                    if (ZBuffer.test(y, x_ecran, z_ecran))
                    {
                        // BUMP MAP
                        V3 Np = N;
                        if (T_bump != null)
                        {
                            V3 dmdu = L1;
                            V3 dmdv = L2;
                            this.T_bump.Bump((float)(u.Norm() / L1.Norm()), (float)(v.Norm() / L2.Norm()), out dhdu, out dhdv);
                            Np = N + bump_coeff * ((dmdu ^ (N * dhdv)) + ((N * dhdu) ^ dmdv));
                        }
                        // FIN BUMP MAP

                        V3 O = new V3(x, y, z);
                        O = camera - O;
                        //Couleur finalColor = computeLights(C_obj, C_ambiant, Np, O, L, k);
                        //BitmapEcran.DrawPixel(x_ecran, z_ecran, finalColor);
                    }
                }
            }
        }*/
        public override Couleur DrawPoint(Couleur C_ambiant, List<Lampe> lampList, V3 camera, V3 R, bool[] occs)
        {
            V3 N = this.N;
            N.Normalize();
            V3 O = camera - R;

            // TEXTURE
            V3 AI = R - this.origin;
            float a = (this.L1 * AI) / (this.L1.Norme2());
            float b = ((AI - a * this.L1).Norm()) / (this.L2.Norm());
            Couleur C_obj = T.LireCouleur(a, 1 - b);

            // BUMP MAP
            if (T_bump != null)
            {
                float dhdu, dhdv;
                V3 dmdu = L1;
                V3 dmdv = L2;
                this.T_bump.Bump(a, b, out dhdu, out dhdv);
                N = N + bump_coeff * ((dmdu ^ (N * dhdv)) + ((N * dhdu) ^ dmdv));
            }
            // FIN BUMP MAP

            Point I = new Point(C_obj, C_ambiant, N, O, this.k);
            Couleur finalColor = computeLights(I, lampList, occs);
            return finalColor;
        }
Ejemplo n.º 3
0
 public Lumiere(int pType, V3 pDirection, V3 pPosition, Couleur pC_lampe)
 {
     this.type = pType;
     this.direction = pDirection;
     this.position = pPosition;
     this.C_lampe = pC_lampe;
 }
Ejemplo n.º 4
0
        /*public override void Draw(Couleur C_ambiant, Lumiere L, V3 camera)
        {
            Couleur final_ambiant;
            Couleur C_lampe = L.getClampe();

            for (double u = 0; u < 2 * Math.PI; u += pas)
            {
                for (double v = -1 * Math.PI / 2; v < Math.PI / 2; v += pas)
                {
                    float dhdu, dhdv;
                    Couleur C_obj = T.LireCouleur((float)(u / (2 * Math.PI)), (float)((v + Math.PI / 2) / Math.PI));
                    final_ambiant = C_obj * C_ambiant;
                    double x = rayon * Math.Cos(v) * Math.Cos(u);
                    double y = rayon * Math.Cos(v) * Math.Sin(u);
                    double z = rayon * Math.Sin(v);
                    int x_ecran = (int)x + (int)origin.x;
                    int z_ecran = (int)z + (int)origin.z;
                    if (ZBuffer.test(y, x_ecran, z_ecran))
                    {
                        V3 N = new V3((float)x, (float)y, (float)z); //ne pas toucher

                        // BUMP MAP
                        if (T_bump != null)
                        {
                            V3 dmdu = new V3((float)(-rayon * Math.Cos(v) * Math.Sin(u)),
                                            (float)(rayon * Math.Cos(v) * Math.Cos(u)),
                                            0.0f);
                            V3 dmdv = new V3((float)(-rayon * Math.Sin(v) * Math.Cos(u)),
                                                (float)(-rayon * Math.Sin(v) * Math.Sin(u)),
                                                (float)(rayon * Math.Cos(v)));
                            this.T_bump.Bump((float)(u / (2 * Math.PI)), (float)((v + Math.PI / 2) / Math.PI), out dhdu, out dhdv);
                            N = N + bump_coeff * ((dmdu ^ (N * dhdv)) + ((N * dhdu) ^ dmdv));
                        }

                        // FIN BUMP MAP

                        V3 O = new V3((float)x, (float)y, (float)z);
                        O = camera - O;
                        //Couleur finalColor = computeLights(C_obj, C_ambiant, N, O, L, k);
                        //BitmapEcran.DrawPixel(x_ecran, z_ecran, finalColor);
                    }
                }
            }
        }*/
        public override Couleur DrawPoint(Couleur C_ambiant, List<Lampe> lampList, V3 camera, V3 R, bool[] occs)
        {
            V3 N = R - this.origin;
            N.Normalize();
            V3 O = camera - R;

            // TEXTURE
            float u, v;
            IMA.Invert_Coord_Spherique(R - this.origin, this.rayon, out u, out v);
            Couleur C_obj = T.LireCouleur((float)(u / (Math.PI)), (float)((v + IMA.PI2) / Math.PI));

            // BUMP MAP
            if (T_bump != null)
            {
                float dhdu, dhdv;
                V3 dmdu = new V3((float)(-rayon * Math.Cos(v) * Math.Sin(u)),
                                (float)(rayon * Math.Cos(v) * Math.Cos(u)),
                                0.0f);
                V3 dmdv = new V3((float)(-rayon * Math.Sin(v) * Math.Cos(u)),
                                    (float)(-rayon * Math.Sin(v) * Math.Sin(u)),
                                    (float)(rayon * Math.Cos(v)));
                this.T_bump.Bump((float)(u / (Math.PI)), (float)((v + IMA.PI2) / Math.PI), out dhdu, out dhdv);
                N = N + bump_coeff * ((dmdu ^ (N * dhdv)) + ((N * dhdu) ^ dmdv));
            }
            // FIN BUMP MAP

            Point I = new Point(C_obj, C_ambiant, N, O, this.k);
            Couleur finalColor = computeLights(I, lampList, occs);
            return finalColor;
        }
Ejemplo n.º 5
0
 public Lumiere()
 {
     type = 0; // directional light
     direction = new V3(0.0f,0.0f,0.0f);
     position = new V3(0.0f, 0.0f, 0.0f);
     C_lampe = new Couleur(1.0f, 1.0f, 1.0f);
 }
Ejemplo n.º 6
0
 public Point()
 {
     this.C_obj = new Couleur (1.0f, 1.0f, 1.0f);
     this.C_ambiant = new Couleur(0.2f, 0.2f, 0.2f);
     this.N = new V3(0, -1, 0);
     this.O = new V3(0, 0, 0);
     this.k = 30;
 }
Ejemplo n.º 7
0
 public Point(Couleur C_obj, Couleur C_ambiant, V3 N, V3 O, int k)
 {
     this.C_obj = C_obj;
     this.C_ambiant = C_ambiant;
     this.N = N;
     this.O = O;
     this.k = k;
 }
Ejemplo n.º 8
0
 public Sphere(V3 center, int rayon, Texture T, Texture T_bump, float bump_coeff)
 {
     pas = 0.005;
     k = 30;
     this.origin = center;
     this.rayon = rayon;
     this.T = T;
     this.T_bump = T_bump;
     this.bump_coeff = bump_coeff;
 }
Ejemplo n.º 9
0
        V3 L1, L2, N; // vecteurs longueur, largeur, normale

        #endregion Fields

        #region Constructors

        public Rect(V3 origin, V3 L1, V3 L2, Texture T, Texture T_bump)
        {
            pas = 0.001;
            k = 30;
            this.origin = origin;
            this.L1 = L1;
            this.L2 = L2;
            this.N = L1 ^ L2;
            N.Normalize();
            this.T = T;
            this.T_bump = T_bump;
            this.bump_coeff = 0.005f;
        }
 public static void Invert_Coord_Spherique(V3 P, float r, out float u, out float v)
 {
     P = P / r;
     if (P.z >= 1) { u =(float) IMA.PI2 ; v = 0; }
     else if (P.z <= -1) { u = (float)-IMA.PI2 ; v = 0; }
     else
     {
         v = (float) Math.Asin(P.z);
         float t = (float) (P.x / IMA.Cosf(v));
         if (t <= -1) { u = (float) IMA.PI; }
         else if (t >= 1) { u = 0; }
         else
         {
             if (P.y < 0) u = (float) ( 2 * IMA.PI - Math.Acos(t));
             else u = (float) Math.Acos(t);
         }
     }
 }
Ejemplo n.º 11
0
 public static float prod_scal(ref V3 u, ref V3 v)
 {
     return(u.x * v.x + u.y * v.y + u.z * v.z);
 }
Ejemplo n.º 12
0
 protected Formes(String textureLocation, String bumpMapLocation, V3 position)
 {
     this.texture  = new Texture(textureLocation);
     this.BumpMap  = new Texture(bumpMapLocation);
     this.position = position;
 }
Ejemplo n.º 13
0
 public V3(V3 t)
 {
     x = t.x;
     y = t.y;
     z = t.z;
 }
Ejemplo n.º 14
0
 public LampePonctuelle(Couleur couleur, float intensite, V3 position, float decay) : base(couleur, intensite)
 {
     this.position = position;
     this.decay    = decay;
 }
Ejemplo n.º 15
0
 public abstract Couleur getCouleurRaycast(V3 PointIntersection, Scene scene);
Ejemplo n.º 16
0
        public override float GetIntensite(V3 point)
        {
            float distance = (this.position - point).Norm();

            return(Math.Max(0, (this.intensite - (decay * distance))));
        }
Ejemplo n.º 17
0
 public Sphere(Couleur chroma, String bumpMapLocation, V3 position, float rayon) : base(chroma, bumpMapLocation, position)
 {
     this.rayon = rayon;
 }
Ejemplo n.º 18
0
        static public void Room(ref List <Object> objects_on_screen)
        {
            /** Room **/

            V3    A, B, C;
            float y = max_y_position;

            //Back wall

            A = new V3(screen_w * 0f, y, screen_h * 0f);
            B = new V3(screen_w * 1f, y, screen_h * 0f);
            C = new V3(screen_w * 0f, y, screen_h * 1f);

            objects_on_screen.Add(new Rectangle_2(A, B, C, T_clouds, objects_on_screen.Count));

            // Left wall
            A = new V3(screen_w * 0f, 0, screen_h * 0f);
            B = new V3(screen_w * 0f, y, screen_h * 0f);
            C = new V3(screen_w * 0f, 0, screen_h * 1f);


            objects_on_screen.Add(new Rectangle_2(A, B, C, T_bricks, objects_on_screen.Count));

            // Right wall
            A = new V3(screen_w * 1f, y, screen_h * 0f);
            C = new V3(screen_w * 1f, y, screen_h * 1f);
            B = new V3(screen_w * 1f, 0, screen_h * 0f);


            objects_on_screen.Add(new Rectangle_2(A, B, C, T_bricks, objects_on_screen.Count));

            // Floor

            A = new V3(screen_w * 0f, 0, screen_h * 0f);
            B = new V3(screen_w * 1f, 0, screen_h * 0f);
            C = new V3(screen_w * 0f, y, screen_h * 0f);

            objects_on_screen.Add(new Rectangle_2(A, B, C, T_wood, objects_on_screen.Count));

            // Celling

            A = new V3(screen_w * 0f, y, screen_h * 1f);
            B = new V3(screen_w * 1f, y, screen_h * 1f);
            C = new V3(screen_w * 0f, 0, screen_h * 1f);

            objects_on_screen.Add(new Rectangle_2(A, B, C, White, objects_on_screen.Count));

            // Front wall
            A = new V3(screen_w * 0f, 0, screen_h * 0f);
            C = new V3(screen_w * 0f, 0, screen_h * 1f);
            B = new V3(screen_w * 1f, 0, screen_h * 0f);

            //objects_on_screen.Add(new Rectangle_2(A, B, C, Green, objects_on_screen.Count));

            // Lamp

            V3 center = new V3(screen_w * 0.5f, y / 2, screen_h * 1.14f);

            objects_on_screen.Add(new Sphere(100, center, White, objects_on_screen.Count));
            objects_on_screen.Last <Object>().setSpecularity(1.2f, 0.1f);
        }
Ejemplo n.º 19
0
 public abstract PointColore GetCouleurIntersect(V3 camera, V3 directionOculaire, float intersection);
Ejemplo n.º 20
0
 public Sphere(String textureLocation, String bumpMapLocation, V3 position, float rayon) : base(textureLocation, bumpMapLocation, position)
 {
     this.rayon = rayon;
 }
Ejemplo n.º 21
0
 public abstract float IntersectRayon(V3 camera, V3 directionOculaire);
Ejemplo n.º 22
0
 protected Formes(Couleur chroma, String bumpMapLocation, V3 position)
 {
     this.texture  = new MonoTexture(chroma);
     this.BumpMap  = new Texture(bumpMapLocation);
     this.position = position;
 }
Ejemplo n.º 23
0
 public Triangle(Texture tex, V3 pointA, V3 pointB, V3 pointC, V3 texA, V3 texB, V3 texC) : base(tex, "n", pointA)
 {
     this.pointB   = pointB;
     this.pointC   = pointC;
     this.textureA = texA;
     this.textureB = texB;
     this.textureC = texC;
     this.resetVectors();
 }
Ejemplo n.º 24
0
        static public void Bed(ref List <Object> objects_on_screen)
        {
            V3    A, B, C;
            float y                = 100;
            float bed_lenght       = 500;
            float starting_w_point = screen_w * 0f;
            float starting_h_point = screen_h * 0.15f;

            // Matress

            A = new V3(starting_w_point + bed_lenght - 10, y + 10, starting_h_point + 20);
            B = new V3(starting_w_point + bed_lenght - 10, y + bed_lenght / 2 - 10, starting_h_point + 20);
            C = new V3(starting_w_point + 10, y + 10, starting_h_point + 20);

            objects_on_screen.Add(new Rectangle_2(A, B, C, White, objects_on_screen.Count));
            objects_on_screen.Last <Object>().setBump(bump_1, 400f);

            A = new V3(starting_w_point + bed_lenght - 10, y + 10, starting_h_point);
            B = new V3(starting_w_point + bed_lenght - 10, y + 10, starting_h_point + 20);
            C = new V3(starting_w_point + 10, y + 10, starting_h_point);

            objects_on_screen.Add(new Rectangle_2(A, B, C, White, objects_on_screen.Count));

            A = new V3(starting_w_point + bed_lenght - 10, y + 10, starting_h_point);
            B = new V3(starting_w_point + bed_lenght - 10, y + bed_lenght / 2 - 10, starting_h_point + 20);
            C = new V3(starting_w_point + bed_lenght - 10, y + 10, starting_h_point + 20);

            objects_on_screen.Add(new Rectangle_2(A, B, C, White, objects_on_screen.Count));

            // Pillow
            V3    center;
            float R = 20;

            for (int i = 30; i < bed_lenght / 2 - 80; i++)
            {
                center = new V3(starting_w_point + R, y + i, starting_h_point + R + 20);
                objects_on_screen.Add(new Sphere(R, center, Pink1, objects_on_screen.Count));
            }

            // Bed
            // top
            A = new V3(starting_w_point + bed_lenght, y, starting_h_point);
            B = new V3(starting_w_point + bed_lenght, y + bed_lenght / 2, starting_h_point);
            C = new V3(starting_w_point, y, starting_h_point);

            objects_on_screen.Add(new Rectangle_2(A, B, C, Blue, objects_on_screen.Count));
            //objects_on_screen.Last<Object>().setBump(bump_1, 400f);

            // side shown
            A = new V3(starting_w_point + bed_lenght, y, 0);
            B = new V3(starting_w_point + bed_lenght, y, starting_h_point);
            C = new V3(starting_w_point, y, 0);

            objects_on_screen.Add(new Rectangle_2(A, B, C, Blue, objects_on_screen.Count));


            // side hidden
            A = new V3(starting_w_point + bed_lenght, y + bed_lenght / 2, 0);
            B = new V3(starting_w_point + bed_lenght, y + bed_lenght / 2, starting_h_point);
            C = new V3(starting_w_point, y + bed_lenght / 2, 0);

            objects_on_screen.Add(new Rectangle_2(A, B, C, Blue, objects_on_screen.Count));


            // front
            A = new V3(starting_w_point + bed_lenght, y + bed_lenght / 2, 0);
            B = new V3(starting_w_point + bed_lenght, y + bed_lenght / 2, starting_h_point);
            C = new V3(starting_w_point + bed_lenght, y, 0);

            objects_on_screen.Add(new Rectangle_2(A, B, C, Blue, objects_on_screen.Count));
        }
Ejemplo n.º 25
0
 //constructeur
 public Sphere(V3 pCenter, float pRayon, Materiel pMateriel)
 {
     center   = pCenter;
     rayon    = pRayon;
     materiel = pMateriel;
 }
Ejemplo n.º 26
0
        static public void Shelf(ref List <Object> objects_on_screen)
        {
            V3    A, B, C;
            float y                = max_y_position - 100;
            float shelf_lenght     = 400;
            float starting_w_point = screen_w * 0f;
            float starting_h_point = screen_h * 0.65f;

            // top
            A = new V3(starting_w_point + shelf_lenght, y, starting_h_point);
            B = new V3(starting_w_point + shelf_lenght, y + shelf_lenght / 3, starting_h_point);
            C = new V3(starting_w_point, y, starting_h_point);

            objects_on_screen.Add(new Rectangle_2(A, B, C, Red, objects_on_screen.Count));

            // bottom
            A = new V3(starting_w_point + shelf_lenght, y, starting_h_point - 20);
            C = new V3(starting_w_point + shelf_lenght, y + shelf_lenght / 3, starting_h_point - 20);
            B = new V3(starting_w_point, y, starting_h_point - 20);

            objects_on_screen.Add(new Rectangle_2(A, B, C, White, objects_on_screen.Count));

            //front
            A = new V3(starting_w_point + shelf_lenght, y, starting_h_point - 20);
            B = new V3(starting_w_point + shelf_lenght, y, starting_h_point);
            C = new V3(starting_w_point, y, starting_h_point - 20);

            objects_on_screen.Add(new Rectangle_2(A, B, C, White, objects_on_screen.Count));

            //side

            A = new V3(starting_w_point + shelf_lenght, y, starting_h_point - 20);
            B = new V3(starting_w_point + shelf_lenght, y + shelf_lenght, starting_h_point - 20);
            C = new V3(starting_w_point + shelf_lenght, y, starting_h_point);

            objects_on_screen.Add(new Rectangle_2(A, B, C, White, objects_on_screen.Count));

            float book_size = 84;

            y = max_y_position - 50;

            // book 1

            A = new V3(starting_w_point + 40, y, starting_h_point);
            B = new V3(starting_w_point + 40, y + shelf_lenght - 3, starting_h_point);
            C = new V3(starting_w_point + 30, y, starting_h_point + book_size);

            objects_on_screen.Add(new Rectangle_2(A, B, C, Yellow, objects_on_screen.Count));

            B = new V3(starting_w_point + 30, y, starting_h_point + book_size);
            C = new V3(starting_w_point + 20, y, starting_h_point);

            objects_on_screen.Add(new Rectangle_2(A, B, C, Yellow, objects_on_screen.Count));

            A = new V3(starting_w_point + 20, y, starting_h_point);
            C = new V3(starting_w_point + 20, y + shelf_lenght - 3, starting_h_point);
            B = new V3(starting_w_point, y, starting_h_point + book_size);

            objects_on_screen.Add(new Rectangle_2(A, B, C, Yellow, objects_on_screen.Count));

            // book 2
            book_size = 150;

            A = new V3(starting_w_point + book_size + 50, y, starting_h_point + 35);
            B = new V3(starting_w_point + book_size + 50, y + shelf_lenght, starting_h_point + 35);
            C = new V3(starting_w_point + 50, y, starting_h_point + 35);

            objects_on_screen.Add(new Rectangle_2(A, B, C, Red, objects_on_screen.Count));

            A = new V3(starting_w_point + book_size + 50, y, starting_h_point);
            B = new V3(starting_w_point + book_size + 50, y, starting_h_point + 35);
            C = new V3(starting_w_point + 50, y, starting_h_point);

            objects_on_screen.Add(new Rectangle_2(A, B, C, Red, objects_on_screen.Count));

            A = new V3(starting_w_point + book_size + 45, y, starting_h_point);
            B = new V3(starting_w_point + book_size + 45, y + shelf_lenght - 5, starting_h_point);
            C = new V3(starting_w_point + book_size + 45, y, starting_h_point + 35);

            objects_on_screen.Add(new Rectangle_2(A, B, C, Yellow2, objects_on_screen.Count));
            objects_on_screen.Last <Object>().setBump(bump_lead, 40f);
        }
 public Parallelogram(V3 pointA, V3 pointB, V3 pointC, Texture texture, bool ignoreShadow, Texture textureBump = null, float intensiteBump = 0, float coefReflexion = 0, float coefRefraction = 0, float indiceFresnel = 0) : base(texture, textureBump, intensiteBump, coefReflexion, coefRefraction, indiceFresnel)
 {
     InitPoints(pointA, pointB, pointC);
     this.ignoreShadow = ignoreShadow;
 }
Ejemplo n.º 28
0
 public abstract float gettIntersect(V3 PosCamera, V3 DirRayon);
Ejemplo n.º 29
0
        public override float getIntersect(V3 Rd, V3 cam)
        {
            // intersection avec le plan (pas le rectangle)
            float t = ((this.origin - cam) * this.N) / (Rd * this.N);
            V3 I = cam + t * Rd;
            V3 AI = (I - this.origin);
            // a et b pour vérifier si on est dans le rectangle (pas que dans le plan)
            float a = (this.L1 * AI) / (this.L1.Norme2());
            //float b = IMA.Sqrtf((this.origin - cam).Norme2() - a * a);
            //float b = (AI.Norm() * IMA.Sqrtf(1 - ((a * L1).Norm() / AI.Norm()) * ((a * L1).Norm() / AI.Norm()))) / this.L2.Norm();
            float b = ((AI - a * this.L1).Norm()) / (this.L2.Norm());
            b = (L2 * (AI - a * this.L1) < 0) ? -b : b;

            if ((0 <= a && a <= 1) && (0 <= b && b <= 1))
            {
                return t;
            }
            else
            {
                return -1f;
            }
        }
Ejemplo n.º 30
0
 public Quadrilatere(string textureLocation, string bumpMapLocation, V3 pointA, V3 pointB, V3 pointC) : base(textureLocation, bumpMapLocation, pointA)
 {
     this.pointB = pointB;
     this.pointC = pointC;
 }
Ejemplo n.º 31
0
        public static void add_light(V3 direction, Couleur c)
        {
            Light_Source l = new Light_Source(direction, c);

            lights.Add(l);
        }
Ejemplo n.º 32
0
 public static float prod_scal(ref V3 u, ref V3 v)
 {
     return u.x * v.x + u.y * v.y + u.z * v.z;
 }
Ejemplo n.º 33
0
        public static Couleur Color_Diffused(Light_Source light, Couleur px_color, V3 P, V3 N)
        {
            V3 L = -light.direction;

            if (light.point_light)
            {
                L = light.position - P;
                //L = P-light.position;
                L.Normalize();
            }
            float cos_theta = N * L;


            if (cos_theta < 0)
            {
                cos_theta = 0;
            }



            float   on_shadow = getShadow(P, light);
            Couleur c         = cos_theta * (light.color * px_color);

            return(c * on_shadow);
        }
Ejemplo n.º 34
0
 public override float getIntersect(V3 R, V3 cam)
 {
     float t, t1, t2;
     float A = R.Norme2();
     float B = 2*(R.x * (cam.x - origin.x) + R.y * (cam.y - origin.y) + R.z * (cam.z - origin.z));
     float C = (cam.x - origin.x) * (cam.x - origin.x) + (cam.y - origin.y) * (cam.y - origin.y) + (cam.z - origin.z) * (cam.z - origin.z) - (this.rayon * this.rayon);
     float D = B * B - 4 * A * C;
     if (D < 0)
     {
         return -1f;
     }
     else
     {
         t = -1f;
         if (D > 0)
         {
             t1 = (-B - IMA.Sqrtf(D)) / (2 * A);
             t2 = (-B + IMA.Sqrtf(D)) / (2 * A);
             if (t1 < t2 && t1 >= 0)
             {
                 t = t1;
             }
             else if (t2 < t1 && t2 >= 0)
             {
                 t = t2;
             }
         }
         else
         {
             t = -B / (2 * A);
         }
         return t;
     }
 }
Ejemplo n.º 35
0
 protected Formes(Texture t, String bp, V3 position)
 {
     this.texture  = t;
     this.BumpMap  = new Texture(bp);
     this.position = position;
 }
Ejemplo n.º 36
0
 public override V3 GetDirection(V3 point)
 {
     return(this.direction);
 }
Ejemplo n.º 37
0
 public LampeDirectionelle(Couleur couleur, float intensite, V3 direction) : base(couleur, intensite)
 {
     this.direction = direction;
 }
Ejemplo n.º 38
0
 public V3(V3 t)
 {
     x = t.x;
     y = t.y;
     z = t.z;
 }
Ejemplo n.º 39
0
 public Quadrilatere(Couleur chroma, string bumpMapLocation, V3 pointA, V3 pointB, V3 pointC) : base(chroma, bumpMapLocation, pointA)
 {
     this.pointB = pointB;
     this.pointC = pointC;
 }
Ejemplo n.º 40
0
        public static void add_light(V3 position, Couleur c, bool point)
        {
            Light_Source l = new Light_Source(position, c, true);

            lights.Add(l);
        }
Ejemplo n.º 41
0
 public void setPosition(V3 pPosition)
 {
     this.position = pPosition;
 }
Ejemplo n.º 42
0
        private void outPosition(float x, float y, float z)
        {
            V3 position = new V3(x, y, z);

            this.formToModif.setPosition(position);
        }
Ejemplo n.º 43
0
 //abstract public void Draw(Couleur C_ambiant, Lumiere L, V3 camera);
 public abstract float getIntersect(V3 R, V3 cam);
Ejemplo n.º 44
0
        public static void Start()
        {
            //création de la scène qui va contenir les objets
            Scene mainScene = new Scene();

            //couleurs
            Couleur blanc  = new Couleur(1, 1, 1);
            Couleur rouge  = new Couleur(0.9f, 0, 0);
            Couleur jaune  = new Couleur(1, 1, 0);
            Couleur vert   = new Couleur(0, 1, 0);
            Couleur cyan   = new Couleur(0, 1, 1);
            Couleur bleu   = new Couleur(0, 0, 1);
            Couleur violet = new Couleur(1, 0, 1);
            Couleur gris   = new Couleur(0.5f, 0.5f, 0.5f);
            Couleur noir   = new Couleur(0, 0, 0);

            //========== Lumières ==========
            //lumière ambiante


            //lumières directionnelles
            V3 directionLumièreDirectionnelle;
            V3 positionLumièrePoint;
            LumiereDirectionnelle lumiereDirerectionnelle;
            LumierePoint          lumierePoint;

            LumiereAmbiante LumAmb = new LumiereAmbiante(new Couleur(0.3f, 0.3f, 0.3f));

            mainScene.SetLumAmb(LumAmb);

            directionLumièreDirectionnelle = new V3(0, -1, 0);
            lumiereDirerectionnelle        = new LumiereDirectionnelle(new Couleur(0.5f, 0.5f, 0.5f), directionLumièreDirectionnelle);
            //mainScene.AddLumDir(lumiereDirerectionnelle);

            positionLumièrePoint = new V3(400, 1, 400);
            lumierePoint         = new LumierePoint(new Couleur(0.5f, 0.5f, 0.5f), positionLumièrePoint);
            mainScene.AddLum(lumierePoint);

            positionLumièrePoint = new V3(BitmapEcran.GetWidth() / 2, 0, BitmapEcran.GetHeight() / 2);
            lumierePoint         = new LumierePoint(new Couleur(0.5f, 0.5f, 0.5f), positionLumièrePoint);
            mainScene.AddLum(lumierePoint);



            //directionLumièreDirectionnelle = new V3(-1, -1, -1);
            //lumiereDirerectionnelle = new LumiereDirectionnelle(new Couleur(0,0, 0.7f), directionLumièreDirectionnelle);
            //mainScene.AddLumDir(lumiereDirerectionnelle);

            //========== Matériaux ==========
            Materiel Blanc  = new Materiel(blanc / 1.2f, new Texture("bump38.jpg"), 50, 1);
            Materiel test   = new Materiel(new Texture("test.jpg"), new Texture("test.jpg"), 200, 3);
            Materiel or     = new Materiel(new Texture("gold.jpg"), new Texture("gold_Bump.jpg"), 200, 0.7f);
            Materiel plomb  = new Materiel(new Texture("lead.jpg"), new Texture("lead_bump.jpg"), 50, 1);
            Materiel brique = new Materiel(new Texture("brickwork-texture.jpg"), new Texture("brickwork-bump-map.jpg"), 500, 1);
            Materiel rock   = new Materiel(new Texture("rock.jpg"), new Texture("rock.jpg"), 500, 1);
            Materiel stone  = new Materiel(new Texture("rock.jpg"), new Texture("rock.jpg"), 500, 1);
            Materiel fibre  = new Materiel(new Texture("rock.jpg"), new Texture("rock.jpg"), 500, 1);
            Materiel Blob   = new Materiel(blanc / 1.2f, new Texture("bump.jpg"), 50, 1);


            //========== Objets ==========
            V3        center;
            Sphere    s;
            Rectangle r;

            //Boule Or
            center = new V3(600, 300f, 200);
            s      = new Sphere(center, 50, or);
            mainScene.AddObjet3D(s);

            //Boule Or
            center = new V3(200, 200, 100);
            s      = new Sphere(center, 150, Blob);
            mainScene.AddObjet3D(s);

            //Boule Plomb
            center = new V3(800, 1000, 400);
            s      = new Sphere(center, 100, plomb);
            mainScene.AddObjet3D(s);

            //Boule Brique
            center = new V3(300, 1000, 400);
            s      = new Sphere(center, 150, Blanc);
            mainScene.AddObjet3D(s);

            //Rectangle brique Gauche
            V3 A = new V3(0, 0, 0);
            V3 B = new V3(0, 2000, 0);
            V3 C = new V3(0, 0, 800);

            r = new Rectangle(A, B, C, brique);
            mainScene.AddObjet3D(r);

            //Rectangle brique Droit
            A = new V3(1000, 2000, 0);
            B = new V3(1000, 0, 0);
            C = new V3(1000, 2000, 800);
            r = new Rectangle(A, B, C, brique);
            mainScene.AddObjet3D(r);

            //Rectangle brique Fond
            A = new V3(0, 2000, 0);
            B = new V3(1000, 2000, 0);
            C = new V3(0, 2000, 800);
            r = new Rectangle(A, B, C, brique);
            mainScene.AddObjet3D(r);

            //Rectangle brique Bas
            A = new V3(0, 0, 0);
            B = new V3(1000, 0, 0);
            C = new V3(0, 2000, 0);
            r = new Rectangle(A, B, C, brique);
            mainScene.AddObjet3D(r);

            A = new V3(400, 0, 0);
            B = new V3(190, -50, 0);
            C = new V3(0, 0, 190);
            r = new Rectangle(A, B, C, brique);
            //mainScene.AddObjet3D(r);


            //Affichage de la scène
            mainScene.DrawScene();
        }
Ejemplo n.º 45
0
 public abstract V3 GetDirection(V3 point);
Ejemplo n.º 46
0
 public void setDirection(V3 pDirection)
 {
     this.direction = pDirection;
 }
Ejemplo n.º 47
0
 public abstract V3 getDirection(V3 PositionObjet);
Ejemplo n.º 48
0
        public static void Go()
        {
            int width = BitmapEcran.GetWidth();
            int height = BitmapEcran.GetHeight()+1;

            Couleur C_ambiant = new Couleur(0.2f, 0.2f, 0.2f);
            V3 camera = new V3(width / 2, -1000, height / 2);

            // LAMPES
            List<Lampe> lampList = new List<Lampe>();
            lampList.Add(new Lumiere(0, new V3(1f, -1f, 1f), new V3(0f, 0f, 0f), new Couleur(0.4f, 0.4f, 0.4f)));
            lampList.Add(new Lumiere(0, new V3(-1f, -1f, 1f), new V3(0f, 0f, 0f), new Couleur(0.4f, 0.4f, 0.4f)));

            // TEXTURES
            Texture T_carreau = new Texture("carreau.jpg");
            Texture T_lead = new Texture("lead.jpg");
            Texture T_Aymeric = new Texture("aymeric.jpg");
            Texture T_stone = new Texture("stone2.jpg");
            Texture T_fibre = new Texture("fibre.jpg");
            Texture T_brick = new Texture("brick01.jpg");
            Texture T_gold = new Texture("gold.jpg");
            // BUMP TEXTURES
            Texture T_bump = new Texture("bump38.jpg");
            Texture T_leadbump = new Texture("lead_bump.jpg");

            // OBJETS
            List<Objet3D> objList = new List<Objet3D>();

            //SPHERES
            objList.Add(new Sphere(new V3(width / 2, 500, height - 50), 150, T_carreau, T_bump, 0.008f));
            objList.Add(new Sphere(new V3(50, 500, height / 2), 150, T_lead, T_leadbump, 0.01f));
            objList.Add(new Sphere(new V3(175, 300, height / 2 + 75), 50, T_gold, T_bump, 0.1f));
            //RECTS
            //fond
            objList.Add(new Rect(new V3(50, 1000, 50), new V3(width - 100, 0, 0), new V3(0, 0, height - 100), T_brick, null));
            //bas
            objList.Add(new Rect(new V3(50, 0, 50), new V3(width - 100, 0, 0), new V3(0, 1000, 0), T_stone, null));
            //haut
            //objList.Add(new Rect(new V3(width-50, 0, height-50), new V3(-(width-100), 0, 0), new V3(0, 1000, 0), T_fibre, null));
            //gauche
            objList.Add(new Rect(new V3(50, 0, 50), new V3(0, 1000, 0), new V3(0, 0, height - 100), T_brick, null));
            //droite
            objList.Add(new Rect(new V3(width - 50, 1000, 50), new V3(0, -1000, 0), new V3(0, 0, height - 100), T_brick, null));
            //milieu
            objList.Add(new Rect(new V3(width / 2 + 100, 750, 50), new V3(0, -500, 0), new V3(0, 0, height / 3), T_brick, null));

            // RAY CASTING

            V3 Rd, R;
            float t, tnew;
            bool[] occs = new bool[lampList.Count];

            //parcourir les pixels en x
            for (int pxx = 0; pxx < width; pxx++) {
                //parcourir les pixels en z
                for (int pxz = 0; pxz < height; pxz++) {
                    t = float.MaxValue;
                    // pour chaque pixel générer un rayon Rd
                    Rd = new V3(pxx - camera.x, -camera.y, pxz - camera.z);
                    Rd.Normalize();
                    // parcourir la liste des objets
                    foreach (Objet3D obj in objList) {
                        // appeler l'intersection et récupérer le point
                        tnew = obj.getIntersect(Rd, camera);
                        if (tnew != -1)
                        {
                            if (tnew <= t)
                            {
                                t = tnew;
                                // R est le point d'intersection de Rd et de l'objet
                                R = camera + t * Rd;
                                occs = obj.occultation(R, objList, lampList);
                                //Console.WriteLine(occs[0]+" "+occs[1]);
                                Couleur finalColor = obj.DrawPoint(C_ambiant, lampList, camera, R, occs);
                                BitmapEcran.DrawPixel(pxx, pxz, finalColor);
                            }
                        }

                    }
                }
            }

            //s1.Draw(C_ambiant, L, camera);
            //s2.Draw(C_ambiant, L, camera);

            //r1.Draw(C_ambiant, L, camera);
            //r2.Draw(C_ambiant, L, camera);
        }
Ejemplo n.º 49
0
 public abstract Couleur DrawPoint(Couleur C_ambiant, List<Lampe> lampList, V3 camera, V3 R, bool[] occs);