Root/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | #region License /* FNA - XNA4 Reimplementation for Desktop Platforms * Copyright 2009-2016 Ethan Lee and the MonoGame Team * * Released under the Microsoft Public License. * See LICENSE for details. */ #endregion #region Using Statements using System; #endregion namespace Microsoft.Xna.Framework.Graphics.PackedVector { public struct NormalizedShort4 : IPackedVector< ulong >, IEquatable<NormalizedShort4> { #region Public Properties [CLSCompliant( false )] public ulong PackedValue { get { return packedValue; } set { packedValue = value; } } #endregion #region Private Variables private ulong packedValue; #endregion #region Public Constructors public NormalizedShort4(Vector4 vector) { packedValue = Pack(vector.X, vector.Y, vector.Z, vector.W); } public NormalizedShort4( float x, float y, float z, float w) { packedValue = Pack(x, y, z, w); } #endregion #region Public Methods public Vector4 ToVector4() { const float maxVal = 0x7FFF; return new Vector4( (( short ) ((packedValue >> 0x00) & 0xFFFF)) / maxVal, (( short ) ((packedValue >> 0x10) & 0xFFFF)) / maxVal, (( short ) ((packedValue >> 0x20) & 0xFFFF)) / maxVal, (( short ) ((packedValue >> 0x30) & 0xFFFF)) / maxVal ); } #endregion #region IPackedVector Methods void IPackedVector.PackFromVector4(Vector4 vector) { packedValue = Pack(vector.X, vector.Y, vector.Z, vector.W); } #endregion #region Public Static Operators and Override Methods public static bool operator !=(NormalizedShort4 a, NormalizedShort4 b) { return !a.Equals(b); } public static bool operator ==(NormalizedShort4 a, NormalizedShort4 b) { return a.Equals(b); } public override bool Equals( object obj) { return (obj is NormalizedShort4) && Equals((NormalizedShort4) obj); } public bool Equals(NormalizedShort4 other) { return packedValue.Equals(other.packedValue); } public override int GetHashCode() { return packedValue.GetHashCode(); } public override string ToString() { return packedValue.ToString( "X" ); } #endregion #region Private Static Pack Method private static ulong Pack( float vectorX, float vectorY, float vectorZ, float vectorW) { const float maxPos = 0x7FFF; const float minNeg = -maxPos; return ( ((( ulong ) MathHelper.Clamp(( float ) Math.Round(vectorX * maxPos), minNeg, maxPos) & 0xFFFF) << 0x00) | ((( ulong ) MathHelper.Clamp(( float ) Math.Round(vectorY * maxPos), minNeg, maxPos) & 0xFFFF) << 0x10) | ((( ulong ) MathHelper.Clamp(( float ) Math.Round(vectorZ * maxPos), minNeg, maxPos) & 0xFFFF) << 0x20) | ((( ulong ) MathHelper.Clamp(( float ) Math.Round(vectorW * maxPos), minNeg, maxPos) & 0xFFFF) << 0x30) ); } #endregion } } |