public void Avancer(bool vitesseMax, Univers univ, List <ObjetPhysique> Exclusion) { //VitesseMax : avancer de la distance qui separe de l'objet le plus proche if (!vitesseMax) { Longueur += Pas; } else { double distmin; if (univ.objets.Count > Exclusion.Count) { distmin = double.PositiveInfinity; } else { distmin = univ.distRayonMax; } foreach (ObjetPhysique obj in univ.objets) { if (!Exclusion.Contains(obj)) { double dist = obj.Distance(Position()); if (dist < distmin) { distmin = dist; } } } Longueur += distmin; } }
public static EnergieLumineuse CalculerAtmosphere(Univers univ, Tir tir) { Rayon r = new Rayon(tir, 0, univ.EpsilonContact, univ.distRayonMax); EnergieLumineuse E = new EnergieLumineuse(); Vector A = tir.depart; while (r.Longueur < r.distMax) { Vector X = r.Position(); foreach (SourceLumineuse sour in univ.sources) { Vector B = sour.Position(); EnergieLumineuse recueBrute = sour.GetEnergieLumineuse(X); Vector Opacite1 = Rayon.CalculerOpacite(univ, B, X); Vector Opacite2 = Rayon.CalculerOpacite(univ, X, A); Vector Opacite = Opacite1 + Opacite2; if (double.IsInfinity(Opacite2.x) && double.IsInfinity(Opacite2.y) && double.IsInfinity(Opacite2.z)) { return(E); } EnergieLumineuse Opacifiee = recueBrute.Opacifier(Opacite, univ.facteurExtinction); double angle = (X - B).Angle(A - X); double densite = univ.atmosphere(X).Norme(); Vector FacteurReorientation = univ.reorientationAtmosphere(angle, densite); E += (Opacifiee * FacteurReorientation) * r.Pas; } r.Avancer(false, univ, new List <ObjetPhysique>()); } return(E); }
Vector Opacite(Univers univ, double LongueurParcours) { //Calcule la somme d'opacite sur un parcours Vector retour = new Vector(0, 0, 0); ObjetPhysique contact; do { Avancer(false, univ, new List <ObjetPhysique>()); contact = Contact(univ, new List <ObjetPhysique>(), univ.EpsilonContact); if (contact is null) { retour += univ.atmosphere(Position()) * Pas; } else { if (contact.getMateriau().Opaque) { return(new Vector(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity)); } else { retour += contact.getMateriau().FiltrationVolumetrique *Pas; } } } while (Longueur < LongueurParcours && Longueur < distMax); return(retour); }
public ObjetPhysique Contact(Univers univ, List <ObjetPhysique> Exclusion, double d0) { foreach (ObjetPhysique obj in univ.objets) { if (!Exclusion.Contains(obj)) { if (obj.Contact(this.Position(), d0)) { return(obj); } } } return(null); }
public InfoContact Tirer(Univers univ, List <ObjetPhysique> Exclusion) { ObjetPhysique contact; do { Avancer(true, univ, Exclusion); contact = Contact(univ, Exclusion, univ.EpsilonContact); } while (contact is null && Longueur < distMax); if (contact is null) { return(new InfoContact(Position(), tir.direction, new Vector(0, 0, 0), null)); } return(new InfoContact(Position(), tir.direction.Normer(), contact.NormaleReelle(Position()), contact)); }
static void Main(string[] args) { Materiau Test = new Materiau(Mapper.Uniforme(new Vector(0.1, 0.03, 0.06)), Mapper.Uniforme(new Vector(0, 0, 0)), Mapper.AttenuationGaussienne(0.1, 0.1, 0.1), Mapper.AttenuationGaussienne(2, 2, 2), new Vector(1, 1, 1), 1, true); Materiau Test2 = new Materiau(Mapper.Uniforme(new Vector(0.01, 0, 0)), Mapper.Uniforme(new Vector(0, 0, 0)), Mapper.AttenuationGaussienne(1, 1, 0.5), ((x) => new Vector(1, 1, 1) * (x / 10)), new Vector(0.4, 0.4, 0.2), 1.3, false); Materiau Test3 = new Materiau(Mapper.Uniforme(new Vector(0, 0.2, 0)), Mapper.Uniforme(new Vector(0, 0, 0)), Mapper.AttenuationGaussienne(1, 1, 0.5), ((x) => new Vector(1, 1, 1) * (x / 10)), new Vector(0.4, 0.4, 0.2), 1, false); SourceLumineuse Source = new SourceLumineuse(new Base(Vector.X(), Vector.Y(), Vector.Z(), new Vector(0, 7, 3)), Mapper.ConeConstant(Color.White)); SourceLumineuse Source2 = new SourceLumineuse(new Base(Vector.X(), Vector.Y(), Vector.Z(), new Vector(0, 7, -3)), Mapper.ConeConstant(Color.White)); Sphere S = new Sphere(5, Test, new Base(Vector.X(), Vector.Y(), Vector.Z(), new Vector(0, 0, 0))); Sphere S1 = new Sphere(1, Test2, new Base(Vector.X(), Vector.Y(), Vector.Z(), new Vector(1.5, 6, 0))); Sphere S2 = new Sphere(1, Test3, new Base(Vector.X(), Vector.Y(), Vector.Z(), new Vector(-1.5, 6, 0))); Univers U = new Univers(new List <ObjetPhysique>() { S, S1, S2 }, new List <SourceLumineuse>() { Source2, Source }, 2, 5, 0.01, 1, Mapper.FiltrationUniforme(new Vector(0.1, 0.1, 0.1)), Mapper.Cacahuete(0.5, 0.01), 0.2); Camera C = new Camera(new Base(Vector.X(), Vector.Y(), Vector.Z(), new Vector(0, 7, 0)), 0.5, 100, 100, 0.05); C.Rendre(U).Save("D:/lab/Rendu3D/1.bmp"); }
public Bitmap Rendre(Univers univ) { Bitmap ret = new Bitmap(X_ecran, Y_ecran); int n = 0; for (int x = 0; x < X_ecran; x++) { for (int y = 0; y < Y_ecran; y++) { n++; Tir tir = GetTirPixel(x, y); Rayon ray = new Rayon(tir, 0, univ.EpsilonContact, univ.distRayonMax); EnergieLumineuse col = univ.GetLumiere(ray, univ.bounceLimit, new List <ObjetPhysique>()); ret.SetPixel(x, y, col.VersRGB()); if (n % 100 == 0) { Console.WriteLine((double)n / (X_ecran * Y_ecran)); } } } return(ret); }
public static Vector CalculerOpacite(Univers univ, Vector A, Vector B) { Rayon r = new Rayon(new Tir((B - A).Normer(), A), univ.PasVolumetrique, univ.PasVolumetrique, univ.distRayonMax); return(r.Opacite(univ, (B - A).Norme() - 2 * univ.PasVolumetrique)); }