OSDN Git Service

SlimDX から SharpDX へ機械的に移行。
[dtxmania/dtxmania.git] / FDK17プロジェクト / コード / 01.フレームワーク / Utilities / TransformedColoredTexturedVertex.cs
1 /*\r
2 * Copyright (c) 2007-2009 SlimDX Group\r
3\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy\r
5 * of this software and associated documentation files (the "Software"), to deal\r
6 * in the Software without restriction, including without limitation the rights\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
8 * copies of the Software, and to permit persons to whom the Software is\r
9 * furnished to do so, subject to the following conditions:\r
10\r
11 * The above copyright notice and this permission notice shall be included in\r
12 * all copies or substantial portions of the Software.\r
13\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
20 * THE SOFTWARE.\r
21 */\r
22 using System;\r
23 using System.Globalization;\r
24 using System.Runtime.InteropServices;\r
25 using SharpDX;\r
26 using SharpDX.Direct3D9;\r
27 \r
28 namespace SampleFramework\r
29 {\r
30     /// <summary>\r
31     /// Represents a single transformed, colored, and textured vertex.\r
32     /// </summary>\r
33     [StructLayout(LayoutKind.Sequential)]\r
34     public struct TransformedColoredTexturedVertex : IEquatable<TransformedColoredTexturedVertex>\r
35     {\r
36                 private Vector4 m_Position;\r
37         /// <summary>\r
38         /// Gets or sets the transformed position of the vertex.\r
39         /// </summary>\r
40         /// <value>The transformed position of the vertex.</value>\r
41         [VertexElement(DeclarationType.Float4, DeclarationUsage.PositionTransformed)]\r
42         public Vector4 Position\r
43         {\r
44                         get { return m_Position; }\r
45                         set { m_Position = value; }\r
46         }\r
47 \r
48                 private int m_Color;\r
49         /// <summary>\r
50         /// Gets or sets the color of the vertex.\r
51         /// </summary>\r
52         /// <value>The color of the vertex.</value>\r
53         [VertexElement(DeclarationType.Color, DeclarationUsage.Color)]\r
54         public int Color\r
55         {\r
56                         get { return m_Color; }\r
57                         set { m_Color = value; }\r
58         }\r
59 \r
60                 private Vector2 m_TextureCoordinates;\r
61         /// <summary>\r
62         /// Gets or sets the texture coordinates.\r
63         /// </summary>\r
64         /// <value>The texture coordinates.</value>\r
65         [VertexElement(DeclarationType.Float2, DeclarationUsage.TextureCoordinate)]\r
66         public Vector2 TextureCoordinates\r
67         {\r
68                         get { return m_TextureCoordinates; }\r
69                         set { m_TextureCoordinates = value; }\r
70         }\r
71 \r
72         /// <summary>\r
73         /// Gets the size in bytes.\r
74         /// </summary>\r
75         /// <value>The size in bytes.</value>\r
76         public static int SizeInBytes\r
77         {\r
78             get { return Marshal.SizeOf(typeof(TransformedColoredTexturedVertex)); }\r
79         }\r
80 \r
81         /// <summary>\r
82         /// Gets the format.\r
83         /// </summary>\r
84         /// <value>The format.</value>\r
85         public static VertexFormat Format\r
86         {\r
87             get { return VertexFormat.PositionRhw | VertexFormat.Diffuse | VertexFormat.Texture1; }\r
88         }\r
89 \r
90         /// <summary>\r
91         /// Initializes a new instance of the <see cref="TransformedColoredTexturedVertex"/> struct.\r
92         /// </summary>\r
93         /// <param name="position">The position.</param>\r
94         /// <param name="color">The color.</param>\r
95         /// <param name="textureCoordinates">The texture coordinates.</param>\r
96         public TransformedColoredTexturedVertex(Vector4 position, int color, Vector2 textureCoordinates)\r
97             : this()\r
98         {\r
99             Position = position;\r
100             Color = color;\r
101             TextureCoordinates = textureCoordinates;\r
102         }\r
103 \r
104         /// <summary>\r
105         /// Implements the operator ==.\r
106         /// </summary>\r
107         /// <param name="left">The left side of the operator.</param>\r
108         /// <param name="right">The right side of the operator.</param>\r
109         /// <returns>The result of the operator.</returns>\r
110         public static bool operator ==(TransformedColoredTexturedVertex left, TransformedColoredTexturedVertex right)\r
111         {\r
112             return left.Equals(right);\r
113         }\r
114 \r
115         /// <summary>\r
116         /// Implements the operator !=.\r
117         /// </summary>\r
118         /// <param name="left">The left side of the operator.</param>\r
119         /// <param name="right">The right side of the operator.</param>\r
120         /// <returns>The result of the operator.</returns>\r
121         public static bool operator !=(TransformedColoredTexturedVertex left, TransformedColoredTexturedVertex right)\r
122         {\r
123             return !(left == right);\r
124         }\r
125 \r
126         /// <summary>\r
127         /// Returns the hash code for this instance.\r
128         /// </summary>\r
129         /// <returns>\r
130         /// A 32-bit signed integer that is the hash code for this instance.\r
131         /// </returns>\r
132         public override int GetHashCode()\r
133         {\r
134             return Position.GetHashCode() + Color.GetHashCode() + TextureCoordinates.GetHashCode();\r
135         }\r
136 \r
137         /// <summary>\r
138         /// Indicates whether this instance and a specified object are equal.\r
139         /// </summary>\r
140         /// <param name="obj">Another object to compare to.</param>\r
141         /// <returns>\r
142         /// true if <paramref name="obj"/> and this instance are the same type and represent the same value; otherwise, false.\r
143         /// </returns>\r
144         public override bool Equals(object obj)\r
145         {\r
146             if (obj == null)\r
147                 return false;\r
148 \r
149             if (GetType() != obj.GetType())\r
150                 return false;\r
151 \r
152             return Equals((TransformedColoredTexturedVertex)obj);\r
153         }\r
154 \r
155         /// <summary>\r
156         /// Indicates whether the current object is equal to another object of the same type.\r
157         /// </summary>\r
158         /// <param name="other">An object to compare with this object.</param>\r
159         /// <returns>\r
160         /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.\r
161         /// </returns>\r
162         public bool Equals(TransformedColoredTexturedVertex other)\r
163         {\r
164             return (Position == other.Position && Color == other.Color && TextureCoordinates == other.TextureCoordinates);\r
165         }\r
166 \r
167         /// <summary>\r
168         /// Returns a string representation of the current object.\r
169         /// </summary>\r
170         /// <returns>\r
171         /// A <see cref="T:System.String"/> representing the vertex.\r
172         /// </returns>\r
173         public override string ToString()\r
174         {\r
175             return string.Format(CultureInfo.CurrentCulture, "{0} ({1}, {2})", Position.ToString(), System.Drawing.Color.FromArgb(Color).ToString(), TextureCoordinates.ToString());\r
176         }\r
177     }\r
178 }\r