VertexPositionNormalColor.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #region License
  2. // Copyright 2020 Kastellanos Nikolaos
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. using System;
  17. using Microsoft.Xna.Framework;
  18. using Microsoft.Xna.Framework.Graphics;
  19. namespace nkast.Aether.Content.Pipeline
  20. {
  21. public struct VertexPositionNormalColor : IVertexType, IEquatable<VertexPositionNormalColor>
  22. {
  23. public Vector3 Position;
  24. public Vector3 Normal;
  25. public Color Color;
  26. #region IVertexType Members
  27. public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration(
  28. new VertexElement[]
  29. {
  30. new VertexElement( 0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
  31. new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
  32. new VertexElement(24, VertexElementFormat.Color, VertexElementUsage.Color, 0)
  33. });
  34. VertexDeclaration IVertexType.VertexDeclaration
  35. {
  36. get { return VertexDeclaration; }
  37. }
  38. #endregion
  39. public VertexPositionNormalColor(Vector3 position, Vector3 normal, Color color)
  40. {
  41. this.Position = position;
  42. this.Normal = normal;
  43. this.Color = color;
  44. }
  45. public override int GetHashCode()
  46. {
  47. return (Position.X.GetHashCode() ^ Position.Y.GetHashCode() ^ Position.Z.GetHashCode()
  48. ^ Normal.X.GetHashCode() ^ Normal.Y.GetHashCode() ^ Normal.Z.GetHashCode()
  49. ^ Color.GetHashCode()
  50. );
  51. }
  52. public override bool Equals(object obj)
  53. {
  54. if (obj is VertexPositionNormalColor)
  55. return Equals((VertexPositionNormalColor)obj);
  56. else
  57. return false;
  58. }
  59. public bool Equals(VertexPositionNormalColor other)
  60. {
  61. return (Position.X.Equals(other.Position.X) && Position.Y.Equals(other.Position.Y) && Position.Z.Equals(other.Position.Z)
  62. && Normal.X.Equals(other.Normal.X) && Normal.Y.Equals(other.Normal.Y) && Normal.Z.Equals(other.Normal.Z)
  63. && Color.PackedValue.Equals(other.Color.PackedValue)
  64. );
  65. }
  66. bool IEquatable<VertexPositionNormalColor>.Equals(VertexPositionNormalColor other)
  67. {
  68. return (Position.X.Equals(other.Position.X) && Position.Y.Equals(other.Position.Y) && Position.Z.Equals(other.Position.Z)
  69. && Normal.X.Equals(other.Normal.X) && Normal.Y.Equals(other.Normal.Y) && Normal.Z.Equals(other.Normal.Z)
  70. && Color.PackedValue.Equals(other.Color.PackedValue)
  71. );
  72. }
  73. }
  74. }