OSDN Git Service

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