Click here to Skip to main content
15,895,746 members
Articles / Programming Languages / C#

Yet Another RayTracer for .NET

Rate me:
Please Sign up or sign in to vote.
4.87/5 (56 votes)
29 Mar 2007CPOL15 min read 130K   3.9K   124  
This article is meant as an introduction to raytracing and explains the basic techniques to raytrace a scene.
namespace RayTracerApp
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.pbScene = new System.Windows.Forms.PictureBox();
            this.Statusbar = new System.Windows.Forms.StatusStrip();
            this.statusETA = new System.Windows.Forms.ToolStripStatusLabel();
            this.statusDuration = new System.Windows.Forms.ToolStripStatusLabel();
            this.label1 = new System.Windows.Forms.Label();
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.sceneToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.marbleSpheresToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.woodenFloorAndStoneWallToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.randomMarblesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.renderNowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.antiAliasingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.noneToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.quickToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.lowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.mediumToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.highToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.veryHighToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.showPhongToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.castShadowsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.showReflectionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.showRefractionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.reflectiveShereOnChessboardToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.woodenBoxAndMarbleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.pbScene)).BeginInit();
            this.Statusbar.SuspendLayout();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // pictureBox1
            // 
            this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.pictureBox1.Location = new System.Drawing.Point(275, 2);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(24, 22);
            this.pictureBox1.TabIndex = 1;
            this.pictureBox1.TabStop = false;
            // 
            // pbScene
            // 
            this.pbScene.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
            this.pbScene.Location = new System.Drawing.Point(0, 27);
            this.pbScene.Name = "pbScene";
            this.pbScene.Size = new System.Drawing.Size(300, 300);
            this.pbScene.TabIndex = 2;
            this.pbScene.TabStop = false;
            this.pbScene.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pbScene_MouseDown);
            // 
            // Statusbar
            // 
            this.Statusbar.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.statusETA,
            this.statusDuration});
            this.Statusbar.Location = new System.Drawing.Point(0, 329);
            this.Statusbar.Name = "Statusbar";
            this.Statusbar.Size = new System.Drawing.Size(300, 22);
            this.Statusbar.TabIndex = 3;
            this.Statusbar.Text = "statusStrip1";
            // 
            // statusETA
            // 
            this.statusETA.AutoSize = false;
            this.statusETA.Name = "statusETA";
            this.statusETA.Size = new System.Drawing.Size(80, 17);
            this.statusETA.Text = "ETA:";
            this.statusETA.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // statusDuration
            // 
            this.statusDuration.Name = "statusDuration";
            this.statusDuration.Size = new System.Drawing.Size(52, 17);
            this.statusDuration.Text = "Duration:";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(71, 48);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(157, 13);
            this.label1.TabIndex = 5;
            this.label1.Text = "Press F5 to start the RayTracer!";
            // 
            // menuStrip1
            // 
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.editToolStripMenuItem,
            this.toolsToolStripMenuItem,
            this.settingsToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(300, 24);
            this.menuStrip1.TabIndex = 6;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // editToolStripMenuItem
            // 
            this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.copyToolStripMenuItem});
            this.editToolStripMenuItem.Name = "editToolStripMenuItem";
            this.editToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
            this.editToolStripMenuItem.Text = "&Edit";
            // 
            // copyToolStripMenuItem
            // 
            this.copyToolStripMenuItem.Name = "copyToolStripMenuItem";
            this.copyToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C)));
            this.copyToolStripMenuItem.Size = new System.Drawing.Size(149, 22);
            this.copyToolStripMenuItem.Text = "&Copy";
            this.copyToolStripMenuItem.Click += new System.EventHandler(this.copyToolStripMenuItem_Click);
            // 
            // toolsToolStripMenuItem
            // 
            this.toolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.sceneToolStripMenuItem,
            this.renderNowToolStripMenuItem});
            this.toolsToolStripMenuItem.Name = "toolsToolStripMenuItem";
            this.toolsToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
            this.toolsToolStripMenuItem.Text = "&Tools";
            // 
            // sceneToolStripMenuItem
            // 
            this.sceneToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.marbleSpheresToolStripMenuItem,
            this.woodenFloorAndStoneWallToolStripMenuItem,
            this.reflectiveShereOnChessboardToolStripMenuItem,
            this.woodenBoxAndMarbleToolStripMenuItem,
            this.randomMarblesToolStripMenuItem});
            this.sceneToolStripMenuItem.Name = "sceneToolStripMenuItem";
            this.sceneToolStripMenuItem.Size = new System.Drawing.Size(176, 22);
            this.sceneToolStripMenuItem.Text = "&Scene";
            // 
            // marbleSpheresToolStripMenuItem
            // 
            this.marbleSpheresToolStripMenuItem.Checked = true;
            this.marbleSpheresToolStripMenuItem.CheckOnClick = true;
            this.marbleSpheresToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
            this.marbleSpheresToolStripMenuItem.Name = "marbleSpheresToolStripMenuItem";
            this.marbleSpheresToolStripMenuItem.Size = new System.Drawing.Size(270, 22);
            this.marbleSpheresToolStripMenuItem.Text = "Two marbles on chessboard";
            this.marbleSpheresToolStripMenuItem.Click += new System.EventHandler(this.marbleSpheresToolStripMenuItem_Click);
            // 
            // woodenFloorAndStoneWallToolStripMenuItem
            // 
            this.woodenFloorAndStoneWallToolStripMenuItem.Name = "woodenFloorAndStoneWallToolStripMenuItem";
            this.woodenFloorAndStoneWallToolStripMenuItem.Size = new System.Drawing.Size(270, 22);
            this.woodenFloorAndStoneWallToolStripMenuItem.Text = "Marble on wooden floor and stone wall";
            this.woodenFloorAndStoneWallToolStripMenuItem.Click += new System.EventHandler(this.woodenFloorAndStoneWallToolStripMenuItem_Click);
            // 
            // randomMarblesToolStripMenuItem
            // 
            this.randomMarblesToolStripMenuItem.Name = "randomMarblesToolStripMenuItem";
            this.randomMarblesToolStripMenuItem.Size = new System.Drawing.Size(270, 22);
            this.randomMarblesToolStripMenuItem.Text = "Random marbles";
            this.randomMarblesToolStripMenuItem.Click += new System.EventHandler(this.randomMarblesToolStripMenuItem_Click);
            // 
            // renderNowToolStripMenuItem
            // 
            this.renderNowToolStripMenuItem.Name = "renderNowToolStripMenuItem";
            this.renderNowToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F5;
            this.renderNowToolStripMenuItem.Size = new System.Drawing.Size(176, 22);
            this.renderNowToolStripMenuItem.Text = "&Raytrace Now!";
            this.renderNowToolStripMenuItem.Click += new System.EventHandler(this.renderNowToolStripMenuItem_Click);
            // 
            // settingsToolStripMenuItem
            // 
            this.settingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.antiAliasingToolStripMenuItem,
            this.showPhongToolStripMenuItem,
            this.castShadowsToolStripMenuItem,
            this.showReflectionsToolStripMenuItem,
            this.showRefractionsToolStripMenuItem});
            this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem";
            this.settingsToolStripMenuItem.Size = new System.Drawing.Size(58, 20);
            this.settingsToolStripMenuItem.Text = "&Settings";
            // 
            // antiAliasingToolStripMenuItem
            // 
            this.antiAliasingToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.noneToolStripMenuItem,
            this.quickToolStripMenuItem,
            this.lowToolStripMenuItem,
            this.mediumToolStripMenuItem,
            this.highToolStripMenuItem,
            this.veryHighToolStripMenuItem});
            this.antiAliasingToolStripMenuItem.Name = "antiAliasingToolStripMenuItem";
            this.antiAliasingToolStripMenuItem.Size = new System.Drawing.Size(193, 22);
            this.antiAliasingToolStripMenuItem.Text = "Anti &Aliasing";
            // 
            // noneToolStripMenuItem
            // 
            this.noneToolStripMenuItem.CheckOnClick = true;
            this.noneToolStripMenuItem.Name = "noneToolStripMenuItem";
            this.noneToolStripMenuItem.Size = new System.Drawing.Size(130, 22);
            this.noneToolStripMenuItem.Text = "None";
            this.noneToolStripMenuItem.Click += new System.EventHandler(this.noneToolStripMenuItem_Click);
            // 
            // quickToolStripMenuItem
            // 
            this.quickToolStripMenuItem.CheckOnClick = true;
            this.quickToolStripMenuItem.Name = "quickToolStripMenuItem";
            this.quickToolStripMenuItem.Size = new System.Drawing.Size(130, 22);
            this.quickToolStripMenuItem.Text = "Quick";
            this.quickToolStripMenuItem.Click += new System.EventHandler(this.quickToolStripMenuItem_Click);
            // 
            // lowToolStripMenuItem
            // 
            this.lowToolStripMenuItem.CheckOnClick = true;
            this.lowToolStripMenuItem.Name = "lowToolStripMenuItem";
            this.lowToolStripMenuItem.Size = new System.Drawing.Size(130, 22);
            this.lowToolStripMenuItem.Text = "Low";
            this.lowToolStripMenuItem.Click += new System.EventHandler(this.lowToolStripMenuItem_Click);
            // 
            // mediumToolStripMenuItem
            // 
            this.mediumToolStripMenuItem.Checked = true;
            this.mediumToolStripMenuItem.CheckOnClick = true;
            this.mediumToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
            this.mediumToolStripMenuItem.Name = "mediumToolStripMenuItem";
            this.mediumToolStripMenuItem.Size = new System.Drawing.Size(130, 22);
            this.mediumToolStripMenuItem.Text = "Medium";
            this.mediumToolStripMenuItem.Click += new System.EventHandler(this.mediumToolStripMenuItem_Click);
            // 
            // highToolStripMenuItem
            // 
            this.highToolStripMenuItem.CheckOnClick = true;
            this.highToolStripMenuItem.Name = "highToolStripMenuItem";
            this.highToolStripMenuItem.Size = new System.Drawing.Size(130, 22);
            this.highToolStripMenuItem.Text = "High";
            this.highToolStripMenuItem.Click += new System.EventHandler(this.highToolStripMenuItem_Click);
            // 
            // veryHighToolStripMenuItem
            // 
            this.veryHighToolStripMenuItem.CheckOnClick = true;
            this.veryHighToolStripMenuItem.Name = "veryHighToolStripMenuItem";
            this.veryHighToolStripMenuItem.Size = new System.Drawing.Size(130, 22);
            this.veryHighToolStripMenuItem.Text = "Very high";
            this.veryHighToolStripMenuItem.Click += new System.EventHandler(this.veryHighToolStripMenuItem_Click);
            // 
            // showPhongToolStripMenuItem
            // 
            this.showPhongToolStripMenuItem.Checked = true;
            this.showPhongToolStripMenuItem.CheckOnClick = true;
            this.showPhongToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
            this.showPhongToolStripMenuItem.Name = "showPhongToolStripMenuItem";
            this.showPhongToolStripMenuItem.Size = new System.Drawing.Size(193, 22);
            this.showPhongToolStripMenuItem.Text = "Show Phong Highlights";
            // 
            // castShadowsToolStripMenuItem
            // 
            this.castShadowsToolStripMenuItem.Checked = true;
            this.castShadowsToolStripMenuItem.CheckOnClick = true;
            this.castShadowsToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
            this.castShadowsToolStripMenuItem.Name = "castShadowsToolStripMenuItem";
            this.castShadowsToolStripMenuItem.Size = new System.Drawing.Size(193, 22);
            this.castShadowsToolStripMenuItem.Text = "Cast Shadows";
            // 
            // showReflectionsToolStripMenuItem
            // 
            this.showReflectionsToolStripMenuItem.Checked = true;
            this.showReflectionsToolStripMenuItem.CheckOnClick = true;
            this.showReflectionsToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
            this.showReflectionsToolStripMenuItem.Name = "showReflectionsToolStripMenuItem";
            this.showReflectionsToolStripMenuItem.Size = new System.Drawing.Size(193, 22);
            this.showReflectionsToolStripMenuItem.Text = "Show Reflections";
            // 
            // showRefractionsToolStripMenuItem
            // 
            this.showRefractionsToolStripMenuItem.Checked = true;
            this.showRefractionsToolStripMenuItem.CheckOnClick = true;
            this.showRefractionsToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
            this.showRefractionsToolStripMenuItem.Name = "showRefractionsToolStripMenuItem";
            this.showRefractionsToolStripMenuItem.Size = new System.Drawing.Size(193, 22);
            this.showRefractionsToolStripMenuItem.Text = "Show Refractions";
            // 
            // reflectiveShereOnChessboardToolStripMenuItem
            // 
            this.reflectiveShereOnChessboardToolStripMenuItem.Name = "reflectiveShereOnChessboardToolStripMenuItem";
            this.reflectiveShereOnChessboardToolStripMenuItem.Size = new System.Drawing.Size(270, 22);
            this.reflectiveShereOnChessboardToolStripMenuItem.Text = "Reflective shere on chessboard";
            this.reflectiveShereOnChessboardToolStripMenuItem.Click += new System.EventHandler(this.reflectiveShereOnChessboardToolStripMenuItem_Click);
            // 
            // woodenBoxAndMarbleToolStripMenuItem
            // 
            this.woodenBoxAndMarbleToolStripMenuItem.Name = "woodenBoxAndMarbleToolStripMenuItem";
            this.woodenBoxAndMarbleToolStripMenuItem.Size = new System.Drawing.Size(270, 22);
            this.woodenBoxAndMarbleToolStripMenuItem.Text = "Wooden box and marble";
            this.woodenBoxAndMarbleToolStripMenuItem.Click += new System.EventHandler(this.woodenBoxAndMarbleToolStripMenuItem_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(300, 351);
            this.Controls.Add(this.Statusbar);
            this.Controls.Add(this.pictureBox1);
            this.Controls.Add(this.menuStrip1);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.pbScene);
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "Form1";
            this.Text = "Raytracer.Net";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pbScene)).EndInit();
            this.Statusbar.ResumeLayout(false);
            this.Statusbar.PerformLayout();
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.PictureBox pictureBox1;
        private System.Windows.Forms.PictureBox pbScene;
        private System.Windows.Forms.StatusStrip Statusbar;
        private System.Windows.Forms.ToolStripStatusLabel statusETA;
        private System.Windows.Forms.ToolStripStatusLabel statusDuration;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem copyToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem toolsToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem sceneToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem marbleSpheresToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem woodenFloorAndStoneWallToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem antiAliasingToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem noneToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem quickToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem lowToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem mediumToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem highToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem veryHighToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem renderNowToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem randomMarblesToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem castShadowsToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem showReflectionsToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem showRefractionsToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem showPhongToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem reflectiveShereOnChessboardToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem woodenBoxAndMarbleToolStripMenuItem;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Rubicon
Netherlands Netherlands
Currently Herre Kuijpers is employed at Rubicon. During his career he developed skills with all kinds of technologies, methodologies and programming languages such as c#, ASP.Net, .Net Core, VC++, Javascript, SQL, Agile, Scrum, DevOps, ALM. Currently he fulfills the role of software architect in various projects.

Herre Kuijpers is a very experienced software architect with deep knowledge of software design and development on the Microsoft .Net platform. He has a broad knowledge of Microsoft products and knows how these, in combination with custom software, can be optimally implemented in the often complex environment of the customer.

Comments and Discussions