Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Vector2.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 // -----------------------------------------------------------------------------
5 // Original code from SlimMath project. http://code.google.com/p/slimmath/
6 // Greetings to SlimDX Group. Original code published with the following license:
7 // -----------------------------------------------------------------------------
8 /*
9 * Copyright (c) 2007-2011 SlimDX Group
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * THE SOFTWARE.
28 */
29 using System;
30 using System.Globalization;
31 using System.Runtime.InteropServices;
32 using System.ComponentModel;
33 
34 namespace SiliconStudio.Core.Mathematics
35 {
36  /// <summary>
37  /// Represents a two dimensional mathematical vector.
38  /// </summary>
39  [DataContract("float2")]
40  [DataStyle(DataStyle.Compact)]
41  [StructLayout(LayoutKind.Sequential, Pack = 4)]
42  public struct Vector2 : IEquatable<Vector2>, IFormattable
43  {
44  /// <summary>
45  /// The size of the <see cref="SiliconStudio.Core.Mathematics.Vector2"/> type, in bytes.
46  /// </summary>
47  public static readonly int SizeInBytes = Marshal.SizeOf(typeof(Vector2));
48 
49  /// <summary>
50  /// A <see cref="SiliconStudio.Core.Mathematics.Vector2"/> with all of its components set to zero.
51  /// </summary>
52  public static readonly Vector2 Zero = new Vector2();
53 
54  /// <summary>
55  /// The X unit <see cref="SiliconStudio.Core.Mathematics.Vector2"/> (1, 0).
56  /// </summary>
57  public static readonly Vector2 UnitX = new Vector2(1.0f, 0.0f);
58 
59  /// <summary>
60  /// The Y unit <see cref="SiliconStudio.Core.Mathematics.Vector2"/> (0, 1).
61  /// </summary>
62  public static readonly Vector2 UnitY = new Vector2(0.0f, 1.0f);
63 
64  /// <summary>
65  /// A <see cref="SiliconStudio.Core.Mathematics.Vector2"/> with all of its components set to one.
66  /// </summary>
67  public static readonly Vector2 One = new Vector2(1.0f, 1.0f);
68 
69  /// <summary>
70  /// The X component of the vector.
71  /// </summary>
72  [DataMember(0)]
73  public float X;
74 
75  /// <summary>
76  /// The Y component of the vector.
77  /// </summary>
78  [DataMember(1)]
79  public float Y;
80 
81  /// <summary>
82  /// Initializes a new instance of the <see cref="SiliconStudio.Core.Mathematics.Vector2"/> struct.
83  /// </summary>
84  /// <param name="value">The value that will be assigned to all components.</param>
85  public Vector2(float value)
86  {
87  X = value;
88  Y = value;
89  }
90 
91  /// <summary>
92  /// Initializes a new instance of the <see cref="SiliconStudio.Core.Mathematics.Vector2"/> struct.
93  /// </summary>
94  /// <param name="x">Initial value for the X component of the vector.</param>
95  /// <param name="y">Initial value for the Y component of the vector.</param>
96  public Vector2(float x, float y)
97  {
98  X = x;
99  Y = y;
100  }
101 
102  /// <summary>
103  /// Initializes a new instance of the <see cref="SiliconStudio.Core.Mathematics.Vector2"/> struct.
104  /// </summary>
105  /// <param name="values">The values to assign to the X and Y components of the vector. This must be an array with two elements.</param>
106  /// <exception cref="ArgumentNullException">Thrown when <paramref name="values"/> is <c>null</c>.</exception>
107  /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="values"/> contains more or less than two elements.</exception>
108  public Vector2(float[] values)
109  {
110  if (values == null)
111  throw new ArgumentNullException("values");
112  if (values.Length != 2)
113  throw new ArgumentOutOfRangeException("values", "There must be two and only two input values for Vector2.");
114 
115  X = values[0];
116  Y = values[1];
117  }
118 
119  /// <summary>
120  /// Gets a value indicting whether this instance is normalized.
121  /// </summary>
122  public bool IsNormalized
123  {
124  get { return Math.Abs((X * X) + (Y * Y) - 1f) < MathUtil.ZeroTolerance; }
125  }
126 
127  /// <summary>
128  /// Gets or sets the component at the specified index.
129  /// </summary>
130  /// <value>The value of the X or Y component, depending on the index.</value>
131  /// <param name="index">The index of the component to access. Use 0 for the X component and 1 for the Y component.</param>
132  /// <returns>The value of the component at the specified index.</returns>
133  /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="index"/> is out of the range [0, 1].</exception>
134  public float this[int index]
135  {
136  get
137  {
138  switch (index)
139  {
140  case 0: return X;
141  case 1: return Y;
142  }
143 
144  throw new ArgumentOutOfRangeException("index", "Indices for Vector2 run from 0 to 1, inclusive.");
145  }
146 
147  set
148  {
149  switch (index)
150  {
151  case 0: X = value; break;
152  case 1: Y = value; break;
153  default: throw new ArgumentOutOfRangeException("index", "Indices for Vector2 run from 0 to 1, inclusive.");
154  }
155  }
156  }
157 
158  /// <summary>
159  /// Calculates the length of the vector.
160  /// </summary>
161  /// <returns>The length of the vector.</returns>
162  /// <remarks>
163  /// <see cref="SiliconStudio.Core.Mathematics.Vector2.LengthSquared"/> may be preferred when only the relative length is needed
164  /// and speed is of the essence.
165  /// </remarks>
166  public float Length()
167  {
168  return (float)Math.Sqrt((X * X) + (Y * Y));
169  }
170 
171  /// <summary>
172  /// Calculates the squared length of the vector.
173  /// </summary>
174  /// <returns>The squared length of the vector.</returns>
175  /// <remarks>
176  /// This method may be preferred to <see cref="SiliconStudio.Core.Mathematics.Vector2.Length"/> when only a relative length is needed
177  /// and speed is of the essence.
178  /// </remarks>
179  public float LengthSquared()
180  {
181  return (X * X) + (Y * Y);
182  }
183 
184  /// <summary>
185  /// Converts the vector into a unit vector.
186  /// </summary>
187  public void Normalize()
188  {
189  float length = Length();
190  if (length > MathUtil.ZeroTolerance)
191  {
192  float inv = 1.0f / length;
193  X *= inv;
194  Y *= inv;
195  }
196  }
197 
198  /// <summary>
199  /// Creates an array containing the elements of the vector.
200  /// </summary>
201  /// <returns>A two-element array containing the components of the vector.</returns>
202  public float[] ToArray()
203  {
204  return new float[] { X, Y };
205  }
206 
207  /// <summary>
208  /// Adds two vectors.
209  /// </summary>
210  /// <param name="left">The first vector to add.</param>
211  /// <param name="right">The second vector to add.</param>
212  /// <param name="result">When the method completes, contains the sum of the two vectors.</param>
213  public static void Add(ref Vector2 left, ref Vector2 right, out Vector2 result)
214  {
215  result = new Vector2(left.X + right.X, left.Y + right.Y);
216  }
217 
218  /// <summary>
219  /// Adds two vectors.
220  /// </summary>
221  /// <param name="left">The first vector to add.</param>
222  /// <param name="right">The second vector to add.</param>
223  /// <returns>The sum of the two vectors.</returns>
224  public static Vector2 Add(Vector2 left, Vector2 right)
225  {
226  return new Vector2(left.X + right.X, left.Y + right.Y);
227  }
228 
229  /// <summary>
230  /// Subtracts two vectors.
231  /// </summary>
232  /// <param name="left">The first vector to subtract.</param>
233  /// <param name="right">The second vector to subtract.</param>
234  /// <param name="result">When the method completes, contains the difference of the two vectors.</param>
235  public static void Subtract(ref Vector2 left, ref Vector2 right, out Vector2 result)
236  {
237  result = new Vector2(left.X - right.X, left.Y - right.Y);
238  }
239 
240  /// <summary>
241  /// Subtracts two vectors.
242  /// </summary>
243  /// <param name="left">The first vector to subtract.</param>
244  /// <param name="right">The second vector to subtract.</param>
245  /// <returns>The difference of the two vectors.</returns>
246  public static Vector2 Subtract(Vector2 left, Vector2 right)
247  {
248  return new Vector2(left.X - right.X, left.Y - right.Y);
249  }
250 
251  /// <summary>
252  /// Scales a vector by the given value.
253  /// </summary>
254  /// <param name="value">The vector to scale.</param>
255  /// <param name="scale">The amount by which to scale the vector.</param>
256  /// <param name="result">When the method completes, contains the scaled vector.</param>
257  public static void Multiply(ref Vector2 value, float scale, out Vector2 result)
258  {
259  result = new Vector2(value.X * scale, value.Y * scale);
260  }
261 
262  /// <summary>
263  /// Scales a vector by the given value.
264  /// </summary>
265  /// <param name="value">The vector to scale.</param>
266  /// <param name="scale">The amount by which to scale the vector.</param>
267  /// <returns>The scaled vector.</returns>
268  public static Vector2 Multiply(Vector2 value, float scale)
269  {
270  return new Vector2(value.X * scale, value.Y * scale);
271  }
272 
273  /// <summary>
274  /// Modulates a vector with another by performing component-wise multiplication.
275  /// </summary>
276  /// <param name="left">The first vector to modulate.</param>
277  /// <param name="right">The second vector to modulate.</param>
278  /// <param name="result">When the method completes, contains the modulated vector.</param>
279  public static void Modulate(ref Vector2 left, ref Vector2 right, out Vector2 result)
280  {
281  result = new Vector2(left.X * right.X, left.Y * right.Y);
282  }
283 
284  /// <summary>
285  /// Modulates a vector with another by performing component-wise multiplication.
286  /// </summary>
287  /// <param name="left">The first vector to modulate.</param>
288  /// <param name="right">The second vector to modulate.</param>
289  /// <returns>The modulated vector.</returns>
290  public static Vector2 Modulate(Vector2 left, Vector2 right)
291  {
292  return new Vector2(left.X * right.X, left.Y * right.Y);
293  }
294 
295  /// <summary>
296  /// Scales a vector by the given value.
297  /// </summary>
298  /// <param name="value">The vector to scale.</param>
299  /// <param name="scale">The amount by which to scale the vector.</param>
300  /// <param name="result">When the method completes, contains the scaled vector.</param>
301  public static void Divide(ref Vector2 value, float scale, out Vector2 result)
302  {
303  result = new Vector2(value.X / scale, value.Y / scale);
304  }
305 
306  /// <summary>
307  /// Scales a vector by the given value.
308  /// </summary>
309  /// <param name="value">The vector to scale.</param>
310  /// <param name="scale">The amount by which to scale the vector.</param>
311  /// <returns>The scaled vector.</returns>
312  public static Vector2 Divide(Vector2 value, float scale)
313  {
314  return new Vector2(value.X / scale, value.Y / scale);
315  }
316 
317  /// <summary>
318  /// Demodulates a vector with another by performing component-wise division.
319  /// </summary>
320  /// <param name="left">The first vector to demodulate.</param>
321  /// <param name="right">The second vector to demodulate.</param>
322  /// <param name="result">When the method completes, contains the demodulated vector.</param>
323  public static void Demodulate(ref Vector2 left, ref Vector2 right, out Vector2 result)
324  {
325  result = new Vector2(left.X / right.X, left.Y / right.Y);
326  }
327 
328  /// <summary>
329  /// Demodulates a vector with another by performing component-wise division.
330  /// </summary>
331  /// <param name="left">The first vector to demodulate.</param>
332  /// <param name="right">The second vector to demodulate.</param>
333  /// <returns>The demodulated vector.</returns>
334  public static Vector2 Demodulate(Vector2 left, Vector2 right)
335  {
336  return new Vector2(left.X / right.X, left.Y / right.Y);
337  }
338 
339  /// <summary>
340  /// Reverses the direction of a given vector.
341  /// </summary>
342  /// <param name="value">The vector to negate.</param>
343  /// <param name="result">When the method completes, contains a vector facing in the opposite direction.</param>
344  public static void Negate(ref Vector2 value, out Vector2 result)
345  {
346  result = new Vector2(-value.X, -value.Y);
347  }
348 
349  /// <summary>
350  /// Reverses the direction of a given vector.
351  /// </summary>
352  /// <param name="value">The vector to negate.</param>
353  /// <returns>A vector facing in the opposite direction.</returns>
354  public static Vector2 Negate(Vector2 value)
355  {
356  return new Vector2(-value.X, -value.Y);
357  }
358 
359  /// <summary>
360  /// Returns a <see cref="SiliconStudio.Core.Mathematics.Vector2"/> containing the 2D Cartesian coordinates of a point specified in Barycentric coordinates relative to a 2D triangle.
361  /// </summary>
362  /// <param name="value1">A <see cref="SiliconStudio.Core.Mathematics.Vector2"/> containing the 2D Cartesian coordinates of vertex 1 of the triangle.</param>
363  /// <param name="value2">A <see cref="SiliconStudio.Core.Mathematics.Vector2"/> containing the 2D Cartesian coordinates of vertex 2 of the triangle.</param>
364  /// <param name="value3">A <see cref="SiliconStudio.Core.Mathematics.Vector2"/> containing the 2D Cartesian coordinates of vertex 3 of the triangle.</param>
365  /// <param name="amount1">Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in <paramref name="value2"/>).</param>
366  /// <param name="amount2">Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in <paramref name="value3"/>).</param>
367  /// <param name="result">When the method completes, contains the 2D Cartesian coordinates of the specified point.</param>
368  public static void Barycentric(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, float amount1, float amount2, out Vector2 result)
369  {
370  result = new Vector2((value1.X + (amount1 * (value2.X - value1.X))) + (amount2 * (value3.X - value1.X)),
371  (value1.Y + (amount1 * (value2.Y - value1.Y))) + (amount2 * (value3.Y - value1.Y)));
372  }
373 
374  /// <summary>
375  /// Returns a <see cref="SiliconStudio.Core.Mathematics.Vector2"/> containing the 2D Cartesian coordinates of a point specified in Barycentric coordinates relative to a 2D triangle.
376  /// </summary>
377  /// <param name="value1">A <see cref="SiliconStudio.Core.Mathematics.Vector2"/> containing the 2D Cartesian coordinates of vertex 1 of the triangle.</param>
378  /// <param name="value2">A <see cref="SiliconStudio.Core.Mathematics.Vector2"/> containing the 2D Cartesian coordinates of vertex 2 of the triangle.</param>
379  /// <param name="value3">A <see cref="SiliconStudio.Core.Mathematics.Vector2"/> containing the 2D Cartesian coordinates of vertex 3 of the triangle.</param>
380  /// <param name="amount1">Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in <paramref name="value2"/>).</param>
381  /// <param name="amount2">Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in <paramref name="value3"/>).</param>
382  /// <returns>A new <see cref="SiliconStudio.Core.Mathematics.Vector2"/> containing the 2D Cartesian coordinates of the specified point.</returns>
383  public static Vector2 Barycentric(Vector2 value1, Vector2 value2, Vector2 value3, float amount1, float amount2)
384  {
385  Vector2 result;
386  Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out result);
387  return result;
388  }
389 
390  /// <summary>
391  /// Restricts a value to be within a specified range.
392  /// </summary>
393  /// <param name="value">The value to clamp.</param>
394  /// <param name="min">The minimum value.</param>
395  /// <param name="max">The maximum value.</param>
396  /// <param name="result">When the method completes, contains the clamped value.</param>
397  public static void Clamp(ref Vector2 value, ref Vector2 min, ref Vector2 max, out Vector2 result)
398  {
399  float x = value.X;
400  x = (x > max.X) ? max.X : x;
401  x = (x < min.X) ? min.X : x;
402 
403  float y = value.Y;
404  y = (y > max.Y) ? max.Y : y;
405  y = (y < min.Y) ? min.Y : y;
406 
407  result = new Vector2(x, y);
408  }
409 
410  /// <summary>
411  /// Restricts a value to be within a specified range.
412  /// </summary>
413  /// <param name="value">The value to clamp.</param>
414  /// <param name="min">The minimum value.</param>
415  /// <param name="max">The maximum value.</param>
416  /// <returns>The clamped value.</returns>
417  public static Vector2 Clamp(Vector2 value, Vector2 min, Vector2 max)
418  {
419  Vector2 result;
420  Clamp(ref value, ref min, ref max, out result);
421  return result;
422  }
423 
424  /// <summary>
425  /// Calculates the distance between two vectors.
426  /// </summary>
427  /// <param name="value1">The first vector.</param>
428  /// <param name="value2">The second vector.</param>
429  /// <param name="result">When the method completes, contains the distance between the two vectors.</param>
430  /// <remarks>
431  /// <see cref="SiliconStudio.Core.Mathematics.Vector2.DistanceSquared(ref Vector2, ref Vector2, out float)"/> may be preferred when only the relative distance is needed
432  /// and speed is of the essence.
433  /// </remarks>
434  public static void Distance(ref Vector2 value1, ref Vector2 value2, out float result)
435  {
436  float x = value1.X - value2.X;
437  float y = value1.Y - value2.Y;
438 
439  result = (float)Math.Sqrt((x * x) + (y * y));
440  }
441 
442  /// <summary>
443  /// Calculates the distance between two vectors.
444  /// </summary>
445  /// <param name="value1">The first vector.</param>
446  /// <param name="value2">The second vector.</param>
447  /// <returns>The distance between the two vectors.</returns>
448  /// <remarks>
449  /// <see cref="SiliconStudio.Core.Mathematics.Vector2.DistanceSquared(Vector2, Vector2)"/> may be preferred when only the relative distance is needed
450  /// and speed is of the essence.
451  /// </remarks>
452  public static float Distance(Vector2 value1, Vector2 value2)
453  {
454  float x = value1.X - value2.X;
455  float y = value1.Y - value2.Y;
456 
457  return (float)Math.Sqrt((x * x) + (y * y));
458  }
459 
460  /// <summary>
461  /// Calculates the squared distance between two vectors.
462  /// </summary>
463  /// <param name="value1">The first vector.</param>
464  /// <param name="value2">The second vector</param>
465  /// <param name="result">When the method completes, contains the squared distance between the two vectors.</param>
466  /// <remarks>Distance squared is the value before taking the square root.
467  /// Distance squared can often be used in place of distance if relative comparisons are being made.
468  /// For example, consider three points A, B, and C. To determine whether B or C is further from A,
469  /// compare the distance between A and B to the distance between A and C. Calculating the two distances
470  /// involves two square roots, which are computationally expensive. However, using distance squared
471  /// provides the same information and avoids calculating two square roots.
472  /// </remarks>
473  public static void DistanceSquared(ref Vector2 value1, ref Vector2 value2, out float result)
474  {
475  float x = value1.X - value2.X;
476  float y = value1.Y - value2.Y;
477 
478  result = (x * x) + (y * y);
479  }
480 
481  /// <summary>
482  /// Calculates the squared distance between two vectors.
483  /// </summary>
484  /// <param name="value1">The first vector.</param>
485  /// <param name="value2">The second vector.</param>
486  /// <returns>The squared distance between the two vectors.</returns>
487  /// <remarks>Distance squared is the value before taking the square root.
488  /// Distance squared can often be used in place of distance if relative comparisons are being made.
489  /// For example, consider three points A, B, and C. To determine whether B or C is further from A,
490  /// compare the distance between A and B to the distance between A and C. Calculating the two distances
491  /// involves two square roots, which are computationally expensive. However, using distance squared
492  /// provides the same information and avoids calculating two square roots.
493  /// </remarks>
494  public static float DistanceSquared(Vector2 value1, Vector2 value2)
495  {
496  float x = value1.X - value2.X;
497  float y = value1.Y - value2.Y;
498 
499  return (x * x) + (y * y);
500  }
501 
502  /// <summary>
503  /// Calculates the dot product of two vectors.
504  /// </summary>
505  /// <param name="left">First source vector.</param>
506  /// <param name="right">Second source vector.</param>
507  /// <param name="result">When the method completes, contains the dot product of the two vectors.</param>
508  public static void Dot(ref Vector2 left, ref Vector2 right, out float result)
509  {
510  result = (left.X * right.X) + (left.Y * right.Y);
511  }
512 
513  /// <summary>
514  /// Calculates the dot product of two vectors.
515  /// </summary>
516  /// <param name="left">First source vector.</param>
517  /// <param name="right">Second source vector.</param>
518  /// <returns>The dot product of the two vectors.</returns>
519  public static float Dot(Vector2 left, Vector2 right)
520  {
521  return (left.X * right.X) + (left.Y * right.Y);
522  }
523 
524  /// <summary>
525  /// Converts the vector into a unit vector.
526  /// </summary>
527  /// <param name="value">The vector to normalize.</param>
528  /// <param name="result">When the method completes, contains the normalized vector.</param>
529  public static void Normalize(ref Vector2 value, out Vector2 result)
530  {
531  result = value;
532  result.Normalize();
533  }
534 
535  /// <summary>
536  /// Converts the vector into a unit vector.
537  /// </summary>
538  /// <param name="value">The vector to normalize.</param>
539  /// <returns>The normalized vector.</returns>
540  public static Vector2 Normalize(Vector2 value)
541  {
542  value.Normalize();
543  return value;
544  }
545 
546  /// <summary>
547  /// Performs a linear interpolation between two vectors.
548  /// </summary>
549  /// <param name="start">Start vector.</param>
550  /// <param name="end">End vector.</param>
551  /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
552  /// <param name="result">When the method completes, contains the linear interpolation of the two vectors.</param>
553  /// <remarks>
554  /// This method performs the linear interpolation based on the following formula.
555  /// <code>start + (end - start) * amount</code>
556  /// Passing <paramref name="amount"/> a value of 0 will cause <paramref name="start"/> to be returned; a value of 1 will cause <paramref name="end"/> to be returned.
557  /// </remarks>
558  public static void Lerp(ref Vector2 start, ref Vector2 end, float amount, out Vector2 result)
559  {
560  result.X = start.X + ((end.X - start.X) * amount);
561  result.Y = start.Y + ((end.Y - start.Y) * amount);
562  }
563 
564  /// <summary>
565  /// Performs a linear interpolation between two vectors.
566  /// </summary>
567  /// <param name="start">Start vector.</param>
568  /// <param name="end">End vector.</param>
569  /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
570  /// <returns>The linear interpolation of the two vectors.</returns>
571  /// <remarks>
572  /// This method performs the linear interpolation based on the following formula.
573  /// <code>start + (end - start) * amount</code>
574  /// Passing <paramref name="amount"/> a value of 0 will cause <paramref name="start"/> to be returned; a value of 1 will cause <paramref name="end"/> to be returned.
575  /// </remarks>
576  public static Vector2 Lerp(Vector2 start, Vector2 end, float amount)
577  {
578  Vector2 result;
579  Lerp(ref start, ref end, amount, out result);
580  return result;
581  }
582 
583  /// <summary>
584  /// Performs a cubic interpolation between two vectors.
585  /// </summary>
586  /// <param name="start">Start vector.</param>
587  /// <param name="end">End vector.</param>
588  /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
589  /// <param name="result">When the method completes, contains the cubic interpolation of the two vectors.</param>
590  public static void SmoothStep(ref Vector2 start, ref Vector2 end, float amount, out Vector2 result)
591  {
592  amount = (amount > 1.0f) ? 1.0f : ((amount < 0.0f) ? 0.0f : amount);
593  amount = (amount * amount) * (3.0f - (2.0f * amount));
594 
595  result.X = start.X + ((end.X - start.X) * amount);
596  result.Y = start.Y + ((end.Y - start.Y) * amount);
597  }
598 
599  /// <summary>
600  /// Performs a cubic interpolation between two vectors.
601  /// </summary>
602  /// <param name="start">Start vector.</param>
603  /// <param name="end">End vector.</param>
604  /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
605  /// <returns>The cubic interpolation of the two vectors.</returns>
606  public static Vector2 SmoothStep(Vector2 start, Vector2 end, float amount)
607  {
608  Vector2 result;
609  SmoothStep(ref start, ref end, amount, out result);
610  return result;
611  }
612 
613  /// <summary>
614  /// Performs a Hermite spline interpolation.
615  /// </summary>
616  /// <param name="value1">First source position vector.</param>
617  /// <param name="tangent1">First source tangent vector.</param>
618  /// <param name="value2">Second source position vector.</param>
619  /// <param name="tangent2">Second source tangent vector.</param>
620  /// <param name="amount">Weighting factor.</param>
621  /// <param name="result">When the method completes, contains the result of the Hermite spline interpolation.</param>
622  public static void Hermite(ref Vector2 value1, ref Vector2 tangent1, ref Vector2 value2, ref Vector2 tangent2, float amount, out Vector2 result)
623  {
624  float squared = amount * amount;
625  float cubed = amount * squared;
626  float part1 = ((2.0f * cubed) - (3.0f * squared)) + 1.0f;
627  float part2 = (-2.0f * cubed) + (3.0f * squared);
628  float part3 = (cubed - (2.0f * squared)) + amount;
629  float part4 = cubed - squared;
630 
631  result.X = (((value1.X * part1) + (value2.X * part2)) + (tangent1.X * part3)) + (tangent2.X * part4);
632  result.Y = (((value1.Y * part1) + (value2.Y * part2)) + (tangent1.Y * part3)) + (tangent2.Y * part4);
633  }
634 
635  /// <summary>
636  /// Performs a Hermite spline interpolation.
637  /// </summary>
638  /// <param name="value1">First source position vector.</param>
639  /// <param name="tangent1">First source tangent vector.</param>
640  /// <param name="value2">Second source position vector.</param>
641  /// <param name="tangent2">Second source tangent vector.</param>
642  /// <param name="amount">Weighting factor.</param>
643  /// <returns>The result of the Hermite spline interpolation.</returns>
644  public static Vector2 Hermite(Vector2 value1, Vector2 tangent1, Vector2 value2, Vector2 tangent2, float amount)
645  {
646  Vector2 result;
647  Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result);
648  return result;
649  }
650 
651  /// <summary>
652  /// Performs a Catmull-Rom interpolation using the specified positions.
653  /// </summary>
654  /// <param name="value1">The first position in the interpolation.</param>
655  /// <param name="value2">The second position in the interpolation.</param>
656  /// <param name="value3">The third position in the interpolation.</param>
657  /// <param name="value4">The fourth position in the interpolation.</param>
658  /// <param name="amount">Weighting factor.</param>
659  /// <param name="result">When the method completes, contains the result of the Catmull-Rom interpolation.</param>
660  public static void CatmullRom(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, ref Vector2 value4, float amount, out Vector2 result)
661  {
662  float squared = amount * amount;
663  float cubed = amount * squared;
664 
665  result.X = 0.5f * ((((2.0f * value2.X) + ((-value1.X + value3.X) * amount)) +
666  (((((2.0f * value1.X) - (5.0f * value2.X)) + (4.0f * value3.X)) - value4.X) * squared)) +
667  ((((-value1.X + (3.0f * value2.X)) - (3.0f * value3.X)) + value4.X) * cubed));
668 
669  result.Y = 0.5f * ((((2.0f * value2.Y) + ((-value1.Y + value3.Y) * amount)) +
670  (((((2.0f * value1.Y) - (5.0f * value2.Y)) + (4.0f * value3.Y)) - value4.Y) * squared)) +
671  ((((-value1.Y + (3.0f * value2.Y)) - (3.0f * value3.Y)) + value4.Y) * cubed));
672  }
673 
674  /// <summary>
675  /// Performs a Catmull-Rom interpolation using the specified positions.
676  /// </summary>
677  /// <param name="value1">The first position in the interpolation.</param>
678  /// <param name="value2">The second position in the interpolation.</param>
679  /// <param name="value3">The third position in the interpolation.</param>
680  /// <param name="value4">The fourth position in the interpolation.</param>
681  /// <param name="amount">Weighting factor.</param>
682  /// <returns>A vector that is the result of the Catmull-Rom interpolation.</returns>
683  public static Vector2 CatmullRom(Vector2 value1, Vector2 value2, Vector2 value3, Vector2 value4, float amount)
684  {
685  Vector2 result;
686  CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out result);
687  return result;
688  }
689 
690  /// <summary>
691  /// Returns a vector containing the smallest components of the specified vectors.
692  /// </summary>
693  /// <param name="left">The first source vector.</param>
694  /// <param name="right">The second source vector.</param>
695  /// <param name="result">When the method completes, contains an new vector composed of the largest components of the source vectors.</param>
696  public static void Max(ref Vector2 left, ref Vector2 right, out Vector2 result)
697  {
698  result.X = (left.X > right.X) ? left.X : right.X;
699  result.Y = (left.Y > right.Y) ? left.Y : right.Y;
700  }
701 
702  /// <summary>
703  /// Returns a vector containing the largest components of the specified vectors.
704  /// </summary>
705  /// <param name="left">The first source vector.</param>
706  /// <param name="right">The second source vector.</param>
707  /// <returns>A vector containing the largest components of the source vectors.</returns>
708  public static Vector2 Max(Vector2 left, Vector2 right)
709  {
710  Vector2 result;
711  Max(ref left, ref right, out result);
712  return result;
713  }
714 
715  /// <summary>
716  /// Returns a vector containing the smallest components of the specified vectors.
717  /// </summary>
718  /// <param name="left">The first source vector.</param>
719  /// <param name="right">The second source vector.</param>
720  /// <param name="result">When the method completes, contains an new vector composed of the smallest components of the source vectors.</param>
721  public static void Min(ref Vector2 left, ref Vector2 right, out Vector2 result)
722  {
723  result.X = (left.X < right.X) ? left.X : right.X;
724  result.Y = (left.Y < right.Y) ? left.Y : right.Y;
725  }
726 
727  /// <summary>
728  /// Returns a vector containing the smallest components of the specified vectors.
729  /// </summary>
730  /// <param name="left">The first source vector.</param>
731  /// <param name="right">The second source vector.</param>
732  /// <returns>A vector containing the smallest components of the source vectors.</returns>
733  public static Vector2 Min(Vector2 left, Vector2 right)
734  {
735  Vector2 result;
736  Min(ref left, ref right, out result);
737  return result;
738  }
739 
740  /// <summary>
741  /// Returns the reflection of a vector off a surface that has the specified normal.
742  /// </summary>
743  /// <param name="vector">The source vector.</param>
744  /// <param name="normal">Normal of the surface.</param>
745  /// <param name="result">When the method completes, contains the reflected vector.</param>
746  /// <remarks>Reflect only gives the direction of a reflection off a surface, it does not determine
747  /// whether the original vector was close enough to the surface to hit it.</remarks>
748  public static void Reflect(ref Vector2 vector, ref Vector2 normal, out Vector2 result)
749  {
750  float dot = (vector.X * normal.X) + (vector.Y * normal.Y);
751 
752  result.X = vector.X - ((2.0f * dot) * normal.X);
753  result.Y = vector.Y - ((2.0f * dot) * normal.Y);
754  }
755 
756  /// <summary>
757  /// Returns the reflection of a vector off a surface that has the specified normal.
758  /// </summary>
759  /// <param name="vector">The source vector.</param>
760  /// <param name="normal">Normal of the surface.</param>
761  /// <returns>The reflected vector.</returns>
762  /// <remarks>Reflect only gives the direction of a reflection off a surface, it does not determine
763  /// whether the original vector was close enough to the surface to hit it.</remarks>
764  public static Vector2 Reflect(Vector2 vector, Vector2 normal)
765  {
766  Vector2 result;
767  Reflect(ref vector, ref normal, out result);
768  return result;
769  }
770 
771  /// <summary>
772  /// Orthogonalizes a list of vectors.
773  /// </summary>
774  /// <param name="destination">The list of orthogonalized vectors.</param>
775  /// <param name="source">The list of vectors to orthogonalize.</param>
776  /// <remarks>
777  /// <para>Orthogonalization is the process of making all vectors orthogonal to each other. This
778  /// means that any given vector in the list will be orthogonal to any other given vector in the
779  /// list.</para>
780  /// <para>Because this method uses the modified Gram-Schmidt process, the resulting vectors
781  /// tend to be numerically unstable. The numeric stability decreases according to the vectors
782  /// position in the list so that the first vector is the most stable and the last vector is the
783  /// least stable.</para>
784  /// </remarks>
785  /// <exception cref="ArgumentNullException">Thrown when <paramref name="source"/> or <paramref name="destination"/> is <c>null</c>.</exception>
786  /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="destination"/> is shorter in length than <paramref name="source"/>.</exception>
787  public static void Orthogonalize(Vector2[] destination, params Vector2[] source)
788  {
789  //Uses the modified Gram-Schmidt process.
790  //q1 = m1
791  //q2 = m2 - ((q1 â‹… m2) / (q1 â‹… q1)) * q1
792  //q3 = m3 - ((q1 â‹… m3) / (q1 â‹… q1)) * q1 - ((q2 â‹… m3) / (q2 â‹… q2)) * q2
793  //q4 = m4 - ((q1 â‹… m4) / (q1 â‹… q1)) * q1 - ((q2 â‹… m4) / (q2 â‹… q2)) * q2 - ((q3 â‹… m4) / (q3 â‹… q3)) * q3
794  //q5 = ...
795 
796  if (source == null)
797  throw new ArgumentNullException("source");
798  if (destination == null)
799  throw new ArgumentNullException("destination");
800  if (destination.Length < source.Length)
801  throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
802 
803  for (int i = 0; i < source.Length; ++i)
804  {
805  Vector2 newvector = source[i];
806 
807  for (int r = 0; r < i; ++r)
808  {
809  newvector -= (Vector2.Dot(destination[r], newvector) / Vector2.Dot(destination[r], destination[r])) * destination[r];
810  }
811 
812  destination[i] = newvector;
813  }
814  }
815 
816  /// <summary>
817  /// Orthonormalizes a list of vectors.
818  /// </summary>
819  /// <param name="destination">The list of orthonormalized vectors.</param>
820  /// <param name="source">The list of vectors to orthonormalize.</param>
821  /// <remarks>
822  /// <para>Orthonormalization is the process of making all vectors orthogonal to each
823  /// other and making all vectors of unit length. This means that any given vector will
824  /// be orthogonal to any other given vector in the list.</para>
825  /// <para>Because this method uses the modified Gram-Schmidt process, the resulting vectors
826  /// tend to be numerically unstable. The numeric stability decreases according to the vectors
827  /// position in the list so that the first vector is the most stable and the last vector is the
828  /// least stable.</para>
829  /// </remarks>
830  /// <exception cref="ArgumentNullException">Thrown when <paramref name="source"/> or <paramref name="destination"/> is <c>null</c>.</exception>
831  /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="destination"/> is shorter in length than <paramref name="source"/>.</exception>
832  public static void Orthonormalize(Vector2[] destination, params Vector2[] source)
833  {
834  //Uses the modified Gram-Schmidt process.
835  //Because we are making unit vectors, we can optimize the math for orthogonalization
836  //and simplify the projection operation to remove the division.
837  //q1 = m1 / |m1|
838  //q2 = (m2 - (q1 â‹… m2) * q1) / |m2 - (q1 â‹… m2) * q1|
839  //q3 = (m3 - (q1 â‹… m3) * q1 - (q2 â‹… m3) * q2) / |m3 - (q1 â‹… m3) * q1 - (q2 â‹… m3) * q2|
840  //q4 = (m4 - (q1 â‹… m4) * q1 - (q2 â‹… m4) * q2 - (q3 â‹… m4) * q3) / |m4 - (q1 â‹… m4) * q1 - (q2 â‹… m4) * q2 - (q3 â‹… m4) * q3|
841  //q5 = ...
842 
843  if (source == null)
844  throw new ArgumentNullException("source");
845  if (destination == null)
846  throw new ArgumentNullException("destination");
847  if (destination.Length < source.Length)
848  throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
849 
850  for (int i = 0; i < source.Length; ++i)
851  {
852  Vector2 newvector = source[i];
853 
854  for (int r = 0; r < i; ++r)
855  {
856  newvector -= Vector2.Dot(destination[r], newvector) * destination[r];
857  }
858 
859  newvector.Normalize();
860  destination[i] = newvector;
861  }
862  }
863 
864  /// <summary>
865  /// Transforms a 2D vector by the given <see cref="SiliconStudio.Core.Mathematics.Quaternion"/> rotation.
866  /// </summary>
867  /// <param name="vector">The vector to rotate.</param>
868  /// <param name="rotation">The <see cref="SiliconStudio.Core.Mathematics.Quaternion"/> rotation to apply.</param>
869  /// <param name="result">When the method completes, contains the transformed <see cref="SiliconStudio.Core.Mathematics.Vector4"/>.</param>
870  public static void Transform(ref Vector2 vector, ref Quaternion rotation, out Vector2 result)
871  {
872  float x = rotation.X + rotation.X;
873  float y = rotation.Y + rotation.Y;
874  float z = rotation.Z + rotation.Z;
875  float wz = rotation.W * z;
876  float xx = rotation.X * x;
877  float xy = rotation.X * y;
878  float yy = rotation.Y * y;
879  float zz = rotation.Z * z;
880 
881  result = new Vector2((vector.X * (1.0f - yy - zz)) + (vector.Y * (xy - wz)), (vector.X * (xy + wz)) + (vector.Y * (1.0f - xx - zz)));
882  }
883 
884  /// <summary>
885  /// Transforms a 2D vector by the given <see cref="SiliconStudio.Core.Mathematics.Quaternion"/> rotation.
886  /// </summary>
887  /// <param name="vector">The vector to rotate.</param>
888  /// <param name="rotation">The <see cref="SiliconStudio.Core.Mathematics.Quaternion"/> rotation to apply.</param>
889  /// <returns>The transformed <see cref="SiliconStudio.Core.Mathematics.Vector4"/>.</returns>
890  public static Vector2 Transform(Vector2 vector, Quaternion rotation)
891  {
892  Vector2 result;
893  Transform(ref vector, ref rotation, out result);
894  return result;
895  }
896 
897  /// <summary>
898  /// Transforms an array of vectors by the given <see cref="SiliconStudio.Core.Mathematics.Quaternion"/> rotation.
899  /// </summary>
900  /// <param name="source">The array of vectors to transform.</param>
901  /// <param name="rotation">The <see cref="SiliconStudio.Core.Mathematics.Quaternion"/> rotation to apply.</param>
902  /// <param name="destination">The array for which the transformed vectors are stored.
903  /// This array may be the same array as <paramref name="source"/>.</param>
904  /// <exception cref="ArgumentNullException">Thrown when <paramref name="source"/> or <paramref name="destination"/> is <c>null</c>.</exception>
905  /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="destination"/> is shorter in length than <paramref name="source"/>.</exception>
906  public static void Transform(Vector2[] source, ref Quaternion rotation, Vector2[] destination)
907  {
908  if (source == null)
909  throw new ArgumentNullException("source");
910  if (destination == null)
911  throw new ArgumentNullException("destination");
912  if (destination.Length < source.Length)
913  throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
914 
915  float x = rotation.X + rotation.X;
916  float y = rotation.Y + rotation.Y;
917  float z = rotation.Z + rotation.Z;
918  float wz = rotation.W * z;
919  float xx = rotation.X * x;
920  float xy = rotation.X * y;
921  float yy = rotation.Y * y;
922  float zz = rotation.Z * z;
923 
924  float num1 = (1.0f - yy - zz);
925  float num2 = (xy - wz);
926  float num3 = (xy + wz);
927  float num4 = (1.0f - xx - zz);
928 
929  for (int i = 0; i < source.Length; ++i)
930  {
931  destination[i] = new Vector2(
932  (source[i].X * num1) + (source[i].Y * num2),
933  (source[i].X * num3) + (source[i].Y * num4));
934  }
935  }
936 
937  /// <summary>
938  /// Transforms a 2D vector by the given <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.
939  /// </summary>
940  /// <param name="vector">The source vector.</param>
941  /// <param name="transform">The transformation <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.</param>
942  /// <param name="result">When the method completes, contains the transformed <see cref="SiliconStudio.Core.Mathematics.Vector4"/>.</param>
943  public static void Transform(ref Vector2 vector, ref Matrix transform, out Vector4 result)
944  {
945  result = new Vector4(
946  (vector.X * transform.M11) + (vector.Y * transform.M21) + transform.M41,
947  (vector.X * transform.M12) + (vector.Y * transform.M22) + transform.M42,
948  (vector.X * transform.M13) + (vector.Y * transform.M23) + transform.M43,
949  (vector.X * transform.M14) + (vector.Y * transform.M24) + transform.M44);
950  }
951 
952  /// <summary>
953  /// Transforms a 2D vector by the given <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.
954  /// </summary>
955  /// <param name="vector">The source vector.</param>
956  /// <param name="transform">The transformation <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.</param>
957  /// <returns>The transformed <see cref="SiliconStudio.Core.Mathematics.Vector4"/>.</returns>
958  public static Vector4 Transform(Vector2 vector, Matrix transform)
959  {
960  Vector4 result;
961  Transform(ref vector, ref transform, out result);
962  return result;
963  }
964 
965  /// <summary>
966  /// Transforms an array of 2D vectors by the given <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.
967  /// </summary>
968  /// <param name="source">The array of vectors to transform.</param>
969  /// <param name="transform">The transformation <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.</param>
970  /// <param name="destination">The array for which the transformed vectors are stored.</param>
971  /// <exception cref="ArgumentNullException">Thrown when <paramref name="source"/> or <paramref name="destination"/> is <c>null</c>.</exception>
972  /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="destination"/> is shorter in length than <paramref name="source"/>.</exception>
973  public static void Transform(Vector2[] source, ref Matrix transform, Vector4[] destination)
974  {
975  if (source == null)
976  throw new ArgumentNullException("source");
977  if (destination == null)
978  throw new ArgumentNullException("destination");
979  if (destination.Length < source.Length)
980  throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
981 
982  for (int i = 0; i < source.Length; ++i)
983  {
984  Transform(ref source[i], ref transform, out destination[i]);
985  }
986  }
987 
988  /// <summary>
989  /// Performs a coordinate transformation using the given <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.
990  /// </summary>
991  /// <param name="coordinate">The coordinate vector to transform.</param>
992  /// <param name="transform">The transformation <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.</param>
993  /// <param name="result">When the method completes, contains the transformed coordinates.</param>
994  /// <remarks>
995  /// A coordinate transform performs the transformation with the assumption that the w component
996  /// is one. The four dimensional vector obtained from the transformation operation has each
997  /// component in the vector divided by the w component. This forces the wcomponent to be one and
998  /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working
999  /// with coordinates as the w component can safely be ignored.
1000  /// </remarks>
1001  public static void TransformCoordinate(ref Vector2 coordinate, ref Matrix transform, out Vector2 result)
1002  {
1003  Vector4 vector = new Vector4();
1004  vector.X = (coordinate.X * transform.M11) + (coordinate.Y * transform.M21) + transform.M41;
1005  vector.Y = (coordinate.X * transform.M12) + (coordinate.Y * transform.M22) + transform.M42;
1006  vector.Z = (coordinate.X * transform.M13) + (coordinate.Y * transform.M23) + transform.M43;
1007  vector.W = 1f / ((coordinate.X * transform.M14) + (coordinate.Y * transform.M24) + transform.M44);
1008 
1009  result = new Vector2(vector.X * vector.W, vector.Y * vector.W);
1010  }
1011 
1012  /// <summary>
1013  /// Performs a coordinate transformation using the given <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.
1014  /// </summary>
1015  /// <param name="coordinate">The coordinate vector to transform.</param>
1016  /// <param name="transform">The transformation <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.</param>
1017  /// <returns>The transformed coordinates.</returns>
1018  /// <remarks>
1019  /// A coordinate transform performs the transformation with the assumption that the w component
1020  /// is one. The four dimensional vector obtained from the transformation operation has each
1021  /// component in the vector divided by the w component. This forces the wcomponent to be one and
1022  /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working
1023  /// with coordinates as the w component can safely be ignored.
1024  /// </remarks>
1025  public static Vector2 TransformCoordinate(Vector2 coordinate, Matrix transform)
1026  {
1027  Vector2 result;
1028  TransformCoordinate(ref coordinate, ref transform, out result);
1029  return result;
1030  }
1031 
1032  /// <summary>
1033  /// Performs a coordinate transformation on an array of vectors using the given <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.
1034  /// </summary>
1035  /// <param name="source">The array of coordinate vectors to trasnform.</param>
1036  /// <param name="transform">The transformation <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.</param>
1037  /// <param name="destination">The array for which the transformed vectors are stored.
1038  /// This array may be the same array as <paramref name="source"/>.</param>
1039  /// <exception cref="ArgumentNullException">Thrown when <paramref name="source"/> or <paramref name="destination"/> is <c>null</c>.</exception>
1040  /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="destination"/> is shorter in length than <paramref name="source"/>.</exception>
1041  /// <remarks>
1042  /// A coordinate transform performs the transformation with the assumption that the w component
1043  /// is one. The four dimensional vector obtained from the transformation operation has each
1044  /// component in the vector divided by the w component. This forces the wcomponent to be one and
1045  /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working
1046  /// with coordinates as the w component can safely be ignored.
1047  /// </remarks>
1048  public static void TransformCoordinate(Vector2[] source, ref Matrix transform, Vector2[] destination)
1049  {
1050  if (source == null)
1051  throw new ArgumentNullException("source");
1052  if (destination == null)
1053  throw new ArgumentNullException("destination");
1054  if (destination.Length < source.Length)
1055  throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
1056 
1057  for (int i = 0; i < source.Length; ++i)
1058  {
1059  TransformCoordinate(ref source[i], ref transform, out destination[i]);
1060  }
1061  }
1062 
1063  /// <summary>
1064  /// Performs a normal transformation using the given <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.
1065  /// </summary>
1066  /// <param name="normal">The normal vector to transform.</param>
1067  /// <param name="transform">The transformation <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.</param>
1068  /// <param name="result">When the method completes, contains the transformed normal.</param>
1069  /// <remarks>
1070  /// A normal transform performs the transformation with the assumption that the w component
1071  /// is zero. This causes the fourth row and fourth collumn of the matrix to be unused. The
1072  /// end result is a vector that is not translated, but all other transformation properties
1073  /// apply. This is often prefered for normal vectors as normals purely represent direction
1074  /// rather than location because normal vectors should not be translated.
1075  /// </remarks>
1076  public static void TransformNormal(ref Vector2 normal, ref Matrix transform, out Vector2 result)
1077  {
1078  result = new Vector2(
1079  (normal.X * transform.M11) + (normal.Y * transform.M21),
1080  (normal.X * transform.M12) + (normal.Y * transform.M22));
1081  }
1082 
1083  /// <summary>
1084  /// Performs a normal transformation using the given <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.
1085  /// </summary>
1086  /// <param name="normal">The normal vector to transform.</param>
1087  /// <param name="transform">The transformation <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.</param>
1088  /// <returns>The transformed normal.</returns>
1089  /// <remarks>
1090  /// A normal transform performs the transformation with the assumption that the w component
1091  /// is zero. This causes the fourth row and fourth collumn of the matrix to be unused. The
1092  /// end result is a vector that is not translated, but all other transformation properties
1093  /// apply. This is often prefered for normal vectors as normals purely represent direction
1094  /// rather than location because normal vectors should not be translated.
1095  /// </remarks>
1096  public static Vector2 TransformNormal(Vector2 normal, Matrix transform)
1097  {
1098  Vector2 result;
1099  TransformNormal(ref normal, ref transform, out result);
1100  return result;
1101  }
1102 
1103  /// <summary>
1104  /// Performs a normal transformation on an array of vectors using the given <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.
1105  /// </summary>
1106  /// <param name="source">The array of normal vectors to transform.</param>
1107  /// <param name="transform">The transformation <see cref="SiliconStudio.Core.Mathematics.Matrix"/>.</param>
1108  /// <param name="destination">The array for which the transformed vectors are stored.
1109  /// This array may be the same array as <paramref name="source"/>.</param>
1110  /// <exception cref="ArgumentNullException">Thrown when <paramref name="source"/> or <paramref name="destination"/> is <c>null</c>.</exception>
1111  /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="destination"/> is shorter in length than <paramref name="source"/>.</exception>
1112  /// <remarks>
1113  /// A normal transform performs the transformation with the assumption that the w component
1114  /// is zero. This causes the fourth row and fourth collumn of the matrix to be unused. The
1115  /// end result is a vector that is not translated, but all other transformation properties
1116  /// apply. This is often prefered for normal vectors as normals purely represent direction
1117  /// rather than location because normal vectors should not be translated.
1118  /// </remarks>
1119  public static void TransformNormal(Vector2[] source, ref Matrix transform, Vector2[] destination)
1120  {
1121  if (source == null)
1122  throw new ArgumentNullException("source");
1123  if (destination == null)
1124  throw new ArgumentNullException("destination");
1125  if (destination.Length < source.Length)
1126  throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
1127 
1128  for (int i = 0; i < source.Length; ++i)
1129  {
1130  TransformNormal(ref source[i], ref transform, out destination[i]);
1131  }
1132  }
1133 
1134  /// <summary>
1135  /// Adds two vectors.
1136  /// </summary>
1137  /// <param name="left">The first vector to add.</param>
1138  /// <param name="right">The second vector to add.</param>
1139  /// <returns>The sum of the two vectors.</returns>
1140  public static Vector2 operator +(Vector2 left, Vector2 right)
1141  {
1142  return new Vector2(left.X + right.X, left.Y + right.Y);
1143  }
1144 
1145  /// <summary>
1146  /// Assert a vector (return it unchanged).
1147  /// </summary>
1148  /// <param name="value">The vector to assert (unchange).</param>
1149  /// <returns>The asserted (unchanged) vector.</returns>
1150  public static Vector2 operator +(Vector2 value)
1151  {
1152  return value;
1153  }
1154 
1155  /// <summary>
1156  /// Subtracts two vectors.
1157  /// </summary>
1158  /// <param name="left">The first vector to subtract.</param>
1159  /// <param name="right">The second vector to subtract.</param>
1160  /// <returns>The difference of the two vectors.</returns>
1161  public static Vector2 operator -(Vector2 left, Vector2 right)
1162  {
1163  return new Vector2(left.X - right.X, left.Y - right.Y);
1164  }
1165 
1166  /// <summary>
1167  /// Reverses the direction of a given vector.
1168  /// </summary>
1169  /// <param name="value">The vector to negate.</param>
1170  /// <returns>A vector facing in the opposite direction.</returns>
1171  public static Vector2 operator -(Vector2 value)
1172  {
1173  return new Vector2(-value.X, -value.Y);
1174  }
1175 
1176  /// <summary>
1177  /// Scales a vector by the given value.
1178  /// </summary>
1179  /// <param name="left">The left.</param>
1180  /// <param name="right">The right.</param>
1181  /// <returns>The scaled vector.</returns>
1182  public static Vector2 operator *(Vector2 left, Vector2 right)
1183  {
1184  return new Vector2(left.X*right.X, left.Y*right.Y);
1185  }
1186 
1187  /// <summary>
1188  /// Scales a vector by the given value.
1189  /// </summary>
1190  /// <param name="value">The vector to scale.</param>
1191  /// <param name="scale">The amount by which to scale the vector.</param>
1192  /// <returns>The scaled vector.</returns>
1193  public static Vector2 operator *(float scale, Vector2 value)
1194  {
1195  return new Vector2(value.X * scale, value.Y * scale);
1196  }
1197 
1198  /// <summary>
1199  /// Scales a vector by the given value.
1200  /// </summary>
1201  /// <param name="value">The vector to scale.</param>
1202  /// <param name="scale">The amount by which to scale the vector.</param>
1203  /// <returns>The scaled vector.</returns>
1204  public static Vector2 operator *(Vector2 value, float scale)
1205  {
1206  return new Vector2(value.X * scale, value.Y * scale);
1207  }
1208 
1209  /// <summary>
1210  /// Scales a vector by the given value.
1211  /// </summary>
1212  /// <param name="value">The vector to scale.</param>
1213  /// <param name="scale">The amount by which to scale the vector.</param>
1214  /// <returns>The scaled vector.</returns>
1215  public static Vector2 operator /(Vector2 value, float scale)
1216  {
1217  return new Vector2(value.X / scale, value.Y / scale);
1218  }
1219 
1220  /// <summary>
1221  /// Tests for equality between two objects.
1222  /// </summary>
1223  /// <param name="left">The first value to compare.</param>
1224  /// <param name="right">The second value to compare.</param>
1225  /// <returns><c>true</c> if <paramref name="left"/> has the same value as <paramref name="right"/>; otherwise, <c>false</c>.</returns>
1226  public static bool operator ==(Vector2 left, Vector2 right)
1227  {
1228  return left.Equals(right);
1229  }
1230 
1231  /// <summary>
1232  /// Tests for inequality between two objects.
1233  /// </summary>
1234  /// <param name="left">The first value to compare.</param>
1235  /// <param name="right">The second value to compare.</param>
1236  /// <returns><c>true</c> if <paramref name="left"/> has a different value than <paramref name="right"/>; otherwise, <c>false</c>.</returns>
1237  public static bool operator !=(Vector2 left, Vector2 right)
1238  {
1239  return !left.Equals(right);
1240  }
1241 
1242  /// <summary>
1243  /// Performs an explicit conversion from <see cref="SiliconStudio.Core.Mathematics.Vector2"/> to <see cref="SiliconStudio.Core.Mathematics.Vector3"/>.
1244  /// </summary>
1245  /// <param name="value">The value.</param>
1246  /// <returns>The result of the conversion.</returns>
1247  public static explicit operator Vector3(Vector2 value)
1248  {
1249  return new Vector3(value, 0.0f);
1250  }
1251 
1252  /// <summary>
1253  /// Performs an explicit conversion from <see cref="SiliconStudio.Core.Mathematics.Vector2"/> to <see cref="SiliconStudio.Core.Mathematics.Vector4"/>.
1254  /// </summary>
1255  /// <param name="value">The value.</param>
1256  /// <returns>The result of the conversion.</returns>
1257  public static explicit operator Vector4(Vector2 value)
1258  {
1259  return new Vector4(value, 0.0f, 0.0f);
1260  }
1261 
1262  /// <summary>
1263  /// Returns a <see cref="System.String"/> that represents this instance.
1264  /// </summary>
1265  /// <returns>
1266  /// A <see cref="System.String"/> that represents this instance.
1267  /// </returns>
1268  public override string ToString()
1269  {
1270  return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1}", X, Y);
1271  }
1272 
1273  /// <summary>
1274  /// Returns a <see cref="System.String"/> that represents this instance.
1275  /// </summary>
1276  /// <param name="format">The format.</param>
1277  /// <returns>
1278  /// A <see cref="System.String"/> that represents this instance.
1279  /// </returns>
1280  public string ToString(string format)
1281  {
1282  if (format == null)
1283  return ToString();
1284 
1285  return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1}", X.ToString(format, CultureInfo.CurrentCulture), Y.ToString(format, CultureInfo.CurrentCulture));
1286  }
1287 
1288  /// <summary>
1289  /// Returns a <see cref="System.String"/> that represents this instance.
1290  /// </summary>
1291  /// <param name="formatProvider">The format provider.</param>
1292  /// <returns>
1293  /// A <see cref="System.String"/> that represents this instance.
1294  /// </returns>
1295  public string ToString(IFormatProvider formatProvider)
1296  {
1297  return string.Format(formatProvider, "X:{0} Y:{1}", X, Y);
1298  }
1299 
1300  /// <summary>
1301  /// Returns a <see cref="System.String"/> that represents this instance.
1302  /// </summary>
1303  /// <param name="format">The format.</param>
1304  /// <param name="formatProvider">The format provider.</param>
1305  /// <returns>
1306  /// A <see cref="System.String"/> that represents this instance.
1307  /// </returns>
1308  public string ToString(string format, IFormatProvider formatProvider)
1309  {
1310  if (format == null)
1311  ToString(formatProvider);
1312 
1313  return string.Format(formatProvider, "X:{0} Y:{1}", X.ToString(format, formatProvider), Y.ToString(format, formatProvider));
1314  }
1315 
1316  /// <summary>
1317  /// Returns a hash code for this instance.
1318  /// </summary>
1319  /// <returns>
1320  /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
1321  /// </returns>
1322  public override int GetHashCode()
1323  {
1324  return X.GetHashCode() + Y.GetHashCode();
1325  }
1326 
1327  /// <summary>
1328  /// Determines whether the specified <see cref="SiliconStudio.Core.Mathematics.Vector2"/> is equal to this instance.
1329  /// </summary>
1330  /// <param name="other">The <see cref="SiliconStudio.Core.Mathematics.Vector2"/> to compare with this instance.</param>
1331  /// <returns>
1332  /// <c>true</c> if the specified <see cref="SiliconStudio.Core.Mathematics.Vector2"/> is equal to this instance; otherwise, <c>false</c>.
1333  /// </returns>
1334  public bool Equals(Vector2 other)
1335  {
1336  return ((float)Math.Abs(other.X - X) < MathUtil.ZeroTolerance &&
1337  (float)Math.Abs(other.Y - Y) < MathUtil.ZeroTolerance);
1338  }
1339 
1340  /// <summary>
1341  /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
1342  /// </summary>
1343  /// <param name="value">The <see cref="System.Object"/> to compare with this instance.</param>
1344  /// <returns>
1345  /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
1346  /// </returns>
1347  public override bool Equals(object value)
1348  {
1349  if (value == null)
1350  return false;
1351 
1352  if (value.GetType() != GetType())
1353  return false;
1354 
1355  return Equals((Vector2)value);
1356  }
1357 
1358 #if WPFInterop
1359  /// <summary>
1360  /// Performs an implicit conversion from <see cref="SiliconStudio.Core.Mathematics.Vector2"/> to <see cref="System.Windows.Point"/>.
1361  /// </summary>
1362  /// <param name="value">The value.</param>
1363  /// <returns>The result of the conversion.</returns>
1364  public static implicit operator System.Windows.Point(Vector2 value)
1365  {
1366  return new System.Windows.Point(value.X, value.Y);
1367  }
1368 
1369  /// <summary>
1370  /// Performs an explicit conversion from <see cref="System.Windows.Point"/> to <see cref="SiliconStudio.Core.Mathematics.Vector2"/>.
1371  /// </summary>
1372  /// <param name="value">The value.</param>
1373  /// <returns>The result of the conversion.</returns>
1374  public static explicit operator Vector2(System.Windows.Point value)
1375  {
1376  return new Vector2((float)value.X, (float)value.Y);
1377  }
1378 #endif
1379 
1380 #if XnaInterop
1381  /// <summary>
1382  /// Performs an implicit conversion from <see cref="SiliconStudio.Core.Mathematics.Vector2"/> to <see cref="Microsoft.Xna.Framework.Vector2"/>.
1383  /// </summary>
1384  /// <param name="value">The value.</param>
1385  /// <returns>The result of the conversion.</returns>
1386  public static implicit operator Microsoft.Xna.Framework.Vector2(Vector2 value)
1387  {
1388  return new Microsoft.Xna.Framework.Vector2(value.X, value.Y);
1389  }
1390 
1391  /// <summary>
1392  /// Performs an implicit conversion from <see cref="Microsoft.Xna.Framework.Vector2"/> to <see cref="SiliconStudio.Core.Mathematics.Vector2"/>.
1393  /// </summary>
1394  /// <param name="value">The value.</param>
1395  /// <returns>The result of the conversion.</returns>
1396  public static implicit operator Vector2(Microsoft.Xna.Framework.Vector2 value)
1397  {
1398  return new Vector2(value.X, value.Y);
1399  }
1400 #endif
1401  }
1402 }
static void Clamp(ref Vector2 value, ref Vector2 min, ref Vector2 max, out Vector2 result)
Restricts a value to be within a specified range.
Definition: Vector2.cs:397
static Vector2 Hermite(Vector2 value1, Vector2 tangent1, Vector2 value2, Vector2 tangent2, float amount)
Performs a Hermite spline interpolation.
Definition: Vector2.cs:644
static float Distance(Vector2 value1, Vector2 value2)
Calculates the distance between two vectors.
Definition: Vector2.cs:452
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
FbxDouble3 operator*(double factor, FbxDouble3 vector)
float W
The W component of the vector.
Definition: Vector4.cs:101
static Vector2 Transform(Vector2 vector, Quaternion rotation)
Transforms a 2D vector by the given SiliconStudio.Core.Mathematics.Quaternion rotation.
Definition: Vector2.cs:890
static void Barycentric(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, float amount1, float amount2, out Vector2 result)
Returns a SiliconStudio.Core.Mathematics.Vector2 containing the 2D Cartesian coordinates of a point s...
Definition: Vector2.cs:368
Represents a two dimensional mathematical vector.
Definition: Vector2.cs:42
static Vector2 Min(Vector2 left, Vector2 right)
Returns a vector containing the smallest components of the specified vectors.
Definition: Vector2.cs:733
static Vector2 SmoothStep(Vector2 start, Vector2 end, float amount)
Performs a cubic interpolation between two vectors.
Definition: Vector2.cs:606
static void TransformCoordinate(ref Vector2 coordinate, ref Matrix transform, out Vector2 result)
Performs a coordinate transformation using the given SiliconStudio.Core.Mathematics.Matrix.
Definition: Vector2.cs:1001
static void Orthogonalize(Vector2[] destination, params Vector2[] source)
Orthogonalizes a list of vectors.
Definition: Vector2.cs:787
void Normalize()
Converts the vector into a unit vector.
Definition: Vector2.cs:187
float Length()
Calculates the length of the vector.
Definition: Vector2.cs:166
static Vector2 Lerp(Vector2 start, Vector2 end, float amount)
Performs a linear interpolation between two vectors.
Definition: Vector2.cs:576
static void DistanceSquared(ref Vector2 value1, ref Vector2 value2, out float result)
Calculates the squared distance between two vectors.
Definition: Vector2.cs:473
Vector2(float x, float y)
Initializes a new instance of the SiliconStudio.Core.Mathematics.Vector2 struct.
Definition: Vector2.cs:96
static Vector2 Subtract(Vector2 left, Vector2 right)
Subtracts two vectors.
Definition: Vector2.cs:246
static Vector2 CatmullRom(Vector2 value1, Vector2 value2, Vector2 value3, Vector2 value4, float amount)
Performs a Catmull-Rom interpolation using the specified positions.
Definition: Vector2.cs:683
static Vector2 Multiply(Vector2 value, float scale)
Scales a vector by the given value.
Definition: Vector2.cs:268
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
static void Transform(Vector2[] source, ref Quaternion rotation, Vector2[] destination)
Transforms an array of vectors by the given SiliconStudio.Core.Mathematics.Quaternion rotation...
Definition: Vector2.cs:906
static Vector2 Divide(Vector2 value, float scale)
Scales a vector by the given value.
Definition: Vector2.cs:312
Vector2(float[] values)
Initializes a new instance of the SiliconStudio.Core.Mathematics.Vector2 struct.
Definition: Vector2.cs:108
static void Max(ref Vector2 left, ref Vector2 right, out Vector2 result)
Returns a vector containing the smallest components of the specified vectors.
Definition: Vector2.cs:696
const float ZeroTolerance
The value for which all absolute numbers smaller than are considered equal to zero.
Definition: MathUtil.cs:38
static void Transform(ref Vector2 vector, ref Quaternion rotation, out Vector2 result)
Transforms a 2D vector by the given SiliconStudio.Core.Mathematics.Quaternion rotation.
Definition: Vector2.cs:870
Vector2(float value)
Initializes a new instance of the SiliconStudio.Core.Mathematics.Vector2 struct.
Definition: Vector2.cs:85
string ToString(IFormatProvider formatProvider)
Returns a System.String that represents this instance.
Definition: Vector2.cs:1295
static float Dot(Vector2 left, Vector2 right)
Calculates the dot product of two vectors.
Definition: Vector2.cs:519
static Vector2 Max(Vector2 left, Vector2 right)
Returns a vector containing the largest components of the specified vectors.
Definition: Vector2.cs:708
static void Hermite(ref Vector2 value1, ref Vector2 tangent1, ref Vector2 value2, ref Vector2 tangent2, float amount, out Vector2 result)
Performs a Hermite spline interpolation.
Definition: Vector2.cs:622
static void Lerp(ref Vector2 start, ref Vector2 end, float amount, out Vector2 result)
Performs a linear interpolation between two vectors.
Definition: Vector2.cs:558
static void Multiply(ref Vector2 value, float scale, out Vector2 result)
Scales a vector by the given value.
Definition: Vector2.cs:257
static Vector2 Add(Vector2 left, Vector2 right)
Adds two vectors.
Definition: Vector2.cs:224
static Vector2 TransformNormal(Vector2 normal, Matrix transform)
Performs a normal transformation using the given SiliconStudio.Core.Mathematics.Matrix.
Definition: Vector2.cs:1096
string ToString(string format, IFormatProvider formatProvider)
Returns a System.String that represents this instance.
Definition: Vector2.cs:1308
static Vector2 Negate(Vector2 value)
Reverses the direction of a given vector.
Definition: Vector2.cs:354
static void TransformCoordinate(Vector2[] source, ref Matrix transform, Vector2[] destination)
Performs a coordinate transformation on an array of vectors using the given SiliconStudio.Core.Mathematics.Matrix.
Definition: Vector2.cs:1048
static void Min(ref Vector2 left, ref Vector2 right, out Vector2 result)
Returns a vector containing the smallest components of the specified vectors.
Definition: Vector2.cs:721
Represents a four dimensional mathematical vector.
Definition: Vector4.cs:42
float Y
The Y component of the vector.
Definition: Vector2.cs:79
Represents a four dimensional mathematical quaternion.
Definition: Quaternion.cs:45
static Vector2 Demodulate(Vector2 left, Vector2 right)
Demodulates a vector with another by performing component-wise division.
Definition: Vector2.cs:334
override int GetHashCode()
Returns a hash code for this instance.
Definition: Vector2.cs:1322
static void TransformNormal(Vector2[] source, ref Matrix transform, Vector2[] destination)
Performs a normal transformation on an array of vectors using the given SiliconStudio.Core.Mathematics.Matrix.
Definition: Vector2.cs:1119
static void Normalize(ref Vector2 value, out Vector2 result)
Converts the vector into a unit vector.
Definition: Vector2.cs:529
static void Dot(ref Vector2 left, ref Vector2 right, out float result)
Calculates the dot product of two vectors.
Definition: Vector2.cs:508
static void Negate(ref Vector2 value, out Vector2 result)
Reverses the direction of a given vector.
Definition: Vector2.cs:344
float Length()
Calculates the length of the vector.
Definition: Vector4.cs:227
static void TransformNormal(ref Vector2 normal, ref Matrix transform, out Vector2 result)
Performs a normal transformation using the given SiliconStudio.Core.Mathematics.Matrix.
Definition: Vector2.cs:1076
static void Reflect(ref Vector2 vector, ref Vector2 normal, out Vector2 result)
Returns the reflection of a vector off a surface that has the specified normal.
Definition: Vector2.cs:748
static Vector2 Reflect(Vector2 vector, Vector2 normal)
Returns the reflection of a vector off a surface that has the specified normal.
Definition: Vector2.cs:764
float Y
The Y component of the vector.
Definition: Vector4.cs:89
static void Demodulate(ref Vector2 left, ref Vector2 right, out Vector2 result)
Demodulates a vector with another by performing component-wise division.
Definition: Vector2.cs:323
static Vector2 Clamp(Vector2 value, Vector2 min, Vector2 max)
Restricts a value to be within a specified range.
Definition: Vector2.cs:417
static void Modulate(ref Vector2 left, ref Vector2 right, out Vector2 result)
Modulates a vector with another by performing component-wise multiplication.
Definition: Vector2.cs:279
static Vector4 Transform(Vector2 vector, Matrix transform)
Transforms a 2D vector by the given SiliconStudio.Core.Mathematics.Matrix.
Definition: Vector2.cs:958
static void Transform(ref Vector2 vector, ref Matrix transform, out Vector4 result)
Transforms a 2D vector by the given SiliconStudio.Core.Mathematics.Matrix.
Definition: Vector2.cs:943
float X
The X component of the vector.
Definition: Vector2.cs:73
static Vector2 Normalize(Vector2 value)
Converts the vector into a unit vector.
Definition: Vector2.cs:540
static void Subtract(ref Vector2 left, ref Vector2 right, out Vector2 result)
Subtracts two vectors.
Definition: Vector2.cs:235
override bool Equals(object value)
Determines whether the specified System.Object is equal to this instance.
Definition: Vector2.cs:1347
SiliconStudio.Core.Mathematics.Vector3 Vector3
static Vector2 TransformCoordinate(Vector2 coordinate, Matrix transform)
Performs a coordinate transformation using the given SiliconStudio.Core.Mathematics.Matrix.
Definition: Vector2.cs:1025
string ToString(string format)
Returns a System.String that represents this instance.
Definition: Vector2.cs:1280
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
Definition: DirectXTexP.h:175
static Vector2 Modulate(Vector2 left, Vector2 right)
Modulates a vector with another by performing component-wise multiplication.
Definition: Vector2.cs:290
static void Add(ref Vector2 left, ref Vector2 right, out Vector2 result)
Adds two vectors.
Definition: Vector2.cs:213
static void Transform(Vector2[] source, ref Matrix transform, Vector4[] destination)
Transforms an array of 2D vectors by the given SiliconStudio.Core.Mathematics.Matrix.
Definition: Vector2.cs:973
static void Orthonormalize(Vector2[] destination, params Vector2[] source)
Orthonormalizes a list of vectors.
Definition: Vector2.cs:832
static void Divide(ref Vector2 value, float scale, out Vector2 result)
Scales a vector by the given value.
Definition: Vector2.cs:301
static void CatmullRom(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, ref Vector2 value4, float amount, out Vector2 result)
Performs a Catmull-Rom interpolation using the specified positions.
Definition: Vector2.cs:660
static float DistanceSquared(Vector2 value1, Vector2 value2)
Calculates the squared distance between two vectors.
Definition: Vector2.cs:494
static void SmoothStep(ref Vector2 start, ref Vector2 end, float amount, out Vector2 result)
Performs a cubic interpolation between two vectors.
Definition: Vector2.cs:590
DataStyle
Specifies the style used for textual serialization when an array/list or a dictionary/map must be ser...
Definition: DataStyle.cs:9
float LengthSquared()
Calculates the squared length of the vector.
Definition: Vector2.cs:179
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t size_t z
Definition: DirectXTexP.h:191
override string ToString()
Returns a System.String that represents this instance.
Definition: Vector2.cs:1268
bool Equals(Vector2 other)
Determines whether the specified SiliconStudio.Core.Mathematics.Vector2 is equal to this instance...
Definition: Vector2.cs:1334
static Vector2 Barycentric(Vector2 value1, Vector2 value2, Vector2 value3, float amount1, float amount2)
Returns a SiliconStudio.Core.Mathematics.Vector2 containing the 2D Cartesian coordinates of a point s...
Definition: Vector2.cs:383
static void Distance(ref Vector2 value1, ref Vector2 value2, out float result)
Calculates the distance between two vectors.
Definition: Vector2.cs:434
float[] ToArray()
Creates an array containing the elements of the vector.
Definition: Vector2.cs:202
Represents a 4x4 mathematical matrix.
Definition: Matrix.cs:47