diff --git a/VoxelIsometricRenderer.sln b/VoxelIsometricRenderer.sln new file mode 100644 index 0000000..50409d5 --- /dev/null +++ b/VoxelIsometricRenderer.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36811.4 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VoxelIsometricRenderer", "VoxelIsometricRenderer\VoxelIsometricRenderer.csproj", "{BC07C626-47CC-41D7-BF64-E0842741C697}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BC07C626-47CC-41D7-BF64-E0842741C697}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BC07C626-47CC-41D7-BF64-E0842741C697}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BC07C626-47CC-41D7-BF64-E0842741C697}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BC07C626-47CC-41D7-BF64-E0842741C697}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {54007B9B-4054-4DFA-B7B3-1763935EAECD} + EndGlobalSection +EndGlobal diff --git a/VoxelIsometricRenderer/App.config b/VoxelIsometricRenderer/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/VoxelIsometricRenderer/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/VoxelIsometricRenderer/Program.cs b/VoxelIsometricRenderer/Program.cs new file mode 100644 index 0000000..b149e9e --- /dev/null +++ b/VoxelIsometricRenderer/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace VoxelIsometricRenderer +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Terrain4()); + } + } +} diff --git a/VoxelIsometricRenderer/Properties/AssemblyInfo.cs b/VoxelIsometricRenderer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6beea6c --- /dev/null +++ b/VoxelIsometricRenderer/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("VoxelIsometricRenderer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("VoxelIsometricRenderer")] +[assembly: AssemblyCopyright("Copyright © 2026")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("bc07c626-47cc-41d7-bf64-e0842741c697")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/VoxelIsometricRenderer/Properties/Resources.Designer.cs b/VoxelIsometricRenderer/Properties/Resources.Designer.cs new file mode 100644 index 0000000..9e42955 --- /dev/null +++ b/VoxelIsometricRenderer/Properties/Resources.Designer.cs @@ -0,0 +1,303 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace VoxelIsometricRenderer.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("VoxelIsometricRenderer.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap _16xDefaultTile { + get { + object obj = ResourceManager.GetObject("_16xDefaultTile", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap BlueSquare { + get { + object obj = ResourceManager.GetObject("BlueSquare", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap ColourEdges { + get { + object obj = ResourceManager.GetObject("ColourEdges", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap dirt { + get { + object obj = ResourceManager.GetObject("dirt", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap flower { + get { + object obj = ResourceManager.GetObject("flower", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap grasside { + get { + object obj = ResourceManager.GetObject("grasside", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap grassmed { + get { + object obj = ResourceManager.GetObject("grassmed", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap grasstall { + get { + object obj = ResourceManager.GetObject("grasstall", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap grasstop { + get { + object obj = ResourceManager.GetObject("grasstop", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap greenSquare { + get { + object obj = ResourceManager.GetObject("greenSquare", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap leaves { + get { + object obj = ResourceManager.GetObject("leaves", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap log { + get { + object obj = ResourceManager.GetObject("log", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap logtop { + get { + object obj = ResourceManager.GetObject("logtop", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap OrangeSquare { + get { + object obj = ResourceManager.GetObject("OrangeSquare", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap ore1 { + get { + object obj = ResourceManager.GetObject("ore1", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap PinkSquare { + get { + object obj = ResourceManager.GetObject("PinkSquare", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap RedSquare { + get { + object obj = ResourceManager.GetObject("RedSquare", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap spruceleaves { + get { + object obj = ResourceManager.GetObject("spruceleaves", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap sprucelog { + get { + object obj = ResourceManager.GetObject("sprucelog", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap stone1 { + get { + object obj = ResourceManager.GetObject("stone1", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap stone2 { + get { + object obj = ResourceManager.GetObject("stone2", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap stone3 { + get { + object obj = ResourceManager.GetObject("stone3", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap vine { + get { + object obj = ResourceManager.GetObject("vine", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap YellowSquare { + get { + object obj = ResourceManager.GetObject("YellowSquare", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/VoxelIsometricRenderer/Properties/Resources.resx b/VoxelIsometricRenderer/Properties/Resources.resx new file mode 100644 index 0000000..3c05fd1 --- /dev/null +++ b/VoxelIsometricRenderer/Properties/Resources.resx @@ -0,0 +1,193 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + ..\Resources\BlueSquare.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\ColourEdges.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\dirt.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\flower.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\grasside.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\grassmed.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\grasstall.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\grasstop.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\greenSquare.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\leaves.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\log.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\logtop.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\OrangeSquare.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\ore1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\PinkSquare.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\RedSquare.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\spruceleaves.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\sprucelog.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\stone1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\stone2.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\stone3.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\vine.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\YellowSquare.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\16xDefaultTile.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/VoxelIsometricRenderer/Properties/Settings.Designer.cs b/VoxelIsometricRenderer/Properties/Settings.Designer.cs new file mode 100644 index 0000000..c718e98 --- /dev/null +++ b/VoxelIsometricRenderer/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace VoxelIsometricRenderer.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/VoxelIsometricRenderer/Properties/Settings.settings b/VoxelIsometricRenderer/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/VoxelIsometricRenderer/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/VoxelIsometricRenderer/Resources/16xDefaultTile.png b/VoxelIsometricRenderer/Resources/16xDefaultTile.png new file mode 100644 index 0000000..7eb255b Binary files /dev/null and b/VoxelIsometricRenderer/Resources/16xDefaultTile.png differ diff --git a/VoxelIsometricRenderer/Resources/BlueSquare.png b/VoxelIsometricRenderer/Resources/BlueSquare.png new file mode 100644 index 0000000..a92bfb8 Binary files /dev/null and b/VoxelIsometricRenderer/Resources/BlueSquare.png differ diff --git a/VoxelIsometricRenderer/Resources/ColourEdges.png b/VoxelIsometricRenderer/Resources/ColourEdges.png new file mode 100644 index 0000000..bc1b44c Binary files /dev/null and b/VoxelIsometricRenderer/Resources/ColourEdges.png differ diff --git a/VoxelIsometricRenderer/Resources/OrangeSquare.png b/VoxelIsometricRenderer/Resources/OrangeSquare.png new file mode 100644 index 0000000..50cb7bc Binary files /dev/null and b/VoxelIsometricRenderer/Resources/OrangeSquare.png differ diff --git a/VoxelIsometricRenderer/Resources/PinkSquare.png b/VoxelIsometricRenderer/Resources/PinkSquare.png new file mode 100644 index 0000000..2cf51fd Binary files /dev/null and b/VoxelIsometricRenderer/Resources/PinkSquare.png differ diff --git a/VoxelIsometricRenderer/Resources/RedSquare.png b/VoxelIsometricRenderer/Resources/RedSquare.png new file mode 100644 index 0000000..590983b Binary files /dev/null and b/VoxelIsometricRenderer/Resources/RedSquare.png differ diff --git a/VoxelIsometricRenderer/Resources/YellowSquare.png b/VoxelIsometricRenderer/Resources/YellowSquare.png new file mode 100644 index 0000000..b1a24b4 Binary files /dev/null and b/VoxelIsometricRenderer/Resources/YellowSquare.png differ diff --git a/VoxelIsometricRenderer/Resources/dirt.png b/VoxelIsometricRenderer/Resources/dirt.png new file mode 100644 index 0000000..df9ad63 Binary files /dev/null and b/VoxelIsometricRenderer/Resources/dirt.png differ diff --git a/VoxelIsometricRenderer/Resources/flower.png b/VoxelIsometricRenderer/Resources/flower.png new file mode 100644 index 0000000..8118fce Binary files /dev/null and b/VoxelIsometricRenderer/Resources/flower.png differ diff --git a/VoxelIsometricRenderer/Resources/grasside.png b/VoxelIsometricRenderer/Resources/grasside.png new file mode 100644 index 0000000..30fcccd Binary files /dev/null and b/VoxelIsometricRenderer/Resources/grasside.png differ diff --git a/VoxelIsometricRenderer/Resources/grassmed.png b/VoxelIsometricRenderer/Resources/grassmed.png new file mode 100644 index 0000000..8c4ad4e Binary files /dev/null and b/VoxelIsometricRenderer/Resources/grassmed.png differ diff --git a/VoxelIsometricRenderer/Resources/grasstall.png b/VoxelIsometricRenderer/Resources/grasstall.png new file mode 100644 index 0000000..359fa1d Binary files /dev/null and b/VoxelIsometricRenderer/Resources/grasstall.png differ diff --git a/VoxelIsometricRenderer/Resources/grasstop.png b/VoxelIsometricRenderer/Resources/grasstop.png new file mode 100644 index 0000000..7e16fa3 Binary files /dev/null and b/VoxelIsometricRenderer/Resources/grasstop.png differ diff --git a/VoxelIsometricRenderer/Resources/greenSquare.png b/VoxelIsometricRenderer/Resources/greenSquare.png new file mode 100644 index 0000000..981ca74 Binary files /dev/null and b/VoxelIsometricRenderer/Resources/greenSquare.png differ diff --git a/VoxelIsometricRenderer/Resources/image (2).png b/VoxelIsometricRenderer/Resources/image (2).png new file mode 100644 index 0000000..5234ff4 Binary files /dev/null and b/VoxelIsometricRenderer/Resources/image (2).png differ diff --git a/VoxelIsometricRenderer/Resources/image (2).webp b/VoxelIsometricRenderer/Resources/image (2).webp new file mode 100644 index 0000000..aafab6f Binary files /dev/null and b/VoxelIsometricRenderer/Resources/image (2).webp differ diff --git a/VoxelIsometricRenderer/Resources/image (3).png b/VoxelIsometricRenderer/Resources/image (3).png new file mode 100644 index 0000000..3b678f0 Binary files /dev/null and b/VoxelIsometricRenderer/Resources/image (3).png differ diff --git a/VoxelIsometricRenderer/Resources/leaves.png b/VoxelIsometricRenderer/Resources/leaves.png new file mode 100644 index 0000000..780a417 Binary files /dev/null and b/VoxelIsometricRenderer/Resources/leaves.png differ diff --git a/VoxelIsometricRenderer/Resources/log.png b/VoxelIsometricRenderer/Resources/log.png new file mode 100644 index 0000000..d780de3 Binary files /dev/null and b/VoxelIsometricRenderer/Resources/log.png differ diff --git a/VoxelIsometricRenderer/Resources/logtop.png b/VoxelIsometricRenderer/Resources/logtop.png new file mode 100644 index 0000000..6a4feb3 Binary files /dev/null and b/VoxelIsometricRenderer/Resources/logtop.png differ diff --git a/VoxelIsometricRenderer/Resources/ore1.png b/VoxelIsometricRenderer/Resources/ore1.png new file mode 100644 index 0000000..6f35b56 Binary files /dev/null and b/VoxelIsometricRenderer/Resources/ore1.png differ diff --git a/VoxelIsometricRenderer/Resources/spruceleaves.png b/VoxelIsometricRenderer/Resources/spruceleaves.png new file mode 100644 index 0000000..dd13751 Binary files /dev/null and b/VoxelIsometricRenderer/Resources/spruceleaves.png differ diff --git a/VoxelIsometricRenderer/Resources/sprucelog.png b/VoxelIsometricRenderer/Resources/sprucelog.png new file mode 100644 index 0000000..3fc7b1d Binary files /dev/null and b/VoxelIsometricRenderer/Resources/sprucelog.png differ diff --git a/VoxelIsometricRenderer/Resources/stone1.png b/VoxelIsometricRenderer/Resources/stone1.png new file mode 100644 index 0000000..697d2b4 Binary files /dev/null and b/VoxelIsometricRenderer/Resources/stone1.png differ diff --git a/VoxelIsometricRenderer/Resources/stone2.png b/VoxelIsometricRenderer/Resources/stone2.png new file mode 100644 index 0000000..d931abb Binary files /dev/null and b/VoxelIsometricRenderer/Resources/stone2.png differ diff --git a/VoxelIsometricRenderer/Resources/stone3.png b/VoxelIsometricRenderer/Resources/stone3.png new file mode 100644 index 0000000..734c5bb Binary files /dev/null and b/VoxelIsometricRenderer/Resources/stone3.png differ diff --git a/VoxelIsometricRenderer/Resources/vine.png b/VoxelIsometricRenderer/Resources/vine.png new file mode 100644 index 0000000..13e4eca Binary files /dev/null and b/VoxelIsometricRenderer/Resources/vine.png differ diff --git a/VoxelIsometricRenderer/Terrain4.Designer.cs b/VoxelIsometricRenderer/Terrain4.Designer.cs new file mode 100644 index 0000000..fc83a7d --- /dev/null +++ b/VoxelIsometricRenderer/Terrain4.Designer.cs @@ -0,0 +1,69 @@ +namespace VoxelIsometricRenderer +{ + partial class Terrain4 + { + /// + /// 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.Display = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.Display)).BeginInit(); + this.SuspendLayout(); + // + // Display + // + this.Display.BackColor = System.Drawing.Color.Aquamarine; + this.Display.Location = new System.Drawing.Point(12, 12); + this.Display.Name = "Display"; + this.Display.Size = new System.Drawing.Size(100, 50); + this.Display.TabIndex = 0; + this.Display.TabStop = false; + this.Display.Paint += new System.Windows.Forms.PaintEventHandler(this.Draw); + // + // Terrain4 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.Display); + this.DoubleBuffered = true; + this.Name = "Terrain4"; + this.Text = "Form1"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.KillThreads); + this.Load += new System.EventHandler(this.Terrain4_Load); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.KeyDownEvent); + this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.KeyUpEvent); + this.Resize += new System.EventHandler(this.ResizeAspectRatio); + ((System.ComponentModel.ISupportInitialize)(this.Display)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.PictureBox Display; + } +} + diff --git a/VoxelIsometricRenderer/Terrain4.cs b/VoxelIsometricRenderer/Terrain4.cs new file mode 100644 index 0000000..3b36c34 --- /dev/null +++ b/VoxelIsometricRenderer/Terrain4.cs @@ -0,0 +1,179 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; +using VoxelIsometricRenderer.Properties; + +namespace VoxelIsometricRenderer +{ + public partial class Terrain4 : Form + { + public static bool running = true; + public static List Voxels = new List(); + public static Thread MainThread; + public static float scale = 2f; + public static int FPS = 0; + public static int Frames = 0; + public Terrain4() + { + InitializeComponent(); + TextureManager.AddBitmap(Resources.grasside); + TextureManager.AddBitmap(Resources.grasstop); + TextureManager.AddBitmap(Resources.dirt); + TextureManager.AddBitmap(Resources.log); + TextureManager.AddBitmap(Resources.sprucelog); + TextureManager.AddBitmap(Resources.logtop); + TextureManager.AddBitmap(Resources.leaves); + TextureManager.AddBitmap(Resources.spruceleaves); + TextureManager.AddBitmap(Resources.stone1); + TextureManager.AddBitmap(Resources.stone2); + TextureManager.AddBitmap(Resources.stone3); + TextureManager.AddBitmap(Resources.ore1); + TextureManager.AddBitmap(Resources.flower); + TextureManager.AddBitmap(Resources.vine); + TextureManager.AddBitmap(Resources.grasstall); + TextureManager.AddBitmap(Resources.grassmed); + TextureManager.AddBitmap(Resources.BlueSquare); + TextureManager.AddBitmap(Resources.greenSquare); + TextureManager.AddBitmap(Resources.RedSquare); + TextureManager.AddBitmap(Resources.YellowSquare); + TextureManager.AddBitmap(Resources.PinkSquare); + TextureManager.AddBitmap(Resources.OrangeSquare); + TextureManager.AddBitmap(Resources.ColourEdges); + Voxels.Add(new Voxel(0, 0, 0, 0, 0, 0)); + Voxels.Add(new Voxel(9, 9, 9, 9, 9, 9)); + Voxels.Add(new Voxel(10, 10, 10, 10, 10, 10)); + Voxels.Add(new Voxel(11, 11, 11, 11, 11, 11)); + Voxels.Add(new Voxel(12, 12, 12, 12, 12, 12)); + Voxels.Add(new Voxel(3, 3, 3, 3, 3, 3)); + Voxels.Add(new Voxel(1, 1, 1, 1, 2, 3)); + Voxels.Add(new Voxel(4, 4, 4, 4, 6, 6)); + Voxels.Add(new Voxel(5, 5, 5, 5, 6, 6)); + Voxels.Add(new Voxel(7, 7, 7, 7, 7, 7)); + Voxels.Add(new Voxel(17, 18, 19, 20, 21, 22)); + Voxels.Add(new Voxel(23, 23, 23, 23, 23, 23)); + Voxels.Add(new Voxel(17, 18, 19, 20, -1, -1)); + Voxels.Add(new Voxel(23, 23, 23, 23, -1, -1)); + Voxels.Add(new Voxel(-1, -1, -1, -1, 21, 22)); + Voxels.Add(new Voxel(-1, -1, -1, -1, 23, 23)); + Voxels.Add(new Voxel(1, 13, 13, 13, 13, -1, -1)); + Voxels.Add(new Voxel(1, 14, 14, 14,14, -1, -1)); + Voxels.Add(new Voxel(1, 15, 15, 15,15, -1, -1)); + Voxels.Add(new Voxel(1, 16, 16, 16,16, -1, -1)); + Random rnd = new Random(); + for(int i = 0; i < 25; i++) + { + Voxels.Add(new Voxel(rnd.Next(0,TextureManager.textures.Count - 1), rnd.Next(0, TextureManager.textures.Count - 1), rnd.Next(0, TextureManager.textures.Count - 1), rnd.Next(0, TextureManager.textures.Count - 1), rnd.Next(0, TextureManager.textures.Count - 1), rnd.Next(0, TextureManager.textures.Count - 1))); + } + TextureManager.GenerateVoxelFaces(); + for (int i = 0; i < Voxels.Count; i++) + { + //TextureManager.CreateModel(Voxels[i]); + } + MainThread = new Thread(Runtime); + MainThread.SetApartmentState(ApartmentState.STA); + MainThread.Start(); + ResizeDisplay(); + } + + private void Runtime() + { + bool up = false; + double LightingFrameTime = Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds; + double SecondFrameTime = Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds; + while (running) + { + Display.Refresh(); + if (Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds - LightingFrameTime > 16) + { + LightingFrameTime = Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds; + LightingManager.UpdateLighting(); + LightingManager.sunAngles[0] += 5f; + LightingManager.sunAngles[1] += 1f; + } + if (Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds - SecondFrameTime > 1000) { + SecondFrameTime = Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds; + FPS = Frames; + Frames = 0; + } + if (up && LightingManager.AmbientColouring[0] < 1.5f) + { + //LightingManager.AmbientColouring[0] += 0.01f; + //LightingManager.AmbientColouring[1] += 0.01f; + //LightingManager.AmbientColouring[2] += 0.01f; + } + else if (up) up = false; + else if (LightingManager.AmbientColouring[0] > 0.5f) + { + //LightingManager.AmbientColouring[0] -= 0.01f; + //LightingManager.AmbientColouring[1] -= 0.01f; + //LightingManager.AmbientColouring[2] -= 0.01f; + } + else up = true; + } + } + private void Draw(object sender, PaintEventArgs e) + { + Graphics g = e.Graphics; + g.PixelOffsetMode = PixelOffsetMode.Half; + g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; + g.ScaleTransform(scale, scale); + int x = 0; + int y = 0; + foreach(Voxel voxel in Voxels) + { + voxel.Draw(g,2 + x,2 + y); + x += 36; + if ((x+32) * scale > Width) + { + y += 36; + x = 0; + } + } + g.ResetTransform(); + g.DrawString(String.Format("FPS: {0}", FPS), SystemFonts.DefaultFont, Brushes.Red, new PointF(0, 0)); + Frames++; + } + public void ResizeDisplay() + { + Display.Left = 0; + Display.Top = 0; + Display.Width = Width; + Display.Height = Height; + } + private void ResizeAspectRatio(object sender, EventArgs e) + { + ResizeDisplay(); + } + + private void KillThreads(object sender, FormClosingEventArgs e) + { + running = false; + } + + private void KeyDownEvent(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Up) scale += 0.25f; + if (e.KeyCode == Keys.Down) scale -= 0.25f; + } + + private void KeyUpEvent(object sender, KeyEventArgs e) + { + + } + + private void Terrain4_Load(object sender, EventArgs e) + { + + } + } +} diff --git a/VoxelIsometricRenderer/Terrain4.resx b/VoxelIsometricRenderer/Terrain4.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/VoxelIsometricRenderer/Terrain4.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/VoxelIsometricRenderer/Voxel.cs b/VoxelIsometricRenderer/Voxel.cs new file mode 100644 index 0000000..a3d84ec --- /dev/null +++ b/VoxelIsometricRenderer/Voxel.cs @@ -0,0 +1,580 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.Linq; +using System.Security.AccessControl; +using System.Security.Policy; +using System.Text; +using System.Threading.Tasks; +using VoxelIsometricRenderer.Properties; + +namespace VoxelIsometricRenderer +{ + public enum LightDirection + { + North, + NorthEast, + NorthWest, + East, + West, + SouthEast, + SouthWest, + South + } + public static class LightingManager + { + public static float[] AmbientColouring = new float[] { 1.0f, 1.0f, 1.0f }; + public static float[] AmbientMinimums = new float[] { 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f }; + public static float[] DefaultValues = new float[] { 0.6f, 0.6f, 0.6f, 0.6f, 1.0f, 0.4f }; + public static float[] SunModifiedValues = new float[] { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; + public static float[] sunAngles = new float[] { 180, 0 }; + public static LightDirection SunAngle = LightDirection.North; + + public static void UpdateLighting() + { + float[] AngleRanges = new float[] { 0,45, 90, 135, 180, 225, 270, 315 }; + float[] AngleOffsets = new float[] { 0,180, 90, 270, -1, -1}; + LightDirection[] directions = new LightDirection[] { LightDirection.North, LightDirection.NorthEast, LightDirection.East, LightDirection.SouthEast, LightDirection.South, LightDirection.SouthWest, LightDirection.West, LightDirection.NorthWest }; + if (sunAngles[0] > 360) sunAngles[0] -= 360; + if (sunAngles[1] > 360) sunAngles[1] -= 360; + if (sunAngles[0] <= -360) sunAngles[0] += 360; + if (sunAngles[1] <= -360) sunAngles[1] += 360; + float CurrentAngle = 0; + int AngleIndex = 0; + for (int i = 0; i < AngleRanges.Length; i++) + { + if (sunAngles[0] < AngleRanges[i]) + { + CurrentAngle = AngleRanges[i]; + AngleIndex = i; + break; + } + } + if (Square(CurrentAngle - sunAngles[0]) > Square(sunAngles[0] - AngleRanges[AngleIndex - 1 >= 0 ? AngleIndex - 1 : AngleRanges.Length - 1])) + { + AngleIndex = AngleIndex - 1 >= 0 ? AngleIndex - 1 : AngleRanges.Length - 1; + } + SunAngle = directions[AngleIndex]; + for (int i = 0; i < SunModifiedValues.Length - 2; i++) + { + SunModifiedValues[i] = (float)((1 + Math.Cos(Math.PI * (sunAngles[0] + AngleOffsets[i]) / 180)/ 2.0) * (float)( 1 + Math.Sin(Math.PI * (sunAngles[1] + 45) / 180))/ 2.0); + } + for (int i = SunModifiedValues.Length - 2; i < SunModifiedValues.Length; i++) + { + SunModifiedValues[i] = (float)Math.Max((1 + Math.Cos(Math.PI * (sunAngles[1]) / 180)) / 2.0, 0.3f); + } + } + private static float Square(float ValueIn) + { + return ValueIn * ValueIn; + } + } + public static class TextureManager + { + public static List textures = new List() {Resources._16xDefaultTile}; + public static List PreCompiledModels = new List(); + public static Bitmap[,] GeneratedFaceTextures = new Bitmap[0,0]; + public static int VoxelCount = 0; + public static Bitmap GetModel(int modelNum) + { + return PreCompiledModels[modelNum]; + } + public static void CreateModel(Voxel voxel) + { + if (GeneratedFaceTextures.GetLength(1) < 6) GenerateVoxelFaces(); + int ImageWidth = 0; + int ImageHeight = 0; + int[] faces = voxel.getFaces(); + int[] DrawOrder = voxel.GetDrawOrder(); + for(int i = 0; i < faces.Length; i++) + { + if (faces[i] >= 0 && GeneratedFaceTextures[faces[i], i].Width > ImageWidth) ImageWidth = GeneratedFaceTextures[faces[i], i].Width; + if (faces[i] >= 0 && GeneratedFaceTextures[faces[i], i].Height > ImageHeight) ImageHeight = GeneratedFaceTextures[faces[i], i].Height; + } + Bitmap GeneratedModel = new Bitmap(ImageWidth, ImageHeight); + voxel.Draw(Graphics.FromImage(GeneratedModel),0,0); + voxel.SetPreCompiledModel(PreCompiledModels.Count); + PreCompiledModels.Add(GeneratedModel); + GeneratedModel.Save("Model" + voxel.GetModelNum() + ".png"); + } + public static float GetSunlightValue(int face) + { + return LightingManager.SunModifiedValues[face] * LightingManager.DefaultValues[face]; + } + public static float GetShadingValue(float LightValue, int RGBIndex, int FaceIndex) + { + return (float)Math.Max(LightValue * LightingManager.AmbientColouring[RGBIndex], LightingManager.AmbientMinimums[FaceIndex]); + } + public static ImageAttributes GetShadow(int face) + { + ImageAttributes imageAttributes; + float[][] colorMatrixElements; + ColorMatrix colorMatrix; + switch (face) { + case 0: + colorMatrixElements = new float[][]{ + new float[] { GetShadingValue(GetSunlightValue(face), 0,face), 0, 0, 0, 0}, // red + new float[] {0, GetShadingValue(GetSunlightValue(face), 1, face), 0, 0, 0}, // green + new float[] {0, 0, GetShadingValue(GetSunlightValue(face), 2, face), 0, 0}, // blue + new float[] {0, 0, 0, 1, 0}, // alpha + new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2 + + colorMatrix = new ColorMatrix(colorMatrixElements); + imageAttributes = new ImageAttributes(); + imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); + return imageAttributes; + case 1: + colorMatrixElements = new float[][]{ + new float[] { GetShadingValue(GetSunlightValue(face), 0,face), 0, 0, 0, 0}, // red + new float[] {0, GetShadingValue(GetSunlightValue(face), 1, face), 0, 0, 0}, // green + new float[] {0, 0, GetShadingValue(GetSunlightValue(face), 2, face), 0, 0}, // blue + new float[] {0, 0, 0, 1, 0}, // alpha + new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2 + + colorMatrix = new ColorMatrix(colorMatrixElements); + imageAttributes = new ImageAttributes(); + imageAttributes.SetColorMatrix( colorMatrix,ColorMatrixFlag.Default,ColorAdjustType.Bitmap); + return imageAttributes; + case 2: + colorMatrixElements = new float[][]{ + new float[] { GetShadingValue(GetSunlightValue(face), 0,face), 0, 0, 0, 0}, // red + new float[] {0, GetShadingValue(GetSunlightValue(face), 1, face), 0, 0, 0}, // green + new float[] {0, 0, GetShadingValue(GetSunlightValue(face), 2, face), 0, 0}, // blue + new float[] {0, 0, 0, 1, 0}, // alpha + new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2 + + colorMatrix = new ColorMatrix(colorMatrixElements); + imageAttributes = new ImageAttributes(); + imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); + return imageAttributes; + case 3: + colorMatrixElements = new float[][]{ + new float[] { GetShadingValue(GetSunlightValue(face), 0,face), 0, 0, 0, 0}, // red + new float[] {0, GetShadingValue(GetSunlightValue(face), 1, face), 0, 0, 0}, // green + new float[] {0, 0, GetShadingValue(GetSunlightValue(face), 2, face), 0, 0}, // blue + new float[] {0, 0, 0, 1, 0}, // alpha + new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2 + + colorMatrix = new ColorMatrix(colorMatrixElements); + imageAttributes = new ImageAttributes(); + imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); + return imageAttributes; + case 4: + colorMatrixElements = new float[][]{ + new float[] { GetShadingValue(GetSunlightValue(face), 0,face), 0, 0, 0, 0}, // red + new float[] {0, GetShadingValue(GetSunlightValue(face), 1, face), 0, 0, 0}, // green + new float[] {0, 0, GetShadingValue(GetSunlightValue(face), 2, face), 0, 0}, // blue + new float[] {0, 0, 0, 1, 0}, // alpha + new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2 + + colorMatrix = new ColorMatrix(colorMatrixElements); + imageAttributes = new ImageAttributes(); + imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); + return imageAttributes; + case 5: + colorMatrixElements = new float[][]{ + new float[] { GetShadingValue(GetSunlightValue(face), 0,face), 0, 0, 0, 0}, // red + new float[] {0, GetShadingValue(GetSunlightValue(face), 1, face), 0, 0, 0}, // green + new float[] {0, 0, GetShadingValue(GetSunlightValue(face), 2, face), 0, 0}, // blue + new float[] {0, 0, 0, 1, 0}, // alpha + new float[] {0, 0, -0, 0, 1}}; // three translations of 0.2 + + colorMatrix = new ColorMatrix(colorMatrixElements); + imageAttributes = new ImageAttributes(); + imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); + return imageAttributes; + default: + imageAttributes = new ImageAttributes(); + return imageAttributes; + + } + } + public static Point IntegerCalculateIsometricProjection(int width, int height, int X, int Y, int Z, int Corner) + { + switch (Corner) + { + case 0: + return new Point(width / 2 + (int)((X * 1) + (Z * -1)), + height / 2 + (int)Math.Ceiling((X * 0.5f) + (Z * 0.5f) - (Y / 3) * 2)); + case 1: + return new Point(width / 2 + (int)((X * 1) + (Z * -1)), + height / 2 + (int)Math.Floor((X * 0.5f) + (Z * 0.5f) - (Y / 3) * 2)); + case 2: + return new Point(-1 + width / 2 + (int)((X * 1) + (Z * -1)), + height / 2 + (int)Math.Floor((X * 0.5f) + (Z * 0.5f) - (Y / 3) * 2)); + default: + return new Point(-1 + width / 2 + (int)((X * 1) + (Z * -1)), + height / 2 + (int)Math.Ceiling((X * 0.5f) + (Z * 0.5f) - (Y / 3) * 2)); + } + } + public static Point IntegerCalculateIsometricProjection(int width, int height, int X, int Y, int Z) + { + return new Point(width / 2 + (int)((X * 1) + (Z * -1)), + height / 2 + (int)((X * 0.5f) + (Z * 0.5f) - (Y / 3) * 2)); + } + public static PointF CalculateIsometricProjection(double[] Position, int width, int height, int X, int Y, int Z) + { + return new PointF(width / 2 + (float)(((/*Globals.CameraX*/ +X + Position[0]) * 0.5) + ((/*Globals.CameraZ +*/ Z + Position[1]) * -0.5)), + height / 2 + (float)(((/*Globals.CameraX*/ +X + Position[0]) * 0.25f) + ((/*Globals.CameraZ*/ +Z + Position[1]) * 0.25f) - (((/*Globals.CameraY*/ +Position[2]) + (Y / 3) * 2)))); + } + public static Bitmap GetVoxelFaceBitmap(int index, int face) + { + if (GeneratedFaceTextures.GetLength(1) < 6) GenerateVoxelFaces(); + return GeneratedFaceTextures[index,face]; + } + public static Bitmap GetBitmap(int index) + { + return textures[index]; + } + public static void AddBitmap(Bitmap texture) + { + textures.Add(texture); + } + public static void GenerateVoxelFaces() + { + GeneratedFaceTextures = new Bitmap[textures.Count, 6]; + for (int i = 0; i < textures.Count; i++) + { + for (int face = 0; face < 6; face++) + { + Bitmap SkewedTexture = new Bitmap(textures[i].Width * 2, textures[i].Height * 2); + int y = 0;// textures[i].Height; + switch (face) + { + case 0: + y = 1; + for(int x = 0; x < textures[i].Width; x++) + { + for(int ypx = 0; ypx < textures[i].Height; ypx++) + { + SkewedTexture.SetPixel(textures[i].Width+ x, y + ypx, textures[i].GetPixel(x, ypx)); + } + if (x % 2 != 0) y++; + } + y = 0; + break; + case 1: + for (int x = textures[i].Width - 1; x >= 0 ; x--) + { + for (int ypx = 0; ypx < textures[i].Height; ypx++) + { + SkewedTexture.SetPixel(x, SkewedTexture.Height - (y + ypx + 1), textures[i].GetPixel(x, textures[i].Height - 1 - ypx)); + } + if (x % 2 == 0) y++; + } + y = 0; + break; + case 2: + for (int x = 0; x < textures[i].Width; x++) + { + for (int ypx = 0; ypx < textures[i].Height; ypx++) + { + SkewedTexture.SetPixel(textures[i].Width + x, SkewedTexture.Height - (y + ypx + 1), textures[i].GetPixel(x, textures[i].Height - 1 - ypx)); + } + if (x % 2 != 0) y++; + } + y = 0; + break; + case 3: + y = 1; + for (int x = textures[i].Width - 1; x >= 0; x--) + { + for (int ypx = 0; ypx < textures[i].Height; ypx++) + { + SkewedTexture.SetPixel(x, y + ypx, textures[i].GetPixel(x, ypx)); + } + if (x % 2 == 0) y++; + } + y = 0; + break; + case 4: + Bitmap[] Textures = new Bitmap[4]; + Bitmap MergedTextures = new Bitmap(SkewedTexture.Width, SkewedTexture.Height); + for (int l = 0; l < 4; l++) + { + Textures[l] = new Bitmap(SkewedTexture.Width, SkewedTexture.Height); + } + for(int l = 0; l < 4; l++) + { + for (int x = 0; x < textures[i].Width; x++) + { + for (int ypx = 0; ypx < textures[i].Height; ypx++) + { + Point PixelLocation = IntegerCalculateIsometricProjection(textures[i].Width * 2, 0, x, 0, ypx,l); + PixelLocation.X = Math.Max(Math.Min(PixelLocation.X, SkewedTexture.Width - 1), 0); + PixelLocation.Y = Math.Max(Math.Min(PixelLocation.Y, SkewedTexture.Height - 1), 0); + Textures[l].SetPixel(PixelLocation.X, PixelLocation.Y, textures[i].GetPixel(x, ypx)); + } + } + } + for (int l = 0; l < 4; l++) + { + int Startx = 0; + int Starty = 0; + int endX = Textures[l].Width; + int endY = Textures[l].Height; + switch (l) + { + case 1: + Startx = Textures[l].Width / 2; + Starty = 0; + endX = Textures[l].Width; + endY = Textures[l].Height/4; + break; + case 0: + Startx = Textures[l].Width / 2; + Starty = Textures[l].Height / 4; + endX = Textures[l].Width; + endY = Textures[l].Height/2; + break; + case 2: + Startx = 0; + Starty = 0; + endX = Textures[l].Width/2; + endY = Textures[l].Height / 4 ; + break; + case 3: + Startx = 0; + Starty = Textures[l].Height / 4; + endX = Textures[l].Width/2; + endY = Textures[l].Height/2; + break; + } + for(int x = Startx; x < endX; x++) + { + for (int ypx = Starty; ypx < endY;ypx++) + { + MergedTextures.SetPixel(x, ypx, Textures[l].GetPixel(x, ypx)); + } + } + } + SkewedTexture = MergedTextures; + y = 0; + break; + case 5: + Textures = new Bitmap[4]; + MergedTextures = new Bitmap(SkewedTexture.Width, SkewedTexture.Height); + for (int l = 0; l < 4; l++) + { + Textures[l] = new Bitmap(SkewedTexture.Width, SkewedTexture.Height); + } + for (int l = 0; l < 4; l++) + { + for (int x = 0; x < textures[i].Width; x++) + { + for (int ypx = 0; ypx < textures[i].Height; ypx++) + { + Point PixelLocation = IntegerCalculateIsometricProjection(textures[i].Width * 2, 0, x, 0, ypx, l); + PixelLocation.X = Math.Max(Math.Min(PixelLocation.X, SkewedTexture.Width - 1), 0); + PixelLocation.Y = Math.Max(Math.Min(textures[i].Height + PixelLocation.Y, SkewedTexture.Height - 1), 0); + Textures[l].SetPixel(PixelLocation.X, PixelLocation.Y, textures[i].GetPixel(x, ypx)); + } + } + } + for (int l = 0; l < 4; l++) + { + int Startx = 0; + int Starty = 0; + int endX = Textures[l].Width; + int endY = Textures[l].Height; + switch (l) + { + case 1: + Startx = Textures[l].Width / 2; + Starty = Textures[l].Height / 2; + endX = Textures[l].Width; + endY = (Textures[l].Height / 4) * 3; + break; + case 0: + Startx = Textures[l].Width / 2; + Starty = (Textures[l].Height / 4) * 3; + endX = Textures[l].Width; + endY = Textures[l].Height; + break; + case 2: + Startx = 0; + Starty = Textures[l].Height / 2; + endX = Textures[l].Width / 2; + endY = (Textures[l].Height / 4) * 3; + break; + case 3: + Startx = 0; + Starty = (Textures[l].Height / 4)*3; + endX = Textures[l].Width / 2; + endY = Textures[l].Height; + break; + } + for (int x = Startx; x < endX; x++) + { + for (int ypx = Starty; ypx < endY; ypx++) + { + MergedTextures.SetPixel(x, ypx, Textures[l].GetPixel(x, ypx)); + } + } + } + SkewedTexture = MergedTextures; + y = 0; + break; + + } + GeneratedFaceTextures[i, face] = SkewedTexture; + } + } + } + } + public class Voxel + { + int VoxelNum; + int[] faces = new int[6]; + int[] DrawOrder = new int[] { 5, 0, 3, 1, 2, 4 }; + int ModelType = 0; + int ModelNum = -1; + public int[] getFaces() + { + return faces; + } + public int[] GetDrawOrder() + { + return DrawOrder; + } + public int GetModelNum() + { + return ModelNum; + } + public int GetModelType() + { + return ModelType; + } + public int GetVoxelNum() + { + return VoxelNum; + } + public Voxel(int ModelType,int NorthFace, int SouthFace, int EastFace, int WestFace, int UpFace, int DownFace) + { + this.ModelType = ModelType; + faces = new int[] { NorthFace, SouthFace, EastFace, WestFace, UpFace, DownFace }; + VoxelNum = TextureManager.VoxelCount; + TextureManager.VoxelCount++; + } + public void SetPreCompiledModel(int ModelNum) + { + this.ModelNum = ModelNum; + } + public Voxel(int NorthFace, int SouthFace, int EastFace, int WestFace, int UpFace, int DownFace) + { + faces = new int[] {NorthFace, SouthFace, EastFace, WestFace, UpFace, DownFace}; + VoxelNum = TextureManager.VoxelCount; + TextureManager.VoxelCount++; + } + virtual public void Draw(Graphics g, int x, int y) + { + for (int i = 0; i < DrawOrder.Length; i++) { + if (faces[DrawOrder[i]] >= 0) + { + if (ModelNum == -1) + { + Bitmap Side; + switch (ModelType) + { + case 0: + Side = GetRenderedSide(DrawOrder[i]); + g.DrawImage(Side, new Rectangle(x, y, Side.Width, Side.Height), 0, 0, Side.Width, Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(DrawOrder[i])); + break; + default: + + switch (DrawOrder[i]) + { + case 0: + Side = GetRenderedSide(0); + g.DrawImage(Side, new Rectangle(x - (Side.Width / 4), y, Side.Width, Side.Height),0,0,Side.Width,Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(0)); + break; + case 1: + Side = GetRenderedSide(1); + g.DrawImage(Side, new Rectangle(x + (Side.Width / 4), y - (Side.Height / 4), Side.Width, Side.Height),0,0,Side.Width,Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(1)); + break; + case 2: + Side = GetRenderedSide(2); + g.DrawImage(Side, new Rectangle(x - (Side.Width / 4), y - (Side.Height / 4), Side.Width, Side.Height),0,0,Side.Width,Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(2)); + break; + case 3: + Side = GetRenderedSide(3); + g.DrawImage(Side, new Rectangle( x + (Side.Width / 4),y,Side.Width,Side.Height),0,0,Side.Width,Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(3)); + break; + default: + Side = GetRenderedSide(DrawOrder[i]); + g.DrawImage(Side, new Rectangle(x, y, Side.Width, Side.Height), 0, 0, Side.Width, Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(DrawOrder[i])); + break; + } + break; + } + } + else + { + g.DrawImage(TextureManager.GetModel(ModelNum), x, y); + } + } + } + } + public Bitmap GetRenderedSide(int FaceIndex) + { + return TextureManager.GetVoxelFaceBitmap(faces[FaceIndex], FaceIndex); + } + public int GetFace(int index) + { + return faces[index]; + } + public int GetNorthFace() + { + return faces[0]; + } + public int GetSouthFace() + { + return faces[1]; + } + public int GetEastFace() + { + return faces[2]; + } + public int GetWestFace() + { + return faces[3]; + } + public int GetUpFace() + { + return faces[4]; + } + public int GetDownFace() + { + return faces[5]; + } + public void SetFace(int face, int Texture) + { + faces[face] = Texture; + } + public void SetNorthFace(int Texture) + { + faces[0] = Texture; + } + public void SetSouthFace(int Texture) + { + faces[1] = Texture; + } + public void SetEastFace(int Texture) + { + faces[2] = Texture; + } + public void SetWestFace(int Texture) + { + faces[3] = Texture; + } + public void SetUpFace(int Texture) + { + faces[4] = Texture; + } + public void SetDownFace(int Texture) + { + faces[5] = Texture; + } + } +} diff --git a/VoxelIsometricRenderer/VoxelIsometricRenderer.csproj b/VoxelIsometricRenderer/VoxelIsometricRenderer.csproj new file mode 100644 index 0000000..92e04de --- /dev/null +++ b/VoxelIsometricRenderer/VoxelIsometricRenderer.csproj @@ -0,0 +1,164 @@ + + + + + Debug + AnyCPU + {BC07C626-47CC-41D7-BF64-E0842741C697} + WinExe + VoxelIsometricRenderer + VoxelIsometricRenderer + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Terrain4.cs + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + Terrain4.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file