Thread: [Rpgworldmodel-commits] SF.net SVN: rpgworldmodel: [8] src/test_applications/ItemsViewer
Status: Inactive
Brought to you by:
deadwood_pl
From: <pos...@us...> - 2006-06-26 15:10:57
|
Revision: 8 Author: poserdev Date: 2006-06-26 08:10:32 -0700 (Mon, 26 Jun 2006) ViewCVS: http://svn.sourceforge.net/rpgworldmodel/?rev=8&view=rev Log Message: ----------- Some more simple ItemsViewer implementation. It now work with the app config file. Models folder should by stored in the app startup path, like: ....\bin\Debug\Models. Some basic model rotation, but I really need to get some tutorials on DirectX transformations :D Modified Paths: -------------- src/test_applications/ItemsViewer/ItemsViewer.csproj src/test_applications/ItemsViewer/Program.cs src/test_applications/ItemsViewer/Surface.cs Added Paths: ----------- src/test_applications/ItemsViewer/App.config src/test_applications/ItemsViewer/IModel.cs src/test_applications/ItemsViewer/Model.cs src/test_applications/ItemsViewer/OpenModelDialog.Designer.cs src/test_applications/ItemsViewer/OpenModelDialog.cs src/test_applications/ItemsViewer/ViewController.cs src/test_applications/ItemsViewer/ViewState.cs Removed Paths: ------------- src/test_applications/ItemsViewer/Surface.Designer.cs src/test_applications/ItemsViewer/Surface.resx Added: src/test_applications/ItemsViewer/App.config =================================================================== --- src/test_applications/ItemsViewer/App.config (rev 0) +++ src/test_applications/ItemsViewer/App.config 2006-06-26 15:10:32 UTC (rev 8) @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8" ?> + +<configuration> + <configSections> + <section name="models" type="System.Configuration.NameValueSectionHandler" /> + </configSections> + + <models> + <add key="Long Iron Sword" value="Models\sword.x" /> + </models> +</configuration> \ No newline at end of file Added: src/test_applications/ItemsViewer/IModel.cs =================================================================== --- src/test_applications/ItemsViewer/IModel.cs (rev 0) +++ src/test_applications/ItemsViewer/IModel.cs 2006-06-26 15:10:32 UTC (rev 8) @@ -0,0 +1,24 @@ +using System; + +using Microsoft.DirectX.Direct3D; + +namespace RPGWorldModel.ItemsViewer +{ + public interface IModel + { + Mesh Object + { + get; + } + + Material[] Materials + { + get; + } + + Texture[] Textures + { + get; + } + } +} Modified: src/test_applications/ItemsViewer/ItemsViewer.csproj =================================================================== --- src/test_applications/ItemsViewer/ItemsViewer.csproj 2006-06-25 10:49:06 UTC (rev 7) +++ src/test_applications/ItemsViewer/ItemsViewer.csproj 2006-06-26 15:10:32 UTC (rev 8) @@ -7,7 +7,7 @@ <ProjectGuid>{57684296-F942-4797-8C0F-ADB151A02477}</ProjectGuid> <OutputType>WinExe</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>ModelViewer</RootNamespace> + <RootNamespace>RPGWorldModel.ItemsViewer</RootNamespace> <AssemblyName>ModelViewer</AssemblyName> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> @@ -37,24 +37,35 @@ <Reference Include="Microsoft.DirectX.Direct3DX, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> <Private>False</Private> </Reference> + <Reference Include="RPGWorldModel.Abstracts, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\RPGWorldModel.Abstracts\bin\Debug\RPGWorldModel.Abstracts.dll</HintPath> + </Reference> <Reference Include="System" /> + <Reference Include="System.configuration" /> <Reference Include="System.Drawing" /> <Reference Include="System.Windows.Forms" /> </ItemGroup> <ItemGroup> + <Compile Include="IModel.cs" /> + <Compile Include="Model.cs" /> + <Compile Include="OpenModelDialog.cs"> + <SubType>Form</SubType> + </Compile> + <Compile Include="OpenModelDialog.Designer.cs"> + <DependentUpon>OpenModelDialog.cs</DependentUpon> + </Compile> <Compile Include="Surface.cs"> <SubType>Form</SubType> </Compile> - <Compile Include="Surface.Designer.cs"> - <DependentUpon>Surface.cs</DependentUpon> - </Compile> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> - <EmbeddedResource Include="Surface.resx"> - <SubType>Designer</SubType> - <DependentUpon>Surface.cs</DependentUpon> - </EmbeddedResource> + <Compile Include="ViewController.cs" /> + <Compile Include="ViewState.cs" /> </ItemGroup> + <ItemGroup> + <None Include="App.config" /> + </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. Added: src/test_applications/ItemsViewer/Model.cs =================================================================== --- src/test_applications/ItemsViewer/Model.cs (rev 0) +++ src/test_applications/ItemsViewer/Model.cs 2006-06-26 15:10:32 UTC (rev 8) @@ -0,0 +1,69 @@ +using System; +using System.IO; +using System.Windows.Forms; + +using Microsoft.DirectX; +using Microsoft.DirectX.Direct3D; + +namespace RPGWorldModel.ItemsViewer +{ + public class Model : IModel + { + private Mesh m_Object; + private Material[] m_Materials; + private Texture[] m_Textures; + + public Model(string source, Device device) + { + + + if (File.Exists(source)) + { + Directory.SetCurrentDirectory(Application.StartupPath + + Path.DirectorySeparatorChar + Path.GetDirectoryName(source)); + + // Load the model + ExtendedMaterial[] materials; + this.m_Object = Mesh.FromFile(System.IO.Path.GetFileName(source), MeshFlags.SystemMemory, device, out materials); + + this.m_Textures = new Texture[materials.Length]; + this.m_Materials = new Material[materials.Length]; + + for (int i = 0; i < materials.Length; i++) + { + this.m_Materials[i] = materials[i].Material3D; + this.m_Materials[i].Ambient = this.m_Materials[i].Diffuse; + this.m_Textures[i] = TextureLoader.FromFile(device, materials[i].TextureFilename); + } + } + } + + #region IModel Members + + public Mesh Object + { + get + { + return this.m_Object; + } + } + + public Material[] Materials + { + get + { + return this.m_Materials; + } + } + + public Texture[] Textures + { + get + { + return this.m_Textures; + } + } + + #endregion + } +} Added: src/test_applications/ItemsViewer/OpenModelDialog.Designer.cs =================================================================== --- src/test_applications/ItemsViewer/OpenModelDialog.Designer.cs (rev 0) +++ src/test_applications/ItemsViewer/OpenModelDialog.Designer.cs 2006-06-26 15:10:32 UTC (rev 8) @@ -0,0 +1,84 @@ +namespace RPGWorldModel.ItemsViewer +{ + partial class OpenModelDialog + { + /// <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.m_List = new System.Windows.Forms.ListBox(); + this.m_Picture = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.m_Picture)).BeginInit(); + this.SuspendLayout(); + // + // m_List + // + this.m_List.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.m_List.Dock = System.Windows.Forms.DockStyle.Left; + this.m_List.Font = new System.Drawing.Font("Microsoft Sans Serif", 12.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.m_List.IntegralHeight = false; + this.m_List.ItemHeight = 20; + this.m_List.Location = new System.Drawing.Point(0, 0); + this.m_List.Margin = new System.Windows.Forms.Padding(0); + this.m_List.Name = "m_List"; + this.m_List.ScrollAlwaysVisible = true; + this.m_List.Size = new System.Drawing.Size(400, 168); + this.m_List.TabIndex = 0; + this.m_List.DoubleClick += new System.EventHandler(this.m_List_DoubleClick); + this.m_List.SelectedIndexChanged += new System.EventHandler(this.m_List_SelectedIndexChanged); + // + // m_Picture + // + this.m_Picture.Dock = System.Windows.Forms.DockStyle.Fill; + this.m_Picture.Location = new System.Drawing.Point(400, 0); + this.m_Picture.Name = "m_Picture"; + this.m_Picture.Size = new System.Drawing.Size(194, 168); + this.m_Picture.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.m_Picture.TabIndex = 1; + this.m_Picture.TabStop = false; + // + // OpenModelDialog + // + this.AutoSize = true; + this.ClientSize = new System.Drawing.Size(594, 168); + this.Controls.Add(this.m_Picture); + this.Controls.Add(this.m_List); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "OpenModelDialog"; + this.ShowIcon = false; + this.Text = "Model"; + ((System.ComponentModel.ISupportInitialize)(this.m_Picture)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListBox m_List; + private System.Windows.Forms.PictureBox m_Picture; + } +} \ No newline at end of file Added: src/test_applications/ItemsViewer/OpenModelDialog.cs =================================================================== --- src/test_applications/ItemsViewer/OpenModelDialog.cs (rev 0) +++ src/test_applications/ItemsViewer/OpenModelDialog.cs 2006-06-26 15:10:32 UTC (rev 8) @@ -0,0 +1,54 @@ +using System; +using System.IO; +using System.Collections.Specialized; +using System.ComponentModel; +using System.Drawing; +using System.Windows.Forms; + +namespace RPGWorldModel.ItemsViewer +{ + public partial class OpenModelDialog : Form + { + private string m_SelectedModel; + private NameValueCollection m_Models; + + public OpenModelDialog(NameValueCollection models) + { + InitializeComponent(); + + this.m_Models = models; + + foreach (string key in this.m_Models.AllKeys) + this.m_List.Items.Add(key); + + this.m_List.SelectedIndex = -1; + } + + private void m_List_SelectedIndexChanged(object sender, EventArgs e) + { + string file = this.m_Models[this.m_List.SelectedItem.ToString()]; + // Load the model image + this.m_Picture.Load(Path.GetDirectoryName(file) + Path.DirectorySeparatorChar + + Path.GetFileNameWithoutExtension(file) + @".bmp"); + } + + private void m_List_DoubleClick(object sender, EventArgs e) + { + if (this.m_List.SelectedItem != null) + { + this.m_SelectedModel = this.m_List.SelectedItem.ToString(); + + this.DialogResult = DialogResult.OK; + this.Close(); + } + } + + public string SelectedModel + { + get + { + return this.m_SelectedModel; + } + } + } +} \ No newline at end of file Modified: src/test_applications/ItemsViewer/Program.cs =================================================================== --- src/test_applications/ItemsViewer/Program.cs 2006-06-25 10:49:06 UTC (rev 7) +++ src/test_applications/ItemsViewer/Program.cs 2006-06-26 15:10:32 UTC (rev 8) @@ -1,19 +1,13 @@ using System; -using System.Collections.Generic; -using System.Windows.Forms; -namespace ModelViewer +namespace RPGWorldModel.ItemsViewer { static class Program { - /// <summary> - /// The main entry point for the application. - /// </summary> [STAThread] static void Main() { - Surface surface = new Surface(); - surface.ShowDialog(); + ViewController view = new ViewController(); } } } \ No newline at end of file Deleted: src/test_applications/ItemsViewer/Surface.Designer.cs =================================================================== --- src/test_applications/ItemsViewer/Surface.Designer.cs 2006-06-25 10:49:06 UTC (rev 7) +++ src/test_applications/ItemsViewer/Surface.Designer.cs 2006-06-26 15:10:32 UTC (rev 8) @@ -1,51 +0,0 @@ -namespace ModelViewer -{ - partial class Surface - { - /// <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.SuspendLayout(); - // - // Surface - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(794, 568); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.Name = "Surface"; - this.ShowIcon = false; - this.WindowState = System.Windows.Forms.FormWindowState.Maximized; - this.Load += new System.EventHandler(this.Surface_Load); - this.ResumeLayout(false); - - } - - #endregion - - } -} - Modified: src/test_applications/ItemsViewer/Surface.cs =================================================================== --- src/test_applications/ItemsViewer/Surface.cs 2006-06-25 10:49:06 UTC (rev 7) +++ src/test_applications/ItemsViewer/Surface.cs 2006-06-26 15:10:32 UTC (rev 8) @@ -7,37 +7,78 @@ using Microsoft.DirectX; using Microsoft.DirectX.Direct3D; -namespace ModelViewer +namespace RPGWorldModel.ItemsViewer { - public partial class Surface : Form + public sealed partial class Surface : Form { - private Device m_RenderingDevice = null; - private PresentParameters m_DeviceParameters = null; - private Mesh m_SceenObjct = null; - private Material[] m_ObjectMaterials; - private Texture[] m_ObjectTextures; + private Device m_RenderingDevice; + private IModel m_Model; public Surface() { - InitializeComponent(); + this.SuspendLayout(); + + this.ClientSize = new System.Drawing.Size(800, 600); + this.ShowIcon = false; + this.KeyDown += new KeyEventHandler(Surface_KeyDown); + this.Paint += new PaintEventHandler(Surface_Paint); + + this.ResumeLayout(false); + + this.InitializeDevice(); } - private void SetMetrices() + void Surface_Paint(object sender, PaintEventArgs e) { - this.m_RenderingDevice.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 0.0f, -100.0f), - new Vector3(0.0f, 0.0f, 0.0f), - new Vector3(1.0f, 1.0f, 0.0f)); + this.RenderSceen(); + } - this.m_RenderingDevice.Transform.World = Matrix.Scaling(0.1f, 0.1f, 0.1f); - + float yAngle = 0.0f; + float xAngle = 0.0f; + + void Surface_KeyDown(object sender, KeyEventArgs e) + { + switch (e.KeyCode) + { + case(Keys.Left): + { + this.m_RenderingDevice.Transform.World = Matrix.RotationY((yAngle += 0.1f)); + this.RenderSceen(); + break; + } + case (Keys.Right): + { + this.m_RenderingDevice.Transform.World = Matrix.RotationY((yAngle -= 0.1f)); + this.RenderSceen(); + break; + } + case (Keys.Up): + { + this.m_RenderingDevice.Transform.World = Matrix.RotationX((xAngle += 0.1f)); + this.RenderSceen(); + break; + } + case (Keys.Down): + { + this.m_RenderingDevice.Transform.World = Matrix.RotationX((xAngle -= 0.1f)); + this.RenderSceen(); + break; + } + } + } + + private void InitializeDevice() + { + PresentParameters parameters = new PresentParameters(); + parameters.Windowed = true; + parameters.SwapEffect = SwapEffect.Discard; + + this.m_RenderingDevice = new Device(0, DeviceType.Hardware, + this, CreateFlags.SoftwareVertexProcessing, parameters); + + // Set metrices + this.m_RenderingDevice.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 0.0f, -100.0f), new Vector3(0.0f, 0.0f, 50.0f), new Vector3(0.0f, 1.0f, 0.0f)); this.m_RenderingDevice.Transform.Projection = Matrix.PerspectiveFovLH((float)(Math.PI / 2), 1.0f, 1.0f, 100.0f); - - this.m_RenderingDevice.Lights[0].Type = LightType.Directional; - this.m_RenderingDevice.Lights[0].Diffuse = System.Drawing.Color.Red; - this.m_RenderingDevice.Lights[0].Direction = new Vector3((float)Math.Cos(Environment.TickCount / 250.0f), 1.0f, (float)Math.Sin(Environment.TickCount / 250.0f)); - this.m_RenderingDevice.Lights[0].Direction = new Vector3(-1, 0, 0); - this.m_RenderingDevice.Lights[0].Enabled = true; - } public void RenderSceen() @@ -47,59 +88,39 @@ this.m_RenderingDevice.RenderState.Ambient = System.Drawing.Color.FromArgb(0x676766); - for (int i = 0; i < this.m_ObjectMaterials.Length; i++) + for (int i = 0; i < this.m_Model.Materials.Length; i++) { - this.m_RenderingDevice.Material = this.m_ObjectMaterials[i]; - this.m_RenderingDevice.SetTexture(0, this.m_ObjectTextures[i]); - this.m_SceenObjct.DrawSubset(i); + this.m_RenderingDevice.Material = this.m_Model.Materials[i]; + this.m_RenderingDevice.SetTexture(0, this.m_Model.Textures[i]); + this.m_Model.Object.DrawSubset(i); } this.m_RenderingDevice.EndScene(); this.m_RenderingDevice.Present(); } - private void Surface_Load(object sender, EventArgs e) + #region Public properties + + public Device RenderingDevice { - using (OpenFileDialog modelSource = new OpenFileDialog()) + get { - modelSource.Multiselect = false; - modelSource.Filter = "DirectX X Models (*.x)|*.x"; + return this.m_RenderingDevice; + } + } - if (modelSource.ShowDialog() == DialogResult.OK) - { - System.IO.Directory.SetCurrentDirectory(System.IO.Path.GetDirectoryName(modelSource.FileName)); - - this.m_DeviceParameters = new PresentParameters(); - this.m_DeviceParameters.Windowed = true; - this.m_DeviceParameters.SwapEffect = SwapEffect.Discard; - - this.m_RenderingDevice = new Device(0, DeviceType.Hardware, - this, CreateFlags.SoftwareVertexProcessing, this.m_DeviceParameters); - - ExtendedMaterial[] materials; - - this.m_SceenObjct = Mesh.FromFile(System.IO.Path.GetFileName(modelSource.FileName), MeshFlags.SystemMemory, this.m_RenderingDevice, out materials); - - this.m_ObjectTextures = new Texture[materials.Length]; - this.m_ObjectMaterials = new Material[materials.Length]; - - for (int i = 0; i < materials.Length; i++) - { - this.m_ObjectMaterials[i] = materials[i].Material3D; - this.m_ObjectMaterials[i].Ambient = this.m_ObjectMaterials[i].Diffuse; - this.m_ObjectTextures[i] = TextureLoader.FromFile(this.m_RenderingDevice, materials[i].TextureFilename); - } - - this.SetMetrices(); - - this.RenderSceen(); - } - else - { - MessageBox.Show("No model selected"); - this.Close(); - } + public IModel Model + { + get + { + return this.m_Model; } + set + { + this.m_Model = value; + } } + + #endregion } } \ No newline at end of file Deleted: src/test_applications/ItemsViewer/Surface.resx =================================================================== --- src/test_applications/ItemsViewer/Surface.resx 2006-06-25 10:49:06 UTC (rev 7) +++ src/test_applications/ItemsViewer/Surface.resx 2006-06-26 15:10:32 UTC (rev 8) @@ -1,120 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<root> - <!-- - Microsoft ResX Schema - - Version 2.0 - - The primary goals of this format is to allow a simple XML format - that is mostly human readable. The generation and parsing of the - various data types are done through the TypeConverter classes - associated with the data types. - - Example: - - ... ado.net/XML headers & schema ... - <resheader name="resmimetype">text/microsoft-resx</resheader> - <resheader name="version">2.0</resheader> - <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> - <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> - <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> - <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> - <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> - <value>[base64 mime encoded serialized .NET Framework object]</value> - </data> - <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> - <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> - <comment>This is a comment</comment> - </data> - - There are any number of "resheader" rows that contain simple - name/value pairs. - - Each data row contains a name, and value. The row also contains a - type or mimetype. Type corresponds to a .NET class that support - text/value conversion through the TypeConverter architecture. - Classes that don't support this are serialized and stored with the - mimetype set. - - The mimetype is used for serialized objects, and tells the - ResXResourceReader how to depersist the object. This is currently not - extensible. For a given mimetype the value must be set accordingly: - - Note - application/x-microsoft.net.object.binary.base64 is the format - that the ResXResourceWriter will generate, however the reader can - read any of the formats listed below. - - mimetype: application/x-microsoft.net.object.binary.base64 - value : The object must be serialized with - : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter - : and then encoded with base64 encoding. - - mimetype: application/x-microsoft.net.object.soap.base64 - value : The object must be serialized with - : System.Runtime.Serialization.Formatters.Soap.SoapFormatter - : and then encoded with base64 encoding. - - mimetype: application/x-microsoft.net.object.bytearray.base64 - value : The object must be serialized into a byte array - : using a System.ComponentModel.TypeConverter - : and then encoded with base64 encoding. - --> - <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> - <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> - <xsd:element name="root" msdata:IsDataSet="true"> - <xsd:complexType> - <xsd:choice maxOccurs="unbounded"> - <xsd:element name="metadata"> - <xsd:complexType> - <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" /> - </xsd:sequence> - <xsd:attribute name="name" use="required" type="xsd:string" /> - <xsd:attribute name="type" type="xsd:string" /> - <xsd:attribute name="mimetype" type="xsd:string" /> - <xsd:attribute ref="xml:space" /> - </xsd:complexType> - </xsd:element> - <xsd:element name="assembly"> - <xsd:complexType> - <xsd:attribute name="alias" type="xsd:string" /> - <xsd:attribute name="name" type="xsd:string" /> - </xsd:complexType> - </xsd:element> - <xsd:element name="data"> - <xsd:complexType> - <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> - <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> - </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> - <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> - <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> - <xsd:attribute ref="xml:space" /> - </xsd:complexType> - </xsd:element> - <xsd:element name="resheader"> - <xsd:complexType> - <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> - </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" use="required" /> - </xsd:complexType> - </xsd:element> - </xsd:choice> - </xsd:complexType> - </xsd:element> - </xsd:schema> - <resheader name="resmimetype"> - <value>text/microsoft-resx</value> - </resheader> - <resheader name="version"> - <value>2.0</value> - </resheader> - <resheader name="reader"> - <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> - <resheader name="writer"> - <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> -</root> \ No newline at end of file Added: src/test_applications/ItemsViewer/ViewController.cs =================================================================== --- src/test_applications/ItemsViewer/ViewController.cs (rev 0) +++ src/test_applications/ItemsViewer/ViewController.cs 2006-06-26 15:10:32 UTC (rev 8) @@ -0,0 +1,54 @@ +using System; +using System.IO; +using System.Configuration; +using System.Collections.Specialized; +using System.Windows.Forms; + +namespace RPGWorldModel.ItemsViewer +{ + public sealed class ViewController + { + private Surface m_View; + private Model m_Model; + + public ViewController() + { + this.m_View = new Surface(); + + if (this.LoadModel()) + { + this.m_View.Model = this.m_Model; + this.m_View.ShowDialog(); + } + } + + private bool LoadModel() + { + NameValueCollection models = (NameValueCollection)ConfigurationManager.GetSection("models"); + + if (models != null) + { + using (OpenModelDialog openModel = new OpenModelDialog(models)) + { + Directory.SetCurrentDirectory(Application.StartupPath); + + if (openModel.ShowDialog() == DialogResult.OK) + { + try + { + this.m_Model = new Model(models[openModel.SelectedModel], this.m_View.RenderingDevice); + } + catch + { + return false; + } + + return true; + } + } + } + + return false; + } + } +} Added: src/test_applications/ItemsViewer/ViewState.cs =================================================================== --- src/test_applications/ItemsViewer/ViewState.cs (rev 0) +++ src/test_applications/ItemsViewer/ViewState.cs 2006-06-26 15:10:32 UTC (rev 8) @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace RPGWorldModel.ItemsViewer +{ + public struct ViewState + { + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pos...@us...> - 2006-07-06 13:53:44
|
Revision: 10 Author: poserdev Date: 2006-07-06 06:53:21 -0700 (Thu, 06 Jul 2006) ViewCVS: http://svn.sourceforge.net/rpgworldmodel/?rev=10&view=rev Log Message: ----------- Big reorganization in the application structure. Enabling object rotation/scaling in progress. Home I make it right from now :) Modified Paths: -------------- src/test_applications/ItemsViewer/App.config src/test_applications/ItemsViewer/ItemsViewer.csproj src/test_applications/ItemsViewer/Program.cs src/test_applications/ItemsViewer/Properties/AssemblyInfo.cs Added Paths: ----------- src/test_applications/ItemsViewer/Form1.Designer.cs src/test_applications/ItemsViewer/Form1.cs src/test_applications/ItemsViewer/SceenObject.cs src/test_applications/ItemsViewer/SwordObject.cs Removed Paths: ------------- src/test_applications/ItemsViewer/IModel.cs src/test_applications/ItemsViewer/Model.cs src/test_applications/ItemsViewer/OpenModelDialog.Designer.cs src/test_applications/ItemsViewer/OpenModelDialog.cs src/test_applications/ItemsViewer/Surface.cs src/test_applications/ItemsViewer/ViewController.cs src/test_applications/ItemsViewer/ViewState.cs Modified: src/test_applications/ItemsViewer/App.config =================================================================== --- src/test_applications/ItemsViewer/App.config 2006-07-03 20:23:33 UTC (rev 9) +++ src/test_applications/ItemsViewer/App.config 2006-07-06 13:53:21 UTC (rev 10) @@ -1,11 +1,3 @@ <?xml version="1.0" encoding="utf-8" ?> - <configuration> - <configSections> - <section name="models" type="System.Configuration.NameValueSectionHandler" /> - </configSections> - - <models> - <add key="Long Iron Sword" value="Models\sword.x" /> - </models> </configuration> \ No newline at end of file Added: src/test_applications/ItemsViewer/Form1.Designer.cs =================================================================== --- src/test_applications/ItemsViewer/Form1.Designer.cs (rev 0) +++ src/test_applications/ItemsViewer/Form1.Designer.cs 2006-07-06 13:53:21 UTC (rev 10) @@ -0,0 +1,49 @@ +namespace ItemsViewer +{ + 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.SuspendLayout(); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(292, 273); + this.MinimumSize = new System.Drawing.Size(100, 100); + this.Name = "Form1"; + this.Text = "Form1"; + this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); + this.ResumeLayout(false); + + } + + #endregion + } +} + Added: src/test_applications/ItemsViewer/Form1.cs =================================================================== --- src/test_applications/ItemsViewer/Form1.cs (rev 0) +++ src/test_applications/ItemsViewer/Form1.cs 2006-07-06 13:53:21 UTC (rev 10) @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +using Microsoft.DirectX; +using Microsoft.DirectX.Direct3D; + +using ItemsViewer.SceenObjects; + +namespace ItemsViewer +{ + public partial class Form1 : Form + { + private Device m_Device; + private SwordObject m_SceenObject; + + public Form1() + { + InitializeComponent(); + this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); + + this.MouseWheel += new MouseEventHandler(Form1_MouseWheel); + + InitializeGraphics(); + } + + private void SetupCamera() + { + this.m_Device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, + 1, 1, 100.0f); + this.m_Device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, 20), new Vector3(), + new Vector3(0, 1, 0)); + + this.m_Device.Transform.World = Matrix.RotationZ(Environment.TickCount / 1000.0f) * + Matrix.RotationY(Environment.TickCount / 1000.0f) * Matrix.Scaling(0.02f, 0.02f, 0.02f); + } + + private void InitializeGraphics() + { + PresentParameters parameters = new PresentParameters(); + parameters.Windowed = true; + parameters.SwapEffect = SwapEffect.Discard; + parameters.EnableAutoDepthStencil = true; + parameters.AutoDepthStencilFormat = DepthFormat.D16; + + this.m_Device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, parameters); + this.m_Device.RenderState.CullMode = Cull.None; + this.m_Device.RenderState.ZBufferEnable = true; + + this.m_SceenObject = new SwordObject(this.m_Device); + this.m_SceenObject.LoadMesh(@"Models\Base\Sword\sword.x"); + } + + private void Form1_Paint(object sender, PaintEventArgs e) + { + this.m_Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.CornflowerBlue, 1.0f, 0); + this.m_Device.RenderState.Ambient = Color.White; + + this.SetupCamera(); + + this.m_Device.BeginScene(); + + for (int i = 0; i < this.m_SceenObject.Materials.Length; i++) + { + this.m_Device.Material = this.m_SceenObject.Materials[i]; + this.m_Device.SetTexture(0, this.m_SceenObject.Textures[i]); + this.m_SceenObject.Mesh.DrawSubset(i); + } + + this.m_Device.EndScene(); + + this.m_Device.Present(); + this.Invalidate(); + } + + // Control over the sceen object zoom factor + void Form1_MouseWheel(object sender, MouseEventArgs e) + { + if (e.Delta > 0) + { + } + else + { + } + } + } +} \ No newline at end of file Deleted: src/test_applications/ItemsViewer/IModel.cs =================================================================== --- src/test_applications/ItemsViewer/IModel.cs 2006-07-03 20:23:33 UTC (rev 9) +++ src/test_applications/ItemsViewer/IModel.cs 2006-07-06 13:53:21 UTC (rev 10) @@ -1,24 +0,0 @@ -using System; - -using Microsoft.DirectX.Direct3D; - -namespace RPGWorldModel.ItemsViewer -{ - public interface IModel - { - Mesh Object - { - get; - } - - Material[] Materials - { - get; - } - - Texture[] Textures - { - get; - } - } -} Modified: src/test_applications/ItemsViewer/ItemsViewer.csproj =================================================================== --- src/test_applications/ItemsViewer/ItemsViewer.csproj 2006-07-03 20:23:33 UTC (rev 9) +++ src/test_applications/ItemsViewer/ItemsViewer.csproj 2006-07-06 13:53:21 UTC (rev 10) @@ -4,11 +4,11 @@ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion>8.0.50727</ProductVersion> <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{57684296-F942-4797-8C0F-ADB151A02477}</ProjectGuid> + <ProjectGuid>{CA0D68AD-69C4-46D2-B09B-036D02ABA061}</ProjectGuid> <OutputType>WinExe</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>RPGWorldModel.ItemsViewer</RootNamespace> - <AssemblyName>ModelViewer</AssemblyName> + <RootNamespace>ItemsViewer</RootNamespace> + <AssemblyName>ItemsViewer</AssemblyName> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -28,43 +28,28 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> - <Reference Include="Microsoft.DirectX, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> - <Private>False</Private> - </Reference> - <Reference Include="Microsoft.DirectX.Direct3D, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> - <Private>False</Private> - </Reference> - <Reference Include="Microsoft.DirectX.Direct3DX, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> - <Private>False</Private> - </Reference> - <Reference Include="RPGWorldModel.Abstracts, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\RPGWorldModel.Abstracts\bin\Debug\RPGWorldModel.Abstracts.dll</HintPath> - </Reference> + <Reference Include="Microsoft.DirectX, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> + <Reference Include="Microsoft.DirectX.Direct3D, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> + <Reference Include="Microsoft.DirectX.Direct3DX, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> <Reference Include="System" /> - <Reference Include="System.configuration" /> + <Reference Include="System.Data" /> + <Reference Include="System.Deployment" /> <Reference Include="System.Drawing" /> <Reference Include="System.Windows.Forms" /> + <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> - <Compile Include="IModel.cs" /> - <Compile Include="Model.cs" /> - <Compile Include="OpenModelDialog.cs"> + <Compile Include="Form1.cs"> <SubType>Form</SubType> </Compile> - <Compile Include="OpenModelDialog.Designer.cs"> - <DependentUpon>OpenModelDialog.cs</DependentUpon> + <Compile Include="Form1.Designer.cs"> + <DependentUpon>Form1.cs</DependentUpon> </Compile> - <Compile Include="Surface.cs"> - <SubType>Form</SubType> - </Compile> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> - <Compile Include="ViewController.cs" /> - <Compile Include="ViewState.cs" /> - </ItemGroup> - <ItemGroup> <None Include="App.config" /> + <Compile Include="SceenObject.cs" /> + <Compile Include="SwordObject.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Deleted: src/test_applications/ItemsViewer/Model.cs =================================================================== --- src/test_applications/ItemsViewer/Model.cs 2006-07-03 20:23:33 UTC (rev 9) +++ src/test_applications/ItemsViewer/Model.cs 2006-07-06 13:53:21 UTC (rev 10) @@ -1,69 +0,0 @@ -using System; -using System.IO; -using System.Windows.Forms; - -using Microsoft.DirectX; -using Microsoft.DirectX.Direct3D; - -namespace RPGWorldModel.ItemsViewer -{ - public class Model : IModel - { - private Mesh m_Object; - private Material[] m_Materials; - private Texture[] m_Textures; - - public Model(string source, Device device) - { - - - if (File.Exists(source)) - { - Directory.SetCurrentDirectory(Application.StartupPath + - Path.DirectorySeparatorChar + Path.GetDirectoryName(source)); - - // Load the model - ExtendedMaterial[] materials; - this.m_Object = Mesh.FromFile(System.IO.Path.GetFileName(source), MeshFlags.SystemMemory, device, out materials); - - this.m_Textures = new Texture[materials.Length]; - this.m_Materials = new Material[materials.Length]; - - for (int i = 0; i < materials.Length; i++) - { - this.m_Materials[i] = materials[i].Material3D; - this.m_Materials[i].Ambient = this.m_Materials[i].Diffuse; - this.m_Textures[i] = TextureLoader.FromFile(device, materials[i].TextureFilename); - } - } - } - - #region IModel Members - - public Mesh Object - { - get - { - return this.m_Object; - } - } - - public Material[] Materials - { - get - { - return this.m_Materials; - } - } - - public Texture[] Textures - { - get - { - return this.m_Textures; - } - } - - #endregion - } -} Deleted: src/test_applications/ItemsViewer/OpenModelDialog.Designer.cs =================================================================== --- src/test_applications/ItemsViewer/OpenModelDialog.Designer.cs 2006-07-03 20:23:33 UTC (rev 9) +++ src/test_applications/ItemsViewer/OpenModelDialog.Designer.cs 2006-07-06 13:53:21 UTC (rev 10) @@ -1,84 +0,0 @@ -namespace RPGWorldModel.ItemsViewer -{ - partial class OpenModelDialog - { - /// <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.m_List = new System.Windows.Forms.ListBox(); - this.m_Picture = new System.Windows.Forms.PictureBox(); - ((System.ComponentModel.ISupportInitialize)(this.m_Picture)).BeginInit(); - this.SuspendLayout(); - // - // m_List - // - this.m_List.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.m_List.Dock = System.Windows.Forms.DockStyle.Left; - this.m_List.Font = new System.Drawing.Font("Microsoft Sans Serif", 12.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.m_List.IntegralHeight = false; - this.m_List.ItemHeight = 20; - this.m_List.Location = new System.Drawing.Point(0, 0); - this.m_List.Margin = new System.Windows.Forms.Padding(0); - this.m_List.Name = "m_List"; - this.m_List.ScrollAlwaysVisible = true; - this.m_List.Size = new System.Drawing.Size(400, 168); - this.m_List.TabIndex = 0; - this.m_List.DoubleClick += new System.EventHandler(this.m_List_DoubleClick); - this.m_List.SelectedIndexChanged += new System.EventHandler(this.m_List_SelectedIndexChanged); - // - // m_Picture - // - this.m_Picture.Dock = System.Windows.Forms.DockStyle.Fill; - this.m_Picture.Location = new System.Drawing.Point(400, 0); - this.m_Picture.Name = "m_Picture"; - this.m_Picture.Size = new System.Drawing.Size(194, 168); - this.m_Picture.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; - this.m_Picture.TabIndex = 1; - this.m_Picture.TabStop = false; - // - // OpenModelDialog - // - this.AutoSize = true; - this.ClientSize = new System.Drawing.Size(594, 168); - this.Controls.Add(this.m_Picture); - this.Controls.Add(this.m_List); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "OpenModelDialog"; - this.ShowIcon = false; - this.Text = "Model"; - ((System.ComponentModel.ISupportInitialize)(this.m_Picture)).EndInit(); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.ListBox m_List; - private System.Windows.Forms.PictureBox m_Picture; - } -} \ No newline at end of file Deleted: src/test_applications/ItemsViewer/OpenModelDialog.cs =================================================================== --- src/test_applications/ItemsViewer/OpenModelDialog.cs 2006-07-03 20:23:33 UTC (rev 9) +++ src/test_applications/ItemsViewer/OpenModelDialog.cs 2006-07-06 13:53:21 UTC (rev 10) @@ -1,54 +0,0 @@ -using System; -using System.IO; -using System.Collections.Specialized; -using System.ComponentModel; -using System.Drawing; -using System.Windows.Forms; - -namespace RPGWorldModel.ItemsViewer -{ - public partial class OpenModelDialog : Form - { - private string m_SelectedModel; - private NameValueCollection m_Models; - - public OpenModelDialog(NameValueCollection models) - { - InitializeComponent(); - - this.m_Models = models; - - foreach (string key in this.m_Models.AllKeys) - this.m_List.Items.Add(key); - - this.m_List.SelectedIndex = -1; - } - - private void m_List_SelectedIndexChanged(object sender, EventArgs e) - { - string file = this.m_Models[this.m_List.SelectedItem.ToString()]; - // Load the model image - this.m_Picture.Load(Path.GetDirectoryName(file) + Path.DirectorySeparatorChar + - Path.GetFileNameWithoutExtension(file) + @".bmp"); - } - - private void m_List_DoubleClick(object sender, EventArgs e) - { - if (this.m_List.SelectedItem != null) - { - this.m_SelectedModel = this.m_List.SelectedItem.ToString(); - - this.DialogResult = DialogResult.OK; - this.Close(); - } - } - - public string SelectedModel - { - get - { - return this.m_SelectedModel; - } - } - } -} \ No newline at end of file Modified: src/test_applications/ItemsViewer/Program.cs =================================================================== --- src/test_applications/ItemsViewer/Program.cs 2006-07-03 20:23:33 UTC (rev 9) +++ src/test_applications/ItemsViewer/Program.cs 2006-07-06 13:53:21 UTC (rev 10) @@ -1,13 +1,20 @@ using System; +using System.Collections.Generic; +using System.Windows.Forms; -namespace RPGWorldModel.ItemsViewer +namespace ItemsViewer { static class Program { + /// <summary> + /// The main entry point for the application. + /// </summary> [STAThread] static void Main() { - ViewController view = new ViewController(); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); } } } \ No newline at end of file Modified: src/test_applications/ItemsViewer/Properties/AssemblyInfo.cs =================================================================== --- src/test_applications/ItemsViewer/Properties/AssemblyInfo.cs 2006-07-03 20:23:33 UTC (rev 9) +++ src/test_applications/ItemsViewer/Properties/AssemblyInfo.cs 2006-07-06 13:53:21 UTC (rev 10) @@ -5,11 +5,11 @@ // 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("ModelViewer")] +[assembly: AssemblyTitle("ItemsViewer")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ModelViewer")] +[assembly: AssemblyProduct("ItemsViewer")] [assembly: AssemblyCopyright("Copyright © 2006")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -20,7 +20,7 @@ [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("2526b583-4d40-451f-b223-b66498fedb85")] +[assembly: Guid("ddbe5d05-3a77-4fe1-b4b0-108222295195")] // Version information for an assembly consists of the following four values: // Added: src/test_applications/ItemsViewer/SceenObject.cs =================================================================== --- src/test_applications/ItemsViewer/SceenObject.cs (rev 0) +++ src/test_applications/ItemsViewer/SceenObject.cs 2006-07-06 13:53:21 UTC (rev 10) @@ -0,0 +1,63 @@ +using System; +using System.IO; +using System.Drawing; +using System.Windows.Forms; + +using Microsoft.DirectX.Direct3D; + +namespace ItemsViewer.SceenObjects +{ + public class SceenObject + { + private Mesh m_Mesh; + private Material[] m_Materials; + private Texture[] m_Textures; + private Device m_Device; + + /// <summary> + /// Creates a new screen object + /// </summary> + public SceenObject(ref Device device) + { + this.m_Mesh = null; + this.m_Materials = null; + this.m_Textures = null; + this.m_Device = device; + } + + public virtual void LoadMesh(string source) + { + Directory.SetCurrentDirectory( + System.IO.Path.Combine(Application.StartupPath, System.IO.Path.GetDirectoryName(source))); + + ExtendedMaterial[] materials = null; + + this.m_Mesh = Mesh.FromFile(Path.GetFileName(source), MeshFlags.SystemMemory, this.m_Device, out materials); + + this.m_Textures = new Texture[materials.Length]; + this.m_Materials = new Material[materials.Length]; + + for (int i = 0; i < materials.Length; i++) + { + this.m_Materials[i] = materials[i].Material3D; + this.m_Materials[i].Ambient = this.m_Materials[i].Diffuse; + this.m_Textures[i] = TextureLoader.FromFile(this.m_Device, materials[i].TextureFilename); + } + } + + public Mesh Mesh + { + get { return this.m_Mesh; } + } + + public Texture[] Textures + { + get { return this.m_Textures; } + } + + public Material[] Materials + { + get { return this.m_Materials; } + } + } +} Deleted: src/test_applications/ItemsViewer/Surface.cs =================================================================== --- src/test_applications/ItemsViewer/Surface.cs 2006-07-03 20:23:33 UTC (rev 9) +++ src/test_applications/ItemsViewer/Surface.cs 2006-07-06 13:53:21 UTC (rev 10) @@ -1,126 +0,0 @@ -using System; - -using System.ComponentModel; -using System.Drawing; -using System.Windows.Forms; - -using Microsoft.DirectX; -using Microsoft.DirectX.Direct3D; - -namespace RPGWorldModel.ItemsViewer -{ - public sealed partial class Surface : Form - { - private Device m_RenderingDevice; - private IModel m_Model; - - public Surface() - { - this.SuspendLayout(); - - this.ClientSize = new System.Drawing.Size(800, 600); - this.ShowIcon = false; - this.KeyDown += new KeyEventHandler(Surface_KeyDown); - this.Paint += new PaintEventHandler(Surface_Paint); - - this.ResumeLayout(false); - - this.InitializeDevice(); - } - - void Surface_Paint(object sender, PaintEventArgs e) - { - this.RenderSceen(); - } - - float yAngle = 0.0f; - float xAngle = 0.0f; - - void Surface_KeyDown(object sender, KeyEventArgs e) - { - switch (e.KeyCode) - { - case(Keys.Left): - { - this.m_RenderingDevice.Transform.World = Matrix.RotationY((yAngle += 0.1f)); - this.RenderSceen(); - break; - } - case (Keys.Right): - { - this.m_RenderingDevice.Transform.World = Matrix.RotationY((yAngle -= 0.1f)); - this.RenderSceen(); - break; - } - case (Keys.Up): - { - this.m_RenderingDevice.Transform.World = Matrix.RotationX((xAngle += 0.1f)); - this.RenderSceen(); - break; - } - case (Keys.Down): - { - this.m_RenderingDevice.Transform.World = Matrix.RotationX((xAngle -= 0.1f)); - this.RenderSceen(); - break; - } - } - } - - private void InitializeDevice() - { - PresentParameters parameters = new PresentParameters(); - parameters.Windowed = true; - parameters.SwapEffect = SwapEffect.Discard; - - this.m_RenderingDevice = new Device(0, DeviceType.Hardware, - this, CreateFlags.SoftwareVertexProcessing, parameters); - - // Set metrices - this.m_RenderingDevice.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 0.0f, -100.0f), new Vector3(0.0f, 0.0f, 50.0f), new Vector3(0.0f, 1.0f, 0.0f)); - this.m_RenderingDevice.Transform.Projection = Matrix.PerspectiveFovLH((float)(Math.PI / 2), 1.0f, 1.0f, 100.0f); - } - - public void RenderSceen() - { - this.m_RenderingDevice.Clear(ClearFlags.Target, System.Drawing.Color.Black, 1.0f, 0); - this.m_RenderingDevice.BeginScene(); - - this.m_RenderingDevice.RenderState.Ambient = System.Drawing.Color.FromArgb(0x676766); - - for (int i = 0; i < this.m_Model.Materials.Length; i++) - { - this.m_RenderingDevice.Material = this.m_Model.Materials[i]; - this.m_RenderingDevice.SetTexture(0, this.m_Model.Textures[i]); - this.m_Model.Object.DrawSubset(i); - } - - this.m_RenderingDevice.EndScene(); - this.m_RenderingDevice.Present(); - } - - #region Public properties - - public Device RenderingDevice - { - get - { - return this.m_RenderingDevice; - } - } - - public IModel Model - { - get - { - return this.m_Model; - } - set - { - this.m_Model = value; - } - } - - #endregion - } -} \ No newline at end of file Added: src/test_applications/ItemsViewer/SwordObject.cs =================================================================== --- src/test_applications/ItemsViewer/SwordObject.cs (rev 0) +++ src/test_applications/ItemsViewer/SwordObject.cs 2006-07-06 13:53:21 UTC (rev 10) @@ -0,0 +1,13 @@ +using System; + +using Microsoft.DirectX.Direct3D; + +namespace ItemsViewer.SceenObjects +{ + public class SwordObject : SceenObject + { + public SwordObject(Device device) : base(ref device) + { + } + } +} Deleted: src/test_applications/ItemsViewer/ViewController.cs =================================================================== --- src/test_applications/ItemsViewer/ViewController.cs 2006-07-03 20:23:33 UTC (rev 9) +++ src/test_applications/ItemsViewer/ViewController.cs 2006-07-06 13:53:21 UTC (rev 10) @@ -1,54 +0,0 @@ -using System; -using System.IO; -using System.Configuration; -using System.Collections.Specialized; -using System.Windows.Forms; - -namespace RPGWorldModel.ItemsViewer -{ - public sealed class ViewController - { - private Surface m_View; - private Model m_Model; - - public ViewController() - { - this.m_View = new Surface(); - - if (this.LoadModel()) - { - this.m_View.Model = this.m_Model; - this.m_View.ShowDialog(); - } - } - - private bool LoadModel() - { - NameValueCollection models = (NameValueCollection)ConfigurationManager.GetSection("models"); - - if (models != null) - { - using (OpenModelDialog openModel = new OpenModelDialog(models)) - { - Directory.SetCurrentDirectory(Application.StartupPath); - - if (openModel.ShowDialog() == DialogResult.OK) - { - try - { - this.m_Model = new Model(models[openModel.SelectedModel], this.m_View.RenderingDevice); - } - catch - { - return false; - } - - return true; - } - } - } - - return false; - } - } -} Deleted: src/test_applications/ItemsViewer/ViewState.cs =================================================================== --- src/test_applications/ItemsViewer/ViewState.cs 2006-07-03 20:23:33 UTC (rev 9) +++ src/test_applications/ItemsViewer/ViewState.cs 2006-07-06 13:53:21 UTC (rev 10) @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace RPGWorldModel.ItemsViewer -{ - public struct ViewState - { - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pos...@us...> - 2006-07-06 14:56:39
|
Revision: 11 Author: poserdev Date: 2006-07-06 07:56:26 -0700 (Thu, 06 Jul 2006) ViewCVS: http://svn.sourceforge.net/rpgworldmodel/?rev=11&view=rev Log Message: ----------- Cool! Now we all can rotate/scale the object. Someone did a great job there :P Modified Paths: -------------- src/test_applications/ItemsViewer/Form1.Designer.cs src/test_applications/ItemsViewer/Form1.cs src/test_applications/ItemsViewer/ItemsViewer.csproj Added Paths: ----------- src/test_applications/ItemsViewer/Camera.cs Added: src/test_applications/ItemsViewer/Camera.cs =================================================================== --- src/test_applications/ItemsViewer/Camera.cs (rev 0) +++ src/test_applications/ItemsViewer/Camera.cs 2006-07-06 14:56:26 UTC (rev 11) @@ -0,0 +1,34 @@ +using System; + +namespace ItemsViewer +{ + public struct Camera + { + private int ZMax; + public int Z; + private int ZMin; + public float RotationY; + public float RotationX; + + public Camera(int zMax, int z, int zMin) + { + this.ZMax = zMax; + this.Z = z; + this.ZMin = zMin; + this.RotationY = 0; + this.RotationX = 0; + } + + public void ZoomIn() + { + if ((ZMin + 1) != Z) + Z--; + } + + public void ZoomOut() + { + if ((ZMax - 1) != Z) + Z++; + } + } +} \ No newline at end of file Modified: src/test_applications/ItemsViewer/Form1.Designer.cs =================================================================== --- src/test_applications/ItemsViewer/Form1.Designer.cs 2006-07-06 13:53:21 UTC (rev 10) +++ src/test_applications/ItemsViewer/Form1.Designer.cs 2006-07-06 14:56:26 UTC (rev 11) @@ -39,6 +39,7 @@ this.Name = "Form1"; this.Text = "Form1"; this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown); this.ResumeLayout(false); } Modified: src/test_applications/ItemsViewer/Form1.cs =================================================================== --- src/test_applications/ItemsViewer/Form1.cs 2006-07-06 13:53:21 UTC (rev 10) +++ src/test_applications/ItemsViewer/Form1.cs 2006-07-06 14:56:26 UTC (rev 11) @@ -17,6 +17,7 @@ { private Device m_Device; private SwordObject m_SceenObject; + private Camera m_Camera; public Form1() { @@ -32,11 +33,13 @@ { this.m_Device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1, 1, 100.0f); - this.m_Device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, 20), new Vector3(), + + this.m_Device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, this.m_Camera.Z), new Vector3(), new Vector3(0, 1, 0)); - this.m_Device.Transform.World = Matrix.RotationZ(Environment.TickCount / 1000.0f) * - Matrix.RotationY(Environment.TickCount / 1000.0f) * Matrix.Scaling(0.02f, 0.02f, 0.02f); + this.m_Device.Transform.World = Matrix.Scaling(0.02f, 0.02f, 0.02f) + * Matrix.RotationY(this.m_Camera.RotationY) * + Matrix.RotationX(this.m_Camera.RotationX); } private void InitializeGraphics() @@ -53,6 +56,8 @@ this.m_SceenObject = new SwordObject(this.m_Device); this.m_SceenObject.LoadMesh(@"Models\Base\Sword\sword.x"); + + this.m_Camera = new Camera(100, 10, 2); } private void Form1_Paint(object sender, PaintEventArgs e) @@ -81,11 +86,29 @@ void Form1_MouseWheel(object sender, MouseEventArgs e) { if (e.Delta > 0) + this.m_Camera.ZoomIn(); + else + this.m_Camera.ZoomOut(); + } + + private void Form1_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Left) { + this.m_Camera.RotationY += 0.05f; } - else + else if (e.KeyCode == Keys.Right) { + this.m_Camera.RotationY -= 0.05f; } + else if (e.KeyCode == Keys.Up) + { + this.m_Camera.RotationX += 0.05f; + } + else if (e.KeyCode == Keys.Down) + { + this.m_Camera.RotationX -= 0.05f; + } } } } \ No newline at end of file Modified: src/test_applications/ItemsViewer/ItemsViewer.csproj =================================================================== --- src/test_applications/ItemsViewer/ItemsViewer.csproj 2006-07-06 13:53:21 UTC (rev 10) +++ src/test_applications/ItemsViewer/ItemsViewer.csproj 2006-07-06 14:56:26 UTC (rev 11) @@ -39,6 +39,7 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> + <Compile Include="Camera.cs" /> <Compile Include="Form1.cs"> <SubType>Form</SubType> </Compile> @@ -51,6 +52,12 @@ <Compile Include="SceenObject.cs" /> <Compile Include="SwordObject.cs" /> </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="Form1.resx"> + <SubType>Designer</SubType> + <DependentUpon>Form1.cs</DependentUpon> + </EmbeddedResource> + </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |