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