CustomVertex.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //-----------------------------------------------------------------------------
  2. // CustomVertex.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using Microsoft.Xna.Framework;
  8. using Microsoft.Xna.Framework.Content;
  9. using Microsoft.Xna.Framework.Graphics;
  10. namespace UseCustomVertex
  11. {
  12. //[StructLayout(LayoutKind.Sequential)]
  13. public struct CustomVertex : IVertexType
  14. {
  15. Vector3 vertexPosition;
  16. Vector2 vertexTextureCoordinate;
  17. public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration
  18. (
  19. new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
  20. new VertexElement(12, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
  21. );
  22. //The constructor for the custom vertex. This allows similar
  23. //initialization of custom vertex arrays as compared to arrays of a
  24. //standard vertex type, such as VertexPositionColor.
  25. public CustomVertex(Vector3 pos, Vector2 textureCoordinate)
  26. {
  27. vertexPosition = pos;
  28. vertexTextureCoordinate = textureCoordinate;
  29. }
  30. //Public methods for accessing the components of the custom vertex.
  31. public Vector3 Position
  32. {
  33. get { return vertexPosition; }
  34. set { vertexPosition = value; }
  35. }
  36. public Vector2 TextureCoordinate
  37. {
  38. get { return vertexTextureCoordinate; }
  39. set { vertexTextureCoordinate = value; }
  40. }
  41. VertexDeclaration IVertexType.VertexDeclaration
  42. {
  43. get { return VertexDeclaration; }
  44. }
  45. }
  46. }