Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Half4.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under MIT License. See LICENSE.md for details.
3 //
4 // Copyright (c) 2010-2011 SharpDX - Alexandre Mutel
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // THE SOFTWARE.
23 
24 using System;
25 using System.ComponentModel;
26 using System.Runtime.InteropServices;
27 using SiliconStudio.Core.Serialization;
28 
29 namespace SiliconStudio.Core.Mathematics
30 {
31  /// <summary>
32  /// Defines a four component vector, using half precision floating point coordinates.
33  /// </summary>
34  [DataContract]
35  [StructLayout(LayoutKind.Sequential, Pack = 2)]
36  public struct Half4 : IEquatable<Half4>
37  {
38  /// <summary>
39  /// Gets or sets the X component of the vector.
40  /// </summary>
41  /// <value>The X component of the vector.</value>
42  public Half X;
43  /// <summary>
44  /// Gets or sets the Y component of the vector.
45  /// </summary>
46  /// <value>The Y component of the vector.</value>
47  public Half Y;
48  /// <summary>
49  /// Gets or sets the Z component of the vector.
50  /// </summary>
51  /// <value>The Z component of the vector.</value>
52  public Half Z;
53  /// <summary>
54  /// Gets or sets the W component of the vector.
55  /// </summary>
56  /// <value>The W component of the vector.</value>
57  public Half W;
58 
59  /// <summary>
60  /// Initializes a new instance of the <see cref="T:SiliconStudio.Core.Mathematics.Half4" /> structure.
61  /// </summary>
62  /// <param name="x">The X component.</param>
63  /// <param name="y">The Y component.</param>
64  /// <param name="z">The Z component.</param>
65  /// <param name="w">The W component.</param>
66  public Half4(Half x, Half y, Half z, Half w)
67  {
68  this.X = x;
69  this.Y = y;
70  this.Z = z;
71  this.W = w;
72  }
73 
74  /// <summary>
75  /// Initializes a new instance of the <see cref="T:SiliconStudio.Core.Mathematics.Half4" /> structure.
76  /// </summary>
77  /// <param name="value">The value to set for the X, Y, Z, and W components.</param>
78  public Half4(Half value)
79  {
80  this.X = value;
81  this.Y = value;
82  this.Z = value;
83  this.W = value;
84  }
85 
86  /// <summary>
87  /// Tests for equality between two objects.
88  /// </summary>
89  /// <param name="left">The first value to compare.</param>
90  /// <param name="right">The second value to compare.</param>
91  /// <returns>
92  /// <c>true</c> if <paramref name="left" /> has the same value as <paramref name="right" />; otherwise, <c>false</c>.</returns>
93  public static bool operator ==(Half4 left, Half4 right)
94  {
95  return Equals(ref left, ref right);
96  }
97 
98  /// <summary>
99  /// Tests for inequality between two objects.
100  /// </summary>
101  /// <param name="left">The first value to compare.</param>
102  /// <param name="right">The second value to compare.</param>
103  /// <returns>
104  /// <c>true</c> if <paramref name="left" /> has a different value than <paramref name="right" />; otherwise, <c>false</c>.</returns>
105  public static bool operator !=(Half4 left, Half4 right)
106  {
107  return !Equals(ref left, ref right);
108  }
109 
110  /// <summary>
111  /// Returns the hash code for this instance.
112  /// </summary>
113  /// <returns>A 32-bit signed integer hash code.</returns>
114  public override int GetHashCode()
115  {
116  int num2 = this.W.GetHashCode() + this.Z.GetHashCode();
117  int num = this.Y.GetHashCode() + num2;
118  return (this.X.GetHashCode() + num);
119  }
120 
121  /// <summary>
122  /// Determines whether the specified object instances are considered equal.
123  /// </summary>
124  /// <param name="value1" />
125  /// <param name="value2" />
126  /// <returns>
127  /// <c>true</c> if <paramref name="value1" /> is the same instance as <paramref name="value2" /> or
128  /// if both are <c>null</c> references or if <c>value1.Equals(value2)</c> returns <c>true</c>; otherwise, <c>false</c>.</returns>
129  public static bool Equals(ref Half4 value1, ref Half4 value2)
130  {
131  return (((value1.X == value2.X) && (value1.Y == value2.Y)) && ((value1.Z == value2.Z) && (value1.W == value2.W)));
132  }
133 
134  /// <summary>
135  /// Returns a value that indicates whether the current instance is equal to the specified object.
136  /// </summary>
137  /// <param name="other">Object to make the comparison with.</param>
138  /// <returns>
139  /// <c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns>
140  public bool Equals(Half4 other)
141  {
142  return (((this.X == other.X) && (this.Y == other.Y)) && ((this.Z == other.Z) && (this.W == other.W)));
143  }
144 
145  /// <summary>
146  /// Performs an explicit conversion from <see cref="Vector4"/> to <see cref="Half4"/>.
147  /// </summary>
148  /// <param name="value">The value.</param>
149  /// <returns>The result of the conversion.</returns>
150  public static explicit operator Half4(Vector4 value)
151  {
152  return new Half4((Half)value.X, (Half)value.Y, (Half)value.Z, (Half)value.W);
153  }
154 
155  /// <summary>
156  /// Performs an explicit conversion from <see cref="Vector4"/> to <see cref="Half4"/>.
157  /// </summary>
158  /// <param name="value">The value.</param>
159  /// <returns>The result of the conversion.</returns>
160  public static explicit operator Vector4(Half4 value)
161  {
162  return new Vector4(value.X, value.Y, value.Z, value.W);
163  }
164 
165  /// <summary>
166  /// Returns a value that indicates whether the current instance is equal to a specified object.
167  /// </summary>
168  /// <param name="obj">Object to make the comparison with.</param>
169  /// <returns>
170  /// <c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns>
171  public override bool Equals(object obj)
172  {
173  if (obj == null)
174  {
175  return false;
176  }
177  if (obj.GetType() != base.GetType())
178  {
179  return false;
180  }
181  return this.Equals((Half4)obj);
182  }
183  }
184 }
float W
The W component of the vector.
Definition: Vector4.cs:101
Half Z
Gets or sets the Z component of the vector.
Definition: Half4.cs:52
float X
The X component of the vector.
Definition: Vector4.cs:83
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
Definition: DirectXTexP.h:191
Half Y
Gets or sets the Y component of the vector.
Definition: Half4.cs:47
SiliconStudio.Paradox.Games.Mathematics.Half4 Half4
static bool Equals(ref Half4 value1, ref Half4 value2)
Determines whether the specified object instances are considered equal.
Definition: Half4.cs:129
Half W
Gets or sets the W component of the vector.
Definition: Half4.cs:57
A half precision (16 bit) floating point value.
Definition: Half.cs:37
Represents a four dimensional mathematical vector.
Definition: Vector4.cs:42
override bool Equals(object obj)
Returns a value that indicates whether the current instance is equal to a specified object...
Definition: Half4.cs:171
bool Equals(Half4 other)
Returns a value that indicates whether the current instance is equal to the specified object...
Definition: Half4.cs:140
float Y
The Y component of the vector.
Definition: Vector4.cs:89
Half4(Half x, Half y, Half z, Half w)
Initializes a new instance of the T:SiliconStudio.Core.Mathematics.Half4 structure.
Definition: Half4.cs:66
float Z
The Z component of the vector.
Definition: Vector4.cs:95
Half4(Half value)
Initializes a new instance of the T:SiliconStudio.Core.Mathematics.Half4 structure.
Definition: Half4.cs:78
Defines a four component vector, using half precision floating point coordinates. ...
Definition: Half4.cs:36
override int GetHashCode()
Returns the hash code for this instance.
Definition: Half4.cs:114
Half X
Gets or sets the X component of the vector.
Definition: Half4.cs:42
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t size_t z
Definition: DirectXTexP.h:191