2 * Copyright (c) 2007-2009 SlimDX Group
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
23 using System.Globalization;
24 using System.Runtime.InteropServices;
26 using SlimDX.Direct3D9;
28 namespace SampleFramework
31 /// Represents a single transformed, colored, and textured vertex.
33 [StructLayout(LayoutKind.Sequential)]
34 public struct TransformedColoredTexturedVertex : IEquatable<TransformedColoredTexturedVertex>
36 private Vector4 m_Position;
38 /// Gets or sets the transformed position of the vertex.
40 /// <value>The transformed position of the vertex.</value>
41 [VertexElement(DeclarationType.Float4, DeclarationUsage.PositionTransformed)]
42 public Vector4 Position
44 get { return m_Position; }
45 set { m_Position = value; }
50 /// Gets or sets the color of the vertex.
52 /// <value>The color of the vertex.</value>
53 [VertexElement(DeclarationType.Color, DeclarationUsage.Color)]
56 get { return m_Color; }
57 set { m_Color = value; }
60 private Vector2 m_TextureCoordinates;
62 /// Gets or sets the texture coordinates.
64 /// <value>The texture coordinates.</value>
65 [VertexElement(DeclarationType.Float2, DeclarationUsage.TextureCoordinate)]
66 public Vector2 TextureCoordinates
68 get { return m_TextureCoordinates; }
69 set { m_TextureCoordinates = value; }
73 /// Gets the size in bytes.
75 /// <value>The size in bytes.</value>
76 public static int SizeInBytes
78 get { return Marshal.SizeOf(typeof(TransformedColoredTexturedVertex)); }
84 /// <value>The format.</value>
85 public static VertexFormat Format
87 get { return VertexFormat.PositionRhw | VertexFormat.Diffuse | VertexFormat.Texture1; }
91 /// Initializes a new instance of the <see cref="TransformedColoredTexturedVertex"/> struct.
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)
101 TextureCoordinates = textureCoordinates;
105 /// Implements the operator ==.
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)
112 return left.Equals(right);
116 /// Implements the operator !=.
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)
123 return !(left == right);
127 /// Returns the hash code for this instance.
130 /// A 32-bit signed integer that is the hash code for this instance.
132 public override int GetHashCode()
134 return Position.GetHashCode() + Color.GetHashCode() + TextureCoordinates.GetHashCode();
138 /// Indicates whether this instance and a specified object are equal.
140 /// <param name="obj">Another object to compare to.</param>
142 /// true if <paramref name="obj"/> and this instance are the same type and represent the same value; otherwise, false.
144 public override bool Equals(object obj)
149 if (GetType() != obj.GetType())
152 return Equals((TransformedColoredTexturedVertex)obj);
156 /// Indicates whether the current object is equal to another object of the same type.
158 /// <param name="other">An object to compare with this object.</param>
160 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
162 public bool Equals(TransformedColoredTexturedVertex other)
164 return (Position == other.Position && Color == other.Color && TextureCoordinates == other.TextureCoordinates);
168 /// Returns a string representation of the current object.
171 /// A <see cref="T:System.String"/> representing the vertex.
173 public override string ToString()
175 return string.Format(CultureInfo.CurrentCulture, "{0} ({1}, {2})", Position.ToString(), System.Drawing.Color.FromArgb(Color).ToString(), TextureCoordinates.ToString());