Optimize assignment to vector math out parameters
See #500 for more details. Instead of using the pattern: result = new Vector(x, y, z) Which would allocate and copy a vector instance, instead assign the fields directly: result.X = x; result.Y = y; result.Z = z; This should be a small improvment in performance.
This commit is contained in:
parent
a498da9448
commit
b1e30393a1
9 changed files with 170 additions and 117 deletions
|
@ -239,7 +239,8 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of operation.</param>
|
/// <param name="result">Result of operation.</param>
|
||||||
public static void Add(ref Vector2 a, ref Vector2 b, out Vector2 result)
|
public static void Add(ref Vector2 a, ref Vector2 b, out Vector2 result)
|
||||||
{
|
{
|
||||||
result = new Vector2(a.X + b.X, a.Y + b.Y);
|
result.X = a.X + b.X;
|
||||||
|
result.Y = a.Y + b.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -262,7 +263,8 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of subtraction</param>
|
/// <param name="result">Result of subtraction</param>
|
||||||
public static void Subtract(ref Vector2 a, ref Vector2 b, out Vector2 result)
|
public static void Subtract(ref Vector2 a, ref Vector2 b, out Vector2 result)
|
||||||
{
|
{
|
||||||
result = new Vector2(a.X - b.X, a.Y - b.Y);
|
result.X = a.X - b.X;
|
||||||
|
result.Y = a.Y - b.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -285,7 +287,8 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Multiply(ref Vector2 vector, float scale, out Vector2 result)
|
public static void Multiply(ref Vector2 vector, float scale, out Vector2 result)
|
||||||
{
|
{
|
||||||
result = new Vector2(vector.X * scale, vector.Y * scale);
|
result.X = vector.X * scale;
|
||||||
|
result.Y = vector.Y * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -308,7 +311,8 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Multiply(ref Vector2 vector, ref Vector2 scale, out Vector2 result)
|
public static void Multiply(ref Vector2 vector, ref Vector2 scale, out Vector2 result)
|
||||||
{
|
{
|
||||||
result = new Vector2(vector.X * scale.X, vector.Y * scale.Y);
|
result.X = vector.X * scale.X;
|
||||||
|
result.Y = vector.Y * scale.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -355,7 +359,8 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Divide(ref Vector2 vector, ref Vector2 scale, out Vector2 result)
|
public static void Divide(ref Vector2 vector, ref Vector2 scale, out Vector2 result)
|
||||||
{
|
{
|
||||||
result = new Vector2(vector.X / scale.X, vector.Y / scale.Y);
|
result.X = vector.X / scale.X;
|
||||||
|
result.Y = vector.Y / scale.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -692,7 +697,8 @@ namespace OpenTK
|
||||||
Quaternion.Multiply(ref quat, ref v, out t);
|
Quaternion.Multiply(ref quat, ref v, out t);
|
||||||
Quaternion.Multiply(ref t, ref i, out v);
|
Quaternion.Multiply(ref t, ref i, out v);
|
||||||
|
|
||||||
result = new Vector2(v.X, v.Y);
|
result.X = v.X;
|
||||||
|
result.Y = v.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -202,7 +202,8 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of operation.</param>
|
/// <param name="result">Result of operation.</param>
|
||||||
public static void Add(ref Vector2d a, ref Vector2d b, out Vector2d result)
|
public static void Add(ref Vector2d a, ref Vector2d b, out Vector2d result)
|
||||||
{
|
{
|
||||||
result = new Vector2d(a.X + b.X, a.Y + b.Y);
|
result.X = a.X + b.X;
|
||||||
|
result.Y = a.Y + b.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -225,7 +226,8 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of subtraction</param>
|
/// <param name="result">Result of subtraction</param>
|
||||||
public static void Subtract(ref Vector2d a, ref Vector2d b, out Vector2d result)
|
public static void Subtract(ref Vector2d a, ref Vector2d b, out Vector2d result)
|
||||||
{
|
{
|
||||||
result = new Vector2d(a.X - b.X, a.Y - b.Y);
|
result.X = a.X - b.X;
|
||||||
|
result.Y = a.Y - b.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -248,7 +250,8 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Multiply(ref Vector2d vector, double scale, out Vector2d result)
|
public static void Multiply(ref Vector2d vector, double scale, out Vector2d result)
|
||||||
{
|
{
|
||||||
result = new Vector2d(vector.X * scale, vector.Y * scale);
|
result.X = vector.X * scale;
|
||||||
|
result.Y = vector.Y * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -271,7 +274,8 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Multiply(ref Vector2d vector, ref Vector2d scale, out Vector2d result)
|
public static void Multiply(ref Vector2d vector, ref Vector2d scale, out Vector2d result)
|
||||||
{
|
{
|
||||||
result = new Vector2d(vector.X * scale.X, vector.Y * scale.Y);
|
result.X = vector.X * scale.X;
|
||||||
|
result.Y = vector.Y * scale.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -318,7 +322,8 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Divide(ref Vector2d vector, ref Vector2d scale, out Vector2d result)
|
public static void Divide(ref Vector2d vector, ref Vector2d scale, out Vector2d result)
|
||||||
{
|
{
|
||||||
result = new Vector2d(vector.X / scale.X, vector.Y / scale.Y);
|
result.X = vector.X / scale.X;
|
||||||
|
result.Y = vector.Y / scale.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -663,7 +668,8 @@ namespace OpenTK
|
||||||
Quaterniond.Multiply(ref quat, ref v, out t);
|
Quaterniond.Multiply(ref quat, ref v, out t);
|
||||||
Quaterniond.Multiply(ref t, ref i, out v);
|
Quaterniond.Multiply(ref t, ref i, out v);
|
||||||
|
|
||||||
result = new Vector2d(v.X, v.Y);
|
result.X = v.X;
|
||||||
|
result.Y = v.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -315,10 +315,9 @@ namespace OpenTK
|
||||||
/// <returns>A new Half2 instance.</returns>
|
/// <returns>A new Half2 instance.</returns>
|
||||||
public static Vector2h FromBytes(byte[] value, int startIndex)
|
public static Vector2h FromBytes(byte[] value, int startIndex)
|
||||||
{
|
{
|
||||||
Vector2h h2 = new Vector2h();
|
return new Vector2h(
|
||||||
h2.X = Half.FromBytes(value, startIndex);
|
Half.FromBytes(value, startIndex),
|
||||||
h2.Y = Half.FromBytes(value, startIndex + 2);
|
Half.FromBytes(value, startIndex + 2));
|
||||||
return h2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -276,7 +276,9 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of operation.</param>
|
/// <param name="result">Result of operation.</param>
|
||||||
public static void Add(ref Vector3 a, ref Vector3 b, out Vector3 result)
|
public static void Add(ref Vector3 a, ref Vector3 b, out Vector3 result)
|
||||||
{
|
{
|
||||||
result = new Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
|
result.X = a.X + b.X;
|
||||||
|
result.Y = a.Y + b.Y;
|
||||||
|
result.Z = a.Z + b.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -299,7 +301,9 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of subtraction</param>
|
/// <param name="result">Result of subtraction</param>
|
||||||
public static void Subtract(ref Vector3 a, ref Vector3 b, out Vector3 result)
|
public static void Subtract(ref Vector3 a, ref Vector3 b, out Vector3 result)
|
||||||
{
|
{
|
||||||
result = new Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
|
result.X = a.X - b.X;
|
||||||
|
result.Y = a.Y - b.Y;
|
||||||
|
result.Z = a.Z - b.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -322,7 +326,9 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Multiply(ref Vector3 vector, float scale, out Vector3 result)
|
public static void Multiply(ref Vector3 vector, float scale, out Vector3 result)
|
||||||
{
|
{
|
||||||
result = new Vector3(vector.X * scale, vector.Y * scale, vector.Z * scale);
|
result.X = vector.X * scale;
|
||||||
|
result.Y = vector.Y * scale;
|
||||||
|
result.Z = vector.Z * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -345,7 +351,9 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Multiply(ref Vector3 vector, ref Vector3 scale, out Vector3 result)
|
public static void Multiply(ref Vector3 vector, ref Vector3 scale, out Vector3 result)
|
||||||
{
|
{
|
||||||
result = new Vector3(vector.X * scale.X, vector.Y * scale.Y, vector.Z * scale.Z);
|
result.X = vector.X * scale.X;
|
||||||
|
result.Y = vector.Y * scale.Y;
|
||||||
|
result.Z = vector.Z * scale.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -393,7 +401,9 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Divide(ref Vector3 vector, ref Vector3 scale, out Vector3 result)
|
public static void Divide(ref Vector3 vector, ref Vector3 scale, out Vector3 result)
|
||||||
{
|
{
|
||||||
result = new Vector3(vector.X / scale.X, vector.Y / scale.Y, vector.Z / scale.Z);
|
result.X = vector.X / scale.X;
|
||||||
|
result.Y = vector.Y / scale.Y;
|
||||||
|
result.Z = vector.Z / scale.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -651,9 +661,9 @@ namespace OpenTK
|
||||||
/// <param name="result">The cross product of the two inputs</param>
|
/// <param name="result">The cross product of the two inputs</param>
|
||||||
public static void Cross(ref Vector3 left, ref Vector3 right, out Vector3 result)
|
public static void Cross(ref Vector3 left, ref Vector3 right, out Vector3 result)
|
||||||
{
|
{
|
||||||
result = new Vector3(left.Y * right.Z - left.Z * right.Y,
|
result.X = left.Y * right.Z - left.Z * right.Y;
|
||||||
left.Z * right.X - left.X * right.Z,
|
result.Y = left.Z * right.X - left.X * right.Z;
|
||||||
left.X * right.Y - left.Y * right.X);
|
result.Z = left.X * right.Y - left.Y * right.X;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -729,11 +739,9 @@ namespace OpenTK
|
||||||
/// <returns>The transformed vector</returns>
|
/// <returns>The transformed vector</returns>
|
||||||
public static Vector3 TransformVector(Vector3 vec, Matrix4 mat)
|
public static Vector3 TransformVector(Vector3 vec, Matrix4 mat)
|
||||||
{
|
{
|
||||||
Vector3 v;
|
Vector3 result;
|
||||||
v.X = Vector3.Dot(vec, new Vector3(mat.Column0));
|
TransformVector(ref vec, ref mat, out result);
|
||||||
v.Y = Vector3.Dot(vec, new Vector3(mat.Column1));
|
return result;
|
||||||
v.Z = Vector3.Dot(vec, new Vector3(mat.Column2));
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Transform a direction vector by the given Matrix
|
/// <summary>Transform a direction vector by the given Matrix
|
||||||
|
@ -767,8 +775,9 @@ namespace OpenTK
|
||||||
/// <returns>The transformed normal</returns>
|
/// <returns>The transformed normal</returns>
|
||||||
public static Vector3 TransformNormal(Vector3 norm, Matrix4 mat)
|
public static Vector3 TransformNormal(Vector3 norm, Matrix4 mat)
|
||||||
{
|
{
|
||||||
mat.Invert();
|
Vector3 result;
|
||||||
return TransformNormalInverse(norm, mat);
|
TransformNormal(ref norm, ref mat, out result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Transform a Normal by the given Matrix</summary>
|
/// <summary>Transform a Normal by the given Matrix</summary>
|
||||||
|
@ -795,11 +804,9 @@ namespace OpenTK
|
||||||
/// <returns>The transformed normal</returns>
|
/// <returns>The transformed normal</returns>
|
||||||
public static Vector3 TransformNormalInverse(Vector3 norm, Matrix4 invMat)
|
public static Vector3 TransformNormalInverse(Vector3 norm, Matrix4 invMat)
|
||||||
{
|
{
|
||||||
Vector3 n;
|
Vector3 result;
|
||||||
n.X = Vector3.Dot(norm, new Vector3(invMat.Row0));
|
TransformNormalInverse(ref norm, ref invMat, out result);
|
||||||
n.Y = Vector3.Dot(norm, new Vector3(invMat.Row1));
|
return result;
|
||||||
n.Z = Vector3.Dot(norm, new Vector3(invMat.Row2));
|
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Transform a Normal by the (transpose of the) given Matrix</summary>
|
/// <summary>Transform a Normal by the (transpose of the) given Matrix</summary>
|
||||||
|
@ -831,11 +838,9 @@ namespace OpenTK
|
||||||
/// <returns>The transformed position</returns>
|
/// <returns>The transformed position</returns>
|
||||||
public static Vector3 TransformPosition(Vector3 pos, Matrix4 mat)
|
public static Vector3 TransformPosition(Vector3 pos, Matrix4 mat)
|
||||||
{
|
{
|
||||||
Vector3 p;
|
Vector3 result;
|
||||||
p.X = Vector3.Dot(pos, new Vector3(mat.Column0)) + mat.Row3.X;
|
TransformPosition(ref pos, ref mat, out result);
|
||||||
p.Y = Vector3.Dot(pos, new Vector3(mat.Column1)) + mat.Row3.Y;
|
return result;
|
||||||
p.Z = Vector3.Dot(pos, new Vector3(mat.Column2)) + mat.Row3.Z;
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Transform a Position by the given Matrix</summary>
|
/// <summary>Transform a Position by the given Matrix</summary>
|
||||||
|
@ -877,10 +882,9 @@ namespace OpenTK
|
||||||
/// <param name="result">The transformed vector</param>
|
/// <param name="result">The transformed vector</param>
|
||||||
public static void Transform(ref Vector3 vec, ref Matrix3 mat, out Vector3 result)
|
public static void Transform(ref Vector3 vec, ref Matrix3 mat, out Vector3 result)
|
||||||
{
|
{
|
||||||
result = new Vector3(
|
result.X = vec.X * mat.Row0.X + vec.Y * mat.Row1.X + vec.Z * mat.Row2.X;
|
||||||
vec.X * mat.Row0.X + vec.Y * mat.Row1.X + vec.Z * mat.Row2.X,
|
result.Y = vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y + vec.Z * mat.Row2.Y;
|
||||||
vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y + vec.Z * mat.Row2.Y,
|
result.Z = vec.X * mat.Row0.Z + vec.Y * mat.Row1.Z + vec.Z * mat.Row2.Z;
|
||||||
vec.X * mat.Row0.Z + vec.Y * mat.Row1.Z + vec.Z * mat.Row2.Z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -931,10 +935,9 @@ namespace OpenTK
|
||||||
/// <param name="result">The transformed vector</param>
|
/// <param name="result">The transformed vector</param>
|
||||||
public static void Transform(ref Matrix3 mat, ref Vector3 vec, out Vector3 result)
|
public static void Transform(ref Matrix3 mat, ref Vector3 vec, out Vector3 result)
|
||||||
{
|
{
|
||||||
result = new Vector3(
|
result.X = mat.Row0.X * vec.X + mat.Row0.Y * vec.Y + mat.Row0.Z * vec.Z;
|
||||||
mat.Row0.X * vec.X + mat.Row0.Y * vec.Y + mat.Row0.Z * vec.Z,
|
result.Y = mat.Row1.X * vec.X + mat.Row1.Y * vec.Y + mat.Row1.Z * vec.Z;
|
||||||
mat.Row1.X * vec.X + mat.Row1.Y * vec.Y + mat.Row1.Z * vec.Z,
|
result.Z = mat.Row2.X * vec.X + mat.Row2.Y * vec.Y + mat.Row2.Z * vec.Z;
|
||||||
mat.Row2.X * vec.X + mat.Row2.Y * vec.Y + mat.Row2.Z * vec.Z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Transform a Vector3 by the given Matrix, and project the resulting Vector4 back to a Vector3</summary>
|
/// <summary>Transform a Vector3 by the given Matrix, and project the resulting Vector4 back to a Vector3</summary>
|
||||||
|
@ -954,7 +957,7 @@ namespace OpenTK
|
||||||
/// <param name="result">The transformed vector</param>
|
/// <param name="result">The transformed vector</param>
|
||||||
public static void TransformPerspective(ref Vector3 vec, ref Matrix4 mat, out Vector3 result)
|
public static void TransformPerspective(ref Vector3 vec, ref Matrix4 mat, out Vector3 result)
|
||||||
{
|
{
|
||||||
Vector4 v = new Vector4(vec, 1);
|
Vector4 v = new Vector4(vec.X, vec.Y, vec.Z, 1);
|
||||||
Vector4.Transform(ref v, ref mat, out v);
|
Vector4.Transform(ref v, ref mat, out v);
|
||||||
result.X = v.X / v.W;
|
result.X = v.X / v.W;
|
||||||
result.Y = v.Y / v.W;
|
result.Y = v.Y / v.W;
|
||||||
|
|
|
@ -274,7 +274,9 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of operation.</param>
|
/// <param name="result">Result of operation.</param>
|
||||||
public static void Add(ref Vector3d a, ref Vector3d b, out Vector3d result)
|
public static void Add(ref Vector3d a, ref Vector3d b, out Vector3d result)
|
||||||
{
|
{
|
||||||
result = new Vector3d(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
|
result.X = a.X + b.X;
|
||||||
|
result.Y = a.Y + b.Y;
|
||||||
|
result.Z = a.Z + b.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -297,7 +299,9 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of subtraction</param>
|
/// <param name="result">Result of subtraction</param>
|
||||||
public static void Subtract(ref Vector3d a, ref Vector3d b, out Vector3d result)
|
public static void Subtract(ref Vector3d a, ref Vector3d b, out Vector3d result)
|
||||||
{
|
{
|
||||||
result = new Vector3d(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
|
result.X = a.X - b.X;
|
||||||
|
result.Y = a.Y - b.Y;
|
||||||
|
result.Z = a.Z - b.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -320,7 +324,9 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Multiply(ref Vector3d vector, double scale, out Vector3d result)
|
public static void Multiply(ref Vector3d vector, double scale, out Vector3d result)
|
||||||
{
|
{
|
||||||
result = new Vector3d(vector.X * scale, vector.Y * scale, vector.Z * scale);
|
result.X = vector.X * scale;
|
||||||
|
result.Y = vector.Y * scale;
|
||||||
|
result.Z = vector.Z * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -343,7 +349,9 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Multiply(ref Vector3d vector, ref Vector3d scale, out Vector3d result)
|
public static void Multiply(ref Vector3d vector, ref Vector3d scale, out Vector3d result)
|
||||||
{
|
{
|
||||||
result = new Vector3d(vector.X * scale.X, vector.Y * scale.Y, vector.Z * scale.Z);
|
result.X = vector.X * scale.X;
|
||||||
|
result.Y = vector.Y * scale.Y;
|
||||||
|
result.Z = vector.Z * scale.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -391,7 +399,9 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Divide(ref Vector3d vector, ref Vector3d scale, out Vector3d result)
|
public static void Divide(ref Vector3d vector, ref Vector3d scale, out Vector3d result)
|
||||||
{
|
{
|
||||||
result = new Vector3d(vector.X / scale.X, vector.Y / scale.Y, vector.Z / scale.Z);
|
result.X = vector.X / scale.X;
|
||||||
|
result.Y = vector.Y / scale.Y;
|
||||||
|
result.Z = vector.Z / scale.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -645,9 +655,9 @@ namespace OpenTK
|
||||||
/// <param name="result">The cross product of the two inputs</param>
|
/// <param name="result">The cross product of the two inputs</param>
|
||||||
public static void Cross(ref Vector3d left, ref Vector3d right, out Vector3d result)
|
public static void Cross(ref Vector3d left, ref Vector3d right, out Vector3d result)
|
||||||
{
|
{
|
||||||
result = new Vector3d(left.Y * right.Z - left.Z * right.Y,
|
result.X = left.Y * right.Z - left.Z * right.Y;
|
||||||
left.Z * right.X - left.X * right.Z,
|
result.Y = left.Z * right.X - left.X * right.Z;
|
||||||
left.X * right.Y - left.Y * right.X);
|
result.Z = left.X * right.Y - left.Y * right.X;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -723,10 +733,9 @@ namespace OpenTK
|
||||||
/// <returns>The transformed vector</returns>
|
/// <returns>The transformed vector</returns>
|
||||||
public static Vector3d TransformVector(Vector3d vec, Matrix4d mat)
|
public static Vector3d TransformVector(Vector3d vec, Matrix4d mat)
|
||||||
{
|
{
|
||||||
return new Vector3d(
|
Vector3d result;
|
||||||
Vector3d.Dot(vec, new Vector3d(mat.Column0)),
|
TransformVector(ref vec, ref mat, out result);
|
||||||
Vector3d.Dot(vec, new Vector3d(mat.Column1)),
|
return result;
|
||||||
Vector3d.Dot(vec, new Vector3d(mat.Column2)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Transform a direction vector by the given Matrix
|
/// <summary>Transform a direction vector by the given Matrix
|
||||||
|
@ -788,10 +797,9 @@ namespace OpenTK
|
||||||
/// <returns>The transformed normal</returns>
|
/// <returns>The transformed normal</returns>
|
||||||
public static Vector3d TransformNormalInverse(Vector3d norm, Matrix4d invMat)
|
public static Vector3d TransformNormalInverse(Vector3d norm, Matrix4d invMat)
|
||||||
{
|
{
|
||||||
return new Vector3d(
|
Vector3d result;
|
||||||
Vector3d.Dot(norm, new Vector3d(invMat.Row0)),
|
TransformNormalInverse(ref norm, ref invMat, out result);
|
||||||
Vector3d.Dot(norm, new Vector3d(invMat.Row1)),
|
return result;
|
||||||
Vector3d.Dot(norm, new Vector3d(invMat.Row2)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Transform a Normal by the (transpose of the) given Matrix</summary>
|
/// <summary>Transform a Normal by the (transpose of the) given Matrix</summary>
|
||||||
|
@ -823,10 +831,9 @@ namespace OpenTK
|
||||||
/// <returns>The transformed position</returns>
|
/// <returns>The transformed position</returns>
|
||||||
public static Vector3d TransformPosition(Vector3d pos, Matrix4d mat)
|
public static Vector3d TransformPosition(Vector3d pos, Matrix4d mat)
|
||||||
{
|
{
|
||||||
return new Vector3d(
|
Vector3d result;
|
||||||
Vector3d.Dot(pos, new Vector3d(mat.Column0)) + mat.Row3.X,
|
TransformPosition(ref pos, ref mat, out result);
|
||||||
Vector3d.Dot(pos, new Vector3d(mat.Column1)) + mat.Row3.Y,
|
return result;
|
||||||
Vector3d.Dot(pos, new Vector3d(mat.Column2)) + mat.Row3.Z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Transform a Position by the given Matrix</summary>
|
/// <summary>Transform a Position by the given Matrix</summary>
|
||||||
|
@ -870,7 +877,9 @@ namespace OpenTK
|
||||||
{
|
{
|
||||||
Vector4d v4 = new Vector4d(vec.X, vec.Y, vec.Z, 1.0);
|
Vector4d v4 = new Vector4d(vec.X, vec.Y, vec.Z, 1.0);
|
||||||
Vector4d.Transform(ref v4, ref mat, out v4);
|
Vector4d.Transform(ref v4, ref mat, out v4);
|
||||||
result = v4.Xyz;
|
result.X = v4.X;
|
||||||
|
result.Y = v4.Y;
|
||||||
|
result.Z = v4.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -924,7 +933,7 @@ namespace OpenTK
|
||||||
/// <param name="result">The transformed vector</param>
|
/// <param name="result">The transformed vector</param>
|
||||||
public static void TransformPerspective(ref Vector3d vec, ref Matrix4d mat, out Vector3d result)
|
public static void TransformPerspective(ref Vector3d vec, ref Matrix4d mat, out Vector3d result)
|
||||||
{
|
{
|
||||||
Vector4d v = new Vector4d(vec, 1);
|
Vector4d v = new Vector4d(vec.X, vec.Y, vec.Z, 1);
|
||||||
Vector4d.Transform(ref v, ref mat, out v);
|
Vector4d.Transform(ref v, ref mat, out v);
|
||||||
result.X = v.X / v.W;
|
result.X = v.X / v.W;
|
||||||
result.Y = v.Y / v.W;
|
result.Y = v.Y / v.W;
|
||||||
|
|
|
@ -310,11 +310,10 @@ namespace OpenTK
|
||||||
/// <returns>The resulting Vector3.</returns>
|
/// <returns>The resulting Vector3.</returns>
|
||||||
public static explicit operator Vector3(Vector3h h3)
|
public static explicit operator Vector3(Vector3h h3)
|
||||||
{
|
{
|
||||||
Vector3 result = new Vector3();
|
return new Vector3(
|
||||||
result.X = h3.X.ToSingle();
|
h3.X.ToSingle(),
|
||||||
result.Y = h3.Y.ToSingle();
|
h3.Y.ToSingle(),
|
||||||
result.Z = h3.Z.ToSingle();
|
h3.Z.ToSingle());
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Converts OpenTK.Half3 to OpenTK.Vector3d.</summary>
|
/// <summary>Converts OpenTK.Half3 to OpenTK.Vector3d.</summary>
|
||||||
|
@ -322,11 +321,10 @@ namespace OpenTK
|
||||||
/// <returns>The resulting Vector3d.</returns>
|
/// <returns>The resulting Vector3d.</returns>
|
||||||
public static explicit operator Vector3d(Vector3h h3)
|
public static explicit operator Vector3d(Vector3h h3)
|
||||||
{
|
{
|
||||||
Vector3d result = new Vector3d();
|
return new Vector3d(
|
||||||
result.X = h3.X.ToSingle();
|
h3.X.ToSingle(),
|
||||||
result.Y = h3.Y.ToSingle();
|
h3.Y.ToSingle(),
|
||||||
result.Z = h3.Z.ToSingle();
|
h3.Z.ToSingle());
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>The size in bytes for an instance of the Half3 struct is 6.</summary>
|
/// <summary>The size in bytes for an instance of the Half3 struct is 6.</summary>
|
||||||
|
@ -411,11 +409,10 @@ namespace OpenTK
|
||||||
/// <returns>A new Half3 instance.</returns>
|
/// <returns>A new Half3 instance.</returns>
|
||||||
public static Vector3h FromBytes(byte[] value, int startIndex)
|
public static Vector3h FromBytes(byte[] value, int startIndex)
|
||||||
{
|
{
|
||||||
Vector3h h3 = new Vector3h();
|
return new Vector3h(
|
||||||
h3.X = Half.FromBytes(value, startIndex);
|
Half.FromBytes(value, startIndex),
|
||||||
h3.Y = Half.FromBytes(value, startIndex + 2);
|
Half.FromBytes(value, startIndex + 2),
|
||||||
h3.Z = Half.FromBytes(value, startIndex + 4);
|
Half.FromBytes(value, startIndex + 4));
|
||||||
return h3;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -314,7 +314,10 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of operation.</param>
|
/// <param name="result">Result of operation.</param>
|
||||||
public static void Add(ref Vector4 a, ref Vector4 b, out Vector4 result)
|
public static void Add(ref Vector4 a, ref Vector4 b, out Vector4 result)
|
||||||
{
|
{
|
||||||
result = new Vector4(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W);
|
result.X = a.X + b.X;
|
||||||
|
result.Y = a.Y + b.Y;
|
||||||
|
result.Z = a.Z + b.Z;
|
||||||
|
result.W = a.W + b.W;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -337,7 +340,10 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of subtraction</param>
|
/// <param name="result">Result of subtraction</param>
|
||||||
public static void Subtract(ref Vector4 a, ref Vector4 b, out Vector4 result)
|
public static void Subtract(ref Vector4 a, ref Vector4 b, out Vector4 result)
|
||||||
{
|
{
|
||||||
result = new Vector4(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W);
|
result.X = a.X - b.X;
|
||||||
|
result.Y = a.Y - b.Y;
|
||||||
|
result.Z = a.Z - b.Z;
|
||||||
|
result.W = a.W - b.W;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -360,7 +366,10 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Multiply(ref Vector4 vector, float scale, out Vector4 result)
|
public static void Multiply(ref Vector4 vector, float scale, out Vector4 result)
|
||||||
{
|
{
|
||||||
result = new Vector4(vector.X * scale, vector.Y * scale, vector.Z * scale, vector.W * scale);
|
result.X = vector.X * scale;
|
||||||
|
result.Y = vector.Y * scale;
|
||||||
|
result.Z = vector.Z * scale;
|
||||||
|
result.W = vector.W * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -383,7 +392,10 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Multiply(ref Vector4 vector, ref Vector4 scale, out Vector4 result)
|
public static void Multiply(ref Vector4 vector, ref Vector4 scale, out Vector4 result)
|
||||||
{
|
{
|
||||||
result = new Vector4(vector.X * scale.X, vector.Y * scale.Y, vector.Z * scale.Z, vector.W * scale.W);
|
result.X = vector.X * scale.X;
|
||||||
|
result.Y = vector.Y * scale.Y;
|
||||||
|
result.Z = vector.Z * scale.Z;
|
||||||
|
result.W = vector.W * scale.W;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -432,7 +444,10 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Divide(ref Vector4 vector, ref Vector4 scale, out Vector4 result)
|
public static void Divide(ref Vector4 vector, ref Vector4 scale, out Vector4 result)
|
||||||
{
|
{
|
||||||
result = new Vector4(vector.X / scale.X, vector.Y / scale.Y, vector.Z / scale.Z, vector.W / scale.W);
|
result.X = vector.X / scale.X;
|
||||||
|
result.Y = vector.Y / scale.Y;
|
||||||
|
result.Z = vector.Z / scale.Z;
|
||||||
|
result.W = vector.W / scale.W;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -833,7 +848,10 @@ namespace OpenTK
|
||||||
Quaternion.Multiply(ref quat, ref v, out t);
|
Quaternion.Multiply(ref quat, ref v, out t);
|
||||||
Quaternion.Multiply(ref t, ref i, out v);
|
Quaternion.Multiply(ref t, ref i, out v);
|
||||||
|
|
||||||
result = new Vector4(v.X, v.Y, v.Z, v.W);
|
result.X = v.X;
|
||||||
|
result.Y = v.Y;
|
||||||
|
result.Z = v.Z;
|
||||||
|
result.W = v.W;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Transform a Vector by the given Matrix using right-handed notation</summary>
|
/// <summary>Transform a Vector by the given Matrix using right-handed notation</summary>
|
||||||
|
|
|
@ -310,7 +310,10 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of operation.</param>
|
/// <param name="result">Result of operation.</param>
|
||||||
public static void Add(ref Vector4d a, ref Vector4d b, out Vector4d result)
|
public static void Add(ref Vector4d a, ref Vector4d b, out Vector4d result)
|
||||||
{
|
{
|
||||||
result = new Vector4d(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W);
|
result.X = a.X + b.X;
|
||||||
|
result.Y = a.Y + b.Y;
|
||||||
|
result.Z = a.Z + b.Z;
|
||||||
|
result.W = a.W + b.W;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -333,7 +336,10 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of subtraction</param>
|
/// <param name="result">Result of subtraction</param>
|
||||||
public static void Subtract(ref Vector4d a, ref Vector4d b, out Vector4d result)
|
public static void Subtract(ref Vector4d a, ref Vector4d b, out Vector4d result)
|
||||||
{
|
{
|
||||||
result = new Vector4d(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W);
|
result.X = a.X - b.X;
|
||||||
|
result.Y = a.Y - b.Y;
|
||||||
|
result.Z = a.Z - b.Z;
|
||||||
|
result.W = a.W - b.W;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -356,7 +362,10 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Multiply(ref Vector4d vector, double scale, out Vector4d result)
|
public static void Multiply(ref Vector4d vector, double scale, out Vector4d result)
|
||||||
{
|
{
|
||||||
result = new Vector4d(vector.X * scale, vector.Y * scale, vector.Z * scale, vector.W * scale);
|
result.X = vector.X * scale;
|
||||||
|
result.Y = vector.Y * scale;
|
||||||
|
result.Z = vector.Z * scale;
|
||||||
|
result.W = vector.W * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -379,7 +388,10 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Multiply(ref Vector4d vector, ref Vector4d scale, out Vector4d result)
|
public static void Multiply(ref Vector4d vector, ref Vector4d scale, out Vector4d result)
|
||||||
{
|
{
|
||||||
result = new Vector4d(vector.X * scale.X, vector.Y * scale.Y, vector.Z * scale.Z, vector.W * scale.W);
|
result.X = vector.X * scale.X;
|
||||||
|
result.Y = vector.Y * scale.Y;
|
||||||
|
result.Z = vector.Z * scale.Z;
|
||||||
|
result.W = vector.W * scale.W;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -428,7 +440,10 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Divide(ref Vector4d vector, ref Vector4d scale, out Vector4d result)
|
public static void Divide(ref Vector4d vector, ref Vector4d scale, out Vector4d result)
|
||||||
{
|
{
|
||||||
result = new Vector4d(vector.X / scale.X, vector.Y / scale.Y, vector.Z / scale.Z, vector.W / scale.W);
|
result.X = vector.X / scale.X;
|
||||||
|
result.Y = vector.Y / scale.Y;
|
||||||
|
result.Z = vector.Z / scale.Z;
|
||||||
|
result.W = vector.W / scale.W;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -825,7 +840,10 @@ namespace OpenTK
|
||||||
Quaterniond.Multiply(ref quat, ref v, out t);
|
Quaterniond.Multiply(ref quat, ref v, out t);
|
||||||
Quaterniond.Multiply(ref t, ref i, out v);
|
Quaterniond.Multiply(ref t, ref i, out v);
|
||||||
|
|
||||||
result = new Vector4d(v.X, v.Y, v.Z, v.W);
|
result.X = v.X;
|
||||||
|
result.Y = v.Y;
|
||||||
|
result.Z = v.Z;
|
||||||
|
result.W = v.W;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -640,12 +640,11 @@ namespace OpenTK
|
||||||
/// <returns>The resulting Vector4.</returns>
|
/// <returns>The resulting Vector4.</returns>
|
||||||
public static explicit operator Vector4(Vector4h h4)
|
public static explicit operator Vector4(Vector4h h4)
|
||||||
{
|
{
|
||||||
Vector4 result = new Vector4();
|
return new Vector4(
|
||||||
result.X = h4.X.ToSingle();
|
h4.X.ToSingle(),
|
||||||
result.Y = h4.Y.ToSingle();
|
h4.Y.ToSingle(),
|
||||||
result.Z = h4.Z.ToSingle();
|
h4.Z.ToSingle(),
|
||||||
result.W = h4.W.ToSingle();
|
h4.W.ToSingle());
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Converts OpenTK.Half4 to OpenTK.Vector4d.</summary>
|
/// <summary>Converts OpenTK.Half4 to OpenTK.Vector4d.</summary>
|
||||||
|
@ -653,12 +652,11 @@ namespace OpenTK
|
||||||
/// <returns>The resulting Vector4d.</returns>
|
/// <returns>The resulting Vector4d.</returns>
|
||||||
public static explicit operator Vector4d(Vector4h h4)
|
public static explicit operator Vector4d(Vector4h h4)
|
||||||
{
|
{
|
||||||
Vector4d result = new Vector4d();
|
return new Vector4d(
|
||||||
result.X = h4.X.ToSingle();
|
h4.X.ToSingle(),
|
||||||
result.Y = h4.Y.ToSingle();
|
h4.Y.ToSingle(),
|
||||||
result.Z = h4.Z.ToSingle();
|
h4.Z.ToSingle(),
|
||||||
result.W = h4.W.ToSingle();
|
h4.W.ToSingle());
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>The size in bytes for an instance of the Half4 struct is 8.</summary>
|
/// <summary>The size in bytes for an instance of the Half4 struct is 8.</summary>
|
||||||
|
@ -750,12 +748,11 @@ namespace OpenTK
|
||||||
/// <returns>A new Half4 instance.</returns>
|
/// <returns>A new Half4 instance.</returns>
|
||||||
public static Vector4h FromBytes(byte[] value, int startIndex)
|
public static Vector4h FromBytes(byte[] value, int startIndex)
|
||||||
{
|
{
|
||||||
Vector4h h4 = new Vector4h();
|
return new Vector4h(
|
||||||
h4.X = Half.FromBytes(value, startIndex);
|
Half.FromBytes(value, startIndex),
|
||||||
h4.Y = Half.FromBytes(value, startIndex + 2);
|
Half.FromBytes(value, startIndex + 2),
|
||||||
h4.Z = Half.FromBytes(value, startIndex + 4);
|
Half.FromBytes(value, startIndex + 4),
|
||||||
h4.W = Half.FromBytes(value, startIndex + 6);
|
Half.FromBytes(value, startIndex + 6));
|
||||||
return h4;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue