fna-workbench

fna-workbench Git Source Tree


Root/src/Graphics/PackedVector/HalfVector2.cs

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
#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 HalfVector2 : IPackedVector<uint>, IPackedVector, IEquatable<HalfVector2>
    {
        #region Public Properties
 
        [CLSCompliant(false)]
        public uint PackedValue
        {
            get
            {
                return packedValue;
            }
            set
            {
                packedValue = value;
            }
        }
 
        #endregion
 
        #region Private Variables
 
        private uint packedValue;
 
        #endregion
 
        #region Public Constructors
 
        public HalfVector2(float x, float y)
        {
            packedValue = PackHelper(x, y);
        }
 
        public HalfVector2(Vector2 vector)
        {
            packedValue = PackHelper(vector.X, vector.Y);
        }
 
        #endregion
 
        #region Public Methods
 
        public Vector2 ToVector2()
        {
            Vector2 vector;
            vector.X = HalfTypeHelper.Convert((ushort) packedValue);
            vector.Y = HalfTypeHelper.Convert((ushort) (packedValue >> 0x10));
            return vector;
        }
 
        #endregion
 
        #region IPackedVector Methods
 
        void IPackedVector.PackFromVector4(Vector4 vector)
        {
            packedValue = PackHelper(vector.X, vector.Y);
        }
 
        Vector4 IPackedVector.ToVector4()
        {
            Vector2 vector = ToVector2();
            return new Vector4(vector.X, vector.Y, 0f, 1f);
        }
 
        #endregion
 
        #region Public Static Operators and Override Methods
 
        public override string ToString()
        {
            return ToVector2().ToString();
        }
 
        public override int GetHashCode()
        {
            return packedValue.GetHashCode();
        }
 
        public override bool Equals(object obj)
        {
            return ((obj is HalfVector2) && Equals((HalfVector2) obj));
        }
 
        public bool Equals(HalfVector2 other)
        {
            return packedValue.Equals(other.packedValue);
        }
 
        public static bool operator ==(HalfVector2 a, HalfVector2 b)
        {
            return a.Equals(b);
        }
 
        public static bool operator !=(HalfVector2 a, HalfVector2 b)
        {
            return !a.Equals(b);
        }
 
        #endregion
 
        #region Private Static Pack Method
 
        private static uint PackHelper(float vectorX, float vectorY)
        {
            return (
                HalfTypeHelper.Convert(vectorX) |
                ((uint) (HalfTypeHelper.Convert(vectorY) << 0x10))
            );
        }
 
        #endregion
    }
}

Archive Download this file

Branches

Number of commits:
Page rendered in 0.22880s using 13 queries.