From 64661b7c6df5e3ced43454056146a5d039a7ac31 Mon Sep 17 00:00:00 2001 From: p-flis Date: Tue, 5 Jan 2021 15:09:40 +0100 Subject: [PATCH 01/31] stop ray tracing while ui is used --- RayTracerApp/Forms/MainForm.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/RayTracerApp/Forms/MainForm.cs b/RayTracerApp/Forms/MainForm.cs index a8a6cc9..45d4756 100644 --- a/RayTracerApp/Forms/MainForm.cs +++ b/RayTracerApp/Forms/MainForm.cs @@ -32,6 +32,7 @@ public partial class MainForm : Form private Timer _fpsTimer = new Timer(); private long lastModification; private bool rayTracingStarted; + private bool _isUiUsed; public void UpdateLastModification() { @@ -43,7 +44,7 @@ public void UpdateLastModification() public bool ShouldRaytrace() { long now = DateTime.Now.Ticks / TimeSpan.TicksPerSecond; - return now - lastModification > SWAP_TIME; + return !_isUiUsed && now - lastModification > SWAP_TIME; } public MainForm() @@ -184,16 +185,27 @@ private void InitializeBackgroundWorker() private void newObjectButton_Click(object sender, EventArgs e) { + UpdateLastModification(); var form = new NewObjectForm(new NewObjectController(_scene)) {StartPosition = FormStartPosition.Manual, Location = Location + Size / 3}; + _isUiUsed = true; + form.Closed += FormOnClosed; form.Show(); } private void editObjectButton_Click(object sender, EventArgs e) { + UpdateLastModification(); var form = new EditObjectForm(new EditObjectController(_scene, _scene.Models[0])) {StartPosition = FormStartPosition.Manual, Location = Location + Size / 3}; + form.Closed += FormOnClosed; form.Show(); } + + private void FormOnClosed(object? sender, EventArgs e) + { + _isUiUsed = false; + UpdateLastModification(); + } } } \ No newline at end of file From e639c7043a5dd2916abf9bfb5858f73364da81b5 Mon Sep 17 00:00:00 2001 From: p-flis Date: Tue, 5 Jan 2021 15:10:07 +0100 Subject: [PATCH 02/31] init material with empty MasterMaterial --- RayTracer/Source/Models/Model.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RayTracer/Source/Models/Model.cs b/RayTracer/Source/Models/Model.cs index c5a832b..168bcf4 100644 --- a/RayTracer/Source/Models/Model.cs +++ b/RayTracer/Source/Models/Model.cs @@ -29,6 +29,11 @@ public virtual Vector3 Rotation protected virtual Matrix3 RotationMatrix { get; set; } = Matrix3.Identity; + public Model() + { + Material = new MasterMaterial(); + } + protected void UpdateRotationMatrix(Vector3 newRotation) { RotationMatrix = Matrix3.CreateRotationX(newRotation.X) * From 68ca993dd587d12e992962fcb27258fc400a6ae8 Mon Sep 17 00:00:00 2001 From: p-flis Date: Tue, 5 Jan 2021 15:55:24 +0100 Subject: [PATCH 03/31] init material with empty master material but not in triangle --- RayTracer/Source/Models/Cube.cs | 2 ++ RayTracer/Source/Models/Cylinder.cs | 2 ++ RayTracer/Source/Models/Model.cs | 5 ----- RayTracer/Source/Models/Sphere.cs | 5 +++++ 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/RayTracer/Source/Models/Cube.cs b/RayTracer/Source/Models/Cube.cs index d848f50..bc66050 100644 --- a/RayTracer/Source/Models/Cube.cs +++ b/RayTracer/Source/Models/Cube.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using OpenTK; +using RayTracing.Materials; using RayTracing.Maths; using RayTracing.RayTracing; @@ -11,6 +12,7 @@ public Cube() { var buffers = GetBuffers(); Mesh = new Mesh(buffers.vertexBuffer, buffers.normalBuffer, buffers.texBuffer, buffers.indicesBuffer); + Material = new MasterMaterial(); } private List GetVertices() diff --git a/RayTracer/Source/Models/Cylinder.cs b/RayTracer/Source/Models/Cylinder.cs index 1130f57..bdd91ad 100644 --- a/RayTracer/Source/Models/Cylinder.cs +++ b/RayTracer/Source/Models/Cylinder.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using OpenTK; +using RayTracing.Materials; using RayTracing.Maths; namespace RayTracing.Models @@ -21,6 +22,7 @@ public Cylinder(float aspect = 1.0f, int sectorCount = 100) { _sectorCount = sectorCount; Aspect = aspect; + Material = new MasterMaterial(); } public override Vector3 Rotation diff --git a/RayTracer/Source/Models/Model.cs b/RayTracer/Source/Models/Model.cs index bfe6d30..877ec44 100644 --- a/RayTracer/Source/Models/Model.cs +++ b/RayTracer/Source/Models/Model.cs @@ -29,11 +29,6 @@ public virtual Vector3 Rotation protected virtual Matrix3 RotationMatrix { get; set; } = Matrix3.Identity; - public Model() - { - Material = new MasterMaterial(); - } - protected void UpdateRotationMatrix(Vector3 newRotation) { RotationMatrix = Matrix3.CreateRotationX(newRotation.X) * diff --git a/RayTracer/Source/Models/Sphere.cs b/RayTracer/Source/Models/Sphere.cs index b99bd3d..2c51067 100644 --- a/RayTracer/Source/Models/Sphere.cs +++ b/RayTracer/Source/Models/Sphere.cs @@ -1,12 +1,17 @@ using System; using System.Collections.Generic; using OpenTK; +using RayTracing.Materials; using RayTracing.Maths; namespace RayTracing.Models { public class Sphere : Model { + public Sphere() + { + Material = new MasterMaterial(); + } private protected override void LoadInternal() { var (positions, texCoords) = GetVertexList(100, 100); From ca8a70450a42d84aeafd00990d82c90c8dba8b06 Mon Sep 17 00:00:00 2001 From: karolk98 <47919588+karolk98@users.noreply.github.com> Date: Tue, 5 Jan 2021 16:09:21 +0100 Subject: [PATCH 04/31] Fix plane texturing and readd bloom --- RayTracer/Source/Materials/Texture.cs | 15 ++++++++++++--- RayTracer/Source/Models/Plane.cs | 4 ++-- RayTracer/Source/Renderer/SamplesRayTracer.cs | 7 +++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/RayTracer/Source/Materials/Texture.cs b/RayTracer/Source/Materials/Texture.cs index 4016e9f..a3f45fe 100644 --- a/RayTracer/Source/Materials/Texture.cs +++ b/RayTracer/Source/Materials/Texture.cs @@ -51,7 +51,16 @@ public Texture(string path, bool glLoad = true) public Color this[float u, float v] { - get => _data[(int) (u * (Width - 1)), (int) (v * (Height - 1))]; + get + { + if (u < 0 || u > 1 || v < 0 || v > 1) + { + u -= (float) Math.Floor(u); + v -= (float) Math.Floor(v); + } + + return _data[(int) (u * (Width - 1)), (int) (v * (Height - 1))]; + } } public Color this[int w, int h] @@ -70,11 +79,11 @@ bool In(int x, int y) for (int i = -strength; i < strength; i++) for (int j = -strength; j < strength; j++) { - if (In(w + i, h + j)) + if (In(w + i, h + j) && i != 0 && j != 0) { int rs = i * i + j * j; if (rs <= strength * strength) - _data[w + i, h + j] += color / (10*strength * (rs + 1)); + _data[w + i, h + j] += color / (10 * strength * (rs + 1)); } } } diff --git a/RayTracer/Source/Models/Plane.cs b/RayTracer/Source/Models/Plane.cs index b05e7de..cbc4d18 100644 --- a/RayTracer/Source/Models/Plane.cs +++ b/RayTracer/Source/Models/Plane.cs @@ -122,8 +122,8 @@ public override bool HitTest(Ray ray, ref HitInfo hit, float from, float to) hit.SetNormal(ref ray, ref _normal); var hitVector = RotationMatrix * (hit.HitPoint - Position); hit.TexCoord = new Vector2( - hitVector.Z % Scale < 0 ? 1 + hitVector.Z % Scale : hitVector.Z % Scale, - 1 - (hitVector.X % Scale < 0 ? 1 + hitVector.X % Scale : hitVector.X % Scale)); + hitVector.Z / Scale, + (Scale - hitVector.X) / Scale); return true; } diff --git a/RayTracer/Source/Renderer/SamplesRayTracer.cs b/RayTracer/Source/Renderer/SamplesRayTracer.cs index c91e7ea..8a383fd 100644 --- a/RayTracer/Source/Renderer/SamplesRayTracer.cs +++ b/RayTracer/Source/Renderer/SamplesRayTracer.cs @@ -13,8 +13,9 @@ namespace RayTracing public class SamplesRayTracer : IncrementalRayTracer { private readonly int _samplesRenderStep; - - public SamplesRayTracer(int maxDepth, int samples, Func> sampling, int resolution, int samplesRenderStep) : base( + + public SamplesRayTracer(int maxDepth, int samples, Func> sampling, int resolution, + int samplesRenderStep) : base( maxDepth, samples, sampling, resolution) { _samplesRenderStep = samplesRenderStep; @@ -40,6 +41,8 @@ public override void Render(Scene scene, Camera camera) float u = (i + sample.X) / (width - 1); float v = (j + sample.Y) / (height - 1); Ray ray = camera.GetRay(u, v); + var shade = Shade(ray, scene, MaxDepth); + image.Bloom(shade, i, j, (int) shade.GetBrightness()); image[i, j] += Shade(ray, scene, MaxDepth); } }); From 300b3ca54888aac502a221352ea50a6510074749 Mon Sep 17 00:00:00 2001 From: p-flis Date: Tue, 5 Jan 2021 16:15:31 +0100 Subject: [PATCH 05/31] check tex coords --- RayTracer/Source/Models/Mesh.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/RayTracer/Source/Models/Mesh.cs b/RayTracer/Source/Models/Mesh.cs index 0840b2a..2b30b07 100644 --- a/RayTracer/Source/Models/Mesh.cs +++ b/RayTracer/Source/Models/Mesh.cs @@ -34,7 +34,10 @@ public void Load() GL.BindVertexArray(vaoId); LoadDataBuffer(Positions, POSITIONS_INDEX, 3); LoadDataBuffer(Normals, NORMALS_INDEX, 3); - LoadDataBuffer(TexCoords, TEX_COORDS_INDEX, 2); + if (TexCoords != null && TexCoords.Count > 0) + { + LoadDataBuffer(TexCoords, TEX_COORDS_INDEX, 2); + } LoadIndexBuffer(Indices); } @@ -114,9 +117,13 @@ public Vector3 GetNormal(int index) public Vector2 GetTexCoord(int index) { - float vx = TexCoords[2 * Indices[index] + 0]; - float vy = TexCoords[2 * Indices[index] + 1]; - return new Vector2(vx, vy); + if (TexCoords != null && TexCoords.Count > 2 * Indices[index] + 1) + { + float vx = TexCoords[2 * Indices[index] + 0]; + float vy = TexCoords[2 * Indices[index] + 1]; + return new Vector2(vx, vy); + } + return new Vector2(); } } } \ No newline at end of file From 5f25d56a6238573ae6cfaa511be661b6aae0a109 Mon Sep 17 00:00:00 2001 From: karolk98 <47919588+karolk98@users.noreply.github.com> Date: Tue, 5 Jan 2021 16:43:05 +0100 Subject: [PATCH 06/31] Review fixes --- RayTracer/Source/Renderer/SamplesRayTracer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RayTracer/Source/Renderer/SamplesRayTracer.cs b/RayTracer/Source/Renderer/SamplesRayTracer.cs index 8a383fd..95cbf24 100644 --- a/RayTracer/Source/Renderer/SamplesRayTracer.cs +++ b/RayTracer/Source/Renderer/SamplesRayTracer.cs @@ -43,7 +43,7 @@ public override void Render(Scene scene, Camera camera) Ray ray = camera.GetRay(u, v); var shade = Shade(ray, scene, MaxDepth); image.Bloom(shade, i, j, (int) shade.GetBrightness()); - image[i, j] += Shade(ray, scene, MaxDepth); + image[i, j] += shade; } }); if (IsCancellationRequested != null && IsCancellationRequested()) From c990f458d89f276d576ad5beb0625296454d73da Mon Sep 17 00:00:00 2001 From: Tomasz Herman Date: Tue, 5 Jan 2021 22:44:17 +0000 Subject: [PATCH 07/31] Merge all meshes into one if model contains many --- RayTracer/Source/Models/Mesh.cs | 10 ++++++++++ RayTracer/Source/Models/ModelLoader.cs | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/RayTracer/Source/Models/Mesh.cs b/RayTracer/Source/Models/Mesh.cs index 0840b2a..5922e6a 100644 --- a/RayTracer/Source/Models/Mesh.cs +++ b/RayTracer/Source/Models/Mesh.cs @@ -118,5 +118,15 @@ public Vector2 GetTexCoord(int index) float vy = TexCoords[2 * Indices[index] + 1]; return new Vector2(vx, vy); } + + public static Mesh operator +(Mesh first, Mesh second) + { + first.Positions.AddRange(second.Positions); + first.Normals.AddRange(second.Normals); + first.TexCoords.AddRange(second.TexCoords); + int indexOffset = first.Positions.Count / 3; + first.Indices.AddRange(second.Indices.ConvertAll(index => index + indexOffset)); + return first; + } } } \ No newline at end of file diff --git a/RayTracer/Source/Models/ModelLoader.cs b/RayTracer/Source/Models/ModelLoader.cs index b9e971c..92dc126 100644 --- a/RayTracer/Source/Models/ModelLoader.cs +++ b/RayTracer/Source/Models/ModelLoader.cs @@ -58,7 +58,12 @@ public static CustomModel Load(string path, PostProcessSteps ppSteps, params Pro Log.Warn($"Model {path} containing more than one mesh. Using first mesh."); } - var mesh = ProcessMesh(scene.Meshes[0]); + var mesh = new Mesh(new List(), new List(), new List(), new List()); + for (int i = 0; i < scene.MeshCount; i++) + { + mesh += ProcessMesh(scene.Meshes[i]); + } + var material = ProcessMaterial(scene.Materials[scene.Meshes[0].MaterialIndex], Path.GetDirectoryName(Path.GetFullPath(path))); model.SetMesh(mesh); From 547ba9888350d5e0d1a5c8d3ddfe2b01d7f326ee Mon Sep 17 00:00:00 2001 From: p-flis Date: Wed, 6 Jan 2021 02:03:51 +0100 Subject: [PATCH 08/31] a lot of ui --- RayTracer/Source/Lights/AmbientLight.cs | 2 +- RayTracer/Source/Materials/MasterMaterial.cs | 4 + RayTracer/Source/Materials/Texture.cs | 7 + RayTracer/Source/Maths/Color.cs | 16 + RayTracer/Source/Models/Model.cs | 2 +- RayTracer/Source/Models/Plane.cs | 6 + RayTracer/Source/Models/Rectangle.cs | 11 + RayTracer/Source/Models/Triangle.cs | 4 +- .../CustomModelFeatureControl.Designer.cs | 74 -- .../Controls/FeaturesPanel.Designer.cs | 60 -- RayTracerApp/Controls/FeaturesPanel.cs | 54 -- RayTracerApp/Controls/IPanel.cs | 12 - .../Controls/MaterialPanel.Designer.cs | 327 ------- RayTracerApp/Controls/MaterialPanel.cs | 34 - .../Controls/NewModelPanel.Designer.cs | 115 --- RayTracerApp/Controls/NewModelPanel.cs | 61 -- .../Controls/PositionPanel.Designer.cs | 389 -------- RayTracerApp/Controls/PositionPanel.cs | 99 -- .../{Menu => }/EditObjectForm.Designer.cs | 46 +- RayTracerApp/Forms/EditObjectForm.cs | 138 +++ .../Forms/{Menu => }/EditObjectForm.resx | 0 RayTracerApp/Forms/MainForm.Designer.cs | 180 ++-- RayTracerApp/Forms/MainForm.cs | 43 +- RayTracerApp/Forms/Menu/EditObjectForm.cs | 130 --- .../Forms/Menu/EditorForm.Designer.cs | 155 ---- RayTracerApp/Forms/Menu/EditorForm.cs | 12 - .../Forms/Menu/NewObjectForm.Designer.cs | 100 -- RayTracerApp/Forms/Menu/NewObjectForm.cs | 140 --- RayTracerApp/Forms/Menu/NewObjectForm.resx | 60 -- RayTracerApp/Forms/NewObjectForm.Designer.cs | 108 +++ RayTracerApp/Forms/NewObjectForm.cs | 139 +++ .../NewObjectForm.resx} | 0 RayTracerApp/Forms/ObjectForm.Designer.cs | 128 +++ RayTracerApp/Forms/ObjectForm.cs | 18 + .../ObjectForm.resx} | 0 RayTracerApp/Panels/FeaturesPanel.Designer.cs | 146 +++ .../FeaturesPanel.cs} | 75 +- .../FeaturesPanel.resx} | 0 RayTracerApp/Panels/IPanelBase.cs | 23 + RayTracerApp/Panels/MaterialPanel.Designer.cs | 870 ++++++++++++++++++ RayTracerApp/Panels/MaterialPanel.cs | 206 +++++ .../MaterialPanel.resx} | 0 .../Panels/ObjectSelectionPanel.Designer.cs | 154 ++++ RayTracerApp/Panels/ObjectSelectionPanel.cs | 65 ++ .../ObjectSelectionPanel.resx} | 118 +-- RayTracerApp/Panels/PositionPanel.Designer.cs | 442 +++++++++ RayTracerApp/Panels/PositionPanel.cs | 93 ++ .../{Controls => Panels}/PositionPanel.resx | 118 +-- RayTracerApp/RayTracerApp.csproj | 10 - .../SceneController/IObjectController.cs | 20 + .../SceneController/ObjectController.cs | 62 ++ .../SceneControllers/EditObjectController.cs | 17 - RayTracerApp/SceneControllers/IController.cs | 14 - .../SceneControllers/NewObjectController.cs | 16 - .../SceneControllers/ObjectController.cs | 38 - 55 files changed, 2976 insertions(+), 2185 deletions(-) delete mode 100644 RayTracerApp/Controls/Features/CustomModelFeatureControl.Designer.cs delete mode 100644 RayTracerApp/Controls/FeaturesPanel.Designer.cs delete mode 100644 RayTracerApp/Controls/FeaturesPanel.cs delete mode 100644 RayTracerApp/Controls/IPanel.cs delete mode 100644 RayTracerApp/Controls/MaterialPanel.Designer.cs delete mode 100644 RayTracerApp/Controls/MaterialPanel.cs delete mode 100644 RayTracerApp/Controls/NewModelPanel.Designer.cs delete mode 100644 RayTracerApp/Controls/NewModelPanel.cs delete mode 100644 RayTracerApp/Controls/PositionPanel.Designer.cs delete mode 100644 RayTracerApp/Controls/PositionPanel.cs rename RayTracerApp/Forms/{Menu => }/EditObjectForm.Designer.cs (60%) create mode 100644 RayTracerApp/Forms/EditObjectForm.cs rename RayTracerApp/Forms/{Menu => }/EditObjectForm.resx (100%) delete mode 100644 RayTracerApp/Forms/Menu/EditObjectForm.cs delete mode 100644 RayTracerApp/Forms/Menu/EditorForm.Designer.cs delete mode 100644 RayTracerApp/Forms/Menu/EditorForm.cs delete mode 100644 RayTracerApp/Forms/Menu/NewObjectForm.Designer.cs delete mode 100644 RayTracerApp/Forms/Menu/NewObjectForm.cs delete mode 100644 RayTracerApp/Forms/Menu/NewObjectForm.resx create mode 100644 RayTracerApp/Forms/NewObjectForm.Designer.cs create mode 100644 RayTracerApp/Forms/NewObjectForm.cs rename RayTracerApp/{Controls/Features/CustomModelFeatureControl.resx => Forms/NewObjectForm.resx} (100%) create mode 100644 RayTracerApp/Forms/ObjectForm.Designer.cs create mode 100644 RayTracerApp/Forms/ObjectForm.cs rename RayTracerApp/{Controls/MaterialPanel.resx => Forms/ObjectForm.resx} (100%) create mode 100644 RayTracerApp/Panels/FeaturesPanel.Designer.cs rename RayTracerApp/{Controls/Features/CustomModelFeatureControl.cs => Panels/FeaturesPanel.cs} (50%) rename RayTracerApp/{Controls/NewModelPanel.resx => Panels/FeaturesPanel.resx} (100%) create mode 100644 RayTracerApp/Panels/IPanelBase.cs create mode 100644 RayTracerApp/Panels/MaterialPanel.Designer.cs create mode 100644 RayTracerApp/Panels/MaterialPanel.cs rename RayTracerApp/{Forms/Menu/EditorForm.resx => Panels/MaterialPanel.resx} (100%) create mode 100644 RayTracerApp/Panels/ObjectSelectionPanel.Designer.cs create mode 100644 RayTracerApp/Panels/ObjectSelectionPanel.cs rename RayTracerApp/{Controls/FeaturesPanel.resx => Panels/ObjectSelectionPanel.resx} (97%) create mode 100644 RayTracerApp/Panels/PositionPanel.Designer.cs create mode 100644 RayTracerApp/Panels/PositionPanel.cs rename RayTracerApp/{Controls => Panels}/PositionPanel.resx (97%) create mode 100644 RayTracerApp/SceneController/IObjectController.cs create mode 100644 RayTracerApp/SceneController/ObjectController.cs delete mode 100644 RayTracerApp/SceneControllers/EditObjectController.cs delete mode 100644 RayTracerApp/SceneControllers/IController.cs delete mode 100644 RayTracerApp/SceneControllers/NewObjectController.cs delete mode 100644 RayTracerApp/SceneControllers/ObjectController.cs diff --git a/RayTracer/Source/Lights/AmbientLight.cs b/RayTracer/Source/Lights/AmbientLight.cs index 12daa93..5f7bbbc 100644 --- a/RayTracer/Source/Lights/AmbientLight.cs +++ b/RayTracer/Source/Lights/AmbientLight.cs @@ -2,7 +2,7 @@ namespace RayTracing.Lights { - public struct AmbientLight + public class AmbientLight { public Color Color; } diff --git a/RayTracer/Source/Materials/MasterMaterial.cs b/RayTracer/Source/Materials/MasterMaterial.cs index 9cd4a11..fb09bdc 100644 --- a/RayTracer/Source/Materials/MasterMaterial.cs +++ b/RayTracer/Source/Materials/MasterMaterial.cs @@ -97,6 +97,10 @@ private ThreadSafeSampler NewSampler() public bool Scatter(ref Ray ray, ref HitInfo hit, out Color attenuation, out Ray scattered) { + if (Parts.reflective == 0.69f) + { + var a = 2; + } return _materials[_sampler.Sample].Scatter(ref ray, ref hit, out attenuation, out scattered); } diff --git a/RayTracer/Source/Materials/Texture.cs b/RayTracer/Source/Materials/Texture.cs index 4016e9f..41e39c3 100644 --- a/RayTracer/Source/Materials/Texture.cs +++ b/RayTracer/Source/Materials/Texture.cs @@ -79,6 +79,13 @@ bool In(int x, int y) } } + public static Texture operator *(Texture texture, float multiplier) + { + var res = new Texture(texture); + res.Process(color => color * multiplier); + return res; + } + public void Process(Func function) { for (int i = 0; i < Width; i++) diff --git a/RayTracer/Source/Maths/Color.cs b/RayTracer/Source/Maths/Color.cs index 3f4dfb5..32250c2 100644 --- a/RayTracer/Source/Maths/Color.cs +++ b/RayTracer/Source/Maths/Color.cs @@ -3,6 +3,7 @@ using Assimp; using OpenTK; using OpenTK.Graphics; +using System.Drawing; namespace RayTracing.Maths { @@ -44,6 +45,21 @@ public static Color FromAssimpColor4(Color4D color4) }; } + public static Color FromSystemDrawing(System.Drawing.Color color) + { + return new Color + { + R = color.R/256f, + G = color.G/256f, + B = color.B/256f + }; + } + + public System.Drawing.Color ToSystemDrawing() + { + return System.Drawing.Color.FromArgb(RComp, GComp, BComp); + } + public static Color operator +(Color first, Color second) { first.R += second.R; diff --git a/RayTracer/Source/Models/Model.cs b/RayTracer/Source/Models/Model.cs index 877ec44..7f37ee6 100644 --- a/RayTracer/Source/Models/Model.cs +++ b/RayTracer/Source/Models/Model.cs @@ -82,7 +82,7 @@ public List MeshToTriangles() v1 = (new Vector4(v1, 1.0f) * modelMatrix).Xyz; v2 = (new Vector4(v2, 1.0f) * modelMatrix).Xyz; v3 = (new Vector4(v3, 1.0f) * modelMatrix).Xyz; - Triangle t = new Triangle(v1, v2, v3, tc1, tc2, tc3); + Triangle t = new Triangle(this, v1, v2, v3, tc1, tc2, tc3); t.Material = Material; hittables.Add(t); } diff --git a/RayTracer/Source/Models/Plane.cs b/RayTracer/Source/Models/Plane.cs index b05e7de..690af4b 100644 --- a/RayTracer/Source/Models/Plane.cs +++ b/RayTracer/Source/Models/Plane.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using OpenTK; +using RayTracing.Materials; using RayTracing.Maths; namespace RayTracing.Models @@ -19,6 +20,11 @@ public override Vector3 Rotation } } + public Plane() + { + Material = new MasterMaterial(); + } + private protected override void LoadInternal() { var buffers = GetBuffers(); diff --git a/RayTracer/Source/Models/Rectangle.cs b/RayTracer/Source/Models/Rectangle.cs index a271433..1d0636a 100644 --- a/RayTracer/Source/Models/Rectangle.cs +++ b/RayTracer/Source/Models/Rectangle.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using OpenTK; +using RayTracing.Materials; using RayTracing.Maths; using RayTracing.RayTracing; @@ -8,10 +9,20 @@ namespace RayTracing.Models public class Rectangle : Model { private float _aspectRatio = 1; + public float AspectRatio + { + get => _aspectRatio; + set + { + _aspectRatio = value; + LoadInternal(); + } + } public Rectangle(float aspect) { _aspectRatio = aspect; + Material = new MasterMaterial(); } private protected override void LoadInternal() diff --git a/RayTracer/Source/Models/Triangle.cs b/RayTracer/Source/Models/Triangle.cs index 87a7f3a..06287e2 100644 --- a/RayTracer/Source/Models/Triangle.cs +++ b/RayTracer/Source/Models/Triangle.cs @@ -10,10 +10,12 @@ public class Triangle : Model private List _vertices; private List _texCoords; private Vector3 _normal; + public readonly Model Parent; - public Triangle(Vector3 v1, Vector3 v2, Vector3 v3, Vector2 tc1 = new Vector2(), Vector2 tc2 = new Vector2(), + public Triangle(Model parent, Vector3 v1, Vector3 v2, Vector3 v3, Vector2 tc1 = new Vector2(), Vector2 tc2 = new Vector2(), Vector2 tc3 = new Vector2()) { + Parent = parent; _vertices = new List {v1, v2, v3}; var a = _vertices[1] - _vertices[0]; var b = _vertices[2] - _vertices[0]; diff --git a/RayTracerApp/Controls/Features/CustomModelFeatureControl.Designer.cs b/RayTracerApp/Controls/Features/CustomModelFeatureControl.Designer.cs deleted file mode 100644 index 561ee23..0000000 --- a/RayTracerApp/Controls/Features/CustomModelFeatureControl.Designer.cs +++ /dev/null @@ -1,74 +0,0 @@ - -namespace RayTracerApp.Controls.Features -{ - partial class CustomModelFeatureControl - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Component Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.loadFromFileButton = new System.Windows.Forms.Button(); - this.loadFromFileLabel = new System.Windows.Forms.Label(); - this.SuspendLayout(); - // - // loadFromFileButton - // - this.loadFromFileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.loadFromFileButton.Location = new System.Drawing.Point(171, 28); - this.loadFromFileButton.Name = "loadFromFileButton"; - this.loadFromFileButton.Size = new System.Drawing.Size(44, 23); - this.loadFromFileButton.TabIndex = 0; - this.loadFromFileButton.Text = "..."; - this.loadFromFileButton.UseVisualStyleBackColor = true; - this.loadFromFileButton.Click += new System.EventHandler(this.loadFromFileButton_Click); - // - // loadFromFileLabel - // - this.loadFromFileLabel.AutoSize = true; - this.loadFromFileLabel.Location = new System.Drawing.Point(17, 32); - this.loadFromFileLabel.Name = "loadFromFileLabel"; - this.loadFromFileLabel.Size = new System.Drawing.Size(63, 15); - this.loadFromFileLabel.TabIndex = 1; - this.loadFromFileLabel.Text = "From file..."; - // - // CustomModelControl - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.loadFromFileLabel); - this.Controls.Add(this.loadFromFileButton); - this.Name = "CustomModelControl"; - this.Size = new System.Drawing.Size(230, 268); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.Button loadFromFileButton; - private System.Windows.Forms.Label loadFromFileLabel; - } -} diff --git a/RayTracerApp/Controls/FeaturesPanel.Designer.cs b/RayTracerApp/Controls/FeaturesPanel.Designer.cs deleted file mode 100644 index d0a9fc0..0000000 --- a/RayTracerApp/Controls/FeaturesPanel.Designer.cs +++ /dev/null @@ -1,60 +0,0 @@ - -namespace RayTracerApp.Controls -{ - partial class FeaturesPanel - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Component Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.customModelFeatureControl = new RayTracerApp.Controls.Features.CustomModelFeatureControl(); - this.SuspendLayout(); - // - // customModelFeatureControl - // - this.customModelFeatureControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.customModelFeatureControl.Location = new System.Drawing.Point(0, 0); - this.customModelFeatureControl.Name = "customModelFeatureControl"; - this.customModelFeatureControl.Size = new System.Drawing.Size(212, 266); - this.customModelFeatureControl.TabIndex = 0; - // - // FeaturesPanel - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.customModelFeatureControl); - this.Name = "FeaturesPanel"; - this.Size = new System.Drawing.Size(215, 294); - this.ResumeLayout(false); - - } - - #endregion - - private Features.CustomModelFeatureControl customModelFeatureControl; - } -} diff --git a/RayTracerApp/Controls/FeaturesPanel.cs b/RayTracerApp/Controls/FeaturesPanel.cs deleted file mode 100644 index 4d5e7f8..0000000 --- a/RayTracerApp/Controls/FeaturesPanel.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Windows.Forms; -using RayTracerApp.SceneControllers; -using RayTracing.Models; - -namespace RayTracerApp.Controls -{ - public partial class FeaturesPanel : UserControl, IPanel - { - private IController _controller; - - public FeaturesPanel() - { - InitializeComponent(); - } - - public void SetController(IController controller) - { - _controller = controller; - } - - public void UpdateForModel() - { - var model = _controller.GetModel(); - HideFeaturesControls(); - ShowProperControl(model); - } - - public void ShowPanel() - { - Visible = true; - } - - public void HidePanel() - { - Visible = false; - } - - private void HideFeaturesControls() - { - customModelFeatureControl.Visible = false; - } - - private void ShowProperControl(Model model) - { - switch (model) - { - case CustomModel customModel: - customModelFeatureControl.Visible = true; - customModelFeatureControl.SetController(_controller); - break; - } - } - } -} \ No newline at end of file diff --git a/RayTracerApp/Controls/IPanel.cs b/RayTracerApp/Controls/IPanel.cs deleted file mode 100644 index 3ac9c42..0000000 --- a/RayTracerApp/Controls/IPanel.cs +++ /dev/null @@ -1,12 +0,0 @@ -using RayTracerApp.SceneControllers; - -namespace RayTracerApp.Controls -{ - internal interface IPanel - { - void UpdateForModel(); - void SetController(IController controller); - void ShowPanel(); - void HidePanel(); - } -} \ No newline at end of file diff --git a/RayTracerApp/Controls/MaterialPanel.Designer.cs b/RayTracerApp/Controls/MaterialPanel.Designer.cs deleted file mode 100644 index ff6d688..0000000 --- a/RayTracerApp/Controls/MaterialPanel.Designer.cs +++ /dev/null @@ -1,327 +0,0 @@ -using System.ComponentModel; - -namespace RayTracerApp.Controls -{ - partial class MaterialPanel - { - /// - /// Required designer variable. - /// - private IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - - base.Dispose(disposing); - } - - #region Component Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.separator1 = new System.Windows.Forms.Label(); - this.textureLabel = new System.Windows.Forms.Label(); - this.textureEnableCheckBox = new System.Windows.Forms.CheckBox(); - this.pathToTextureLabel = new System.Windows.Forms.Label(); - this.chooseTextureButton = new System.Windows.Forms.Button(); - this.ambientLabel = new System.Windows.Forms.Label(); - this.ambientButton = new System.Windows.Forms.Button(); - this.diffuseButton = new System.Windows.Forms.Button(); - this.diffuseLabel = new System.Windows.Forms.Label(); - this.specularButton = new System.Windows.Forms.Button(); - this.specularLabel = new System.Windows.Forms.Label(); - this.specularExpTrackBar = new System.Windows.Forms.TrackBar(); - this.specularExpLabel = new System.Windows.Forms.Label(); - this.separator2 = new System.Windows.Forms.Label(); - this.emissiveLabel = new System.Windows.Forms.Label(); - this.reflectiveLabel = new System.Windows.Forms.Label(); - this.refractiveLabel = new System.Windows.Forms.Label(); - this.refractiveIndexLabel = new System.Windows.Forms.Label(); - this.emissiveButton = new System.Windows.Forms.Button(); - this.trackBar1 = new System.Windows.Forms.TrackBar(); - this.trackBar2 = new System.Windows.Forms.TrackBar(); - this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); - ((System.ComponentModel.ISupportInitialize)(this.specularExpTrackBar)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.trackBar2)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); - this.SuspendLayout(); - // - // separator1 - // - this.separator1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.separator1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; - this.separator1.Location = new System.Drawing.Point(0, 58); - this.separator1.Name = "separator1"; - this.separator1.Size = new System.Drawing.Size(295, 2); - this.separator1.TabIndex = 0; - // - // textureLabel - // - this.textureLabel.AutoSize = true; - this.textureLabel.Location = new System.Drawing.Point(0, 9); - this.textureLabel.Name = "textureLabel"; - this.textureLabel.Size = new System.Drawing.Size(48, 15); - this.textureLabel.TabIndex = 1; - this.textureLabel.Text = "Texture:"; - // - // textureEnableCheckBox - // - this.textureEnableCheckBox.AutoSize = true; - this.textureEnableCheckBox.Location = new System.Drawing.Point(9, 36); - this.textureEnableCheckBox.Name = "textureEnableCheckBox"; - this.textureEnableCheckBox.Size = new System.Drawing.Size(61, 19); - this.textureEnableCheckBox.TabIndex = 2; - this.textureEnableCheckBox.Text = "Enable"; - this.textureEnableCheckBox.UseVisualStyleBackColor = true; - // - // pathToTextureLabel - // - this.pathToTextureLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.pathToTextureLabel.AutoSize = true; - this.pathToTextureLabel.Location = new System.Drawing.Point(155, 37); - this.pathToTextureLabel.Name = "pathToTextureLabel"; - this.pathToTextureLabel.Size = new System.Drawing.Size(89, 15); - this.pathToTextureLabel.TabIndex = 3; - this.pathToTextureLabel.Text = "path/to/texture"; - // - // chooseTextureButton - // - this.chooseTextureButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.chooseTextureButton.Location = new System.Drawing.Point(250, 33); - this.chooseTextureButton.Name = "chooseTextureButton"; - this.chooseTextureButton.Size = new System.Drawing.Size(29, 23); - this.chooseTextureButton.TabIndex = 4; - this.chooseTextureButton.Text = "..."; - this.chooseTextureButton.UseVisualStyleBackColor = true; - // - // ambientLabel - // - this.ambientLabel.AutoSize = true; - this.ambientLabel.Location = new System.Drawing.Point(9, 71); - this.ambientLabel.Name = "ambientLabel"; - this.ambientLabel.Size = new System.Drawing.Size(56, 15); - this.ambientLabel.TabIndex = 5; - this.ambientLabel.Text = "Ambient:"; - // - // ambientButton - // - this.ambientButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ambientButton.Location = new System.Drawing.Point(155, 67); - this.ambientButton.Name = "ambientButton"; - this.ambientButton.Size = new System.Drawing.Size(124, 23); - this.ambientButton.TabIndex = 6; - this.ambientButton.Text = "button1"; - this.ambientButton.UseVisualStyleBackColor = true; - // - // diffuseButton - // - this.diffuseButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.diffuseButton.Location = new System.Drawing.Point(155, 94); - this.diffuseButton.Name = "diffuseButton"; - this.diffuseButton.Size = new System.Drawing.Size(124, 23); - this.diffuseButton.TabIndex = 8; - this.diffuseButton.Text = "button1"; - this.diffuseButton.UseVisualStyleBackColor = true; - // - // diffuseLabel - // - this.diffuseLabel.AutoSize = true; - this.diffuseLabel.Location = new System.Drawing.Point(9, 98); - this.diffuseLabel.Name = "diffuseLabel"; - this.diffuseLabel.Size = new System.Drawing.Size(47, 15); - this.diffuseLabel.TabIndex = 7; - this.diffuseLabel.Text = "Diffuse:"; - // - // specularButton - // - this.specularButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.specularButton.Location = new System.Drawing.Point(155, 123); - this.specularButton.Name = "specularButton"; - this.specularButton.Size = new System.Drawing.Size(124, 23); - this.specularButton.TabIndex = 10; - this.specularButton.Text = "button1"; - this.specularButton.UseVisualStyleBackColor = true; - // - // specularLabel - // - this.specularLabel.AutoSize = true; - this.specularLabel.Location = new System.Drawing.Point(9, 127); - this.specularLabel.Name = "specularLabel"; - this.specularLabel.Size = new System.Drawing.Size(55, 15); - this.specularLabel.TabIndex = 9; - this.specularLabel.Text = "Specular:"; - // - // specularExpTrackBar - // - this.specularExpTrackBar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.specularExpTrackBar.Location = new System.Drawing.Point(155, 152); - this.specularExpTrackBar.Name = "specularExpTrackBar"; - this.specularExpTrackBar.Size = new System.Drawing.Size(124, 45); - this.specularExpTrackBar.TabIndex = 11; - // - // specularExpLabel - // - this.specularExpLabel.AutoSize = true; - this.specularExpLabel.Location = new System.Drawing.Point(10, 152); - this.specularExpLabel.Name = "specularExpLabel"; - this.specularExpLabel.Size = new System.Drawing.Size(108, 15); - this.specularExpLabel.TabIndex = 12; - this.specularExpLabel.Text = "Specular exponent:"; - // - // separator2 - // - this.separator2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.separator2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; - this.separator2.Location = new System.Drawing.Point(0, 191); - this.separator2.Name = "separator2"; - this.separator2.Size = new System.Drawing.Size(295, 2); - this.separator2.TabIndex = 13; - // - // emissiveLabel - // - this.emissiveLabel.AutoSize = true; - this.emissiveLabel.Location = new System.Drawing.Point(10, 211); - this.emissiveLabel.Name = "emissiveLabel"; - this.emissiveLabel.Size = new System.Drawing.Size(55, 15); - this.emissiveLabel.TabIndex = 14; - this.emissiveLabel.Text = "Emissive:"; - // - // reflectiveLabel - // - this.reflectiveLabel.AutoSize = true; - this.reflectiveLabel.Location = new System.Drawing.Point(9, 239); - this.reflectiveLabel.Name = "reflectiveLabel"; - this.reflectiveLabel.Size = new System.Drawing.Size(61, 15); - this.reflectiveLabel.TabIndex = 15; - this.reflectiveLabel.Text = "Reflective:"; - // - // refractiveLabel - // - this.refractiveLabel.AutoSize = true; - this.refractiveLabel.Location = new System.Drawing.Point(8, 269); - this.refractiveLabel.Name = "refractiveLabel"; - this.refractiveLabel.Size = new System.Drawing.Size(62, 15); - this.refractiveLabel.TabIndex = 16; - this.refractiveLabel.Text = "Refractive:"; - // - // refractiveIndexLabel - // - this.refractiveIndexLabel.AutoSize = true; - this.refractiveIndexLabel.Location = new System.Drawing.Point(10, 303); - this.refractiveIndexLabel.Name = "refractiveIndexLabel"; - this.refractiveIndexLabel.Size = new System.Drawing.Size(94, 15); - this.refractiveIndexLabel.TabIndex = 17; - this.refractiveIndexLabel.Text = "Refractive index:"; - // - // emissiveButton - // - this.emissiveButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.emissiveButton.Location = new System.Drawing.Point(155, 211); - this.emissiveButton.Name = "emissiveButton"; - this.emissiveButton.Size = new System.Drawing.Size(124, 23); - this.emissiveButton.TabIndex = 18; - this.emissiveButton.Text = "button1"; - this.emissiveButton.UseVisualStyleBackColor = true; - // - // trackBar1 - // - this.trackBar1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.trackBar1.Location = new System.Drawing.Point(155, 239); - this.trackBar1.Name = "trackBar1"; - this.trackBar1.Size = new System.Drawing.Size(124, 45); - this.trackBar1.TabIndex = 19; - // - // trackBar2 - // - this.trackBar2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.trackBar2.Location = new System.Drawing.Point(155, 269); - this.trackBar2.Name = "trackBar2"; - this.trackBar2.Size = new System.Drawing.Size(124, 45); - this.trackBar2.TabIndex = 20; - // - // numericUpDown1 - // - this.numericUpDown1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.numericUpDown1.Location = new System.Drawing.Point(206, 301); - this.numericUpDown1.Name = "numericUpDown1"; - this.numericUpDown1.Size = new System.Drawing.Size(73, 23); - this.numericUpDown1.TabIndex = 21; - // - // MaterialPanel - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.numericUpDown1); - this.Controls.Add(this.trackBar2); - this.Controls.Add(this.trackBar1); - this.Controls.Add(this.emissiveButton); - this.Controls.Add(this.refractiveIndexLabel); - this.Controls.Add(this.refractiveLabel); - this.Controls.Add(this.reflectiveLabel); - this.Controls.Add(this.emissiveLabel); - this.Controls.Add(this.separator2); - this.Controls.Add(this.specularExpLabel); - this.Controls.Add(this.specularExpTrackBar); - this.Controls.Add(this.specularButton); - this.Controls.Add(this.specularLabel); - this.Controls.Add(this.diffuseButton); - this.Controls.Add(this.diffuseLabel); - this.Controls.Add(this.ambientButton); - this.Controls.Add(this.ambientLabel); - this.Controls.Add(this.chooseTextureButton); - this.Controls.Add(this.pathToTextureLabel); - this.Controls.Add(this.textureEnableCheckBox); - this.Controls.Add(this.textureLabel); - this.Controls.Add(this.separator1); - this.Name = "MaterialPanel"; - this.Size = new System.Drawing.Size(294, 385); - ((System.ComponentModel.ISupportInitialize)(this.specularExpTrackBar)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.trackBar2)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.Label separator1; - private System.Windows.Forms.Label textureLabel; - private System.Windows.Forms.CheckBox textureEnableCheckBox; - private System.Windows.Forms.Label pathToTextureLabel; - private System.Windows.Forms.Button chooseTextureButton; - private System.Windows.Forms.Label ambientLabel; - private System.Windows.Forms.Button ambientButton; - private System.Windows.Forms.Button diffuseButton; - private System.Windows.Forms.Label diffuseLabel; - private System.Windows.Forms.Button specularButton; - private System.Windows.Forms.Label specularLabel; - private System.Windows.Forms.TrackBar specularExpTrackBar; - private System.Windows.Forms.Label specularExpLabel; - private System.Windows.Forms.Label separator2; - private System.Windows.Forms.Label emissiveLabel; - private System.Windows.Forms.Label reflectiveLabel; - private System.Windows.Forms.Label refractiveLabel; - private System.Windows.Forms.Label refractiveIndexLabel; - private System.Windows.Forms.Button emissiveButton; - private System.Windows.Forms.TrackBar trackBar1; - private System.Windows.Forms.TrackBar trackBar2; - private System.Windows.Forms.NumericUpDown numericUpDown1; - } -} \ No newline at end of file diff --git a/RayTracerApp/Controls/MaterialPanel.cs b/RayTracerApp/Controls/MaterialPanel.cs deleted file mode 100644 index 7af22fd..0000000 --- a/RayTracerApp/Controls/MaterialPanel.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Windows.Forms; -using RayTracerApp.SceneControllers; - -namespace RayTracerApp.Controls -{ - public partial class MaterialPanel : UserControl, IPanel - { - private IController _controller; - - public MaterialPanel() - { - InitializeComponent(); - } - - public void SetController(IController controller) - { - _controller = controller; - } - - public void UpdateForModel() - { - } - - public void ShowPanel() - { - Visible = true; - } - - public void HidePanel() - { - Visible = false; - } - } -} \ No newline at end of file diff --git a/RayTracerApp/Controls/NewModelPanel.Designer.cs b/RayTracerApp/Controls/NewModelPanel.Designer.cs deleted file mode 100644 index 238cbd9..0000000 --- a/RayTracerApp/Controls/NewModelPanel.Designer.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System.ComponentModel; -using System.Drawing; -using System.Windows.Forms; - -namespace RayTracerApp.Controls -{ - partial class NewModelPanel - { - /// - /// Required designer variable. - /// - private IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - - base.Dispose(disposing); - } - - #region Component Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.NewModelBox = new System.Windows.Forms.GroupBox(); - this.ModelButton = new System.Windows.Forms.RadioButton(); - this.SphereButton = new System.Windows.Forms.RadioButton(); - this.CubeButton = new System.Windows.Forms.RadioButton(); - this.NewModelBox.SuspendLayout(); - this.SuspendLayout(); - // - // NewModelBox - // - this.NewModelBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.NewModelBox.Controls.Add(this.ModelButton); - this.NewModelBox.Controls.Add(this.SphereButton); - this.NewModelBox.Controls.Add(this.CubeButton); - this.NewModelBox.Location = new System.Drawing.Point(0, 0); - this.NewModelBox.Name = "NewModelBox"; - this.NewModelBox.Size = new System.Drawing.Size(233, 152); - this.NewModelBox.TabIndex = 0; - this.NewModelBox.TabStop = false; - // - // ModelButton - // - this.ModelButton.AutoSize = true; - this.ModelButton.Location = new System.Drawing.Point(6, 69); - this.ModelButton.Name = "ModelButton"; - this.ModelButton.Size = new System.Drawing.Size(104, 19); - this.ModelButton.TabIndex = 2; - this.ModelButton.TabStop = true; - this.ModelButton.Text = "Custom model"; - this.ModelButton.UseVisualStyleBackColor = true; - this.ModelButton.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged); - // - // SphereButton - // - this.SphereButton.AutoSize = true; - this.SphereButton.Location = new System.Drawing.Point(6, 44); - this.SphereButton.Name = "SphereButton"; - this.SphereButton.Size = new System.Drawing.Size(61, 19); - this.SphereButton.TabIndex = 1; - this.SphereButton.TabStop = true; - this.SphereButton.Text = "Sphere"; - this.SphereButton.UseVisualStyleBackColor = true; - this.SphereButton.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged); - // - // CubeButton - // - this.CubeButton.AutoSize = true; - this.CubeButton.Location = new System.Drawing.Point(6, 19); - this.CubeButton.Name = "CubeButton"; - this.CubeButton.Size = new System.Drawing.Size(53, 19); - this.CubeButton.TabIndex = 0; - this.CubeButton.TabStop = true; - this.CubeButton.Text = "Cube"; - this.CubeButton.UseVisualStyleBackColor = true; - this.CubeButton.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged); - // - // NewModelPanel - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.NewModelBox); - this.Name = "NewModelPanel"; - this.Size = new System.Drawing.Size(233, 152); - this.NewModelBox.ResumeLayout(false); - this.NewModelBox.PerformLayout(); - this.ResumeLayout(false); - - } - - - - #endregion - - private GroupBox NewModelBox; - private RadioButton ModelButton; - private RadioButton SphereButton; - private RadioButton CubeButton; - } -} \ No newline at end of file diff --git a/RayTracerApp/Controls/NewModelPanel.cs b/RayTracerApp/Controls/NewModelPanel.cs deleted file mode 100644 index d330ce3..0000000 --- a/RayTracerApp/Controls/NewModelPanel.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Windows.Forms; -using RayTracerApp.SceneControllers; -using RayTracing.Models; - -namespace RayTracerApp.Controls -{ - public partial class NewModelPanel : UserControl, IPanel - { - private IController _controller; - - public NewModelPanel() - { - InitializeComponent(); - } - - public void SetController(IController controller) - { - _controller = controller; - } - - public void UpdateForModel() - { - } - - public void ShowPanel() - { - Visible = true; - } - - public void HidePanel() - { - Visible = false; - } - - private void RadioButton_CheckedChanged(object sender, EventArgs e) - { - var rb = sender as RadioButton; - - if (rb == null) - { - MessageBox.Show("Sender is not a RadioButton"); - return; - } - - if (rb.Checked) - switch (rb.Text) - { - case "Sphere": - _controller.SetModel(new Sphere().Load()); - break; - case "Cube": - _controller.SetModel(new Cube().Load()); - break; - case "Custom model": - _controller.SetModel(new CustomModel()); - break; - } - } - } -} \ No newline at end of file diff --git a/RayTracerApp/Controls/PositionPanel.Designer.cs b/RayTracerApp/Controls/PositionPanel.Designer.cs deleted file mode 100644 index 404a4e2..0000000 --- a/RayTracerApp/Controls/PositionPanel.Designer.cs +++ /dev/null @@ -1,389 +0,0 @@ - -namespace RayTracerApp.Controls -{ - partial class PositionPanel - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Component Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.translationGroupBox = new System.Windows.Forms.GroupBox(); - this.translationLabel = new System.Windows.Forms.Label(); - this.zLabel = new System.Windows.Forms.Label(); - this.yLabel = new System.Windows.Forms.Label(); - this.xLabel = new System.Windows.Forms.Label(); - this.zUpDown = new System.Windows.Forms.NumericUpDown(); - this.yUpDown = new System.Windows.Forms.NumericUpDown(); - this.xUpDown = new System.Windows.Forms.NumericUpDown(); - this.rotationGroupBox = new System.Windows.Forms.GroupBox(); - this.rotationLabel = new System.Windows.Forms.Label(); - this.rollLabel = new System.Windows.Forms.Label(); - this.yawLabel = new System.Windows.Forms.Label(); - this.pitchLabel = new System.Windows.Forms.Label(); - this.rollUpDown = new System.Windows.Forms.NumericUpDown(); - this.yawUpDown = new System.Windows.Forms.NumericUpDown(); - this.pitchUpDown = new System.Windows.Forms.NumericUpDown(); - this.scaleGroupBox = new System.Windows.Forms.GroupBox(); - this.scaleUpDown = new System.Windows.Forms.NumericUpDown(); - this.scaleLabel = new System.Windows.Forms.Label(); - this.translationGroupBox.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.zUpDown)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.yUpDown)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.xUpDown)).BeginInit(); - this.rotationGroupBox.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.rollUpDown)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.yawUpDown)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.pitchUpDown)).BeginInit(); - this.scaleGroupBox.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.scaleUpDown)).BeginInit(); - this.SuspendLayout(); - // - // translationGroupBox - // - this.translationGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.translationGroupBox.Controls.Add(this.translationLabel); - this.translationGroupBox.Controls.Add(this.zLabel); - this.translationGroupBox.Controls.Add(this.yLabel); - this.translationGroupBox.Controls.Add(this.xLabel); - this.translationGroupBox.Controls.Add(this.zUpDown); - this.translationGroupBox.Controls.Add(this.yUpDown); - this.translationGroupBox.Controls.Add(this.xUpDown); - this.translationGroupBox.Location = new System.Drawing.Point(0, 0); - this.translationGroupBox.Name = "translationGroupBox"; - this.translationGroupBox.Size = new System.Drawing.Size(255, 100); - this.translationGroupBox.TabIndex = 0; - this.translationGroupBox.TabStop = false; - // - // translationLabel - // - this.translationLabel.AutoSize = true; - this.translationLabel.Location = new System.Drawing.Point(6, 44); - this.translationLabel.Name = "translationLabel"; - this.translationLabel.Size = new System.Drawing.Size(67, 15); - this.translationLabel.TabIndex = 0; - this.translationLabel.Text = "Translation:"; - // - // zLabel - // - this.zLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.zLabel.AutoSize = true; - this.zLabel.Location = new System.Drawing.Point(159, 73); - this.zLabel.Name = "zLabel"; - this.zLabel.Size = new System.Drawing.Size(14, 15); - this.zLabel.TabIndex = 4; - this.zLabel.Text = "Z"; - // - // yLabel - // - this.yLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.yLabel.AutoSize = true; - this.yLabel.Location = new System.Drawing.Point(159, 44); - this.yLabel.Name = "yLabel"; - this.yLabel.Size = new System.Drawing.Size(14, 15); - this.yLabel.TabIndex = 3; - this.yLabel.Text = "Y"; - // - // xLabel - // - this.xLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.xLabel.AutoSize = true; - this.xLabel.Location = new System.Drawing.Point(159, 15); - this.xLabel.Name = "xLabel"; - this.xLabel.Size = new System.Drawing.Size(14, 15); - this.xLabel.TabIndex = 0; - this.xLabel.Text = "X"; - // - // zUpDown - // - this.zUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.zUpDown.DecimalPlaces = 2; - this.zUpDown.Increment = new decimal(new int[] { - 1, - 0, - 0, - 65536}); - this.zUpDown.Location = new System.Drawing.Point(179, 71); - this.zUpDown.Minimum = new decimal(new int[] { - 100, - 0, - 0, - -2147483648}); - this.zUpDown.Name = "zUpDown"; - this.zUpDown.Size = new System.Drawing.Size(70, 23); - this.zUpDown.TabIndex = 2; - this.zUpDown.ValueChanged += new System.EventHandler(this.zUpDown_ValueChanged); - // - // yUpDown - // - this.yUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.yUpDown.DecimalPlaces = 2; - this.yUpDown.Increment = new decimal(new int[] { - 1, - 0, - 0, - 65536}); - this.yUpDown.Location = new System.Drawing.Point(179, 42); - this.yUpDown.Minimum = new decimal(new int[] { - 100, - 0, - 0, - -2147483648}); - this.yUpDown.Name = "yUpDown"; - this.yUpDown.Size = new System.Drawing.Size(70, 23); - this.yUpDown.TabIndex = 1; - this.yUpDown.ValueChanged += new System.EventHandler(this.yUpDown_ValueChanged); - // - // xUpDown - // - this.xUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.xUpDown.DecimalPlaces = 2; - this.xUpDown.Increment = new decimal(new int[] { - 1, - 0, - 0, - 65536}); - this.xUpDown.Location = new System.Drawing.Point(179, 13); - this.xUpDown.Minimum = new decimal(new int[] { - 100, - 0, - 0, - -2147483648}); - this.xUpDown.Name = "xUpDown"; - this.xUpDown.Size = new System.Drawing.Size(70, 23); - this.xUpDown.TabIndex = 0; - this.xUpDown.ValueChanged += new System.EventHandler(this.xUpDown_ValueChanged); - // - // rotationGroupBox - // - this.rotationGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.rotationGroupBox.Controls.Add(this.rotationLabel); - this.rotationGroupBox.Controls.Add(this.rollLabel); - this.rotationGroupBox.Controls.Add(this.yawLabel); - this.rotationGroupBox.Controls.Add(this.pitchLabel); - this.rotationGroupBox.Controls.Add(this.rollUpDown); - this.rotationGroupBox.Controls.Add(this.yawUpDown); - this.rotationGroupBox.Controls.Add(this.pitchUpDown); - this.rotationGroupBox.Location = new System.Drawing.Point(0, 106); - this.rotationGroupBox.Name = "rotationGroupBox"; - this.rotationGroupBox.Size = new System.Drawing.Size(255, 100); - this.rotationGroupBox.TabIndex = 0; - this.rotationGroupBox.TabStop = false; - // - // rotationLabel - // - this.rotationLabel.AutoSize = true; - this.rotationLabel.Location = new System.Drawing.Point(6, 44); - this.rotationLabel.Name = "rotationLabel"; - this.rotationLabel.Size = new System.Drawing.Size(55, 15); - this.rotationLabel.TabIndex = 11; - this.rotationLabel.Text = "Rotation:"; - // - // rollLabel - // - this.rollLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.rollLabel.AutoSize = true; - this.rollLabel.Location = new System.Drawing.Point(139, 73); - this.rollLabel.Name = "rollLabel"; - this.rollLabel.Size = new System.Drawing.Size(27, 15); - this.rollLabel.TabIndex = 10; - this.rollLabel.Text = "Roll"; - // - // yawLabel - // - this.yawLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.yawLabel.AutoSize = true; - this.yawLabel.Location = new System.Drawing.Point(139, 44); - this.yawLabel.Name = "yawLabel"; - this.yawLabel.Size = new System.Drawing.Size(28, 15); - this.yawLabel.TabIndex = 9; - this.yawLabel.Text = "Yaw"; - // - // pitchLabel - // - this.pitchLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.pitchLabel.AutoSize = true; - this.pitchLabel.Location = new System.Drawing.Point(139, 15); - this.pitchLabel.Name = "pitchLabel"; - this.pitchLabel.Size = new System.Drawing.Size(34, 15); - this.pitchLabel.TabIndex = 5; - this.pitchLabel.Text = "Pitch"; - // - // rollUpDown - // - this.rollUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.rollUpDown.DecimalPlaces = 2; - this.rollUpDown.Increment = new decimal(new int[] { - 1, - 0, - 0, - 65536}); - this.rollUpDown.Location = new System.Drawing.Point(179, 71); - this.rollUpDown.Minimum = new decimal(new int[] { - 100, - 0, - 0, - -2147483648}); - this.rollUpDown.Name = "rollUpDown"; - this.rollUpDown.Size = new System.Drawing.Size(70, 23); - this.rollUpDown.TabIndex = 8; - this.rollUpDown.ValueChanged += new System.EventHandler(this.rollUpDown_ValueChanged); - // - // yawUpDown - // - this.yawUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.yawUpDown.DecimalPlaces = 2; - this.yawUpDown.Increment = new decimal(new int[] { - 1, - 0, - 0, - 65536}); - this.yawUpDown.Location = new System.Drawing.Point(179, 42); - this.yawUpDown.Minimum = new decimal(new int[] { - 100, - 0, - 0, - -2147483648}); - this.yawUpDown.Name = "yawUpDown"; - this.yawUpDown.Size = new System.Drawing.Size(70, 23); - this.yawUpDown.TabIndex = 7; - this.yawUpDown.ValueChanged += new System.EventHandler(this.yawUpDown_ValueChanged); - // - // pitchUpDown - // - this.pitchUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.pitchUpDown.DecimalPlaces = 2; - this.pitchUpDown.Increment = new decimal(new int[] { - 1, - 0, - 0, - 65536}); - this.pitchUpDown.Location = new System.Drawing.Point(179, 13); - this.pitchUpDown.Minimum = new decimal(new int[] { - 100, - 0, - 0, - -2147483648}); - this.pitchUpDown.Name = "pitchUpDown"; - this.pitchUpDown.Size = new System.Drawing.Size(70, 23); - this.pitchUpDown.TabIndex = 6; - this.pitchUpDown.ValueChanged += new System.EventHandler(this.pitchUpDown_ValueChanged); - // - // scaleGroupBox - // - this.scaleGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.scaleGroupBox.Controls.Add(this.scaleUpDown); - this.scaleGroupBox.Controls.Add(this.scaleLabel); - this.scaleGroupBox.Location = new System.Drawing.Point(0, 212); - this.scaleGroupBox.Name = "scaleGroupBox"; - this.scaleGroupBox.Size = new System.Drawing.Size(258, 100); - this.scaleGroupBox.TabIndex = 1; - this.scaleGroupBox.TabStop = false; - // - // scaleUpDown - // - this.scaleUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.scaleUpDown.DecimalPlaces = 2; - this.scaleUpDown.Increment = new decimal(new int[] { - 1, - 0, - 0, - 65536}); - this.scaleUpDown.Location = new System.Drawing.Point(179, 46); - this.scaleUpDown.Minimum = new decimal(new int[] { - 100, - 0, - 0, - -2147483648}); - this.scaleUpDown.Name = "scaleUpDown"; - this.scaleUpDown.Size = new System.Drawing.Size(70, 23); - this.scaleUpDown.TabIndex = 8; - this.scaleUpDown.Value = new decimal(new int[] { - 1, - 0, - 0, - 0}); - this.scaleUpDown.ValueChanged += new System.EventHandler(this.scaleUpDown_ValueChanged); - // - // scaleLabel - // - this.scaleLabel.AutoSize = true; - this.scaleLabel.Location = new System.Drawing.Point(6, 48); - this.scaleLabel.Name = "scaleLabel"; - this.scaleLabel.Size = new System.Drawing.Size(37, 15); - this.scaleLabel.TabIndex = 0; - this.scaleLabel.Text = "Scale:"; - // - // PositionPanel - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.scaleGroupBox); - this.Controls.Add(this.rotationGroupBox); - this.Controls.Add(this.translationGroupBox); - this.Name = "PositionPanel"; - this.Size = new System.Drawing.Size(258, 330); - this.translationGroupBox.ResumeLayout(false); - this.translationGroupBox.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.zUpDown)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.yUpDown)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.xUpDown)).EndInit(); - this.rotationGroupBox.ResumeLayout(false); - this.rotationGroupBox.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.rollUpDown)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.yawUpDown)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.pitchUpDown)).EndInit(); - this.scaleGroupBox.ResumeLayout(false); - this.scaleGroupBox.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.scaleUpDown)).EndInit(); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.GroupBox translationGroupBox; - private System.Windows.Forms.NumericUpDown zUpDown; - private System.Windows.Forms.NumericUpDown yUpDown; - private System.Windows.Forms.NumericUpDown xUpDown; - private System.Windows.Forms.GroupBox rotationGroupBox; - private System.Windows.Forms.GroupBox scaleGroupBox; - private System.Windows.Forms.Label zLabel; - private System.Windows.Forms.Label yLabel; - private System.Windows.Forms.Label xLabel; - private System.Windows.Forms.Label rollLabel; - private System.Windows.Forms.Label yawLabel; - private System.Windows.Forms.Label pitchLabel; - private System.Windows.Forms.NumericUpDown rollUpDown; - private System.Windows.Forms.NumericUpDown yawUpDown; - private System.Windows.Forms.NumericUpDown pitchUpDown; - private System.Windows.Forms.Label translationLabel; - private System.Windows.Forms.Label rotationLabel; - private System.Windows.Forms.NumericUpDown scaleUpDown; - private System.Windows.Forms.Label scaleLabel; - } -} diff --git a/RayTracerApp/Controls/PositionPanel.cs b/RayTracerApp/Controls/PositionPanel.cs deleted file mode 100644 index 4846195..0000000 --- a/RayTracerApp/Controls/PositionPanel.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Windows.Forms; -using RayTracerApp.SceneControllers; - -namespace RayTracerApp.Controls -{ - public partial class PositionPanel : UserControl, IPanel - { - private IController _controller; - - public PositionPanel() - { - InitializeComponent(); - } - - public void SetController(IController controller) - { - _controller = controller; - } - - public void UpdateForModel() - { - var model = _controller.GetModel(); - scaleUpDown.Value = (decimal) model.Scale; - - rollUpDown.Value = (decimal) model.Rotation.Z; - yawUpDown.Value = (decimal) model.Rotation.Y; - pitchUpDown.Value = (decimal) model.Rotation.X; - - xUpDown.Value = (decimal) model.Position.X; - yUpDown.Value = (decimal) model.Position.Y; - zUpDown.Value = (decimal) model.Position.Z; - } - - public void ShowPanel() - { - Visible = true; - } - - public void HidePanel() - { - Visible = false; - } - - private void zUpDown_ValueChanged(object sender, EventArgs e) - { - var nud = sender as NumericUpDown; - var pos = _controller.GetModel().Position; - pos.Z = (float) nud.Value; - _controller.GetModel().Position = pos; - } - - private void yUpDown_ValueChanged(object sender, EventArgs e) - { - var nud = sender as NumericUpDown; - var pos = _controller.GetModel().Position; - pos.Y = (float) nud.Value; - _controller.GetModel().Position = pos; - } - - private void xUpDown_ValueChanged(object sender, EventArgs e) - { - var nud = sender as NumericUpDown; - var pos = _controller.GetModel().Position; - pos.X = (float) nud.Value; - _controller.GetModel().Position = pos; - } - - private void pitchUpDown_ValueChanged(object sender, EventArgs e) - { - var nud = sender as NumericUpDown; - var rotation = _controller.GetModel().Rotation; - rotation.X = (float) nud.Value; - _controller.GetModel().Rotation = rotation; - } - - private void yawUpDown_ValueChanged(object sender, EventArgs e) - { - var nud = sender as NumericUpDown; - var rotation = _controller.GetModel().Rotation; - rotation.Y = (float) nud.Value; - _controller.GetModel().Rotation = rotation; - } - - private void rollUpDown_ValueChanged(object sender, EventArgs e) - { - var nud = sender as NumericUpDown; - var rotation = _controller.GetModel().Rotation; - rotation.Z = (float) nud.Value; - _controller.GetModel().Rotation = rotation; - } - - private void scaleUpDown_ValueChanged(object sender, EventArgs e) - { - var nud = sender as NumericUpDown; - _controller.GetModel().Scale = (float) nud.Value; - } - } -} \ No newline at end of file diff --git a/RayTracerApp/Forms/Menu/EditObjectForm.Designer.cs b/RayTracerApp/Forms/EditObjectForm.Designer.cs similarity index 60% rename from RayTracerApp/Forms/Menu/EditObjectForm.Designer.cs rename to RayTracerApp/Forms/EditObjectForm.Designer.cs index b1b04f5..893c1bb 100644 --- a/RayTracerApp/Forms/Menu/EditObjectForm.Designer.cs +++ b/RayTracerApp/Forms/EditObjectForm.Designer.cs @@ -1,5 +1,5 @@  -namespace RayTracerApp.Forms.Menu +namespace RayTracerApp.Forms { partial class EditObjectForm { @@ -29,45 +29,51 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.featuresPanel = new RayTracerApp.Controls.FeaturesPanel(); - this.positionPanel = new RayTracerApp.Controls.PositionPanel(); - this.materialPanel = new RayTracerApp.Controls.MaterialPanel(); + this.featuresPanel = new RayTracerApp.Panels.FeaturesPanel(); + this.positionPanel = new RayTracerApp.Panels.PositionPanel(); + this.materialPanel = new RayTracerApp.Panels.MaterialPanel(); this.SuspendLayout(); // // featuresPanel // - this.featuresPanel.Location = new System.Drawing.Point(0, 28); + this.featuresPanel.Controller = null; + this.featuresPanel.Location = new System.Drawing.Point(0, 26); this.featuresPanel.Name = "featuresPanel"; - this.featuresPanel.Size = new System.Drawing.Size(334, 329); - this.featuresPanel.TabIndex = 11; - this.materialPanel.Visible = false; + this.featuresPanel.Size = new System.Drawing.Size(484, 594); + this.featuresPanel.TabIndex = 6; // // positionPanel // - this.positionPanel.Location = new System.Drawing.Point(0, 28); + this.positionPanel.Controller = null; + this.positionPanel.Location = new System.Drawing.Point(0, 26); this.positionPanel.Name = "positionPanel"; - this.positionPanel.Size = new System.Drawing.Size(334, 329); - this.positionPanel.TabIndex = 12; - this.materialPanel.Visible = false; + this.positionPanel.Size = new System.Drawing.Size(484, 594); + this.positionPanel.TabIndex = 7; // // materialPanel // - this.materialPanel.Location = new System.Drawing.Point(0, 28); + this.materialPanel.Controller = null; + this.materialPanel.Location = new System.Drawing.Point(0, 26); this.materialPanel.Name = "materialPanel"; - this.materialPanel.Size = new System.Drawing.Size(334, 329); - this.materialPanel.TabIndex = 13; - this.materialPanel.Visible = false; + this.materialPanel.Size = new System.Drawing.Size(484, 594); + this.materialPanel.TabIndex = 8; // // EditObjectForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(334, 411); + this.ClientSize = new System.Drawing.Size(484, 661); this.Controls.Add(this.materialPanel); this.Controls.Add(this.positionPanel); this.Controls.Add(this.featuresPanel); this.Name = "EditObjectForm"; this.Text = "EditObjectForm"; + this.Controls.SetChildIndex(this.rightNextButton, 0); + this.Controls.SetChildIndex(this.middlePreviousButton, 0); + this.Controls.SetChildIndex(this.leftCancelButton, 0); + this.Controls.SetChildIndex(this.topLabel, 0); + this.Controls.SetChildIndex(this.rightFinishButton, 0); + this.Controls.SetChildIndex(this.middleCancelButton, 0); this.Controls.SetChildIndex(this.featuresPanel, 0); this.Controls.SetChildIndex(this.positionPanel, 0); this.Controls.SetChildIndex(this.materialPanel, 0); @@ -77,8 +83,8 @@ private void InitializeComponent() #endregion - private Controls.FeaturesPanel featuresPanel; - private Controls.PositionPanel positionPanel; - private Controls.MaterialPanel materialPanel; + private Panels.FeaturesPanel featuresPanel; + private Panels.PositionPanel positionPanel; + private Panels.MaterialPanel materialPanel; } } \ No newline at end of file diff --git a/RayTracerApp/Forms/EditObjectForm.cs b/RayTracerApp/Forms/EditObjectForm.cs new file mode 100644 index 0000000..a3096d0 --- /dev/null +++ b/RayTracerApp/Forms/EditObjectForm.cs @@ -0,0 +1,138 @@ +using RayTracerApp.Panels; +using RayTracerApp.SceneController; +using RayTracing.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using Rectangle = RayTracing.Models.Rectangle; + +namespace RayTracerApp.Forms +{ + public partial class EditObjectForm : ObjectForm + { + private readonly List _order; + private IObjectController _controller; + private IPanelBase _currentPanel; + + public EditObjectForm(IObjectController controller) + { + InitializeComponent(); + + rightNextButton.Click += nextButton_Click; + middlePreviousButton.Click += previousButton_Click; + leftCancelButton.Click += cancelButton_Click; + leftCancelButton.Text = "OK"; + middleCancelButton.Click += cancelButton_Click; + middleCancelButton.Text = "OK"; + rightFinishButton.Click += finishButton_Click; + + _controller = controller; + + featuresPanel.Visible = false; + positionPanel.Visible = false; + materialPanel.Visible = false; + + var model = _controller.GetModel(); + var featureTypes = new List { typeof(Cylinder), typeof(Rectangle) }; + if (featureTypes.Contains(model.GetType())) + _order = new List { featuresPanel, positionPanel, materialPanel }; + else + _order = new List { positionPanel, materialPanel }; + + _currentPanel = _order[0]; + _currentPanel.ShowPanel(); + + SetController(controller); + foreach(var panel in _order) + { + panel.UpdateFromModel(); + } + if (_controller.GetModel() is CustomModel) + topLabel.Text = "Edit custom model..."; + else + topLabel.Text = $"Edit {_controller.GetModel().GetType().Name.ToLower()}..."; + } + + private void SetController(IObjectController controller) + { + _controller = controller; + foreach (var panel in _order) panel.Controller = _controller; + } + + private void MoveNext() + { + var index = _order.FindIndex(control => control == _currentPanel); + + if (index == 0) + { + leftCancelButton.Visible = true; + middlePreviousButton.Visible = true; + middleCancelButton.Visible = false; + } + + if (index == _order.Count - 2) + { + rightFinishButton.Visible = true; + rightNextButton.Visible = false; + } + + if (index < _order.Count - 1) + { + _order[index + 1].ShowPanel(); + _order[index].HidePanel(); + _currentPanel = _order[index + 1]; + } + } + + private void MovePrevious() + { + var index = _order.FindIndex(control => control == _currentPanel); + + if (index == _order.Count - 1) + { + middleCancelButton.Visible = true; + leftCancelButton.Visible = false; + middlePreviousButton.Visible = false; + } + + if (index == 1) + { + rightNextButton.Visible = true; + rightFinishButton.Visible = false; + } + + if (index > 0) + { + _order[index - 1].UpdateForModel(); + _order[index - 1].ShowPanel(); + _order[index].HidePanel(); + _currentPanel = _order[index - 1]; + } + } + + private void nextButton_Click(object sender, EventArgs e) + { + MoveNext(); + } + + private void finishButton_Click(object sender, EventArgs e) + { + Close(); + } + + private void previousButton_Click(object sender, EventArgs e) + { + MovePrevious(); + } + + private void cancelButton_Click(object sender, EventArgs e) + { + + Close(); + } + } +} diff --git a/RayTracerApp/Forms/Menu/EditObjectForm.resx b/RayTracerApp/Forms/EditObjectForm.resx similarity index 100% rename from RayTracerApp/Forms/Menu/EditObjectForm.resx rename to RayTracerApp/Forms/EditObjectForm.resx diff --git a/RayTracerApp/Forms/MainForm.Designer.cs b/RayTracerApp/Forms/MainForm.Designer.cs index 1e62bd2..f3d6a05 100644 --- a/RayTracerApp/Forms/MainForm.Designer.cs +++ b/RayTracerApp/Forms/MainForm.Designer.cs @@ -1,103 +1,103 @@ -using System; -using System.Windows.Forms; -using OpenTK; - -namespace RayTracerApp.Forms -{ - partial class MainForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "RayTracing"; - this.gLControl.Location = new System.Drawing.Point(0, 20); - this.gLControl.Name = "gLControl"; - this.gLControl.Size = new System.Drawing.Size(500, 300); - this.gLControl.TabIndex = 0; - this.gLControl.VSync = true; - this.gLControl.Load += new System.EventHandler(this.GLControl_Load); - this.Resize += this.OnResize; - this.Controls.Add(this.gLControl); - InitializeToolstrip(); - this.ResumeLayout(false); - } - - private void InitializeToolstrip() - { - this.toolStrip = new System.Windows.Forms.ToolStrip(); - this.newObjectButton = new System.Windows.Forms.ToolStripButton(); - this.editObjectButton = new System.Windows.Forms.ToolStripButton(); - this.toolStrip.SuspendLayout(); - - this.ddButton = new ToolStripDropDownButton(); - this.ddButton.Text = "Edit"; - - this.ddButton.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { +using System; +using System.Windows.Forms; +using OpenTK; + +namespace RayTracerApp.Forms +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "RayTracing"; + this.gLControl.Location = new System.Drawing.Point(0, 20); + this.gLControl.Name = "gLControl"; + this.gLControl.Size = new System.Drawing.Size(500, 300); + this.gLControl.TabIndex = 0; + this.gLControl.VSync = true; + this.gLControl.Load += new System.EventHandler(this.GLControl_Load); + this.Resize += this.OnResize; + this.Controls.Add(this.gLControl); + InitializeToolstrip(); + this.ResumeLayout(false); + } + + private void InitializeToolstrip() + { + this.toolStrip = new System.Windows.Forms.ToolStrip(); + this.newObjectButton = new System.Windows.Forms.ToolStripButton(); + this.editObjectButton = new System.Windows.Forms.ToolStripButton(); + this.toolStrip.SuspendLayout(); + + this.ddButton = new ToolStripDropDownButton(); + this.ddButton.Text = "Edit"; + + this.ddButton.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.newObjectButton, this.editObjectButton - }); - - this.toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + }); + + this.toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ddButton - }); - - this.toolStrip.Location = new System.Drawing.Point(0, 0); - this.toolStrip.Name = "toolStrip"; - this.toolStrip.TabIndex = 0; - this.toolStrip.Text = "toolStrip"; - - this.newObjectButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.newObjectButton.Name = "newObjectButton"; - this.newObjectButton.Text = "New object"; - this.newObjectButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + }); + + this.toolStrip.Location = new System.Drawing.Point(0, 0); + this.toolStrip.Name = "toolStrip"; + this.toolStrip.TabIndex = 0; + this.toolStrip.Text = "toolStrip"; + + this.newObjectButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.newObjectButton.Name = "newObjectButton"; + this.newObjectButton.Text = "New object"; + this.newObjectButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.newObjectButton.Click += new System.EventHandler(this.newObjectButton_Click); - this.editObjectButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.editObjectButton.Name = "editObjectButton"; - this.editObjectButton.Text = "Edit object"; - this.editObjectButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - this.editObjectButton.Click += new System.EventHandler(this.editObjectButton_Click); - - - this.Controls.Add(this.toolStrip); - - this.toolStrip.ResumeLayout(false); - this.PerformLayout(); + this.editObjectButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.editObjectButton.Name = "editObjectButton"; + this.editObjectButton.Text = "Edit object"; + this.editObjectButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.editObjectButton.Click += new System.EventHandler(this.editObjectButton_Click); + + + this.Controls.Add(this.toolStrip); + + this.toolStrip.ResumeLayout(false); + this.PerformLayout(); } - private ToolStrip toolStrip; + private ToolStrip toolStrip; private ToolStripButton newObjectButton; private ToolStripButton editObjectButton; private OpenTK.GLControl gLControl = new GLControl(new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8)); private ToolStripDropDownButton ddButton; - #endregion - } + #endregion + } } \ No newline at end of file diff --git a/RayTracerApp/Forms/MainForm.cs b/RayTracerApp/Forms/MainForm.cs index 45d4756..0010f4e 100644 --- a/RayTracerApp/Forms/MainForm.cs +++ b/RayTracerApp/Forms/MainForm.cs @@ -5,7 +5,6 @@ using OpenTK; using OpenTK.Graphics; using OpenTK.Graphics.OpenGL4; -using RayTracerApp.Forms.Menu; using RayTracing; using RayTracing.Cameras; using RayTracing.Lights; @@ -15,8 +14,8 @@ using RayTracing.World; using Camera = RayTracing.Cameras.Camera; using Timer = System.Windows.Forms.Timer; -using RayTracerApp.SceneControllers; using Color = RayTracing.Maths.Color; +using RayTracerApp.SceneController; namespace RayTracerApp.Forms { @@ -60,9 +59,6 @@ private void GLControl_Load(object sender, EventArgs e) _rayTracer = new SamplesRayTracer(8, 1024, Vec2Sampling.Jittered, gLControl.Width, 32); _cameraController = new CameraController(_camera, gLControl, UpdateLastModification); _scene.AmbientLight = new AmbientLight {Color = Color.FromColor4(Color4.LightSkyBlue)}; - var bulb = new MasterMaterial(); - bulb.Emissive.Emit = new SolidColor(Color.FromColor4(Color4.Yellow) * 25); - bulb.Parts = (1, 0, 0, 0); _scene.AddModel(new Sphere { Position = new Vector3(0, 5.5f, 0), Scale = 1, @@ -91,7 +87,7 @@ private void GLControl_Load(object sender, EventArgs e) _scene.AddModel(new Cube() { Position = new Vector3(0, 0.5f, -3), Scale = 1, - Material = new MasterMaterial(new Reflective(new Texture("wood.jpg"), 0.75f)) + Material = new MasterMaterial(new Diffuse(new Texture("wood.jpg"))) }.Load()); _scene.AddModel(new Rectangle(2) { @@ -186,8 +182,8 @@ private void InitializeBackgroundWorker() private void newObjectButton_Click(object sender, EventArgs e) { UpdateLastModification(); - var form = new NewObjectForm(new NewObjectController(_scene)) - {StartPosition = FormStartPosition.Manual, Location = Location + Size / 3}; + var form = new NewObjectForm(new ObjectController(_scene)) + { StartPosition = FormStartPosition.Manual, Location = Location + Size / 3 }; _isUiUsed = true; form.Closed += FormOnClosed; form.Show(); @@ -195,11 +191,32 @@ private void newObjectButton_Click(object sender, EventArgs e) private void editObjectButton_Click(object sender, EventArgs e) { - UpdateLastModification(); - var form = new EditObjectForm(new EditObjectController(_scene, _scene.Models[0])) - {StartPosition = FormStartPosition.Manual, Location = Location + Size / 3}; - form.Closed += FormOnClosed; - form.Show(); + var ray = _camera.GetRay(0.5f, 0.5f); + var hitInfo = new HitInfo(); + _isUiUsed = true; + if (_scene.HitTest(ray, ref hitInfo, 0.001f, float.PositiveInfinity)) + { + var model = hitInfo.ModelHit; + if (model is Triangle triangle) model = triangle.Parent; + var form = new EditObjectForm(new ObjectController(_scene, model)) + { StartPosition = FormStartPosition.Manual, Location = Location + Size / 3 }; + form.Closed += FormOnClosed; + form.Show(); + } + else + { + // TODO: color dialog title + ColorDialog MyDialog = new ColorDialog(); + MyDialog.AllowFullOpen = true; + MyDialog.Color = _scene.AmbientLight.Color.ToSystemDrawing(); + + if (MyDialog.ShowDialog() == DialogResult.OK) + { + _scene.AmbientLight.Color = Color.FromSystemDrawing(MyDialog.Color); + } + _isUiUsed = false; + UpdateLastModification(); + } } private void FormOnClosed(object? sender, EventArgs e) diff --git a/RayTracerApp/Forms/Menu/EditObjectForm.cs b/RayTracerApp/Forms/Menu/EditObjectForm.cs deleted file mode 100644 index 10a531b..0000000 --- a/RayTracerApp/Forms/Menu/EditObjectForm.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System; -using System.Collections.Generic; -using RayTracerApp.Controls; -using RayTracerApp.SceneControllers; -using RayTracing.Models; - -namespace RayTracerApp.Forms.Menu -{ - public partial class EditObjectForm : EditorForm - { - private readonly List _order; - private IController _controller; - private IPanel _currentPanel; - - public EditObjectForm(IController controller) - { - InitializeComponent(); - - nextButton.Click += nextButton_Click; - previousButton.Click += previousButton_Click; - cancelButton1.Click += cancelButton_Click; - cancelButton2.Click += cancelButton_Click; - finishButton.Click += finishButton_Click; - - _controller = controller; - - switch (controller.GetModel()) - { - case Sphere sphere: - _order = new List {positionPanel, materialPanel}; - _currentPanel = positionPanel; - positionPanel.Visible = true; - break; - - case Cube cube: - _order = new List {positionPanel, materialPanel}; - _currentPanel = positionPanel; - positionPanel.Visible = true; - break; - } - - SetController(controller); - _currentPanel.UpdateForModel(); - if (_controller.GetModel() is CustomModel) - topLabel.Text = "Edit custom model..."; - else - topLabel.Text = $"Edit {_controller.GetModel().GetType().Name.ToLower()}..."; - } - - private void SetController(IController controller) - { - _controller = controller; - foreach (var panel in _order) panel.SetController(_controller); - } - - private void MoveNext() - { - var index = _order.FindIndex(control => control == _currentPanel); - - if (index == 0) - { - cancelButton1.Visible = true; - previousButton.Visible = true; - cancelButton2.Visible = false; - } - - if (index == _order.Count - 2) - { - finishButton.Visible = true; - nextButton.Visible = false; - } - - if (index < _order.Count - 1) - { - _order[index + 1].UpdateForModel(); - _order[index + 1].ShowPanel(); - _order[index].HidePanel(); - _currentPanel = _order[index + 1]; - } - } - - private void MovePrevious() - { - var index = _order.FindIndex(control => control == _currentPanel); - - if (index == _order.Count - 1) - { - cancelButton2.Visible = true; - cancelButton1.Visible = false; - previousButton.Visible = false; - } - - if (index == 1) - { - nextButton.Visible = true; - finishButton.Visible = false; - } - - if (index > 0) - { - _order[index - 1].UpdateForModel(); - _order[index - 1].ShowPanel(); - _order[index].HidePanel(); - _currentPanel = _order[index - 1]; - } - } - - private void nextButton_Click(object sender, EventArgs e) - { - MoveNext(); - } - - private void finishButton_Click(object sender, EventArgs e) - { - _controller.Dispose(); - Close(); - } - - private void previousButton_Click(object sender, EventArgs e) - { - MovePrevious(); - } - - private void cancelButton_Click(object sender, EventArgs e) - { - _controller.Dispose(); - Close(); - } - } -} \ No newline at end of file diff --git a/RayTracerApp/Forms/Menu/EditorForm.Designer.cs b/RayTracerApp/Forms/Menu/EditorForm.Designer.cs deleted file mode 100644 index 1ccb241..0000000 --- a/RayTracerApp/Forms/Menu/EditorForm.Designer.cs +++ /dev/null @@ -1,155 +0,0 @@ -using System.ComponentModel; - -namespace RayTracerApp.Forms -{ - partial class EditorForm - { - /// - /// Required designer variable. - /// - private IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.cancelButton1 = new System.Windows.Forms.Button(); - this.previousButton = new System.Windows.Forms.Button(); - this.nextButton = new System.Windows.Forms.Button(); - this.topLabel = new System.Windows.Forms.Label(); - this.separator1 = new System.Windows.Forms.Label(); - this.separator2 = new System.Windows.Forms.Label(); - this.finishButton = new System.Windows.Forms.Button(); - this.cancelButton2 = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // cancelButton1 - // - this.cancelButton1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.cancelButton1.Location = new System.Drawing.Point(85, 376); - this.cancelButton1.Name = "cancelButton1"; - this.cancelButton1.Size = new System.Drawing.Size(75, 23); - this.cancelButton1.TabIndex = 0; - this.cancelButton1.Text = "Cancel"; - this.cancelButton1.UseVisualStyleBackColor = true; - this.cancelButton1.Visible = false; - // - // previousButton - // - this.previousButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.previousButton.Location = new System.Drawing.Point(166, 376); - this.previousButton.Name = "previousButton"; - this.previousButton.Size = new System.Drawing.Size(75, 23); - this.previousButton.TabIndex = 1; - this.previousButton.Text = "Previous"; - this.previousButton.UseVisualStyleBackColor = true; - // - // nextButton - // - this.nextButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.nextButton.Location = new System.Drawing.Point(247, 376); - this.nextButton.Name = "nextButton"; - this.nextButton.Size = new System.Drawing.Size(75, 23); - this.nextButton.TabIndex = 2; - this.nextButton.Text = "Next"; - this.nextButton.UseVisualStyleBackColor = true; - // - // topLabel - // - this.topLabel.Dock = System.Windows.Forms.DockStyle.Top; - this.topLabel.Location = new System.Drawing.Point(0, 0); - this.topLabel.Name = "topLabel"; - this.topLabel.Size = new System.Drawing.Size(334, 23); - this.topLabel.TabIndex = 8; - this.topLabel.Text = "Add new object..."; - this.topLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // separator1 - // - this.separator1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.separator1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; - this.separator1.Location = new System.Drawing.Point(0, 23); - this.separator1.Name = "separator1"; - this.separator1.Size = new System.Drawing.Size(334, 2); - this.separator1.TabIndex = 9; - // - // separator2 - // - this.separator2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.separator2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; - this.separator2.Location = new System.Drawing.Point(0, 360); - this.separator2.Name = "separator2"; - this.separator2.Size = new System.Drawing.Size(334, 2); - this.separator2.TabIndex = 10; - // - // finishButton - // - this.finishButton.Location = new System.Drawing.Point(247, 376); - this.finishButton.Name = "finishButton"; - this.finishButton.Size = new System.Drawing.Size(75, 23); - this.finishButton.TabIndex = 11; - this.finishButton.Text = "Finish"; - this.finishButton.UseVisualStyleBackColor = true; - this.finishButton.Visible = false; - // - // cancelButton2 - // - this.cancelButton2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.cancelButton2.Location = new System.Drawing.Point(166, 376); - this.cancelButton2.Name = "cancelButton2"; - this.cancelButton2.Size = new System.Drawing.Size(75, 23); - this.cancelButton2.TabIndex = 12; - this.cancelButton2.Text = "Cancel"; - this.cancelButton2.UseVisualStyleBackColor = true; - // - // EditorForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(334, 411); - this.Controls.Add(this.cancelButton2); - this.Controls.Add(this.finishButton); - this.Controls.Add(this.separator2); - this.Controls.Add(this.separator1); - this.Controls.Add(this.topLabel); - this.Controls.Add(this.nextButton); - this.Controls.Add(this.previousButton); - this.Controls.Add(this.cancelButton1); - this.Name = "EditorForm"; - this.Text = "EditorForm"; - this.ResumeLayout(false); - - } - - #endregion - - protected System.Windows.Forms.Button cancelButton1; - protected System.Windows.Forms.Button cancelButton2; - protected System.Windows.Forms.Button previousButton; - protected System.Windows.Forms.Button nextButton; - protected System.Windows.Forms.Button finishButton; - protected System.Windows.Forms.Label topLabel; - private System.Windows.Forms.Label separator1; - private System.Windows.Forms.Label separator2; - } -} \ No newline at end of file diff --git a/RayTracerApp/Forms/Menu/EditorForm.cs b/RayTracerApp/Forms/Menu/EditorForm.cs deleted file mode 100644 index 547fdf4..0000000 --- a/RayTracerApp/Forms/Menu/EditorForm.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Windows.Forms; - -namespace RayTracerApp.Forms -{ - public partial class EditorForm : Form - { - public EditorForm() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/RayTracerApp/Forms/Menu/NewObjectForm.Designer.cs b/RayTracerApp/Forms/Menu/NewObjectForm.Designer.cs deleted file mode 100644 index 727b41e..0000000 --- a/RayTracerApp/Forms/Menu/NewObjectForm.Designer.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System.ComponentModel; -using RayTracerApp.Controls; - -namespace RayTracerApp.Forms -{ - partial class NewObjectForm - { - /// - /// Required designer variable. - /// - private IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.featuresPanel = new RayTracerApp.Controls.FeaturesPanel(); - this.newModelPanel = new RayTracerApp.Controls.NewModelPanel(); - this.positionPanel = new RayTracerApp.Controls.PositionPanel(); - this.materialPanel = new RayTracerApp.Controls.MaterialPanel(); - this.SuspendLayout(); - // - // featuresPanel - // - this.featuresPanel.Location = new System.Drawing.Point(0, 26); - this.featuresPanel.Name = "featuresPanel"; - this.featuresPanel.Size = new System.Drawing.Size(334, 331); - this.featuresPanel.TabIndex = 11; - this.featuresPanel.Visible = false; - // - // newModelPanel - // - this.newModelPanel.Location = new System.Drawing.Point(0, 26); - this.newModelPanel.Name = "newModelPanel"; - this.newModelPanel.Size = new System.Drawing.Size(334, 331); - this.newModelPanel.TabIndex = 12; - // - // positionPanel - // - this.positionPanel.Location = new System.Drawing.Point(0, 26); - this.positionPanel.Name = "positionPanel"; - this.positionPanel.Size = new System.Drawing.Size(334, 331); - this.positionPanel.TabIndex = 13; - this.positionPanel.Visible = false; - // - // materialPanel - // - this.materialPanel.Location = new System.Drawing.Point(0, 28); - this.materialPanel.Name = "materialPanel"; - this.materialPanel.Size = new System.Drawing.Size(334, 329); - this.materialPanel.TabIndex = 14; - this.materialPanel.Visible = false; - // - // NewObjectForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(334, 411); - this.Controls.Add(this.materialPanel); - this.Controls.Add(this.positionPanel); - this.Controls.Add(this.newModelPanel); - this.Controls.Add(this.featuresPanel); - this.MaximumSize = new System.Drawing.Size(350, 450); - this.MinimumSize = new System.Drawing.Size(350, 450); - this.Name = "NewObjectForm"; - this.Text = "NewObjectForm"; - this.Controls.SetChildIndex(this.featuresPanel, 0); - this.Controls.SetChildIndex(this.newModelPanel, 0); - this.Controls.SetChildIndex(this.positionPanel, 0); - this.Controls.SetChildIndex(this.materialPanel, 0); - this.ResumeLayout(false); - - } - - #endregion - - private FeaturesPanel featuresPanel; - private NewModelPanel newModelPanel; - private PositionPanel positionPanel; - private MaterialPanel materialPanel; - } -} \ No newline at end of file diff --git a/RayTracerApp/Forms/Menu/NewObjectForm.cs b/RayTracerApp/Forms/Menu/NewObjectForm.cs deleted file mode 100644 index 31196e3..0000000 --- a/RayTracerApp/Forms/Menu/NewObjectForm.cs +++ /dev/null @@ -1,140 +0,0 @@ -using System; -using System.Collections.Generic; -using RayTracerApp.Controls; -using RayTracerApp.SceneControllers; -using RayTracing.Models; - -namespace RayTracerApp.Forms -{ - public partial class NewObjectForm : EditorForm - { - private readonly IController _controller; - private IPanel _currentPanel; - private List _order; - - public NewObjectForm(IController controller) - { - InitializeComponent(); - - nextButton.Click += nextButton_Click; - previousButton.Click += previousButton_Click; - cancelButton1.Click += cancelButton_Click; - cancelButton2.Click += cancelButton_Click; - finishButton.Click += finishButton_Click; - - _controller = controller; - - _currentPanel = newModelPanel; - _currentPanel.SetController(_controller); - topLabel.Text = "Add new object..."; - } - - private void SetController() - { - foreach (var panel in _order) panel.SetController(_controller); - } - - private void ChooseOrder() - { - switch (_controller.GetModel()) - { - case Sphere sphere: - _order = new List {newModelPanel, positionPanel, materialPanel}; - break; - - case Cube cube: - _order = new List {newModelPanel, positionPanel, materialPanel}; - break; - - case CustomModel customModel: - _order = new List {newModelPanel, featuresPanel, positionPanel, materialPanel}; - break; - } - } - - private void MoveNext() - { - var index = 0; - if (_currentPanel != newModelPanel) index = _order.FindIndex(control => control == _currentPanel); - - if (index == 0) - { - ChooseOrder(); - SetController(); - cancelButton1.Visible = true; - previousButton.Visible = true; - cancelButton2.Visible = false; - - if (_controller.GetModel() is CustomModel) - topLabel.Text = "Add custom model..."; - else - topLabel.Text = $"Add {_controller.GetModel().GetType().Name.ToLower()}..."; - } - - if (index == _order.Count - 2) - { - finishButton.Visible = true; - nextButton.Visible = false; - } - - if (index < _order.Count - 1) - { - _order[index + 1].UpdateForModel(); - _order[index + 1].ShowPanel(); - _order[index].HidePanel(); - _currentPanel = _order[index + 1]; - } - } - - private void MovePrevious() - { - var index = _order.FindIndex(control => control == _currentPanel); - - if (index == 1) - { - topLabel.Text = "Add new object..."; - - cancelButton2.Visible = true; - cancelButton1.Visible = false; - previousButton.Visible = false; - } - - if (index == _order.Count - 1) - { - nextButton.Visible = true; - finishButton.Visible = false; - } - - if (index > 0) - { - _order[index - 1].UpdateForModel(); - _order[index - 1].ShowPanel(); - _order[index].HidePanel(); - _currentPanel = _order[index - 1]; - } - } - - private void nextButton_Click(object sender, EventArgs e) - { - MoveNext(); - } - - private void finishButton_Click(object sender, EventArgs e) - { - _controller.Dispose(); - Close(); - } - - private void previousButton_Click(object sender, EventArgs e) - { - MovePrevious(); - } - - private void cancelButton_Click(object sender, EventArgs e) - { - _controller.DeleteModel(); - _controller.Dispose(); - Close(); - } - } -} \ No newline at end of file diff --git a/RayTracerApp/Forms/Menu/NewObjectForm.resx b/RayTracerApp/Forms/Menu/NewObjectForm.resx deleted file mode 100644 index b5ae26c..0000000 --- a/RayTracerApp/Forms/Menu/NewObjectForm.resx +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/RayTracerApp/Forms/NewObjectForm.Designer.cs b/RayTracerApp/Forms/NewObjectForm.Designer.cs new file mode 100644 index 0000000..e73a6fb --- /dev/null +++ b/RayTracerApp/Forms/NewObjectForm.Designer.cs @@ -0,0 +1,108 @@ + +namespace RayTracerApp.Forms +{ + partial class NewObjectForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.objectSelectionPanel = new RayTracerApp.Panels.ObjectSelectionPanel(); + this.featuresPanel = new RayTracerApp.Panels.FeaturesPanel(); + this.positionPanel = new RayTracerApp.Panels.PositionPanel(); + this.materialPanel = new RayTracerApp.Panels.MaterialPanel(); + this.SuspendLayout(); + // + // objectSelectionPanel + // + this.objectSelectionPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.objectSelectionPanel.Controller = null; + this.objectSelectionPanel.Location = new System.Drawing.Point(0, 26); + this.objectSelectionPanel.Name = "objectSelectionPanel"; + this.objectSelectionPanel.Size = new System.Drawing.Size(484, 594); + this.objectSelectionPanel.TabIndex = 6; + // + // featuresPanel + // + this.featuresPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.featuresPanel.Controller = null; + this.featuresPanel.Location = new System.Drawing.Point(0, 26); + this.featuresPanel.Name = "featuresPanel"; + this.featuresPanel.Size = new System.Drawing.Size(484, 594); + this.featuresPanel.TabIndex = 7; + // + // positionPanel + // + this.positionPanel.Controller = null; + this.positionPanel.Location = new System.Drawing.Point(0, 26); + this.positionPanel.Name = "positionPanel"; + this.positionPanel.Size = new System.Drawing.Size(484, 594); + this.positionPanel.TabIndex = 8; + // + // materialPanel + // + this.materialPanel.Controller = null; + this.materialPanel.Location = new System.Drawing.Point(0, 26); + this.materialPanel.Name = "materialPanel"; + this.materialPanel.Size = new System.Drawing.Size(484, 594); + this.materialPanel.TabIndex = 9; + // + // NewObjectForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(484, 661); + this.Controls.Add(this.materialPanel); + this.Controls.Add(this.positionPanel); + this.Controls.Add(this.featuresPanel); + this.Controls.Add(this.objectSelectionPanel); + this.Name = "NewObjectForm"; + this.Text = "NewObjectForm"; + this.Controls.SetChildIndex(this.rightNextButton, 0); + this.Controls.SetChildIndex(this.middlePreviousButton, 0); + this.Controls.SetChildIndex(this.leftCancelButton, 0); + this.Controls.SetChildIndex(this.topLabel, 0); + this.Controls.SetChildIndex(this.rightFinishButton, 0); + this.Controls.SetChildIndex(this.middleCancelButton, 0); + this.Controls.SetChildIndex(this.objectSelectionPanel, 0); + this.Controls.SetChildIndex(this.featuresPanel, 0); + this.Controls.SetChildIndex(this.positionPanel, 0); + this.Controls.SetChildIndex(this.materialPanel, 0); + this.ResumeLayout(false); + + } + + #endregion + + private Panels.ObjectSelectionPanel objectSelectionPanel; + private Panels.FeaturesPanel featuresPanel; + private Panels.PositionPanel positionPanel; + private Panels.MaterialPanel materialPanel; + } +} \ No newline at end of file diff --git a/RayTracerApp/Forms/NewObjectForm.cs b/RayTracerApp/Forms/NewObjectForm.cs new file mode 100644 index 0000000..8bd9021 --- /dev/null +++ b/RayTracerApp/Forms/NewObjectForm.cs @@ -0,0 +1,139 @@ +using RayTracerApp.Panels; +using RayTracerApp.SceneController; +using RayTracing.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using Rectangle = RayTracing.Models.Rectangle; + +namespace RayTracerApp.Forms +{ + public partial class NewObjectForm : ObjectForm + { + private IObjectController _controller; + private IPanelBase _currentPanel; + private List _order; + public NewObjectForm(IObjectController controller) + { + InitializeComponent(); + + rightNextButton.Click += nextButton_Click; + middlePreviousButton.Click += previousButton_Click; + leftCancelButton.Click += cancelButton_Click; + middleCancelButton.Click += cancelButton_Click; + rightFinishButton.Click += finishButton_Click; + + _controller = controller; + objectSelectionPanel.Visible = true; + featuresPanel.Visible = false; + positionPanel.Visible = false; + materialPanel.Visible = false; + + _currentPanel = objectSelectionPanel; + _currentPanel.Controller = _controller; + topLabel.Text = "Add new object..."; + } + + private void SetController() + { + foreach (var panel in _order) panel.Controller = _controller; + } + + private void ChooseOrder() + { + var model = _controller.GetModel(); + var featureTypes = new List { typeof(Cylinder), typeof(Rectangle), typeof(CustomModel) }; + if (featureTypes.Contains(model.GetType())) + _order = new List { objectSelectionPanel, featuresPanel, positionPanel, materialPanel }; + else + _order = new List { objectSelectionPanel, positionPanel, materialPanel }; + } + + private void MoveNext() + { + var index = 0; + if (_currentPanel != objectSelectionPanel) index = _order.FindIndex(control => control == _currentPanel); + + if (index == 0) + { + ChooseOrder(); + SetController(); + + leftCancelButton.Visible = true; + middlePreviousButton.Visible = true; + middleCancelButton.Visible = false; + + if (_controller.GetModel() is CustomModel) + topLabel.Text = "Add custom model..."; + else + topLabel.Text = $"Add {_controller.GetModel().GetType().Name.ToLower()}..."; + } + + if (index == _order.Count - 2) + { + rightFinishButton.Visible = true; + rightNextButton.Visible = false; + } + + if (index < _order.Count - 1) + { + _order[index + 1].UpdateForModel(); + _order[index + 1].ShowPanel(); + _order[index].HidePanel(); + _currentPanel = _order[index + 1]; + } + } + + private void MovePrevious() + { + var index = _order.FindIndex(control => control == _currentPanel); + + if (index == 1) + { + topLabel.Text = "Add new object..."; + + middleCancelButton.Visible = true; + leftCancelButton.Visible = false; + middlePreviousButton.Visible = false; + } + + if (index == _order.Count - 1) + { + rightNextButton.Visible = true; + rightFinishButton.Visible = false; + } + + if (index > 0) + { + _order[index - 1].ShowPanel(); + _order[index].HidePanel(); + _currentPanel = _order[index - 1]; + } + } + + private void nextButton_Click(object sender, EventArgs e) + { + MoveNext(); + } + + private void finishButton_Click(object sender, EventArgs e) + { + Close(); + } + + private void previousButton_Click(object sender, EventArgs e) + { + MovePrevious(); + } + + private void cancelButton_Click(object sender, EventArgs e) + { + _controller.DeleteModel(); + Close(); + } + } +} diff --git a/RayTracerApp/Controls/Features/CustomModelFeatureControl.resx b/RayTracerApp/Forms/NewObjectForm.resx similarity index 100% rename from RayTracerApp/Controls/Features/CustomModelFeatureControl.resx rename to RayTracerApp/Forms/NewObjectForm.resx diff --git a/RayTracerApp/Forms/ObjectForm.Designer.cs b/RayTracerApp/Forms/ObjectForm.Designer.cs new file mode 100644 index 0000000..b27f008 --- /dev/null +++ b/RayTracerApp/Forms/ObjectForm.Designer.cs @@ -0,0 +1,128 @@ + +namespace RayTracerApp.Forms +{ + partial class ObjectForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.rightNextButton = new System.Windows.Forms.Button(); + this.middlePreviousButton = new System.Windows.Forms.Button(); + this.leftCancelButton = new System.Windows.Forms.Button(); + this.middleCancelButton = new System.Windows.Forms.Button(); + this.rightFinishButton = new System.Windows.Forms.Button(); + this.topLabel = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // rightNextButton + // + this.rightNextButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.rightNextButton.Location = new System.Drawing.Point(397, 626); + this.rightNextButton.Name = "rightNextButton"; + this.rightNextButton.Size = new System.Drawing.Size(75, 23); + this.rightNextButton.TabIndex = 0; + this.rightNextButton.Text = "Next"; + this.rightNextButton.UseVisualStyleBackColor = true; + // + // middlePreviousButton + // + this.middlePreviousButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.middlePreviousButton.Location = new System.Drawing.Point(316, 626); + this.middlePreviousButton.Name = "middlePreviousButton"; + this.middlePreviousButton.Size = new System.Drawing.Size(75, 23); + this.middlePreviousButton.TabIndex = 1; + this.middlePreviousButton.Text = "Previous"; + this.middlePreviousButton.UseVisualStyleBackColor = true; + this.middlePreviousButton.Visible = false; + // + // leftCancelButton + // + this.leftCancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.leftCancelButton.Location = new System.Drawing.Point(235, 626); + this.leftCancelButton.Name = "leftCancelButton"; + this.leftCancelButton.Size = new System.Drawing.Size(75, 23); + this.leftCancelButton.TabIndex = 2; + this.leftCancelButton.Text = "Cancel"; + this.leftCancelButton.UseVisualStyleBackColor = true; + this.leftCancelButton.Visible = false; + // + // middleCancelButton + // + this.middleCancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.middleCancelButton.Location = new System.Drawing.Point(316, 626); + this.middleCancelButton.Name = "middleCancelButton"; + this.middleCancelButton.Size = new System.Drawing.Size(75, 23); + this.middleCancelButton.TabIndex = 3; + this.middleCancelButton.Text = "Cancel"; + this.middleCancelButton.UseVisualStyleBackColor = true; + // + // rightFinishButton + // + this.rightFinishButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.rightFinishButton.Location = new System.Drawing.Point(397, 626); + this.rightFinishButton.Name = "rightFinishButton"; + this.rightFinishButton.Size = new System.Drawing.Size(75, 23); + this.rightFinishButton.TabIndex = 4; + this.rightFinishButton.Text = "Finish"; + this.rightFinishButton.UseVisualStyleBackColor = true; + this.rightFinishButton.Visible = false; + // + // topLabel + // + this.topLabel.Dock = System.Windows.Forms.DockStyle.Top; + this.topLabel.Location = new System.Drawing.Point(0, 0); + this.topLabel.Name = "topLabel"; + this.topLabel.Size = new System.Drawing.Size(484, 23); + this.topLabel.TabIndex = 5; + this.topLabel.Text = "Add new object..."; + this.topLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // ObjectForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(484, 661); + this.Controls.Add(this.middleCancelButton); + this.Controls.Add(this.rightFinishButton); + this.Controls.Add(this.topLabel); + this.Controls.Add(this.leftCancelButton); + this.Controls.Add(this.middlePreviousButton); + this.Controls.Add(this.rightNextButton); + this.Name = "ObjectForm"; + this.Text = "ObjectForm"; + this.ResumeLayout(false); + + } + + #endregion + protected System.Windows.Forms.Button middlePreviousButton; + protected System.Windows.Forms.Button leftCancelButton; + protected System.Windows.Forms.Button middleCancelButton; + protected System.Windows.Forms.Button rightFinishButton; + protected internal System.Windows.Forms.Label topLabel; + protected System.Windows.Forms.Button rightNextButton; + } +} \ No newline at end of file diff --git a/RayTracerApp/Forms/ObjectForm.cs b/RayTracerApp/Forms/ObjectForm.cs new file mode 100644 index 0000000..d04e0a4 --- /dev/null +++ b/RayTracerApp/Forms/ObjectForm.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace RayTracerApp.Forms +{ + public partial class ObjectForm : Form + { + public ObjectForm() + { + InitializeComponent(); + } + } +} diff --git a/RayTracerApp/Controls/MaterialPanel.resx b/RayTracerApp/Forms/ObjectForm.resx similarity index 100% rename from RayTracerApp/Controls/MaterialPanel.resx rename to RayTracerApp/Forms/ObjectForm.resx diff --git a/RayTracerApp/Panels/FeaturesPanel.Designer.cs b/RayTracerApp/Panels/FeaturesPanel.Designer.cs new file mode 100644 index 0000000..78cbdd5 --- /dev/null +++ b/RayTracerApp/Panels/FeaturesPanel.Designer.cs @@ -0,0 +1,146 @@ + +namespace RayTracerApp.Panels +{ + partial class FeaturesPanel + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.filePanel = new System.Windows.Forms.Panel(); + this.fromFileLabel = new System.Windows.Forms.Label(); + this.customModelButton = new System.Windows.Forms.Button(); + this.aspectPanel = new System.Windows.Forms.Panel(); + this.aspectLabel = new System.Windows.Forms.Label(); + this.aspectRatioUpDown = new System.Windows.Forms.NumericUpDown(); + this.filePanel.SuspendLayout(); + this.aspectPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.aspectRatioUpDown)).BeginInit(); + this.SuspendLayout(); + // + // filePanel + // + this.filePanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.filePanel.Controls.Add(this.fromFileLabel); + this.filePanel.Controls.Add(this.customModelButton); + this.filePanel.Location = new System.Drawing.Point(0, 0); + this.filePanel.Name = "filePanel"; + this.filePanel.Size = new System.Drawing.Size(393, 165); + this.filePanel.TabIndex = 0; + // + // fromFileLabel + // + this.fromFileLabel.AutoSize = true; + this.fromFileLabel.Location = new System.Drawing.Point(42, 38); + this.fromFileLabel.Name = "fromFileLabel"; + this.fromFileLabel.Size = new System.Drawing.Size(63, 15); + this.fromFileLabel.TabIndex = 1; + this.fromFileLabel.Text = "From file..."; + // + // customModelButton + // + this.customModelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.customModelButton.Location = new System.Drawing.Point(302, 34); + this.customModelButton.Name = "customModelButton"; + this.customModelButton.Size = new System.Drawing.Size(75, 23); + this.customModelButton.TabIndex = 0; + this.customModelButton.Text = "..."; + this.customModelButton.UseVisualStyleBackColor = true; + this.customModelButton.Click += new System.EventHandler(this.customModelButton_Click); + // + // aspectPanel + // + this.aspectPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.aspectPanel.Controls.Add(this.aspectLabel); + this.aspectPanel.Controls.Add(this.aspectRatioUpDown); + this.aspectPanel.Location = new System.Drawing.Point(0, 196); + this.aspectPanel.Name = "aspectPanel"; + this.aspectPanel.Size = new System.Drawing.Size(393, 139); + this.aspectPanel.TabIndex = 0; + // + // aspectLabel + // + this.aspectLabel.AutoSize = true; + this.aspectLabel.Location = new System.Drawing.Point(42, 68); + this.aspectLabel.Name = "aspectLabel"; + this.aspectLabel.Size = new System.Drawing.Size(46, 15); + this.aspectLabel.TabIndex = 1; + this.aspectLabel.Text = "Aspect:"; + // + // aspectRatioUpDown + // + this.aspectRatioUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.aspectRatioUpDown.DecimalPlaces = 2; + this.aspectRatioUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + this.aspectRatioUpDown.Location = new System.Drawing.Point(302, 66); + this.aspectRatioUpDown.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 131072}); + this.aspectRatioUpDown.Name = "aspectRatioUpDown"; + this.aspectRatioUpDown.Size = new System.Drawing.Size(75, 23); + this.aspectRatioUpDown.TabIndex = 0; + this.aspectRatioUpDown.Value = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.aspectRatioUpDown.ValueChanged += new System.EventHandler(this.aspectRatioUpDown_ValueChanged); + // + // FeaturesPanel + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.aspectPanel); + this.Controls.Add(this.filePanel); + this.Name = "FeaturesPanel"; + this.Size = new System.Drawing.Size(393, 410); + this.VisibleChanged += new System.EventHandler(this.FeaturesPanel_VisibleChanged); + this.filePanel.ResumeLayout(false); + this.filePanel.PerformLayout(); + this.aspectPanel.ResumeLayout(false); + this.aspectPanel.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.aspectRatioUpDown)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel filePanel; + private System.Windows.Forms.Label fromFileLabel; + private System.Windows.Forms.Button customModelButton; + private System.Windows.Forms.Panel aspectPanel; + private System.Windows.Forms.Label aspectLabel; + private System.Windows.Forms.NumericUpDown aspectRatioUpDown; + } +} diff --git a/RayTracerApp/Controls/Features/CustomModelFeatureControl.cs b/RayTracerApp/Panels/FeaturesPanel.cs similarity index 50% rename from RayTracerApp/Controls/Features/CustomModelFeatureControl.cs rename to RayTracerApp/Panels/FeaturesPanel.cs index 93d3c9e..30be6ac 100644 --- a/RayTracerApp/Controls/Features/CustomModelFeatureControl.cs +++ b/RayTracerApp/Panels/FeaturesPanel.cs @@ -1,46 +1,64 @@ -using RayTracing.Models; +using RayTracerApp.SceneController; +using RayTracing.Models; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; -using System.Drawing; using System.IO; using System.Text; using System.Windows.Forms; -using RayTracerApp.SceneControllers; -namespace RayTracerApp.Controls.Features +namespace RayTracerApp.Panels { - public partial class CustomModelFeatureControl : UserControl, IPanel + public partial class FeaturesPanel : UserControl, IPanelBase { - private IController _controller; - - public CustomModelFeatureControl() + public FeaturesPanel() { InitializeComponent(); } - public void HidePanel() - { - Visible = false; - } + public IObjectController Controller { get; set; } - public void SetController(IController controller) + public void UpdateForModel() { - _controller = controller; } - public void ShowPanel() + public void UpdateFromModel() { - Visible = true; + var model = Controller.GetModel(); + switch (model) + { + case Rectangle rectangle: + aspectRatioUpDown.Value = (decimal)rectangle.AspectRatio; + break; + case Cylinder cylinder: + aspectRatioUpDown.Value = (decimal)cylinder.Aspect; + break; + default: + throw new Exception("Bad model type"); + } } - public void UpdateForModel() + private void aspectRatioUpDown_ValueChanged(object sender, EventArgs e) { - + var nud = sender as NumericUpDown; + float val = (float)nud.Value; + + var model = Controller.GetModel(); + switch(model) + { + case Rectangle rectangle: + rectangle.AspectRatio = val; + break; + case Cylinder cylinder: + cylinder.Aspect = val; + break; + default: + throw new Exception("Bad model type"); + } } - private void loadFromFileButton_Click(object sender, EventArgs e) + private void customModelButton_Click(object sender, EventArgs e) { string filePath = ""; using (OpenFileDialog openFileDialog = new OpenFileDialog()) @@ -65,19 +83,28 @@ private void loadFromFileButton_Click(object sender, EventArgs e) "DirectX X (*.x)|*.x|" + "AC3D (*.ac)|*.ac|" + "Milkshape 3D (*.ms3d)|*.ms3d"; - - openFileDialog.FilterIndex = 2; + + openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { filePath = openFileDialog.FileName; var model = ModelLoader.Load(filePath); - _controller.GetModel()?.Unload(); - _controller.SetModel(model); - _controller.GetModel().Load(); + Controller.GetModel()?.Unload(); + Controller.SetModel(model); + Controller.GetModel().Load(); } } } + + private void FeaturesPanel_VisibleChanged(object sender, EventArgs e) + { + if (Controller == null) return; + var model = Controller.GetModel(); + bool customModel = model is CustomModel && !(model is Cube); + filePanel.Visible = customModel; + aspectPanel.Visible = !customModel; + } } } diff --git a/RayTracerApp/Controls/NewModelPanel.resx b/RayTracerApp/Panels/FeaturesPanel.resx similarity index 100% rename from RayTracerApp/Controls/NewModelPanel.resx rename to RayTracerApp/Panels/FeaturesPanel.resx diff --git a/RayTracerApp/Panels/IPanelBase.cs b/RayTracerApp/Panels/IPanelBase.cs new file mode 100644 index 0000000..5074209 --- /dev/null +++ b/RayTracerApp/Panels/IPanelBase.cs @@ -0,0 +1,23 @@ +using RayTracerApp.SceneController; +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; + +namespace RayTracerApp.Panels +{ + interface IPanelBase + { + IObjectController Controller { get; set; } + void UpdateForModel(); + void UpdateFromModel(); + void ShowPanel() + { + (this as Control).Visible = true; + } + void HidePanel() + { + (this as Control).Visible = false; + } + } +} diff --git a/RayTracerApp/Panels/MaterialPanel.Designer.cs b/RayTracerApp/Panels/MaterialPanel.Designer.cs new file mode 100644 index 0000000..fe297eb --- /dev/null +++ b/RayTracerApp/Panels/MaterialPanel.Designer.cs @@ -0,0 +1,870 @@ + +namespace RayTracerApp.Panels +{ + partial class MaterialPanel + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.tableLayoutPanel12 = new System.Windows.Forms.TableLayoutPanel(); + this.refractiveIndexUpDown = new System.Windows.Forms.NumericUpDown(); + this.tableLayoutPanel13 = new System.Windows.Forms.TableLayoutPanel(); + this.refractiveTexture = new System.Windows.Forms.Label(); + this.refractiveColor = new System.Windows.Forms.Button(); + this.refractiveFile = new System.Windows.Forms.Button(); + this.refractiveShareUpDown = new System.Windows.Forms.NumericUpDown(); + this.tableLayoutPanel11 = new System.Windows.Forms.TableLayoutPanel(); + this.label15 = new System.Windows.Forms.Label(); + this.label16 = new System.Windows.Forms.Label(); + this.label17 = new System.Windows.Forms.Label(); + this.tableLayoutPanel9 = new System.Windows.Forms.TableLayoutPanel(); + this.reflectiveDisturbanceUpDown = new System.Windows.Forms.NumericUpDown(); + this.tableLayoutPanel10 = new System.Windows.Forms.TableLayoutPanel(); + this.reflectiveTexture = new System.Windows.Forms.Label(); + this.reflectiveColor = new System.Windows.Forms.Button(); + this.reflectiveFile = new System.Windows.Forms.Button(); + this.reflectiveShareUpDown = new System.Windows.Forms.NumericUpDown(); + this.tableLayoutPanel8 = new System.Windows.Forms.TableLayoutPanel(); + this.label14 = new System.Windows.Forms.Label(); + this.label11 = new System.Windows.Forms.Label(); + this.label12 = new System.Windows.Forms.Label(); + this.tableLayoutPanel6 = new System.Windows.Forms.TableLayoutPanel(); + this.tableLayoutPanel7 = new System.Windows.Forms.TableLayoutPanel(); + this.emissiveTexture = new System.Windows.Forms.Label(); + this.emissiveColor = new System.Windows.Forms.Button(); + this.emissiveFile = new System.Windows.Forms.Button(); + this.emissiveShareUpDown = new System.Windows.Forms.NumericUpDown(); + this.tableLayoutPanel5 = new System.Windows.Forms.TableLayoutPanel(); + this.label8 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); + this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel(); + this.diffuseTexture = new System.Windows.Forms.Label(); + this.diffuseColor = new System.Windows.Forms.Button(); + this.diffuseFile = new System.Windows.Forms.Button(); + this.diffuseShareUpDown = new System.Windows.Forms.NumericUpDown(); + this.label1 = new System.Windows.Forms.Label(); + this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.colorDialog = new System.Windows.Forms.ColorDialog(); + this.tableLayoutPanel1.SuspendLayout(); + this.tableLayoutPanel12.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.refractiveIndexUpDown)).BeginInit(); + this.tableLayoutPanel13.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.refractiveShareUpDown)).BeginInit(); + this.tableLayoutPanel11.SuspendLayout(); + this.tableLayoutPanel9.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.reflectiveDisturbanceUpDown)).BeginInit(); + this.tableLayoutPanel10.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.reflectiveShareUpDown)).BeginInit(); + this.tableLayoutPanel8.SuspendLayout(); + this.tableLayoutPanel6.SuspendLayout(); + this.tableLayoutPanel7.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.emissiveShareUpDown)).BeginInit(); + this.tableLayoutPanel5.SuspendLayout(); + this.tableLayoutPanel3.SuspendLayout(); + this.tableLayoutPanel4.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.diffuseShareUpDown)).BeginInit(); + this.tableLayoutPanel2.SuspendLayout(); + this.SuspendLayout(); + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel1.ColumnCount = 3; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel12, 2, 3); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel11, 1, 3); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel9, 2, 2); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel8, 1, 2); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel6, 2, 1); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel5, 1, 1); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel3, 2, 0); + this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 1, 0); + this.tableLayoutPanel1.Controls.Add(this.label5, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.label6, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.label7, 0, 3); + this.tableLayoutPanel1.Location = new System.Drawing.Point(11, 9); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 4; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 30F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(490, 549); + this.tableLayoutPanel1.TabIndex = 0; + // + // tableLayoutPanel12 + // + this.tableLayoutPanel12.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel12.ColumnCount = 1; + this.tableLayoutPanel12.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel12.Controls.Add(this.refractiveIndexUpDown, 0, 2); + this.tableLayoutPanel12.Controls.Add(this.tableLayoutPanel13, 0, 0); + this.tableLayoutPanel12.Controls.Add(this.refractiveShareUpDown, 0, 1); + this.tableLayoutPanel12.Location = new System.Drawing.Point(247, 385); + this.tableLayoutPanel12.Name = "tableLayoutPanel12"; + this.tableLayoutPanel12.RowCount = 3; + this.tableLayoutPanel12.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel12.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel12.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel12.Size = new System.Drawing.Size(240, 161); + this.tableLayoutPanel12.TabIndex = 11; + // + // refractiveIndexUpDown + // + this.refractiveIndexUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.refractiveIndexUpDown.DecimalPlaces = 2; + this.refractiveIndexUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 131072}); + this.refractiveIndexUpDown.Location = new System.Drawing.Point(3, 122); + this.refractiveIndexUpDown.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.refractiveIndexUpDown.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 131072}); + this.refractiveIndexUpDown.Name = "refractiveIndexUpDown"; + this.refractiveIndexUpDown.Size = new System.Drawing.Size(234, 23); + this.refractiveIndexUpDown.TabIndex = 2; + this.refractiveIndexUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.refractiveIndexUpDown.Value = new decimal(new int[] { + 15, + 0, + 0, + 65536}); + this.refractiveIndexUpDown.ValueChanged += new System.EventHandler(this.refractiveIndexUpDown_ValueChanged); + // + // tableLayoutPanel13 + // + this.tableLayoutPanel13.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel13.ColumnCount = 3; + this.tableLayoutPanel13.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel13.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel13.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel13.Controls.Add(this.refractiveTexture, 0, 0); + this.tableLayoutPanel13.Controls.Add(this.refractiveColor, 1, 0); + this.tableLayoutPanel13.Controls.Add(this.refractiveFile, 2, 0); + this.tableLayoutPanel13.Location = new System.Drawing.Point(3, 3); + this.tableLayoutPanel13.Name = "tableLayoutPanel13"; + this.tableLayoutPanel13.RowCount = 1; + this.tableLayoutPanel13.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel13.Size = new System.Drawing.Size(234, 47); + this.tableLayoutPanel13.TabIndex = 0; + // + // refractiveTexture + // + this.refractiveTexture.Anchor = System.Windows.Forms.AnchorStyles.None; + this.refractiveTexture.AutoSize = true; + this.refractiveTexture.Location = new System.Drawing.Point(14, 16); + this.refractiveTexture.Name = "refractiveTexture"; + this.refractiveTexture.Size = new System.Drawing.Size(49, 15); + this.refractiveTexture.TabIndex = 0; + this.refractiveTexture.Text = " "; + this.refractiveTexture.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // refractiveColor + // + this.refractiveColor.Anchor = System.Windows.Forms.AnchorStyles.None; + this.refractiveColor.Location = new System.Drawing.Point(81, 12); + this.refractiveColor.Name = "refractiveColor"; + this.refractiveColor.Size = new System.Drawing.Size(71, 23); + this.refractiveColor.TabIndex = 1; + this.refractiveColor.Text = "Color"; + this.refractiveColor.UseVisualStyleBackColor = true; + this.refractiveColor.Click += new System.EventHandler(this.refractiveColor_Click); + // + // refractiveFile + // + this.refractiveFile.Anchor = System.Windows.Forms.AnchorStyles.None; + this.refractiveFile.Location = new System.Drawing.Point(159, 12); + this.refractiveFile.Name = "refractiveFile"; + this.refractiveFile.Size = new System.Drawing.Size(72, 23); + this.refractiveFile.TabIndex = 2; + this.refractiveFile.Text = "File"; + this.refractiveFile.UseVisualStyleBackColor = true; + this.refractiveFile.Click += new System.EventHandler(this.refractiveFile_Click); + // + // refractiveShareUpDown + // + this.refractiveShareUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.refractiveShareUpDown.DecimalPlaces = 2; + this.refractiveShareUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 131072}); + this.refractiveShareUpDown.Location = new System.Drawing.Point(3, 68); + this.refractiveShareUpDown.Maximum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.refractiveShareUpDown.Name = "refractiveShareUpDown"; + this.refractiveShareUpDown.Size = new System.Drawing.Size(234, 23); + this.refractiveShareUpDown.TabIndex = 1; + this.refractiveShareUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.refractiveShareUpDown.ValueChanged += new System.EventHandler(this.refractiveShareUpDown_ValueChanged); + // + // tableLayoutPanel11 + // + this.tableLayoutPanel11.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel11.ColumnCount = 1; + this.tableLayoutPanel11.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel11.Controls.Add(this.label15, 0, 2); + this.tableLayoutPanel11.Controls.Add(this.label16, 0, 1); + this.tableLayoutPanel11.Controls.Add(this.label17, 0, 0); + this.tableLayoutPanel11.Location = new System.Drawing.Point(125, 385); + this.tableLayoutPanel11.Name = "tableLayoutPanel11"; + this.tableLayoutPanel11.RowCount = 3; + this.tableLayoutPanel11.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel11.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel11.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel11.Size = new System.Drawing.Size(116, 161); + this.tableLayoutPanel11.TabIndex = 10; + // + // label15 + // + this.label15.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label15.AutoSize = true; + this.label15.Location = new System.Drawing.Point(3, 126); + this.label15.Name = "label15"; + this.label15.Size = new System.Drawing.Size(110, 15); + this.label15.TabIndex = 3; + this.label15.Text = "Reflective Index"; + this.label15.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label16 + // + this.label16.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label16.AutoSize = true; + this.label16.Location = new System.Drawing.Point(3, 72); + this.label16.Name = "label16"; + this.label16.Size = new System.Drawing.Size(110, 15); + this.label16.TabIndex = 2; + this.label16.Text = "Share"; + this.label16.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label17 + // + this.label17.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label17.AutoSize = true; + this.label17.Location = new System.Drawing.Point(3, 19); + this.label17.Name = "label17"; + this.label17.Size = new System.Drawing.Size(110, 15); + this.label17.TabIndex = 1; + this.label17.Text = "Texture"; + this.label17.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // tableLayoutPanel9 + // + this.tableLayoutPanel9.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel9.ColumnCount = 1; + this.tableLayoutPanel9.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel9.Controls.Add(this.reflectiveDisturbanceUpDown, 0, 2); + this.tableLayoutPanel9.Controls.Add(this.tableLayoutPanel10, 0, 0); + this.tableLayoutPanel9.Controls.Add(this.reflectiveShareUpDown, 0, 1); + this.tableLayoutPanel9.Location = new System.Drawing.Point(247, 221); + this.tableLayoutPanel9.Name = "tableLayoutPanel9"; + this.tableLayoutPanel9.RowCount = 3; + this.tableLayoutPanel9.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel9.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel9.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel9.Size = new System.Drawing.Size(240, 158); + this.tableLayoutPanel9.TabIndex = 9; + // + // reflectiveDisturbanceUpDown + // + this.reflectiveDisturbanceUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.reflectiveDisturbanceUpDown.DecimalPlaces = 2; + this.reflectiveDisturbanceUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 131072}); + this.reflectiveDisturbanceUpDown.Location = new System.Drawing.Point(3, 119); + this.reflectiveDisturbanceUpDown.Maximum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.reflectiveDisturbanceUpDown.Name = "reflectiveDisturbanceUpDown"; + this.reflectiveDisturbanceUpDown.Size = new System.Drawing.Size(234, 23); + this.reflectiveDisturbanceUpDown.TabIndex = 2; + this.reflectiveDisturbanceUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.reflectiveDisturbanceUpDown.Value = new decimal(new int[] { + 5, + 0, + 0, + 65536}); + this.reflectiveDisturbanceUpDown.ValueChanged += new System.EventHandler(this.reflectiveDisturbanceUpDown_ValueChanged); + // + // tableLayoutPanel10 + // + this.tableLayoutPanel10.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel10.ColumnCount = 3; + this.tableLayoutPanel10.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel10.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel10.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel10.Controls.Add(this.reflectiveTexture, 0, 0); + this.tableLayoutPanel10.Controls.Add(this.reflectiveColor, 1, 0); + this.tableLayoutPanel10.Controls.Add(this.reflectiveFile, 2, 0); + this.tableLayoutPanel10.Location = new System.Drawing.Point(3, 3); + this.tableLayoutPanel10.Name = "tableLayoutPanel10"; + this.tableLayoutPanel10.RowCount = 1; + this.tableLayoutPanel10.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel10.Size = new System.Drawing.Size(234, 46); + this.tableLayoutPanel10.TabIndex = 0; + // + // reflectiveTexture + // + this.reflectiveTexture.Anchor = System.Windows.Forms.AnchorStyles.None; + this.reflectiveTexture.AutoSize = true; + this.reflectiveTexture.Location = new System.Drawing.Point(14, 15); + this.reflectiveTexture.Name = "reflectiveTexture"; + this.reflectiveTexture.Size = new System.Drawing.Size(49, 15); + this.reflectiveTexture.TabIndex = 0; + this.reflectiveTexture.Text = " "; + this.reflectiveTexture.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // reflectiveColor + // + this.reflectiveColor.Anchor = System.Windows.Forms.AnchorStyles.None; + this.reflectiveColor.Location = new System.Drawing.Point(81, 11); + this.reflectiveColor.Name = "reflectiveColor"; + this.reflectiveColor.Size = new System.Drawing.Size(71, 23); + this.reflectiveColor.TabIndex = 1; + this.reflectiveColor.Text = "Color"; + this.reflectiveColor.UseVisualStyleBackColor = true; + this.reflectiveColor.Click += new System.EventHandler(this.reflectiveColor_Click); + // + // reflectiveFile + // + this.reflectiveFile.Anchor = System.Windows.Forms.AnchorStyles.None; + this.reflectiveFile.Location = new System.Drawing.Point(159, 11); + this.reflectiveFile.Name = "reflectiveFile"; + this.reflectiveFile.Size = new System.Drawing.Size(72, 23); + this.reflectiveFile.TabIndex = 2; + this.reflectiveFile.Text = "File"; + this.reflectiveFile.UseVisualStyleBackColor = true; + this.reflectiveFile.Click += new System.EventHandler(this.reflectiveFile_Click); + // + // reflectiveShareUpDown + // + this.reflectiveShareUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.reflectiveShareUpDown.DecimalPlaces = 2; + this.reflectiveShareUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 131072}); + this.reflectiveShareUpDown.Location = new System.Drawing.Point(3, 66); + this.reflectiveShareUpDown.Maximum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.reflectiveShareUpDown.Name = "reflectiveShareUpDown"; + this.reflectiveShareUpDown.Size = new System.Drawing.Size(234, 23); + this.reflectiveShareUpDown.TabIndex = 1; + this.reflectiveShareUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.reflectiveShareUpDown.ValueChanged += new System.EventHandler(this.reflectiveShareUpDown_ValueChanged); + // + // tableLayoutPanel8 + // + this.tableLayoutPanel8.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel8.ColumnCount = 1; + this.tableLayoutPanel8.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel8.Controls.Add(this.label14, 0, 2); + this.tableLayoutPanel8.Controls.Add(this.label11, 0, 1); + this.tableLayoutPanel8.Controls.Add(this.label12, 0, 0); + this.tableLayoutPanel8.Location = new System.Drawing.Point(125, 221); + this.tableLayoutPanel8.Name = "tableLayoutPanel8"; + this.tableLayoutPanel8.RowCount = 3; + this.tableLayoutPanel8.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel8.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel8.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel8.Size = new System.Drawing.Size(116, 158); + this.tableLayoutPanel8.TabIndex = 8; + // + // label14 + // + this.label14.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label14.AutoSize = true; + this.label14.Location = new System.Drawing.Point(3, 123); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(110, 15); + this.label14.TabIndex = 3; + this.label14.Text = "Disturbance"; + this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label11 + // + this.label11.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label11.AutoSize = true; + this.label11.Location = new System.Drawing.Point(3, 70); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(110, 15); + this.label11.TabIndex = 2; + this.label11.Text = "Share"; + this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label12 + // + this.label12.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label12.AutoSize = true; + this.label12.Location = new System.Drawing.Point(3, 18); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(110, 15); + this.label12.TabIndex = 1; + this.label12.Text = "Texture"; + this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // tableLayoutPanel6 + // + this.tableLayoutPanel6.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel6.ColumnCount = 1; + this.tableLayoutPanel6.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel6.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel6.Controls.Add(this.tableLayoutPanel7, 0, 0); + this.tableLayoutPanel6.Controls.Add(this.emissiveShareUpDown, 0, 1); + this.tableLayoutPanel6.Location = new System.Drawing.Point(247, 112); + this.tableLayoutPanel6.Name = "tableLayoutPanel6"; + this.tableLayoutPanel6.RowCount = 2; + this.tableLayoutPanel6.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel6.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel6.Size = new System.Drawing.Size(240, 103); + this.tableLayoutPanel6.TabIndex = 7; + // + // tableLayoutPanel7 + // + this.tableLayoutPanel7.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel7.ColumnCount = 3; + this.tableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel7.Controls.Add(this.emissiveTexture, 0, 0); + this.tableLayoutPanel7.Controls.Add(this.emissiveColor, 1, 0); + this.tableLayoutPanel7.Controls.Add(this.emissiveFile, 2, 0); + this.tableLayoutPanel7.Location = new System.Drawing.Point(3, 3); + this.tableLayoutPanel7.Name = "tableLayoutPanel7"; + this.tableLayoutPanel7.RowCount = 1; + this.tableLayoutPanel7.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel7.Size = new System.Drawing.Size(234, 45); + this.tableLayoutPanel7.TabIndex = 0; + // + // emissiveTexture + // + this.emissiveTexture.Anchor = System.Windows.Forms.AnchorStyles.None; + this.emissiveTexture.AutoSize = true; + this.emissiveTexture.Location = new System.Drawing.Point(14, 15); + this.emissiveTexture.Name = "emissiveTexture"; + this.emissiveTexture.Size = new System.Drawing.Size(49, 15); + this.emissiveTexture.TabIndex = 0; + this.emissiveTexture.Text = " "; + this.emissiveTexture.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // emissiveColor + // + this.emissiveColor.Anchor = System.Windows.Forms.AnchorStyles.None; + this.emissiveColor.Location = new System.Drawing.Point(81, 11); + this.emissiveColor.Name = "emissiveColor"; + this.emissiveColor.Size = new System.Drawing.Size(71, 23); + this.emissiveColor.TabIndex = 1; + this.emissiveColor.Text = "Color"; + this.emissiveColor.UseVisualStyleBackColor = true; + this.emissiveColor.Click += new System.EventHandler(this.emissiveColor_Click); + // + // emissiveFile + // + this.emissiveFile.Anchor = System.Windows.Forms.AnchorStyles.None; + this.emissiveFile.Location = new System.Drawing.Point(159, 11); + this.emissiveFile.Name = "emissiveFile"; + this.emissiveFile.Size = new System.Drawing.Size(72, 23); + this.emissiveFile.TabIndex = 2; + this.emissiveFile.Text = "File"; + this.emissiveFile.UseVisualStyleBackColor = true; + this.emissiveFile.Click += new System.EventHandler(this.emissiveFile_Click); + // + // emissiveShareUpDown + // + this.emissiveShareUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.emissiveShareUpDown.DecimalPlaces = 2; + this.emissiveShareUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 131072}); + this.emissiveShareUpDown.Location = new System.Drawing.Point(3, 65); + this.emissiveShareUpDown.Maximum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.emissiveShareUpDown.Name = "emissiveShareUpDown"; + this.emissiveShareUpDown.Size = new System.Drawing.Size(234, 23); + this.emissiveShareUpDown.TabIndex = 1; + this.emissiveShareUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.emissiveShareUpDown.ValueChanged += new System.EventHandler(this.emissiveShareUpDown_ValueChanged); + // + // tableLayoutPanel5 + // + this.tableLayoutPanel5.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel5.ColumnCount = 1; + this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel5.Controls.Add(this.label8, 0, 1); + this.tableLayoutPanel5.Controls.Add(this.label9, 0, 0); + this.tableLayoutPanel5.Location = new System.Drawing.Point(125, 112); + this.tableLayoutPanel5.Name = "tableLayoutPanel5"; + this.tableLayoutPanel5.RowCount = 2; + this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel5.Size = new System.Drawing.Size(116, 103); + this.tableLayoutPanel5.TabIndex = 6; + // + // label8 + // + this.label8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(3, 69); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(110, 15); + this.label8.TabIndex = 2; + this.label8.Text = "Share"; + this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label9 + // + this.label9.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(3, 18); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(110, 15); + this.label9.TabIndex = 1; + this.label9.Text = "Texture"; + this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // tableLayoutPanel3 + // + this.tableLayoutPanel3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel3.ColumnCount = 1; + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel3.Controls.Add(this.tableLayoutPanel4, 0, 0); + this.tableLayoutPanel3.Controls.Add(this.diffuseShareUpDown, 0, 1); + this.tableLayoutPanel3.Location = new System.Drawing.Point(247, 3); + this.tableLayoutPanel3.Name = "tableLayoutPanel3"; + this.tableLayoutPanel3.RowCount = 2; + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel3.Size = new System.Drawing.Size(240, 103); + this.tableLayoutPanel3.TabIndex = 2; + // + // tableLayoutPanel4 + // + this.tableLayoutPanel4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel4.ColumnCount = 3; + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel4.Controls.Add(this.diffuseTexture, 0, 0); + this.tableLayoutPanel4.Controls.Add(this.diffuseColor, 1, 0); + this.tableLayoutPanel4.Controls.Add(this.diffuseFile, 2, 0); + this.tableLayoutPanel4.Location = new System.Drawing.Point(3, 3); + this.tableLayoutPanel4.Name = "tableLayoutPanel4"; + this.tableLayoutPanel4.RowCount = 1; + this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel4.Size = new System.Drawing.Size(234, 45); + this.tableLayoutPanel4.TabIndex = 0; + // + // diffuseTexture + // + this.diffuseTexture.Anchor = System.Windows.Forms.AnchorStyles.None; + this.diffuseTexture.AutoSize = true; + this.diffuseTexture.Location = new System.Drawing.Point(14, 15); + this.diffuseTexture.Name = "diffuseTexture"; + this.diffuseTexture.Size = new System.Drawing.Size(49, 15); + this.diffuseTexture.TabIndex = 0; + this.diffuseTexture.Text = " "; + this.diffuseTexture.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // diffuseColor + // + this.diffuseColor.Anchor = System.Windows.Forms.AnchorStyles.None; + this.diffuseColor.Location = new System.Drawing.Point(81, 11); + this.diffuseColor.Name = "diffuseColor"; + this.diffuseColor.Size = new System.Drawing.Size(71, 23); + this.diffuseColor.TabIndex = 1; + this.diffuseColor.Text = "Color"; + this.diffuseColor.UseVisualStyleBackColor = true; + this.diffuseColor.Click += new System.EventHandler(this.diffuseColor_Click); + // + // diffuseFile + // + this.diffuseFile.Anchor = System.Windows.Forms.AnchorStyles.None; + this.diffuseFile.Location = new System.Drawing.Point(159, 11); + this.diffuseFile.Name = "diffuseFile"; + this.diffuseFile.Size = new System.Drawing.Size(72, 23); + this.diffuseFile.TabIndex = 2; + this.diffuseFile.Text = "File"; + this.diffuseFile.UseVisualStyleBackColor = true; + this.diffuseFile.Click += new System.EventHandler(this.diffuseFile_Click); + // + // diffuseShareUpDown + // + this.diffuseShareUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.diffuseShareUpDown.DecimalPlaces = 2; + this.diffuseShareUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 131072}); + this.diffuseShareUpDown.Location = new System.Drawing.Point(3, 65); + this.diffuseShareUpDown.Maximum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.diffuseShareUpDown.Name = "diffuseShareUpDown"; + this.diffuseShareUpDown.Size = new System.Drawing.Size(234, 23); + this.diffuseShareUpDown.TabIndex = 1; + this.diffuseShareUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.diffuseShareUpDown.ValueChanged += new System.EventHandler(this.diffuseShareUpDown_ValueChanged); + // + // label1 + // + this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(3, 47); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(116, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Diffuse"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // tableLayoutPanel2 + // + this.tableLayoutPanel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel2.ColumnCount = 1; + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel2.Controls.Add(this.label3, 0, 1); + this.tableLayoutPanel2.Controls.Add(this.label2, 0, 0); + this.tableLayoutPanel2.Location = new System.Drawing.Point(125, 3); + this.tableLayoutPanel2.Name = "tableLayoutPanel2"; + this.tableLayoutPanel2.RowCount = 2; + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel2.Size = new System.Drawing.Size(116, 103); + this.tableLayoutPanel2.TabIndex = 1; + // + // label3 + // + this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(3, 69); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(110, 15); + this.label3.TabIndex = 2; + this.label3.Text = "Share"; + this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label2 + // + this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(3, 18); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(110, 15); + this.label2.TabIndex = 1; + this.label2.Text = "Texture"; + this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label5 + // + this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(3, 156); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(116, 15); + this.label5.TabIndex = 3; + this.label5.Text = "Emissive"; + this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label6 + // + this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(3, 292); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(116, 15); + this.label6.TabIndex = 4; + this.label6.Text = "Reflective"; + this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label7 + // + this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(3, 458); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(116, 15); + this.label7.TabIndex = 5; + this.label7.Text = "Refractive"; + this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // MaterialPanel + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.tableLayoutPanel1); + this.Name = "MaterialPanel"; + this.Size = new System.Drawing.Size(512, 568); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + this.tableLayoutPanel12.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.refractiveIndexUpDown)).EndInit(); + this.tableLayoutPanel13.ResumeLayout(false); + this.tableLayoutPanel13.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.refractiveShareUpDown)).EndInit(); + this.tableLayoutPanel11.ResumeLayout(false); + this.tableLayoutPanel11.PerformLayout(); + this.tableLayoutPanel9.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.reflectiveDisturbanceUpDown)).EndInit(); + this.tableLayoutPanel10.ResumeLayout(false); + this.tableLayoutPanel10.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.reflectiveShareUpDown)).EndInit(); + this.tableLayoutPanel8.ResumeLayout(false); + this.tableLayoutPanel8.PerformLayout(); + this.tableLayoutPanel6.ResumeLayout(false); + this.tableLayoutPanel7.ResumeLayout(false); + this.tableLayoutPanel7.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.emissiveShareUpDown)).EndInit(); + this.tableLayoutPanel5.ResumeLayout(false); + this.tableLayoutPanel5.PerformLayout(); + this.tableLayoutPanel3.ResumeLayout(false); + this.tableLayoutPanel4.ResumeLayout(false); + this.tableLayoutPanel4.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.diffuseShareUpDown)).EndInit(); + this.tableLayoutPanel2.ResumeLayout(false); + this.tableLayoutPanel2.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel12; + private System.Windows.Forms.NumericUpDown refractiveIndexUpDown; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel13; + private System.Windows.Forms.Label refractiveTexture; + private System.Windows.Forms.Button refractiveColor; + private System.Windows.Forms.Button refractiveFile; + private System.Windows.Forms.NumericUpDown refractiveShareUpDown; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel11; + private System.Windows.Forms.Label label15; + private System.Windows.Forms.Label label16; + private System.Windows.Forms.Label label17; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel9; + private System.Windows.Forms.NumericUpDown reflectiveDisturbanceUpDown; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel10; + private System.Windows.Forms.Label reflectiveTexture; + private System.Windows.Forms.Button reflectiveColor; + private System.Windows.Forms.Button reflectiveFile; + private System.Windows.Forms.NumericUpDown reflectiveShareUpDown; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel8; + private System.Windows.Forms.Label label14; + private System.Windows.Forms.Label label11; + private System.Windows.Forms.Label label12; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel6; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel7; + private System.Windows.Forms.Label emissiveTexture; + private System.Windows.Forms.Button emissiveColor; + private System.Windows.Forms.Button emissiveFile; + private System.Windows.Forms.NumericUpDown emissiveShareUpDown; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel5; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel4; + private System.Windows.Forms.Label diffuseTexture; + private System.Windows.Forms.Button diffuseColor; + private System.Windows.Forms.Button diffuseFile; + private System.Windows.Forms.NumericUpDown diffuseShareUpDown; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.ColorDialog colorDialog; + } +} diff --git a/RayTracerApp/Panels/MaterialPanel.cs b/RayTracerApp/Panels/MaterialPanel.cs new file mode 100644 index 0000000..cb20e2e --- /dev/null +++ b/RayTracerApp/Panels/MaterialPanel.cs @@ -0,0 +1,206 @@ +using RayTracerApp.SceneController; +using RayTracing.Materials; +using RayTracing.Maths; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Text; +using System.Windows.Forms; + +namespace RayTracerApp.Panels +{ + public partial class MaterialPanel : UserControl, IPanelBase + { + public MaterialPanel() + { + InitializeComponent(); + } + + public IObjectController Controller { get; set; } + + public void UpdateForModel() + { + + } + + public void UpdateFromModel() + { + var material = Controller.Material; + refractiveIndexUpDown.Value = (decimal)material.Refractive.RefractiveIndex; + reflectiveDisturbanceUpDown.Value = (decimal)material.Reflective.Disturbance; + diffuseShareUpDown.Value = (decimal)material.Parts.diffuse; + reflectiveShareUpDown.Value = (decimal)material.Parts.reflective; + refractiveShareUpDown.Value = (decimal)material.Parts.refractive; + emissiveShareUpDown.Value = (decimal)material.Parts.emissive; + } + + private string ChooseTexture() + { + string filePath = ""; + using (OpenFileDialog openFileDialog = new OpenFileDialog()) + { + openFileDialog.InitialDirectory = Path.Combine(Application.StartupPath, "../.."); + openFileDialog.Filter = + "All types|*.jpg;*.jpeg;*.png;*.bmp;*.tga|" + + "jpg (*.jpg, *.jpeg)|*.jpg;*.jpeg|" + + "png (*.png)|*.png|" + + "bmp (*.bmp)|*.bmp|" + + "tga (*.tga)|*.tga"; + + openFileDialog.FilterIndex = 1; + openFileDialog.RestoreDirectory = true; + + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + filePath = openFileDialog.FileName; + } + } + return filePath; + } + + private void diffuseFile_Click(object sender, EventArgs e) + { + var texturePath = ChooseTexture(); + if (string.IsNullOrEmpty(texturePath)) return; + + Controller.Material.Diffuse.Albedo = new Texture(texturePath); + diffuseTexture.BackColor = this.BackColor; + diffuseTexture.Text = texturePath.Split(Path.DirectorySeparatorChar)[^1]; + } + + private void emissiveFile_Click(object sender, EventArgs e) + { + var texturePath = ChooseTexture(); + if (string.IsNullOrEmpty(texturePath)) return; + + Controller.Material.Emissive.Emit = new Texture(texturePath); + emissiveTexture.BackColor = this.BackColor; + emissiveTexture.Text = texturePath.Split(Path.DirectorySeparatorChar)[^1]; + } + + private void reflectiveFile_Click(object sender, EventArgs e) + { + var texturePath = ChooseTexture(); + if (string.IsNullOrEmpty(texturePath)) return; + + Controller.Material.Reflective.Albedo = new Texture(texturePath); + reflectiveTexture.BackColor = this.BackColor; + reflectiveTexture.Text = texturePath.Split(Path.DirectorySeparatorChar)[^1]; + } + + private void refractiveFile_Click(object sender, EventArgs e) + { + var texturePath = ChooseTexture(); + if (string.IsNullOrEmpty(texturePath)) return; + + Controller.Material.Refractive.Albedo = new Texture(texturePath); + refractiveTexture.BackColor = this.BackColor; + refractiveTexture.Text = texturePath.Split(Path.DirectorySeparatorChar)[^1]; + } + + private void diffuseShareUpDown_ValueChanged(object sender, EventArgs e) + { + var nud = sender as NumericUpDown; + float val = (float)nud.Value; + + var parts = Controller.Material.Parts; + parts.diffuse = val; + Controller.Material.Parts = parts; + } + + private void emissiveShareUpDown_ValueChanged(object sender, EventArgs e) + { + var nud = sender as NumericUpDown; + float val = (float)nud.Value; + + var parts = Controller.Material.Parts; + parts.emissive = val; + Controller.Material.Parts = parts; + } + + private void reflectiveShareUpDown_ValueChanged(object sender, EventArgs e) + { + var nud = sender as NumericUpDown; + float val = (float)nud.Value; + + var parts = Controller.Material.Parts; + parts.reflective = val; + Controller.Material.Parts = parts; + } + + private void reflectiveDisturbanceUpDown_ValueChanged(object sender, EventArgs e) + { + var nud = sender as NumericUpDown; + float val = (float)nud.Value; + + Controller.Material.Reflective.Disturbance = val; + } + + private void refractiveShareUpDown_ValueChanged(object sender, EventArgs e) + { + var nud = sender as NumericUpDown; + float val = (float)nud.Value; + + var parts = Controller.Material.Parts; + parts.refractive = val; + Controller.Material.Parts = parts; + } + + private void refractiveIndexUpDown_ValueChanged(object sender, EventArgs e) + { + var nud = sender as NumericUpDown; + float val = (float)nud.Value; + + Controller.Material.Refractive.RefractiveIndex = val; + } + + private void diffuseColor_Click(object sender, EventArgs e) + { + if (colorDialog.ShowDialog() == DialogResult.OK) + { + var color = colorDialog.Color; + diffuseTexture.BackColor = color; + diffuseTexture.Text = " "; + + + Controller.Material.Diffuse.Albedo = new SolidColor(RayTracing.Maths.Color.FromSystemDrawing(color)); + } + } + + private void emissiveColor_Click(object sender, EventArgs e) + { + if (colorDialog.ShowDialog() == DialogResult.OK) + { + var color = colorDialog.Color; + emissiveTexture.BackColor = color; + emissiveTexture.Text = " "; + Controller.Material.Emissive.Emit = new SolidColor(RayTracing.Maths.Color.FromSystemDrawing(color)); + } + } + + private void reflectiveColor_Click(object sender, EventArgs e) + { + if (colorDialog.ShowDialog() == DialogResult.OK) + { + var color = colorDialog.Color; + reflectiveTexture.BackColor = color; + reflectiveTexture.Text = " "; + Controller.Material.Reflective.Albedo = new SolidColor(RayTracing.Maths.Color.FromSystemDrawing(color)); + } + } + + private void refractiveColor_Click(object sender, EventArgs e) + { + if (colorDialog.ShowDialog() == DialogResult.OK) + { + var color = colorDialog.Color; + refractiveTexture.BackColor = color; + refractiveTexture.Text = " "; + Controller.Material.Refractive.Albedo = new SolidColor(RayTracing.Maths.Color.FromSystemDrawing(color)); + } + } + } +} diff --git a/RayTracerApp/Forms/Menu/EditorForm.resx b/RayTracerApp/Panels/MaterialPanel.resx similarity index 100% rename from RayTracerApp/Forms/Menu/EditorForm.resx rename to RayTracerApp/Panels/MaterialPanel.resx diff --git a/RayTracerApp/Panels/ObjectSelectionPanel.Designer.cs b/RayTracerApp/Panels/ObjectSelectionPanel.Designer.cs new file mode 100644 index 0000000..67fd47e --- /dev/null +++ b/RayTracerApp/Panels/ObjectSelectionPanel.Designer.cs @@ -0,0 +1,154 @@ + +namespace RayTracerApp.Panels +{ + partial class ObjectSelectionPanel + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panel1 = new System.Windows.Forms.Panel(); + this.rectangleRadioButton = new System.Windows.Forms.RadioButton(); + this.planeRadioButton = new System.Windows.Forms.RadioButton(); + this.customModelRadioButton = new System.Windows.Forms.RadioButton(); + this.cylinderRadioButton = new System.Windows.Forms.RadioButton(); + this.cubeRadioButton = new System.Windows.Forms.RadioButton(); + this.sphereRadioButton = new System.Windows.Forms.RadioButton(); + this.panel1.SuspendLayout(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel1.Controls.Add(this.rectangleRadioButton); + this.panel1.Controls.Add(this.planeRadioButton); + this.panel1.Controls.Add(this.customModelRadioButton); + this.panel1.Controls.Add(this.cylinderRadioButton); + this.panel1.Controls.Add(this.cubeRadioButton); + this.panel1.Controls.Add(this.sphereRadioButton); + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(350, 415); + this.panel1.TabIndex = 0; + // + // rectangleRadioButton + // + this.rectangleRadioButton.AutoSize = true; + this.rectangleRadioButton.Location = new System.Drawing.Point(9, 116); + this.rectangleRadioButton.Name = "rectangleRadioButton"; + this.rectangleRadioButton.Size = new System.Drawing.Size(77, 19); + this.rectangleRadioButton.TabIndex = 5; + this.rectangleRadioButton.TabStop = true; + this.rectangleRadioButton.Text = "Rectangle"; + this.rectangleRadioButton.UseVisualStyleBackColor = true; + this.rectangleRadioButton.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged); + // + // planeRadioButton + // + this.planeRadioButton.AutoSize = true; + this.planeRadioButton.Location = new System.Drawing.Point(9, 91); + this.planeRadioButton.Name = "planeRadioButton"; + this.planeRadioButton.Size = new System.Drawing.Size(54, 19); + this.planeRadioButton.TabIndex = 4; + this.planeRadioButton.TabStop = true; + this.planeRadioButton.Text = "Plane"; + this.planeRadioButton.UseVisualStyleBackColor = true; + this.planeRadioButton.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged); + // + // customModelRadioButton + // + this.customModelRadioButton.AutoSize = true; + this.customModelRadioButton.Location = new System.Drawing.Point(9, 141); + this.customModelRadioButton.Name = "customModelRadioButton"; + this.customModelRadioButton.Size = new System.Drawing.Size(104, 19); + this.customModelRadioButton.TabIndex = 3; + this.customModelRadioButton.TabStop = true; + this.customModelRadioButton.Text = "Custom model"; + this.customModelRadioButton.UseVisualStyleBackColor = true; + this.customModelRadioButton.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged); + // + // cylinderRadioButton + // + this.cylinderRadioButton.AutoSize = true; + this.cylinderRadioButton.Location = new System.Drawing.Point(9, 66); + this.cylinderRadioButton.Name = "cylinderRadioButton"; + this.cylinderRadioButton.Size = new System.Drawing.Size(69, 19); + this.cylinderRadioButton.TabIndex = 2; + this.cylinderRadioButton.TabStop = true; + this.cylinderRadioButton.Text = "Cylinder"; + this.cylinderRadioButton.UseVisualStyleBackColor = true; + this.cylinderRadioButton.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged); + // + // cubeRadioButton + // + this.cubeRadioButton.AutoSize = true; + this.cubeRadioButton.Location = new System.Drawing.Point(9, 41); + this.cubeRadioButton.Name = "cubeRadioButton"; + this.cubeRadioButton.Size = new System.Drawing.Size(53, 19); + this.cubeRadioButton.TabIndex = 1; + this.cubeRadioButton.TabStop = true; + this.cubeRadioButton.Text = "Cube"; + this.cubeRadioButton.UseVisualStyleBackColor = true; + this.cubeRadioButton.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged); + // + // sphereRadioButton + // + this.sphereRadioButton.AutoSize = true; + this.sphereRadioButton.Location = new System.Drawing.Point(9, 16); + this.sphereRadioButton.Name = "sphereRadioButton"; + this.sphereRadioButton.Size = new System.Drawing.Size(61, 19); + this.sphereRadioButton.TabIndex = 0; + this.sphereRadioButton.TabStop = true; + this.sphereRadioButton.Text = "Sphere"; + this.sphereRadioButton.UseVisualStyleBackColor = true; + this.sphereRadioButton.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged); + // + // ObjectSelectionPanel + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.panel1); + this.Name = "ObjectSelectionPanel"; + this.Size = new System.Drawing.Size(350, 415); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.RadioButton rectangleRadioButton; + private System.Windows.Forms.RadioButton planeRadioButton; + private System.Windows.Forms.RadioButton customModelRadioButton; + private System.Windows.Forms.RadioButton cylinderRadioButton; + private System.Windows.Forms.RadioButton cubeRadioButton; + private System.Windows.Forms.RadioButton sphereRadioButton; + } +} diff --git a/RayTracerApp/Panels/ObjectSelectionPanel.cs b/RayTracerApp/Panels/ObjectSelectionPanel.cs new file mode 100644 index 0000000..b79af5a --- /dev/null +++ b/RayTracerApp/Panels/ObjectSelectionPanel.cs @@ -0,0 +1,65 @@ +using RayTracerApp.SceneController; +using RayTracing.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using Rectangle = RayTracing.Models.Rectangle; + +namespace RayTracerApp.Panels +{ + public partial class ObjectSelectionPanel : UserControl, IPanelBase + { + public ObjectSelectionPanel() + { + InitializeComponent(); + } + + public IObjectController Controller { get; set; } + + public void UpdateForModel() + { + } + + public void UpdateFromModel() + { + } + + private void RadioButton_CheckedChanged(object sender, EventArgs e) + { + var rb = sender as RadioButton; + + if (rb == null) + { + MessageBox.Show("Sender is not a RadioButton"); + return; + } + + if (rb.Checked) + switch (rb.Text) + { + case "Sphere": + Controller.SetModel(new Sphere().Load()); + break; + case "Cube": + Controller.SetModel(new Cube().Load()); + break; + case "Cylinder": + Controller.SetModel(new Cylinder().Load()); + break; + case "Plane": + Controller.SetModel(new Plane().Load()); + break; + case "Rectangle": + Controller.SetModel(new Rectangle(1f).Load()); + break; + case "Custom model": + Controller.SetModel(new CustomModel()); + break; + } + } + } +} diff --git a/RayTracerApp/Controls/FeaturesPanel.resx b/RayTracerApp/Panels/ObjectSelectionPanel.resx similarity index 97% rename from RayTracerApp/Controls/FeaturesPanel.resx rename to RayTracerApp/Panels/ObjectSelectionPanel.resx index b5ae26c..f298a7b 100644 --- a/RayTracerApp/Controls/FeaturesPanel.resx +++ b/RayTracerApp/Panels/ObjectSelectionPanel.resx @@ -1,60 +1,60 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/RayTracerApp/Panels/PositionPanel.Designer.cs b/RayTracerApp/Panels/PositionPanel.Designer.cs new file mode 100644 index 0000000..dfd56c0 --- /dev/null +++ b/RayTracerApp/Panels/PositionPanel.Designer.cs @@ -0,0 +1,442 @@ + +namespace RayTracerApp.Panels +{ + partial class PositionPanel + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); + this.zUpDown = new System.Windows.Forms.NumericUpDown(); + this.yUpDown = new System.Windows.Forms.NumericUpDown(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.xUpDown = new System.Windows.Forms.NumericUpDown(); + this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); + this.rollUpDown = new System.Windows.Forms.NumericUpDown(); + this.yawUpDown = new System.Windows.Forms.NumericUpDown(); + this.label7 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.pitchUpDown = new System.Windows.Forms.NumericUpDown(); + this.scaleUpDown = new System.Windows.Forms.NumericUpDown(); + this.tableLayoutPanel1.SuspendLayout(); + this.tableLayoutPanel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.zUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.yUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.xUpDown)).BeginInit(); + this.tableLayoutPanel3.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.rollUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.yawUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pitchUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.scaleUpDown)).BeginInit(); + this.SuspendLayout(); + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel1.ColumnCount = 2; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.label2, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.label3, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 1, 0); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel3, 1, 1); + this.tableLayoutPanel1.Controls.Add(this.scaleUpDown, 1, 2); + this.tableLayoutPanel1.Location = new System.Drawing.Point(11, 13); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 3; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(402, 490); + this.tableLayoutPanel1.TabIndex = 0; + // + // label1 + // + this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(3, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(195, 163); + this.label1.TabIndex = 0; + this.label1.Text = "Translation"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label2 + // + this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(3, 163); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(195, 163); + this.label2.TabIndex = 1; + this.label2.Text = "Rotation"; + this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label3 + // + this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(3, 326); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(195, 164); + this.label3.TabIndex = 2; + this.label3.Text = "Scale"; + this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // tableLayoutPanel2 + // + this.tableLayoutPanel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel2.ColumnCount = 2; + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel2.Controls.Add(this.zUpDown, 1, 2); + this.tableLayoutPanel2.Controls.Add(this.yUpDown, 1, 1); + this.tableLayoutPanel2.Controls.Add(this.label4, 0, 0); + this.tableLayoutPanel2.Controls.Add(this.label5, 0, 1); + this.tableLayoutPanel2.Controls.Add(this.label6, 0, 2); + this.tableLayoutPanel2.Controls.Add(this.xUpDown, 1, 0); + this.tableLayoutPanel2.Location = new System.Drawing.Point(204, 3); + this.tableLayoutPanel2.Name = "tableLayoutPanel2"; + this.tableLayoutPanel2.RowCount = 3; + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel2.Size = new System.Drawing.Size(195, 157); + this.tableLayoutPanel2.TabIndex = 3; + // + // zUpDown + // + this.zUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.zUpDown.DecimalPlaces = 2; + this.zUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + this.zUpDown.Location = new System.Drawing.Point(100, 119); + this.zUpDown.Minimum = new decimal(new int[] { + 100, + 0, + 0, + -2147483648}); + this.zUpDown.Name = "zUpDown"; + this.zUpDown.Size = new System.Drawing.Size(92, 23); + this.zUpDown.TabIndex = 5; + this.zUpDown.ValueChanged += new System.EventHandler(this.zUpDown_ValueChanged); + // + // yUpDown + // + this.yUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.yUpDown.DecimalPlaces = 2; + this.yUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + this.yUpDown.Location = new System.Drawing.Point(100, 66); + this.yUpDown.Minimum = new decimal(new int[] { + 100, + 0, + 0, + -2147483648}); + this.yUpDown.Name = "yUpDown"; + this.yUpDown.Size = new System.Drawing.Size(92, 23); + this.yUpDown.TabIndex = 4; + this.yUpDown.ValueChanged += new System.EventHandler(this.yUpDown_ValueChanged); + // + // label4 + // + this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(3, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(91, 52); + this.label4.TabIndex = 0; + this.label4.Text = "X"; + this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label5 + // + this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(3, 52); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(91, 52); + this.label5.TabIndex = 1; + this.label5.Text = "Y"; + this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label6 + // + this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(3, 104); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(91, 53); + this.label6.TabIndex = 2; + this.label6.Text = "Z"; + this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // xUpDown + // + this.xUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.xUpDown.DecimalPlaces = 2; + this.xUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + this.xUpDown.Location = new System.Drawing.Point(100, 14); + this.xUpDown.Minimum = new decimal(new int[] { + 100, + 0, + 0, + -2147483648}); + this.xUpDown.Name = "xUpDown"; + this.xUpDown.Size = new System.Drawing.Size(92, 23); + this.xUpDown.TabIndex = 3; + this.xUpDown.ValueChanged += new System.EventHandler(this.xUpDown_ValueChanged); + // + // tableLayoutPanel3 + // + this.tableLayoutPanel3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel3.ColumnCount = 2; + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel3.Controls.Add(this.rollUpDown, 1, 2); + this.tableLayoutPanel3.Controls.Add(this.yawUpDown, 1, 1); + this.tableLayoutPanel3.Controls.Add(this.label7, 0, 0); + this.tableLayoutPanel3.Controls.Add(this.label8, 0, 1); + this.tableLayoutPanel3.Controls.Add(this.label9, 0, 2); + this.tableLayoutPanel3.Controls.Add(this.pitchUpDown, 1, 0); + this.tableLayoutPanel3.Location = new System.Drawing.Point(204, 166); + this.tableLayoutPanel3.Name = "tableLayoutPanel3"; + this.tableLayoutPanel3.RowCount = 3; + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel3.Size = new System.Drawing.Size(195, 157); + this.tableLayoutPanel3.TabIndex = 4; + // + // rollUpDown + // + this.rollUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.rollUpDown.DecimalPlaces = 2; + this.rollUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + this.rollUpDown.Location = new System.Drawing.Point(100, 119); + this.rollUpDown.Minimum = new decimal(new int[] { + 100, + 0, + 0, + -2147483648}); + this.rollUpDown.Name = "rollUpDown"; + this.rollUpDown.Size = new System.Drawing.Size(92, 23); + this.rollUpDown.TabIndex = 5; + this.rollUpDown.ValueChanged += new System.EventHandler(this.rollUpDown_ValueChanged); + // + // yawUpDown + // + this.yawUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.yawUpDown.DecimalPlaces = 2; + this.yawUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + this.yawUpDown.Location = new System.Drawing.Point(100, 66); + this.yawUpDown.Minimum = new decimal(new int[] { + 100, + 0, + 0, + -2147483648}); + this.yawUpDown.Name = "yawUpDown"; + this.yawUpDown.Size = new System.Drawing.Size(92, 23); + this.yawUpDown.TabIndex = 4; + this.yawUpDown.ValueChanged += new System.EventHandler(this.yawUpDown_ValueChanged); + // + // label7 + // + this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(3, 0); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(91, 52); + this.label7.TabIndex = 0; + this.label7.Text = "Pitch"; + this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label8 + // + this.label8.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(3, 52); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(91, 52); + this.label8.TabIndex = 1; + this.label8.Text = "Yaw"; + this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label9 + // + this.label9.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(3, 104); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(91, 53); + this.label9.TabIndex = 2; + this.label9.Text = "Roll"; + this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // pitchUpDown + // + this.pitchUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.pitchUpDown.DecimalPlaces = 2; + this.pitchUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + this.pitchUpDown.Location = new System.Drawing.Point(100, 14); + this.pitchUpDown.Minimum = new decimal(new int[] { + 100, + 0, + 0, + -2147483648}); + this.pitchUpDown.Name = "pitchUpDown"; + this.pitchUpDown.Size = new System.Drawing.Size(92, 23); + this.pitchUpDown.TabIndex = 3; + this.pitchUpDown.ValueChanged += new System.EventHandler(this.pitchUpDown_ValueChanged); + // + // scaleUpDown + // + this.scaleUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.scaleUpDown.DecimalPlaces = 2; + this.scaleUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + this.scaleUpDown.Location = new System.Drawing.Point(204, 396); + this.scaleUpDown.Minimum = new decimal(new int[] { + 100, + 0, + 0, + -2147483648}); + this.scaleUpDown.Name = "scaleUpDown"; + this.scaleUpDown.Size = new System.Drawing.Size(195, 23); + this.scaleUpDown.TabIndex = 6; + this.scaleUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.scaleUpDown.Value = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.scaleUpDown.ValueChanged += new System.EventHandler(this.scaleUpDown_ValueChanged); + // + // PositionPanel + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.tableLayoutPanel1); + this.Name = "PositionPanel"; + this.Size = new System.Drawing.Size(424, 513); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + this.tableLayoutPanel2.ResumeLayout(false); + this.tableLayoutPanel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.zUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.yUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.xUpDown)).EndInit(); + this.tableLayoutPanel3.ResumeLayout(false); + this.tableLayoutPanel3.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.rollUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.yawUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pitchUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.scaleUpDown)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; + private System.Windows.Forms.NumericUpDown zUpDown; + private System.Windows.Forms.NumericUpDown yUpDown; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.NumericUpDown xUpDown; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3; + private System.Windows.Forms.NumericUpDown rollUpDown; + private System.Windows.Forms.NumericUpDown yawUpDown; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.NumericUpDown pitchUpDown; + private System.Windows.Forms.NumericUpDown scaleUpDown; + } +} diff --git a/RayTracerApp/Panels/PositionPanel.cs b/RayTracerApp/Panels/PositionPanel.cs new file mode 100644 index 0000000..66bddff --- /dev/null +++ b/RayTracerApp/Panels/PositionPanel.cs @@ -0,0 +1,93 @@ +using RayTracerApp.SceneController; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace RayTracerApp.Panels +{ + public partial class PositionPanel : UserControl, IPanelBase + { + public PositionPanel() + { + InitializeComponent(); + } + + public IObjectController Controller { get; set; } + + public void UpdateForModel() + { + } + + public void UpdateFromModel() + { + var model = Controller.GetModel(); + scaleUpDown.Value = (decimal)model.Scale; + + rollUpDown.Value = (decimal)model.Rotation.Z; + yawUpDown.Value = (decimal)model.Rotation.Y; + pitchUpDown.Value = (decimal)model.Rotation.X; + + xUpDown.Value = (decimal)model.Position.X; + yUpDown.Value = (decimal)model.Position.Y; + zUpDown.Value = (decimal)model.Position.Z; + } + + private void zUpDown_ValueChanged(object sender, EventArgs e) + { + var nud = sender as NumericUpDown; + var pos = Controller.GetModel().Position; + pos.Z = (float)nud.Value; + Controller.GetModel().Position = pos; + } + + private void yUpDown_ValueChanged(object sender, EventArgs e) + { + var nud = sender as NumericUpDown; + var pos = Controller.GetModel().Position; + pos.Y = (float)nud.Value; + Controller.GetModel().Position = pos; + } + + private void xUpDown_ValueChanged(object sender, EventArgs e) + { + var nud = sender as NumericUpDown; + var pos = Controller.GetModel().Position; + pos.X = (float)nud.Value; + Controller.GetModel().Position = pos; + } + + private void pitchUpDown_ValueChanged(object sender, EventArgs e) + { + var nud = sender as NumericUpDown; + var rotation = Controller.GetModel().Rotation; + rotation.X = (float)nud.Value; + Controller.GetModel().Rotation = rotation; + } + + private void yawUpDown_ValueChanged(object sender, EventArgs e) + { + var nud = sender as NumericUpDown; + var rotation = Controller.GetModel().Rotation; + rotation.Y = (float)nud.Value; + Controller.GetModel().Rotation = rotation; + } + + private void rollUpDown_ValueChanged(object sender, EventArgs e) + { + var nud = sender as NumericUpDown; + var rotation = Controller.GetModel().Rotation; + rotation.Z = (float)nud.Value; + Controller.GetModel().Rotation = rotation; + } + + private void scaleUpDown_ValueChanged(object sender, EventArgs e) + { + var nud = sender as NumericUpDown; + Controller.GetModel().Scale = (float)nud.Value; + } + } +} diff --git a/RayTracerApp/Controls/PositionPanel.resx b/RayTracerApp/Panels/PositionPanel.resx similarity index 97% rename from RayTracerApp/Controls/PositionPanel.resx rename to RayTracerApp/Panels/PositionPanel.resx index b5ae26c..f298a7b 100644 --- a/RayTracerApp/Controls/PositionPanel.resx +++ b/RayTracerApp/Panels/PositionPanel.resx @@ -1,60 +1,60 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/RayTracerApp/RayTracerApp.csproj b/RayTracerApp/RayTracerApp.csproj index 67d88b0..94e0a57 100644 --- a/RayTracerApp/RayTracerApp.csproj +++ b/RayTracerApp/RayTracerApp.csproj @@ -19,21 +19,11 @@ - - UserControl - - - - UserControl - True True Resources.resx - - Form - diff --git a/RayTracerApp/SceneController/IObjectController.cs b/RayTracerApp/SceneController/IObjectController.cs new file mode 100644 index 0000000..bdc6aef --- /dev/null +++ b/RayTracerApp/SceneController/IObjectController.cs @@ -0,0 +1,20 @@ +using RayTracing.Materials; +using RayTracing.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace RayTracerApp.SceneController +{ + public interface IObjectController + { + public MasterMaterial Material + { + get; + set; + } + void DeleteModel(); + void SetModel(Model model); + Model GetModel(); + } +} diff --git a/RayTracerApp/SceneController/ObjectController.cs b/RayTracerApp/SceneController/ObjectController.cs new file mode 100644 index 0000000..7a1054c --- /dev/null +++ b/RayTracerApp/SceneController/ObjectController.cs @@ -0,0 +1,62 @@ +using RayTracing.Materials; +using RayTracing.Models; +using RayTracing.World; +using System; +using System.Collections.Generic; +using System.Text; + +namespace RayTracerApp.SceneController +{ + public class ObjectController : IObjectController + { + protected Model model; + protected Scene scene; + protected MasterMaterial _material; + public MasterMaterial Material + { + get => _material; + set => _material = value; + } + + public ObjectController(Scene scene) + { + this.scene = scene; + } + + public ObjectController(Scene scene, Model model) + { + this.scene = scene; + this.model = model; + Material = (MasterMaterial)model.Material; + } + + public void DeleteModel() + { + if (model != null) + { + scene.Models.Remove(model); + model = null; + } + } + public Model GetModel() + { + return model; + } + + public void SetModel(Model model) + { + DeleteModel(); + this.model = model; + if (Material == null) + { + Material = (MasterMaterial)model.Material; + } + else + { + model.Material = Material; + } + + if (this.model != null) scene.AddModel(this.model); + } + } +} diff --git a/RayTracerApp/SceneControllers/EditObjectController.cs b/RayTracerApp/SceneControllers/EditObjectController.cs deleted file mode 100644 index a96e71c..0000000 --- a/RayTracerApp/SceneControllers/EditObjectController.cs +++ /dev/null @@ -1,17 +0,0 @@ -using RayTracing.Models; -using RayTracing.World; -using System; -using System.Collections.Generic; -using System.Text; - -namespace RayTracerApp.SceneControllers -{ - class EditObjectController : ObjectController - { - public EditObjectController(Scene scene, Model model) - { - this.scene = scene; - this.model = model; - } - } -} diff --git a/RayTracerApp/SceneControllers/IController.cs b/RayTracerApp/SceneControllers/IController.cs deleted file mode 100644 index ff923ab..0000000 --- a/RayTracerApp/SceneControllers/IController.cs +++ /dev/null @@ -1,14 +0,0 @@ -using RayTracing.Models; -using System; -using System.Collections.Generic; -using System.Text; - -namespace RayTracerApp.SceneControllers -{ - public interface IController : IDisposable - { - void SetModel(Model model); - Model GetModel(); - void DeleteModel(); - } -} diff --git a/RayTracerApp/SceneControllers/NewObjectController.cs b/RayTracerApp/SceneControllers/NewObjectController.cs deleted file mode 100644 index 906b882..0000000 --- a/RayTracerApp/SceneControllers/NewObjectController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using RayTracing.Models; -using RayTracing.World; -using System; -using System.Collections.Generic; -using System.Text; - -namespace RayTracerApp.SceneControllers -{ - class NewObjectController : ObjectController - { - public NewObjectController(Scene scene) - { - this.scene = scene; - } - } -} diff --git a/RayTracerApp/SceneControllers/ObjectController.cs b/RayTracerApp/SceneControllers/ObjectController.cs deleted file mode 100644 index 965aee4..0000000 --- a/RayTracerApp/SceneControllers/ObjectController.cs +++ /dev/null @@ -1,38 +0,0 @@ -using RayTracing.Models; -using RayTracing.World; - -namespace RayTracerApp.SceneControllers -{ - internal class ObjectController : IController - { - protected Model model; - protected Scene scene; - - public void DeleteModel() - { - if (model != null) - { - scene.Models.Remove(model); - model = null; - } - } - - public void Dispose() - { - scene = null; - model = null; - } - - public Model GetModel() - { - return model; - } - - public void SetModel(Model model) - { - DeleteModel(); - this.model = model; - if (this.model != null) scene.AddModel(this.model); - } - } -} \ No newline at end of file From 1db1f3dc2322c90ac5a72e291cbbaec8865b4d88 Mon Sep 17 00:00:00 2001 From: p-flis Date: Wed, 6 Jan 2021 02:39:08 +0100 Subject: [PATCH 09/31] more ui --- RayTracerApp/Forms/MainForm.cs | 4 +- RayTracerApp/Panels/MaterialPanel.cs | 54 ++++++++++++++++++-------- RayTracerApp/Utils/TextureConverter.cs | 20 ++++++++++ 3 files changed, 60 insertions(+), 18 deletions(-) create mode 100644 RayTracerApp/Utils/TextureConverter.cs diff --git a/RayTracerApp/Forms/MainForm.cs b/RayTracerApp/Forms/MainForm.cs index 0010f4e..0ba13c3 100644 --- a/RayTracerApp/Forms/MainForm.cs +++ b/RayTracerApp/Forms/MainForm.cs @@ -24,7 +24,7 @@ public partial class MainForm : Form private const int SWAP_TIME = 2; private Scene _scene = new Scene(); private IRenderer _renderer; - private Camera _camera = new PerspectiveCamera(new Vector3(0, 0, 20)) {AspectRatio = 1}; + private Camera _camera = new OrthographicCamera(new Vector3(0, 0, 20)) {AspectRatio = 1}; private CameraController _cameraController; private IncrementalRayTracer _rayTracer; private BackgroundWorker _backgroundWorker; @@ -191,6 +191,8 @@ private void newObjectButton_Click(object sender, EventArgs e) private void editObjectButton_Click(object sender, EventArgs e) { + UpdateLastModification(); + _scene.Preprocess(); var ray = _camera.GetRay(0.5f, 0.5f); var hitInfo = new HitInfo(); _isUiUsed = true; diff --git a/RayTracerApp/Panels/MaterialPanel.cs b/RayTracerApp/Panels/MaterialPanel.cs index cb20e2e..3ab1d42 100644 --- a/RayTracerApp/Panels/MaterialPanel.cs +++ b/RayTracerApp/Panels/MaterialPanel.cs @@ -1,4 +1,5 @@ using RayTracerApp.SceneController; +using RayTracerApp.Utils; using RayTracing.Materials; using RayTracing.Maths; using System; @@ -29,6 +30,26 @@ public void UpdateForModel() public void UpdateFromModel() { var material = Controller.Material; + if (material.Diffuse.Albedo is Texture) + diffuseTexture.Image = TextureConverter.Convert(material.Diffuse.Albedo as Texture); + else + diffuseTexture.BackColor = material.Diffuse.Albedo[0, 0].ToSystemDrawing(); + + if (material.Emissive.Emit is Texture) + emissiveTexture.Image = TextureConverter.Convert(material.Emissive.Emit as Texture); + else + emissiveTexture.BackColor = material.Diffuse.Albedo[0, 0].ToSystemDrawing(); + + if (material.Reflective.Albedo is Texture) + reflectiveTexture.Image = TextureConverter.Convert(material.Reflective.Albedo as Texture); + else + reflectiveTexture.BackColor = material.Diffuse.Albedo[0, 0].ToSystemDrawing(); + + if (material.Refractive.Albedo is Texture) + refractiveTexture.Image = TextureConverter.Convert(material.Refractive.Albedo as Texture); + else + refractiveTexture.BackColor = material.Diffuse.Albedo[0, 0].ToSystemDrawing(); + refractiveIndexUpDown.Value = (decimal)material.Refractive.RefractiveIndex; reflectiveDisturbanceUpDown.Value = (decimal)material.Reflective.Disturbance; diffuseShareUpDown.Value = (decimal)material.Parts.diffuse; @@ -66,9 +87,9 @@ private void diffuseFile_Click(object sender, EventArgs e) var texturePath = ChooseTexture(); if (string.IsNullOrEmpty(texturePath)) return; - Controller.Material.Diffuse.Albedo = new Texture(texturePath); - diffuseTexture.BackColor = this.BackColor; - diffuseTexture.Text = texturePath.Split(Path.DirectorySeparatorChar)[^1]; + var texture = new Texture(texturePath); + Controller.Material.Diffuse.Albedo = texture; + diffuseTexture.Image = TextureConverter.Convert(texture); } private void emissiveFile_Click(object sender, EventArgs e) @@ -76,9 +97,9 @@ private void emissiveFile_Click(object sender, EventArgs e) var texturePath = ChooseTexture(); if (string.IsNullOrEmpty(texturePath)) return; - Controller.Material.Emissive.Emit = new Texture(texturePath); - emissiveTexture.BackColor = this.BackColor; - emissiveTexture.Text = texturePath.Split(Path.DirectorySeparatorChar)[^1]; + var texture = new Texture(texturePath); + Controller.Material.Emissive.Emit = texture; + emissiveTexture.Image = TextureConverter.Convert(texture); } private void reflectiveFile_Click(object sender, EventArgs e) @@ -86,9 +107,9 @@ private void reflectiveFile_Click(object sender, EventArgs e) var texturePath = ChooseTexture(); if (string.IsNullOrEmpty(texturePath)) return; - Controller.Material.Reflective.Albedo = new Texture(texturePath); - reflectiveTexture.BackColor = this.BackColor; - reflectiveTexture.Text = texturePath.Split(Path.DirectorySeparatorChar)[^1]; + var texture = new Texture(texturePath); + Controller.Material.Reflective.Albedo = texture; + reflectiveTexture.Image = TextureConverter.Convert(texture); } private void refractiveFile_Click(object sender, EventArgs e) @@ -96,9 +117,9 @@ private void refractiveFile_Click(object sender, EventArgs e) var texturePath = ChooseTexture(); if (string.IsNullOrEmpty(texturePath)) return; - Controller.Material.Refractive.Albedo = new Texture(texturePath); - refractiveTexture.BackColor = this.BackColor; - refractiveTexture.Text = texturePath.Split(Path.DirectorySeparatorChar)[^1]; + var texture = new Texture(texturePath); + Controller.Material.Refractive.Albedo = texture; + refractiveTexture.Image = TextureConverter.Convert(texture); } private void diffuseShareUpDown_ValueChanged(object sender, EventArgs e) @@ -163,8 +184,7 @@ private void diffuseColor_Click(object sender, EventArgs e) { var color = colorDialog.Color; diffuseTexture.BackColor = color; - diffuseTexture.Text = " "; - + diffuseTexture.Image = null; Controller.Material.Diffuse.Albedo = new SolidColor(RayTracing.Maths.Color.FromSystemDrawing(color)); } @@ -176,7 +196,7 @@ private void emissiveColor_Click(object sender, EventArgs e) { var color = colorDialog.Color; emissiveTexture.BackColor = color; - emissiveTexture.Text = " "; + emissiveTexture.Image = null; Controller.Material.Emissive.Emit = new SolidColor(RayTracing.Maths.Color.FromSystemDrawing(color)); } } @@ -187,7 +207,7 @@ private void reflectiveColor_Click(object sender, EventArgs e) { var color = colorDialog.Color; reflectiveTexture.BackColor = color; - reflectiveTexture.Text = " "; + reflectiveTexture.Image = null; Controller.Material.Reflective.Albedo = new SolidColor(RayTracing.Maths.Color.FromSystemDrawing(color)); } } @@ -198,7 +218,7 @@ private void refractiveColor_Click(object sender, EventArgs e) { var color = colorDialog.Color; refractiveTexture.BackColor = color; - refractiveTexture.Text = " "; + refractiveTexture.Image = null; Controller.Material.Refractive.Albedo = new SolidColor(RayTracing.Maths.Color.FromSystemDrawing(color)); } } diff --git a/RayTracerApp/Utils/TextureConverter.cs b/RayTracerApp/Utils/TextureConverter.cs new file mode 100644 index 0000000..4b99052 --- /dev/null +++ b/RayTracerApp/Utils/TextureConverter.cs @@ -0,0 +1,20 @@ +using System.Drawing; +using RayTracing.Materials; + +namespace RayTracerApp.Utils +{ + public static class TextureConverter + { + public static Image Convert(Texture texture) + { + var result = new Bitmap(texture.Width, texture.Height); + for (int i = 0; i < texture.Width; i++) + for (int j = 0; j < texture.Height; j++) + { + result.SetPixel(i, j, texture[i, j].ToSystemDrawing()); + } + + return result; + } + } +} \ No newline at end of file From 7e3dda7ac22ecda2d4f7c5fef91f351614c2a8b6 Mon Sep 17 00:00:00 2001 From: p-flis Date: Wed, 6 Jan 2021 02:51:10 +0100 Subject: [PATCH 10/31] bvh cylinder fix --- RayTracer/Source/World/Scene.cs | 2 +- RayTracerApp/Forms/MainForm.cs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/RayTracer/Source/World/Scene.cs b/RayTracer/Source/World/Scene.cs index d448c4c..2d5d1f4 100644 --- a/RayTracer/Source/World/Scene.cs +++ b/RayTracer/Source/World/Scene.cs @@ -69,7 +69,7 @@ private List BvhPreprocess() var hittablesToBvh = new List(); foreach (var model in Models) { - if (model is Plane) + if (model is Plane || model is Cylinder) { planes.Add(model); } diff --git a/RayTracerApp/Forms/MainForm.cs b/RayTracerApp/Forms/MainForm.cs index 0ba13c3..1d84eeb 100644 --- a/RayTracerApp/Forms/MainForm.cs +++ b/RayTracerApp/Forms/MainForm.cs @@ -24,7 +24,7 @@ public partial class MainForm : Form private const int SWAP_TIME = 2; private Scene _scene = new Scene(); private IRenderer _renderer; - private Camera _camera = new OrthographicCamera(new Vector3(0, 0, 20)) {AspectRatio = 1}; + private Camera _camera = new PerspectiveCamera(new Vector3(0, 0, 20)) {AspectRatio = 1}; private CameraController _cameraController; private IncrementalRayTracer _rayTracer; private BackgroundWorker _backgroundWorker; @@ -82,8 +82,9 @@ private void GLControl_Load(object sender, EventArgs e) _scene.AddModel(new Cylinder(2) { Position = new Vector3(5f, 0.5f, 4), Scale = 1, - Material = new MasterMaterial(new Diffuse(new Texture("wood.jpg"))) - }.Load()); + Material = new MasterMaterial(new Diffuse(new Texture("wood.jpg"))), + Rotation = Vector3.One * (float)Math.PI / 3 + }.Load()); ; _scene.AddModel(new Cube() { Position = new Vector3(0, 0.5f, -3), Scale = 1, From 503f0704c8f41b2439925287d0bb027fa0ce9a1b Mon Sep 17 00:00:00 2001 From: p-flis Date: Wed, 6 Jan 2021 13:40:21 +0100 Subject: [PATCH 11/31] bvh no bvh-able models bugfix --- RayTracer/Source/World/Scene.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/RayTracer/Source/World/Scene.cs b/RayTracer/Source/World/Scene.cs index 2d5d1f4..6684559 100644 --- a/RayTracer/Source/World/Scene.cs +++ b/RayTracer/Source/World/Scene.cs @@ -79,9 +79,12 @@ private List BvhPreprocess() } } - var node = new BvhNode(hittablesToBvh, 0, hittablesToBvh.Count); Hittables.AddRange(planes); - Hittables.Add(node); + if (hittablesToBvh != null && hittablesToBvh.Count > 0) + { + var node = new BvhNode(hittablesToBvh, 0, hittablesToBvh.Count); + Hittables.Add(node); + } return Hittables; } From af9764259639862f03401d29e461dc290a98cfc0 Mon Sep 17 00:00:00 2001 From: p-flis Date: Wed, 6 Jan 2021 15:55:40 +0100 Subject: [PATCH 12/31] even more ui --- RayTracer/Source/Cameras/Camera.cs | 2 +- RayTracer/Source/Materials/MasterMaterial.cs | 8 ++- RayTracer/Source/Models/Cube.cs | 5 ++ RayTracer/Source/Models/CustomModel.cs | 5 ++ RayTracer/Source/Models/Cylinder.cs | 5 ++ RayTracer/Source/Models/Plane.cs | 5 ++ RayTracer/Source/Models/Rectangle.cs | 5 ++ RayTracer/Source/Models/Sphere.cs | 5 ++ .../Source/Renderer/IncrementalRayTracer.cs | 3 +- RayTracer/Source/Renderer/Renderer.cs | 32 +++++++--- RayTracer/Source/Renderer/SamplesRayTracer.cs | 29 +++++---- RayTracer/Source/World/Scene.cs | 11 ++-- RayTracerApp/Forms/EditObjectForm.cs | 7 +- RayTracerApp/Forms/MainForm.Designer.cs | 11 +++- RayTracerApp/Forms/MainForm.cs | 52 +++++++++++++-- RayTracerApp/Forms/NewObjectForm.cs | 32 ++++++++-- RayTracerApp/Forms/SettingsForm.Designer.cs | 64 +++++++++++++++++++ RayTracerApp/Forms/SettingsForm.cs | 18 ++++++ RayTracerApp/Forms/SettingsForm.resx | 60 +++++++++++++++++ RayTracerApp/Panels/FeaturesPanel.cs | 12 ++++ RayTracerApp/Panels/MaterialPanel.Designer.cs | 1 + RayTracerApp/Panels/MaterialPanel.cs | 16 +++-- .../Panels/ObjectSelectionPanel.Designer.cs | 6 +- RayTracerApp/Panels/ObjectSelectionPanel.cs | 3 + RayTracerApp/Panels/PositionPanel.cs | 20 +++++- .../SceneController/IObjectController.cs | 3 + .../SceneController/ObjectController.cs | 6 ++ 27 files changed, 371 insertions(+), 55 deletions(-) create mode 100644 RayTracerApp/Forms/SettingsForm.Designer.cs create mode 100644 RayTracerApp/Forms/SettingsForm.cs create mode 100644 RayTracerApp/Forms/SettingsForm.resx diff --git a/RayTracer/Source/Cameras/Camera.cs b/RayTracer/Source/Cameras/Camera.cs index 637041b..e0904d9 100644 --- a/RayTracer/Source/Cameras/Camera.cs +++ b/RayTracer/Source/Cameras/Camera.cs @@ -6,7 +6,7 @@ namespace RayTracing.Cameras { public abstract class Camera { - protected Vector3 Front { get; set; } = -Vector3.UnitZ; + public Vector3 Front { get; protected set; } = -Vector3.UnitZ; protected Vector3 Up { get; set; } = Vector3.UnitY; protected Vector3 Right { get; set; } = Vector3.UnitX; protected float Pitch { get; set; } diff --git a/RayTracer/Source/Materials/MasterMaterial.cs b/RayTracer/Source/Materials/MasterMaterial.cs index fb09bdc..0fc7a11 100644 --- a/RayTracer/Source/Materials/MasterMaterial.cs +++ b/RayTracer/Source/Materials/MasterMaterial.cs @@ -111,9 +111,11 @@ public Color Emitted(float u, float v) public void Use(Shader shader, float part) { - Emissive.Use(shader, Parts.emissive); - Diffuse.Use(shader, Parts.diffuse); - Reflective.Use(shader, Parts.reflective); + var sum = Parts.diffuse + Parts.emissive + Parts.reflective + Parts.refractive; + if (sum == 0) sum = 1; + Emissive.Use(shader, Parts.emissive / sum); + Diffuse.Use(shader, Parts.diffuse / sum); + Reflective.Use(shader, Parts.reflective / sum); } } } \ No newline at end of file diff --git a/RayTracer/Source/Models/Cube.cs b/RayTracer/Source/Models/Cube.cs index bc66050..c2728bf 100644 --- a/RayTracer/Source/Models/Cube.cs +++ b/RayTracer/Source/Models/Cube.cs @@ -127,5 +127,10 @@ public override List Preprocess() { return MeshToTriangles(); } + + public override string ToString() + { + return "Cube"; + } } } \ No newline at end of file diff --git a/RayTracer/Source/Models/CustomModel.cs b/RayTracer/Source/Models/CustomModel.cs index fdb97b4..ade0d3b 100644 --- a/RayTracer/Source/Models/CustomModel.cs +++ b/RayTracer/Source/Models/CustomModel.cs @@ -43,5 +43,10 @@ public override List Preprocess() { return MeshToTriangles(); } + + public override string ToString() + { + return "Custom model"; + } } } \ No newline at end of file diff --git a/RayTracer/Source/Models/Cylinder.cs b/RayTracer/Source/Models/Cylinder.cs index bdd91ad..311a46d 100644 --- a/RayTracer/Source/Models/Cylinder.cs +++ b/RayTracer/Source/Models/Cylinder.cs @@ -321,5 +321,10 @@ private List GenIndices(int topCenterIndex, int baseCenterIndex) return indices; } + + public override string ToString() + { + return "Cylinder"; + } } } \ No newline at end of file diff --git a/RayTracer/Source/Models/Plane.cs b/RayTracer/Source/Models/Plane.cs index 690af4b..a7d162d 100644 --- a/RayTracer/Source/Models/Plane.cs +++ b/RayTracer/Source/Models/Plane.cs @@ -140,5 +140,10 @@ public override Mesh GetMesh() { return Mesh; } + + public override string ToString() + { + return "Plane"; + } } } \ No newline at end of file diff --git a/RayTracer/Source/Models/Rectangle.cs b/RayTracer/Source/Models/Rectangle.cs index 1d0636a..856c178 100644 --- a/RayTracer/Source/Models/Rectangle.cs +++ b/RayTracer/Source/Models/Rectangle.cs @@ -117,5 +117,10 @@ public override List Preprocess() { return MeshToTriangles(); } + + public override string ToString() + { + return "Rectangle"; + } } } \ No newline at end of file diff --git a/RayTracer/Source/Models/Sphere.cs b/RayTracer/Source/Models/Sphere.cs index 2c51067..ab5f1ec 100644 --- a/RayTracer/Source/Models/Sphere.cs +++ b/RayTracer/Source/Models/Sphere.cs @@ -124,5 +124,10 @@ private List GetIndices(short rings, short sectors) return indices; } + + public override string ToString() + { + return "Sphere"; + } } } \ No newline at end of file diff --git a/RayTracer/Source/Renderer/IncrementalRayTracer.cs b/RayTracer/Source/Renderer/IncrementalRayTracer.cs index 4e55203..6767058 100644 --- a/RayTracer/Source/Renderer/IncrementalRayTracer.cs +++ b/RayTracer/Source/Renderer/IncrementalRayTracer.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using OpenTK; using RayTracing.Cameras; using RayTracing.World; @@ -9,7 +10,7 @@ namespace RayTracing public abstract class IncrementalRayTracer : RayTracer, IRenderer { public Action OnFrameReady { get; set; } - public Func IsCancellationRequested { get; set; } + public CancellationToken CancellationToken { get; set; } public abstract void Render(Scene scene, Camera camera); public IncrementalRayTracer(int maxDepth, int samples, Func> sampling, int resolution) : diff --git a/RayTracer/Source/Renderer/Renderer.cs b/RayTracer/Source/Renderer/Renderer.cs index ac0d407..75504e7 100644 --- a/RayTracer/Source/Renderer/Renderer.cs +++ b/RayTracer/Source/Renderer/Renderer.cs @@ -1,6 +1,7 @@ using System; using OpenTK.Graphics.OpenGL4; using RayTracing.Cameras; +using RayTracing.Materials; using RayTracing.Shaders; using RayTracing.World; @@ -25,16 +26,8 @@ public void Render(Scene scene, Camera camera) _shader.SetVector3("ambientLight", ambient.ToVector3()); _shader.SetVector3("cameraPosition", camera.Position); - var lightsCount = Math.Min(MAX_LIGHTS, scene.Lights.Count); - _shader.SetInt("lightsCount", lightsCount); - for (int i = 0; i < lightsCount; i++) - { - var light = scene.Lights[i]; - _shader.SetVector3($"light[{i}].position", light.Position); - var color = light.Material.AverageColor; - _shader.SetVector3($"light[{i}].diffuse", color.ToVector3()); - } + AddLights(scene); foreach (var model in scene.Models) { if (!model.Loaded) continue; @@ -45,5 +38,26 @@ public void Render(Scene scene, Camera camera) model.GetMesh().Render(); } } + + private void AddLights(Scene scene) + { + var lightsCount = 0; + foreach (var model in scene.Models) + { + if (model.Material is Emissive || model.Material is MasterMaterial && + (model.Material as MasterMaterial).Parts.emissive != 0) + { + if (lightsCount < MAX_LIGHTS) + { + var light = model; + _shader.SetVector3($"light[{lightsCount}].position", light.Position); + var color = light.Material.AverageColor; + _shader.SetVector3($"light[{lightsCount}].diffuse", color.ToVector3()); + lightsCount++; + } + } + } + _shader.SetInt("lightsCount", lightsCount); + } } } \ No newline at end of file diff --git a/RayTracer/Source/Renderer/SamplesRayTracer.cs b/RayTracer/Source/Renderer/SamplesRayTracer.cs index c91e7ea..9b42cf2 100644 --- a/RayTracer/Source/Renderer/SamplesRayTracer.cs +++ b/RayTracer/Source/Renderer/SamplesRayTracer.cs @@ -30,20 +30,25 @@ public override void Render(Scene scene, Camera camera) for (int k = 0; k < Samples; k++) { - Parallel.For(0, width, i => + try { - if (IsCancellationRequested != null && IsCancellationRequested()) - return; - for (int j = 0; j < height; j++) + Parallel.For(0, width, new ParallelOptions {CancellationToken = CancellationToken }, i => { - var sample = sampler.GetSample(k); - float u = (i + sample.X) / (width - 1); - float v = (j + sample.Y) / (height - 1); - Ray ray = camera.GetRay(u, v); - image[i, j] += Shade(ray, scene, MaxDepth); - } - }); - if (IsCancellationRequested != null && IsCancellationRequested()) + for (int j = 0; j < height; j++) + { + var sample = sampler.GetSample(k); + float u = (i + sample.X) / (width - 1); + float v = (j + sample.Y) / (height - 1); + Ray ray = camera.GetRay(u, v); + image[i, j] += Shade(ray, scene, MaxDepth); + } + }); + } + catch(Exception) + { + return; + } + if (CancellationToken.IsCancellationRequested) return; if (k % _samplesRenderStep == 0 || k == Samples - 1) diff --git a/RayTracer/Source/World/Scene.cs b/RayTracer/Source/World/Scene.cs index 6684559..cfcc41c 100644 --- a/RayTracer/Source/World/Scene.cs +++ b/RayTracer/Source/World/Scene.cs @@ -14,17 +14,11 @@ public class Scene : IHittable public bool BvhMode { get; set; } = true; public List Models { get; } = new List(); public List Hittables { get; } = new List(); - public List Lights { get; } = new List(); public AmbientLight AmbientLight { get; set; } public void AddModel(Model model) { Models.Add(model); - if (model.Material is Emissive || model.Material is MasterMaterial && - (model.Material as MasterMaterial).Parts.emissive != 0) // add MasterMaterial - { - Lights.Add(model); - } } public bool HitTest(Ray ray, ref HitInfo hit, float from, float to) @@ -99,5 +93,10 @@ public List Preprocess() return StandardPreprocess(); } } + + public override string ToString() + { + return "Scene"; + } } } \ No newline at end of file diff --git a/RayTracerApp/Forms/EditObjectForm.cs b/RayTracerApp/Forms/EditObjectForm.cs index a3096d0..72d3142 100644 --- a/RayTracerApp/Forms/EditObjectForm.cs +++ b/RayTracerApp/Forms/EditObjectForm.cs @@ -22,6 +22,7 @@ public EditObjectForm(IObjectController controller) { InitializeComponent(); + FormClosed += EditObjectForm_FormClosed; rightNextButton.Click += nextButton_Click; middlePreviousButton.Click += previousButton_Click; leftCancelButton.Click += cancelButton_Click; @@ -57,6 +58,11 @@ public EditObjectForm(IObjectController controller) topLabel.Text = $"Edit {_controller.GetModel().GetType().Name.ToLower()}..."; } + private void EditObjectForm_FormClosed(object sender, FormClosedEventArgs e) + { + _controller?.GetScene()?.Preprocess(); + } + private void SetController(IObjectController controller) { _controller = controller; @@ -131,7 +137,6 @@ private void previousButton_Click(object sender, EventArgs e) private void cancelButton_Click(object sender, EventArgs e) { - Close(); } } diff --git a/RayTracerApp/Forms/MainForm.Designer.cs b/RayTracerApp/Forms/MainForm.Designer.cs index f3d6a05..663cde3 100644 --- a/RayTracerApp/Forms/MainForm.Designer.cs +++ b/RayTracerApp/Forms/MainForm.Designer.cs @@ -54,6 +54,7 @@ private void InitializeToolstrip() this.toolStrip = new System.Windows.Forms.ToolStrip(); this.newObjectButton = new System.Windows.Forms.ToolStripButton(); this.editObjectButton = new System.Windows.Forms.ToolStripButton(); + this.deleteObjectButton = new System.Windows.Forms.ToolStripButton(); this.toolStrip.SuspendLayout(); this.ddButton = new ToolStripDropDownButton(); @@ -61,7 +62,8 @@ private void InitializeToolstrip() this.ddButton.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.newObjectButton, - this.editObjectButton + this.editObjectButton, + this.deleteObjectButton }); this.toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -85,6 +87,12 @@ private void InitializeToolstrip() this.editObjectButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.editObjectButton.Click += new System.EventHandler(this.editObjectButton_Click); + this.deleteObjectButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.deleteObjectButton.Name = "deleteObjectButton"; + this.deleteObjectButton.Text = "Delete object"; + this.deleteObjectButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.deleteObjectButton.Click += new System.EventHandler(this.deleteObjectButton_Click); + this.Controls.Add(this.toolStrip); @@ -95,6 +103,7 @@ private void InitializeToolstrip() private ToolStrip toolStrip; private ToolStripButton newObjectButton; private ToolStripButton editObjectButton; + private ToolStripButton deleteObjectButton; private OpenTK.GLControl gLControl = new GLControl(new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8)); private ToolStripDropDownButton ddButton; diff --git a/RayTracerApp/Forms/MainForm.cs b/RayTracerApp/Forms/MainForm.cs index 1d84eeb..f0af8df 100644 --- a/RayTracerApp/Forms/MainForm.cs +++ b/RayTracerApp/Forms/MainForm.cs @@ -16,6 +16,7 @@ using Timer = System.Windows.Forms.Timer; using Color = RayTracing.Maths.Color; using RayTracerApp.SceneController; +using System.Threading; namespace RayTracerApp.Forms { @@ -28,6 +29,7 @@ public partial class MainForm : Form private CameraController _cameraController; private IncrementalRayTracer _rayTracer; private BackgroundWorker _backgroundWorker; + private CancellationTokenSource _cts; private Timer _fpsTimer = new Timer(); private long lastModification; private bool rayTracingStarted; @@ -38,6 +40,7 @@ public void UpdateLastModification() lastModification = DateTime.Now.Ticks / TimeSpan.TicksPerSecond; rayTracingStarted = false; _backgroundWorker?.CancelAsync(); + _cts?.Cancel(); } public bool ShouldRaytrace() @@ -106,7 +109,7 @@ private void GLControl_Load(object sender, EventArgs e) Parts = (0.0f, 0.8f, 0.1f, 0.0f) } }.Load()); - + _scene.Preprocess(); InitializeFpsTimer(); UpdateViewport(); } @@ -155,7 +158,7 @@ private void UpdateViewport() private void StartRender(object sender, DoWorkEventArgs e) { _rayTracer.OnFrameReady = _backgroundWorker.ReportProgress; - _rayTracer.IsCancellationRequested = () => _backgroundWorker.CancellationPending; + _rayTracer.CancellationToken = _cts.Token; _rayTracer.Render(_scene, _camera); } @@ -178,12 +181,26 @@ private void InitializeBackgroundWorker() }; _backgroundWorker.DoWork += StartRender; _backgroundWorker.ProgressChanged += BackgroundWorkerProgressChanged; + _cts = new CancellationTokenSource(); } private void newObjectButton_Click(object sender, EventArgs e) { UpdateLastModification(); - var form = new NewObjectForm(new ObjectController(_scene)) + var sphere = new Sphere().Load(); + var ray = _camera.GetRay(0.5f, 0.5f); + var hitInfo = new HitInfo(); + _isUiUsed = true; + if (_scene.HitTest(ray, ref hitInfo, 0.001f, float.PositiveInfinity) && hitInfo.Distance < 50) + { + sphere.Position = hitInfo.HitPoint; + } + else + { + sphere.Position = _camera.Position + _camera.Front.Normalized() * 4; + } + _scene.AddModel(sphere); + var form = new NewObjectForm(new ObjectController(_scene, sphere)) { StartPosition = FormStartPosition.Manual, Location = Location + Size / 3 }; _isUiUsed = true; form.Closed += FormOnClosed; @@ -193,7 +210,6 @@ private void newObjectButton_Click(object sender, EventArgs e) private void editObjectButton_Click(object sender, EventArgs e) { UpdateLastModification(); - _scene.Preprocess(); var ray = _camera.GetRay(0.5f, 0.5f); var hitInfo = new HitInfo(); _isUiUsed = true; @@ -221,7 +237,33 @@ private void editObjectButton_Click(object sender, EventArgs e) UpdateLastModification(); } } - + + private void deleteObjectButton_Click(object sender, EventArgs e) + { + UpdateLastModification(); + _isUiUsed = true; + var ray = _camera.GetRay(0.5f, 0.5f); + var hitInfo = new HitInfo(); + if (_scene.HitTest(ray, ref hitInfo, 0.001f, float.PositiveInfinity)) + { + var model = hitInfo.ModelHit; + if (model is Triangle triangle) model = triangle.Parent; + string message = + $"Are you sure that you would like to delete the {model.ToString()}?"; + const string caption = "Form Closing"; + var result = MessageBox.Show(message, caption, + MessageBoxButtons.YesNo, + MessageBoxIcon.Question); + + if (result == DialogResult.Yes) + { + _scene.Models.Remove(model); + _scene.Preprocess(); + } + } + _isUiUsed = false; + } + private void FormOnClosed(object? sender, EventArgs e) { _isUiUsed = false; diff --git a/RayTracerApp/Forms/NewObjectForm.cs b/RayTracerApp/Forms/NewObjectForm.cs index 8bd9021..5c9e98a 100644 --- a/RayTracerApp/Forms/NewObjectForm.cs +++ b/RayTracerApp/Forms/NewObjectForm.cs @@ -36,11 +36,26 @@ public NewObjectForm(IObjectController controller) _currentPanel = objectSelectionPanel; _currentPanel.Controller = _controller; topLabel.Text = "Add new object..."; + SetController(); + + controller.UpdateModelFromUI = () => { + ChooseOrder(); + UpdateForModel(); + materialPanel.UpdateFromModel(); + }; + ChooseOrder(); + foreach(var panel in _order) + { + panel.UpdateFromModel(); + } } private void SetController() { - foreach (var panel in _order) panel.Controller = _controller; + objectSelectionPanel.Controller = _controller; + featuresPanel.Controller = _controller; + positionPanel.Controller = _controller; + materialPanel.Controller = _controller; } private void ChooseOrder() @@ -53,6 +68,14 @@ private void ChooseOrder() _order = new List { objectSelectionPanel, positionPanel, materialPanel }; } + private void UpdateForModel() + { + foreach(var panel in _order) + { + panel.UpdateForModel(); + } + } + private void MoveNext() { var index = 0; @@ -60,14 +83,11 @@ private void MoveNext() if (index == 0) { - ChooseOrder(); - SetController(); - leftCancelButton.Visible = true; middlePreviousButton.Visible = true; middleCancelButton.Visible = false; - if (_controller.GetModel() is CustomModel) + if (_controller.GetModel().GetType() == typeof(CustomModel)) topLabel.Text = "Add custom model..."; else topLabel.Text = $"Add {_controller.GetModel().GetType().Name.ToLower()}..."; @@ -81,7 +101,6 @@ private void MoveNext() if (index < _order.Count - 1) { - _order[index + 1].UpdateForModel(); _order[index + 1].ShowPanel(); _order[index].HidePanel(); _currentPanel = _order[index + 1]; @@ -122,6 +141,7 @@ private void nextButton_Click(object sender, EventArgs e) private void finishButton_Click(object sender, EventArgs e) { + _controller.GetScene().Preprocess(); Close(); } diff --git a/RayTracerApp/Forms/SettingsForm.Designer.cs b/RayTracerApp/Forms/SettingsForm.Designer.cs new file mode 100644 index 0000000..4e21681 --- /dev/null +++ b/RayTracerApp/Forms/SettingsForm.Designer.cs @@ -0,0 +1,64 @@ + +namespace RayTracerApp.Forms +{ + partial class SettingsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.SuspendLayout(); + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 2; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.Location = new System.Drawing.Point(43, 53); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 2; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(200, 100); + this.tableLayoutPanel1.TabIndex = 0; + // + // SettingsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(467, 668); + this.Controls.Add(this.tableLayoutPanel1); + this.Name = "SettingsForm"; + this.Text = "SettingsForm"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + } +} \ No newline at end of file diff --git a/RayTracerApp/Forms/SettingsForm.cs b/RayTracerApp/Forms/SettingsForm.cs new file mode 100644 index 0000000..fdb153d --- /dev/null +++ b/RayTracerApp/Forms/SettingsForm.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace RayTracerApp.Forms +{ + public partial class SettingsForm : Form + { + public SettingsForm() + { + InitializeComponent(); + } + } +} diff --git a/RayTracerApp/Forms/SettingsForm.resx b/RayTracerApp/Forms/SettingsForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/RayTracerApp/Forms/SettingsForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RayTracerApp/Panels/FeaturesPanel.cs b/RayTracerApp/Panels/FeaturesPanel.cs index 30be6ac..d276c25 100644 --- a/RayTracerApp/Panels/FeaturesPanel.cs +++ b/RayTracerApp/Panels/FeaturesPanel.cs @@ -21,6 +21,18 @@ public FeaturesPanel() public void UpdateForModel() { + var model = Controller.GetModel(); + switch (model) + { + case Rectangle rectangle: + rectangle.AspectRatio = (float)aspectRatioUpDown.Value; + break; + case Cylinder cylinder: + cylinder.Aspect = (float)aspectRatioUpDown.Value; + break; + default: + throw new Exception("Bad model type"); + } } public void UpdateFromModel() diff --git a/RayTracerApp/Panels/MaterialPanel.Designer.cs b/RayTracerApp/Panels/MaterialPanel.Designer.cs index fe297eb..74fe24e 100644 --- a/RayTracerApp/Panels/MaterialPanel.Designer.cs +++ b/RayTracerApp/Panels/MaterialPanel.Designer.cs @@ -126,6 +126,7 @@ private void InitializeComponent() this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 30F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(490, 549); this.tableLayoutPanel1.TabIndex = 0; + this.tableLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.tableLayoutPanel1_Paint); // // tableLayoutPanel12 // diff --git a/RayTracerApp/Panels/MaterialPanel.cs b/RayTracerApp/Panels/MaterialPanel.cs index 3ab1d42..dc8f8c1 100644 --- a/RayTracerApp/Panels/MaterialPanel.cs +++ b/RayTracerApp/Panels/MaterialPanel.cs @@ -24,7 +24,7 @@ public MaterialPanel() public void UpdateForModel() { - + // done in Controller SetModel() } public void UpdateFromModel() @@ -38,17 +38,17 @@ public void UpdateFromModel() if (material.Emissive.Emit is Texture) emissiveTexture.Image = TextureConverter.Convert(material.Emissive.Emit as Texture); else - emissiveTexture.BackColor = material.Diffuse.Albedo[0, 0].ToSystemDrawing(); + emissiveTexture.BackColor = material.Emissive.Emit[0, 0].ToSystemDrawing(); if (material.Reflective.Albedo is Texture) reflectiveTexture.Image = TextureConverter.Convert(material.Reflective.Albedo as Texture); else - reflectiveTexture.BackColor = material.Diffuse.Albedo[0, 0].ToSystemDrawing(); + reflectiveTexture.BackColor = material.Reflective.Albedo[0, 0].ToSystemDrawing(); if (material.Refractive.Albedo is Texture) refractiveTexture.Image = TextureConverter.Convert(material.Refractive.Albedo as Texture); else - refractiveTexture.BackColor = material.Diffuse.Albedo[0, 0].ToSystemDrawing(); + refractiveTexture.BackColor = material.Refractive.Albedo[0, 0].ToSystemDrawing(); refractiveIndexUpDown.Value = (decimal)material.Refractive.RefractiveIndex; reflectiveDisturbanceUpDown.Value = (decimal)material.Reflective.Disturbance; @@ -222,5 +222,13 @@ private void refractiveColor_Click(object sender, EventArgs e) Controller.Material.Refractive.Albedo = new SolidColor(RayTracing.Maths.Color.FromSystemDrawing(color)); } } + + private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e) + { + var rectangle = e.ClipRectangle; + rectangle.Inflate(-1, -1); + + ControlPaint.DrawBorder3D(e.Graphics, rectangle, Border3DStyle.Raised, Border3DSide.All); + } } } diff --git a/RayTracerApp/Panels/ObjectSelectionPanel.Designer.cs b/RayTracerApp/Panels/ObjectSelectionPanel.Designer.cs index 67fd47e..561b15d 100644 --- a/RayTracerApp/Panels/ObjectSelectionPanel.Designer.cs +++ b/RayTracerApp/Panels/ObjectSelectionPanel.Designer.cs @@ -63,7 +63,6 @@ private void InitializeComponent() this.rectangleRadioButton.Name = "rectangleRadioButton"; this.rectangleRadioButton.Size = new System.Drawing.Size(77, 19); this.rectangleRadioButton.TabIndex = 5; - this.rectangleRadioButton.TabStop = true; this.rectangleRadioButton.Text = "Rectangle"; this.rectangleRadioButton.UseVisualStyleBackColor = true; this.rectangleRadioButton.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged); @@ -75,7 +74,6 @@ private void InitializeComponent() this.planeRadioButton.Name = "planeRadioButton"; this.planeRadioButton.Size = new System.Drawing.Size(54, 19); this.planeRadioButton.TabIndex = 4; - this.planeRadioButton.TabStop = true; this.planeRadioButton.Text = "Plane"; this.planeRadioButton.UseVisualStyleBackColor = true; this.planeRadioButton.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged); @@ -87,7 +85,6 @@ private void InitializeComponent() this.customModelRadioButton.Name = "customModelRadioButton"; this.customModelRadioButton.Size = new System.Drawing.Size(104, 19); this.customModelRadioButton.TabIndex = 3; - this.customModelRadioButton.TabStop = true; this.customModelRadioButton.Text = "Custom model"; this.customModelRadioButton.UseVisualStyleBackColor = true; this.customModelRadioButton.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged); @@ -99,7 +96,6 @@ private void InitializeComponent() this.cylinderRadioButton.Name = "cylinderRadioButton"; this.cylinderRadioButton.Size = new System.Drawing.Size(69, 19); this.cylinderRadioButton.TabIndex = 2; - this.cylinderRadioButton.TabStop = true; this.cylinderRadioButton.Text = "Cylinder"; this.cylinderRadioButton.UseVisualStyleBackColor = true; this.cylinderRadioButton.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged); @@ -111,7 +107,6 @@ private void InitializeComponent() this.cubeRadioButton.Name = "cubeRadioButton"; this.cubeRadioButton.Size = new System.Drawing.Size(53, 19); this.cubeRadioButton.TabIndex = 1; - this.cubeRadioButton.TabStop = true; this.cubeRadioButton.Text = "Cube"; this.cubeRadioButton.UseVisualStyleBackColor = true; this.cubeRadioButton.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged); @@ -119,6 +114,7 @@ private void InitializeComponent() // sphereRadioButton // this.sphereRadioButton.AutoSize = true; + this.sphereRadioButton.Checked = true; this.sphereRadioButton.Location = new System.Drawing.Point(9, 16); this.sphereRadioButton.Name = "sphereRadioButton"; this.sphereRadioButton.Size = new System.Drawing.Size(61, 19); diff --git a/RayTracerApp/Panels/ObjectSelectionPanel.cs b/RayTracerApp/Panels/ObjectSelectionPanel.cs index b79af5a..0a08cc4 100644 --- a/RayTracerApp/Panels/ObjectSelectionPanel.cs +++ b/RayTracerApp/Panels/ObjectSelectionPanel.cs @@ -39,6 +39,7 @@ private void RadioButton_CheckedChanged(object sender, EventArgs e) } if (rb.Checked) + { switch (rb.Text) { case "Sphere": @@ -60,6 +61,8 @@ private void RadioButton_CheckedChanged(object sender, EventArgs e) Controller.SetModel(new CustomModel()); break; } + Controller.UpdateModelFromUI(); + } } } } diff --git a/RayTracerApp/Panels/PositionPanel.cs b/RayTracerApp/Panels/PositionPanel.cs index 66bddff..0cde35c 100644 --- a/RayTracerApp/Panels/PositionPanel.cs +++ b/RayTracerApp/Panels/PositionPanel.cs @@ -1,4 +1,5 @@ -using RayTracerApp.SceneController; +using OpenTK; +using RayTracerApp.SceneController; using System; using System.Collections.Generic; using System.ComponentModel; @@ -20,6 +21,23 @@ public PositionPanel() public void UpdateForModel() { + var model = Controller.GetModel(); + model.Scale = (float)scaleUpDown.Value; + var rotation = new Vector3 + { + X = (float)yawUpDown.Value, + Y = (float)pitchUpDown.Value, + Z = (float)rollUpDown.Value + }; + model.Rotation = rotation; + + var position = new Vector3 + { + X = (float)xUpDown.Value, + Y = (float)yUpDown.Value, + Z = (float)zUpDown.Value + }; + model.Position = position; } public void UpdateFromModel() diff --git a/RayTracerApp/SceneController/IObjectController.cs b/RayTracerApp/SceneController/IObjectController.cs index bdc6aef..6af3dc2 100644 --- a/RayTracerApp/SceneController/IObjectController.cs +++ b/RayTracerApp/SceneController/IObjectController.cs @@ -1,5 +1,6 @@ using RayTracing.Materials; using RayTracing.Models; +using RayTracing.World; using System; using System.Collections.Generic; using System.Text; @@ -16,5 +17,7 @@ public MasterMaterial Material void DeleteModel(); void SetModel(Model model); Model GetModel(); + Scene GetScene(); + Action UpdateModelFromUI { get; set; } } } diff --git a/RayTracerApp/SceneController/ObjectController.cs b/RayTracerApp/SceneController/ObjectController.cs index 7a1054c..268b2a0 100644 --- a/RayTracerApp/SceneController/ObjectController.cs +++ b/RayTracerApp/SceneController/ObjectController.cs @@ -17,6 +17,7 @@ public MasterMaterial Material get => _material; set => _material = value; } + public Action UpdateModelFromUI { get; set; } public ObjectController(Scene scene) { @@ -58,5 +59,10 @@ public void SetModel(Model model) if (this.model != null) scene.AddModel(this.model); } + + public Scene GetScene() + { + return scene; + } } } From 45c78499f6e650885918824a93cfe20e5036565e Mon Sep 17 00:00:00 2001 From: p-flis Date: Wed, 6 Jan 2021 20:21:19 +0100 Subject: [PATCH 13/31] it's ui again --- RayTracerApp/Forms/MainForm.Designer.cs | 94 ++++- RayTracerApp/Forms/MainForm.cs | 90 +++- RayTracerApp/Forms/MainForm.resx | 62 +-- RayTracerApp/Forms/SettingsForm.Designer.cs | 438 +++++++++++++++++++- RayTracerApp/Forms/TestForm.Designer.cs | 87 ++++ RayTracerApp/Forms/TestForm.cs | 18 + RayTracerApp/Forms/TestForm.resx | 60 +++ RayTracerApp/Panels/FeaturesPanel.cs | 2 + 8 files changed, 770 insertions(+), 81 deletions(-) create mode 100644 RayTracerApp/Forms/TestForm.Designer.cs create mode 100644 RayTracerApp/Forms/TestForm.cs create mode 100644 RayTracerApp/Forms/TestForm.resx diff --git a/RayTracerApp/Forms/MainForm.Designer.cs b/RayTracerApp/Forms/MainForm.Designer.cs index 663cde3..0f73543 100644 --- a/RayTracerApp/Forms/MainForm.Designer.cs +++ b/RayTracerApp/Forms/MainForm.Designer.cs @@ -43,12 +43,96 @@ private void InitializeComponent() this.gLControl.TabIndex = 0; this.gLControl.VSync = true; this.gLControl.Load += new System.EventHandler(this.GLControl_Load); + + this.FormClosed += MainForm_FormClosed; + this.Resize += this.OnResize; this.Controls.Add(this.gLControl); + InitializeToolstrip(); + InitializeNewEditDeleteMenu(); + InitializeNewEditMenu(); this.ResumeLayout(false); } + + private void InitializeNewEditDeleteMenu() + { + int width = 150; + this.addItem1 = new ToolStripMenuItem(); + this.addItem1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.addItem1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.addItem1.Text = "Add object"; + this.addItem1.Name = "AddObject1"; + this.addItem1.Size = new System.Drawing.Size(width, 22); + this.addItem1.Click += AddItem_Click; + + this.editItem1 = new ToolStripMenuItem(); + this.editItem1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.editItem1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.editItem1.Text = "Edit object"; + this.editItem1.Name = "EditObject1"; + this.editItem1.Size = new System.Drawing.Size(width, 22); + this.editItem1.Click += EditItem_Click; + + this.deleteItem1 = new ToolStripMenuItem(); + this.deleteItem1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.deleteItem1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.deleteItem1.Text = "Delete object"; + this.deleteItem1.Name = "DeleteObject1"; + this.deleteItem1.Size = new System.Drawing.Size(width, 22); + this.deleteItem1.Click += DeleteItem_Click; + + this.newDeleteStrip = new ContextMenuStrip(components); + this.newDeleteStrip.SuspendLayout(); + this.newDeleteStrip.AutoSize = false; + this.newDeleteStrip.Name = "newDeleteMenu"; + this.newDeleteStrip.TabIndex = 2; + this.newDeleteStrip.Text = "newDeleteMenu"; + this.newDeleteStrip.Items.Add(addItem1); + this.newDeleteStrip.Items.Add(editItem1); + this.newDeleteStrip.Items.Add(deleteItem1); + + this.newDeleteStrip.Size = new System.Drawing.Size(width+1, 70); + + this.newDeleteStrip.ResumeLayout(false); + this.PerformLayout(); + } + + private void InitializeNewEditMenu() + { + int width = 150; + this.addItem2 = new ToolStripMenuItem(); + this.addItem2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.addItem2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.addItem2.Text = "Add object"; + this.addItem2.Name = "AddObject2"; + this.addItem2.Size = new System.Drawing.Size(width, 22); + this.addItem2.Click += AddItem_Click; + + this.editItem2 = new ToolStripMenuItem(); + this.editItem2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.editItem2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.editItem2.Text = "Edit object"; + this.editItem2.Name = "EditObject2"; + this.editItem2.Size = new System.Drawing.Size(width, 22); + this.editItem2.Click += EditItem_Click; + + this.newEditStrip = new ContextMenuStrip(components); + this.newEditStrip.SuspendLayout(); + this.newEditStrip.AutoSize = false; + this.newEditStrip.Name = "newEditMenu"; + this.newEditStrip.TabIndex = 3; + this.newEditStrip.Text = "newEditMenu"; + this.newEditStrip.Items.Add(addItem2); + this.newEditStrip.Items.Add(editItem2); + + this.newEditStrip.Size = new System.Drawing.Size(width+1, 48); + + this.newEditStrip.ResumeLayout(false); + this.PerformLayout(); + } + private void InitializeToolstrip() { this.toolStrip = new System.Windows.Forms.ToolStrip(); @@ -72,7 +156,7 @@ private void InitializeToolstrip() this.toolStrip.Location = new System.Drawing.Point(0, 0); this.toolStrip.Name = "toolStrip"; - this.toolStrip.TabIndex = 0; + this.toolStrip.TabIndex = 1; this.toolStrip.Text = "toolStrip"; this.newObjectButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; @@ -93,7 +177,6 @@ private void InitializeToolstrip() this.deleteObjectButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.deleteObjectButton.Click += new System.EventHandler(this.deleteObjectButton_Click); - this.Controls.Add(this.toolStrip); this.toolStrip.ResumeLayout(false); @@ -106,6 +189,13 @@ private void InitializeToolstrip() private ToolStripButton deleteObjectButton; private OpenTK.GLControl gLControl = new GLControl(new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8)); private ToolStripDropDownButton ddButton; + private ContextMenuStrip newDeleteStrip; + private ToolStripMenuItem addItem1; + private ToolStripMenuItem editItem1; + private ToolStripMenuItem deleteItem1; + private ToolStripMenuItem addItem2; + private ToolStripMenuItem editItem2; + private ContextMenuStrip newEditStrip; #endregion } diff --git a/RayTracerApp/Forms/MainForm.cs b/RayTracerApp/Forms/MainForm.cs index f0af8df..e0a43af 100644 --- a/RayTracerApp/Forms/MainForm.cs +++ b/RayTracerApp/Forms/MainForm.cs @@ -35,6 +35,9 @@ public partial class MainForm : Form private bool rayTracingStarted; private bool _isUiUsed; + private HitInfo _contextHitInfo; + private bool _contextHit; + public void UpdateLastModification() { lastModification = DateTime.Now.Ticks / TimeSpan.TicksPerSecond; @@ -59,7 +62,7 @@ private void GLControl_Load(object sender, EventArgs e) { GL.Enable(EnableCap.DepthTest); _renderer = new Renderer(); - _rayTracer = new SamplesRayTracer(8, 1024, Vec2Sampling.Jittered, gLControl.Width, 32); + _rayTracer = new SamplesRayTracer(8, 1024, Vec2Sampling.Jittered, gLControl.Width, 8); _cameraController = new CameraController(_camera, gLControl, UpdateLastModification); _scene.AmbientLight = new AmbientLight {Color = Color.FromColor4(Color4.LightSkyBlue)}; _scene.AddModel(new Sphere @@ -112,6 +115,8 @@ private void GLControl_Load(object sender, EventArgs e) _scene.Preprocess(); InitializeFpsTimer(); UpdateViewport(); + + gLControl.MouseClick += GLControl_MouseClick; } private void InitializeFpsTimer() @@ -167,7 +172,8 @@ private void BackgroundWorkerProgressChanged(object sender, { var texture = (Texture) e.UserState; texture?.Blit(); - gLControl.SwapBuffers(); + if(!gLControl.IsDisposed) + gLControl.SwapBuffers(); texture?.Dispose(); Text = $@"{e.ProgressPercentage}%"; } @@ -186,12 +192,18 @@ private void InitializeBackgroundWorker() private void newObjectButton_Click(object sender, EventArgs e) { - UpdateLastModification(); - var sphere = new Sphere().Load(); var ray = _camera.GetRay(0.5f, 0.5f); var hitInfo = new HitInfo(); + var hit = _scene.HitTest(ray, ref hitInfo, 0.001f, float.PositiveInfinity); + NewObjectFunction(hit, ref hitInfo); + } + + private void NewObjectFunction(bool hit, ref HitInfo hitInfo) + { + UpdateLastModification(); + var sphere = new Sphere().Load(); _isUiUsed = true; - if (_scene.HitTest(ray, ref hitInfo, 0.001f, float.PositiveInfinity) && hitInfo.Distance < 50) + if (hit && hitInfo.Distance < 50) { sphere.Position = hitInfo.HitPoint; } @@ -209,11 +221,17 @@ private void newObjectButton_Click(object sender, EventArgs e) private void editObjectButton_Click(object sender, EventArgs e) { - UpdateLastModification(); var ray = _camera.GetRay(0.5f, 0.5f); var hitInfo = new HitInfo(); + var hit = _scene.HitTest(ray, ref hitInfo, 0.001f, float.PositiveInfinity); + EditObjectFunction(hit, ref hitInfo); + } + + private void EditObjectFunction(bool hit, ref HitInfo hitInfo) + { + UpdateLastModification(); _isUiUsed = true; - if (_scene.HitTest(ray, ref hitInfo, 0.001f, float.PositiveInfinity)) + if (hit) { var model = hitInfo.ModelHit; if (model is Triangle triangle) model = triangle.Parent; @@ -224,7 +242,6 @@ private void editObjectButton_Click(object sender, EventArgs e) } else { - // TODO: color dialog title ColorDialog MyDialog = new ColorDialog(); MyDialog.AllowFullOpen = true; MyDialog.Color = _scene.AmbientLight.Color.ToSystemDrawing(); @@ -240,16 +257,22 @@ private void editObjectButton_Click(object sender, EventArgs e) private void deleteObjectButton_Click(object sender, EventArgs e) { - UpdateLastModification(); - _isUiUsed = true; var ray = _camera.GetRay(0.5f, 0.5f); var hitInfo = new HitInfo(); - if (_scene.HitTest(ray, ref hitInfo, 0.001f, float.PositiveInfinity)) + var hit = _scene.HitTest(ray, ref hitInfo, 0.001f, float.PositiveInfinity); + DeleteObjectFunction(hit, ref hitInfo); + } + + private void DeleteObjectFunction(bool hit, ref HitInfo hitInfo) + { + UpdateLastModification(); + _isUiUsed = true; + if (hit) { var model = hitInfo.ModelHit; if (model is Triangle triangle) model = triangle.Parent; string message = - $"Are you sure that you would like to delete the {model.ToString()}?"; + $"Are you sure that you would like to delete the {model}?"; const string caption = "Form Closing"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, @@ -264,10 +287,53 @@ private void deleteObjectButton_Click(object sender, EventArgs e) _isUiUsed = false; } + private void GLControl_MouseClick(object sender, MouseEventArgs e) + { + if(e.Button == MouseButtons.Right) + { + var width = (float)gLControl.Width; + var height = (float)gLControl.Height; + var u = e.X / width; + var v = 1 - e.Y / height; + var ray = _camera.GetRay(u, v); + _contextHitInfo = new HitInfo(); + _contextHit = _scene.HitTest(ray, ref _contextHitInfo, 0.001f, float.PositiveInfinity); + + if (_contextHit) + { + newDeleteStrip.Show(Cursor.Position); + } + else + { + newEditStrip.Show(Cursor.Position); + } + } + } + + private void DeleteItem_Click(object sender, EventArgs e) + { + DeleteObjectFunction(_contextHit, ref _contextHitInfo); + } + + private void EditItem_Click(object sender, EventArgs e) + { + EditObjectFunction(_contextHit, ref _contextHitInfo); + } + + private void AddItem_Click(object sender, EventArgs e) + { + NewObjectFunction(_contextHit, ref _contextHitInfo); + } + private void FormOnClosed(object? sender, EventArgs e) { _isUiUsed = false; UpdateLastModification(); } + + private void MainForm_FormClosed(object sender, FormClosedEventArgs e) + { + UpdateLastModification(); + } } } \ No newline at end of file diff --git a/RayTracerApp/Forms/MainForm.resx b/RayTracerApp/Forms/MainForm.resx index 1af7de1..f298a7b 100644 --- a/RayTracerApp/Forms/MainForm.resx +++ b/RayTracerApp/Forms/MainForm.resx @@ -1,64 +1,4 @@ - - - + diff --git a/RayTracerApp/Forms/SettingsForm.Designer.cs b/RayTracerApp/Forms/SettingsForm.Designer.cs index 4e21681..8646e2d 100644 --- a/RayTracerApp/Forms/SettingsForm.Designer.cs +++ b/RayTracerApp/Forms/SettingsForm.Designer.cs @@ -30,29 +30,427 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.linkLabel1 = new System.Windows.Forms.LinkLabel(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.label6 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); + this.panel1 = new System.Windows.Forms.Panel(); + this.radioButton1 = new System.Windows.Forms.RadioButton(); + this.radioButton2 = new System.Windows.Forms.RadioButton(); + this.radioButton3 = new System.Windows.Forms.RadioButton(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.panel2 = new System.Windows.Forms.Panel(); + this.radioButton4 = new System.Windows.Forms.RadioButton(); + this.radioButton5 = new System.Windows.Forms.RadioButton(); + this.radioButton6 = new System.Windows.Forms.RadioButton(); + this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel(); + this.label9 = new System.Windows.Forms.Label(); + this.label10 = new System.Windows.Forms.Label(); + this.label11 = new System.Windows.Forms.Label(); + this.label12 = new System.Windows.Forms.Label(); + this.label13 = new System.Windows.Forms.Label(); + this.tableLayoutPanel1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.tableLayoutPanel2.SuspendLayout(); + this.groupBox1.SuspendLayout(); + this.tableLayoutPanel3.SuspendLayout(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + this.panel2.SuspendLayout(); + this.tableLayoutPanel4.SuspendLayout(); this.SuspendLayout(); // // tableLayoutPanel1 // - this.tableLayoutPanel1.ColumnCount = 2; + this.tableLayoutPanel1.ColumnCount = 1; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel1.Location = new System.Drawing.Point(43, 53); + this.tableLayoutPanel1.Controls.Add(this.groupBox2, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.groupBox1, 0, 0); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 2; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel1.Size = new System.Drawing.Size(200, 100); + this.tableLayoutPanel1.Size = new System.Drawing.Size(623, 654); this.tableLayoutPanel1.TabIndex = 0; // + // label1 + // + this.label1.Location = new System.Drawing.Point(0, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(100, 23); + this.label1.TabIndex = 0; + this.label1.Text = "label1"; + // + // label2 + // + this.label2.Location = new System.Drawing.Point(0, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(100, 23); + this.label2.TabIndex = 0; + this.label2.Text = "label2"; + // + // label3 + // + this.label3.Location = new System.Drawing.Point(0, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(100, 23); + this.label3.TabIndex = 0; + this.label3.Text = "label3"; + // + // label4 + // + this.label4.Location = new System.Drawing.Point(0, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(100, 23); + this.label4.TabIndex = 0; + this.label4.Text = "label4"; + // + // label5 + // + this.label5.Location = new System.Drawing.Point(0, 0); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(100, 23); + this.label5.TabIndex = 0; + this.label5.Text = "label5"; + // + // linkLabel1 + // + this.linkLabel1.Location = new System.Drawing.Point(0, 0); + this.linkLabel1.Name = "linkLabel1"; + this.linkLabel1.Size = new System.Drawing.Size(100, 23); + this.linkLabel1.TabIndex = 0; + this.linkLabel1.TabStop = true; + this.linkLabel1.Text = "linkLabel1"; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.tableLayoutPanel4); + this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill; + this.groupBox2.Location = new System.Drawing.Point(3, 330); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(617, 321); + this.groupBox2.TabIndex = 1; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Ray Tracer"; + // + // tableLayoutPanel2 + // + this.tableLayoutPanel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel2.ColumnCount = 2; + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel2.Controls.Add(this.panel2, 1, 2); + this.tableLayoutPanel2.Controls.Add(this.label6, 0, 0); + this.tableLayoutPanel2.Controls.Add(this.label7, 0, 1); + this.tableLayoutPanel2.Controls.Add(this.label8, 0, 2); + this.tableLayoutPanel2.Controls.Add(this.tableLayoutPanel3, 1, 0); + this.tableLayoutPanel2.Controls.Add(this.numericUpDown1, 1, 1); + this.tableLayoutPanel2.Location = new System.Drawing.Point(6, 22); + this.tableLayoutPanel2.Name = "tableLayoutPanel2"; + this.tableLayoutPanel2.RowCount = 3; + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel2.Size = new System.Drawing.Size(602, 293); + this.tableLayoutPanel2.TabIndex = 0; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.tableLayoutPanel2); + this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.groupBox1.Location = new System.Drawing.Point(3, 3); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(617, 321); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Camera"; + // + // label6 + // + this.label6.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(113, 41); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(74, 15); + this.label6.TabIndex = 0; + this.label6.Text = "Camera type"; + this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label7 + // + this.label7.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(114, 138); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(73, 15); + this.label7.TabIndex = 1; + this.label7.Text = "Field of view"; + this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label8 + // + this.label8.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(122, 236); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(57, 15); + this.label8.TabIndex = 2; + this.label8.Text = "Sampling"; + this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // tableLayoutPanel3 + // + this.tableLayoutPanel3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel3.ColumnCount = 2; + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel3.Controls.Add(this.panel1, 0, 0); + this.tableLayoutPanel3.Location = new System.Drawing.Point(304, 3); + this.tableLayoutPanel3.Name = "tableLayoutPanel3"; + this.tableLayoutPanel3.RowCount = 1; + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel3.Size = new System.Drawing.Size(295, 91); + this.tableLayoutPanel3.TabIndex = 3; + // + // panel1 + // + this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel1.Controls.Add(this.radioButton3); + this.panel1.Controls.Add(this.radioButton2); + this.panel1.Controls.Add(this.radioButton1); + this.panel1.Location = new System.Drawing.Point(3, 3); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(141, 85); + this.panel1.TabIndex = 2; + // + // radioButton1 + // + this.radioButton1.AutoSize = true; + this.radioButton1.Checked = true; + this.radioButton1.Location = new System.Drawing.Point(0, 4); + this.radioButton1.Name = "radioButton1"; + this.radioButton1.Size = new System.Drawing.Size(85, 19); + this.radioButton1.TabIndex = 0; + this.radioButton1.TabStop = true; + this.radioButton1.Text = "Perspective"; + this.radioButton1.UseVisualStyleBackColor = true; + // + // radioButton2 + // + this.radioButton2.AutoSize = true; + this.radioButton2.Location = new System.Drawing.Point(0, 29); + this.radioButton2.Name = "radioButton2"; + this.radioButton2.Size = new System.Drawing.Size(49, 19); + this.radioButton2.TabIndex = 1; + this.radioButton2.Text = "Lens"; + this.radioButton2.UseVisualStyleBackColor = true; + // + // radioButton3 + // + this.radioButton3.AutoSize = true; + this.radioButton3.Location = new System.Drawing.Point(0, 54); + this.radioButton3.Name = "radioButton3"; + this.radioButton3.Size = new System.Drawing.Size(89, 19); + this.radioButton3.TabIndex = 2; + this.radioButton3.Text = "Ortographic"; + this.radioButton3.UseVisualStyleBackColor = true; + // + // numericUpDown1 + // + this.numericUpDown1.Anchor = System.Windows.Forms.AnchorStyles.None; + this.numericUpDown1.Location = new System.Drawing.Point(391, 134); + this.numericUpDown1.Maximum = new decimal(new int[] { + 170, + 0, + 0, + 0}); + this.numericUpDown1.Minimum = new decimal(new int[] { + 30, + 0, + 0, + 0}); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(120, 23); + this.numericUpDown1.TabIndex = 4; + this.numericUpDown1.Value = new decimal(new int[] { + 30, + 0, + 0, + 0}); + // + // panel2 + // + this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel2.Controls.Add(this.radioButton4); + this.panel2.Controls.Add(this.radioButton5); + this.panel2.Controls.Add(this.radioButton6); + this.panel2.Location = new System.Drawing.Point(304, 197); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(295, 93); + this.panel2.TabIndex = 5; + // + // radioButton4 + // + this.radioButton4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.radioButton4.AutoSize = true; + this.radioButton4.Location = new System.Drawing.Point(0, 54); + this.radioButton4.Name = "radioButton4"; + this.radioButton4.Size = new System.Drawing.Size(70, 19); + this.radioButton4.TabIndex = 2; + this.radioButton4.Text = "Random"; + this.radioButton4.UseVisualStyleBackColor = true; + // + // radioButton5 + // + this.radioButton5.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.radioButton5.AutoSize = true; + this.radioButton5.Location = new System.Drawing.Point(0, 29); + this.radioButton5.Name = "radioButton5"; + this.radioButton5.Size = new System.Drawing.Size(60, 19); + this.radioButton5.TabIndex = 1; + this.radioButton5.Text = "Center"; + this.radioButton5.UseVisualStyleBackColor = true; + // + // radioButton6 + // + this.radioButton6.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.radioButton6.AutoSize = true; + this.radioButton6.Checked = true; + this.radioButton6.Location = new System.Drawing.Point(0, 4); + this.radioButton6.Name = "radioButton6"; + this.radioButton6.Size = new System.Drawing.Size(63, 19); + this.radioButton6.TabIndex = 0; + this.radioButton6.TabStop = true; + this.radioButton6.Text = "Jittered"; + this.radioButton6.UseVisualStyleBackColor = true; + // + // tableLayoutPanel4 + // + this.tableLayoutPanel4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel4.ColumnCount = 2; + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel4.Controls.Add(this.label13, 0, 4); + this.tableLayoutPanel4.Controls.Add(this.label9, 0, 0); + this.tableLayoutPanel4.Controls.Add(this.label10, 0, 1); + this.tableLayoutPanel4.Controls.Add(this.label11, 0, 2); + this.tableLayoutPanel4.Controls.Add(this.label12, 0, 3); + this.tableLayoutPanel4.Location = new System.Drawing.Point(6, 22); + this.tableLayoutPanel4.Name = "tableLayoutPanel4"; + this.tableLayoutPanel4.RowCount = 5; + this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); + this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); + this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); + this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); + this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); + this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel4.Size = new System.Drawing.Size(599, 290); + this.tableLayoutPanel4.TabIndex = 0; + // + // label9 + // + this.label9.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(124, 21); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(51, 15); + this.label9.TabIndex = 1; + this.label9.Text = "Samples"; + this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label10 + // + this.label10.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(99, 79); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(101, 15); + this.label10.TabIndex = 2; + this.label10.Text = "Update frequency"; + this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label11 + // + this.label11.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label11.AutoSize = true; + this.label11.Location = new System.Drawing.Point(96, 137); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(106, 15); + this.label11.TabIndex = 3; + this.label11.Text = "Gamma correction"; + this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label12 + // + this.label12.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label12.AutoSize = true; + this.label12.Location = new System.Drawing.Point(128, 195); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(42, 15); + this.label12.TabIndex = 4; + this.label12.Text = "Bloom"; + this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label13 + // + this.label13.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label13.AutoSize = true; + this.label13.Location = new System.Drawing.Point(33, 253); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(232, 15); + this.label13.TabIndex = 5; + this.label13.Text = "Ray tracing by recursion levels (unoptimal)"; + this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // // SettingsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(467, 668); + this.ClientSize = new System.Drawing.Size(623, 654); this.Controls.Add(this.tableLayoutPanel1); this.Name = "SettingsForm"; - this.Text = "SettingsForm"; + this.Text = "Settings"; + this.tableLayoutPanel1.ResumeLayout(false); + this.groupBox2.ResumeLayout(false); + this.tableLayoutPanel2.ResumeLayout(false); + this.tableLayoutPanel2.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.tableLayoutPanel3.ResumeLayout(false); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + this.panel2.ResumeLayout(false); + this.panel2.PerformLayout(); + this.tableLayoutPanel4.ResumeLayout(false); + this.tableLayoutPanel4.PerformLayout(); this.ResumeLayout(false); } @@ -60,5 +458,33 @@ private void InitializeComponent() #endregion private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.LinkLabel linkLabel1; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel4; + private System.Windows.Forms.Label label13; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.Label label11; + private System.Windows.Forms.Label label12; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.RadioButton radioButton4; + private System.Windows.Forms.RadioButton radioButton5; + private System.Windows.Forms.RadioButton radioButton6; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.RadioButton radioButton3; + private System.Windows.Forms.RadioButton radioButton2; + private System.Windows.Forms.RadioButton radioButton1; + private System.Windows.Forms.NumericUpDown numericUpDown1; } } \ No newline at end of file diff --git a/RayTracerApp/Forms/TestForm.Designer.cs b/RayTracerApp/Forms/TestForm.Designer.cs new file mode 100644 index 0000000..a34fe96 --- /dev/null +++ b/RayTracerApp/Forms/TestForm.Designer.cs @@ -0,0 +1,87 @@ + +namespace RayTracerApp.Forms +{ + partial class TestForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); + this.contextMenuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // contextMenuStrip1 + // + this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItem1, + this.toolStripMenuItem2, + this.toolStripMenuItem3}); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(181, 70); + // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(180, 22); + this.toolStripMenuItem1.Text = "toolStripMenuItem1"; + // + // toolStripMenuItem2 + // + this.toolStripMenuItem2.Name = "toolStripMenuItem2"; + this.toolStripMenuItem2.Size = new System.Drawing.Size(180, 22); + this.toolStripMenuItem2.Text = "toolStripMenuItem2"; + // + // toolStripMenuItem3 + // + this.toolStripMenuItem3.Name = "toolStripMenuItem3"; + this.toolStripMenuItem3.Size = new System.Drawing.Size(180, 22); + this.toolStripMenuItem3.Text = "toolStripMenuItem3"; + // + // TestForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.ContextMenuStrip = this.contextMenuStrip1; + this.Name = "TestForm"; + this.Text = "TestForm"; + this.contextMenuStrip1.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem3; + } +} \ No newline at end of file diff --git a/RayTracerApp/Forms/TestForm.cs b/RayTracerApp/Forms/TestForm.cs new file mode 100644 index 0000000..2c67e1d --- /dev/null +++ b/RayTracerApp/Forms/TestForm.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace RayTracerApp.Forms +{ + public partial class TestForm : Form + { + public TestForm() + { + InitializeComponent(); + } + } +} diff --git a/RayTracerApp/Forms/TestForm.resx b/RayTracerApp/Forms/TestForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/RayTracerApp/Forms/TestForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RayTracerApp/Panels/FeaturesPanel.cs b/RayTracerApp/Panels/FeaturesPanel.cs index d276c25..625a5f6 100644 --- a/RayTracerApp/Panels/FeaturesPanel.cs +++ b/RayTracerApp/Panels/FeaturesPanel.cs @@ -30,6 +30,8 @@ public void UpdateForModel() case Cylinder cylinder: cylinder.Aspect = (float)aspectRatioUpDown.Value; break; + case CustomModel cylinder: + break; default: throw new Exception("Bad model type"); } From 603b18436a3f63edaf5f253cb202134a4146a25f Mon Sep 17 00:00:00 2001 From: p-flis Date: Thu, 7 Jan 2021 01:05:14 +0100 Subject: [PATCH 14/31] uiuiui --- RayTracer/Source/Cameras/Camera.cs | 32 +- RayTracer/Source/Cameras/LensCamera.cs | 13 +- RayTracer/Source/Cameras/PerspectiveCamera.cs | 12 - RayTracer/Source/Models/Plane.cs | 2 +- .../Source/Renderer/IncrementalRayTracer.cs | 5 +- RayTracer/Source/Renderer/RayTracer.cs | 4 + .../Source/Renderer/RecursionRayTracer.cs | 4 +- RayTracer/Source/Renderer/SamplesRayTracer.cs | 7 +- RayTracerApp/CameraController.cs | 5 + .../ColorSlider/ColorSlider.Designer.cs | 42 + RayTracerApp/ColorSlider/ColorSlider.cs | 1071 +++++++++++++++++ RayTracerApp/ColorSlider/ColorSlider.resx | 123 ++ RayTracerApp/Forms/EditObjectForm.Designer.cs | 8 +- RayTracerApp/Forms/MainForm.Designer.cs | 11 +- RayTracerApp/Forms/MainForm.cs | 39 +- RayTracerApp/Forms/NewObjectForm.Designer.cs | 16 +- RayTracerApp/Forms/SettingsForm.Designer.cs | 799 ++++++++---- RayTracerApp/Forms/SettingsForm.cs | 176 ++- RayTracerApp/Forms/TestForm.Designer.cs | 12 + RayTracerApp/Panels/MaterialPanel.Designer.cs | 2 +- RayTracerApp/Panels/MaterialPanel.cs | 6 +- RayTracerApp/Panels/PositionPanel.Designer.cs | 25 +- RayTracerApp/Panels/PositionPanel.cs | 7 + .../SceneController/SettingsController.cs | 20 + 24 files changed, 2104 insertions(+), 337 deletions(-) create mode 100644 RayTracerApp/ColorSlider/ColorSlider.Designer.cs create mode 100644 RayTracerApp/ColorSlider/ColorSlider.cs create mode 100644 RayTracerApp/ColorSlider/ColorSlider.resx create mode 100644 RayTracerApp/SceneController/SettingsController.cs diff --git a/RayTracer/Source/Cameras/Camera.cs b/RayTracer/Source/Cameras/Camera.cs index e0904d9..9913baf 100644 --- a/RayTracer/Source/Cameras/Camera.cs +++ b/RayTracer/Source/Cameras/Camera.cs @@ -9,15 +9,43 @@ public abstract class Camera public Vector3 Front { get; protected set; } = -Vector3.UnitZ; protected Vector3 Up { get; set; } = Vector3.UnitY; protected Vector3 Right { get; set; } = Vector3.UnitX; - protected float Pitch { get; set; } - protected float Yaw { get; set; } = -MathHelper.PiOver2; + private float _pitch; + public float Pitch + { + get => _pitch; + set + { + _pitch = value; + UpdateVectors(); + } + } + private float _yaw = -MathHelper.PiOver2; + public float Yaw + { + get => _yaw; + set + { + _yaw = value; + UpdateVectors(); + } + } private float _aspectRatio = 16f / 9; + protected float _fov = MathHelper.PiOver3; public Vector3 Position { get; set; } protected Vector3 Horizontal { get; set; } protected Vector3 Vertical { get; set; } protected Vector3 LowerLeft { get; set; } public float FarPlane { get; set; } = 1000f; + public float Fov + { + get => MathHelper.RadiansToDegrees(_fov); + set + { + var angle = MathHelper.Clamp(value, 1f, 90f); + _fov = MathHelper.DegreesToRadians(angle); + } + } public float AspectRatio { diff --git a/RayTracer/Source/Cameras/LensCamera.cs b/RayTracer/Source/Cameras/LensCamera.cs index 5efef2b..023f30e 100644 --- a/RayTracer/Source/Cameras/LensCamera.cs +++ b/RayTracer/Source/Cameras/LensCamera.cs @@ -10,22 +10,12 @@ public class LensCamera : Camera { private const int SAMPLE_SETS = 8; - private float _fov = MathHelper.PiOver3; private float _lensRadius; private float _focusDistance; private AbstractSampler _lensSampler; private Func> _sampling; private int _samplesCount; - public float Fov - { - get => MathHelper.RadiansToDegrees(_fov); - set - { - var angle = MathHelper.Clamp(value, 1f, 90f); - _fov = MathHelper.DegreesToRadians(angle); - } - } public float LensRadius { @@ -67,7 +57,7 @@ public int SamplesCount } } - public LensCamera(Vector3 position, float lensRadius, float focusDistance, int samplesCount = 64, Func> sampling = null) + public LensCamera(Vector3 position, float lensRadius = 10, float focusDistance = 5, int samplesCount = 64, Func> sampling = null) { Position = position; _lensRadius = lensRadius; @@ -94,6 +84,7 @@ public override Matrix4 GetViewMatrix() public override Matrix4 GetProjectionMatrix() { + Log.Info("" + _fov); return Matrix4.CreatePerspectiveFieldOfView(_fov, AspectRatio, 1, FarPlane); } diff --git a/RayTracer/Source/Cameras/PerspectiveCamera.cs b/RayTracer/Source/Cameras/PerspectiveCamera.cs index ba25932..4ed51d8 100644 --- a/RayTracer/Source/Cameras/PerspectiveCamera.cs +++ b/RayTracer/Source/Cameras/PerspectiveCamera.cs @@ -6,18 +6,6 @@ namespace RayTracing.Cameras { public class PerspectiveCamera : Camera { - private float _fov = MathHelper.PiOver3; - - public float Fov - { - get => MathHelper.RadiansToDegrees(_fov); - set - { - var angle = MathHelper.Clamp(value, 1f, 90f); - _fov = MathHelper.DegreesToRadians(angle); - } - } - public PerspectiveCamera(Vector3 position) { this.Position = position; diff --git a/RayTracer/Source/Models/Plane.cs b/RayTracer/Source/Models/Plane.cs index a7d162d..c25446c 100644 --- a/RayTracer/Source/Models/Plane.cs +++ b/RayTracer/Source/Models/Plane.cs @@ -9,7 +9,7 @@ namespace RayTracing.Models public class Plane : Model { private Vector3 _normal = Vector3.UnitY; - private int _sideCount = 1000; + private int _sideCount = 100; public override Vector3 Rotation { diff --git a/RayTracer/Source/Renderer/IncrementalRayTracer.cs b/RayTracer/Source/Renderer/IncrementalRayTracer.cs index 6767058..d0cc686 100644 --- a/RayTracer/Source/Renderer/IncrementalRayTracer.cs +++ b/RayTracer/Source/Renderer/IncrementalRayTracer.cs @@ -11,11 +11,14 @@ public abstract class IncrementalRayTracer : RayTracer, IRenderer { public Action OnFrameReady { get; set; } public CancellationToken CancellationToken { get; set; } + + public int SamplesRenderStep { get; set; } public abstract void Render(Scene scene, Camera camera); - public IncrementalRayTracer(int maxDepth, int samples, Func> sampling, int resolution) : + public IncrementalRayTracer(int maxDepth, int samples, Func> sampling, int resolution, int samplesRenderStep) : base(maxDepth, samples, sampling, resolution) { + SamplesRenderStep = samplesRenderStep; } } } \ No newline at end of file diff --git a/RayTracer/Source/Renderer/RayTracer.cs b/RayTracer/Source/Renderer/RayTracer.cs index 1592218..06496da 100644 --- a/RayTracer/Source/Renderer/RayTracer.cs +++ b/RayTracer/Source/Renderer/RayTracer.cs @@ -13,6 +13,10 @@ public abstract class RayTracer public Func> Sampling { get; set; } public int Resolution { get; set; } + public int Bloom { get; set; } + + public int GammaCorrection { get; set; } + public RayTracer(int maxDepth, int samples, Func> sampling, int resolution) { MaxDepth = maxDepth; diff --git a/RayTracer/Source/Renderer/RecursionRayTracer.cs b/RayTracer/Source/Renderer/RecursionRayTracer.cs index 333b5fa..7b533c9 100644 --- a/RayTracer/Source/Renderer/RecursionRayTracer.cs +++ b/RayTracer/Source/Renderer/RecursionRayTracer.cs @@ -8,8 +8,8 @@ namespace RayTracing { public class RecursionRayTracer : SamplesRayTracer { - public RecursionRayTracer(int maxDepth, int samples, Func> sampling, int resolution) : base( - maxDepth, samples, sampling, resolution, 1) + public RecursionRayTracer(int maxDepth, int samples, Func> sampling, int resolution, int renderStep) : base( + maxDepth, samples, sampling, resolution, renderStep) { } diff --git a/RayTracer/Source/Renderer/SamplesRayTracer.cs b/RayTracer/Source/Renderer/SamplesRayTracer.cs index 9b42cf2..d11a45f 100644 --- a/RayTracer/Source/Renderer/SamplesRayTracer.cs +++ b/RayTracer/Source/Renderer/SamplesRayTracer.cs @@ -12,12 +12,9 @@ namespace RayTracing { public class SamplesRayTracer : IncrementalRayTracer { - private readonly int _samplesRenderStep; - public SamplesRayTracer(int maxDepth, int samples, Func> sampling, int resolution, int samplesRenderStep) : base( - maxDepth, samples, sampling, resolution) + maxDepth, samples, sampling, resolution, samplesRenderStep) { - _samplesRenderStep = samplesRenderStep; } public override void Render(Scene scene, Camera camera) @@ -51,7 +48,7 @@ public override void Render(Scene scene, Camera camera) if (CancellationToken.IsCancellationRequested) return; - if (k % _samplesRenderStep == 0 || k == Samples - 1) + if (k % SamplesRenderStep == 0 || k == Samples - 1) { var output = new Texture(image); output.Process(c => (c / (k + 1)).Clamp()); diff --git a/RayTracerApp/CameraController.cs b/RayTracerApp/CameraController.cs index 7a58fc0..9fa3454 100644 --- a/RayTracerApp/CameraController.cs +++ b/RayTracerApp/CameraController.cs @@ -26,6 +26,11 @@ public CameraController(Camera camera, Control control, Action onModification) _onModification = onModification; } + public Camera GetCamera() + { + return _camera; + } + private void OnKeyUp(object sender, KeyEventArgs e) { keys[e.KeyCode] = false; diff --git a/RayTracerApp/ColorSlider/ColorSlider.Designer.cs b/RayTracerApp/ColorSlider/ColorSlider.Designer.cs new file mode 100644 index 0000000..d91aaa1 --- /dev/null +++ b/RayTracerApp/ColorSlider/ColorSlider.Designer.cs @@ -0,0 +1,42 @@ +namespace RayTracerApp.Controls +{ + partial class ColorSlider + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.SuspendLayout(); + // + // ColorSlider + // + this.Size = new System.Drawing.Size(200, 30); + this.ResumeLayout(false); + + } + + #endregion + } +} diff --git a/RayTracerApp/ColorSlider/ColorSlider.cs b/RayTracerApp/ColorSlider/ColorSlider.cs new file mode 100644 index 0000000..6dda1e4 --- /dev/null +++ b/RayTracerApp/ColorSlider/ColorSlider.cs @@ -0,0 +1,1071 @@ +using System; +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Windows.Forms; + +namespace RayTracerApp.Controls +{ + /// + /// Encapsulates control that visualy displays certain integer value and allows user to change it within desired range. It imitates as far as mouse usage is concerned. + /// + [ToolboxBitmap(typeof(TrackBar))] + [DefaultEvent("Scroll"), DefaultProperty("BarInnerColor")] + public partial class ColorSlider : UserControl + { + #region Events + + /// + /// Fires when Slider position has changed + /// + [Description("Event fires when the Value property changes")] + [Category("Action")] + public event EventHandler ValueChanged; + + /// + /// Fires when user scrolls the Slider + /// + [Description("Event fires when the Slider position is changed")] + [Category("Behavior")] + public event ScrollEventHandler Scroll; + + #endregion + + #region Properties + + private Rectangle thumbRect; //bounding rectangle of thumb area + /// + /// Gets the thumb rect. Usefull to determine bounding rectangle when creating custom thumb shape. + /// + /// The thumb rect. + [Browsable(false)] + public Rectangle ThumbRect + { + get { return thumbRect; } + } + + private Rectangle barRect; //bounding rectangle of bar area + private Rectangle barHalfRect; + private Rectangle thumbHalfRect; + private Rectangle elapsedRect; //bounding rectangle of elapsed area + + private int thumbSize = 15; + /// + /// Gets or sets the size of the thumb. + /// + /// The size of the thumb. + /// exception thrown when value is lower than zero or grather than half of appropiate dimension + [Description("Set Slider thumb size")] + [Category("ColorSlider")] + [DefaultValue(15)] + public int ThumbSize + { + get { return thumbSize; } + set + { + if (value > 0 & + value < (barOrientation == Orientation.Horizontal ? ClientRectangle.Width : ClientRectangle.Height)) + thumbSize = value; + else + throw new ArgumentOutOfRangeException( + "TrackSize has to be greather than zero and lower than half of Slider width"); + Invalidate(); + } + } + + private GraphicsPath thumbCustomShape = null; + /// + /// Gets or sets the thumb custom shape. Use ThumbRect property to determine bounding rectangle. + /// + /// The thumb custom shape. null means default shape + [Description("Set Slider's thumb's custom shape")] + [Category("ColorSlider")] + [Browsable(false)] + [DefaultValue(typeof(GraphicsPath), "null")] + public GraphicsPath ThumbCustomShape + { + get { return thumbCustomShape; } + set + { + thumbCustomShape = value; + thumbSize = (int) (barOrientation == Orientation.Horizontal ? value.GetBounds().Width : value.GetBounds().Height) + 1; + Invalidate(); + } + } + + private Size thumbRoundRectSize = new Size(8, 8); + /// + /// Gets or sets the size of the thumb round rectangle edges. + /// + /// The size of the thumb round rectangle edges. + [Description("Set Slider's thumb round rect size")] + [Category("ColorSlider")] + [DefaultValue(typeof(Size), "8; 8")] + public Size ThumbRoundRectSize + { + get { return thumbRoundRectSize; } + set + { + int h = value.Height, w = value.Width; + if (h <= 0) h = 1; + if (w <= 0) w = 1; + thumbRoundRectSize = new Size(w, h); + Invalidate(); + } + } + + private Size borderRoundRectSize = new Size(8, 8); + /// + /// Gets or sets the size of the border round rect. + /// + /// The size of the border round rect. + [Description("Set Slider's border round rect size")] + [Category("ColorSlider")] + [DefaultValue(typeof(Size), "8; 8")] + public Size BorderRoundRectSize + { + get { return borderRoundRectSize; } + set + { + int h = value.Height, w = value.Width; + if (h <= 0) h = 1; + if (w <= 0) w = 1; + borderRoundRectSize = new Size(w, h); + Invalidate(); + } + } + + private Orientation barOrientation = Orientation.Horizontal; + /// + /// Gets or sets the orientation of Slider. + /// + /// The orientation. + [Description("Set Slider orientation")] + [Category("ColorSlider")] + [DefaultValue(Orientation.Horizontal)] + public Orientation Orientation + { + get { return barOrientation; } + set + { + if (barOrientation != value) + { + barOrientation = value; + int temp = Width; + Width = Height; + Height = temp; + if (thumbCustomShape != null) + thumbSize = + (int) + (barOrientation == Orientation.Horizontal + ? thumbCustomShape.GetBounds().Width + : thumbCustomShape.GetBounds().Height) + 1; + Invalidate(); + } + } + } + + + private int trackerValue = 50; + /// + /// Gets or sets the value of Slider. + /// + /// The value. + /// exception thrown when value is outside appropriate range (min, max) + [Description("Set Slider value")] + [Category("ColorSlider")] + [DefaultValue(50)] + public int Value + { + get { return trackerValue; } + set + { + if (value >= barMinimum & value <= barMaximum) + { + trackerValue = value; + if (ValueChanged != null) ValueChanged(this, new EventArgs()); + Invalidate(); + } + else throw new ArgumentOutOfRangeException("Value is outside appropriate range (min, max)"); + } + } + + + private int barMinimum = 0; + /// + /// Gets or sets the minimum value. + /// + /// The minimum value. + /// exception thrown when minimal value is greather than maximal one + [Description("Set Slider minimal point")] + [Category("ColorSlider")] + [DefaultValue(0)] + public int Minimum + { + get { return barMinimum; } + set + { + if (value < barMaximum) + { + barMinimum = value; + if (trackerValue < barMinimum) + { + trackerValue = barMinimum; + if (ValueChanged != null) ValueChanged(this, new EventArgs()); + } + Invalidate(); + } + else throw new ArgumentOutOfRangeException("Minimal value is greather than maximal one"); + } + } + + + private int barMaximum = 100; + /// + /// Gets or sets the maximum value. + /// + /// The maximum value. + /// exception thrown when maximal value is lower than minimal one + [Description("Set Slider maximal point")] + [Category("ColorSlider")] + [DefaultValue(100)] + public int Maximum + { + get { return barMaximum; } + set + { + if (value > barMinimum) + { + barMaximum = value; + if (trackerValue > barMaximum) + { + trackerValue = barMaximum; + if (ValueChanged != null) ValueChanged(this, new EventArgs()); + } + Invalidate(); + } + else throw new ArgumentOutOfRangeException("Maximal value is lower than minimal one"); + } + } + + private uint smallChange = 1; + /// + /// Gets or sets trackbar's small change. It affects how to behave when directional keys are pressed + /// + /// The small change value. + [Description("Set trackbar's small change")] + [Category("ColorSlider")] + [DefaultValue(1)] + public uint SmallChange + { + get { return smallChange; } + set { smallChange = value; } + } + + private uint largeChange = 5; + + /// + /// Gets or sets trackbar's large change. It affects how to behave when PageUp/PageDown keys are pressed + /// + /// The large change value. + [Description("Set trackbar's large change")] + [Category("ColorSlider")] + [DefaultValue(5)] + public uint LargeChange + { + get { return largeChange; } + set { largeChange = value; } + } + + private bool drawFocusRectangle = true; + /// + /// Gets or sets a value indicating whether to draw focus rectangle. + /// + /// true if focus rectangle should be drawn; otherwise, false. + [Description("Set whether to draw focus rectangle")] + [Category("ColorSlider")] + [DefaultValue(true)] + public bool DrawFocusRectangle + { + get { return drawFocusRectangle; } + set + { + drawFocusRectangle = value; + Invalidate(); + } + } + + private bool drawSemitransparentThumb = true; + /// + /// Gets or sets a value indicating whether to draw semitransparent thumb. + /// + /// true if semitransparent thumb should be drawn; otherwise, false. + [Description("Set whether to draw semitransparent thumb")] + [Category("ColorSlider")] + [DefaultValue(true)] + public bool DrawSemitransparentThumb + { + get { return drawSemitransparentThumb; } + set + { + drawSemitransparentThumb = value; + Invalidate(); + } + } + + private bool mouseEffects = true; + /// + /// Gets or sets whether mouse entry and exit actions have impact on how control look. + /// + /// true if mouse entry and exit actions have impact on how control look; otherwise, false. + [Description("Set whether mouse entry and exit actions have impact on how control look")] + [Category("ColorSlider")] + [DefaultValue(true)] + public bool MouseEffects + { + get { return mouseEffects; } + set + { + mouseEffects = value; + Invalidate(); + } + } + + private int mouseWheelBarPartitions = 10; + /// + /// Gets or sets the mouse wheel bar partitions. + /// + /// The mouse wheel bar partitions. + /// exception thrown when value isn't greather than zero + [Description("Set to how many parts is bar divided when using mouse wheel")] + [Category("ColorSlider")] + [DefaultValue(10)] + public int MouseWheelBarPartitions + { + get { return mouseWheelBarPartitions; } + set + { + if (value > 0) + mouseWheelBarPartitions = value; + else throw new ArgumentOutOfRangeException("MouseWheelBarPartitions has to be greather than zero"); + } + } + + private Color thumbOuterColor = Color.White; + /// + /// Gets or sets the thumb outer color . + /// + /// The thumb outer color. + [Description("Set Slider thumb outer color")] + [Category("ColorSlider")] + [DefaultValue(typeof(Color), "White")] + public Color ThumbOuterColor + { + get { return thumbOuterColor; } + set + { + thumbOuterColor = value; + Invalidate(); + } + } + + + private Color thumbInnerColor = Color.Gainsboro; + /// + /// Gets or sets the inner color of the thumb. + /// + /// The inner color of the thumb. + [Description("Set Slider thumb inner color")] + [Category("ColorSlider")] + [DefaultValue(typeof(Color), "Gainsboro")] + public Color ThumbInnerColor + { + get { return thumbInnerColor; } + set + { + thumbInnerColor = value; + Invalidate(); + } + } + + + private Color thumbPenColor = Color.Silver; + /// + /// Gets or sets the color of the thumb pen. + /// + /// The color of the thumb pen. + [Description("Set Slider thumb pen color")] + [Category("ColorSlider")] + [DefaultValue(typeof(Color), "Silver")] + public Color ThumbPenColor + { + get { return thumbPenColor; } + set + { + thumbPenColor = value; + Invalidate(); + } + } + + + private Color barOuterColor = Color.SkyBlue; + /// + /// Gets or sets the outer color of the bar. + /// + /// The outer color of the bar. + [Description("Set Slider bar outer color")] + [Category("ColorSlider")] + [DefaultValue(typeof(Color), "SkyBlue")] + public Color BarOuterColor + { + get { return barOuterColor; } + set + { + barOuterColor = value; + Invalidate(); + } + } + + + private Color barInnerColor = Color.DarkSlateBlue; + /// + /// Gets or sets the inner color of the bar. + /// + /// The inner color of the bar. + [Description("Set Slider bar inner color")] + [Category("ColorSlider")] + [DefaultValue(typeof(Color), "DarkSlateBlue")] + public Color BarInnerColor + { + get { return barInnerColor; } + set + { + barInnerColor = value; + Invalidate(); + } + } + + + private Color barPenColor = Color.Gainsboro; + /// + /// Gets or sets the color of the bar pen. + /// + /// The color of the bar pen. + [Description("Set Slider bar pen color")] + [Category("ColorSlider")] + [DefaultValue(typeof(Color), "Gainsboro")] + public Color BarPenColor + { + get { return barPenColor; } + set + { + barPenColor = value; + Invalidate(); + } + } + + private Color elapsedOuterColor = Color.DarkGreen; + /// + /// Gets or sets the outer color of the elapsed. + /// + /// The outer color of the elapsed. + [Description("Set Slider's elapsed part outer color")] + [Category("ColorSlider")] + [DefaultValue(typeof(Color), "DarkGreen")] + public Color ElapsedOuterColor + { + get { return elapsedOuterColor; } + set + { + elapsedOuterColor = value; + Invalidate(); + } + } + + private Color elapsedInnerColor = Color.Chartreuse; + /// + /// Gets or sets the inner color of the elapsed. + /// + /// The inner color of the elapsed. + [Description("Set Slider's elapsed part inner color")] + [Category("ColorSlider")] + [DefaultValue(typeof(Color), "Chartreuse")] + public Color ElapsedInnerColor + { + get { return elapsedInnerColor; } + set + { + elapsedInnerColor = value; + Invalidate(); + } + } + + #endregion + + #region Color schemas + + //define own color schemas + private Color[,] aColorSchema = new Color[,] + { + { + Color.White, Color.Gainsboro, Color.Silver, Color.SkyBlue, Color.DarkSlateBlue, Color.Gainsboro, + Color.DarkGreen, Color.Chartreuse + }, + { + Color.White, Color.Gainsboro, Color.Silver, Color.Red, Color.DarkRed, Color.Gainsboro, Color.Coral, + Color.LightCoral + }, + { + Color.White, Color.Gainsboro, Color.Silver, Color.GreenYellow, Color.Yellow, Color.Gold, Color.Orange, + Color.OrangeRed + }, + { + Color.White, Color.Gainsboro, Color.Silver, Color.Red, Color.Crimson, Color.Gainsboro, Color.DarkViolet + , Color.Violet + } + }; + + public enum ColorSchemas + { + PerlBlueGreen, + PerlRedCoral, + PerlGold, + PerlRoyalColors + } + + private ColorSchemas colorSchema = ColorSchemas.PerlBlueGreen; + /// + /// Sets color schema. Color generalization / fast color changing. Has no effect when slider colors are changed manually after schema was applied. + /// + /// New color schema value + [Description("Set Slider color schema. Has no effect when slider colors are changed manually after schema was applied.")] + [Category("ColorSlider")] + [DefaultValue(typeof(ColorSchemas), "PerlBlueGreen")] + public ColorSchemas ColorSchema + { + get { return colorSchema; } + set + { + colorSchema = value; + byte sn = (byte)value; + thumbOuterColor = aColorSchema[sn, 0]; + thumbInnerColor = aColorSchema[sn, 1]; + thumbPenColor = aColorSchema[sn, 2]; + barOuterColor = aColorSchema[sn, 3]; + barInnerColor = aColorSchema[sn, 4]; + barPenColor = aColorSchema[sn, 5]; + elapsedOuterColor = aColorSchema[sn, 6]; + elapsedInnerColor = aColorSchema[sn, 7]; + + Invalidate(); + } + } + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The minimum value. + /// The maximum value. + /// The current value. + public ColorSlider(int min, int max, int value) + { + InitializeComponent(); + SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | + ControlStyles.ResizeRedraw | ControlStyles.Selectable | + ControlStyles.SupportsTransparentBackColor | ControlStyles.UserMouse | + ControlStyles.UserPaint, true); + BackColor = Color.Transparent; + + Minimum = min; + Maximum = max; + Value = value; + } + + /// + /// Initializes a new instance of the class. + /// + public ColorSlider() : this(0, 100, 50) { } + + #endregion + + #region Paint + + /// + /// Raises the event. + /// + /// A that contains the event data. + protected override void OnPaint(PaintEventArgs e) + { + if (!Enabled) + { + Color[] desaturatedColors = DesaturateColors(thumbOuterColor, thumbInnerColor, thumbPenColor, + barOuterColor, barInnerColor, barPenColor, + elapsedOuterColor, elapsedInnerColor); + DrawColorSlider(e, desaturatedColors[0], desaturatedColors[1], desaturatedColors[2], + desaturatedColors[3], + desaturatedColors[4], desaturatedColors[5], desaturatedColors[6], desaturatedColors[7]); + } + else + { + if (mouseEffects && mouseInRegion) + { + Color[] lightenedColors = LightenColors(thumbOuterColor, thumbInnerColor, thumbPenColor, + barOuterColor, barInnerColor, barPenColor, + elapsedOuterColor, elapsedInnerColor); + DrawColorSlider(e, lightenedColors[0], lightenedColors[1], lightenedColors[2], lightenedColors[3], + lightenedColors[4], lightenedColors[5], lightenedColors[6], lightenedColors[7]); + } + else + { + DrawColorSlider(e, thumbOuterColor, thumbInnerColor, thumbPenColor, + barOuterColor, barInnerColor, barPenColor, + elapsedOuterColor, elapsedInnerColor); + } + } + } + + /// + /// Draws the colorslider control using passed colors. + /// + /// The instance containing the event data. + /// The thumb outer color paint. + /// The thumb inner color paint. + /// The thumb pen color paint. + /// The bar outer color paint. + /// The bar inner color paint. + /// The bar pen color paint. + /// The elapsed outer color paint. + /// The elapsed inner color paint. + private void DrawColorSlider(PaintEventArgs e, Color thumbOuterColorPaint, Color thumbInnerColorPaint, + Color thumbPenColorPaint, Color barOuterColorPaint, Color barInnerColorPaint, + Color barPenColorPaint, Color elapsedOuterColorPaint, Color elapsedInnerColorPaint) + { + try + { + //set up thumbRect aproprietly + if (barOrientation == Orientation.Horizontal) + { + int TrackX = (((trackerValue - barMinimum) * (ClientRectangle.Width - thumbSize)) / (barMaximum - barMinimum)); + thumbRect = new Rectangle(TrackX, 1, thumbSize - 1, ClientRectangle.Height - 3); + } + else + { + int TrackY = (((trackerValue - barMinimum) * (ClientRectangle.Height - thumbSize)) / (barMaximum - barMinimum)); + thumbRect = new Rectangle(1, TrackY, ClientRectangle.Width - 3, thumbSize - 1); + } + + //adjust drawing rects + barRect = ClientRectangle; + thumbHalfRect = thumbRect; + LinearGradientMode gradientOrientation; + if (barOrientation == Orientation.Horizontal) + { + barRect.Inflate(-1, -barRect.Height / 3); + barHalfRect = barRect; + barHalfRect.Height /= 2; + gradientOrientation = LinearGradientMode.Vertical; + thumbHalfRect.Height /= 2; + elapsedRect = barRect; + elapsedRect.Width = thumbRect.Left + thumbSize / 2; + } + else + { + barRect.Inflate(-barRect.Width / 3, -1); + barHalfRect = barRect; + barHalfRect.Width /= 2; + gradientOrientation = LinearGradientMode.Horizontal; + thumbHalfRect.Width /= 2; + elapsedRect = barRect; + elapsedRect.Height = thumbRect.Top + thumbSize / 2; + } + //get thumb shape path + GraphicsPath thumbPath; + if (thumbCustomShape == null) + thumbPath = CreateRoundRectPath(thumbRect, thumbRoundRectSize); + else + { + thumbPath = thumbCustomShape; + Matrix m = new Matrix(); + m.Translate(thumbRect.Left - thumbPath.GetBounds().Left, thumbRect.Top - thumbPath.GetBounds().Top); + thumbPath.Transform(m); + } + + //draw bar + using ( + LinearGradientBrush lgbBar = + new LinearGradientBrush(barHalfRect, barOuterColorPaint, barInnerColorPaint, gradientOrientation) + ) + { + lgbBar.WrapMode = WrapMode.TileFlipXY; + e.Graphics.FillRectangle(lgbBar, barRect); + //draw elapsed bar + using ( + LinearGradientBrush lgbElapsed = + new LinearGradientBrush(barHalfRect, elapsedOuterColorPaint, elapsedInnerColorPaint, + gradientOrientation)) + { + lgbElapsed.WrapMode = WrapMode.TileFlipXY; + if (Capture && drawSemitransparentThumb) + { + Region elapsedReg = new Region(elapsedRect); + elapsedReg.Exclude(thumbPath); + e.Graphics.FillRegion(lgbElapsed, elapsedReg); + } + else + e.Graphics.FillRectangle(lgbElapsed, elapsedRect); + } + //draw bar band + using (Pen barPen = new Pen(barPenColorPaint, 0.5f)) + { + e.Graphics.DrawRectangle(barPen, barRect); + } + } + + //draw thumb + Color newthumbOuterColorPaint = thumbOuterColorPaint, newthumbInnerColorPaint = thumbInnerColorPaint; + if (Capture && drawSemitransparentThumb) + { + newthumbOuterColorPaint = Color.FromArgb(175, thumbOuterColorPaint); + newthumbInnerColorPaint = Color.FromArgb(175, thumbInnerColorPaint); + } + using ( + LinearGradientBrush lgbThumb = + new LinearGradientBrush(thumbHalfRect, newthumbOuterColorPaint, newthumbInnerColorPaint, + gradientOrientation)) + { + lgbThumb.WrapMode = WrapMode.TileFlipXY; + e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; + e.Graphics.FillPath(lgbThumb, thumbPath); + //draw thumb band + Color newThumbPenColor = thumbPenColorPaint; + if (mouseEffects && (Capture || mouseInThumbRegion)) + newThumbPenColor = ControlPaint.Dark(newThumbPenColor); + using (Pen thumbPen = new Pen(newThumbPenColor)) + { + e.Graphics.DrawPath(thumbPen, thumbPath); + } + //gp.Dispose(); + /*if (Capture || mouseInThumbRegion) + using (LinearGradientBrush lgbThumb2 = new LinearGradientBrush(thumbHalfRect, Color.FromArgb(150, Color.Blue), Color.Transparent, gradientOrientation)) + { + lgbThumb2.WrapMode = WrapMode.TileFlipXY; + e.Graphics.FillPath(lgbThumb2, gp); + }*/ + } + + //draw focusing rectangle + if (Focused & drawFocusRectangle) + using (Pen p = new Pen(Color.FromArgb(200, barPenColorPaint))) + { + p.DashStyle = DashStyle.Dot; + Rectangle r = ClientRectangle; + r.Width -= 2; + r.Height--; + r.X++; + //ControlPaint.DrawFocusRectangle(e.Graphics, r); + using (GraphicsPath gpBorder = CreateRoundRectPath(r, borderRoundRectSize)) + { + e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; + e.Graphics.DrawPath(p, gpBorder); + } + } + } + catch (Exception Err) + { + Console.WriteLine("DrawBackGround Error in " + Name + ":" + Err.Message); + } + finally + { + } + } + + #endregion + + #region Overided events + + private bool mouseInRegion = false; + /// + /// Raises the event. + /// + /// An that contains the event data. + protected override void OnEnabledChanged(EventArgs e) + { + base.OnEnabledChanged(e); + Invalidate(); + } + + /// + /// Raises the event. + /// + /// An that contains the event data. + protected override void OnMouseEnter(EventArgs e) + { + base.OnMouseEnter(e); + mouseInRegion = true; + Invalidate(); + } + + /// + /// Raises the event. + /// + /// An that contains the event data. + protected override void OnMouseLeave(EventArgs e) + { + base.OnMouseLeave(e); + mouseInRegion = false; + mouseInThumbRegion = false; + Invalidate(); + } + + /// + /// Raises the event. + /// + /// A that contains the event data. + protected override void OnMouseDown(MouseEventArgs e) + { + base.OnMouseDown(e); + if (e.Button == MouseButtons.Left) + { + Capture = true; + if (Scroll != null) Scroll(this, new ScrollEventArgs(ScrollEventType.ThumbTrack, trackerValue)); + if (ValueChanged != null) ValueChanged(this, new EventArgs()); + OnMouseMove(e); + } + } + + private bool mouseInThumbRegion = false; + + /// + /// Raises the event. + /// + /// A that contains the event data. + protected override void OnMouseMove(MouseEventArgs e) + { + base.OnMouseMove(e); + mouseInThumbRegion = IsPointInRect(e.Location, thumbRect); + if (Capture & e.Button == MouseButtons.Left) + { + ScrollEventType set = ScrollEventType.ThumbPosition; + Point pt = e.Location; + int p = barOrientation == Orientation.Horizontal ? pt.X : pt.Y; + int margin = thumbSize >> 1; + p -= margin; + float coef = (float)(barMaximum - barMinimum) / + (float) + ((barOrientation == Orientation.Horizontal ? ClientSize.Width : ClientSize.Height) - + 2 * margin); + trackerValue = (int)(p * coef + barMinimum); + + if (trackerValue <= barMinimum) + { + trackerValue = barMinimum; + set = ScrollEventType.First; + } + else if (trackerValue >= barMaximum) + { + trackerValue = barMaximum; + set = ScrollEventType.Last; + } + + if (Scroll != null) Scroll(this, new ScrollEventArgs(set, trackerValue)); + if (ValueChanged != null) ValueChanged(this, new EventArgs()); + } + Invalidate(); + } + + /// + /// Raises the event. + /// + /// A that contains the event data. + protected override void OnMouseUp(MouseEventArgs e) + { + base.OnMouseUp(e); + Capture = false; + mouseInThumbRegion = IsPointInRect(e.Location, thumbRect); + if (Scroll != null) Scroll(this, new ScrollEventArgs(ScrollEventType.EndScroll, trackerValue)); + if (ValueChanged != null) ValueChanged(this, new EventArgs()); + Invalidate(); + } + + /// + /// Raises the event. + /// + /// A that contains the event data. + protected override void OnMouseWheel(MouseEventArgs e) + { + base.OnMouseWheel(e); + int v = e.Delta / 120 * (barMaximum - barMinimum) / mouseWheelBarPartitions; + SetProperValue(Value + v); + } + + /// + /// Raises the event. + /// + /// An that contains the event data. + protected override void OnGotFocus(EventArgs e) + { + base.OnGotFocus(e); + Invalidate(); + } + + /// + /// Raises the event. + /// + /// An that contains the event data. + protected override void OnLostFocus(EventArgs e) + { + base.OnLostFocus(e); + Invalidate(); + } + + /// + /// Raises the event. + /// + /// A that contains the event data. + protected override void OnKeyUp(KeyEventArgs e) + { + base.OnKeyUp(e); + switch (e.KeyCode) + { + case Keys.Down: + case Keys.Left: + SetProperValue(Value - (int)smallChange); + if (Scroll != null) Scroll(this, new ScrollEventArgs(ScrollEventType.SmallDecrement, Value)); + break; + case Keys.Up: + case Keys.Right: + SetProperValue(Value + (int)smallChange); + if (Scroll != null) Scroll(this, new ScrollEventArgs(ScrollEventType.SmallIncrement, Value)); + break; + case Keys.Home: + Value = barMinimum; + break; + case Keys.End: + Value = barMaximum; + break; + case Keys.PageDown: + SetProperValue(Value - (int)largeChange); + if (Scroll != null) Scroll(this, new ScrollEventArgs(ScrollEventType.LargeDecrement, Value)); + break; + case Keys.PageUp: + SetProperValue(Value + (int)largeChange); + if (Scroll != null) Scroll(this, new ScrollEventArgs(ScrollEventType.LargeIncrement, Value)); + break; + } + if (Scroll != null && Value == barMinimum) Scroll(this, new ScrollEventArgs(ScrollEventType.First, Value)); + if (Scroll != null && Value == barMaximum) Scroll(this, new ScrollEventArgs(ScrollEventType.Last, Value)); + Point pt = PointToClient(Cursor.Position); + OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, pt.X, pt.Y, 0)); + } + + /// + /// Processes a dialog key. + /// + /// One of the values that represents the key to process. + /// + /// true if the key was processed by the control; otherwise, false. + /// + protected override bool ProcessDialogKey(Keys keyData) + { + if (keyData == Keys.Tab | ModifierKeys == Keys.Shift) + return base.ProcessDialogKey(keyData); + else + { + OnKeyDown(new KeyEventArgs(keyData)); + return true; + } + } + + #endregion + + #region Help routines + + /// + /// Creates the round rect path. + /// + /// The rectangle on which graphics path will be spanned. + /// The size of rounded rectangle edges. + /// + public static GraphicsPath CreateRoundRectPath(Rectangle rect, Size size) + { + GraphicsPath gp = new GraphicsPath(); + gp.AddLine(rect.Left + size.Width / 2, rect.Top, rect.Right - size.Width / 2, rect.Top); + gp.AddArc(rect.Right - size.Width, rect.Top, size.Width, size.Height, 270, 90); + + gp.AddLine(rect.Right, rect.Top + size.Height / 2, rect.Right, rect.Bottom - size.Width / 2); + gp.AddArc(rect.Right - size.Width, rect.Bottom - size.Height, size.Width, size.Height, 0, 90); + + gp.AddLine(rect.Right - size.Width / 2, rect.Bottom, rect.Left + size.Width / 2, rect.Bottom); + gp.AddArc(rect.Left, rect.Bottom - size.Height, size.Width, size.Height, 90, 90); + + gp.AddLine(rect.Left, rect.Bottom - size.Height / 2, rect.Left, rect.Top + size.Height / 2); + gp.AddArc(rect.Left, rect.Top, size.Width, size.Height, 180, 90); + return gp; + } + + /// + /// Desaturates colors from given array. + /// + /// The colors to be desaturated. + /// + public static Color[] DesaturateColors(params Color[] colorsToDesaturate) + { + Color[] colorsToReturn = new Color[colorsToDesaturate.Length]; + for (int i = 0; i < colorsToDesaturate.Length; i++) + { + //use NTSC weighted avarage + int gray = + (int)(colorsToDesaturate[i].R * 0.3 + colorsToDesaturate[i].G * 0.6 + colorsToDesaturate[i].B * 0.1); + colorsToReturn[i] = Color.FromArgb(-0x010101 * (255 - gray) - 1); + } + return colorsToReturn; + } + + /// + /// Lightens colors from given array. + /// + /// The colors to lighten. + /// + public static Color[] LightenColors(params Color[] colorsToLighten) + { + Color[] colorsToReturn = new Color[colorsToLighten.Length]; + for (int i = 0; i < colorsToLighten.Length; i++) + { + colorsToReturn[i] = ControlPaint.Light(colorsToLighten[i]); + } + return colorsToReturn; + } + + /// + /// Sets the trackbar value so that it wont exceed allowed range. + /// + /// The value. + private void SetProperValue(int val) + { + if (val < barMinimum) Value = barMinimum; + else if (val > barMaximum) Value = barMaximum; + else Value = val; + } + + /// + /// Determines whether rectangle contains given point. + /// + /// The point to test. + /// The base rectangle. + /// + /// true if rectangle contains given point; otherwise, false. + /// + private static bool IsPointInRect(Point pt, Rectangle rect) + { + if (pt.X > rect.Left & pt.X < rect.Right & pt.Y > rect.Top & pt.Y < rect.Bottom) + return true; + else return false; + } + + #endregion + } +} \ No newline at end of file diff --git a/RayTracerApp/ColorSlider/ColorSlider.resx b/RayTracerApp/ColorSlider/ColorSlider.resx new file mode 100644 index 0000000..52a9ad3 --- /dev/null +++ b/RayTracerApp/ColorSlider/ColorSlider.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + False + + \ No newline at end of file diff --git a/RayTracerApp/Forms/EditObjectForm.Designer.cs b/RayTracerApp/Forms/EditObjectForm.Designer.cs index 893c1bb..126b342 100644 --- a/RayTracerApp/Forms/EditObjectForm.Designer.cs +++ b/RayTracerApp/Forms/EditObjectForm.Designer.cs @@ -44,6 +44,9 @@ private void InitializeComponent() // // positionPanel // + this.positionPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.positionPanel.Controller = null; this.positionPanel.Location = new System.Drawing.Point(0, 26); this.positionPanel.Name = "positionPanel"; @@ -52,6 +55,9 @@ private void InitializeComponent() // // materialPanel // + this.materialPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.materialPanel.Controller = null; this.materialPanel.Location = new System.Drawing.Point(0, 26); this.materialPanel.Name = "materialPanel"; @@ -67,7 +73,7 @@ private void InitializeComponent() this.Controls.Add(this.positionPanel); this.Controls.Add(this.featuresPanel); this.Name = "EditObjectForm"; - this.Text = "EditObjectForm"; + this.Text = "Edit"; this.Controls.SetChildIndex(this.rightNextButton, 0); this.Controls.SetChildIndex(this.middlePreviousButton, 0); this.Controls.SetChildIndex(this.leftCancelButton, 0); diff --git a/RayTracerApp/Forms/MainForm.Designer.cs b/RayTracerApp/Forms/MainForm.Designer.cs index 0f73543..f132cf6 100644 --- a/RayTracerApp/Forms/MainForm.Designer.cs +++ b/RayTracerApp/Forms/MainForm.Designer.cs @@ -136,6 +136,7 @@ private void InitializeNewEditMenu() private void InitializeToolstrip() { this.toolStrip = new System.Windows.Forms.ToolStrip(); + this.settingsButton = new System.Windows.Forms.ToolStripButton(); this.newObjectButton = new System.Windows.Forms.ToolStripButton(); this.editObjectButton = new System.Windows.Forms.ToolStripButton(); this.deleteObjectButton = new System.Windows.Forms.ToolStripButton(); @@ -151,7 +152,8 @@ private void InitializeToolstrip() }); this.toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.ddButton + this.ddButton, + this.settingsButton }); this.toolStrip.Location = new System.Drawing.Point(0, 0); @@ -159,6 +161,12 @@ private void InitializeToolstrip() this.toolStrip.TabIndex = 1; this.toolStrip.Text = "toolStrip"; + this.settingsButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.settingsButton.Name = "settingsButton"; + this.settingsButton.Text = "Settings"; + this.settingsButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.settingsButton.Click += new System.EventHandler(this.settingsButton_Click); + this.newObjectButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; this.newObjectButton.Name = "newObjectButton"; this.newObjectButton.Text = "New object"; @@ -184,6 +192,7 @@ private void InitializeToolstrip() } private ToolStrip toolStrip; + private ToolStripButton settingsButton; private ToolStripButton newObjectButton; private ToolStripButton editObjectButton; private ToolStripButton deleteObjectButton; diff --git a/RayTracerApp/Forms/MainForm.cs b/RayTracerApp/Forms/MainForm.cs index e0a43af..ec1ecd9 100644 --- a/RayTracerApp/Forms/MainForm.cs +++ b/RayTracerApp/Forms/MainForm.cs @@ -129,7 +129,7 @@ private void InitializeFpsTimer() private void OnTimerTick(object sender, EventArgs e) { _cameraController.UpdateCamera(_fpsTimer.Interval); - + if (!rayTracingStarted) if (ShouldRaytrace()) { @@ -139,7 +139,7 @@ private void OnTimerTick(object sender, EventArgs e) } else { - _renderer.Render(_scene, _camera); + _renderer.Render(_scene, _cameraController.GetCamera()); gLControl.SwapBuffers(); } } @@ -155,7 +155,7 @@ private void UpdateViewport() gLControl.Height = Height; gLControl.Width = Width; GL.Viewport(0, 0, Width, Height); - _camera.AspectRatio = gLControl.Width / (float) gLControl.Height; + _cameraController.GetCamera().AspectRatio = gLControl.Width / (float) gLControl.Height; gLControl.Invalidate(); _rayTracer.Resolution = gLControl.Width; } @@ -164,7 +164,7 @@ private void StartRender(object sender, DoWorkEventArgs e) { _rayTracer.OnFrameReady = _backgroundWorker.ReportProgress; _rayTracer.CancellationToken = _cts.Token; - _rayTracer.Render(_scene, _camera); + _rayTracer.Render(_scene, _cameraController.GetCamera()); } private void BackgroundWorkerProgressChanged(object sender, @@ -192,12 +192,31 @@ private void InitializeBackgroundWorker() private void newObjectButton_Click(object sender, EventArgs e) { - var ray = _camera.GetRay(0.5f, 0.5f); + var ray = _cameraController.GetCamera().GetRay(0.5f, 0.5f); var hitInfo = new HitInfo(); var hit = _scene.HitTest(ray, ref hitInfo, 0.001f, float.PositiveInfinity); NewObjectFunction(hit, ref hitInfo); } - + + private void settingsButton_Click(object sender, EventArgs e) + { + UpdateLastModification(); + _isUiUsed = true; + + var controller = new SettingsController(_camera, _rayTracer); + var form = new SettingsForm(controller) + { StartPosition = FormStartPosition.Manual, Location = Location + Size / 3 }; + + form.Closed += FormOnClosed; + form.Closed += (a, b) => + { + _camera = controller.Camera; + _cameraController = new CameraController(_camera, gLControl, UpdateLastModification); + _rayTracer = controller.RayTracer; + }; + form.Show(); + } + private void NewObjectFunction(bool hit, ref HitInfo hitInfo) { UpdateLastModification(); @@ -221,7 +240,7 @@ private void NewObjectFunction(bool hit, ref HitInfo hitInfo) private void editObjectButton_Click(object sender, EventArgs e) { - var ray = _camera.GetRay(0.5f, 0.5f); + var ray = _cameraController.GetCamera().GetRay(0.5f, 0.5f); var hitInfo = new HitInfo(); var hit = _scene.HitTest(ray, ref hitInfo, 0.001f, float.PositiveInfinity); EditObjectFunction(hit, ref hitInfo); @@ -257,7 +276,7 @@ private void EditObjectFunction(bool hit, ref HitInfo hitInfo) private void deleteObjectButton_Click(object sender, EventArgs e) { - var ray = _camera.GetRay(0.5f, 0.5f); + var ray = _cameraController.GetCamera().GetRay(0.5f, 0.5f); var hitInfo = new HitInfo(); var hit = _scene.HitTest(ray, ref hitInfo, 0.001f, float.PositiveInfinity); DeleteObjectFunction(hit, ref hitInfo); @@ -273,7 +292,7 @@ private void DeleteObjectFunction(bool hit, ref HitInfo hitInfo) if (model is Triangle triangle) model = triangle.Parent; string message = $"Are you sure that you would like to delete the {model}?"; - const string caption = "Form Closing"; + const string caption = "Delete object"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); @@ -295,7 +314,7 @@ private void GLControl_MouseClick(object sender, MouseEventArgs e) var height = (float)gLControl.Height; var u = e.X / width; var v = 1 - e.Y / height; - var ray = _camera.GetRay(u, v); + var ray = _cameraController.GetCamera().GetRay(u, v); _contextHitInfo = new HitInfo(); _contextHit = _scene.HitTest(ray, ref _contextHitInfo, 0.001f, float.PositiveInfinity); diff --git a/RayTracerApp/Forms/NewObjectForm.Designer.cs b/RayTracerApp/Forms/NewObjectForm.Designer.cs index e73a6fb..a533015 100644 --- a/RayTracerApp/Forms/NewObjectForm.Designer.cs +++ b/RayTracerApp/Forms/NewObjectForm.Designer.cs @@ -52,21 +52,27 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.featuresPanel.Controller = null; - this.featuresPanel.Location = new System.Drawing.Point(0, 26); + this.featuresPanel.Location = new System.Drawing.Point(0, 28); this.featuresPanel.Name = "featuresPanel"; - this.featuresPanel.Size = new System.Drawing.Size(484, 594); + this.featuresPanel.Size = new System.Drawing.Size(484, 592); this.featuresPanel.TabIndex = 7; // // positionPanel // + this.positionPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.positionPanel.Controller = null; - this.positionPanel.Location = new System.Drawing.Point(0, 26); + this.positionPanel.Location = new System.Drawing.Point(0, 41); this.positionPanel.Name = "positionPanel"; - this.positionPanel.Size = new System.Drawing.Size(484, 594); + this.positionPanel.Size = new System.Drawing.Size(484, 565); this.positionPanel.TabIndex = 8; // // materialPanel // + this.materialPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.materialPanel.Controller = null; this.materialPanel.Location = new System.Drawing.Point(0, 26); this.materialPanel.Name = "materialPanel"; @@ -83,7 +89,7 @@ private void InitializeComponent() this.Controls.Add(this.featuresPanel); this.Controls.Add(this.objectSelectionPanel); this.Name = "NewObjectForm"; - this.Text = "NewObjectForm"; + this.Text = "Add new model..."; this.Controls.SetChildIndex(this.rightNextButton, 0); this.Controls.SetChildIndex(this.middlePreviousButton, 0); this.Controls.SetChildIndex(this.leftCancelButton, 0); diff --git a/RayTracerApp/Forms/SettingsForm.Designer.cs b/RayTracerApp/Forms/SettingsForm.Designer.cs index 8646e2d..341a770 100644 --- a/RayTracerApp/Forms/SettingsForm.Designer.cs +++ b/RayTracerApp/Forms/SettingsForm.Designer.cs @@ -30,43 +30,63 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.label3 = new System.Windows.Forms.Label(); - this.label4 = new System.Windows.Forms.Label(); - this.label5 = new System.Windows.Forms.Label(); - this.linkLabel1 = new System.Windows.Forms.LinkLabel(); this.groupBox2 = new System.Windows.Forms.GroupBox(); - this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); + this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel(); + this.label13 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.label10 = new System.Windows.Forms.Label(); + this.label11 = new System.Windows.Forms.Label(); + this.label12 = new System.Windows.Forms.Label(); + this.samplesUpDown = new System.Windows.Forms.NumericUpDown(); + this.updateUpDown = new System.Windows.Forms.NumericUpDown(); + this.bloomUpDown = new System.Windows.Forms.NumericUpDown(); + this.recursionCheckbox = new System.Windows.Forms.CheckBox(); + this.gammaUpDown = new System.Windows.Forms.NumericUpDown(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); + this.panel2 = new System.Windows.Forms.Panel(); + this.randomRadioButton = new System.Windows.Forms.RadioButton(); + this.centerRadioButton = new System.Windows.Forms.RadioButton(); + this.jitteredRadioButton = new System.Windows.Forms.RadioButton(); this.label6 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.label8 = new System.Windows.Forms.Label(); this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); this.panel1 = new System.Windows.Forms.Panel(); - this.radioButton1 = new System.Windows.Forms.RadioButton(); - this.radioButton2 = new System.Windows.Forms.RadioButton(); - this.radioButton3 = new System.Windows.Forms.RadioButton(); - this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); - this.panel2 = new System.Windows.Forms.Panel(); - this.radioButton4 = new System.Windows.Forms.RadioButton(); - this.radioButton5 = new System.Windows.Forms.RadioButton(); - this.radioButton6 = new System.Windows.Forms.RadioButton(); - this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel(); - this.label9 = new System.Windows.Forms.Label(); - this.label10 = new System.Windows.Forms.Label(); - this.label11 = new System.Windows.Forms.Label(); - this.label12 = new System.Windows.Forms.Label(); - this.label13 = new System.Windows.Forms.Label(); + this.ortographicCameraRadioButton = new System.Windows.Forms.RadioButton(); + this.lensCameraRadioButton = new System.Windows.Forms.RadioButton(); + this.perspectiveCameraRadioButton = new System.Windows.Forms.RadioButton(); + this.lensCameraLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.label15 = new System.Windows.Forms.Label(); + this.lensRadiusUpDown = new System.Windows.Forms.NumericUpDown(); + this.focusDistanceUpDown = new System.Windows.Forms.NumericUpDown(); + this.label14 = new System.Windows.Forms.Label(); + this.fovUpDown = new System.Windows.Forms.NumericUpDown(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.linkLabel1 = new System.Windows.Forms.LinkLabel(); + this.label16 = new System.Windows.Forms.Label(); + this.recLevelUpDown = new System.Windows.Forms.NumericUpDown(); this.tableLayoutPanel1.SuspendLayout(); this.groupBox2.SuspendLayout(); - this.tableLayoutPanel2.SuspendLayout(); + this.tableLayoutPanel4.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.samplesUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.updateUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.bloomUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.gammaUpDown)).BeginInit(); this.groupBox1.SuspendLayout(); + this.tableLayoutPanel2.SuspendLayout(); + this.panel2.SuspendLayout(); this.tableLayoutPanel3.SuspendLayout(); this.panel1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); - this.panel2.SuspendLayout(); - this.tableLayoutPanel4.SuspendLayout(); + this.lensCameraLayoutPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.lensRadiusUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.focusDistanceUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.fovUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.recLevelUpDown)).BeginInit(); this.SuspendLayout(); // // tableLayoutPanel1 @@ -81,68 +101,205 @@ private void InitializeComponent() this.tableLayoutPanel1.RowCount = 2; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel1.Size = new System.Drawing.Size(623, 654); + this.tableLayoutPanel1.Size = new System.Drawing.Size(611, 586); this.tableLayoutPanel1.TabIndex = 0; // - // label1 + // groupBox2 // - this.label1.Location = new System.Drawing.Point(0, 0); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(100, 23); - this.label1.TabIndex = 0; - this.label1.Text = "label1"; + this.groupBox2.Controls.Add(this.tableLayoutPanel4); + this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill; + this.groupBox2.Location = new System.Drawing.Point(3, 296); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(605, 287); + this.groupBox2.TabIndex = 1; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Ray Tracer"; // - // label2 + // tableLayoutPanel4 // - this.label2.Location = new System.Drawing.Point(0, 0); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(100, 23); - this.label2.TabIndex = 0; - this.label2.Text = "label2"; + this.tableLayoutPanel4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel4.ColumnCount = 2; + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel4.Controls.Add(this.label16, 0, 5); + this.tableLayoutPanel4.Controls.Add(this.label9, 0, 0); + this.tableLayoutPanel4.Controls.Add(this.label10, 0, 1); + this.tableLayoutPanel4.Controls.Add(this.label11, 0, 2); + this.tableLayoutPanel4.Controls.Add(this.label12, 0, 3); + this.tableLayoutPanel4.Controls.Add(this.samplesUpDown, 1, 0); + this.tableLayoutPanel4.Controls.Add(this.updateUpDown, 1, 1); + this.tableLayoutPanel4.Controls.Add(this.bloomUpDown, 1, 3); + this.tableLayoutPanel4.Controls.Add(this.gammaUpDown, 1, 2); + this.tableLayoutPanel4.Controls.Add(this.recursionCheckbox, 1, 4); + this.tableLayoutPanel4.Controls.Add(this.label13, 0, 4); + this.tableLayoutPanel4.Controls.Add(this.recLevelUpDown, 1, 5); + this.tableLayoutPanel4.Location = new System.Drawing.Point(6, 22); + this.tableLayoutPanel4.Name = "tableLayoutPanel4"; + this.tableLayoutPanel4.RowCount = 6; + this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); + this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); + this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); + this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); + this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); + this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); + this.tableLayoutPanel4.Size = new System.Drawing.Size(587, 256); + this.tableLayoutPanel4.TabIndex = 0; + this.tableLayoutPanel4.CellPaint += new System.Windows.Forms.TableLayoutCellPaintEventHandler(this.tableLayoutPanel_CellPaint); // - // label3 + // label13 // - this.label3.Location = new System.Drawing.Point(0, 0); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(100, 23); - this.label3.TabIndex = 0; - this.label3.Text = "label3"; + this.label13.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label13.AutoSize = true; + this.label13.Location = new System.Drawing.Point(30, 181); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(232, 15); + this.label13.TabIndex = 5; + this.label13.Text = "Ray tracing by recursion levels (unoptimal)"; + this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label4 + // label9 // - this.label4.Location = new System.Drawing.Point(0, 0); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(100, 23); - this.label4.TabIndex = 0; - this.label4.Text = "label4"; + this.label9.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(121, 13); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(51, 15); + this.label9.TabIndex = 1; + this.label9.Text = "Samples"; + this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label5 + // label10 // - this.label5.Location = new System.Drawing.Point(0, 0); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(100, 23); - this.label5.TabIndex = 0; - this.label5.Text = "label5"; + this.label10.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(96, 55); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(101, 15); + this.label10.TabIndex = 2; + this.label10.Text = "Update frequency"; + this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // linkLabel1 + // label11 // - this.linkLabel1.Location = new System.Drawing.Point(0, 0); - this.linkLabel1.Name = "linkLabel1"; - this.linkLabel1.Size = new System.Drawing.Size(100, 23); - this.linkLabel1.TabIndex = 0; - this.linkLabel1.TabStop = true; - this.linkLabel1.Text = "linkLabel1"; + this.label11.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label11.AutoSize = true; + this.label11.Location = new System.Drawing.Point(93, 97); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(106, 15); + this.label11.TabIndex = 3; + this.label11.Text = "Gamma correction"; + this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // groupBox2 + // label12 // - this.groupBox2.Controls.Add(this.tableLayoutPanel4); - this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill; - this.groupBox2.Location = new System.Drawing.Point(3, 330); - this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(617, 321); - this.groupBox2.TabIndex = 1; - this.groupBox2.TabStop = false; - this.groupBox2.Text = "Ray Tracer"; + this.label12.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label12.AutoSize = true; + this.label12.Location = new System.Drawing.Point(125, 139); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(42, 15); + this.label12.TabIndex = 4; + this.label12.Text = "Bloom"; + this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // samplesUpDown + // + this.samplesUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; + this.samplesUpDown.Location = new System.Drawing.Point(380, 9); + this.samplesUpDown.Maximum = new decimal(new int[] { + 100000, + 0, + 0, + 0}); + this.samplesUpDown.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.samplesUpDown.Name = "samplesUpDown"; + this.samplesUpDown.Size = new System.Drawing.Size(120, 23); + this.samplesUpDown.TabIndex = 6; + this.samplesUpDown.Value = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.samplesUpDown.ValueChanged += new System.EventHandler(this.samplesUpDown_ValueChanged); + // + // updateUpDown + // + this.updateUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; + this.updateUpDown.Location = new System.Drawing.Point(380, 51); + this.updateUpDown.Maximum = new decimal(new int[] { + 100000, + 0, + 0, + 0}); + this.updateUpDown.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.updateUpDown.Name = "updateUpDown"; + this.updateUpDown.Size = new System.Drawing.Size(120, 23); + this.updateUpDown.TabIndex = 7; + this.updateUpDown.Value = new decimal(new int[] { + 30, + 0, + 0, + 0}); + this.updateUpDown.ValueChanged += new System.EventHandler(this.updateUpDown_ValueChanged); + // + // bloomUpDown + // + this.bloomUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; + this.bloomUpDown.Location = new System.Drawing.Point(380, 135); + this.bloomUpDown.Name = "bloomUpDown"; + this.bloomUpDown.Size = new System.Drawing.Size(120, 23); + this.bloomUpDown.TabIndex = 11; + this.bloomUpDown.Value = new decimal(new int[] { + 30, + 0, + 0, + 0}); + this.bloomUpDown.ValueChanged += new System.EventHandler(this.bloomUpDown_ValueChanged); + // + // recursionCheckbox + // + this.recursionCheckbox.Anchor = System.Windows.Forms.AnchorStyles.None; + this.recursionCheckbox.AutoSize = true; + this.recursionCheckbox.Location = new System.Drawing.Point(432, 182); + this.recursionCheckbox.Name = "recursionCheckbox"; + this.recursionCheckbox.Size = new System.Drawing.Size(15, 14); + this.recursionCheckbox.TabIndex = 10; + this.recursionCheckbox.UseVisualStyleBackColor = true; + this.recursionCheckbox.CheckedChanged += new System.EventHandler(this.recursionCheckbox_CheckedChanged); + // + // gammaUpDown + // + this.gammaUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; + this.gammaUpDown.Location = new System.Drawing.Point(380, 93); + this.gammaUpDown.Name = "gammaUpDown"; + this.gammaUpDown.Size = new System.Drawing.Size(120, 23); + this.gammaUpDown.TabIndex = 12; + this.gammaUpDown.Value = new decimal(new int[] { + 30, + 0, + 0, + 0}); + this.gammaUpDown.ValueChanged += new System.EventHandler(this.gammaUpDown_ValueChanged); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.tableLayoutPanel2); + this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.groupBox1.Location = new System.Drawing.Point(3, 3); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(605, 287); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Camera"; // // tableLayoutPanel2 // @@ -157,32 +314,79 @@ private void InitializeComponent() this.tableLayoutPanel2.Controls.Add(this.label7, 0, 1); this.tableLayoutPanel2.Controls.Add(this.label8, 0, 2); this.tableLayoutPanel2.Controls.Add(this.tableLayoutPanel3, 1, 0); - this.tableLayoutPanel2.Controls.Add(this.numericUpDown1, 1, 1); + this.tableLayoutPanel2.Controls.Add(this.fovUpDown, 1, 1); this.tableLayoutPanel2.Location = new System.Drawing.Point(6, 22); this.tableLayoutPanel2.Name = "tableLayoutPanel2"; this.tableLayoutPanel2.RowCount = 3; this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); - this.tableLayoutPanel2.Size = new System.Drawing.Size(602, 293); + this.tableLayoutPanel2.Size = new System.Drawing.Size(590, 259); this.tableLayoutPanel2.TabIndex = 0; + this.tableLayoutPanel2.CellPaint += new System.Windows.Forms.TableLayoutCellPaintEventHandler(this.tableLayoutPanel_CellPaint); // - // groupBox1 + // panel2 // - this.groupBox1.Controls.Add(this.tableLayoutPanel2); - this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill; - this.groupBox1.Location = new System.Drawing.Point(3, 3); - this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(617, 321); - this.groupBox1.TabIndex = 0; - this.groupBox1.TabStop = false; - this.groupBox1.Text = "Camera"; + this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel2.Controls.Add(this.randomRadioButton); + this.panel2.Controls.Add(this.centerRadioButton); + this.panel2.Controls.Add(this.jitteredRadioButton); + this.panel2.Location = new System.Drawing.Point(298, 175); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(289, 81); + this.panel2.TabIndex = 5; + // + // randomRadioButton + // + this.randomRadioButton.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.randomRadioButton.AutoSize = true; + this.randomRadioButton.Location = new System.Drawing.Point(0, 54); + this.randomRadioButton.Name = "randomRadioButton"; + this.randomRadioButton.Size = new System.Drawing.Size(70, 19); + this.randomRadioButton.TabIndex = 2; + this.randomRadioButton.Text = "Random"; + this.randomRadioButton.UseVisualStyleBackColor = true; + this.randomRadioButton.CheckedChanged += new System.EventHandler(this.randomRadioButton_CheckedChanged); + // + // centerRadioButton + // + this.centerRadioButton.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.centerRadioButton.AutoSize = true; + this.centerRadioButton.Location = new System.Drawing.Point(0, 29); + this.centerRadioButton.Name = "centerRadioButton"; + this.centerRadioButton.Size = new System.Drawing.Size(60, 19); + this.centerRadioButton.TabIndex = 1; + this.centerRadioButton.Text = "Center"; + this.centerRadioButton.UseVisualStyleBackColor = true; + this.centerRadioButton.CheckedChanged += new System.EventHandler(this.centerRadioButton_CheckedChanged); + // + // jitteredRadioButton + // + this.jitteredRadioButton.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.jitteredRadioButton.AutoSize = true; + this.jitteredRadioButton.Checked = true; + this.jitteredRadioButton.Location = new System.Drawing.Point(0, 4); + this.jitteredRadioButton.Name = "jitteredRadioButton"; + this.jitteredRadioButton.Size = new System.Drawing.Size(63, 19); + this.jitteredRadioButton.TabIndex = 0; + this.jitteredRadioButton.TabStop = true; + this.jitteredRadioButton.Text = "Jittered"; + this.jitteredRadioButton.UseVisualStyleBackColor = true; + this.jitteredRadioButton.CheckedChanged += new System.EventHandler(this.jitteredRadioButton_CheckedChanged); // // label6 // this.label6.Anchor = System.Windows.Forms.AnchorStyles.None; this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(113, 41); + this.label6.Location = new System.Drawing.Point(110, 35); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(74, 15); this.label6.TabIndex = 0; @@ -193,7 +397,7 @@ private void InitializeComponent() // this.label7.Anchor = System.Windows.Forms.AnchorStyles.None; this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(114, 138); + this.label7.Location = new System.Drawing.Point(111, 121); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(73, 15); this.label7.TabIndex = 1; @@ -204,7 +408,7 @@ private void InitializeComponent() // this.label8.Anchor = System.Windows.Forms.AnchorStyles.None; this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(122, 236); + this.label8.Location = new System.Drawing.Point(119, 208); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(57, 15); this.label8.TabIndex = 2; @@ -220,12 +424,13 @@ private void InitializeComponent() this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel3.Controls.Add(this.panel1, 0, 0); - this.tableLayoutPanel3.Location = new System.Drawing.Point(304, 3); + this.tableLayoutPanel3.Controls.Add(this.lensCameraLayoutPanel, 1, 0); + this.tableLayoutPanel3.Location = new System.Drawing.Point(298, 3); this.tableLayoutPanel3.Name = "tableLayoutPanel3"; this.tableLayoutPanel3.RowCount = 1; this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); - this.tableLayoutPanel3.Size = new System.Drawing.Size(295, 91); + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 80F)); + this.tableLayoutPanel3.Size = new System.Drawing.Size(289, 80); this.tableLayoutPanel3.TabIndex = 3; // // panel1 @@ -233,224 +438,275 @@ private void InitializeComponent() this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.panel1.Controls.Add(this.radioButton3); - this.panel1.Controls.Add(this.radioButton2); - this.panel1.Controls.Add(this.radioButton1); + this.panel1.Controls.Add(this.ortographicCameraRadioButton); + this.panel1.Controls.Add(this.lensCameraRadioButton); + this.panel1.Controls.Add(this.perspectiveCameraRadioButton); this.panel1.Location = new System.Drawing.Point(3, 3); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(141, 85); + this.panel1.Size = new System.Drawing.Size(138, 74); this.panel1.TabIndex = 2; // - // radioButton1 - // - this.radioButton1.AutoSize = true; - this.radioButton1.Checked = true; - this.radioButton1.Location = new System.Drawing.Point(0, 4); - this.radioButton1.Name = "radioButton1"; - this.radioButton1.Size = new System.Drawing.Size(85, 19); - this.radioButton1.TabIndex = 0; - this.radioButton1.TabStop = true; - this.radioButton1.Text = "Perspective"; - this.radioButton1.UseVisualStyleBackColor = true; - // - // radioButton2 - // - this.radioButton2.AutoSize = true; - this.radioButton2.Location = new System.Drawing.Point(0, 29); - this.radioButton2.Name = "radioButton2"; - this.radioButton2.Size = new System.Drawing.Size(49, 19); - this.radioButton2.TabIndex = 1; - this.radioButton2.Text = "Lens"; - this.radioButton2.UseVisualStyleBackColor = true; - // - // radioButton3 - // - this.radioButton3.AutoSize = true; - this.radioButton3.Location = new System.Drawing.Point(0, 54); - this.radioButton3.Name = "radioButton3"; - this.radioButton3.Size = new System.Drawing.Size(89, 19); - this.radioButton3.TabIndex = 2; - this.radioButton3.Text = "Ortographic"; - this.radioButton3.UseVisualStyleBackColor = true; - // - // numericUpDown1 - // - this.numericUpDown1.Anchor = System.Windows.Forms.AnchorStyles.None; - this.numericUpDown1.Location = new System.Drawing.Point(391, 134); - this.numericUpDown1.Maximum = new decimal(new int[] { - 170, + // ortographicCameraRadioButton + // + this.ortographicCameraRadioButton.AutoSize = true; + this.ortographicCameraRadioButton.Location = new System.Drawing.Point(0, 54); + this.ortographicCameraRadioButton.Name = "ortographicCameraRadioButton"; + this.ortographicCameraRadioButton.Size = new System.Drawing.Size(89, 19); + this.ortographicCameraRadioButton.TabIndex = 2; + this.ortographicCameraRadioButton.Text = "Ortographic"; + this.ortographicCameraRadioButton.UseVisualStyleBackColor = true; + this.ortographicCameraRadioButton.CheckedChanged += new System.EventHandler(this.ortographicCameraRadioButton_CheckedChanged); + // + // lensCameraRadioButton + // + this.lensCameraRadioButton.AutoSize = true; + this.lensCameraRadioButton.Location = new System.Drawing.Point(0, 29); + this.lensCameraRadioButton.Name = "lensCameraRadioButton"; + this.lensCameraRadioButton.Size = new System.Drawing.Size(49, 19); + this.lensCameraRadioButton.TabIndex = 1; + this.lensCameraRadioButton.Text = "Lens"; + this.lensCameraRadioButton.UseVisualStyleBackColor = true; + this.lensCameraRadioButton.CheckedChanged += new System.EventHandler(this.lensCameraRadioButton_CheckedChanged); + // + // perspectiveCameraRadioButton + // + this.perspectiveCameraRadioButton.AutoSize = true; + this.perspectiveCameraRadioButton.Location = new System.Drawing.Point(0, 4); + this.perspectiveCameraRadioButton.Name = "perspectiveCameraRadioButton"; + this.perspectiveCameraRadioButton.Size = new System.Drawing.Size(85, 19); + this.perspectiveCameraRadioButton.TabIndex = 0; + this.perspectiveCameraRadioButton.Text = "Perspective"; + this.perspectiveCameraRadioButton.UseVisualStyleBackColor = true; + this.perspectiveCameraRadioButton.CheckedChanged += new System.EventHandler(this.perspectiveCameraRadioButton_CheckedChanged); + // + // lensCameraLayoutPanel + // + this.lensCameraLayoutPanel.ColumnCount = 2; + this.lensCameraLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.lensCameraLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.lensCameraLayoutPanel.Controls.Add(this.label15, 0, 1); + this.lensCameraLayoutPanel.Controls.Add(this.lensRadiusUpDown, 1, 0); + this.lensCameraLayoutPanel.Controls.Add(this.focusDistanceUpDown, 1, 1); + this.lensCameraLayoutPanel.Controls.Add(this.label14, 0, 0); + this.lensCameraLayoutPanel.Location = new System.Drawing.Point(147, 3); + this.lensCameraLayoutPanel.Name = "lensCameraLayoutPanel"; + this.lensCameraLayoutPanel.RowCount = 2; + this.lensCameraLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.lensCameraLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.lensCameraLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.lensCameraLayoutPanel.Size = new System.Drawing.Size(139, 74); + this.lensCameraLayoutPanel.TabIndex = 3; + // + // label15 + // + this.label15.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label15.AutoSize = true; + this.label15.Location = new System.Drawing.Point(9, 40); + this.label15.Name = "label15"; + this.label15.Size = new System.Drawing.Size(51, 30); + this.label15.TabIndex = 8; + this.label15.Text = "Focus distance"; + this.label15.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // lensRadiusUpDown + // + this.lensRadiusUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; + this.lensRadiusUpDown.DecimalPlaces = 2; + this.lensRadiusUpDown.Increment = new decimal(new int[] { + 1, 0, 0, - 0}); - this.numericUpDown1.Minimum = new decimal(new int[] { + 65536}); + this.lensRadiusUpDown.Location = new System.Drawing.Point(72, 7); + this.lensRadiusUpDown.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 131072}); + this.lensRadiusUpDown.Name = "lensRadiusUpDown"; + this.lensRadiusUpDown.Size = new System.Drawing.Size(64, 23); + this.lensRadiusUpDown.TabIndex = 5; + this.lensRadiusUpDown.Value = new decimal(new int[] { 30, 0, 0, 0}); - this.numericUpDown1.Name = "numericUpDown1"; - this.numericUpDown1.Size = new System.Drawing.Size(120, 23); - this.numericUpDown1.TabIndex = 4; - this.numericUpDown1.Value = new decimal(new int[] { + this.lensRadiusUpDown.ValueChanged += new System.EventHandler(this.lensRadiusUpDown_ValueChanged); + // + // focusDistanceUpDown + // + this.focusDistanceUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; + this.focusDistanceUpDown.DecimalPlaces = 2; + this.focusDistanceUpDown.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + this.focusDistanceUpDown.Location = new System.Drawing.Point(72, 44); + this.focusDistanceUpDown.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 131072}); + this.focusDistanceUpDown.Name = "focusDistanceUpDown"; + this.focusDistanceUpDown.Size = new System.Drawing.Size(64, 23); + this.focusDistanceUpDown.TabIndex = 6; + this.focusDistanceUpDown.Value = new decimal(new int[] { 30, 0, 0, 0}); + this.focusDistanceUpDown.ValueChanged += new System.EventHandler(this.focusDistanceUpDown_ValueChanged); // - // panel2 + // label14 // - this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.panel2.Controls.Add(this.radioButton4); - this.panel2.Controls.Add(this.radioButton5); - this.panel2.Controls.Add(this.radioButton6); - this.panel2.Location = new System.Drawing.Point(304, 197); - this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(295, 93); - this.panel2.TabIndex = 5; + this.label14.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label14.AutoSize = true; + this.label14.Location = new System.Drawing.Point(13, 11); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(42, 15); + this.label14.TabIndex = 7; + this.label14.Text = "Radius"; + this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // radioButton4 + // fovUpDown // - this.radioButton4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.radioButton4.AutoSize = true; - this.radioButton4.Location = new System.Drawing.Point(0, 54); - this.radioButton4.Name = "radioButton4"; - this.radioButton4.Size = new System.Drawing.Size(70, 19); - this.radioButton4.TabIndex = 2; - this.radioButton4.Text = "Random"; - this.radioButton4.UseVisualStyleBackColor = true; + this.fovUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; + this.fovUpDown.Location = new System.Drawing.Point(382, 117); + this.fovUpDown.Maximum = new decimal(new int[] { + 170, + 0, + 0, + 0}); + this.fovUpDown.Minimum = new decimal(new int[] { + 30, + 0, + 0, + 0}); + this.fovUpDown.Name = "fovUpDown"; + this.fovUpDown.Size = new System.Drawing.Size(120, 23); + this.fovUpDown.TabIndex = 4; + this.fovUpDown.Value = new decimal(new int[] { + 30, + 0, + 0, + 0}); + this.fovUpDown.ValueChanged += new System.EventHandler(this.fovUpDown_ValueChanged); // - // radioButton5 + // label1 // - this.radioButton5.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.radioButton5.AutoSize = true; - this.radioButton5.Location = new System.Drawing.Point(0, 29); - this.radioButton5.Name = "radioButton5"; - this.radioButton5.Size = new System.Drawing.Size(60, 19); - this.radioButton5.TabIndex = 1; - this.radioButton5.Text = "Center"; - this.radioButton5.UseVisualStyleBackColor = true; + this.label1.Location = new System.Drawing.Point(0, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(100, 23); + this.label1.TabIndex = 0; + this.label1.Text = "label1"; // - // radioButton6 + // label2 // - this.radioButton6.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.radioButton6.AutoSize = true; - this.radioButton6.Checked = true; - this.radioButton6.Location = new System.Drawing.Point(0, 4); - this.radioButton6.Name = "radioButton6"; - this.radioButton6.Size = new System.Drawing.Size(63, 19); - this.radioButton6.TabIndex = 0; - this.radioButton6.TabStop = true; - this.radioButton6.Text = "Jittered"; - this.radioButton6.UseVisualStyleBackColor = true; + this.label2.Location = new System.Drawing.Point(0, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(100, 23); + this.label2.TabIndex = 0; + this.label2.Text = "label2"; // - // tableLayoutPanel4 + // label3 // - this.tableLayoutPanel4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.tableLayoutPanel4.ColumnCount = 2; - this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel4.Controls.Add(this.label13, 0, 4); - this.tableLayoutPanel4.Controls.Add(this.label9, 0, 0); - this.tableLayoutPanel4.Controls.Add(this.label10, 0, 1); - this.tableLayoutPanel4.Controls.Add(this.label11, 0, 2); - this.tableLayoutPanel4.Controls.Add(this.label12, 0, 3); - this.tableLayoutPanel4.Location = new System.Drawing.Point(6, 22); - this.tableLayoutPanel4.Name = "tableLayoutPanel4"; - this.tableLayoutPanel4.RowCount = 5; - this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); - this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); - this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); - this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); - this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); - this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); - this.tableLayoutPanel4.Size = new System.Drawing.Size(599, 290); - this.tableLayoutPanel4.TabIndex = 0; + this.label3.Location = new System.Drawing.Point(0, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(100, 23); + this.label3.TabIndex = 0; + this.label3.Text = "label3"; // - // label9 + // label4 // - this.label9.Anchor = System.Windows.Forms.AnchorStyles.None; - this.label9.AutoSize = true; - this.label9.Location = new System.Drawing.Point(124, 21); - this.label9.Name = "label9"; - this.label9.Size = new System.Drawing.Size(51, 15); - this.label9.TabIndex = 1; - this.label9.Text = "Samples"; - this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label4.Location = new System.Drawing.Point(0, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(100, 23); + this.label4.TabIndex = 0; + this.label4.Text = "label4"; // - // label10 + // label5 // - this.label10.Anchor = System.Windows.Forms.AnchorStyles.None; - this.label10.AutoSize = true; - this.label10.Location = new System.Drawing.Point(99, 79); - this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(101, 15); - this.label10.TabIndex = 2; - this.label10.Text = "Update frequency"; - this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label5.Location = new System.Drawing.Point(0, 0); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(100, 23); + this.label5.TabIndex = 0; + this.label5.Text = "label5"; // - // label11 + // linkLabel1 // - this.label11.Anchor = System.Windows.Forms.AnchorStyles.None; - this.label11.AutoSize = true; - this.label11.Location = new System.Drawing.Point(96, 137); - this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(106, 15); - this.label11.TabIndex = 3; - this.label11.Text = "Gamma correction"; - this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.linkLabel1.Location = new System.Drawing.Point(0, 0); + this.linkLabel1.Name = "linkLabel1"; + this.linkLabel1.Size = new System.Drawing.Size(100, 23); + this.linkLabel1.TabIndex = 0; + this.linkLabel1.TabStop = true; + this.linkLabel1.Text = "linkLabel1"; // - // label12 + // label16 // - this.label12.Anchor = System.Windows.Forms.AnchorStyles.None; - this.label12.AutoSize = true; - this.label12.Location = new System.Drawing.Point(128, 195); - this.label12.Name = "label12"; - this.label12.Size = new System.Drawing.Size(42, 15); - this.label12.TabIndex = 4; - this.label12.Text = "Bloom"; - this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label16.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label16.AutoSize = true; + this.label16.Location = new System.Drawing.Point(102, 225); + this.label16.Name = "label16"; + this.label16.Size = new System.Drawing.Size(88, 15); + this.label16.TabIndex = 13; + this.label16.Text = "Recursion leves"; + this.label16.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // label13 + // recLevelUpDown // - this.label13.Anchor = System.Windows.Forms.AnchorStyles.None; - this.label13.AutoSize = true; - this.label13.Location = new System.Drawing.Point(33, 253); - this.label13.Name = "label13"; - this.label13.Size = new System.Drawing.Size(232, 15); - this.label13.TabIndex = 5; - this.label13.Text = "Ray tracing by recursion levels (unoptimal)"; - this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.recLevelUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; + this.recLevelUpDown.Location = new System.Drawing.Point(380, 221); + this.recLevelUpDown.Maximum = new decimal(new int[] { + 20, + 0, + 0, + 0}); + this.recLevelUpDown.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.recLevelUpDown.Name = "recLevelUpDown"; + this.recLevelUpDown.Size = new System.Drawing.Size(120, 23); + this.recLevelUpDown.TabIndex = 14; + this.recLevelUpDown.Value = new decimal(new int[] { + 8, + 0, + 0, + 0}); + this.recLevelUpDown.ValueChanged += new System.EventHandler(this.recLevelUpDown_ValueChanged); // // SettingsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(623, 654); + this.ClientSize = new System.Drawing.Size(611, 586); this.Controls.Add(this.tableLayoutPanel1); this.Name = "SettingsForm"; this.Text = "Settings"; this.tableLayoutPanel1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); + this.tableLayoutPanel4.ResumeLayout(false); + this.tableLayoutPanel4.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.samplesUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.updateUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.bloomUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.gammaUpDown)).EndInit(); + this.groupBox1.ResumeLayout(false); this.tableLayoutPanel2.ResumeLayout(false); this.tableLayoutPanel2.PerformLayout(); - this.groupBox1.ResumeLayout(false); + this.panel2.ResumeLayout(false); + this.panel2.PerformLayout(); this.tableLayoutPanel3.ResumeLayout(false); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); - this.panel2.ResumeLayout(false); - this.panel2.PerformLayout(); - this.tableLayoutPanel4.ResumeLayout(false); - this.tableLayoutPanel4.PerformLayout(); + this.lensCameraLayoutPanel.ResumeLayout(false); + this.lensCameraLayoutPanel.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.lensRadiusUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.focusDistanceUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.fovUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.recLevelUpDown)).EndInit(); this.ResumeLayout(false); } @@ -478,13 +734,26 @@ private void InitializeComponent() private System.Windows.Forms.Label label11; private System.Windows.Forms.Label label12; private System.Windows.Forms.Panel panel2; - private System.Windows.Forms.RadioButton radioButton4; - private System.Windows.Forms.RadioButton radioButton5; - private System.Windows.Forms.RadioButton radioButton6; + private System.Windows.Forms.RadioButton randomRadioButton; + private System.Windows.Forms.RadioButton centerRadioButton; + private System.Windows.Forms.RadioButton jitteredRadioButton; private System.Windows.Forms.Panel panel1; - private System.Windows.Forms.RadioButton radioButton3; - private System.Windows.Forms.RadioButton radioButton2; - private System.Windows.Forms.RadioButton radioButton1; - private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.RadioButton ortographicCameraRadioButton; + private System.Windows.Forms.RadioButton lensCameraRadioButton; + private System.Windows.Forms.RadioButton perspectiveCameraRadioButton; + private System.Windows.Forms.NumericUpDown fovUpDown; + private System.Windows.Forms.NumericUpDown samplesUpDown; + private System.Windows.Forms.NumericUpDown updateUpDown; + private System.Windows.Forms.CheckBox recursionCheckbox; + private System.Windows.Forms.NumericUpDown bloomUpDown; + private System.Windows.Forms.NumericUpDown gammaUpDown; + private System.Windows.Forms.TableLayoutPanel lensCameraLayoutPanel; + private System.Windows.Forms.Label label15; + private System.Windows.Forms.NumericUpDown lensRadiusUpDown; + private System.Windows.Forms.NumericUpDown focusDistanceUpDown; + private System.Windows.Forms.Label label14; + private System.Windows.Forms.Label label16; + private System.Windows.Forms.NumericUpDown recLevelUpDown; + private System.Windows.Forms.NumericUpDown recursionLevelUpDown; } } \ No newline at end of file diff --git a/RayTracerApp/Forms/SettingsForm.cs b/RayTracerApp/Forms/SettingsForm.cs index fdb153d..57e3c9a 100644 --- a/RayTracerApp/Forms/SettingsForm.cs +++ b/RayTracerApp/Forms/SettingsForm.cs @@ -1,4 +1,8 @@ -using System; +using RayTracerApp.SceneController; +using RayTracing; +using RayTracing.Cameras; +using RayTracing.Sampling; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -10,9 +14,177 @@ namespace RayTracerApp.Forms { public partial class SettingsForm : Form { - public SettingsForm() + private SettingsController _controller; + public SettingsForm(SettingsController controller) { + _controller = controller; InitializeComponent(); + LoadFromController(); + } + + private void LoadFromController() + { + var camera = _controller.Camera; + var rayTracer = _controller.RayTracer; + + perspectiveCameraRadioButton.Checked = camera is PerspectiveCamera; + lensCameraRadioButton.Checked = camera is LensCamera; + ortographicCameraRadioButton.Checked = camera is OrthographicCamera; + + fovUpDown.Value = (decimal)camera.Fov; + + jitteredRadioButton.Checked = rayTracer.Sampling == Vec2Sampling.Jittered; + centerRadioButton.Checked = rayTracer.Sampling == Vec2Sampling.Dummy; + randomRadioButton.Checked = rayTracer.Sampling == Vec2Sampling.Random; + + samplesUpDown.Value = rayTracer.Samples; + + updateUpDown.Value = rayTracer.SamplesRenderStep; + + gammaUpDown.Value = rayTracer.GammaCorrection; + + bloomUpDown.Value = rayTracer.Bloom; + + recLevelUpDown.Value = rayTracer.MaxDepth; + + recursionCheckbox.Checked = rayTracer is RecursionRayTracer; + + if(camera is LensCamera lc) + { + lensRadiusUpDown.Value = (decimal)lc.LensRadius; + focusDistanceUpDown.Value = (decimal)lc.FocusDistance; + lensCameraLayoutPanel.Visible = true; + } + else + { + lensCameraLayoutPanel.Visible = false; + } + } + + private void tableLayoutPanel_CellPaint(object sender, TableLayoutCellPaintEventArgs e) + { + var rectangle = e.CellBounds; + rectangle.Inflate(-1, -1); + + ControlPaint.DrawBorder3D(e.Graphics, rectangle, Border3DStyle.Raised, Border3DSide.Bottom); + } + + private void recursionCheckbox_CheckedChanged(object sender, EventArgs e) + { + var previous = _controller.RayTracer; + IncrementalRayTracer newRayTracer; + if (recursionCheckbox.Checked) + newRayTracer = new RecursionRayTracer(previous.MaxDepth, previous.Samples, previous.Sampling, previous.Resolution, previous.SamplesRenderStep); + else + newRayTracer = new SamplesRayTracer(previous.MaxDepth, previous.Samples, previous.Sampling, previous.Resolution, previous.SamplesRenderStep); + + newRayTracer.Bloom = previous.Bloom; + newRayTracer.GammaCorrection = previous.GammaCorrection; + _controller.RayTracer = newRayTracer; + } + + private void bloomUpDown_ValueChanged(object sender, EventArgs e) + { + _controller.RayTracer.Bloom = (int)bloomUpDown.Value; + } + + private void gammaUpDown_ValueChanged(object sender, EventArgs e) + { + _controller.RayTracer.GammaCorrection = (int)gammaUpDown.Value; + } + + private void updateUpDown_ValueChanged(object sender, EventArgs e) + { + _controller.RayTracer.SamplesRenderStep = (int)updateUpDown.Value; + } + + private void samplesUpDown_ValueChanged(object sender, EventArgs e) + { + _controller.RayTracer.Samples = (int)samplesUpDown.Value; + } + + private void jitteredRadioButton_CheckedChanged(object sender, EventArgs e) + { + if(jitteredRadioButton.Checked) + _controller.RayTracer.Sampling = Vec2Sampling.Jittered; + } + + private void centerRadioButton_CheckedChanged(object sender, EventArgs e) + { + if (centerRadioButton.Checked) + _controller.RayTracer.Sampling = Vec2Sampling.Dummy; + } + + private void randomRadioButton_CheckedChanged(object sender, EventArgs e) + { + if (randomRadioButton.Checked) + _controller.RayTracer.Sampling = Vec2Sampling.Random; + } + + private void fovUpDown_ValueChanged(object sender, EventArgs e) + { + _controller.Camera.Fov = (float)fovUpDown.Value; + } + + private void UpdateCamera(Camera old, Camera newCamera) + { + newCamera.AspectRatio = old.AspectRatio; + newCamera.Fov = old.Fov; + newCamera.Pitch = old.Pitch; + newCamera.Yaw = old.Yaw; + } + + private void perspectiveCameraRadioButton_CheckedChanged(object sender, EventArgs e) + { + if(perspectiveCameraRadioButton.Checked) + { + lensCameraLayoutPanel.Visible = false; + var previous = _controller.Camera; + var newCamera = new PerspectiveCamera(previous.Position); + _controller.Camera = newCamera; + UpdateCamera(previous, newCamera); + } + } + + private void lensCameraRadioButton_CheckedChanged(object sender, EventArgs e) + { + if (lensCameraRadioButton.Checked) + { + lensCameraLayoutPanel.Visible = true; + var previous = _controller.Camera; + var newCamera = new LensCamera(previous.Position); + _controller.Camera = newCamera; + lensRadiusUpDown.Value = (decimal)newCamera.LensRadius; + focusDistanceUpDown.Value = (decimal)newCamera.FocusDistance; + UpdateCamera(previous, newCamera); + } + } + + private void ortographicCameraRadioButton_CheckedChanged(object sender, EventArgs e) + { + if (ortographicCameraRadioButton.Checked) + { + lensCameraLayoutPanel.Visible = false; + var previous = _controller.Camera; + var newCamera = new OrthographicCamera(previous.Position); + _controller.Camera = newCamera; + UpdateCamera(previous, newCamera); + } + } + + private void focusDistanceUpDown_ValueChanged(object sender, EventArgs e) + { + (_controller.Camera as LensCamera).FocusDistance = (float)focusDistanceUpDown.Value; + } + + private void lensRadiusUpDown_ValueChanged(object sender, EventArgs e) + { + (_controller.Camera as LensCamera).LensRadius = (float)lensRadiusUpDown.Value; + } + + private void recLevelUpDown_ValueChanged(object sender, EventArgs e) + { + _controller.RayTracer.MaxDepth = (int)recLevelUpDown.Value; } } } diff --git a/RayTracerApp/Forms/TestForm.Designer.cs b/RayTracerApp/Forms/TestForm.Designer.cs index a34fe96..afe2ce2 100644 --- a/RayTracerApp/Forms/TestForm.Designer.cs +++ b/RayTracerApp/Forms/TestForm.Designer.cs @@ -34,6 +34,7 @@ private void InitializeComponent() this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.contextMenuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -64,16 +65,26 @@ private void InitializeComponent() this.toolStripMenuItem3.Size = new System.Drawing.Size(180, 22); this.toolStripMenuItem3.Text = "toolStripMenuItem3"; // + // toolStrip1 + // + this.toolStrip1.Location = new System.Drawing.Point(0, 0); + this.toolStrip1.Name = "toolStrip1"; + this.toolStrip1.Size = new System.Drawing.Size(800, 25); + this.toolStrip1.TabIndex = 1; + this.toolStrip1.Text = "toolStrip1"; + // // TestForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); this.ContextMenuStrip = this.contextMenuStrip1; + this.Controls.Add(this.toolStrip1); this.Name = "TestForm"; this.Text = "TestForm"; this.contextMenuStrip1.ResumeLayout(false); this.ResumeLayout(false); + this.PerformLayout(); } @@ -83,5 +94,6 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem3; + private System.Windows.Forms.ToolStrip toolStrip1; } } \ No newline at end of file diff --git a/RayTracerApp/Panels/MaterialPanel.Designer.cs b/RayTracerApp/Panels/MaterialPanel.Designer.cs index 74fe24e..5bb9aab 100644 --- a/RayTracerApp/Panels/MaterialPanel.Designer.cs +++ b/RayTracerApp/Panels/MaterialPanel.Designer.cs @@ -126,7 +126,7 @@ private void InitializeComponent() this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 30F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(490, 549); this.tableLayoutPanel1.TabIndex = 0; - this.tableLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.tableLayoutPanel1_Paint); + this.tableLayoutPanel1.CellPaint += new System.Windows.Forms.TableLayoutCellPaintEventHandler(this.tableLayoutPanel1_CellPaint); // // tableLayoutPanel12 // diff --git a/RayTracerApp/Panels/MaterialPanel.cs b/RayTracerApp/Panels/MaterialPanel.cs index dc8f8c1..afbc1fd 100644 --- a/RayTracerApp/Panels/MaterialPanel.cs +++ b/RayTracerApp/Panels/MaterialPanel.cs @@ -223,12 +223,12 @@ private void refractiveColor_Click(object sender, EventArgs e) } } - private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e) + private void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e) { - var rectangle = e.ClipRectangle; + var rectangle = e.CellBounds; rectangle.Inflate(-1, -1); - ControlPaint.DrawBorder3D(e.Graphics, rectangle, Border3DStyle.Raised, Border3DSide.All); + ControlPaint.DrawBorder3D(e.Graphics, rectangle, Border3DStyle.Raised, Border3DSide.Bottom); } } } diff --git a/RayTracerApp/Panels/PositionPanel.Designer.cs b/RayTracerApp/Panels/PositionPanel.Designer.cs index dfd56c0..948e64e 100644 --- a/RayTracerApp/Panels/PositionPanel.Designer.cs +++ b/RayTracerApp/Panels/PositionPanel.Designer.cs @@ -82,42 +82,37 @@ private void InitializeComponent() this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(402, 490); this.tableLayoutPanel1.TabIndex = 0; + this.tableLayoutPanel1.CellPaint += new System.Windows.Forms.TableLayoutCellPaintEventHandler(this.tableLayoutPanel1_CellPaint); // // label1 // - this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + this.label1.Anchor = System.Windows.Forms.AnchorStyles.None; this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(3, 0); + this.label1.Location = new System.Drawing.Point(68, 74); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(195, 163); + this.label1.Size = new System.Drawing.Size(64, 15); this.label1.TabIndex = 0; this.label1.Text = "Translation"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // label2 // - this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + this.label2.Anchor = System.Windows.Forms.AnchorStyles.None; this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(3, 163); + this.label2.Location = new System.Drawing.Point(74, 237); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(195, 163); + this.label2.Size = new System.Drawing.Size(52, 15); this.label2.TabIndex = 1; this.label2.Text = "Rotation"; this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // label3 // - this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + this.label3.Anchor = System.Windows.Forms.AnchorStyles.None; this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(3, 326); + this.label3.Location = new System.Drawing.Point(83, 400); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(195, 164); + this.label3.Size = new System.Drawing.Size(34, 15); this.label3.TabIndex = 2; this.label3.Text = "Scale"; this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; diff --git a/RayTracerApp/Panels/PositionPanel.cs b/RayTracerApp/Panels/PositionPanel.cs index 0cde35c..1256b36 100644 --- a/RayTracerApp/Panels/PositionPanel.cs +++ b/RayTracerApp/Panels/PositionPanel.cs @@ -107,5 +107,12 @@ private void scaleUpDown_ValueChanged(object sender, EventArgs e) var nud = sender as NumericUpDown; Controller.GetModel().Scale = (float)nud.Value; } + + private void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e) + { + var rectangle = e.CellBounds; + + ControlPaint.DrawBorder3D(e.Graphics, rectangle, Border3DStyle.Raised, Border3DSide.Bottom); + } } } diff --git a/RayTracerApp/SceneController/SettingsController.cs b/RayTracerApp/SceneController/SettingsController.cs new file mode 100644 index 0000000..c9daac3 --- /dev/null +++ b/RayTracerApp/SceneController/SettingsController.cs @@ -0,0 +1,20 @@ +using RayTracing; +using RayTracing.Cameras; +using System; +using System.Collections.Generic; +using System.Text; + +namespace RayTracerApp.SceneController +{ + public class SettingsController + { + public Camera Camera { get; set; } + public IncrementalRayTracer RayTracer { get; set; } + + public SettingsController(Camera camera, IncrementalRayTracer rayTracer) + { + Camera = camera; + RayTracer = rayTracer; + } + } +} From 58717dd1a264c88a575d1f6b14c144b2cee761a6 Mon Sep 17 00:00:00 2001 From: p-flis Date: Thu, 7 Jan 2021 01:35:03 +0100 Subject: [PATCH 15/31] lens camera autofocus --- RayTracer/Source/Cameras/LensCamera.cs | 5 +- RayTracer/Source/Renderer/SamplesRayTracer.cs | 16 + RayTracerApp/Forms/MainForm.cs | 2 +- RayTracerApp/Forms/SettingsForm.Designer.cs | 300 +++++++++++------- RayTracerApp/Forms/SettingsForm.cs | 15 + 5 files changed, 212 insertions(+), 126 deletions(-) diff --git a/RayTracer/Source/Cameras/LensCamera.cs b/RayTracer/Source/Cameras/LensCamera.cs index 023f30e..cf6a18d 100644 --- a/RayTracer/Source/Cameras/LensCamera.cs +++ b/RayTracer/Source/Cameras/LensCamera.cs @@ -9,13 +9,14 @@ namespace RayTracing.Cameras public class LensCamera : Camera { private const int SAMPLE_SETS = 8; - + private float _lensRadius; private float _focusDistance; private AbstractSampler _lensSampler; private Func> _sampling; private int _samplesCount; + public bool AutoFocus { get; set; } public float LensRadius { @@ -57,7 +58,7 @@ public int SamplesCount } } - public LensCamera(Vector3 position, float lensRadius = 10, float focusDistance = 5, int samplesCount = 64, Func> sampling = null) + public LensCamera(Vector3 position, float lensRadius = 0.25f, float focusDistance = 5, int samplesCount = 10000, Func> sampling = null) { Position = position; _lensRadius = lensRadius; diff --git a/RayTracer/Source/Renderer/SamplesRayTracer.cs b/RayTracer/Source/Renderer/SamplesRayTracer.cs index d11a45f..a72d1ec 100644 --- a/RayTracer/Source/Renderer/SamplesRayTracer.cs +++ b/RayTracer/Source/Renderer/SamplesRayTracer.cs @@ -20,6 +20,22 @@ public SamplesRayTracer(int maxDepth, int samples, Func> samp public override void Render(Scene scene, Camera camera) { scene.Preprocess(); + + if (camera is LensCamera lensCamera && lensCamera.AutoFocus) + { + var ray = lensCamera.GetRay(0.5f, 0.5f); + var hitInfo = new HitInfo(); + var hit = scene.HitTest(ray, ref hitInfo, 0.001f, float.PositiveInfinity); + if(hit) + { + lensCamera.FocusDistance = hitInfo.Distance; + } + else + { + lensCamera.FocusDistance = 999999f; + } + } + int width = Resolution; int height = (int) (width / camera.AspectRatio); var image = new Texture(width, height); diff --git a/RayTracerApp/Forms/MainForm.cs b/RayTracerApp/Forms/MainForm.cs index ec1ecd9..ccffda8 100644 --- a/RayTracerApp/Forms/MainForm.cs +++ b/RayTracerApp/Forms/MainForm.cs @@ -25,7 +25,7 @@ public partial class MainForm : Form private const int SWAP_TIME = 2; private Scene _scene = new Scene(); private IRenderer _renderer; - private Camera _camera = new PerspectiveCamera(new Vector3(0, 0, 20)) {AspectRatio = 1}; + private Camera _camera = new LensCamera(new Vector3(0, 0, 20)) {AspectRatio = 1, AutoFocus = true}; private CameraController _cameraController; private IncrementalRayTracer _rayTracer; private BackgroundWorker _backgroundWorker; diff --git a/RayTracerApp/Forms/SettingsForm.Designer.cs b/RayTracerApp/Forms/SettingsForm.Designer.cs index 341a770..257f30f 100644 --- a/RayTracerApp/Forms/SettingsForm.Designer.cs +++ b/RayTracerApp/Forms/SettingsForm.Designer.cs @@ -32,7 +32,7 @@ private void InitializeComponent() this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel(); - this.label13 = new System.Windows.Forms.Label(); + this.label16 = new System.Windows.Forms.Label(); this.label9 = new System.Windows.Forms.Label(); this.label10 = new System.Windows.Forms.Label(); this.label11 = new System.Windows.Forms.Label(); @@ -40,8 +40,10 @@ private void InitializeComponent() this.samplesUpDown = new System.Windows.Forms.NumericUpDown(); this.updateUpDown = new System.Windows.Forms.NumericUpDown(); this.bloomUpDown = new System.Windows.Forms.NumericUpDown(); - this.recursionCheckbox = new System.Windows.Forms.CheckBox(); this.gammaUpDown = new System.Windows.Forms.NumericUpDown(); + this.recursionCheckbox = new System.Windows.Forms.CheckBox(); + this.label13 = new System.Windows.Forms.Label(); + this.recLevelUpDown = new System.Windows.Forms.NumericUpDown(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.panel2 = new System.Windows.Forms.Panel(); @@ -57,10 +59,10 @@ private void InitializeComponent() this.lensCameraRadioButton = new System.Windows.Forms.RadioButton(); this.perspectiveCameraRadioButton = new System.Windows.Forms.RadioButton(); this.lensCameraLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); - this.label15 = new System.Windows.Forms.Label(); this.lensRadiusUpDown = new System.Windows.Forms.NumericUpDown(); this.focusDistanceUpDown = new System.Windows.Forms.NumericUpDown(); this.label14 = new System.Windows.Forms.Label(); + this.label15 = new System.Windows.Forms.Label(); this.fovUpDown = new System.Windows.Forms.NumericUpDown(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); @@ -68,8 +70,9 @@ private void InitializeComponent() this.label4 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.linkLabel1 = new System.Windows.Forms.LinkLabel(); - this.label16 = new System.Windows.Forms.Label(); - this.recLevelUpDown = new System.Windows.Forms.NumericUpDown(); + this.finishButton = new System.Windows.Forms.Button(); + this.label17 = new System.Windows.Forms.Label(); + this.autoFocusCheckBox = new System.Windows.Forms.CheckBox(); this.tableLayoutPanel1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.tableLayoutPanel4.SuspendLayout(); @@ -77,6 +80,7 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.updateUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bloomUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.gammaUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.recLevelUpDown)).BeginInit(); this.groupBox1.SuspendLayout(); this.tableLayoutPanel2.SuspendLayout(); this.panel2.SuspendLayout(); @@ -86,31 +90,34 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.lensRadiusUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.focusDistanceUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.fovUpDown)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.recLevelUpDown)).BeginInit(); this.SuspendLayout(); // // tableLayoutPanel1 // + this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.tableLayoutPanel1.ColumnCount = 1; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.Controls.Add(this.groupBox2, 0, 1); this.tableLayoutPanel1.Controls.Add(this.groupBox1, 0, 0); - this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; - this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 2); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 2; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel1.Size = new System.Drawing.Size(611, 586); + this.tableLayoutPanel1.Size = new System.Drawing.Size(664, 673); this.tableLayoutPanel1.TabIndex = 0; // // groupBox2 // + this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.groupBox2.Controls.Add(this.tableLayoutPanel4); - this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill; - this.groupBox2.Location = new System.Drawing.Point(3, 296); + this.groupBox2.Location = new System.Drawing.Point(3, 339); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(605, 287); + this.groupBox2.Size = new System.Drawing.Size(658, 331); this.groupBox2.TabIndex = 1; this.groupBox2.TabStop = false; this.groupBox2.Text = "Ray Tracer"; @@ -135,7 +142,7 @@ private void InitializeComponent() this.tableLayoutPanel4.Controls.Add(this.recursionCheckbox, 1, 4); this.tableLayoutPanel4.Controls.Add(this.label13, 0, 4); this.tableLayoutPanel4.Controls.Add(this.recLevelUpDown, 1, 5); - this.tableLayoutPanel4.Location = new System.Drawing.Point(6, 22); + this.tableLayoutPanel4.Location = new System.Drawing.Point(9, 22); this.tableLayoutPanel4.Name = "tableLayoutPanel4"; this.tableLayoutPanel4.RowCount = 6; this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); @@ -144,26 +151,26 @@ private void InitializeComponent() this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); - this.tableLayoutPanel4.Size = new System.Drawing.Size(587, 256); + this.tableLayoutPanel4.Size = new System.Drawing.Size(643, 303); this.tableLayoutPanel4.TabIndex = 0; this.tableLayoutPanel4.CellPaint += new System.Windows.Forms.TableLayoutCellPaintEventHandler(this.tableLayoutPanel_CellPaint); // - // label13 + // label16 // - this.label13.Anchor = System.Windows.Forms.AnchorStyles.None; - this.label13.AutoSize = true; - this.label13.Location = new System.Drawing.Point(30, 181); - this.label13.Name = "label13"; - this.label13.Size = new System.Drawing.Size(232, 15); - this.label13.TabIndex = 5; - this.label13.Text = "Ray tracing by recursion levels (unoptimal)"; - this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label16.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label16.AutoSize = true; + this.label16.Location = new System.Drawing.Point(116, 269); + this.label16.Name = "label16"; + this.label16.Size = new System.Drawing.Size(88, 15); + this.label16.TabIndex = 13; + this.label16.Text = "Recursion leves"; + this.label16.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // label9 // this.label9.Anchor = System.Windows.Forms.AnchorStyles.None; this.label9.AutoSize = true; - this.label9.Location = new System.Drawing.Point(121, 13); + this.label9.Location = new System.Drawing.Point(135, 17); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(51, 15); this.label9.TabIndex = 1; @@ -174,7 +181,7 @@ private void InitializeComponent() // this.label10.Anchor = System.Windows.Forms.AnchorStyles.None; this.label10.AutoSize = true; - this.label10.Location = new System.Drawing.Point(96, 55); + this.label10.Location = new System.Drawing.Point(110, 67); this.label10.Name = "label10"; this.label10.Size = new System.Drawing.Size(101, 15); this.label10.TabIndex = 2; @@ -185,7 +192,7 @@ private void InitializeComponent() // this.label11.Anchor = System.Windows.Forms.AnchorStyles.None; this.label11.AutoSize = true; - this.label11.Location = new System.Drawing.Point(93, 97); + this.label11.Location = new System.Drawing.Point(107, 117); this.label11.Name = "label11"; this.label11.Size = new System.Drawing.Size(106, 15); this.label11.TabIndex = 3; @@ -196,7 +203,7 @@ private void InitializeComponent() // this.label12.Anchor = System.Windows.Forms.AnchorStyles.None; this.label12.AutoSize = true; - this.label12.Location = new System.Drawing.Point(125, 139); + this.label12.Location = new System.Drawing.Point(139, 167); this.label12.Name = "label12"; this.label12.Size = new System.Drawing.Size(42, 15); this.label12.TabIndex = 4; @@ -206,7 +213,7 @@ private void InitializeComponent() // samplesUpDown // this.samplesUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; - this.samplesUpDown.Location = new System.Drawing.Point(380, 9); + this.samplesUpDown.Location = new System.Drawing.Point(422, 13); this.samplesUpDown.Maximum = new decimal(new int[] { 100000, 0, @@ -230,7 +237,7 @@ private void InitializeComponent() // updateUpDown // this.updateUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; - this.updateUpDown.Location = new System.Drawing.Point(380, 51); + this.updateUpDown.Location = new System.Drawing.Point(422, 63); this.updateUpDown.Maximum = new decimal(new int[] { 100000, 0, @@ -254,7 +261,7 @@ private void InitializeComponent() // bloomUpDown // this.bloomUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; - this.bloomUpDown.Location = new System.Drawing.Point(380, 135); + this.bloomUpDown.Location = new System.Drawing.Point(422, 163); this.bloomUpDown.Name = "bloomUpDown"; this.bloomUpDown.Size = new System.Drawing.Size(120, 23); this.bloomUpDown.TabIndex = 11; @@ -265,30 +272,65 @@ private void InitializeComponent() 0}); this.bloomUpDown.ValueChanged += new System.EventHandler(this.bloomUpDown_ValueChanged); // + // gammaUpDown + // + this.gammaUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; + this.gammaUpDown.Location = new System.Drawing.Point(422, 113); + this.gammaUpDown.Name = "gammaUpDown"; + this.gammaUpDown.Size = new System.Drawing.Size(120, 23); + this.gammaUpDown.TabIndex = 12; + this.gammaUpDown.Value = new decimal(new int[] { + 30, + 0, + 0, + 0}); + this.gammaUpDown.ValueChanged += new System.EventHandler(this.gammaUpDown_ValueChanged); + // // recursionCheckbox // this.recursionCheckbox.Anchor = System.Windows.Forms.AnchorStyles.None; this.recursionCheckbox.AutoSize = true; - this.recursionCheckbox.Location = new System.Drawing.Point(432, 182); + this.recursionCheckbox.Location = new System.Drawing.Point(474, 218); this.recursionCheckbox.Name = "recursionCheckbox"; this.recursionCheckbox.Size = new System.Drawing.Size(15, 14); this.recursionCheckbox.TabIndex = 10; this.recursionCheckbox.UseVisualStyleBackColor = true; this.recursionCheckbox.CheckedChanged += new System.EventHandler(this.recursionCheckbox_CheckedChanged); // - // gammaUpDown + // label13 // - this.gammaUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; - this.gammaUpDown.Location = new System.Drawing.Point(380, 93); - this.gammaUpDown.Name = "gammaUpDown"; - this.gammaUpDown.Size = new System.Drawing.Size(120, 23); - this.gammaUpDown.TabIndex = 12; - this.gammaUpDown.Value = new decimal(new int[] { - 30, + this.label13.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label13.AutoSize = true; + this.label13.Location = new System.Drawing.Point(44, 217); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(232, 15); + this.label13.TabIndex = 5; + this.label13.Text = "Ray tracing by recursion levels (unoptimal)"; + this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // recLevelUpDown + // + this.recLevelUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; + this.recLevelUpDown.Location = new System.Drawing.Point(422, 265); + this.recLevelUpDown.Maximum = new decimal(new int[] { + 20, 0, 0, 0}); - this.gammaUpDown.ValueChanged += new System.EventHandler(this.gammaUpDown_ValueChanged); + this.recLevelUpDown.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.recLevelUpDown.Name = "recLevelUpDown"; + this.recLevelUpDown.Size = new System.Drawing.Size(120, 23); + this.recLevelUpDown.TabIndex = 14; + this.recLevelUpDown.Value = new decimal(new int[] { + 8, + 0, + 0, + 0}); + this.recLevelUpDown.ValueChanged += new System.EventHandler(this.recLevelUpDown_ValueChanged); // // groupBox1 // @@ -296,7 +338,7 @@ private void InitializeComponent() this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill; this.groupBox1.Location = new System.Drawing.Point(3, 3); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(605, 287); + this.groupBox1.Size = new System.Drawing.Size(658, 330); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "Camera"; @@ -318,10 +360,10 @@ private void InitializeComponent() this.tableLayoutPanel2.Location = new System.Drawing.Point(6, 22); this.tableLayoutPanel2.Name = "tableLayoutPanel2"; this.tableLayoutPanel2.RowCount = 3; - this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); - this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); - this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); - this.tableLayoutPanel2.Size = new System.Drawing.Size(590, 259); + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 43.47826F)); + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 13.04348F)); + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 43.47826F)); + this.tableLayoutPanel2.Size = new System.Drawing.Size(643, 302); this.tableLayoutPanel2.TabIndex = 0; this.tableLayoutPanel2.CellPaint += new System.Windows.Forms.TableLayoutCellPaintEventHandler(this.tableLayoutPanel_CellPaint); // @@ -333,9 +375,9 @@ private void InitializeComponent() this.panel2.Controls.Add(this.randomRadioButton); this.panel2.Controls.Add(this.centerRadioButton); this.panel2.Controls.Add(this.jitteredRadioButton); - this.panel2.Location = new System.Drawing.Point(298, 175); + this.panel2.Location = new System.Drawing.Point(324, 173); this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(289, 81); + this.panel2.Size = new System.Drawing.Size(316, 126); this.panel2.TabIndex = 5; // // randomRadioButton @@ -386,7 +428,7 @@ private void InitializeComponent() // this.label6.Anchor = System.Windows.Forms.AnchorStyles.None; this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(110, 35); + this.label6.Location = new System.Drawing.Point(123, 58); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(74, 15); this.label6.TabIndex = 0; @@ -397,7 +439,7 @@ private void InitializeComponent() // this.label7.Anchor = System.Windows.Forms.AnchorStyles.None; this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(111, 121); + this.label7.Location = new System.Drawing.Point(124, 143); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(73, 15); this.label7.TabIndex = 1; @@ -408,7 +450,7 @@ private void InitializeComponent() // this.label8.Anchor = System.Windows.Forms.AnchorStyles.None; this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(119, 208); + this.label8.Location = new System.Drawing.Point(132, 228); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(57, 15); this.label8.TabIndex = 2; @@ -425,12 +467,12 @@ private void InitializeComponent() this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel3.Controls.Add(this.panel1, 0, 0); this.tableLayoutPanel3.Controls.Add(this.lensCameraLayoutPanel, 1, 0); - this.tableLayoutPanel3.Location = new System.Drawing.Point(298, 3); + this.tableLayoutPanel3.Location = new System.Drawing.Point(324, 3); this.tableLayoutPanel3.Name = "tableLayoutPanel3"; this.tableLayoutPanel3.RowCount = 1; this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 80F)); - this.tableLayoutPanel3.Size = new System.Drawing.Size(289, 80); + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 125F)); + this.tableLayoutPanel3.Size = new System.Drawing.Size(316, 125); this.tableLayoutPanel3.TabIndex = 3; // // panel1 @@ -443,7 +485,7 @@ private void InitializeComponent() this.panel1.Controls.Add(this.perspectiveCameraRadioButton); this.panel1.Location = new System.Drawing.Point(3, 3); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(138, 74); + this.panel1.Size = new System.Drawing.Size(152, 119); this.panel1.TabIndex = 2; // // ortographicCameraRadioButton @@ -481,33 +523,27 @@ private void InitializeComponent() // // lensCameraLayoutPanel // + this.lensCameraLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.lensCameraLayoutPanel.ColumnCount = 2; this.lensCameraLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.lensCameraLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.lensCameraLayoutPanel.Controls.Add(this.label15, 0, 1); + this.lensCameraLayoutPanel.Controls.Add(this.label17, 0, 2); this.lensCameraLayoutPanel.Controls.Add(this.lensRadiusUpDown, 1, 0); this.lensCameraLayoutPanel.Controls.Add(this.focusDistanceUpDown, 1, 1); this.lensCameraLayoutPanel.Controls.Add(this.label14, 0, 0); - this.lensCameraLayoutPanel.Location = new System.Drawing.Point(147, 3); + this.lensCameraLayoutPanel.Controls.Add(this.label15, 0, 1); + this.lensCameraLayoutPanel.Controls.Add(this.autoFocusCheckBox, 1, 2); + this.lensCameraLayoutPanel.Location = new System.Drawing.Point(161, 3); this.lensCameraLayoutPanel.Name = "lensCameraLayoutPanel"; - this.lensCameraLayoutPanel.RowCount = 2; - this.lensCameraLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.lensCameraLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.lensCameraLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); - this.lensCameraLayoutPanel.Size = new System.Drawing.Size(139, 74); + this.lensCameraLayoutPanel.RowCount = 3; + this.lensCameraLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.lensCameraLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.lensCameraLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.lensCameraLayoutPanel.Size = new System.Drawing.Size(152, 119); this.lensCameraLayoutPanel.TabIndex = 3; // - // label15 - // - this.label15.Anchor = System.Windows.Forms.AnchorStyles.None; - this.label15.AutoSize = true; - this.label15.Location = new System.Drawing.Point(9, 40); - this.label15.Name = "label15"; - this.label15.Size = new System.Drawing.Size(51, 30); - this.label15.TabIndex = 8; - this.label15.Text = "Focus distance"; - this.label15.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // // lensRadiusUpDown // this.lensRadiusUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -516,21 +552,26 @@ private void InitializeComponent() 1, 0, 0, - 65536}); - this.lensRadiusUpDown.Location = new System.Drawing.Point(72, 7); + 131072}); + this.lensRadiusUpDown.Location = new System.Drawing.Point(89, 8); + this.lensRadiusUpDown.Maximum = new decimal(new int[] { + 5, + 0, + 0, + 0}); this.lensRadiusUpDown.Minimum = new decimal(new int[] { 1, 0, 0, 131072}); this.lensRadiusUpDown.Name = "lensRadiusUpDown"; - this.lensRadiusUpDown.Size = new System.Drawing.Size(64, 23); + this.lensRadiusUpDown.Size = new System.Drawing.Size(50, 23); this.lensRadiusUpDown.TabIndex = 5; this.lensRadiusUpDown.Value = new decimal(new int[] { - 30, + 25, 0, 0, - 0}); + 131072}); this.lensRadiusUpDown.ValueChanged += new System.EventHandler(this.lensRadiusUpDown_ValueChanged); // // focusDistanceUpDown @@ -542,17 +583,17 @@ private void InitializeComponent() 0, 0, 65536}); - this.focusDistanceUpDown.Location = new System.Drawing.Point(72, 44); - this.focusDistanceUpDown.Minimum = new decimal(new int[] { - 1, + this.focusDistanceUpDown.Location = new System.Drawing.Point(89, 47); + this.focusDistanceUpDown.Maximum = new decimal(new int[] { + 9999999, 0, 0, - 131072}); + 0}); this.focusDistanceUpDown.Name = "focusDistanceUpDown"; - this.focusDistanceUpDown.Size = new System.Drawing.Size(64, 23); + this.focusDistanceUpDown.Size = new System.Drawing.Size(50, 23); this.focusDistanceUpDown.TabIndex = 6; this.focusDistanceUpDown.Value = new decimal(new int[] { - 30, + 5, 0, 0, 0}); @@ -562,24 +603,35 @@ private void InitializeComponent() // this.label14.Anchor = System.Windows.Forms.AnchorStyles.None; this.label14.AutoSize = true; - this.label14.Location = new System.Drawing.Point(13, 11); + this.label14.Location = new System.Drawing.Point(17, 12); this.label14.Name = "label14"; this.label14.Size = new System.Drawing.Size(42, 15); this.label14.TabIndex = 7; this.label14.Text = "Radius"; this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // + // label15 + // + this.label15.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label15.AutoSize = true; + this.label15.Location = new System.Drawing.Point(12, 43); + this.label15.Name = "label15"; + this.label15.Size = new System.Drawing.Size(51, 30); + this.label15.TabIndex = 8; + this.label15.Text = "Focus distance"; + this.label15.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // // fovUpDown // this.fovUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; - this.fovUpDown.Location = new System.Drawing.Point(382, 117); + this.fovUpDown.Location = new System.Drawing.Point(422, 139); this.fovUpDown.Maximum = new decimal(new int[] { - 170, + 90, 0, 0, 0}); this.fovUpDown.Minimum = new decimal(new int[] { - 30, + 10, 0, 0, 0}); @@ -642,46 +694,45 @@ private void InitializeComponent() this.linkLabel1.TabStop = true; this.linkLabel1.Text = "linkLabel1"; // - // label16 - // - this.label16.Anchor = System.Windows.Forms.AnchorStyles.None; - this.label16.AutoSize = true; - this.label16.Location = new System.Drawing.Point(102, 225); - this.label16.Name = "label16"; - this.label16.Size = new System.Drawing.Size(88, 15); - this.label16.TabIndex = 13; - this.label16.Text = "Recursion leves"; - this.label16.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // recLevelUpDown - // - this.recLevelUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; - this.recLevelUpDown.Location = new System.Drawing.Point(380, 221); - this.recLevelUpDown.Maximum = new decimal(new int[] { - 20, - 0, - 0, - 0}); - this.recLevelUpDown.Minimum = new decimal(new int[] { - 1, - 0, - 0, - 0}); - this.recLevelUpDown.Name = "recLevelUpDown"; - this.recLevelUpDown.Size = new System.Drawing.Size(120, 23); - this.recLevelUpDown.TabIndex = 14; - this.recLevelUpDown.Value = new decimal(new int[] { - 8, - 0, - 0, - 0}); - this.recLevelUpDown.ValueChanged += new System.EventHandler(this.recLevelUpDown_ValueChanged); + // finishButton + // + this.finishButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.finishButton.Location = new System.Drawing.Point(580, 684); + this.finishButton.Name = "finishButton"; + this.finishButton.Size = new System.Drawing.Size(75, 23); + this.finishButton.TabIndex = 1; + this.finishButton.Text = "Finish"; + this.finishButton.UseVisualStyleBackColor = true; + this.finishButton.Click += new System.EventHandler(this.finishButton_Click); + // + // label17 + // + this.label17.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label17.AutoSize = true; + this.label17.Location = new System.Drawing.Point(5, 91); + this.label17.Name = "label17"; + this.label17.Size = new System.Drawing.Size(65, 15); + this.label17.TabIndex = 9; + this.label17.Text = "Auto focus"; + this.label17.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // autoFocusCheckBox + // + this.autoFocusCheckBox.Anchor = System.Windows.Forms.AnchorStyles.None; + this.autoFocusCheckBox.AutoSize = true; + this.autoFocusCheckBox.Location = new System.Drawing.Point(106, 91); + this.autoFocusCheckBox.Name = "autoFocusCheckBox"; + this.autoFocusCheckBox.Size = new System.Drawing.Size(15, 14); + this.autoFocusCheckBox.TabIndex = 11; + this.autoFocusCheckBox.UseVisualStyleBackColor = true; + this.autoFocusCheckBox.CheckedChanged += new System.EventHandler(this.autoFocusCheckBox_CheckedChanged); // // SettingsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(611, 586); + this.ClientSize = new System.Drawing.Size(664, 719); + this.Controls.Add(this.finishButton); this.Controls.Add(this.tableLayoutPanel1); this.Name = "SettingsForm"; this.Text = "Settings"; @@ -693,6 +744,7 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.updateUpDown)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.bloomUpDown)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.gammaUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.recLevelUpDown)).EndInit(); this.groupBox1.ResumeLayout(false); this.tableLayoutPanel2.ResumeLayout(false); this.tableLayoutPanel2.PerformLayout(); @@ -706,7 +758,6 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.lensRadiusUpDown)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.focusDistanceUpDown)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.fovUpDown)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.recLevelUpDown)).EndInit(); this.ResumeLayout(false); } @@ -755,5 +806,8 @@ private void InitializeComponent() private System.Windows.Forms.Label label16; private System.Windows.Forms.NumericUpDown recLevelUpDown; private System.Windows.Forms.NumericUpDown recursionLevelUpDown; + private System.Windows.Forms.Button finishButton; + private System.Windows.Forms.Label label17; + private System.Windows.Forms.CheckBox autoFocusCheckBox; } } \ No newline at end of file diff --git a/RayTracerApp/Forms/SettingsForm.cs b/RayTracerApp/Forms/SettingsForm.cs index 57e3c9a..a0e7467 100644 --- a/RayTracerApp/Forms/SettingsForm.cs +++ b/RayTracerApp/Forms/SettingsForm.cs @@ -53,6 +53,7 @@ private void LoadFromController() { lensRadiusUpDown.Value = (decimal)lc.LensRadius; focusDistanceUpDown.Value = (decimal)lc.FocusDistance; + autoFocusCheckBox.Checked = lc.AutoFocus; lensCameraLayoutPanel.Visible = true; } else @@ -186,5 +187,19 @@ private void recLevelUpDown_ValueChanged(object sender, EventArgs e) { _controller.RayTracer.MaxDepth = (int)recLevelUpDown.Value; } + + private void finishButton_Click(object sender, EventArgs e) + { + Close(); + } + + private void autoFocusCheckBox_CheckedChanged(object sender, EventArgs e) + { + var camera = (_controller.Camera as LensCamera); + if (camera != null) + { + camera.AutoFocus = autoFocusCheckBox.Checked; + } + } } } From 64a9cb646aacd8e524510282d3e1392e37aa8ae2 Mon Sep 17 00:00:00 2001 From: p-flis Date: Thu, 7 Jan 2021 01:35:39 +0100 Subject: [PATCH 16/31] repair rt demo --- RayTracerDemo/Program.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/RayTracerDemo/Program.cs b/RayTracerDemo/Program.cs index c421ebe..ee60b7b 100644 --- a/RayTracerDemo/Program.cs +++ b/RayTracerDemo/Program.cs @@ -33,11 +33,6 @@ static void Main(string[] args) scene.AddModel(new Sphere {Position = new Vector3(2.5f, 0.5f, 1), Scale = 1, Material = matteGlass}); scene.AddModel(new Plane {Position = new Vector3(0, -0.5f, 0), Scale = 1, Material = new Diffuse(Color.FromColor4(Color4.ForestGreen))}); scene.AddModel(new Sphere {Position = new Vector3(5f, 0.5f, 1.5f), Scale = 1, Material = new Diffuse(new Texture("earthmap.jpg", false))}); - scene.AddModel(new Triangle( - new Vector3(-4f, 0f, -1f), - new Vector3(-5f, 2f, 2.5f), - new Vector3(-5f, -0.5f, 2f) - ) {Material = new Reflective(Color.FromColor4(Color4.AliceBlue), 0.05f)}); scene.AddModel(new Cube {Position = new Vector3(1.0f, 0.5f, -1.5f), Rotation = new Vector3(-0, 2f, 0), Material = new Diffuse(Color.FromColor4(Color4.Crimson))}); scene.AddModel(new Sphere {Position = new Vector3(0f, 0.0f, 3.5f), Scale = 0.5f, Material = new Refractive(Color.FromColor4(Color4.White), 1.333f)}); var rayTracer = new FileRayTracer("RenderedScene.png", 10, 64, Vec2Sampling.Jittered, 1280); From 501d439eb4ec69005d6c530f4a9ec53a815bb753 Mon Sep 17 00:00:00 2001 From: p-flis Date: Thu, 7 Jan 2021 01:51:55 +0100 Subject: [PATCH 17/31] model loading update from ui --- RayTracerApp/Panels/FeaturesPanel.Designer.cs | 6 +++--- RayTracerApp/Panels/FeaturesPanel.cs | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/RayTracerApp/Panels/FeaturesPanel.Designer.cs b/RayTracerApp/Panels/FeaturesPanel.Designer.cs index 78cbdd5..5f1df7a 100644 --- a/RayTracerApp/Panels/FeaturesPanel.Designer.cs +++ b/RayTracerApp/Panels/FeaturesPanel.Designer.cs @@ -44,6 +44,7 @@ private void InitializeComponent() // this.filePanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.filePanel.Controls.Add(this.aspectPanel); this.filePanel.Controls.Add(this.fromFileLabel); this.filePanel.Controls.Add(this.customModelButton); this.filePanel.Location = new System.Drawing.Point(0, 0); @@ -77,9 +78,9 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Right))); this.aspectPanel.Controls.Add(this.aspectLabel); this.aspectPanel.Controls.Add(this.aspectRatioUpDown); - this.aspectPanel.Location = new System.Drawing.Point(0, 196); + this.aspectPanel.Location = new System.Drawing.Point(0, 0); this.aspectPanel.Name = "aspectPanel"; - this.aspectPanel.Size = new System.Drawing.Size(393, 139); + this.aspectPanel.Size = new System.Drawing.Size(393, 153); this.aspectPanel.TabIndex = 0; // // aspectLabel @@ -120,7 +121,6 @@ private void InitializeComponent() // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.aspectPanel); this.Controls.Add(this.filePanel); this.Name = "FeaturesPanel"; this.Size = new System.Drawing.Size(393, 410); diff --git a/RayTracerApp/Panels/FeaturesPanel.cs b/RayTracerApp/Panels/FeaturesPanel.cs index 625a5f6..151af65 100644 --- a/RayTracerApp/Panels/FeaturesPanel.cs +++ b/RayTracerApp/Panels/FeaturesPanel.cs @@ -30,7 +30,7 @@ public void UpdateForModel() case Cylinder cylinder: cylinder.Aspect = (float)aspectRatioUpDown.Value; break; - case CustomModel cylinder: + case CustomModel custoModel: break; default: throw new Exception("Bad model type"); @@ -108,6 +108,7 @@ private void customModelButton_Click(object sender, EventArgs e) Controller.GetModel()?.Unload(); Controller.SetModel(model); Controller.GetModel().Load(); + Controller.UpdateModelFromUI(); } } } From 388765f48e63501a1243e660bd047e8284c0d209 Mon Sep 17 00:00:00 2001 From: p-flis Date: Thu, 7 Jan 2021 02:28:00 +0100 Subject: [PATCH 18/31] after merge --- RayTracer/Source/Renderer/SamplesRayTracer.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/RayTracer/Source/Renderer/SamplesRayTracer.cs b/RayTracer/Source/Renderer/SamplesRayTracer.cs index ad26f0c..f5fe480 100644 --- a/RayTracer/Source/Renderer/SamplesRayTracer.cs +++ b/RayTracer/Source/Renderer/SamplesRayTracer.cs @@ -16,7 +16,7 @@ public class SamplesRayTracer : IncrementalRayTracer public SamplesRayTracer(int maxDepth, int samples, Func> sampling, int resolution, int samplesRenderStep) : base( - maxDepth, samples, sampling, resolution) + maxDepth, samples, sampling, resolution, samplesRenderStep) { _samplesRenderStep = samplesRenderStep; } @@ -30,7 +30,7 @@ public override void Render(Scene scene, Camera camera) var ray = lensCamera.GetRay(0.5f, 0.5f); var hitInfo = new HitInfo(); var hit = scene.HitTest(ray, ref hitInfo, 0.001f, float.PositiveInfinity); - if(hit) + if (hit) { lensCamera.FocusDistance = hitInfo.Distance; } @@ -47,9 +47,9 @@ public override void Render(Scene scene, Camera camera) for (int k = 0; k < Samples; k++) { - Parallel.For(0, width, i => + try { - Parallel.For(0, width, new ParallelOptions {CancellationToken = CancellationToken }, i => + Parallel.For(0, width, new ParallelOptions {CancellationToken = CancellationToken}, i => { for (int j = 0; j < height; j++) { @@ -57,14 +57,17 @@ public override void Render(Scene scene, Camera camera) float u = (i + sample.X) / (width - 1); float v = (j + sample.Y) / (height - 1); Ray ray = camera.GetRay(u, v); - image[i, j] += Shade(ray, scene, MaxDepth); + var shade = Shade(ray, scene, MaxDepth); + image.Bloom(shade, i, j, (int) shade.GetBrightness()); + image[i, j] += shade; } }); } - catch(Exception) + catch (Exception e) { return; } + if (CancellationToken.IsCancellationRequested) return; From a86f290563b389cea8e44eec7792e2194272cfaf Mon Sep 17 00:00:00 2001 From: karolk98 <47919588+karolk98@users.noreply.github.com> Date: Thu, 7 Jan 2021 03:18:23 +0100 Subject: [PATCH 19/31] Progress bar --- RayTracerApp/Forms/MainForm.Designer.cs | 17 ++++++++++++++++- RayTracerApp/Forms/MainForm.cs | 10 +++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/RayTracerApp/Forms/MainForm.Designer.cs b/RayTracerApp/Forms/MainForm.Designer.cs index 0f73543..2f931f4 100644 --- a/RayTracerApp/Forms/MainForm.Designer.cs +++ b/RayTracerApp/Forms/MainForm.Designer.cs @@ -37,13 +37,14 @@ private void InitializeComponent() this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); this.Text = "RayTracing"; + InitializeProgressBar(); this.gLControl.Location = new System.Drawing.Point(0, 20); this.gLControl.Name = "gLControl"; this.gLControl.Size = new System.Drawing.Size(500, 300); this.gLControl.TabIndex = 0; this.gLControl.VSync = true; this.gLControl.Load += new System.EventHandler(this.GLControl_Load); - + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.FormClosed += MainForm_FormClosed; this.Resize += this.OnResize; @@ -55,6 +56,19 @@ private void InitializeComponent() this.ResumeLayout(false); } + private void InitializeProgressBar() + { + this.progressBar = new ProgressBar(); + this.progressBar.Anchor = AnchorStyles.Bottom|AnchorStyles.Left|AnchorStyles.Right; + this.progressBar.Width = Width/2; + this.progressBar.Height = 20; + this.progressBar.Location = new System.Drawing.Point((Width-progressBar.Width)/2, (int)(Height - progressBar.Height*3.5f)); + this.progressBar.Maximum = 100; + this.progressBar.Step = 1; + this.progressBar.Value = 0; + this.progressBar.Visible = false; + this.Controls.Add(this.progressBar); + } private void InitializeNewEditDeleteMenu() { @@ -196,6 +210,7 @@ private void InitializeToolstrip() private ToolStripMenuItem addItem2; private ToolStripMenuItem editItem2; private ContextMenuStrip newEditStrip; + private ProgressBar progressBar; #endregion } diff --git a/RayTracerApp/Forms/MainForm.cs b/RayTracerApp/Forms/MainForm.cs index e0a43af..2cff81d 100644 --- a/RayTracerApp/Forms/MainForm.cs +++ b/RayTracerApp/Forms/MainForm.cs @@ -62,7 +62,7 @@ private void GLControl_Load(object sender, EventArgs e) { GL.Enable(EnableCap.DepthTest); _renderer = new Renderer(); - _rayTracer = new SamplesRayTracer(8, 1024, Vec2Sampling.Jittered, gLControl.Width, 8); + _rayTracer = new SamplesRayTracer(8, 10, Vec2Sampling.Jittered, gLControl.Width, 1); _cameraController = new CameraController(_camera, gLControl, UpdateLastModification); _scene.AmbientLight = new AmbientLight {Color = Color.FromColor4(Color4.LightSkyBlue)}; _scene.AddModel(new Sphere @@ -135,6 +135,8 @@ private void OnTimerTick(object sender, EventArgs e) { InitializeBackgroundWorker(); _backgroundWorker.RunWorkerAsync(); + progressBar.Value = 0; + progressBar.Visible = true; rayTracingStarted = true; } else @@ -176,6 +178,7 @@ private void BackgroundWorkerProgressChanged(object sender, gLControl.SwapBuffers(); texture?.Dispose(); Text = $@"{e.ProgressPercentage}%"; + progressBar.Value = e.ProgressPercentage; } private void InitializeBackgroundWorker() @@ -187,6 +190,11 @@ private void InitializeBackgroundWorker() }; _backgroundWorker.DoWork += StartRender; _backgroundWorker.ProgressChanged += BackgroundWorkerProgressChanged; + _backgroundWorker.RunWorkerCompleted += (o,args) => + { + progressBar.Visible = false; + gLControl.SwapBuffers(); + }; _cts = new CancellationTokenSource(); } From 727e85ee7dcd6196b49de7a86ff8643dd4ca0d76 Mon Sep 17 00:00:00 2001 From: p-flis Date: Thu, 7 Jan 2021 03:21:28 +0100 Subject: [PATCH 20/31] saving --- RayTracer/Source/Materials/Texture.cs | 30 ++++++++++++++++++++----- RayTracerApp/Forms/MainForm.Designer.cs | 11 ++++++++- RayTracerApp/Forms/MainForm.cs | 16 +++++++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/RayTracer/Source/Materials/Texture.cs b/RayTracer/Source/Materials/Texture.cs index a4b08ba..1c6f924 100644 --- a/RayTracer/Source/Materials/Texture.cs +++ b/RayTracer/Source/Materials/Texture.cs @@ -26,10 +26,13 @@ public Texture(int width, int height) public Texture(Texture image) // copy constructor { - _data = new Color[image.Width, image.Height]; - for (int i = 0; i < Width; i++) - for (int j = 0; j < Height; j++) - _data[i, j] = image._data[i, j]; + lock(this) + { + _data = new Color[image.Width, image.Height]; + for (int i = 0; i < Width; i++) + for (int j = 0; j < Height; j++) + _data[i, j] = image._data[i, j]; + } } public Texture(string path, bool glLoad = true) @@ -69,6 +72,18 @@ public Texture(string path, bool glLoad = true) set => _data[w, h] = value; } + public void CopyFrom(Texture texture) + { + if (this.Width != texture.Width || this.Height != texture.Height) return; + for(int i = 0; i < Width; i++) + { + for (int j = 0; j < Height; j++) + { + this[i, j] = texture[i, j]; + } + } + } + public void Bloom(Color color, int w, int h, int strength = 1) { bool In(int x, int y) @@ -233,8 +248,11 @@ public void Blit() public void Dispose() { - GL.DeleteTexture(_id); - _data = null; + lock (this) + { + GL.DeleteTexture(_id); + _data = null; + } } } } \ No newline at end of file diff --git a/RayTracerApp/Forms/MainForm.Designer.cs b/RayTracerApp/Forms/MainForm.Designer.cs index f132cf6..548d835 100644 --- a/RayTracerApp/Forms/MainForm.Designer.cs +++ b/RayTracerApp/Forms/MainForm.Designer.cs @@ -140,6 +140,7 @@ private void InitializeToolstrip() this.newObjectButton = new System.Windows.Forms.ToolStripButton(); this.editObjectButton = new System.Windows.Forms.ToolStripButton(); this.deleteObjectButton = new System.Windows.Forms.ToolStripButton(); + this.saveImageToFileButton = new System.Windows.Forms.ToolStripButton(); this.toolStrip.SuspendLayout(); this.ddButton = new ToolStripDropDownButton(); @@ -153,7 +154,8 @@ private void InitializeToolstrip() this.toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ddButton, - this.settingsButton + this.settingsButton, + this.saveImageToFileButton }); this.toolStrip.Location = new System.Drawing.Point(0, 0); @@ -161,6 +163,12 @@ private void InitializeToolstrip() this.toolStrip.TabIndex = 1; this.toolStrip.Text = "toolStrip"; + this.saveImageToFileButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.saveImageToFileButton.Name = "saveImageToFile"; + this.saveImageToFileButton.Text = "Save image"; + this.saveImageToFileButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.saveImageToFileButton.Click += new System.EventHandler(this.SaveImage_Click); + this.settingsButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; this.settingsButton.Name = "settingsButton"; this.settingsButton.Text = "Settings"; @@ -196,6 +204,7 @@ private void InitializeToolstrip() private ToolStripButton newObjectButton; private ToolStripButton editObjectButton; private ToolStripButton deleteObjectButton; + private ToolStripButton saveImageToFileButton; private OpenTK.GLControl gLControl = new GLControl(new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8)); private ToolStripDropDownButton ddButton; private ContextMenuStrip newDeleteStrip; diff --git a/RayTracerApp/Forms/MainForm.cs b/RayTracerApp/Forms/MainForm.cs index ccffda8..3c536f7 100644 --- a/RayTracerApp/Forms/MainForm.cs +++ b/RayTracerApp/Forms/MainForm.cs @@ -38,6 +38,8 @@ public partial class MainForm : Form private HitInfo _contextHitInfo; private bool _contextHit; + private Texture _lastTexture; + public void UpdateLastModification() { lastModification = DateTime.Now.Ticks / TimeSpan.TicksPerSecond; @@ -158,6 +160,7 @@ private void UpdateViewport() _cameraController.GetCamera().AspectRatio = gLControl.Width / (float) gLControl.Height; gLControl.Invalidate(); _rayTracer.Resolution = gLControl.Width; + _lastTexture = new Texture(Width, Height); } private void StartRender(object sender, DoWorkEventArgs e) @@ -174,6 +177,7 @@ private void BackgroundWorkerProgressChanged(object sender, texture?.Blit(); if(!gLControl.IsDisposed) gLControl.SwapBuffers(); + _lastTexture?.CopyFrom(texture); texture?.Dispose(); Text = $@"{e.ProgressPercentage}%"; } @@ -329,6 +333,18 @@ private void GLControl_MouseClick(object sender, MouseEventArgs e) } } + private void SaveImage_Click(object sender, EventArgs e) + { + SaveFileDialog saveDialog = new SaveFileDialog(); + DialogResult result = saveDialog.ShowDialog(); + if (result == DialogResult.OK) + { + String fileName = saveDialog.FileName; + _lastTexture.Write(fileName); + } + + } + private void DeleteItem_Click(object sender, EventArgs e) { DeleteObjectFunction(_contextHit, ref _contextHitInfo); From 8130c20586e07f4cb93202075496b14d2a762a16 Mon Sep 17 00:00:00 2001 From: p-flis Date: Thu, 7 Jan 2021 03:25:55 +0100 Subject: [PATCH 21/31] redundant locks --- RayTracer/Source/Materials/Texture.cs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/RayTracer/Source/Materials/Texture.cs b/RayTracer/Source/Materials/Texture.cs index 1c6f924..bbf4dfd 100644 --- a/RayTracer/Source/Materials/Texture.cs +++ b/RayTracer/Source/Materials/Texture.cs @@ -26,13 +26,10 @@ public Texture(int width, int height) public Texture(Texture image) // copy constructor { - lock(this) - { - _data = new Color[image.Width, image.Height]; - for (int i = 0; i < Width; i++) - for (int j = 0; j < Height; j++) - _data[i, j] = image._data[i, j]; - } + _data = new Color[image.Width, image.Height]; + for (int i = 0; i < Width; i++) + for (int j = 0; j < Height; j++) + _data[i, j] = image._data[i, j]; } public Texture(string path, bool glLoad = true) @@ -75,7 +72,7 @@ public Texture(string path, bool glLoad = true) public void CopyFrom(Texture texture) { if (this.Width != texture.Width || this.Height != texture.Height) return; - for(int i = 0; i < Width; i++) + for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { @@ -248,11 +245,8 @@ public void Blit() public void Dispose() { - lock (this) - { - GL.DeleteTexture(_id); - _data = null; - } + GL.DeleteTexture(_id); + _data = null; } } } \ No newline at end of file From d2344bf276833a286735e7d011ab8d72fe5fa8b6 Mon Sep 17 00:00:00 2001 From: karolk98 <47919588+karolk98@users.noreply.github.com> Date: Thu, 7 Jan 2021 04:07:52 +0100 Subject: [PATCH 22/31] Emissive amplification --- RayTracer/Source/Materials/Emissive.cs | 23 +++++++++++++---------- RayTracer/Source/Models/ModelLoader.cs | 2 +- RayTracerApp/Forms/MainForm.cs | 2 +- RayTracerApp/Panels/MaterialPanel.cs | 10 +++++----- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/RayTracer/Source/Materials/Emissive.cs b/RayTracer/Source/Materials/Emissive.cs index 2905376..e23b4f6 100644 --- a/RayTracer/Source/Materials/Emissive.cs +++ b/RayTracer/Source/Materials/Emissive.cs @@ -9,30 +9,33 @@ namespace RayTracing.Materials public class Emissive : IMaterial { private const int SAMPLES = 10000; - private ITexture _emit; + private ITexture _albedo; public Color AverageColor => _averageColor; + public float Amplification { get; set; } = 1; - public ITexture Emit + public ITexture Albedo { - get => _emit; + get => _albedo; set { - _emit = value; + _albedo = value; UpdateAverageColor(value); } } private Color _averageColor; - public Emissive(ITexture emit) + public Emissive(ITexture emit, float amp = 1) { - Emit = emit; + Amplification = amp; + Albedo = emit; } - public Emissive(Color emitColor) + public Emissive(Color emitColor, float amp = 1) { - Emit = new SolidColor(emitColor); + Amplification = amp; + Albedo = new SolidColor(emitColor); } private void UpdateAverageColor(ITexture texture) @@ -56,12 +59,12 @@ public bool Scatter(ref Ray ray, ref HitInfo hit, out Color attenuation, out Ray public Color Emitted(float u, float v) { - return Emit[u, v]; + return Albedo[u, v] * Amplification; } public void Use(Shader shader, float part) { - Emit.Use(shader, 0, part); + Albedo.Use(shader, 0, part); } } } \ No newline at end of file diff --git a/RayTracer/Source/Models/ModelLoader.cs b/RayTracer/Source/Models/ModelLoader.cs index b9e971c..9b3fd09 100644 --- a/RayTracer/Source/Models/ModelLoader.cs +++ b/RayTracer/Source/Models/ModelLoader.cs @@ -80,7 +80,7 @@ private static IMaterial ProcessMaterial(Assimp.Material material, string dir) { Emissive = { - Emit = ProcessTexture(material.HasTextureAmbient, material.ColorAmbient, + Albedo = ProcessTexture(material.HasTextureAmbient, material.ColorAmbient, material.TextureAmbient, dir) }, Diffuse = diff --git a/RayTracerApp/Forms/MainForm.cs b/RayTracerApp/Forms/MainForm.cs index 4ba9bfb..dc16731 100644 --- a/RayTracerApp/Forms/MainForm.cs +++ b/RayTracerApp/Forms/MainForm.cs @@ -70,7 +70,7 @@ private void GLControl_Load(object sender, EventArgs e) _scene.AddModel(new Sphere { Position = new Vector3(0, 5.5f, 0), Scale = 1, - Material = new MasterMaterial(new Emissive(Color.FromColor4(Color4.LightYellow) * 25)) + Material = new MasterMaterial(new Emissive(Color.FromColor4(Color4.LightYellow),25)) }.Load()); _scene.AddModel(new Sphere { diff --git a/RayTracerApp/Panels/MaterialPanel.cs b/RayTracerApp/Panels/MaterialPanel.cs index afbc1fd..b4c4a43 100644 --- a/RayTracerApp/Panels/MaterialPanel.cs +++ b/RayTracerApp/Panels/MaterialPanel.cs @@ -35,10 +35,10 @@ public void UpdateFromModel() else diffuseTexture.BackColor = material.Diffuse.Albedo[0, 0].ToSystemDrawing(); - if (material.Emissive.Emit is Texture) - emissiveTexture.Image = TextureConverter.Convert(material.Emissive.Emit as Texture); + if (material.Emissive.Albedo is Texture) + emissiveTexture.Image = TextureConverter.Convert(material.Emissive.Albedo as Texture); else - emissiveTexture.BackColor = material.Emissive.Emit[0, 0].ToSystemDrawing(); + emissiveTexture.BackColor = material.Emissive.Albedo[0, 0].ToSystemDrawing(); if (material.Reflective.Albedo is Texture) reflectiveTexture.Image = TextureConverter.Convert(material.Reflective.Albedo as Texture); @@ -98,7 +98,7 @@ private void emissiveFile_Click(object sender, EventArgs e) if (string.IsNullOrEmpty(texturePath)) return; var texture = new Texture(texturePath); - Controller.Material.Emissive.Emit = texture; + Controller.Material.Emissive.Albedo = texture; emissiveTexture.Image = TextureConverter.Convert(texture); } @@ -197,7 +197,7 @@ private void emissiveColor_Click(object sender, EventArgs e) var color = colorDialog.Color; emissiveTexture.BackColor = color; emissiveTexture.Image = null; - Controller.Material.Emissive.Emit = new SolidColor(RayTracing.Maths.Color.FromSystemDrawing(color)); + Controller.Material.Emissive.Albedo = new SolidColor(RayTracing.Maths.Color.FromSystemDrawing(color)); } } From 331744ace920de9bb1d43fb768d255f63ba614e7 Mon Sep 17 00:00:00 2001 From: p-flis Date: Thu, 7 Jan 2021 04:09:59 +0100 Subject: [PATCH 23/31] bloom and gamma --- RayTracer/Source/Materials/Texture.cs | 14 ++- .../Source/Renderer/IncrementalRayTracer.cs | 2 +- RayTracer/Source/Renderer/RayTracer.cs | 4 +- RayTracer/Source/Renderer/SamplesRayTracer.cs | 9 +- RayTracerApp/Forms/MainForm.cs | 3 +- RayTracerApp/Forms/SettingsForm.Designer.cs | 93 +++++++++++-------- RayTracerApp/Forms/SettingsForm.cs | 12 +-- 7 files changed, 78 insertions(+), 59 deletions(-) diff --git a/RayTracer/Source/Materials/Texture.cs b/RayTracer/Source/Materials/Texture.cs index bbf4dfd..887fde3 100644 --- a/RayTracer/Source/Materials/Texture.cs +++ b/RayTracer/Source/Materials/Texture.cs @@ -81,21 +81,25 @@ public void CopyFrom(Texture texture) } } - public void Bloom(Color color, int w, int h, int strength = 1) + public void Bloom(Color color, int w, int h, int brightness, int strength = 1) { + if (strength == 0 || brightness <= 1) return; + + brightness *= strength; + bool In(int x, int y) { return x >= 0 && x < Width && y >= 0 && y < Height; } - for (int i = -strength; i < strength; i++) - for (int j = -strength; j < strength; j++) + for (int i = -brightness; i < brightness; i++) + for (int j = -brightness; j < brightness; j++) { if (In(w + i, h + j) && i != 0 && j != 0) { int rs = i * i + j * j; - if (rs <= strength * strength) - _data[w + i, h + j] += color / (10 * strength * (rs + 1)); + if (rs <= brightness * brightness) + _data[w + i, h + j] += color * strength * strength / (10 * brightness * (rs + 1)); } } } diff --git a/RayTracer/Source/Renderer/IncrementalRayTracer.cs b/RayTracer/Source/Renderer/IncrementalRayTracer.cs index d0cc686..5b6e3fb 100644 --- a/RayTracer/Source/Renderer/IncrementalRayTracer.cs +++ b/RayTracer/Source/Renderer/IncrementalRayTracer.cs @@ -11,8 +11,8 @@ public abstract class IncrementalRayTracer : RayTracer, IRenderer { public Action OnFrameReady { get; set; } public CancellationToken CancellationToken { get; set; } - public int SamplesRenderStep { get; set; } + public abstract void Render(Scene scene, Camera camera); public IncrementalRayTracer(int maxDepth, int samples, Func> sampling, int resolution, int samplesRenderStep) : diff --git a/RayTracer/Source/Renderer/RayTracer.cs b/RayTracer/Source/Renderer/RayTracer.cs index 06496da..1e76a78 100644 --- a/RayTracer/Source/Renderer/RayTracer.cs +++ b/RayTracer/Source/Renderer/RayTracer.cs @@ -13,9 +13,9 @@ public abstract class RayTracer public Func> Sampling { get; set; } public int Resolution { get; set; } - public int Bloom { get; set; } + public int Bloom { get; set; } = 1; - public int GammaCorrection { get; set; } + public bool GammaCorrection { get; set; } = true; public RayTracer(int maxDepth, int samples, Func> sampling, int resolution) { diff --git a/RayTracer/Source/Renderer/SamplesRayTracer.cs b/RayTracer/Source/Renderer/SamplesRayTracer.cs index f5fe480..89f5c69 100644 --- a/RayTracer/Source/Renderer/SamplesRayTracer.cs +++ b/RayTracer/Source/Renderer/SamplesRayTracer.cs @@ -36,7 +36,7 @@ public override void Render(Scene scene, Camera camera) } else { - lensCamera.FocusDistance = 999999f; + lensCamera.FocusDistance = 100000f; } } @@ -58,7 +58,7 @@ public override void Render(Scene scene, Camera camera) float v = (j + sample.Y) / (height - 1); Ray ray = camera.GetRay(u, v); var shade = Shade(ray, scene, MaxDepth); - image.Bloom(shade, i, j, (int) shade.GetBrightness()); + image.Bloom(shade, i, j, (int) shade.GetBrightness(), Bloom); image[i, j] += shade; } }); @@ -75,7 +75,10 @@ public override void Render(Scene scene, Camera camera) { var output = new Texture(image); output.Process(c => (c / (k + 1)).Clamp()); - output.AutoGammaCorrect(); + if (GammaCorrection) + { + output.AutoGammaCorrect(); + } var percentage = (k + 1) * 100 / Samples; OnFrameReady?.Invoke(percentage, output); } diff --git a/RayTracerApp/Forms/MainForm.cs b/RayTracerApp/Forms/MainForm.cs index dc16731..54c0ce9 100644 --- a/RayTracerApp/Forms/MainForm.cs +++ b/RayTracerApp/Forms/MainForm.cs @@ -64,7 +64,7 @@ private void GLControl_Load(object sender, EventArgs e) { GL.Enable(EnableCap.DepthTest); _renderer = new Renderer(); - _rayTracer = new SamplesRayTracer(8, 10, Vec2Sampling.Jittered, gLControl.Width, 1); + _rayTracer = new SamplesRayTracer(8, 1000, Vec2Sampling.Jittered, gLControl.Width, 10); _cameraController = new CameraController(_camera, gLControl, UpdateLastModification); _scene.AmbientLight = new AmbientLight {Color = Color.FromColor4(Color4.LightSkyBlue)}; _scene.AddModel(new Sphere @@ -181,7 +181,6 @@ private void BackgroundWorkerProgressChanged(object sender, gLControl.SwapBuffers(); _lastTexture?.CopyFrom(texture); texture?.Dispose(); - Text = $@"{e.ProgressPercentage}%"; progressBar.Value = e.ProgressPercentage; } diff --git a/RayTracerApp/Forms/SettingsForm.Designer.cs b/RayTracerApp/Forms/SettingsForm.Designer.cs index 257f30f..04f77c3 100644 --- a/RayTracerApp/Forms/SettingsForm.Designer.cs +++ b/RayTracerApp/Forms/SettingsForm.Designer.cs @@ -40,7 +40,6 @@ private void InitializeComponent() this.samplesUpDown = new System.Windows.Forms.NumericUpDown(); this.updateUpDown = new System.Windows.Forms.NumericUpDown(); this.bloomUpDown = new System.Windows.Forms.NumericUpDown(); - this.gammaUpDown = new System.Windows.Forms.NumericUpDown(); this.recursionCheckbox = new System.Windows.Forms.CheckBox(); this.label13 = new System.Windows.Forms.Label(); this.recLevelUpDown = new System.Windows.Forms.NumericUpDown(); @@ -59,10 +58,12 @@ private void InitializeComponent() this.lensCameraRadioButton = new System.Windows.Forms.RadioButton(); this.perspectiveCameraRadioButton = new System.Windows.Forms.RadioButton(); this.lensCameraLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.label17 = new System.Windows.Forms.Label(); this.lensRadiusUpDown = new System.Windows.Forms.NumericUpDown(); this.focusDistanceUpDown = new System.Windows.Forms.NumericUpDown(); this.label14 = new System.Windows.Forms.Label(); this.label15 = new System.Windows.Forms.Label(); + this.autoFocusCheckBox = new System.Windows.Forms.CheckBox(); this.fovUpDown = new System.Windows.Forms.NumericUpDown(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); @@ -71,15 +72,14 @@ private void InitializeComponent() this.label5 = new System.Windows.Forms.Label(); this.linkLabel1 = new System.Windows.Forms.LinkLabel(); this.finishButton = new System.Windows.Forms.Button(); - this.label17 = new System.Windows.Forms.Label(); - this.autoFocusCheckBox = new System.Windows.Forms.CheckBox(); + this.checkBox1 = new System.Windows.Forms.CheckBox(); + this.gammaCheckBox = new System.Windows.Forms.CheckBox(); this.tableLayoutPanel1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.tableLayoutPanel4.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.samplesUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.updateUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bloomUpDown)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.gammaUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.recLevelUpDown)).BeginInit(); this.groupBox1.SuspendLayout(); this.tableLayoutPanel2.SuspendLayout(); @@ -130,6 +130,7 @@ private void InitializeComponent() this.tableLayoutPanel4.ColumnCount = 2; this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel4.Controls.Add(this.gammaCheckBox, 1, 2); this.tableLayoutPanel4.Controls.Add(this.label16, 0, 5); this.tableLayoutPanel4.Controls.Add(this.label9, 0, 0); this.tableLayoutPanel4.Controls.Add(this.label10, 0, 1); @@ -138,7 +139,6 @@ private void InitializeComponent() this.tableLayoutPanel4.Controls.Add(this.samplesUpDown, 1, 0); this.tableLayoutPanel4.Controls.Add(this.updateUpDown, 1, 1); this.tableLayoutPanel4.Controls.Add(this.bloomUpDown, 1, 3); - this.tableLayoutPanel4.Controls.Add(this.gammaUpDown, 1, 2); this.tableLayoutPanel4.Controls.Add(this.recursionCheckbox, 1, 4); this.tableLayoutPanel4.Controls.Add(this.label13, 0, 4); this.tableLayoutPanel4.Controls.Add(this.recLevelUpDown, 1, 5); @@ -151,6 +151,7 @@ private void InitializeComponent() this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66667F)); + this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel4.Size = new System.Drawing.Size(643, 303); this.tableLayoutPanel4.TabIndex = 0; this.tableLayoutPanel4.CellPaint += new System.Windows.Forms.TableLayoutCellPaintEventHandler(this.tableLayoutPanel_CellPaint); @@ -262,30 +263,21 @@ private void InitializeComponent() // this.bloomUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; this.bloomUpDown.Location = new System.Drawing.Point(422, 163); + this.bloomUpDown.Maximum = new decimal(new int[] { + 5, + 0, + 0, + 0}); this.bloomUpDown.Name = "bloomUpDown"; this.bloomUpDown.Size = new System.Drawing.Size(120, 23); this.bloomUpDown.TabIndex = 11; this.bloomUpDown.Value = new decimal(new int[] { - 30, + 5, 0, 0, 0}); this.bloomUpDown.ValueChanged += new System.EventHandler(this.bloomUpDown_ValueChanged); // - // gammaUpDown - // - this.gammaUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; - this.gammaUpDown.Location = new System.Drawing.Point(422, 113); - this.gammaUpDown.Name = "gammaUpDown"; - this.gammaUpDown.Size = new System.Drawing.Size(120, 23); - this.gammaUpDown.TabIndex = 12; - this.gammaUpDown.Value = new decimal(new int[] { - 30, - 0, - 0, - 0}); - this.gammaUpDown.ValueChanged += new System.EventHandler(this.gammaUpDown_ValueChanged); - // // recursionCheckbox // this.recursionCheckbox.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -544,6 +536,17 @@ private void InitializeComponent() this.lensCameraLayoutPanel.Size = new System.Drawing.Size(152, 119); this.lensCameraLayoutPanel.TabIndex = 3; // + // label17 + // + this.label17.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label17.AutoSize = true; + this.label17.Location = new System.Drawing.Point(5, 91); + this.label17.Name = "label17"; + this.label17.Size = new System.Drawing.Size(65, 15); + this.label17.TabIndex = 9; + this.label17.Text = "Auto focus"; + this.label17.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // // lensRadiusUpDown // this.lensRadiusUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -621,6 +624,17 @@ private void InitializeComponent() this.label15.Text = "Focus distance"; this.label15.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // + // autoFocusCheckBox + // + this.autoFocusCheckBox.Anchor = System.Windows.Forms.AnchorStyles.None; + this.autoFocusCheckBox.AutoSize = true; + this.autoFocusCheckBox.Location = new System.Drawing.Point(106, 91); + this.autoFocusCheckBox.Name = "autoFocusCheckBox"; + this.autoFocusCheckBox.Size = new System.Drawing.Size(15, 14); + this.autoFocusCheckBox.TabIndex = 11; + this.autoFocusCheckBox.UseVisualStyleBackColor = true; + this.autoFocusCheckBox.CheckedChanged += new System.EventHandler(this.autoFocusCheckBox_CheckedChanged); + // // fovUpDown // this.fovUpDown.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -705,27 +719,26 @@ private void InitializeComponent() this.finishButton.UseVisualStyleBackColor = true; this.finishButton.Click += new System.EventHandler(this.finishButton_Click); // - // label17 + // checkBox1 // - this.label17.Anchor = System.Windows.Forms.AnchorStyles.None; - this.label17.AutoSize = true; - this.label17.Location = new System.Drawing.Point(5, 91); - this.label17.Name = "label17"; - this.label17.Size = new System.Drawing.Size(65, 15); - this.label17.TabIndex = 9; - this.label17.Text = "Auto focus"; - this.label17.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.checkBox1.Anchor = System.Windows.Forms.AnchorStyles.None; + this.checkBox1.AutoSize = true; + this.checkBox1.Location = new System.Drawing.Point(474, 251); + this.checkBox1.Name = "checkBox1"; + this.checkBox1.Size = new System.Drawing.Size(15, 14); + this.checkBox1.TabIndex = 15; + this.checkBox1.UseVisualStyleBackColor = true; // - // autoFocusCheckBox + // gammaCheckBox // - this.autoFocusCheckBox.Anchor = System.Windows.Forms.AnchorStyles.None; - this.autoFocusCheckBox.AutoSize = true; - this.autoFocusCheckBox.Location = new System.Drawing.Point(106, 91); - this.autoFocusCheckBox.Name = "autoFocusCheckBox"; - this.autoFocusCheckBox.Size = new System.Drawing.Size(15, 14); - this.autoFocusCheckBox.TabIndex = 11; - this.autoFocusCheckBox.UseVisualStyleBackColor = true; - this.autoFocusCheckBox.CheckedChanged += new System.EventHandler(this.autoFocusCheckBox_CheckedChanged); + this.gammaCheckBox.Anchor = System.Windows.Forms.AnchorStyles.None; + this.gammaCheckBox.AutoSize = true; + this.gammaCheckBox.Location = new System.Drawing.Point(474, 118); + this.gammaCheckBox.Name = "gammaCheckBox"; + this.gammaCheckBox.Size = new System.Drawing.Size(15, 14); + this.gammaCheckBox.TabIndex = 15; + this.gammaCheckBox.UseVisualStyleBackColor = true; + this.gammaCheckBox.CheckedChanged += new System.EventHandler(this.gammaCheckBox_CheckedChanged); // // SettingsForm // @@ -743,7 +756,6 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.samplesUpDown)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.updateUpDown)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.bloomUpDown)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.gammaUpDown)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.recLevelUpDown)).EndInit(); this.groupBox1.ResumeLayout(false); this.tableLayoutPanel2.ResumeLayout(false); @@ -797,7 +809,6 @@ private void InitializeComponent() private System.Windows.Forms.NumericUpDown updateUpDown; private System.Windows.Forms.CheckBox recursionCheckbox; private System.Windows.Forms.NumericUpDown bloomUpDown; - private System.Windows.Forms.NumericUpDown gammaUpDown; private System.Windows.Forms.TableLayoutPanel lensCameraLayoutPanel; private System.Windows.Forms.Label label15; private System.Windows.Forms.NumericUpDown lensRadiusUpDown; @@ -809,5 +820,7 @@ private void InitializeComponent() private System.Windows.Forms.Button finishButton; private System.Windows.Forms.Label label17; private System.Windows.Forms.CheckBox autoFocusCheckBox; + private System.Windows.Forms.CheckBox gammaCheckBox; + private System.Windows.Forms.CheckBox checkBox1; } } \ No newline at end of file diff --git a/RayTracerApp/Forms/SettingsForm.cs b/RayTracerApp/Forms/SettingsForm.cs index a0e7467..e45290b 100644 --- a/RayTracerApp/Forms/SettingsForm.cs +++ b/RayTracerApp/Forms/SettingsForm.cs @@ -41,7 +41,7 @@ private void LoadFromController() updateUpDown.Value = rayTracer.SamplesRenderStep; - gammaUpDown.Value = rayTracer.GammaCorrection; + gammaCheckBox.Checked = _controller.RayTracer.GammaCorrection; bloomUpDown.Value = rayTracer.Bloom; @@ -89,11 +89,6 @@ private void bloomUpDown_ValueChanged(object sender, EventArgs e) _controller.RayTracer.Bloom = (int)bloomUpDown.Value; } - private void gammaUpDown_ValueChanged(object sender, EventArgs e) - { - _controller.RayTracer.GammaCorrection = (int)gammaUpDown.Value; - } - private void updateUpDown_ValueChanged(object sender, EventArgs e) { _controller.RayTracer.SamplesRenderStep = (int)updateUpDown.Value; @@ -201,5 +196,10 @@ private void autoFocusCheckBox_CheckedChanged(object sender, EventArgs e) camera.AutoFocus = autoFocusCheckBox.Checked; } } + + private void gammaCheckBox_CheckedChanged(object sender, EventArgs e) + { + _controller.RayTracer.GammaCorrection = gammaCheckBox.Checked; + } } } From 99aa5438d60033f8811a67e98b3d7a5940dc7c48 Mon Sep 17 00:00:00 2001 From: p-flis Date: Thu, 7 Jan 2021 04:27:12 +0100 Subject: [PATCH 24/31] ui --- RayTracerApp/Panels/FeaturesPanel.Designer.cs | 14 +- RayTracerApp/Panels/MaterialPanel.Designer.cs | 160 +++++++++++------- RayTracerApp/Panels/MaterialPanel.cs | 9 + 3 files changed, 114 insertions(+), 69 deletions(-) diff --git a/RayTracerApp/Panels/FeaturesPanel.Designer.cs b/RayTracerApp/Panels/FeaturesPanel.Designer.cs index 5f1df7a..cc595a9 100644 --- a/RayTracerApp/Panels/FeaturesPanel.Designer.cs +++ b/RayTracerApp/Panels/FeaturesPanel.Designer.cs @@ -44,13 +44,13 @@ private void InitializeComponent() // this.filePanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.filePanel.Controls.Add(this.aspectPanel); this.filePanel.Controls.Add(this.fromFileLabel); this.filePanel.Controls.Add(this.customModelButton); this.filePanel.Location = new System.Drawing.Point(0, 0); this.filePanel.Name = "filePanel"; - this.filePanel.Size = new System.Drawing.Size(393, 165); + this.filePanel.Size = new System.Drawing.Size(393, 70); this.filePanel.TabIndex = 0; + this.filePanel.Visible = false; // // fromFileLabel // @@ -78,15 +78,16 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Right))); this.aspectPanel.Controls.Add(this.aspectLabel); this.aspectPanel.Controls.Add(this.aspectRatioUpDown); - this.aspectPanel.Location = new System.Drawing.Point(0, 0); + this.aspectPanel.Location = new System.Drawing.Point(0, 76); this.aspectPanel.Name = "aspectPanel"; - this.aspectPanel.Size = new System.Drawing.Size(393, 153); + this.aspectPanel.Size = new System.Drawing.Size(393, 32); this.aspectPanel.TabIndex = 0; + this.aspectPanel.Visible = false; // // aspectLabel // this.aspectLabel.AutoSize = true; - this.aspectLabel.Location = new System.Drawing.Point(42, 68); + this.aspectLabel.Location = new System.Drawing.Point(42, 2); this.aspectLabel.Name = "aspectLabel"; this.aspectLabel.Size = new System.Drawing.Size(46, 15); this.aspectLabel.TabIndex = 1; @@ -101,7 +102,7 @@ private void InitializeComponent() 0, 0, 65536}); - this.aspectRatioUpDown.Location = new System.Drawing.Point(302, 66); + this.aspectRatioUpDown.Location = new System.Drawing.Point(302, 0); this.aspectRatioUpDown.Minimum = new decimal(new int[] { 1, 0, @@ -121,6 +122,7 @@ private void InitializeComponent() // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.aspectPanel); this.Controls.Add(this.filePanel); this.Name = "FeaturesPanel"; this.Size = new System.Drawing.Size(393, 410); diff --git a/RayTracerApp/Panels/MaterialPanel.Designer.cs b/RayTracerApp/Panels/MaterialPanel.Designer.cs index 5bb9aab..b51fa3e 100644 --- a/RayTracerApp/Panels/MaterialPanel.Designer.cs +++ b/RayTracerApp/Panels/MaterialPanel.Designer.cs @@ -75,6 +75,8 @@ private void InitializeComponent() this.label6 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.colorDialog = new System.Windows.Forms.ColorDialog(); + this.label4 = new System.Windows.Forms.Label(); + this.ampUpDown = new System.Windows.Forms.NumericUpDown(); this.tableLayoutPanel1.SuspendLayout(); this.tableLayoutPanel12.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.refractiveIndexUpDown)).BeginInit(); @@ -94,6 +96,7 @@ private void InitializeComponent() this.tableLayoutPanel4.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.diffuseShareUpDown)).BeginInit(); this.tableLayoutPanel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.ampUpDown)).BeginInit(); this.SuspendLayout(); // // tableLayoutPanel1 @@ -120,10 +123,10 @@ private void InitializeComponent() this.tableLayoutPanel1.Location = new System.Drawing.Point(11, 9); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 4; - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 30F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 18.18182F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 27.27273F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 27.27273F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 27.27273F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(490, 549); this.tableLayoutPanel1.TabIndex = 0; this.tableLayoutPanel1.CellPaint += new System.Windows.Forms.TableLayoutCellPaintEventHandler(this.tableLayoutPanel1_CellPaint); @@ -138,13 +141,13 @@ private void InitializeComponent() this.tableLayoutPanel12.Controls.Add(this.refractiveIndexUpDown, 0, 2); this.tableLayoutPanel12.Controls.Add(this.tableLayoutPanel13, 0, 0); this.tableLayoutPanel12.Controls.Add(this.refractiveShareUpDown, 0, 1); - this.tableLayoutPanel12.Location = new System.Drawing.Point(247, 385); + this.tableLayoutPanel12.Location = new System.Drawing.Point(247, 400); this.tableLayoutPanel12.Name = "tableLayoutPanel12"; this.tableLayoutPanel12.RowCount = 3; this.tableLayoutPanel12.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); this.tableLayoutPanel12.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); this.tableLayoutPanel12.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); - this.tableLayoutPanel12.Size = new System.Drawing.Size(240, 161); + this.tableLayoutPanel12.Size = new System.Drawing.Size(240, 146); this.tableLayoutPanel12.TabIndex = 11; // // refractiveIndexUpDown @@ -156,7 +159,7 @@ private void InitializeComponent() 0, 0, 131072}); - this.refractiveIndexUpDown.Location = new System.Drawing.Point(3, 122); + this.refractiveIndexUpDown.Location = new System.Drawing.Point(3, 109); this.refractiveIndexUpDown.Maximum = new decimal(new int[] { 10, 0, @@ -194,14 +197,14 @@ private void InitializeComponent() this.tableLayoutPanel13.Name = "tableLayoutPanel13"; this.tableLayoutPanel13.RowCount = 1; this.tableLayoutPanel13.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel13.Size = new System.Drawing.Size(234, 47); + this.tableLayoutPanel13.Size = new System.Drawing.Size(234, 42); this.tableLayoutPanel13.TabIndex = 0; // // refractiveTexture // this.refractiveTexture.Anchor = System.Windows.Forms.AnchorStyles.None; this.refractiveTexture.AutoSize = true; - this.refractiveTexture.Location = new System.Drawing.Point(14, 16); + this.refractiveTexture.Location = new System.Drawing.Point(14, 13); this.refractiveTexture.Name = "refractiveTexture"; this.refractiveTexture.Size = new System.Drawing.Size(49, 15); this.refractiveTexture.TabIndex = 0; @@ -211,7 +214,7 @@ private void InitializeComponent() // refractiveColor // this.refractiveColor.Anchor = System.Windows.Forms.AnchorStyles.None; - this.refractiveColor.Location = new System.Drawing.Point(81, 12); + this.refractiveColor.Location = new System.Drawing.Point(81, 9); this.refractiveColor.Name = "refractiveColor"; this.refractiveColor.Size = new System.Drawing.Size(71, 23); this.refractiveColor.TabIndex = 1; @@ -222,7 +225,7 @@ private void InitializeComponent() // refractiveFile // this.refractiveFile.Anchor = System.Windows.Forms.AnchorStyles.None; - this.refractiveFile.Location = new System.Drawing.Point(159, 12); + this.refractiveFile.Location = new System.Drawing.Point(159, 9); this.refractiveFile.Name = "refractiveFile"; this.refractiveFile.Size = new System.Drawing.Size(72, 23); this.refractiveFile.TabIndex = 2; @@ -239,7 +242,7 @@ private void InitializeComponent() 0, 0, 131072}); - this.refractiveShareUpDown.Location = new System.Drawing.Point(3, 68); + this.refractiveShareUpDown.Location = new System.Drawing.Point(3, 60); this.refractiveShareUpDown.Maximum = new decimal(new int[] { 1, 0, @@ -261,20 +264,20 @@ private void InitializeComponent() this.tableLayoutPanel11.Controls.Add(this.label15, 0, 2); this.tableLayoutPanel11.Controls.Add(this.label16, 0, 1); this.tableLayoutPanel11.Controls.Add(this.label17, 0, 0); - this.tableLayoutPanel11.Location = new System.Drawing.Point(125, 385); + this.tableLayoutPanel11.Location = new System.Drawing.Point(125, 400); this.tableLayoutPanel11.Name = "tableLayoutPanel11"; this.tableLayoutPanel11.RowCount = 3; this.tableLayoutPanel11.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); this.tableLayoutPanel11.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); this.tableLayoutPanel11.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); - this.tableLayoutPanel11.Size = new System.Drawing.Size(116, 161); + this.tableLayoutPanel11.Size = new System.Drawing.Size(116, 146); this.tableLayoutPanel11.TabIndex = 10; // // label15 // this.label15.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label15.AutoSize = true; - this.label15.Location = new System.Drawing.Point(3, 126); + this.label15.Location = new System.Drawing.Point(3, 113); this.label15.Name = "label15"; this.label15.Size = new System.Drawing.Size(110, 15); this.label15.TabIndex = 3; @@ -285,7 +288,7 @@ private void InitializeComponent() // this.label16.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label16.AutoSize = true; - this.label16.Location = new System.Drawing.Point(3, 72); + this.label16.Location = new System.Drawing.Point(3, 64); this.label16.Name = "label16"; this.label16.Size = new System.Drawing.Size(110, 15); this.label16.TabIndex = 2; @@ -296,7 +299,7 @@ private void InitializeComponent() // this.label17.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label17.AutoSize = true; - this.label17.Location = new System.Drawing.Point(3, 19); + this.label17.Location = new System.Drawing.Point(3, 16); this.label17.Name = "label17"; this.label17.Size = new System.Drawing.Size(110, 15); this.label17.TabIndex = 1; @@ -313,13 +316,13 @@ private void InitializeComponent() this.tableLayoutPanel9.Controls.Add(this.reflectiveDisturbanceUpDown, 0, 2); this.tableLayoutPanel9.Controls.Add(this.tableLayoutPanel10, 0, 0); this.tableLayoutPanel9.Controls.Add(this.reflectiveShareUpDown, 0, 1); - this.tableLayoutPanel9.Location = new System.Drawing.Point(247, 221); + this.tableLayoutPanel9.Location = new System.Drawing.Point(247, 251); this.tableLayoutPanel9.Name = "tableLayoutPanel9"; this.tableLayoutPanel9.RowCount = 3; this.tableLayoutPanel9.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); this.tableLayoutPanel9.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); this.tableLayoutPanel9.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); - this.tableLayoutPanel9.Size = new System.Drawing.Size(240, 158); + this.tableLayoutPanel9.Size = new System.Drawing.Size(240, 143); this.tableLayoutPanel9.TabIndex = 9; // // reflectiveDisturbanceUpDown @@ -331,7 +334,7 @@ private void InitializeComponent() 0, 0, 131072}); - this.reflectiveDisturbanceUpDown.Location = new System.Drawing.Point(3, 119); + this.reflectiveDisturbanceUpDown.Location = new System.Drawing.Point(3, 107); this.reflectiveDisturbanceUpDown.Maximum = new decimal(new int[] { 1, 0, @@ -364,14 +367,14 @@ private void InitializeComponent() this.tableLayoutPanel10.Name = "tableLayoutPanel10"; this.tableLayoutPanel10.RowCount = 1; this.tableLayoutPanel10.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel10.Size = new System.Drawing.Size(234, 46); + this.tableLayoutPanel10.Size = new System.Drawing.Size(234, 41); this.tableLayoutPanel10.TabIndex = 0; // // reflectiveTexture // this.reflectiveTexture.Anchor = System.Windows.Forms.AnchorStyles.None; this.reflectiveTexture.AutoSize = true; - this.reflectiveTexture.Location = new System.Drawing.Point(14, 15); + this.reflectiveTexture.Location = new System.Drawing.Point(14, 13); this.reflectiveTexture.Name = "reflectiveTexture"; this.reflectiveTexture.Size = new System.Drawing.Size(49, 15); this.reflectiveTexture.TabIndex = 0; @@ -381,7 +384,7 @@ private void InitializeComponent() // reflectiveColor // this.reflectiveColor.Anchor = System.Windows.Forms.AnchorStyles.None; - this.reflectiveColor.Location = new System.Drawing.Point(81, 11); + this.reflectiveColor.Location = new System.Drawing.Point(81, 9); this.reflectiveColor.Name = "reflectiveColor"; this.reflectiveColor.Size = new System.Drawing.Size(71, 23); this.reflectiveColor.TabIndex = 1; @@ -392,7 +395,7 @@ private void InitializeComponent() // reflectiveFile // this.reflectiveFile.Anchor = System.Windows.Forms.AnchorStyles.None; - this.reflectiveFile.Location = new System.Drawing.Point(159, 11); + this.reflectiveFile.Location = new System.Drawing.Point(159, 9); this.reflectiveFile.Name = "reflectiveFile"; this.reflectiveFile.Size = new System.Drawing.Size(72, 23); this.reflectiveFile.TabIndex = 2; @@ -409,7 +412,7 @@ private void InitializeComponent() 0, 0, 131072}); - this.reflectiveShareUpDown.Location = new System.Drawing.Point(3, 66); + this.reflectiveShareUpDown.Location = new System.Drawing.Point(3, 59); this.reflectiveShareUpDown.Maximum = new decimal(new int[] { 1, 0, @@ -431,20 +434,20 @@ private void InitializeComponent() this.tableLayoutPanel8.Controls.Add(this.label14, 0, 2); this.tableLayoutPanel8.Controls.Add(this.label11, 0, 1); this.tableLayoutPanel8.Controls.Add(this.label12, 0, 0); - this.tableLayoutPanel8.Location = new System.Drawing.Point(125, 221); + this.tableLayoutPanel8.Location = new System.Drawing.Point(125, 251); this.tableLayoutPanel8.Name = "tableLayoutPanel8"; this.tableLayoutPanel8.RowCount = 3; this.tableLayoutPanel8.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); this.tableLayoutPanel8.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); this.tableLayoutPanel8.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); - this.tableLayoutPanel8.Size = new System.Drawing.Size(116, 158); + this.tableLayoutPanel8.Size = new System.Drawing.Size(116, 143); this.tableLayoutPanel8.TabIndex = 8; // // label14 // this.label14.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label14.AutoSize = true; - this.label14.Location = new System.Drawing.Point(3, 123); + this.label14.Location = new System.Drawing.Point(3, 111); this.label14.Name = "label14"; this.label14.Size = new System.Drawing.Size(110, 15); this.label14.TabIndex = 3; @@ -455,7 +458,7 @@ private void InitializeComponent() // this.label11.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label11.AutoSize = true; - this.label11.Location = new System.Drawing.Point(3, 70); + this.label11.Location = new System.Drawing.Point(3, 63); this.label11.Name = "label11"; this.label11.Size = new System.Drawing.Size(110, 15); this.label11.TabIndex = 2; @@ -466,7 +469,7 @@ private void InitializeComponent() // this.label12.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label12.AutoSize = true; - this.label12.Location = new System.Drawing.Point(3, 18); + this.label12.Location = new System.Drawing.Point(3, 16); this.label12.Name = "label12"; this.label12.Size = new System.Drawing.Size(110, 15); this.label12.TabIndex = 1; @@ -480,15 +483,16 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Right))); this.tableLayoutPanel6.ColumnCount = 1; this.tableLayoutPanel6.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel6.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel6.Controls.Add(this.ampUpDown, 0, 2); this.tableLayoutPanel6.Controls.Add(this.tableLayoutPanel7, 0, 0); this.tableLayoutPanel6.Controls.Add(this.emissiveShareUpDown, 0, 1); - this.tableLayoutPanel6.Location = new System.Drawing.Point(247, 112); + this.tableLayoutPanel6.Location = new System.Drawing.Point(247, 102); this.tableLayoutPanel6.Name = "tableLayoutPanel6"; - this.tableLayoutPanel6.RowCount = 2; - this.tableLayoutPanel6.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel6.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel6.Size = new System.Drawing.Size(240, 103); + this.tableLayoutPanel6.RowCount = 3; + this.tableLayoutPanel6.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel6.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel6.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel6.Size = new System.Drawing.Size(240, 143); this.tableLayoutPanel6.TabIndex = 7; // // tableLayoutPanel7 @@ -507,14 +511,14 @@ private void InitializeComponent() this.tableLayoutPanel7.Name = "tableLayoutPanel7"; this.tableLayoutPanel7.RowCount = 1; this.tableLayoutPanel7.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel7.Size = new System.Drawing.Size(234, 45); + this.tableLayoutPanel7.Size = new System.Drawing.Size(234, 41); this.tableLayoutPanel7.TabIndex = 0; // // emissiveTexture // this.emissiveTexture.Anchor = System.Windows.Forms.AnchorStyles.None; this.emissiveTexture.AutoSize = true; - this.emissiveTexture.Location = new System.Drawing.Point(14, 15); + this.emissiveTexture.Location = new System.Drawing.Point(14, 13); this.emissiveTexture.Name = "emissiveTexture"; this.emissiveTexture.Size = new System.Drawing.Size(49, 15); this.emissiveTexture.TabIndex = 0; @@ -524,7 +528,7 @@ private void InitializeComponent() // emissiveColor // this.emissiveColor.Anchor = System.Windows.Forms.AnchorStyles.None; - this.emissiveColor.Location = new System.Drawing.Point(81, 11); + this.emissiveColor.Location = new System.Drawing.Point(81, 9); this.emissiveColor.Name = "emissiveColor"; this.emissiveColor.Size = new System.Drawing.Size(71, 23); this.emissiveColor.TabIndex = 1; @@ -535,7 +539,7 @@ private void InitializeComponent() // emissiveFile // this.emissiveFile.Anchor = System.Windows.Forms.AnchorStyles.None; - this.emissiveFile.Location = new System.Drawing.Point(159, 11); + this.emissiveFile.Location = new System.Drawing.Point(159, 9); this.emissiveFile.Name = "emissiveFile"; this.emissiveFile.Size = new System.Drawing.Size(72, 23); this.emissiveFile.TabIndex = 2; @@ -552,7 +556,7 @@ private void InitializeComponent() 0, 0, 131072}); - this.emissiveShareUpDown.Location = new System.Drawing.Point(3, 65); + this.emissiveShareUpDown.Location = new System.Drawing.Point(3, 59); this.emissiveShareUpDown.Maximum = new decimal(new int[] { 1, 0, @@ -571,23 +575,23 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Right))); this.tableLayoutPanel5.ColumnCount = 1; this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel5.Controls.Add(this.label4, 0, 2); this.tableLayoutPanel5.Controls.Add(this.label8, 0, 1); this.tableLayoutPanel5.Controls.Add(this.label9, 0, 0); - this.tableLayoutPanel5.Location = new System.Drawing.Point(125, 112); + this.tableLayoutPanel5.Location = new System.Drawing.Point(125, 102); this.tableLayoutPanel5.Name = "tableLayoutPanel5"; - this.tableLayoutPanel5.RowCount = 2; - this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); - this.tableLayoutPanel5.Size = new System.Drawing.Size(116, 103); + this.tableLayoutPanel5.RowCount = 3; + this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel5.Size = new System.Drawing.Size(116, 143); this.tableLayoutPanel5.TabIndex = 6; // // label8 // this.label8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(3, 69); + this.label8.Location = new System.Drawing.Point(3, 63); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(110, 15); this.label8.TabIndex = 2; @@ -598,7 +602,7 @@ private void InitializeComponent() // this.label9.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label9.AutoSize = true; - this.label9.Location = new System.Drawing.Point(3, 18); + this.label9.Location = new System.Drawing.Point(3, 16); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(110, 15); this.label9.TabIndex = 1; @@ -620,7 +624,7 @@ private void InitializeComponent() this.tableLayoutPanel3.RowCount = 2; this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel3.Size = new System.Drawing.Size(240, 103); + this.tableLayoutPanel3.Size = new System.Drawing.Size(240, 93); this.tableLayoutPanel3.TabIndex = 2; // // tableLayoutPanel4 @@ -639,14 +643,14 @@ private void InitializeComponent() this.tableLayoutPanel4.Name = "tableLayoutPanel4"; this.tableLayoutPanel4.RowCount = 1; this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel4.Size = new System.Drawing.Size(234, 45); + this.tableLayoutPanel4.Size = new System.Drawing.Size(234, 40); this.tableLayoutPanel4.TabIndex = 0; // // diffuseTexture // this.diffuseTexture.Anchor = System.Windows.Forms.AnchorStyles.None; this.diffuseTexture.AutoSize = true; - this.diffuseTexture.Location = new System.Drawing.Point(14, 15); + this.diffuseTexture.Location = new System.Drawing.Point(14, 12); this.diffuseTexture.Name = "diffuseTexture"; this.diffuseTexture.Size = new System.Drawing.Size(49, 15); this.diffuseTexture.TabIndex = 0; @@ -656,7 +660,7 @@ private void InitializeComponent() // diffuseColor // this.diffuseColor.Anchor = System.Windows.Forms.AnchorStyles.None; - this.diffuseColor.Location = new System.Drawing.Point(81, 11); + this.diffuseColor.Location = new System.Drawing.Point(81, 8); this.diffuseColor.Name = "diffuseColor"; this.diffuseColor.Size = new System.Drawing.Size(71, 23); this.diffuseColor.TabIndex = 1; @@ -667,7 +671,7 @@ private void InitializeComponent() // diffuseFile // this.diffuseFile.Anchor = System.Windows.Forms.AnchorStyles.None; - this.diffuseFile.Location = new System.Drawing.Point(159, 11); + this.diffuseFile.Location = new System.Drawing.Point(159, 8); this.diffuseFile.Name = "diffuseFile"; this.diffuseFile.Size = new System.Drawing.Size(72, 23); this.diffuseFile.TabIndex = 2; @@ -684,7 +688,7 @@ private void InitializeComponent() 0, 0, 131072}); - this.diffuseShareUpDown.Location = new System.Drawing.Point(3, 65); + this.diffuseShareUpDown.Location = new System.Drawing.Point(3, 58); this.diffuseShareUpDown.Maximum = new decimal(new int[] { 1, 0, @@ -700,7 +704,7 @@ private void InitializeComponent() // this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(3, 47); + this.label1.Location = new System.Drawing.Point(3, 42); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(116, 15); this.label1.TabIndex = 0; @@ -722,14 +726,14 @@ private void InitializeComponent() this.tableLayoutPanel2.RowCount = 2; this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel2.Size = new System.Drawing.Size(116, 103); + this.tableLayoutPanel2.Size = new System.Drawing.Size(116, 93); this.tableLayoutPanel2.TabIndex = 1; // // label3 // this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(3, 69); + this.label3.Location = new System.Drawing.Point(3, 62); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(110, 15); this.label3.TabIndex = 2; @@ -740,7 +744,7 @@ private void InitializeComponent() // this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(3, 18); + this.label2.Location = new System.Drawing.Point(3, 15); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(110, 15); this.label2.TabIndex = 1; @@ -751,7 +755,7 @@ private void InitializeComponent() // this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(3, 156); + this.label5.Location = new System.Drawing.Point(3, 166); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(116, 15); this.label5.TabIndex = 3; @@ -762,7 +766,7 @@ private void InitializeComponent() // this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(3, 292); + this.label6.Location = new System.Drawing.Point(3, 315); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(116, 15); this.label6.TabIndex = 4; @@ -773,13 +777,40 @@ private void InitializeComponent() // this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(3, 458); + this.label7.Location = new System.Drawing.Point(3, 465); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(116, 15); this.label7.TabIndex = 5; this.label7.Text = "Refractive"; this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // + // label4 + // + this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(3, 111); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(110, 15); + this.label4.TabIndex = 3; + this.label4.Text = "Amplification"; + this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // ampUpDown + // + this.ampUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.ampUpDown.DecimalPlaces = 2; + this.ampUpDown.Location = new System.Drawing.Point(3, 107); + this.ampUpDown.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.ampUpDown.Name = "ampUpDown"; + this.ampUpDown.Size = new System.Drawing.Size(234, 23); + this.ampUpDown.TabIndex = 2; + this.ampUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.ampUpDown.ValueChanged += new System.EventHandler(this.ampUpDown_ValueChanged); + // // MaterialPanel // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -815,6 +846,7 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.diffuseShareUpDown)).EndInit(); this.tableLayoutPanel2.ResumeLayout(false); this.tableLayoutPanel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.ampUpDown)).EndInit(); this.ResumeLayout(false); } @@ -867,5 +899,7 @@ private void InitializeComponent() private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label7; private System.Windows.Forms.ColorDialog colorDialog; + private System.Windows.Forms.NumericUpDown ampUpDown; + private System.Windows.Forms.Label label4; } } diff --git a/RayTracerApp/Panels/MaterialPanel.cs b/RayTracerApp/Panels/MaterialPanel.cs index b4c4a43..f9e5ee8 100644 --- a/RayTracerApp/Panels/MaterialPanel.cs +++ b/RayTracerApp/Panels/MaterialPanel.cs @@ -56,6 +56,7 @@ public void UpdateFromModel() reflectiveShareUpDown.Value = (decimal)material.Parts.reflective; refractiveShareUpDown.Value = (decimal)material.Parts.refractive; emissiveShareUpDown.Value = (decimal)material.Parts.emissive; + ampUpDown.Value = (decimal)material.Emissive.Amplification; } private string ChooseTexture() @@ -230,5 +231,13 @@ private void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEven ControlPaint.DrawBorder3D(e.Graphics, rectangle, Border3DStyle.Raised, Border3DSide.Bottom); } + + private void ampUpDown_ValueChanged(object sender, EventArgs e) + { + var nud = sender as NumericUpDown; + float val = (float)nud.Value; + + Controller.Material.Emissive.Amplification = val; + } } } From 789749a59248d22ada244f662aa3f6b93b026a96 Mon Sep 17 00:00:00 2001 From: p-flis Date: Thu, 7 Jan 2021 04:30:45 +0100 Subject: [PATCH 25/31] deleted redundant files --- .../ColorSlider/ColorSlider.Designer.cs | 42 - RayTracerApp/ColorSlider/ColorSlider.cs | 1071 ----------------- RayTracerApp/ColorSlider/ColorSlider.resx | 123 -- RayTracerApp/Forms/TestForm.Designer.cs | 99 -- RayTracerApp/Forms/TestForm.cs | 18 - RayTracerApp/Forms/TestForm.resx | 60 - 6 files changed, 1413 deletions(-) delete mode 100644 RayTracerApp/ColorSlider/ColorSlider.Designer.cs delete mode 100644 RayTracerApp/ColorSlider/ColorSlider.cs delete mode 100644 RayTracerApp/ColorSlider/ColorSlider.resx delete mode 100644 RayTracerApp/Forms/TestForm.Designer.cs delete mode 100644 RayTracerApp/Forms/TestForm.cs delete mode 100644 RayTracerApp/Forms/TestForm.resx diff --git a/RayTracerApp/ColorSlider/ColorSlider.Designer.cs b/RayTracerApp/ColorSlider/ColorSlider.Designer.cs deleted file mode 100644 index d91aaa1..0000000 --- a/RayTracerApp/ColorSlider/ColorSlider.Designer.cs +++ /dev/null @@ -1,42 +0,0 @@ -namespace RayTracerApp.Controls -{ - partial class ColorSlider - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Component Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.SuspendLayout(); - // - // ColorSlider - // - this.Size = new System.Drawing.Size(200, 30); - this.ResumeLayout(false); - - } - - #endregion - } -} diff --git a/RayTracerApp/ColorSlider/ColorSlider.cs b/RayTracerApp/ColorSlider/ColorSlider.cs deleted file mode 100644 index 6dda1e4..0000000 --- a/RayTracerApp/ColorSlider/ColorSlider.cs +++ /dev/null @@ -1,1071 +0,0 @@ -using System; -using System.ComponentModel; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Windows.Forms; - -namespace RayTracerApp.Controls -{ - /// - /// Encapsulates control that visualy displays certain integer value and allows user to change it within desired range. It imitates as far as mouse usage is concerned. - /// - [ToolboxBitmap(typeof(TrackBar))] - [DefaultEvent("Scroll"), DefaultProperty("BarInnerColor")] - public partial class ColorSlider : UserControl - { - #region Events - - /// - /// Fires when Slider position has changed - /// - [Description("Event fires when the Value property changes")] - [Category("Action")] - public event EventHandler ValueChanged; - - /// - /// Fires when user scrolls the Slider - /// - [Description("Event fires when the Slider position is changed")] - [Category("Behavior")] - public event ScrollEventHandler Scroll; - - #endregion - - #region Properties - - private Rectangle thumbRect; //bounding rectangle of thumb area - /// - /// Gets the thumb rect. Usefull to determine bounding rectangle when creating custom thumb shape. - /// - /// The thumb rect. - [Browsable(false)] - public Rectangle ThumbRect - { - get { return thumbRect; } - } - - private Rectangle barRect; //bounding rectangle of bar area - private Rectangle barHalfRect; - private Rectangle thumbHalfRect; - private Rectangle elapsedRect; //bounding rectangle of elapsed area - - private int thumbSize = 15; - /// - /// Gets or sets the size of the thumb. - /// - /// The size of the thumb. - /// exception thrown when value is lower than zero or grather than half of appropiate dimension - [Description("Set Slider thumb size")] - [Category("ColorSlider")] - [DefaultValue(15)] - public int ThumbSize - { - get { return thumbSize; } - set - { - if (value > 0 & - value < (barOrientation == Orientation.Horizontal ? ClientRectangle.Width : ClientRectangle.Height)) - thumbSize = value; - else - throw new ArgumentOutOfRangeException( - "TrackSize has to be greather than zero and lower than half of Slider width"); - Invalidate(); - } - } - - private GraphicsPath thumbCustomShape = null; - /// - /// Gets or sets the thumb custom shape. Use ThumbRect property to determine bounding rectangle. - /// - /// The thumb custom shape. null means default shape - [Description("Set Slider's thumb's custom shape")] - [Category("ColorSlider")] - [Browsable(false)] - [DefaultValue(typeof(GraphicsPath), "null")] - public GraphicsPath ThumbCustomShape - { - get { return thumbCustomShape; } - set - { - thumbCustomShape = value; - thumbSize = (int) (barOrientation == Orientation.Horizontal ? value.GetBounds().Width : value.GetBounds().Height) + 1; - Invalidate(); - } - } - - private Size thumbRoundRectSize = new Size(8, 8); - /// - /// Gets or sets the size of the thumb round rectangle edges. - /// - /// The size of the thumb round rectangle edges. - [Description("Set Slider's thumb round rect size")] - [Category("ColorSlider")] - [DefaultValue(typeof(Size), "8; 8")] - public Size ThumbRoundRectSize - { - get { return thumbRoundRectSize; } - set - { - int h = value.Height, w = value.Width; - if (h <= 0) h = 1; - if (w <= 0) w = 1; - thumbRoundRectSize = new Size(w, h); - Invalidate(); - } - } - - private Size borderRoundRectSize = new Size(8, 8); - /// - /// Gets or sets the size of the border round rect. - /// - /// The size of the border round rect. - [Description("Set Slider's border round rect size")] - [Category("ColorSlider")] - [DefaultValue(typeof(Size), "8; 8")] - public Size BorderRoundRectSize - { - get { return borderRoundRectSize; } - set - { - int h = value.Height, w = value.Width; - if (h <= 0) h = 1; - if (w <= 0) w = 1; - borderRoundRectSize = new Size(w, h); - Invalidate(); - } - } - - private Orientation barOrientation = Orientation.Horizontal; - /// - /// Gets or sets the orientation of Slider. - /// - /// The orientation. - [Description("Set Slider orientation")] - [Category("ColorSlider")] - [DefaultValue(Orientation.Horizontal)] - public Orientation Orientation - { - get { return barOrientation; } - set - { - if (barOrientation != value) - { - barOrientation = value; - int temp = Width; - Width = Height; - Height = temp; - if (thumbCustomShape != null) - thumbSize = - (int) - (barOrientation == Orientation.Horizontal - ? thumbCustomShape.GetBounds().Width - : thumbCustomShape.GetBounds().Height) + 1; - Invalidate(); - } - } - } - - - private int trackerValue = 50; - /// - /// Gets or sets the value of Slider. - /// - /// The value. - /// exception thrown when value is outside appropriate range (min, max) - [Description("Set Slider value")] - [Category("ColorSlider")] - [DefaultValue(50)] - public int Value - { - get { return trackerValue; } - set - { - if (value >= barMinimum & value <= barMaximum) - { - trackerValue = value; - if (ValueChanged != null) ValueChanged(this, new EventArgs()); - Invalidate(); - } - else throw new ArgumentOutOfRangeException("Value is outside appropriate range (min, max)"); - } - } - - - private int barMinimum = 0; - /// - /// Gets or sets the minimum value. - /// - /// The minimum value. - /// exception thrown when minimal value is greather than maximal one - [Description("Set Slider minimal point")] - [Category("ColorSlider")] - [DefaultValue(0)] - public int Minimum - { - get { return barMinimum; } - set - { - if (value < barMaximum) - { - barMinimum = value; - if (trackerValue < barMinimum) - { - trackerValue = barMinimum; - if (ValueChanged != null) ValueChanged(this, new EventArgs()); - } - Invalidate(); - } - else throw new ArgumentOutOfRangeException("Minimal value is greather than maximal one"); - } - } - - - private int barMaximum = 100; - /// - /// Gets or sets the maximum value. - /// - /// The maximum value. - /// exception thrown when maximal value is lower than minimal one - [Description("Set Slider maximal point")] - [Category("ColorSlider")] - [DefaultValue(100)] - public int Maximum - { - get { return barMaximum; } - set - { - if (value > barMinimum) - { - barMaximum = value; - if (trackerValue > barMaximum) - { - trackerValue = barMaximum; - if (ValueChanged != null) ValueChanged(this, new EventArgs()); - } - Invalidate(); - } - else throw new ArgumentOutOfRangeException("Maximal value is lower than minimal one"); - } - } - - private uint smallChange = 1; - /// - /// Gets or sets trackbar's small change. It affects how to behave when directional keys are pressed - /// - /// The small change value. - [Description("Set trackbar's small change")] - [Category("ColorSlider")] - [DefaultValue(1)] - public uint SmallChange - { - get { return smallChange; } - set { smallChange = value; } - } - - private uint largeChange = 5; - - /// - /// Gets or sets trackbar's large change. It affects how to behave when PageUp/PageDown keys are pressed - /// - /// The large change value. - [Description("Set trackbar's large change")] - [Category("ColorSlider")] - [DefaultValue(5)] - public uint LargeChange - { - get { return largeChange; } - set { largeChange = value; } - } - - private bool drawFocusRectangle = true; - /// - /// Gets or sets a value indicating whether to draw focus rectangle. - /// - /// true if focus rectangle should be drawn; otherwise, false. - [Description("Set whether to draw focus rectangle")] - [Category("ColorSlider")] - [DefaultValue(true)] - public bool DrawFocusRectangle - { - get { return drawFocusRectangle; } - set - { - drawFocusRectangle = value; - Invalidate(); - } - } - - private bool drawSemitransparentThumb = true; - /// - /// Gets or sets a value indicating whether to draw semitransparent thumb. - /// - /// true if semitransparent thumb should be drawn; otherwise, false. - [Description("Set whether to draw semitransparent thumb")] - [Category("ColorSlider")] - [DefaultValue(true)] - public bool DrawSemitransparentThumb - { - get { return drawSemitransparentThumb; } - set - { - drawSemitransparentThumb = value; - Invalidate(); - } - } - - private bool mouseEffects = true; - /// - /// Gets or sets whether mouse entry and exit actions have impact on how control look. - /// - /// true if mouse entry and exit actions have impact on how control look; otherwise, false. - [Description("Set whether mouse entry and exit actions have impact on how control look")] - [Category("ColorSlider")] - [DefaultValue(true)] - public bool MouseEffects - { - get { return mouseEffects; } - set - { - mouseEffects = value; - Invalidate(); - } - } - - private int mouseWheelBarPartitions = 10; - /// - /// Gets or sets the mouse wheel bar partitions. - /// - /// The mouse wheel bar partitions. - /// exception thrown when value isn't greather than zero - [Description("Set to how many parts is bar divided when using mouse wheel")] - [Category("ColorSlider")] - [DefaultValue(10)] - public int MouseWheelBarPartitions - { - get { return mouseWheelBarPartitions; } - set - { - if (value > 0) - mouseWheelBarPartitions = value; - else throw new ArgumentOutOfRangeException("MouseWheelBarPartitions has to be greather than zero"); - } - } - - private Color thumbOuterColor = Color.White; - /// - /// Gets or sets the thumb outer color . - /// - /// The thumb outer color. - [Description("Set Slider thumb outer color")] - [Category("ColorSlider")] - [DefaultValue(typeof(Color), "White")] - public Color ThumbOuterColor - { - get { return thumbOuterColor; } - set - { - thumbOuterColor = value; - Invalidate(); - } - } - - - private Color thumbInnerColor = Color.Gainsboro; - /// - /// Gets or sets the inner color of the thumb. - /// - /// The inner color of the thumb. - [Description("Set Slider thumb inner color")] - [Category("ColorSlider")] - [DefaultValue(typeof(Color), "Gainsboro")] - public Color ThumbInnerColor - { - get { return thumbInnerColor; } - set - { - thumbInnerColor = value; - Invalidate(); - } - } - - - private Color thumbPenColor = Color.Silver; - /// - /// Gets or sets the color of the thumb pen. - /// - /// The color of the thumb pen. - [Description("Set Slider thumb pen color")] - [Category("ColorSlider")] - [DefaultValue(typeof(Color), "Silver")] - public Color ThumbPenColor - { - get { return thumbPenColor; } - set - { - thumbPenColor = value; - Invalidate(); - } - } - - - private Color barOuterColor = Color.SkyBlue; - /// - /// Gets or sets the outer color of the bar. - /// - /// The outer color of the bar. - [Description("Set Slider bar outer color")] - [Category("ColorSlider")] - [DefaultValue(typeof(Color), "SkyBlue")] - public Color BarOuterColor - { - get { return barOuterColor; } - set - { - barOuterColor = value; - Invalidate(); - } - } - - - private Color barInnerColor = Color.DarkSlateBlue; - /// - /// Gets or sets the inner color of the bar. - /// - /// The inner color of the bar. - [Description("Set Slider bar inner color")] - [Category("ColorSlider")] - [DefaultValue(typeof(Color), "DarkSlateBlue")] - public Color BarInnerColor - { - get { return barInnerColor; } - set - { - barInnerColor = value; - Invalidate(); - } - } - - - private Color barPenColor = Color.Gainsboro; - /// - /// Gets or sets the color of the bar pen. - /// - /// The color of the bar pen. - [Description("Set Slider bar pen color")] - [Category("ColorSlider")] - [DefaultValue(typeof(Color), "Gainsboro")] - public Color BarPenColor - { - get { return barPenColor; } - set - { - barPenColor = value; - Invalidate(); - } - } - - private Color elapsedOuterColor = Color.DarkGreen; - /// - /// Gets or sets the outer color of the elapsed. - /// - /// The outer color of the elapsed. - [Description("Set Slider's elapsed part outer color")] - [Category("ColorSlider")] - [DefaultValue(typeof(Color), "DarkGreen")] - public Color ElapsedOuterColor - { - get { return elapsedOuterColor; } - set - { - elapsedOuterColor = value; - Invalidate(); - } - } - - private Color elapsedInnerColor = Color.Chartreuse; - /// - /// Gets or sets the inner color of the elapsed. - /// - /// The inner color of the elapsed. - [Description("Set Slider's elapsed part inner color")] - [Category("ColorSlider")] - [DefaultValue(typeof(Color), "Chartreuse")] - public Color ElapsedInnerColor - { - get { return elapsedInnerColor; } - set - { - elapsedInnerColor = value; - Invalidate(); - } - } - - #endregion - - #region Color schemas - - //define own color schemas - private Color[,] aColorSchema = new Color[,] - { - { - Color.White, Color.Gainsboro, Color.Silver, Color.SkyBlue, Color.DarkSlateBlue, Color.Gainsboro, - Color.DarkGreen, Color.Chartreuse - }, - { - Color.White, Color.Gainsboro, Color.Silver, Color.Red, Color.DarkRed, Color.Gainsboro, Color.Coral, - Color.LightCoral - }, - { - Color.White, Color.Gainsboro, Color.Silver, Color.GreenYellow, Color.Yellow, Color.Gold, Color.Orange, - Color.OrangeRed - }, - { - Color.White, Color.Gainsboro, Color.Silver, Color.Red, Color.Crimson, Color.Gainsboro, Color.DarkViolet - , Color.Violet - } - }; - - public enum ColorSchemas - { - PerlBlueGreen, - PerlRedCoral, - PerlGold, - PerlRoyalColors - } - - private ColorSchemas colorSchema = ColorSchemas.PerlBlueGreen; - /// - /// Sets color schema. Color generalization / fast color changing. Has no effect when slider colors are changed manually after schema was applied. - /// - /// New color schema value - [Description("Set Slider color schema. Has no effect when slider colors are changed manually after schema was applied.")] - [Category("ColorSlider")] - [DefaultValue(typeof(ColorSchemas), "PerlBlueGreen")] - public ColorSchemas ColorSchema - { - get { return colorSchema; } - set - { - colorSchema = value; - byte sn = (byte)value; - thumbOuterColor = aColorSchema[sn, 0]; - thumbInnerColor = aColorSchema[sn, 1]; - thumbPenColor = aColorSchema[sn, 2]; - barOuterColor = aColorSchema[sn, 3]; - barInnerColor = aColorSchema[sn, 4]; - barPenColor = aColorSchema[sn, 5]; - elapsedOuterColor = aColorSchema[sn, 6]; - elapsedInnerColor = aColorSchema[sn, 7]; - - Invalidate(); - } - } - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The minimum value. - /// The maximum value. - /// The current value. - public ColorSlider(int min, int max, int value) - { - InitializeComponent(); - SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | - ControlStyles.ResizeRedraw | ControlStyles.Selectable | - ControlStyles.SupportsTransparentBackColor | ControlStyles.UserMouse | - ControlStyles.UserPaint, true); - BackColor = Color.Transparent; - - Minimum = min; - Maximum = max; - Value = value; - } - - /// - /// Initializes a new instance of the class. - /// - public ColorSlider() : this(0, 100, 50) { } - - #endregion - - #region Paint - - /// - /// Raises the event. - /// - /// A that contains the event data. - protected override void OnPaint(PaintEventArgs e) - { - if (!Enabled) - { - Color[] desaturatedColors = DesaturateColors(thumbOuterColor, thumbInnerColor, thumbPenColor, - barOuterColor, barInnerColor, barPenColor, - elapsedOuterColor, elapsedInnerColor); - DrawColorSlider(e, desaturatedColors[0], desaturatedColors[1], desaturatedColors[2], - desaturatedColors[3], - desaturatedColors[4], desaturatedColors[5], desaturatedColors[6], desaturatedColors[7]); - } - else - { - if (mouseEffects && mouseInRegion) - { - Color[] lightenedColors = LightenColors(thumbOuterColor, thumbInnerColor, thumbPenColor, - barOuterColor, barInnerColor, barPenColor, - elapsedOuterColor, elapsedInnerColor); - DrawColorSlider(e, lightenedColors[0], lightenedColors[1], lightenedColors[2], lightenedColors[3], - lightenedColors[4], lightenedColors[5], lightenedColors[6], lightenedColors[7]); - } - else - { - DrawColorSlider(e, thumbOuterColor, thumbInnerColor, thumbPenColor, - barOuterColor, barInnerColor, barPenColor, - elapsedOuterColor, elapsedInnerColor); - } - } - } - - /// - /// Draws the colorslider control using passed colors. - /// - /// The instance containing the event data. - /// The thumb outer color paint. - /// The thumb inner color paint. - /// The thumb pen color paint. - /// The bar outer color paint. - /// The bar inner color paint. - /// The bar pen color paint. - /// The elapsed outer color paint. - /// The elapsed inner color paint. - private void DrawColorSlider(PaintEventArgs e, Color thumbOuterColorPaint, Color thumbInnerColorPaint, - Color thumbPenColorPaint, Color barOuterColorPaint, Color barInnerColorPaint, - Color barPenColorPaint, Color elapsedOuterColorPaint, Color elapsedInnerColorPaint) - { - try - { - //set up thumbRect aproprietly - if (barOrientation == Orientation.Horizontal) - { - int TrackX = (((trackerValue - barMinimum) * (ClientRectangle.Width - thumbSize)) / (barMaximum - barMinimum)); - thumbRect = new Rectangle(TrackX, 1, thumbSize - 1, ClientRectangle.Height - 3); - } - else - { - int TrackY = (((trackerValue - barMinimum) * (ClientRectangle.Height - thumbSize)) / (barMaximum - barMinimum)); - thumbRect = new Rectangle(1, TrackY, ClientRectangle.Width - 3, thumbSize - 1); - } - - //adjust drawing rects - barRect = ClientRectangle; - thumbHalfRect = thumbRect; - LinearGradientMode gradientOrientation; - if (barOrientation == Orientation.Horizontal) - { - barRect.Inflate(-1, -barRect.Height / 3); - barHalfRect = barRect; - barHalfRect.Height /= 2; - gradientOrientation = LinearGradientMode.Vertical; - thumbHalfRect.Height /= 2; - elapsedRect = barRect; - elapsedRect.Width = thumbRect.Left + thumbSize / 2; - } - else - { - barRect.Inflate(-barRect.Width / 3, -1); - barHalfRect = barRect; - barHalfRect.Width /= 2; - gradientOrientation = LinearGradientMode.Horizontal; - thumbHalfRect.Width /= 2; - elapsedRect = barRect; - elapsedRect.Height = thumbRect.Top + thumbSize / 2; - } - //get thumb shape path - GraphicsPath thumbPath; - if (thumbCustomShape == null) - thumbPath = CreateRoundRectPath(thumbRect, thumbRoundRectSize); - else - { - thumbPath = thumbCustomShape; - Matrix m = new Matrix(); - m.Translate(thumbRect.Left - thumbPath.GetBounds().Left, thumbRect.Top - thumbPath.GetBounds().Top); - thumbPath.Transform(m); - } - - //draw bar - using ( - LinearGradientBrush lgbBar = - new LinearGradientBrush(barHalfRect, barOuterColorPaint, barInnerColorPaint, gradientOrientation) - ) - { - lgbBar.WrapMode = WrapMode.TileFlipXY; - e.Graphics.FillRectangle(lgbBar, barRect); - //draw elapsed bar - using ( - LinearGradientBrush lgbElapsed = - new LinearGradientBrush(barHalfRect, elapsedOuterColorPaint, elapsedInnerColorPaint, - gradientOrientation)) - { - lgbElapsed.WrapMode = WrapMode.TileFlipXY; - if (Capture && drawSemitransparentThumb) - { - Region elapsedReg = new Region(elapsedRect); - elapsedReg.Exclude(thumbPath); - e.Graphics.FillRegion(lgbElapsed, elapsedReg); - } - else - e.Graphics.FillRectangle(lgbElapsed, elapsedRect); - } - //draw bar band - using (Pen barPen = new Pen(barPenColorPaint, 0.5f)) - { - e.Graphics.DrawRectangle(barPen, barRect); - } - } - - //draw thumb - Color newthumbOuterColorPaint = thumbOuterColorPaint, newthumbInnerColorPaint = thumbInnerColorPaint; - if (Capture && drawSemitransparentThumb) - { - newthumbOuterColorPaint = Color.FromArgb(175, thumbOuterColorPaint); - newthumbInnerColorPaint = Color.FromArgb(175, thumbInnerColorPaint); - } - using ( - LinearGradientBrush lgbThumb = - new LinearGradientBrush(thumbHalfRect, newthumbOuterColorPaint, newthumbInnerColorPaint, - gradientOrientation)) - { - lgbThumb.WrapMode = WrapMode.TileFlipXY; - e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; - e.Graphics.FillPath(lgbThumb, thumbPath); - //draw thumb band - Color newThumbPenColor = thumbPenColorPaint; - if (mouseEffects && (Capture || mouseInThumbRegion)) - newThumbPenColor = ControlPaint.Dark(newThumbPenColor); - using (Pen thumbPen = new Pen(newThumbPenColor)) - { - e.Graphics.DrawPath(thumbPen, thumbPath); - } - //gp.Dispose(); - /*if (Capture || mouseInThumbRegion) - using (LinearGradientBrush lgbThumb2 = new LinearGradientBrush(thumbHalfRect, Color.FromArgb(150, Color.Blue), Color.Transparent, gradientOrientation)) - { - lgbThumb2.WrapMode = WrapMode.TileFlipXY; - e.Graphics.FillPath(lgbThumb2, gp); - }*/ - } - - //draw focusing rectangle - if (Focused & drawFocusRectangle) - using (Pen p = new Pen(Color.FromArgb(200, barPenColorPaint))) - { - p.DashStyle = DashStyle.Dot; - Rectangle r = ClientRectangle; - r.Width -= 2; - r.Height--; - r.X++; - //ControlPaint.DrawFocusRectangle(e.Graphics, r); - using (GraphicsPath gpBorder = CreateRoundRectPath(r, borderRoundRectSize)) - { - e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; - e.Graphics.DrawPath(p, gpBorder); - } - } - } - catch (Exception Err) - { - Console.WriteLine("DrawBackGround Error in " + Name + ":" + Err.Message); - } - finally - { - } - } - - #endregion - - #region Overided events - - private bool mouseInRegion = false; - /// - /// Raises the event. - /// - /// An that contains the event data. - protected override void OnEnabledChanged(EventArgs e) - { - base.OnEnabledChanged(e); - Invalidate(); - } - - /// - /// Raises the event. - /// - /// An that contains the event data. - protected override void OnMouseEnter(EventArgs e) - { - base.OnMouseEnter(e); - mouseInRegion = true; - Invalidate(); - } - - /// - /// Raises the event. - /// - /// An that contains the event data. - protected override void OnMouseLeave(EventArgs e) - { - base.OnMouseLeave(e); - mouseInRegion = false; - mouseInThumbRegion = false; - Invalidate(); - } - - /// - /// Raises the event. - /// - /// A that contains the event data. - protected override void OnMouseDown(MouseEventArgs e) - { - base.OnMouseDown(e); - if (e.Button == MouseButtons.Left) - { - Capture = true; - if (Scroll != null) Scroll(this, new ScrollEventArgs(ScrollEventType.ThumbTrack, trackerValue)); - if (ValueChanged != null) ValueChanged(this, new EventArgs()); - OnMouseMove(e); - } - } - - private bool mouseInThumbRegion = false; - - /// - /// Raises the event. - /// - /// A that contains the event data. - protected override void OnMouseMove(MouseEventArgs e) - { - base.OnMouseMove(e); - mouseInThumbRegion = IsPointInRect(e.Location, thumbRect); - if (Capture & e.Button == MouseButtons.Left) - { - ScrollEventType set = ScrollEventType.ThumbPosition; - Point pt = e.Location; - int p = barOrientation == Orientation.Horizontal ? pt.X : pt.Y; - int margin = thumbSize >> 1; - p -= margin; - float coef = (float)(barMaximum - barMinimum) / - (float) - ((barOrientation == Orientation.Horizontal ? ClientSize.Width : ClientSize.Height) - - 2 * margin); - trackerValue = (int)(p * coef + barMinimum); - - if (trackerValue <= barMinimum) - { - trackerValue = barMinimum; - set = ScrollEventType.First; - } - else if (trackerValue >= barMaximum) - { - trackerValue = barMaximum; - set = ScrollEventType.Last; - } - - if (Scroll != null) Scroll(this, new ScrollEventArgs(set, trackerValue)); - if (ValueChanged != null) ValueChanged(this, new EventArgs()); - } - Invalidate(); - } - - /// - /// Raises the event. - /// - /// A that contains the event data. - protected override void OnMouseUp(MouseEventArgs e) - { - base.OnMouseUp(e); - Capture = false; - mouseInThumbRegion = IsPointInRect(e.Location, thumbRect); - if (Scroll != null) Scroll(this, new ScrollEventArgs(ScrollEventType.EndScroll, trackerValue)); - if (ValueChanged != null) ValueChanged(this, new EventArgs()); - Invalidate(); - } - - /// - /// Raises the event. - /// - /// A that contains the event data. - protected override void OnMouseWheel(MouseEventArgs e) - { - base.OnMouseWheel(e); - int v = e.Delta / 120 * (barMaximum - barMinimum) / mouseWheelBarPartitions; - SetProperValue(Value + v); - } - - /// - /// Raises the event. - /// - /// An that contains the event data. - protected override void OnGotFocus(EventArgs e) - { - base.OnGotFocus(e); - Invalidate(); - } - - /// - /// Raises the event. - /// - /// An that contains the event data. - protected override void OnLostFocus(EventArgs e) - { - base.OnLostFocus(e); - Invalidate(); - } - - /// - /// Raises the event. - /// - /// A that contains the event data. - protected override void OnKeyUp(KeyEventArgs e) - { - base.OnKeyUp(e); - switch (e.KeyCode) - { - case Keys.Down: - case Keys.Left: - SetProperValue(Value - (int)smallChange); - if (Scroll != null) Scroll(this, new ScrollEventArgs(ScrollEventType.SmallDecrement, Value)); - break; - case Keys.Up: - case Keys.Right: - SetProperValue(Value + (int)smallChange); - if (Scroll != null) Scroll(this, new ScrollEventArgs(ScrollEventType.SmallIncrement, Value)); - break; - case Keys.Home: - Value = barMinimum; - break; - case Keys.End: - Value = barMaximum; - break; - case Keys.PageDown: - SetProperValue(Value - (int)largeChange); - if (Scroll != null) Scroll(this, new ScrollEventArgs(ScrollEventType.LargeDecrement, Value)); - break; - case Keys.PageUp: - SetProperValue(Value + (int)largeChange); - if (Scroll != null) Scroll(this, new ScrollEventArgs(ScrollEventType.LargeIncrement, Value)); - break; - } - if (Scroll != null && Value == barMinimum) Scroll(this, new ScrollEventArgs(ScrollEventType.First, Value)); - if (Scroll != null && Value == barMaximum) Scroll(this, new ScrollEventArgs(ScrollEventType.Last, Value)); - Point pt = PointToClient(Cursor.Position); - OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, pt.X, pt.Y, 0)); - } - - /// - /// Processes a dialog key. - /// - /// One of the values that represents the key to process. - /// - /// true if the key was processed by the control; otherwise, false. - /// - protected override bool ProcessDialogKey(Keys keyData) - { - if (keyData == Keys.Tab | ModifierKeys == Keys.Shift) - return base.ProcessDialogKey(keyData); - else - { - OnKeyDown(new KeyEventArgs(keyData)); - return true; - } - } - - #endregion - - #region Help routines - - /// - /// Creates the round rect path. - /// - /// The rectangle on which graphics path will be spanned. - /// The size of rounded rectangle edges. - /// - public static GraphicsPath CreateRoundRectPath(Rectangle rect, Size size) - { - GraphicsPath gp = new GraphicsPath(); - gp.AddLine(rect.Left + size.Width / 2, rect.Top, rect.Right - size.Width / 2, rect.Top); - gp.AddArc(rect.Right - size.Width, rect.Top, size.Width, size.Height, 270, 90); - - gp.AddLine(rect.Right, rect.Top + size.Height / 2, rect.Right, rect.Bottom - size.Width / 2); - gp.AddArc(rect.Right - size.Width, rect.Bottom - size.Height, size.Width, size.Height, 0, 90); - - gp.AddLine(rect.Right - size.Width / 2, rect.Bottom, rect.Left + size.Width / 2, rect.Bottom); - gp.AddArc(rect.Left, rect.Bottom - size.Height, size.Width, size.Height, 90, 90); - - gp.AddLine(rect.Left, rect.Bottom - size.Height / 2, rect.Left, rect.Top + size.Height / 2); - gp.AddArc(rect.Left, rect.Top, size.Width, size.Height, 180, 90); - return gp; - } - - /// - /// Desaturates colors from given array. - /// - /// The colors to be desaturated. - /// - public static Color[] DesaturateColors(params Color[] colorsToDesaturate) - { - Color[] colorsToReturn = new Color[colorsToDesaturate.Length]; - for (int i = 0; i < colorsToDesaturate.Length; i++) - { - //use NTSC weighted avarage - int gray = - (int)(colorsToDesaturate[i].R * 0.3 + colorsToDesaturate[i].G * 0.6 + colorsToDesaturate[i].B * 0.1); - colorsToReturn[i] = Color.FromArgb(-0x010101 * (255 - gray) - 1); - } - return colorsToReturn; - } - - /// - /// Lightens colors from given array. - /// - /// The colors to lighten. - /// - public static Color[] LightenColors(params Color[] colorsToLighten) - { - Color[] colorsToReturn = new Color[colorsToLighten.Length]; - for (int i = 0; i < colorsToLighten.Length; i++) - { - colorsToReturn[i] = ControlPaint.Light(colorsToLighten[i]); - } - return colorsToReturn; - } - - /// - /// Sets the trackbar value so that it wont exceed allowed range. - /// - /// The value. - private void SetProperValue(int val) - { - if (val < barMinimum) Value = barMinimum; - else if (val > barMaximum) Value = barMaximum; - else Value = val; - } - - /// - /// Determines whether rectangle contains given point. - /// - /// The point to test. - /// The base rectangle. - /// - /// true if rectangle contains given point; otherwise, false. - /// - private static bool IsPointInRect(Point pt, Rectangle rect) - { - if (pt.X > rect.Left & pt.X < rect.Right & pt.Y > rect.Top & pt.Y < rect.Bottom) - return true; - else return false; - } - - #endregion - } -} \ No newline at end of file diff --git a/RayTracerApp/ColorSlider/ColorSlider.resx b/RayTracerApp/ColorSlider/ColorSlider.resx deleted file mode 100644 index 52a9ad3..0000000 --- a/RayTracerApp/ColorSlider/ColorSlider.resx +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - False - - \ No newline at end of file diff --git a/RayTracerApp/Forms/TestForm.Designer.cs b/RayTracerApp/Forms/TestForm.Designer.cs deleted file mode 100644 index afe2ce2..0000000 --- a/RayTracerApp/Forms/TestForm.Designer.cs +++ /dev/null @@ -1,99 +0,0 @@ - -namespace RayTracerApp.Forms -{ - partial class TestForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); - this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStrip1 = new System.Windows.Forms.ToolStrip(); - this.contextMenuStrip1.SuspendLayout(); - this.SuspendLayout(); - // - // contextMenuStrip1 - // - this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripMenuItem1, - this.toolStripMenuItem2, - this.toolStripMenuItem3}); - this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(181, 70); - // - // toolStripMenuItem1 - // - this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(180, 22); - this.toolStripMenuItem1.Text = "toolStripMenuItem1"; - // - // toolStripMenuItem2 - // - this.toolStripMenuItem2.Name = "toolStripMenuItem2"; - this.toolStripMenuItem2.Size = new System.Drawing.Size(180, 22); - this.toolStripMenuItem2.Text = "toolStripMenuItem2"; - // - // toolStripMenuItem3 - // - this.toolStripMenuItem3.Name = "toolStripMenuItem3"; - this.toolStripMenuItem3.Size = new System.Drawing.Size(180, 22); - this.toolStripMenuItem3.Text = "toolStripMenuItem3"; - // - // toolStrip1 - // - this.toolStrip1.Location = new System.Drawing.Point(0, 0); - this.toolStrip1.Name = "toolStrip1"; - this.toolStrip1.Size = new System.Drawing.Size(800, 25); - this.toolStrip1.TabIndex = 1; - this.toolStrip1.Text = "toolStrip1"; - // - // TestForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.ContextMenuStrip = this.contextMenuStrip1; - this.Controls.Add(this.toolStrip1); - this.Name = "TestForm"; - this.Text = "TestForm"; - this.contextMenuStrip1.ResumeLayout(false); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; - private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; - private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; - private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem3; - private System.Windows.Forms.ToolStrip toolStrip1; - } -} \ No newline at end of file diff --git a/RayTracerApp/Forms/TestForm.cs b/RayTracerApp/Forms/TestForm.cs deleted file mode 100644 index 2c67e1d..0000000 --- a/RayTracerApp/Forms/TestForm.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; - -namespace RayTracerApp.Forms -{ - public partial class TestForm : Form - { - public TestForm() - { - InitializeComponent(); - } - } -} diff --git a/RayTracerApp/Forms/TestForm.resx b/RayTracerApp/Forms/TestForm.resx deleted file mode 100644 index f298a7b..0000000 --- a/RayTracerApp/Forms/TestForm.resx +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file From d4bf2ffb85d60e2654f32767e5ef4bcd07d270cf Mon Sep 17 00:00:00 2001 From: p-flis Date: Thu, 7 Jan 2021 04:39:26 +0100 Subject: [PATCH 26/31] revert --- RayTracer/Source/Models/Mesh.cs | 10 ---------- RayTracer/Source/Models/ModelLoader.cs | 6 +----- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/RayTracer/Source/Models/Mesh.cs b/RayTracer/Source/Models/Mesh.cs index 012e458..2b30b07 100644 --- a/RayTracer/Source/Models/Mesh.cs +++ b/RayTracer/Source/Models/Mesh.cs @@ -125,15 +125,5 @@ public Vector2 GetTexCoord(int index) } return new Vector2(); } - - public static Mesh operator +(Mesh first, Mesh second) - { - first.Positions.AddRange(second.Positions); - first.Normals.AddRange(second.Normals); - first.TexCoords.AddRange(second.TexCoords); - int indexOffset = first.Positions.Count / 3; - first.Indices.AddRange(second.Indices.ConvertAll(index => index + indexOffset)); - return first; - } } } \ No newline at end of file diff --git a/RayTracer/Source/Models/ModelLoader.cs b/RayTracer/Source/Models/ModelLoader.cs index 87fec9a..709ee0e 100644 --- a/RayTracer/Source/Models/ModelLoader.cs +++ b/RayTracer/Source/Models/ModelLoader.cs @@ -58,11 +58,7 @@ public static CustomModel Load(string path, PostProcessSteps ppSteps, params Pro Log.Warn($"Model {path} containing more than one mesh. Using first mesh."); } - var mesh = new Mesh(new List(), new List(), new List(), new List()); - for (int i = 0; i < scene.MeshCount; i++) - { - mesh += ProcessMesh(scene.Meshes[i]); - } + var mesh = ProcessMesh(scene.Meshes[0]); var material = ProcessMaterial(scene.Materials[scene.Meshes[0].MaterialIndex], Path.GetDirectoryName(Path.GetFullPath(path))); From af5b027c9dbc77080904e3b7ea3f0fd29b4fac50 Mon Sep 17 00:00:00 2001 From: Tomasz Herman Date: Thu, 7 Jan 2021 05:05:43 +0100 Subject: [PATCH 27/31] Fixed indices indexing --- RayTracer/Source/Models/Mesh.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RayTracer/Source/Models/Mesh.cs b/RayTracer/Source/Models/Mesh.cs index 5922e6a..0139f6b 100644 --- a/RayTracer/Source/Models/Mesh.cs +++ b/RayTracer/Source/Models/Mesh.cs @@ -121,10 +121,10 @@ public Vector2 GetTexCoord(int index) public static Mesh operator +(Mesh first, Mesh second) { + int indexOffset = first.Positions.Count / 3; first.Positions.AddRange(second.Positions); first.Normals.AddRange(second.Normals); first.TexCoords.AddRange(second.TexCoords); - int indexOffset = first.Positions.Count / 3; first.Indices.AddRange(second.Indices.ConvertAll(index => index + indexOffset)); return first; } From fd0ffcd71cac372571c2d6c53e5a6fa6acaa4220 Mon Sep 17 00:00:00 2001 From: karolk98 <47919588+karolk98@users.noreply.github.com> Date: Thu, 7 Jan 2021 17:09:07 +0100 Subject: [PATCH 28/31] Resolve warnings --- RayTracer/Source/Materials/MasterMaterial.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/RayTracer/Source/Materials/MasterMaterial.cs b/RayTracer/Source/Materials/MasterMaterial.cs index 0fc7a11..591dcd8 100644 --- a/RayTracer/Source/Materials/MasterMaterial.cs +++ b/RayTracer/Source/Materials/MasterMaterial.cs @@ -97,10 +97,6 @@ private ThreadSafeSampler NewSampler() public bool Scatter(ref Ray ray, ref HitInfo hit, out Color attenuation, out Ray scattered) { - if (Parts.reflective == 0.69f) - { - var a = 2; - } return _materials[_sampler.Sample].Scatter(ref ray, ref hit, out attenuation, out scattered); } From c078289768b2a32183567730b1e3e214c08a9cef Mon Sep 17 00:00:00 2001 From: karolk98 <47919588+karolk98@users.noreply.github.com> Date: Thu, 7 Jan 2021 17:18:36 +0100 Subject: [PATCH 29/31] Minor fixes --- RayTracer/Source/Renderer/SamplesRayTracer.cs | 2 +- RayTracerApp/Forms/MainForm.cs | 40 ++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/RayTracer/Source/Renderer/SamplesRayTracer.cs b/RayTracer/Source/Renderer/SamplesRayTracer.cs index 89f5c69..65410c6 100644 --- a/RayTracer/Source/Renderer/SamplesRayTracer.cs +++ b/RayTracer/Source/Renderer/SamplesRayTracer.cs @@ -65,7 +65,7 @@ public override void Render(Scene scene, Camera camera) } catch (Exception e) { - return; + Log.Warn(e); } if (CancellationToken.IsCancellationRequested) diff --git a/RayTracerApp/Forms/MainForm.cs b/RayTracerApp/Forms/MainForm.cs index 54c0ce9..c426c9c 100644 --- a/RayTracerApp/Forms/MainForm.cs +++ b/RayTracerApp/Forms/MainForm.cs @@ -70,7 +70,7 @@ private void GLControl_Load(object sender, EventArgs e) _scene.AddModel(new Sphere { Position = new Vector3(0, 5.5f, 0), Scale = 1, - Material = new MasterMaterial(new Emissive(Color.FromColor4(Color4.LightYellow),25)) + Material = new MasterMaterial(new Emissive(Color.FromColor4(Color4.LightYellow), 25)) }.Load()); _scene.AddModel(new Sphere { @@ -91,8 +91,9 @@ private void GLControl_Load(object sender, EventArgs e) { Position = new Vector3(5f, 0.5f, 4), Scale = 1, Material = new MasterMaterial(new Diffuse(new Texture("wood.jpg"))), - Rotation = Vector3.One * (float)Math.PI / 3 - }.Load()); ; + Rotation = Vector3.One * (float) Math.PI / 3 + }.Load()); + ; _scene.AddModel(new Cube() { Position = new Vector3(0, 0.5f, -3), Scale = 1, @@ -131,7 +132,7 @@ private void InitializeFpsTimer() private void OnTimerTick(object sender, EventArgs e) { _cameraController.UpdateCamera(_fpsTimer.Interval); - + if (!rayTracingStarted) if (ShouldRaytrace()) { @@ -177,7 +178,7 @@ private void BackgroundWorkerProgressChanged(object sender, { var texture = (Texture) e.UserState; texture?.Blit(); - if(!gLControl.IsDisposed) + if (!gLControl.IsDisposed) gLControl.SwapBuffers(); _lastTexture?.CopyFrom(texture); texture?.Dispose(); @@ -193,10 +194,11 @@ private void InitializeBackgroundWorker() }; _backgroundWorker.DoWork += StartRender; _backgroundWorker.ProgressChanged += BackgroundWorkerProgressChanged; - _backgroundWorker.RunWorkerCompleted += (o,args) => + _backgroundWorker.RunWorkerCompleted += (o, args) => { progressBar.Visible = false; - gLControl.SwapBuffers(); + if (!gLControl.IsDisposed) + gLControl.SwapBuffers(); }; _cts = new CancellationTokenSource(); } @@ -216,7 +218,7 @@ private void settingsButton_Click(object sender, EventArgs e) var controller = new SettingsController(_camera, _rayTracer); var form = new SettingsForm(controller) - { StartPosition = FormStartPosition.Manual, Location = Location + Size / 3 }; + {StartPosition = FormStartPosition.Manual, Location = Location + Size / 3}; form.Closed += FormOnClosed; form.Closed += (a, b) => @@ -241,9 +243,10 @@ private void NewObjectFunction(bool hit, ref HitInfo hitInfo) { sphere.Position = _camera.Position + _camera.Front.Normalized() * 4; } + _scene.AddModel(sphere); var form = new NewObjectForm(new ObjectController(_scene, sphere)) - { StartPosition = FormStartPosition.Manual, Location = Location + Size / 3 }; + {StartPosition = FormStartPosition.Manual, Location = Location + Size / 3}; _isUiUsed = true; form.Closed += FormOnClosed; form.Show(); @@ -266,7 +269,7 @@ private void EditObjectFunction(bool hit, ref HitInfo hitInfo) var model = hitInfo.ModelHit; if (model is Triangle triangle) model = triangle.Parent; var form = new EditObjectForm(new ObjectController(_scene, model)) - { StartPosition = FormStartPosition.Manual, Location = Location + Size / 3 }; + {StartPosition = FormStartPosition.Manual, Location = Location + Size / 3}; form.Closed += FormOnClosed; form.Show(); } @@ -280,6 +283,7 @@ private void EditObjectFunction(bool hit, ref HitInfo hitInfo) { _scene.AmbientLight.Color = Color.FromSystemDrawing(MyDialog.Color); } + _isUiUsed = false; UpdateLastModification(); } @@ -302,11 +306,11 @@ private void DeleteObjectFunction(bool hit, ref HitInfo hitInfo) var model = hitInfo.ModelHit; if (model is Triangle triangle) model = triangle.Parent; string message = - $"Are you sure that you would like to delete the {model}?"; + $"Are you sure that you would like to delete the {model}?"; const string caption = "Delete object"; var result = MessageBox.Show(message, caption, - MessageBoxButtons.YesNo, - MessageBoxIcon.Question); + MessageBoxButtons.YesNo, + MessageBoxIcon.Question); if (result == DialogResult.Yes) { @@ -314,21 +318,22 @@ private void DeleteObjectFunction(bool hit, ref HitInfo hitInfo) _scene.Preprocess(); } } + _isUiUsed = false; } private void GLControl_MouseClick(object sender, MouseEventArgs e) { - if(e.Button == MouseButtons.Right) + if (e.Button == MouseButtons.Right) { - var width = (float)gLControl.Width; - var height = (float)gLControl.Height; + var width = (float) gLControl.Width; + var height = (float) gLControl.Height; var u = e.X / width; var v = 1 - e.Y / height; var ray = _cameraController.GetCamera().GetRay(u, v); _contextHitInfo = new HitInfo(); _contextHit = _scene.HitTest(ray, ref _contextHitInfo, 0.001f, float.PositiveInfinity); - + if (_contextHit) { newDeleteStrip.Show(Cursor.Position); @@ -349,7 +354,6 @@ private void SaveImage_Click(object sender, EventArgs e) String fileName = saveDialog.FileName; _lastTexture.Write(fileName); } - } private void DeleteItem_Click(object sender, EventArgs e) From 060f8df406fee0acd6b5c360cf4d7d6218481e1d Mon Sep 17 00:00:00 2001 From: karolk98 <47919588+karolk98@users.noreply.github.com> Date: Thu, 7 Jan 2021 17:24:48 +0100 Subject: [PATCH 30/31] Fix coding style in library part --- RayTracer/Source/Cameras/Camera.cs | 7 +- RayTracer/Source/Cameras/LensCamera.cs | 18 +++-- .../Source/Cameras/OrthographicCamera.cs | 1 - RayTracer/Source/Lights/Light.cs | 12 --- RayTracer/Source/Maths/AABB.cs | 9 ++- RayTracer/Source/Maths/Color.cs | 1 - RayTracer/Source/Models/Cylinder.cs | 79 ++++++++++--------- RayTracer/Source/Models/Mesh.cs | 2 + RayTracer/Source/Models/ModelLoader.cs | 11 +-- RayTracer/Source/Models/Plane.cs | 3 +- RayTracer/Source/Models/Rectangle.cs | 1 + RayTracer/Source/RayTracing/HitInfo.cs | 3 +- RayTracer/Source/Renderer/Renderer.cs | 3 +- RayTracer/Source/Sampling/AbstractSampler.cs | 5 +- RayTracer/Source/Sampling/IntSampling.cs | 16 ++-- RayTracer/Source/Sampling/Sampler.cs | 15 ++-- .../Source/Sampling/ThreadSafeSampler.cs | 19 +++-- RayTracer/Source/Sampling/Vec2Sampling.cs | 72 ++++++++++------- RayTracer/Source/Sampling/Vec3Sampling.cs | 12 ++- RayTracer/Source/Shaders/Shader.cs | 14 ++-- RayTracer/Source/World/Scene.cs | 3 +- RayTracerApp/Forms/MainForm.cs | 2 - 22 files changed, 170 insertions(+), 138 deletions(-) delete mode 100644 RayTracer/Source/Lights/Light.cs diff --git a/RayTracer/Source/Cameras/Camera.cs b/RayTracer/Source/Cameras/Camera.cs index 9913baf..7017603 100644 --- a/RayTracer/Source/Cameras/Camera.cs +++ b/RayTracer/Source/Cameras/Camera.cs @@ -10,6 +10,7 @@ public abstract class Camera protected Vector3 Up { get; set; } = Vector3.UnitY; protected Vector3 Right { get; set; } = Vector3.UnitX; private float _pitch; + public float Pitch { get => _pitch; @@ -19,7 +20,9 @@ public float Pitch UpdateVectors(); } } + private float _yaw = -MathHelper.PiOver2; + public float Yaw { get => _yaw; @@ -29,14 +32,16 @@ public float Yaw UpdateVectors(); } } + private float _aspectRatio = 16f / 9; protected float _fov = MathHelper.PiOver3; public Vector3 Position { get; set; } protected Vector3 Horizontal { get; set; } protected Vector3 Vertical { get; set; } protected Vector3 LowerLeft { get; set; } - + public float FarPlane { get; set; } = 1000f; + public float Fov { get => MathHelper.RadiansToDegrees(_fov); diff --git a/RayTracer/Source/Cameras/LensCamera.cs b/RayTracer/Source/Cameras/LensCamera.cs index cf6a18d..a353dfb 100644 --- a/RayTracer/Source/Cameras/LensCamera.cs +++ b/RayTracer/Source/Cameras/LensCamera.cs @@ -37,28 +37,31 @@ public float FocusDistance UpdateViewport(); } } - + public Func> Sampling { get => _sampling; set { _sampling = value; - _lensSampler = new ThreadSafeSampler(_sampling, _samplesCount, SAMPLE_SETS, Vec2Sampling.ToDisk); + _lensSampler = + new ThreadSafeSampler(_sampling, _samplesCount, SAMPLE_SETS, Vec2Sampling.ToDisk); } } - + public int SamplesCount { get => _samplesCount; set { _samplesCount = value; - _lensSampler = new ThreadSafeSampler(_sampling, _samplesCount, SAMPLE_SETS, Vec2Sampling.ToDisk); + _lensSampler = + new ThreadSafeSampler(_sampling, _samplesCount, SAMPLE_SETS, Vec2Sampling.ToDisk); } } - public LensCamera(Vector3 position, float lensRadius = 0.25f, float focusDistance = 5, int samplesCount = 10000, Func> sampling = null) + public LensCamera(Vector3 position, float lensRadius = 0.25f, float focusDistance = 5, int samplesCount = 10000, + Func> sampling = null) { Position = position; _lensRadius = lensRadius; @@ -93,8 +96,9 @@ public override Ray GetRay(float x, float y) { Vector2 rd = _lensRadius * _lensSampler.Sample; Vector3 offset = Right * rd.X + Up * rd.Y; - - return new Ray(Position + offset, (LowerLeft + x * Horizontal + y * Vertical - Position - offset).Normalized()); + + return new Ray(Position + offset, + (LowerLeft + x * Horizontal + y * Vertical - Position - offset).Normalized()); } } } \ No newline at end of file diff --git a/RayTracer/Source/Cameras/OrthographicCamera.cs b/RayTracer/Source/Cameras/OrthographicCamera.cs index abd4dd2..8dbae76 100644 --- a/RayTracer/Source/Cameras/OrthographicCamera.cs +++ b/RayTracer/Source/Cameras/OrthographicCamera.cs @@ -1,4 +1,3 @@ -using System; using OpenTK; using RayTracing.Maths; diff --git a/RayTracer/Source/Lights/Light.cs b/RayTracer/Source/Lights/Light.cs deleted file mode 100644 index c504ade..0000000 --- a/RayTracer/Source/Lights/Light.cs +++ /dev/null @@ -1,12 +0,0 @@ -using OpenTK; -using RayTracing.Maths; - -namespace RayTracing.Lights -{ - public struct Light - { - public Vector3 Position; - public Vector3 Direction; - public Color Color; - } -} \ No newline at end of file diff --git a/RayTracer/Source/Maths/AABB.cs b/RayTracer/Source/Maths/AABB.cs index 42e84cb..3165a47 100644 --- a/RayTracer/Source/Maths/AABB.cs +++ b/RayTracer/Source/Maths/AABB.cs @@ -7,7 +7,7 @@ public class AABB { public Vector3 Min { get; set; } public Vector3 Max { get; set; } - + public AABB(Vector3 min, Vector3 max) { if (min.X > max.X || min.Y > max.Y || min.Z > max.Z) @@ -15,7 +15,7 @@ public AABB(Vector3 min, Vector3 max) Min = min; Max = max; } - + public AABB(float xMin, float yMin, float zMin, float xMax, float yMax, float zMax) { if (xMin > xMax || yMin > yMax || zMin > zMax) @@ -26,7 +26,7 @@ public AABB(float xMin, float yMin, float zMin, float xMax, float yMax, float zM public bool Test(ref Ray ray, float from = 0, float to = float.PositiveInfinity) { - for (int a = 0; a < 3; a++) + for (int a = 0; a < 3; a++) { float invD = 1.0f / ray.Direction[a]; float t0 = (Min[a] - ray.Origin[a]) * invD; @@ -38,12 +38,13 @@ public bool Test(ref Ray ray, float from = 0, float to = float.PositiveInfinity) if (to <= from) return false; } + return true; } public static AABB operator +(AABB first, AABB second) { - return new AABB(Vector3.ComponentMin(first.Min, second.Min), + return new AABB(Vector3.ComponentMin(first.Min, second.Min), Vector3.ComponentMax(first.Max, second.Max)); } } diff --git a/RayTracer/Source/Maths/Color.cs b/RayTracer/Source/Maths/Color.cs index 32250c2..aa5e3cf 100644 --- a/RayTracer/Source/Maths/Color.cs +++ b/RayTracer/Source/Maths/Color.cs @@ -3,7 +3,6 @@ using Assimp; using OpenTK; using OpenTK.Graphics; -using System.Drawing; namespace RayTracing.Maths { diff --git a/RayTracer/Source/Models/Cylinder.cs b/RayTracer/Source/Models/Cylinder.cs index 311a46d..327d2a0 100644 --- a/RayTracer/Source/Models/Cylinder.cs +++ b/RayTracer/Source/Models/Cylinder.cs @@ -148,7 +148,7 @@ private void CapHitTest(ref Ray ray, ref HitInfo hit, float from, float to, ref GetCapUV(hitPoint, ref hit.TexCoord); } } - + // https://www.iquilezles.org/www/articles/diskbbox/diskbbox.htm public override AABB BoundingBox() { @@ -161,7 +161,7 @@ public override AABB BoundingBox() Vector3.ComponentMin(_top - e, _bottom - e), Vector3.ComponentMax(_top + e, _bottom + e)); } - + private void GetCylinderUV(Vector3 hitPoint, ref Vector2 uv) { var hitVector = RotationMatrix * (hitPoint - Position) / _height; @@ -170,7 +170,7 @@ private void GetCylinderUV(Vector3 hitPoint, ref Vector2 uv) uv.X = (float) (phi / (2 * Math.PI)); uv.Y = 0.5f - hitVector.Y; } - + private void GetCapUV(Vector3 hitPoint, ref Vector2 uv) { var hitVector = RotationMatrix * (hitPoint - Position) / Scale; @@ -189,68 +189,75 @@ private List GetUnitCircleVertices() float sectorStep = (float) (2 * Math.PI / _sectorCount); var unitCircleVertices = new List(); - for(int i = 0; i <= _sectorCount; ++i) + for (int i = 0; i <= _sectorCount; ++i) { var sectorAngle = i * sectorStep; - unitCircleVertices.Add((float)Math.Cos(sectorAngle)); - unitCircleVertices.Add((float)Math.Sin(sectorAngle)); + unitCircleVertices.Add((float) Math.Cos(sectorAngle)); + unitCircleVertices.Add((float) Math.Sin(sectorAngle)); unitCircleVertices.Add(0); } + return unitCircleVertices; } - + // http://www.songho.ca/opengl/gl_cylinder.html#cylinder - private (List indicesBuffer, List vertexBuffer, List texBuffer, List normalBuffer) GetBuffers() + private (List indicesBuffer, List vertexBuffer, List texBuffer, List normalBuffer) + GetBuffers() { var unitVertices = GetUnitCircleVertices(); var vertices = new List(); var normals = new List(); var texCoords = new List(); - + float height = _aspect; float radius = 1f; - - for(int i = 0; i < 2; ++i) + + for (int i = 0; i < 2; ++i) { float h = -height / 2.0f + i * height; float t = 1.0f - i; - for(int j = 0, k = 0; j <= _sectorCount; ++j, k += 3) + for (int j = 0, k = 0; j <= _sectorCount; ++j, k += 3) { float ux = unitVertices[k]; - float uy = unitVertices[k+1]; - float uz = unitVertices[k+2]; - + float uy = unitVertices[k + 1]; + float uz = unitVertices[k + 2]; + vertices.Add(ux * radius); vertices.Add(h); vertices.Add(uy * radius); - + normals.Add(ux); normals.Add(uz); normals.Add(uy); - - texCoords.Add(1 - (float)j / _sectorCount); + + texCoords.Add(1 - (float) j / _sectorCount); texCoords.Add(t); } } - + int baseCenterIndex = vertices.Count / 3; int topCenterIndex = baseCenterIndex + _sectorCount + 1; - - for(int i = 0; i < 2; ++i) + + for (int i = 0; i < 2; ++i) { float h = -height / 2.0f + i * height; float nz = -1 + i * 2; - - vertices.Add(0); vertices.Add(h); vertices.Add(0); - normals.Add(0); normals.Add(nz); normals.Add(0); - texCoords.Add(0.5f); texCoords.Add(0.5f); - for(int j = 0, k = 0; j < _sectorCount; ++j, k += 3) + vertices.Add(0); + vertices.Add(h); + vertices.Add(0); + normals.Add(0); + normals.Add(nz); + normals.Add(0); + texCoords.Add(0.5f); + texCoords.Add(0.5f); + + for (int j = 0, k = 0; j < _sectorCount; ++j, k += 3) { float ux = unitVertices[k]; - float uy = unitVertices[k+1]; - + float uy = unitVertices[k + 1]; + vertices.Add(ux * radius); vertices.Add(h); vertices.Add(uy * radius); @@ -275,8 +282,8 @@ private List GenIndices(int topCenterIndex, int baseCenterIndex) var indices = new List(); int k1 = 0; int k2 = _sectorCount + 1; - - for(int i = 0; i < _sectorCount; ++i, ++k1, ++k2) + + for (int i = 0; i < _sectorCount; ++i, ++k1, ++k2) { indices.Add(k1); indices.Add(k1 + 1); @@ -286,10 +293,10 @@ private List GenIndices(int topCenterIndex, int baseCenterIndex) indices.Add(k1 + 1); indices.Add(k2 + 1); } - - for(int i = 0, k = baseCenterIndex + 1; i < _sectorCount; ++i, ++k) + + for (int i = 0, k = baseCenterIndex + 1; i < _sectorCount; ++i, ++k) { - if(i < _sectorCount - 1) + if (i < _sectorCount - 1) { indices.Add(baseCenterIndex); indices.Add(k + 1); @@ -302,10 +309,10 @@ private List GenIndices(int topCenterIndex, int baseCenterIndex) indices.Add(k); } } - - for(int i = 0, k = topCenterIndex + 1; i < _sectorCount; ++i, ++k) + + for (int i = 0, k = topCenterIndex + 1; i < _sectorCount; ++i, ++k) { - if(i < _sectorCount - 1) + if (i < _sectorCount - 1) { indices.Add(topCenterIndex); indices.Add(k); diff --git a/RayTracer/Source/Models/Mesh.cs b/RayTracer/Source/Models/Mesh.cs index 25560cc..b47fef3 100644 --- a/RayTracer/Source/Models/Mesh.cs +++ b/RayTracer/Source/Models/Mesh.cs @@ -37,6 +37,7 @@ public void Load() { LoadDataBuffer(TexCoords, TEX_COORDS_INDEX, 2); } + LoadIndexBuffer(Indices); } @@ -122,6 +123,7 @@ public Vector2 GetTexCoord(int index) float vy = TexCoords[2 * Indices[index] + 1]; return new Vector2(vx, vy); } + return new Vector2(); } diff --git a/RayTracer/Source/Models/ModelLoader.cs b/RayTracer/Source/Models/ModelLoader.cs index 709ee0e..8a23b98 100644 --- a/RayTracer/Source/Models/ModelLoader.cs +++ b/RayTracer/Source/Models/ModelLoader.cs @@ -52,19 +52,20 @@ public static CustomModel Load(string path, PostProcessSteps ppSteps, params Pro Log.Error($"Error loading model {path}. No meshes found."); return model; } - + if (scene.Meshes.Count > 1) { Log.Warn($"Model {path} containing more than one mesh. Using first mesh."); } var mesh = ProcessMesh(scene.Meshes[0]); - - var material = ProcessMaterial(scene.Materials[scene.Meshes[0].MaterialIndex], Path.GetDirectoryName(Path.GetFullPath(path))); + + var material = ProcessMaterial(scene.Materials[scene.Meshes[0].MaterialIndex], + Path.GetDirectoryName(Path.GetFullPath(path))); model.SetMesh(mesh); model.Material = material; - + return model; } catch (AssimpException e) @@ -92,7 +93,7 @@ private static IMaterial ProcessMaterial(Assimp.Material material, string dir) Reflective = { Albedo = - ProcessTexture(material.HasTextureSpecular, material.ColorSpecular, + ProcessTexture(material.HasTextureSpecular, material.ColorSpecular, material.TextureSpecular, dir), Disturbance = Math.Min(Math.Max(1 - material.ShininessStrength / 100, 0), 1) }, diff --git a/RayTracer/Source/Models/Plane.cs b/RayTracer/Source/Models/Plane.cs index 5b7b68d..753dfa3 100644 --- a/RayTracer/Source/Models/Plane.cs +++ b/RayTracer/Source/Models/Plane.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using OpenTK; using RayTracing.Materials; using RayTracing.Maths; diff --git a/RayTracer/Source/Models/Rectangle.cs b/RayTracer/Source/Models/Rectangle.cs index 856c178..19b8931 100644 --- a/RayTracer/Source/Models/Rectangle.cs +++ b/RayTracer/Source/Models/Rectangle.cs @@ -9,6 +9,7 @@ namespace RayTracing.Models public class Rectangle : Model { private float _aspectRatio = 1; + public float AspectRatio { get => _aspectRatio; diff --git a/RayTracer/Source/RayTracing/HitInfo.cs b/RayTracer/Source/RayTracing/HitInfo.cs index b6134b0..db7229d 100644 --- a/RayTracer/Source/RayTracing/HitInfo.cs +++ b/RayTracer/Source/RayTracing/HitInfo.cs @@ -13,7 +13,8 @@ public struct HitInfo public Vector2 TexCoord; public bool FrontFace; - public void SetNormal(ref Ray ray, ref Vector3 normal) { + public void SetNormal(ref Ray ray, ref Vector3 normal) + { FrontFace = Vector3.Dot(ray.Direction, normal) <= 0; Normal = FrontFace ? normal : -normal; } diff --git a/RayTracer/Source/Renderer/Renderer.cs b/RayTracer/Source/Renderer/Renderer.cs index 75504e7..fc09a46 100644 --- a/RayTracer/Source/Renderer/Renderer.cs +++ b/RayTracer/Source/Renderer/Renderer.cs @@ -1,5 +1,4 @@ -using System; -using OpenTK.Graphics.OpenGL4; +using OpenTK.Graphics.OpenGL4; using RayTracing.Cameras; using RayTracing.Materials; using RayTracing.Shaders; diff --git a/RayTracer/Source/Sampling/AbstractSampler.cs b/RayTracer/Source/Sampling/AbstractSampler.cs index 8b22da9..1704c6e 100644 --- a/RayTracer/Source/Sampling/AbstractSampler.cs +++ b/RayTracer/Source/Sampling/AbstractSampler.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Threading; namespace RayTracing.Sampling { @@ -9,7 +8,7 @@ public abstract class AbstractSampler protected readonly List> Samples = new List>(); protected readonly int count; protected readonly int Sets; - + public AbstractSampler(Func> generator, int count = 64, int sets = 1, Func mapper = null) { this.count = count; @@ -30,7 +29,7 @@ public AbstractSampler(Func> generator, int count = 64, int sets = public abstract T GetSample(int i); public int Count => count; - + public T Sample => GetSample(); } } \ No newline at end of file diff --git a/RayTracer/Source/Sampling/IntSampling.cs b/RayTracer/Source/Sampling/IntSampling.cs index ee8c112..75555b7 100644 --- a/RayTracer/Source/Sampling/IntSampling.cs +++ b/RayTracer/Source/Sampling/IntSampling.cs @@ -12,22 +12,22 @@ public static List Distribution(int count, params float[] probabilities) { if (probabilities.Length == 0) throw new ArgumentException("Zero lenght probabilities array"); - if(probabilities.Any(probability => probability < 0)) + if (probabilities.Any(probability => probability < 0)) throw new ArgumentException("Probability lesser than zero."); float sum = probabilities.Sum(); - if(sum == 0) + if (sum == 0) { Log.Warn("Probabilities sum to 0 returning list containing zeroes"); return Enumerable.Repeat(0, count).ToList(); } List samples = new List(); - + for (int i = 0; i < count; i++) { - float next = (float)_random.NextDouble() * sum; + float next = (float) _random.NextDouble() * sum; float counter = 0; for (int j = 0; j < probabilities.Length; j++) { @@ -45,16 +45,16 @@ public static List Distribution(int count, params float[] probabilities) public static List Random(int count, int minInclusive, int maxExclusive) { - if(count < 0) + if (count < 0) throw new ArgumentException("Count less than zero"); if (minInclusive >= maxExclusive) throw new ArgumentException("Wrong limits"); - + List samples = new List(); - + for (int i = 0; i < count; i++) { - samples.Add(_random.Next(minInclusive, maxExclusive)); + samples.Add(_random.Next(minInclusive, maxExclusive)); } return samples; diff --git a/RayTracer/Source/Sampling/Sampler.cs b/RayTracer/Source/Sampling/Sampler.cs index 245f956..78bbdda 100644 --- a/RayTracer/Source/Sampling/Sampler.cs +++ b/RayTracer/Source/Sampling/Sampler.cs @@ -8,20 +8,23 @@ public class Sampler : AbstractSampler private Random random = new Random(); private int current; private int set; - - public Sampler(Func> generator, int count = 64, int sets = 1, Func mapper = null) - : base(generator, count, sets, mapper) { } + + public Sampler(Func> generator, int count = 64, int sets = 1, Func mapper = null) + : base(generator, count, sets, mapper) + { + } public override T GetSample() { - if(current >= count) + if (current >= count) { current = 0; - if(Sets > 1) set = random.Next(Sets); + if (Sets > 1) set = random.Next(Sets); } + return Samples[set][current++]; } - + public override T GetSample(int i) { return Samples[set][i]; diff --git a/RayTracer/Source/Sampling/ThreadSafeSampler.cs b/RayTracer/Source/Sampling/ThreadSafeSampler.cs index 8291315..ab8d707 100644 --- a/RayTracer/Source/Sampling/ThreadSafeSampler.cs +++ b/RayTracer/Source/Sampling/ThreadSafeSampler.cs @@ -6,23 +6,28 @@ namespace RayTracing.Sampling { public class ThreadSafeSampler : AbstractSampler { - private ThreadLocal _random = new ThreadLocal(() => new Random(Thread.CurrentThread.ManagedThreadId)); + private ThreadLocal _random = + new ThreadLocal(() => new Random(Thread.CurrentThread.ManagedThreadId)); + private ThreadLocal _current = new ThreadLocal(() => 0); private ThreadLocal _set = new ThreadLocal(() => 0); - - public ThreadSafeSampler(Func> generator, int count = 64, int sets = 1, Func mapper = null) - : base(generator, count, sets, mapper) { } + + public ThreadSafeSampler(Func> generator, int count = 64, int sets = 1, Func mapper = null) + : base(generator, count, sets, mapper) + { + } public override T GetSample() { - if(_current.Value >= count) + if (_current.Value >= count) { _current.Value = 0; - if(Sets > 1) _set.Value = _random.Value.Next(Sets); + if (Sets > 1) _set.Value = _random.Value.Next(Sets); } + return Samples[_set.Value][_current.Value++]; } - + public override T GetSample(int i) { return Samples[_set.Value][i]; diff --git a/RayTracer/Source/Sampling/Vec2Sampling.cs b/RayTracer/Source/Sampling/Vec2Sampling.cs index 21ef8a3..0849d2d 100644 --- a/RayTracer/Source/Sampling/Vec2Sampling.cs +++ b/RayTracer/Source/Sampling/Vec2Sampling.cs @@ -8,7 +8,7 @@ namespace RayTracing.Sampling public static class Vec2Sampling { private static readonly Random _random = new Random(); - + public static List Dummy(int count) { List samples = new List(); @@ -16,91 +16,109 @@ public static List Dummy(int count) { samples.Add(new Vector2(0.5f, 0.5f)); } + return samples; } - + public static List Regular(int count) { int size = (int) Math.Ceiling(Math.Sqrt(count)); List samples = new List(); - for (int i = 0; i < size; ++i) { - for (int j = 0; j < size; ++j) { + for (int i = 0; i < size; ++i) + { + for (int j = 0; j < size; ++j) + { Vector2 sample = new Vector2( - (i + 0.5f) / size, + (i + 0.5f) / size, (j + 0.5f) / size ); samples.Add(sample); } } - + samples = samples.OrderBy(item => _random.Next()).Take(count).ToList(); - + return samples; } - + public static List Jittered(int count) { int size = (int) Math.Ceiling(Math.Sqrt(count)); List samples = new List(); - for (int i = 0; i < size; ++i) { - for (int j = 0; j < size; ++j) { + for (int i = 0; i < size; ++i) + { + for (int j = 0; j < size; ++j) + { Vector2 sample = new Vector2( - (i + (float)_random.NextDouble()) / size, - (j + (float)_random.NextDouble()) / size + (i + (float) _random.NextDouble()) / size, + (j + (float) _random.NextDouble()) / size ); samples.Add(sample); } } - + samples = samples.OrderBy(item => _random.Next()).Take(count).ToList(); return samples; } - + public static List Random(int count) { List samples = new List(); for (int i = 0; i < count; ++i) { samples.Add(new Vector2( - (float)_random.NextDouble(), - (float)_random.NextDouble()) + (float) _random.NextDouble(), + (float) _random.NextDouble()) ); } + return samples; } - + public static Vector2 WiderRange(Vector2 sample) { return new Vector2(sample.X * 2 - 1, sample.Y * 2 - 1); } - + public static Vector2 ToDisk(Vector2 sample) { sample = WiderRange(sample); float r, phi; - if(sample.X > -sample.Y) { - if(sample.X > sample.Y) { + if (sample.X > -sample.Y) + { + if (sample.X > sample.Y) + { r = sample.X; phi = sample.Y / sample.X; - } else { + } + else + { r = sample.Y; phi = 2 - sample.X / sample.Y; } - } else { - if(sample.X < sample.Y) { + } + else + { + if (sample.X < sample.Y) + { r = -sample.X; phi = 4 + sample.Y / sample.X; - } else { + } + else + { r = -sample.Y; phi = 6 - sample.X / sample.Y; } } - if(sample.X == 0 && sample.Y == 0) { + + if (sample.X == 0 && sample.Y == 0) + { phi = 0; } - phi *= (float)Math.PI / 4; - return new Vector2(r * (float)Math.Cos(phi), r * (float)Math.Sin(phi)); + + phi *= (float) Math.PI / 4; + return new Vector2(r * (float) Math.Cos(phi), r * (float) Math.Sin(phi)); } } } \ No newline at end of file diff --git a/RayTracer/Source/Sampling/Vec3Sampling.cs b/RayTracer/Source/Sampling/Vec3Sampling.cs index 20cfe66..946c2bf 100644 --- a/RayTracer/Source/Sampling/Vec3Sampling.cs +++ b/RayTracer/Source/Sampling/Vec3Sampling.cs @@ -7,10 +7,12 @@ namespace RayTracing.Sampling public static class Vec3Sampling { private static readonly Random Random = new Random(); - - public static List UniformSphere(int count) { + + public static List UniformSphere(int count) + { List samples = new List(); - for (int i = 0; i < count; ++i) { + for (int i = 0; i < count; ++i) + { Vector3 sample = new Vector3(); do { @@ -18,11 +20,13 @@ public static List UniformSphere(int count) { sample.Y = (float) Random.NextDouble() * 2 - 1; sample.Z = (float) Random.NextDouble() * 2 - 1; } while (sample.LengthSquared > 1); + samples.Add(sample); } + return samples; } - + public static Vector3 ToSphereSurface(Vector3 sample) { return sample != Vector3.Zero ? sample.Normalized() : UniformSphere(1)[0].Normalized(); diff --git a/RayTracer/Source/Shaders/Shader.cs b/RayTracer/Source/Shaders/Shader.cs index 56d7364..cd9822a 100644 --- a/RayTracer/Source/Shaders/Shader.cs +++ b/RayTracer/Source/Shaders/Shader.cs @@ -22,9 +22,9 @@ public Shader(string vertexPath, string fragmentPath) var fragmentShaderId = CompileShader(fragmentShaderSource, ShaderType.FragmentShader); _handle = LinkShader(vertexShaderId, fragmentShaderId); GL.GetProgram(_handle, GetProgramParameterName.ActiveUniforms, out var numberOfUniforms); - + _uniformLocations = new Dictionary(); - + for (var i = 0; i < numberOfUniforms; i++) { var key = GL.GetActiveUniform(_handle, i, out _, out _); @@ -36,7 +36,7 @@ public Shader(string vertexPath, string fragmentPath) private string ReadShaderFromFile(string shaderName) { var assembly = GetType().Assembly; - using Stream vertexShaderStream = assembly.GetManifestResourceStream(ShadersPath+shaderName); + using Stream vertexShaderStream = assembly.GetManifestResourceStream(ShadersPath + shaderName); using StreamReader reader = new StreamReader(vertexShaderStream, Encoding.UTF8); return reader.ReadToEnd(); } @@ -50,7 +50,7 @@ private static int CompileShader(string shaderSource, ShaderType shaderType) string infoLogVert = GL.GetShaderInfoLog(shaderId); if (!string.IsNullOrEmpty(infoLogVert)) Log.Error(infoLogVert); - + return shaderId; } @@ -76,19 +76,19 @@ public void SetMatrix4(string name, Matrix4 data) GL.UseProgram(_handle); GL.UniformMatrix4(_uniformLocations[name], true, ref data); } - + public void SetVector3(string name, Vector3 data) { GL.UseProgram(_handle); GL.Uniform3(_uniformLocations[name], data); } - + public void SetInt(string name, int data) { GL.UseProgram(_handle); GL.Uniform1(_uniformLocations[name], data); } - + public void SetFloat(string name, float data) { GL.UseProgram(_handle); diff --git a/RayTracer/Source/World/Scene.cs b/RayTracer/Source/World/Scene.cs index cfcc41c..555062f 100644 --- a/RayTracer/Source/World/Scene.cs +++ b/RayTracer/Source/World/Scene.cs @@ -1,11 +1,9 @@ using System.Collections.Generic; using RayTracing.BVH; using RayTracing.Lights; -using RayTracing.Materials; using RayTracing.Maths; using RayTracing.Models; using RayTracing.RayTracing; -using RayTracing.Sampling; namespace RayTracing.World { @@ -79,6 +77,7 @@ private List BvhPreprocess() var node = new BvhNode(hittablesToBvh, 0, hittablesToBvh.Count); Hittables.Add(node); } + return Hittables; } diff --git a/RayTracerApp/Forms/MainForm.cs b/RayTracerApp/Forms/MainForm.cs index c426c9c..b9fbefc 100644 --- a/RayTracerApp/Forms/MainForm.cs +++ b/RayTracerApp/Forms/MainForm.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; using OpenTK; @@ -93,7 +92,6 @@ private void GLControl_Load(object sender, EventArgs e) Material = new MasterMaterial(new Diffuse(new Texture("wood.jpg"))), Rotation = Vector3.One * (float) Math.PI / 3 }.Load()); - ; _scene.AddModel(new Cube() { Position = new Vector3(0, 0.5f, -3), Scale = 1, From daee217a35a0b7e375ccd7fd14ea26232d51c878 Mon Sep 17 00:00:00 2001 From: p-flis Date: Thu, 7 Jan 2021 18:23:40 +0100 Subject: [PATCH 31/31] review changes --- RayTracer/Source/Cameras/LensCamera.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/RayTracer/Source/Cameras/LensCamera.cs b/RayTracer/Source/Cameras/LensCamera.cs index a353dfb..89a6202 100644 --- a/RayTracer/Source/Cameras/LensCamera.cs +++ b/RayTracer/Source/Cameras/LensCamera.cs @@ -88,7 +88,6 @@ public override Matrix4 GetViewMatrix() public override Matrix4 GetProjectionMatrix() { - Log.Info("" + _fov); return Matrix4.CreatePerspectiveFieldOfView(_fov, AspectRatio, 1, FarPlane); }