private void button1_Click(object sender, EventArgs e) { RenderSing.getCurrentRender().clear(); RenderSing.getCurrentRender().addObjects(this.listBox1.Items.Cast <Object3D>().ToList()); RenderSing.getCurrentRender().addLights(this.listBox2.Items.Cast <Light>().ToList()); float x, y, z; x = 0; y = 0; z = 0; if ( !float.TryParse(this.textBox4.Text, out x) || !float.TryParse(this.textBox5.Text, out y) || !float.TryParse(this.textBox6.Text, out z)) { Console.WriteLine("erreur ambiante"); } RenderSing.getCurrentRender().addLight(new AmbiantLight(new Couleur(x, y, z))); BitmapEcran.RefreshScreen(new Couleur(0, 0, 0)); ProjetEleve.Go(); BitmapEcran.Show(); }
private void textBox3_TextChanged(object sender, EventArgs e) { RenderSing rnd = RenderSing.getCurrentRender(); string txt = ((TextBox)sender).Text; int value = 0; if (rnd.alock && int.TryParse(txt, out value) && value < 0) { rnd.setEyesPosition(value); } }
private void textBox2_TextChanged_1(object sender, EventArgs e) { RenderSing rnd = RenderSing.getCurrentRender(); string txt = ((TextBox)sender).Text; int value = 0; if (rnd.alock && int.TryParse(txt, out value)) { rnd.setResolutionX(value); } }
//singleton public static RenderSing getCurrentRender() { if (current == null) { current = new RenderSing(new V3(0, 0, 0), new V3(0, 1, 0), -20, 400, 400); } return(current); }
public override Couleur drawPixel(V3 positionInScene) { V3 posionForSphere = positionInScene - this.getPosition(); float v; float u; IMA.Invert_Coord_Spherique(posionForSphere, this.rayon, out u, out v); V3 vectSphere = new V3((float)(this.rayon * Math.Cos(v) * Math.Cos(u)), (float)(this.rayon * Math.Cos(v) * Math.Sin(u)), (float)(this.rayon * Math.Sin(v))); V3 copyvectSphere = new V3(vectSphere); copyvectSphere.Normalize(); float dhsdu; float dhsdv; this.getBump(u / (Math.PI * 2), v / Math.PI + Math.PI / 2, out dhsdu, out dhsdv); V3 dmsdu = new V3((float)(-1 * Math.Cos(v) * Math.Sin(u)), (float)(1 * Math.Cos(v) * Math.Cos(u)), 0.0f); V3 dmsdv = new V3((float)(-1 * Math.Sin(v) * Math.Cos(u)), (float)(-1 * Math.Sin(v) * Math.Sin(u)), (float)(1 * Math.Cos(v))); V3 dmpsdu = dmsdu + dhsdu * copyvectSphere; V3 dmpsdv = dmsdv + dhsdv * copyvectSphere; V3 Np = ((dmpsdu ^ dmpsdv) / (dmpsdu ^ dmpsdv).Norm()); V3 vecteurBump = Np; V3 vect = this.getPosition() + vectSphere; Couleur vcolor = new Couleur(); foreach (Light light in RenderSing.getCurrentRender().getLight()) { vcolor += light.applyLight(this, vect, vecteurBump, this.getColor(u / (2 * Math.PI), v / Math.PI + Math.PI / 2)); } return(vcolor); }
public Form1() { InitializeComponent(); pictureBox1.Image = BitmapEcran.Init(pictureBox1.Width, pictureBox1.Height); this.textBox1.Text = RenderSing.getCurrentRender().getResolutionX().ToString(); this.textBox2.Text = RenderSing.getCurrentRender().getResolutionY().ToString(); this.textBox3.Text = RenderSing.getCurrentRender().getEyesPosition().y.ToString(); this.textBox4.Text = "0,5"; this.textBox5.Text = "0,5"; this.textBox6.Text = "0,5"; this.listBox1.Items.Add(new form.Rectangle(new V3(-50f, 0f, -10f), new V3(100f, 0f, 0f), new V3(0, 100f, 0f), new Texture("brick01.jpg"), new Texture("lead_bump.jpg"))); this.listBox1.Items.Add(new form.Rectangle(new V3(-20.0f, 50f, 10f), new V3(20f, 20f, 10f), new V3(0, 0, 20f), new Texture("lead.jpg"), new Texture("lead_bump.jpg"))); this.listBox1.Items.Add(new Sphere(new V3(0.0f, 50f, 0.0f), 15f, new Texture("carreau.jpg"), new Texture("bump38.jpg"))); this.listBox1.Items.Add(new Sphere(new V3(20.0f, 75f, 0.0f), 10f, new Couleur(1f, 0, 0), new Texture("bump38.jpg"))); this.listBox2.Items.Add(new DirectionalLight(new V3(1f, -1f, 1f), new Couleur(.8f, .8f, .8f))); }
public static void Go() { /* * RenderSing.getCurrentRender() * .addObject(new Rectangle( new V3(-50f, 0f, -10f), * new V3(100f, 0f, 0f), * new V3(0, 100f, 0f), * new Texture("brick01.jpg"), * new Texture("lead_bump.jpg"))) * * .addObject(new Rectangle( new V3(-20.0f, 50f, 10f), * new V3(20f, 20f,10f), * new V3(0,0,20f), * new Texture("lead.jpg"), * new Texture("lead_bump.jpg"))) * * .addObject(new Sphere( new V3(0.0f, 50f, 0.0f), * 15f, * new Texture("carreau.jpg"), * new Texture("bump38.jpg"))) * * .addObject(new Sphere( new V3(20.0f, 75f, 0.0f), * 10f, * new Couleur(1f,0,0), * new Texture("bump38.jpg"))) * ;*/ /* * * RenderSing.getCurrentRender() * .addLight(new DirectionalLight( new V3(1f, -1f, 1f), * new Couleur(.8f, .8f, .8f))) * * .addLight(new AmbiantLight( new Couleur(.3f, 0.3f, 0.3f))); */ RenderSing rnd = RenderSing.getCurrentRender(); for (double x = rnd.getMinX(); x < rnd.getMaxX(); x += rnd.stepX) { for (double z = rnd.getMinY(); z < rnd.getMaxY(); z += rnd.stepY) { V3 rayProjection = new V3((float)x, 0.0f, (float)z) - RenderSing.getCurrentRender().getEyesPosition(); rayProjection.Normalize(); Double positionColition = 0; Double minPosition = Double.MaxValue; Object3D elementprox = null; foreach (Object3D one in RenderSing.getCurrentRender().getObject()) { if (one.testColition( RenderSing.getCurrentRender().getEyesPosition(), rayProjection, out positionColition) && positionColition < minPosition) { minPosition = positionColition; elementprox = one; } } Couleur color_pixel; if (elementprox != null) { color_pixel = elementprox.drawPixel((float)minPosition * rayProjection + RenderSing.getCurrentRender().getEyesPosition()); } else { //TODO sky map inplements color_pixel = new Couleur(0, 0, 0); } RenderSing.getCurrentRender().Draw(x, z, color_pixel); } } }