30 using System.Globalization;
31 using System.Runtime.InteropServices;
33 namespace SiliconStudio.Core.Mathematics
38 [DataContract(
"Int3")]
40 [StructLayout(LayoutKind.Sequential, Pack = 4)]
46 public static readonly
int SizeInBytes = Marshal.SizeOf(typeof(
Int3));
56 public static readonly
Int3 UnitX =
new Int3(1, 0, 0);
61 public static readonly
Int3 UnitY =
new Int3(0, 1, 0);
66 public static readonly
Int3 UnitZ =
new Int3(0, 0, 1);
71 public static readonly
Int3 One =
new Int3(1, 1, 1);
136 throw new ArgumentNullException(
"values");
137 if (values.Length != 3)
138 throw new ArgumentOutOfRangeException(
"values",
"There must be three and only three input values for Int3.");
148 public bool IsNormalized
150 get {
return Math.Abs((X * X) + (Y * Y) + (Z * Z) - 1f) < MathUtil.ZeroTolerance; }
160 public int this[
int index]
171 throw new ArgumentOutOfRangeException(
"index",
"Indices for Int3 run from 0 to 2, inclusive.");
178 case 0: X = value;
break;
179 case 1: Y = value;
break;
180 case 2: Z = value;
break;
181 default:
throw new ArgumentOutOfRangeException(
"index",
"Indices for Int3 run from 0 to 2, inclusive.");
196 return (
int)Math.Sqrt((X * X) + (Y * Y) + (Z * Z));
209 return (X * X) + (Y * Y) + (Z * Z);
217 int length = Length();
220 int inv = 1 / length;
231 public void Pow(
int exponent)
233 X = (int)Math.Pow(X, exponent);
234 Y = (int)Math.Pow(Y, exponent);
235 Z = (int)Math.Pow(Z, exponent);
244 return new int[] { X, Y, Z };
255 result =
new Int3(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
266 return new Int3(left.
X + right.
X, left.
Y + right.
Y, left.
Z + right.
Z);
277 result =
new Int3(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
288 return new Int3(left.
X - right.
X, left.
Y - right.
Y, left.
Z - right.
Z);
299 result =
new Int3(value.X * scale, value.Y * scale, value.Z * scale);
310 return new Int3(value.
X * scale, value.
Y * scale, value.
Z * scale);
321 result =
new Int3(left.X * right.X, left.Y * right.Y, left.Z * right.Z);
332 return new Int3(left.
X * right.
X, left.
Y * right.
Y, left.
Z * right.
Z);
343 result =
new Int3(value.X / scale, value.Y / scale, value.Z / scale);
354 return new Int3(value.
X / scale, value.
Y / scale, value.
Z / scale);
364 result =
new Int3(-value.X, -value.Y, -value.Z);
374 return new Int3(-value.
X, -value.
Y, -value.
Z);
387 x = (x > max.X) ? max.X : x;
388 x = (x < min.X) ? min.X : x;
391 y = (y > max.Y) ? max.Y : y;
392 y = (y < min.Y) ? min.Y :
y;
395 z = (z > max.Z) ? max.Z : z;
396 z = (z < min.Z) ? min.Z :
z;
398 result =
new Int3(x, y, z);
411 Clamp(ref value, ref min, ref max, out result);
421 public static void Dot(ref
Int3 left, ref
Int3 right, out
int result)
423 result = (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z);
434 return (left.
X * right.
X) + (left.Y * right.Y) + (left.
Z * right.
Z);
473 result.X = (int)(start.X + ((end.X - start.X) * amount));
474 result.Y = (int)(start.Y + ((end.Y - start.Y) * amount));
475 result.Z = (int)(start.Z + ((end.Z - start.Z) * amount));
493 Lerp(ref start, ref end, amount, out result);
506 amount = (amount > 1) ? 1 : ((amount < 0) ? 0 : amount);
507 amount = (amount * amount) * (3 - (2 * amount));
509 result.X = (int)(start.X + ((end.X - start.X) * amount));
510 result.Y = (int)(start.Y + ((end.Y - start.Y) * amount));
511 result.Z = (int)(start.Z + ((end.Z - start.Z) * amount));
524 SmoothStep(ref start, ref end, amount, out result);
536 result.X = (left.X > right.X) ? left.X : right.X;
537 result.Y = (left.Y > right.Y) ? left.Y : right.Y;
538 result.Z = (left.Z > right.Z) ? left.Z : right.Z;
550 Max(ref left, ref right, out result);
562 result.X = (left.X < right.X) ? left.X : right.X;
563 result.Y = (left.Y < right.Y) ? left.Y : right.Y;
564 result.Z = (left.Z < right.Z) ? left.Z : right.Z;
576 Min(ref left, ref right, out result);
588 return new Int3(left.
X + right.
X, left.
Y + right.
Y, left.
Z + right.
Z);
609 return new Int3(left.
X - right.
X, left.
Y - right.
Y, left.
Z - right.
Z);
619 return new Int3(-value.
X, -value.
Y, -value.
Z);
630 return new Int3((
int)(value.
X * scale), (
int)(value.
Y * scale), (
int)(value.
Z * scale));
641 return new Int3((
int)(value.
X * scale),(
int)(value.
Y * scale),(
int)(value.
Z * scale));
650 public static Int3 operator /(
Int3 value,
float scale)
652 return new Int3((
int)(value.
X / scale), (
int)(value.
Y / scale), (
int)(value.
Z / scale));
661 public static bool operator ==(
Int3 left,
Int3 right)
663 return left.Equals(right);
672 public static bool operator !=(
Int3 left,
Int3 right)
674 return !left.Equals(right);
694 return new Vector4(value.
X, value.
Y, value.
Z, 0);
705 return string.Format(CultureInfo.CurrentCulture,
"X:{0} Y:{1} Z:{2}", X, Y, Z);
720 return string.Format(CultureInfo.CurrentCulture,
"X:{0} Y:{1} Z:{2}", X.ToString(
format, CultureInfo.CurrentCulture),
721 Y.ToString(format, CultureInfo.CurrentCulture), Z.ToString(
format, CultureInfo.CurrentCulture));
731 public string ToString(IFormatProvider formatProvider)
733 return string.Format(formatProvider,
"X:{0} Y:{1} Z:{2}", X, Y, Z);
747 return ToString(formatProvider);
749 return string.Format(formatProvider,
"X:{0} Y:{1} Z:{2}", X.ToString(
format, formatProvider),
750 Y.ToString(format, formatProvider), Z.ToString(
format, formatProvider));
761 return X.GetHashCode() + Y.GetHashCode() + Z.GetHashCode();
773 return ((
float)Math.Abs(other.
X - X) < MathUtil.ZeroTolerance &&
774 (float)Math.Abs(other.
Y - Y) < MathUtil.ZeroTolerance &&
775 (float)Math.Abs(other.
Z - Z) < MathUtil.ZeroTolerance);
785 public override bool Equals(
object value)
790 if (value.GetType() != GetType())
793 return Equals((
Int3)value);
801 public static implicit
operator System.Windows.Media.Media3D.Int3D(
Int3 value)
803 return new System.Windows.Media.Media3D.Int3D(value.X, value.Y, value.Z);
811 public static explicit operator Int3(System.Windows.Media.Media3D.Int3D value)
813 return new Int3((
float)value.X, (
float)value.Y, (
float)value.Z);
823 public static implicit
operator Microsoft.Xna.Framework.Int3(Int3 value)
825 return new Microsoft.Xna.Framework.Int3(value.X, value.Y, value.Z);
833 public static implicit
operator Int3(Microsoft.Xna.Framework.Int3 value)
835 return new Int3(value.X, value.Y, value.Z);
static void Multiply(ref Int3 value, int scale, out Int3 result)
Scales a vector by the given value.
void Pow(int exponent)
Raises the exponent for each components.
static void Modulate(ref Int3 left, ref Int3 right, out Int3 result)
Modulates a vector with another by performing component-wise multiplication.
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
override string ToString()
Returns a System.String that represents this instance.
static Int3 Modulate(Int3 left, Int3 right)
Modulates a vector with another by performing component-wise multiplication.
FbxDouble3 operator*(double factor, FbxDouble3 vector)
int X
The X component of the vector.
Int3(Vector2 value, int z)
Initializes a new instance of the Int3 struct.
static void Negate(ref Int3 value, out Int3 result)
Reverses the direction of a given vector.
Represents a two dimensional mathematical vector.
static void Subtract(ref Int3 left, ref Int3 right, out Int3 result)
Subtracts two vectors.
string ToString(IFormatProvider formatProvider)
Returns a System.String that represents this instance.
Int3(int value)
Initializes a new instance of the Int3 struct.
static void Divide(ref Int3 value, int scale, out Int3 result)
Scales a vector by the given value.
static Int3 Add(Int3 left, Int3 right)
Adds two vectors.
static Int3 Min(Int3 left, Int3 right)
Returns a vector containing the smallest components of the specified vectors.
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
static void SmoothStep(ref Int3 start, ref Int3 end, float amount, out Int3 result)
Performs a cubic interpolation between two vectors.
const float ZeroTolerance
The value for which all absolute numbers smaller than are considered equal to zero.
static Int3 Max(Int3 left, Int3 right)
Returns a vector containing the largest components of the specified vectors.
static void Lerp(ref Int3 start, ref Int3 end, float amount, out Int3 result)
Performs a linear interpolation between two vectors.
bool Equals(Int3 other)
Determines whether the specified Int3 is equal to this instance.
int LengthSquared()
Calculates the squared length of the vector.
int[] ToArray()
Creates an array containing the elements of the vector.
static int Dot(Int3 left, Int3 right)
Calculates the dot product of two vectors.
Represents a three dimensional mathematical vector.
int Y
The Y component of the vector.
void Normalize()
Converts the vector into a unit vector.
static void Max(ref Int3 left, ref Int3 right, out Int3 result)
Returns a vector containing the smallest components of the specified vectors.
static Int3 Subtract(Int3 left, Int3 right)
Subtracts two vectors.
static Int3 Negate(Int3 value)
Reverses the direction of a given vector.
Int3(int[] values)
Initializes a new instance of the Int3 struct.
static void Add(ref Int3 left, ref Int3 right, out Int3 result)
Adds two vectors.
Represents a four dimensional mathematical vector.
string ToString(string format)
Returns a System.String that represents this instance.
static void Clamp(ref Int3 value, ref Int3 min, ref Int3 max, out Int3 result)
Restricts a value to be within a specified range.
override int GetHashCode()
Returns a hash code for this instance.
static Int3 Divide(Int3 value, int scale)
Scales a vector by the given value.
string ToString(string format, IFormatProvider formatProvider)
Returns a System.String that represents this instance.
Int3(int x, int y, int z)
Initializes a new instance of the Int3 struct.
int Z
The Z component of the vector.
float X
The X component of the vector.
static Int3 Normalize(Int3 value)
Converts the vector into a unit vector.
int Length()
Calculates the length of the vector.
static void Normalize(ref Int3 value, out Int3 result)
Converts the vector into a unit vector.
static void Dot(ref Int3 left, ref Int3 right, out int result)
Calculates the dot product of two vectors.
static Int3 Multiply(Int3 value, int scale)
Scales a vector by the given value.
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
static Int3 SmoothStep(Int3 start, Int3 end, float amount)
Performs a cubic interpolation between two vectors.
override bool Equals(object value)
Determines whether the specified System.Object is equal to this instance.
static Int3 Clamp(Int3 value, Int3 min, Int3 max)
Restricts a value to be within a specified range.
static void Min(ref Int3 left, ref Int3 right, out Int3 result)
Returns a vector containing the smallest components of the specified vectors.
DataStyle
Specifies the style used for textual serialization when an array/list or a dictionary/map must be ser...
static Int3 Lerp(Int3 start, Int3 end, float amount)
Performs a linear interpolation between two vectors.
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t size_t z