Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Half3.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 three component vector, using half precision floating point coordinates.
33  /// </summary>
34  [DataContract]
35  [StructLayout(LayoutKind.Sequential, Pack = 2)]
36  public struct Half3 : IEquatable<Half3>
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 
54  /// <summary>
55  /// Initializes a new instance of the <see cref="T:SiliconStudio.Core.Mathematics.Half3" /> structure.
56  /// </summary>
57  /// <param name="x">The X component.</param>
58  /// <param name="y">The Y component.</param>
59  /// <param name="z">The Z component.</param>
60  public Half3(Half x, Half y, Half z)
61  {
62  this.X = x;
63  this.Y = y;
64  this.Z = z;
65  }
66 
67  /// <summary>
68  /// Initializes a new instance of the <see cref="T:SiliconStudio.Core.Mathematics.Half3" /> structure.
69  /// </summary>
70  /// <param name="value">The value to set for the X, Y, and Z components.</param>
71  public Half3(Half value)
72  {
73  this.X = value;
74  this.Y = value;
75  this.Z = value;
76  }
77 
78  /// <summary>
79  /// Initializes a new instance of the <see cref="T:SiliconStudio.Core.Mathematics.Half3" /> structure.
80  /// </summary>
81  /// <param name="x">The X component.</param>
82  /// <param name="y">The Y component.</param>
83  /// <param name="z">The Z component.</param>
84  public Half3(float x, float y, float z)
85  {
86  this.X = (Half)x;
87  this.Y = (Half)y;
88  this.Z = (Half)z;
89  }
90 
91  /// <summary>
92  /// Initializes a new instance of the <see cref="T:SiliconStudio.Core.Mathematics.Half3" /> structure.
93  /// </summary>
94  /// <param name="value">The value to set for the X, Y, and Z components.</param>
95  public Half3(float value)
96  {
97  this.X = (Half)value;
98  this.Y = (Half)value;
99  this.Z = (Half)value;
100  }
101 
102  /// <summary>
103  /// Tests for equality between two objects.
104  /// </summary>
105  /// <param name="left">The first value to compare.</param>
106  /// <param name="right">The second value to compare.</param>
107  /// <returns>
108  /// <c>true</c> if <paramref name="left" /> has the same value as <paramref name="right" />; otherwise, <c>false</c>.</returns>
109  public static bool operator ==(Half3 left, Half3 right)
110  {
111  return Equals(ref left, ref right);
112  }
113 
114  /// <summary>
115  /// Tests for inequality between two objects.
116  /// </summary>
117  /// <param name="left">The first value to compare.</param>
118  /// <param name="right">The second value to compare.</param>
119  /// <returns>
120  /// <c>true</c> if <paramref name="left" /> has a different value than <paramref name="right" />; otherwise, <c>false</c>.</returns>
121  [return: MarshalAs(UnmanagedType.U1)]
122  public static bool operator !=(Half3 left, Half3 right)
123  {
124  return !Equals(ref left, ref right);
125  }
126 
127  /// <summary>
128  /// Returns the hash code for this instance.
129  /// </summary>
130  /// <returns>A 32-bit signed integer hash code.</returns>
131  public override int GetHashCode()
132  {
133  int num = this.Z.GetHashCode() + this.Y.GetHashCode();
134  return (this.X.GetHashCode() + num);
135  }
136 
137  /// <summary>
138  /// Determines whether the specified object instances are considered equal.
139  /// </summary>
140  /// <param name="value1" />
141  /// <param name="value2" />
142  /// <returns>
143  /// <c>true</c> if <paramref name="value1" /> is the same instance as <paramref name="value2" /> or
144  /// if both are <c>null</c> references or if <c>value1.Equals(value2)</c> returns <c>true</c>; otherwise, <c>false</c>.</returns>
145  public static bool Equals(ref Half3 value1, ref Half3 value2)
146  {
147  return (((value1.X == value2.X) && (value1.Y == value2.Y)) && (value1.Z == value2.Z));
148  }
149 
150  /// <summary>
151  /// Returns a value that indicates whether the current instance is equal to the specified object.
152  /// </summary>
153  /// <param name="other">Object to make the comparison with.</param>
154  /// <returns>
155  /// <c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns>
156  public bool Equals(Half3 other)
157  {
158  return (((this.X == other.X) && (this.Y == other.Y)) && (this.Z == other.Z));
159  }
160 
161  /// <summary>
162  /// Performs an explicit conversion from <see cref="Vector3"/> to <see cref="Half3"/>.
163  /// </summary>
164  /// <param name="value">The value.</param>
165  /// <returns>The result of the conversion.</returns>
166  public static explicit operator Half3(Vector3 value)
167  {
168  return new Half3((Half)value.X, (Half)value.Y, (Half)value.Z);
169  }
170 
171  /// <summary>
172  /// Performs an explicit conversion from <see cref="Vector3"/> to <see cref="Half3"/>.
173  /// </summary>
174  /// <param name="value">The value.</param>
175  /// <returns>The result of the conversion.</returns>
176  public static explicit operator Vector3(Half3 value)
177  {
178  return new Vector3(value.X, value.Y, value.Z);
179  }
180 
181  /// <summary>
182  /// Returns a value that indicates whether the current instance is equal to a specified object.
183  /// </summary>
184  /// <param name="obj">Object to make the comparison with.</param>
185  /// <returns>
186  /// <c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns>
187  public override bool Equals(object obj)
188  {
189  if (obj == null)
190  {
191  return false;
192  }
193  if (obj.GetType() != base.GetType())
194  {
195  return false;
196  }
197  return this.Equals((Half3)obj);
198  }
199  }
200 }
Half3(Half x, Half y, Half z)
Initializes a new instance of the T:SiliconStudio.Core.Mathematics.Half3 structure.
Definition: Half3.cs:60
float Y
The Y component of the vector.
Definition: Vector3.cs:84
Half X
Gets or sets the X component of the vector.
Definition: Half3.cs:42
override bool Equals(object obj)
Returns a value that indicates whether the current instance is equal to a specified object...
Definition: Half3.cs:187
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
Definition: DirectXTexP.h:191
Half3(float x, float y, float z)
Initializes a new instance of the T:SiliconStudio.Core.Mathematics.Half3 structure.
Definition: Half3.cs:84
float X
The X component of the vector.
Definition: Vector3.cs:78
Represents a three dimensional mathematical vector.
Definition: Vector3.cs:42
bool Equals(Half3 other)
Returns a value that indicates whether the current instance is equal to the specified object...
Definition: Half3.cs:156
Half3(Half value)
Initializes a new instance of the T:SiliconStudio.Core.Mathematics.Half3 structure.
Definition: Half3.cs:71
A half precision (16 bit) floating point value.
Definition: Half.cs:37
override int GetHashCode()
Returns the hash code for this instance.
Definition: Half3.cs:131
SiliconStudio.Paradox.Games.Mathematics.Half Half
static bool Equals(ref Half3 value1, ref Half3 value2)
Determines whether the specified object instances are considered equal.
Definition: Half3.cs:145
Defines a three component vector, using half precision floating point coordinates.
Definition: Half3.cs:36
SiliconStudio.Core.Mathematics.Vector3 Vector3
float Z
The Z component of the vector.
Definition: Vector3.cs:90
Half3(float value)
Initializes a new instance of the T:SiliconStudio.Core.Mathematics.Half3 structure.
Definition: Half3.cs:95
Half Z
Gets or sets the Z component of the vector.
Definition: Half3.cs:52
Half Y
Gets or sets the Y component of the vector.
Definition: Half3.cs:47
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t size_t z
Definition: DirectXTexP.h:191