Click here to Skip to main content
15,881,757 members
Articles / Programming Languages / C#

Simple Ray Tracing in C# Part VI (Vertex Normal Interpolation)

Rate me:
Please Sign up or sign in to vote.
4.75/5 (26 votes)
15 Jul 2016GPL33 min read 62K   70  
An approach to interpolate vertex normals on triangles
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace RayTracer
{
    public class Helpers
    {
        public static bool LoadTextFile(string sFilename, ref string sTextFromFile)
        {
            sTextFromFile = "";

            try
            {
                StreamReader oStreamReader = new StreamReader(sFilename);
                sTextFromFile = oStreamReader.ReadToEnd();
                oStreamReader.Close();
                oStreamReader.Dispose();
            }
            catch(Exception ex)
            {
                sTextFromFile = ex.ToString();
                return false;
            }
            return true;
        }

        public static bool SaveTextFile(string sFilename, string sText)
        {
            try
            {
                StreamWriter oStreamWriter = new StreamWriter(sFilename);
                oStreamWriter.Write(sText);
                oStreamWriter.Flush();
                oStreamWriter.Close();
                oStreamWriter.Dispose();
            }
            catch
            {
                return false;
            }
            return true;
        }

        public static string SaveTempFile(string sText)
        {
            string FileName = Path.GetTempFileName();
            FileStream File_Stream = new FileStream(FileName, FileMode.Append, FileAccess.Write);
            StreamWriter FileWriter = new StreamWriter(File_Stream);
            try
            {
                FileWriter.BaseStream.Seek(0, SeekOrigin.End);
                FileWriter.Write(sText);
            }
            catch (IOException)// ex)
            {
                //Debug.Assert(false, ex.ToString());
            }
            finally
            {
                FileWriter.Close();
            }
            return FileName;
        }

    }
}

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 GNU General Public License (GPLv3)


Written By
CEO
Brazil Brazil
"A well written code is self explanatory" - Anonymous Programmer
Founder @TIHUNTER.COM.BR
Linkedin Profile

Comments and Discussions