Added OpenEXR terms to the License.

Added Half and Vector[234]h structs.
Added Vector[234]d, Matrix4d and Quaterniond structs.
This commit is contained in:
the_fiddler 2008-12-09 20:45:18 +00:00
Родитель 033d4722af
Коммит 969d66e9f1
16 изменённых файлов: 5124 добавлений и 5496 удалений

Просмотреть файл

@ -1,6 +1,6 @@
The Open Toolkit Library License The Open Toolkit library license
Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted. Copyright (c) 2006 - 2008 The Open Toolkit library.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@ -10,4 +10,29 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
The Open Toolkit library contains code from the Mono class library. This code is distributed under the terms of the MIT/X11 license (displayed above) and is copyright (c) 2004 Novell, Inc.
Third parties
The Open Toolkit library includes portions of the Mono class library, which are covered by the following license:
Copyright (c) 2004 Novell, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Half-to-Single and Single-to-Half conversions are covered by the following license:
Copyright (c) 2002, Industrial Light & Magic, a division of Lucas Digital Ltd. LLC. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Industrial Light & Magic nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

588
Source/OpenTK/Math/Half.cs Normal file
Просмотреть файл

@ -0,0 +1,588 @@
#region --- License ---
/*
Copyright (c) 2006 - 2008 The Open Toolkit library.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
The conversion functions are derived from OpenEXR's implementation and are
governed by the following license:
Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
Digital Ltd. LLC
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Industrial Light & Magic nor the names of
its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion --- License ---
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace OpenTK.Math
{
/// <summary>
/// The name Half is derived from half-precision floating-point number.
/// It occupies only 16 Bits, which are split into 1 Sign bit, 5 Exponent bits and 10 Mantissa bits.
/// </summary>
/// <remarks>
/// Quote from ARB_half_float_pixel specification:
/// Any representable 16-bit floating-point value is legal as input to a GL command that accepts 16-bit floating-point data. The
/// result of providing a value that is not a floating-point number (such as infinity or NaN) to such a command is unspecified,
/// but must not lead to GL interruption or termination. Providing a denormalized number or negative zero to GL must yield
/// predictable results.
/// </remarks>
[Serializable, StructLayout(LayoutKind.Sequential)]
public struct Half : ISerializable, IComparable<Half>, IFormattable, IEquatable<Half>
{
#region Internal Field
UInt16 bits;
#endregion Internal Field
#region Properties
/// <summary>Returns true if the Half is zero.</summary>
public bool IsZero { get { return (bits == 0) || (bits == 0x8000); } }
/// <summary>Returns true if the Half represents Not A Number (NaN)</summary>
public bool IsNaN { get { return (((bits & 0x7C00) == 0x7C00) && (bits & 0x03FF) != 0x0000); } }
/// <summary>Returns true if the Half represents positive infinity.</summary>
public bool IsPositiveInfinity { get { return (bits == 31744); } }
/// <summary>Returns true if the Half represents negative infinity.</summary>
public bool IsNegativeInfinity { get { return (bits == 64512); } }
#endregion Properties
#region Constructors
/// <summary>
/// The new Half instance will convert the parameter into 16-Bit Half precision floating point.
/// </summary>
/// <param name="f">32-Bit Single precision floating point number.</param>
public Half(Single f)
: this()
{
unsafe
{
bits = SingleToHalf(*(int*)&f);
}
}
/// <summary>
/// The new Half instance will convert the parameter into 16-Bit Half precision floating point.
/// </summary>
/// <param name="f">32-Bit Single precision floating point number.</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
public Half(Single f, bool throwOnError)
: this(f)
{
if (throwOnError)
{
// handle cases that cause overflow rather than silently ignoring it
if (f > Half.MaxValue) throw new ArithmeticException("Half: Positive maximum value exceeded.");
if (f < -Half.MaxValue) throw new ArithmeticException("Half: Negative minimum value exceeded.");
// handle cases that make no sense
if (Single.IsNaN(f)) throw new ArithmeticException("Half: input is Not a Number (NaN).");
if (Single.IsPositiveInfinity(f)) throw new ArithmeticException("Half: input is +infinity.");
if (Single.IsNegativeInfinity(f)) throw new ArithmeticException("Half: input is -infinity.");
}
}
/// <summary>
/// The new Half instance will convert the parameter into 16-Bit Half precision floating point.
/// </summary>
/// <param name="d">64-Bit Double precision floating point number.</param>
public Half(Double d) : this((Single)d) { }
/// <summary>
/// The new Half instance will convert the parameter into 16-Bit Half precision floating point.
/// </summary>
/// <param name="d">64-Bit Double precision floating point number.</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
public Half(Double d, bool throwOnError) : this((Single)d, throwOnError) { }
#endregion Constructors
#region Single -> Half
/// <summary>Ported from OpenEXR's IlmBase 1.0.1</summary>
private UInt16 SingleToHalf(Int32 si32)
{
// Our floating point number, F, is represented by the bit pattern in integer i.
// Disassemble that bit pattern into the sign, S, the exponent, E, and the significand, M.
// Shift S into the position where it will go in in the resulting half number.
// Adjust E, accounting for the different exponent bias of float and half (127 versus 15).
Int32 sign = (si32 >> 16) & 0x00008000;
Int32 exponent = ((si32 >> 23) & 0x000000ff) - (127 - 15);
Int32 mantissa = si32 & 0x007fffff;
// Now reassemble S, E and M into a half:
if (exponent <= 0)
{
if (exponent < -10)
{
// E is less than -10. The absolute value of F is less than Half.MinValue
// (F may be a small normalized float, a denormalized float or a zero).
//
// We convert F to a half zero with the same sign as F.
return (UInt16)sign;
}
// E is between -10 and 0. F is a normalized float whose magnitude is less than Half.MinNormalizedValue.
//
// We convert F to a denormalized half.
// Add an explicit leading 1 to the significand.
mantissa = mantissa | 0x00800000;
// Round to M to the nearest (10+E)-bit value (with E between -10 and 0); in case of a tie, round to the nearest even value.
//
// Rounding may cause the significand to overflow and make our number normalized. Because of the way a half's bits
// are laid out, we don't have to treat this case separately; the code below will handle it correctly.
Int32 t = 14 - exponent;
Int32 a = (1 << (t - 1)) - 1;
Int32 b = (mantissa >> t) & 1;
mantissa = (mantissa + a + b) >> t;
// Assemble the half from S, E (==zero) and M.
return (UInt16)(sign | mantissa);
}
else if (exponent == 0xff - (127 - 15))
{
if (mantissa == 0)
{
// F is an infinity; convert F to a half infinity with the same sign as F.
return (UInt16)(sign | 0x7c00);
}
else
{
// F is a NAN; we produce a half NAN that preserves the sign bit and the 10 leftmost bits of the
// significand of F, with one exception: If the 10 leftmost bits are all zero, the NAN would turn
// into an infinity, so we have to set at least one bit in the significand.
mantissa >>= 13;
return (UInt16)(sign | 0x7c00 | mantissa | ((mantissa == 0) ? 1 : 0));
}
}
else
{
// E is greater than zero. F is a normalized float. We try to convert F to a normalized half.
// Round to M to the nearest 10-bit value. In case of a tie, round to the nearest even value.
mantissa = mantissa + 0x00000fff + ((mantissa >> 13) & 1);
if ((mantissa & 0x00800000) == 1)
{
mantissa = 0; // overflow in significand,
exponent += 1; // adjust exponent
}
// exponent overflow
if (exponent > 30) throw new ArithmeticException("Half: hardware floating point overflow.");
// Assemble the half from S, E and M.
return (UInt16)(sign | (exponent << 10) | (mantissa >> 13));
}
}
#endregion Single -> Half
#region Half -> Single
/// <summary>Converts the 16-Bit half to 32-Bit floating point.</summary>
/// <returns>A Single precision floating point Number.</returns>
public Single ToSingle()
{
int i = HalfToFloat(bits);
unsafe
{
return *(float*)&i;
}
}
/// <summary>Ported from OpenEXR's IlmBase 1.0.1</summary>
private Int32 HalfToFloat(UInt16 ui16)
{
Int32 sign = (ui16 >> 15) & 0x00000001;
Int32 exponent = (ui16 >> 10) & 0x0000001f;
Int32 mantissa = ui16 & 0x000003ff;
if (exponent == 0)
{
if (mantissa == 0)
{
// Plus or minus zero
return sign << 31;
}
else
{
// Denormalized number -- renormalize it
while ((mantissa & 0x00000400) == 0)
{
mantissa <<= 1;
exponent -= 1;
}
exponent += 1;
mantissa &= ~0x00000400;
}
}
else if (exponent == 31)
{
if (mantissa == 0)
{
// Positive or negative infinity
return (sign << 31) | 0x7f800000;
}
else
{
// Nan -- preserve sign and significand bits
return (sign << 31) | 0x7f800000 | (mantissa << 13);
}
}
// Normalized number
exponent = exponent + (127 - 15);
mantissa = mantissa << 13;
// Assemble S, E and M.
return (sign << 31) | (exponent << 23) | mantissa;
}
#endregion Half -> Single
#region Conversions
/// <summary>
/// Converts a System.Single to a OpenTK.Math.Half.
/// </summary>
/// <param name="f">The value to convert.
/// A <see cref="System.Single"/>
/// </param>
/// <returns>The result of the conversion.
/// A <see cref="Half"/>
/// </returns>
public static explicit operator Half(float f)
{
return new Half(f);
}
/// <summary>
/// Converts a System.Double to a OpenTK.Math.Half.
/// </summary>
/// <param name="d">The value to convert.
/// A <see cref="System.Double"/>
/// </param>
/// <returns>The result of the conversion.
/// A <see cref="Half"/>
/// </returns>
public static explicit operator Half(double d)
{
return new Half(d);
}
/// <summary>
/// Converts a OpenTK.Math.Half to a System.Single.
/// </summary>
/// <param name="h">The value to convert.
/// A <see cref="Half"/>
/// </param>
/// <returns>The result of the conversion.
/// A <see cref="System.Single"/>
/// </returns>
public static implicit operator float(Half h)
{
return h.ToSingle();
}
/// <summary>
/// Converts a OpenTK.Math.Half to a System.Double.
/// </summary>
/// <param name="h">The value to convert.
/// A <see cref="Half"/>
/// </param>
/// <returns>The result of the conversion.
/// A <see cref="System.Double"/>
/// </returns>
public static implicit operator double(Half h)
{
return (double)h.ToSingle();
}
#endregion Conversions
#region Constants
/// <summary>The size in bytes for an instance of the Half struct.</summary>
public static readonly Int32 SizeInBytes = 2;
/// <summary>Smallest positive half</summary>
public static readonly Single MinValue = 5.96046448e-08f;
/// <summary>Smallest positive normalized half</summary>
public static readonly Single MinNormalizedValue = 6.10351562e-05f;
/// <summary>Largest positive half</summary>
public static readonly Single MaxValue = 65504.0f;
/// <summary>Smallest positive e for which half (1.0 + e) != half (1.0)</summary>
public static readonly Single Epsilon = 0.00097656f;
#endregion Constants
#region ISerializable
/// <summary>Constructor used by ISerializable to deserialize the object.</summary>
/// <param name="info"></param>
/// <param name="context"></param>
public Half(SerializationInfo info, StreamingContext context)
{
this.bits = (ushort)info.GetValue("bits", typeof(ushort));
}
/// <summary>Used by ISerialize to serialize the object.</summary>
/// <param name="info"></param>
/// <param name="context"></param>
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("bits", this.bits);
}
#endregion ISerializable
#region Binary dump
/// <summary>Updates the Half by reading from a Stream.</summary>
/// <param name="bin">A BinaryReader instance associated with an open Stream.</param>
public void FromBinaryStream(BinaryReader bin)
{
this.bits = bin.ReadUInt16();
}
/// <summary>Writes the Half into a Stream.</summary>
/// <param name="bin">A BinaryWriter instance associated with an open Stream.</param>
public void ToBinaryStream(BinaryWriter bin)
{
bin.Write(this.bits);
}
#endregion Binary dump
#region IEquatable<Half> Members
const int maxUlps = 1;
/// <summary>
/// Returns a value indicating whether this instance is equal to a specified OpenTK.Math.Half value.
/// </summary>
/// <param name="other">OpenTK.Math.Half object to compare to this instance..</param>
/// <returns>True, if other is equal to this instance; false otherwise.</returns>
public bool Equals(Half other)
{
short aInt, bInt;
unchecked { aInt = (short)other.bits; }
unchecked { bInt = (short)this.bits; }
// Make aInt lexicographically ordered as a twos-complement int
if (aInt < 0)
aInt = (short)(0x8000 - aInt);
// Make bInt lexicographically ordered as a twos-complement int
if (bInt < 0)
bInt = (short)(0x8000 - bInt);
short intDiff = System.Math.Abs((short)(aInt - bInt));
if (intDiff <= maxUlps)
return true;
return false;
}
#endregion
#region IComparable<Half> Members
/// <summary>
/// Compares this instance to a specified half-precision floating-point number
/// and returns an integer that indicates whether the value of this instance
/// is less than, equal to, or greater than the value of the specified half-precision
/// floating-point number.
/// </summary>
/// <param name="other">A half-precision floating-point number to compare.</param>
/// <returns>
/// A signed number indicating the relative values of this instance and value. If the number is:
/// <para>Less than zero, then this instance is less than other, or this instance is not a number
/// (OpenTK.Math.Half.NaN) and other is a number.</para>
/// <para>Zero: this instance is equal to value, or both this instance and other
/// are not a number (OpenTK.Math.Half.NaN), OpenTK.Math.Half.PositiveInfinity, or
/// OpenTK.Math.Half.NegativeInfinity.</para>
/// <para>Greater than zero: this instance is greater than othrs, or this instance is a number
/// and other is not a number (OpenTK.Math.Half.NaN).</para>
/// </returns>
public int CompareTo(Half other)
{
return ((float)this).CompareTo((float)other);
}
#endregion IComparable<Half> Members
#region IFormattable Members
/// <summary>Converts this Half into a human-legible string representation.</summary>
/// <returns>The string representation of this instance.</returns>
public override string ToString()
{
return this.ToSingle().ToString();
}
/// <summary>Converts this Half into a human-legible string representation.</summary>
/// <param name="format">formatting for the output string.</param>
/// <param name="formatProvider">Culture-specific formatting information.</param>
/// <returns>The string representation of this instance.</returns>
public string ToString(string format, IFormatProvider formatProvider)
{
return this.ToSingle().ToString(format, formatProvider);
}
#endregion IFormattable Members
#region String -> Half
/// <summary>Converts the string representation of a number to a Half precision floating point equivalent.</summary>
/// <param name="s">string representation of the number to convert.</param>
/// <returns>A new Half instance.</returns>
public static Half Parse(string s)
{
return (Half)Single.Parse(s);
}
/// <summary>Converts the string representation of a number to a Half precision floating point equivalent.</summary>
/// <param name="s">string representation of the number to convert.</param>
/// <param name="style">specifies the format of s.</param>
/// <param name="provider">Culture-specific formatting information.</param>
/// <returns>A new Half instance.</returns>
public static Half Parse(string s, System.Globalization.NumberStyles style, IFormatProvider provider)
{
return (Half)Single.Parse(s, style, provider);
}
/// <summary>Converts the string representation of a number to a Half precision floating point equivalent. Returns success.</summary>
/// <param name="s">string representation of the number to convert.</param>
/// <param name="result">The Half instance to write to.</param>
/// <returns>Success.</returns>
public static bool TryParse(string s, out Half result)
{
float f;
bool b = Single.TryParse(s, out f);
result = (Half)f;
return b;
}
/// <summary>Converts the string representation of a number to a Half precision floating point equivalent. Returns success.</summary>
/// <param name="s">string representation of the number to convert.</param>
/// <param name="style">specifies the format of s.</param>
/// <param name="provider">Culture-specific formatting information.</param>
/// <param name="result">The Half instance to write to.</param>
/// <returns>Success.</returns>
public static bool TryParse(string s, System.Globalization.NumberStyles style, IFormatProvider provider, out Half result)
{
float f;
bool b = Single.TryParse(s, style, provider, out f);
result = (Half)f;
return b;
}
#endregion String -> Half
#region BitConverter
/// <summary>Returns the Half as an array of bytes.</summary>
/// <param name="h">The Half to convert.</param>
/// <returns>The input as byte array.</returns>
public static byte[] GetBytes(Half h)
{
return BitConverter.GetBytes(h.bits);
}
/// <summary>Converts an array of bytes into Half.</summary>
/// <param name="value">A Half in it's byte[] representation.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A new Half instance.</returns>
public static Half FromBytes(byte[] value, int startIndex)
{
Half h;
h.bits = BitConverter.ToUInt16(value, startIndex);
return h;
}
#endregion BitConverter
}
}

Просмотреть файл

@ -1,10 +1,24 @@
#region --- License --- #region --- License ---
/* Licensed under the MIT/X11 license. /*
* Copyright (c) 2006-2008 the OpenTK Team. Copyright (c) 2006 - 2008 The Open Toolkit library.
* This notice may not be removed from any source distribution.
* See license.txt for licensing detailed licensing details. Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* Contributions by James Talton. the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/ */
#endregion #endregion
@ -15,10 +29,10 @@ namespace OpenTK.Math
{ {
// Todo: Remove this warning when the code goes public. // Todo: Remove this warning when the code goes public.
#pragma warning disable 3019 #pragma warning disable 3019
#if false
[Serializable] [Serializable]
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal struct Matrix3d : IEquatable<Matrix3d> public struct Matrix3d : IEquatable<Matrix3d>
{ {
#region Fields & Access #region Fields & Access
@ -275,20 +289,19 @@ namespace OpenTK.Math
/// <summary>Constructs left matrix from the given quaternion.</summary> /// <summary>Constructs left matrix from the given quaternion.</summary>
/// <param name="quaternion">The quaternion to use to construct the martix.</param> /// <param name="quaternion">The quaternion to use to construct the martix.</param>
public Matrix3d(ref Quaterniond quaternion) public Matrix3d(Quaterniond quaternion)
{ {
Quaterniond quaternionNormalized; quaternion.Normalize();
quaternion.Normalize(out quaternionNormalized);
double xx = quaternionNormalized.X * quaternionNormalized.X; double xx = quaternion.X * quaternion.X;
double yy = quaternionNormalized.Y * quaternionNormalized.Y; double yy = quaternion.Y * quaternion.Y;
double zz = quaternionNormalized.Z * quaternionNormalized.Z; double zz = quaternion.Z * quaternion.Z;
double xy = quaternionNormalized.X * quaternionNormalized.Y; double xy = quaternion.X * quaternion.Y;
double xz = quaternionNormalized.X * quaternionNormalized.Z; double xz = quaternion.X * quaternion.Z;
double yz = quaternionNormalized.Y * quaternionNormalized.Z; double yz = quaternion.Y * quaternion.Z;
double wx = quaternionNormalized.W * quaternionNormalized.X; double wx = quaternion.W * quaternion.X;
double wy = quaternionNormalized.W * quaternionNormalized.Y; double wy = quaternion.W * quaternion.Y;
double wz = quaternionNormalized.W * quaternionNormalized.Z; double wz = quaternion.W * quaternion.Z;
R0C0 = 1 - 2 * (yy + zz); R0C0 = 1 - 2 * (yy + zz);
R0C1 = 2 * (xy - wz); R0C1 = 2 * (xy - wz);
@ -752,9 +765,9 @@ namespace OpenTK.Math
result.R2C2 = 1; result.R2C2 = 1;
} }
public void Quaternion(out Quaterniond quaternion) public Quaterniond ToQuaternion()
{ {
quaternion = new Quaterniond(ref this); //return new Quaterniond(ref this);
} }
#endregion #endregion
@ -810,6 +823,6 @@ namespace OpenTK.Math
#endregion #endregion
} }
#endif
#pragma warning restore 3019 #pragma warning restore 3019
} }

Просмотреть файл

@ -1,14 +1,28 @@
#region --- License --- #region --- License ---
/* Copyright (c) 2006, 2007 the OpenTK team /*
* See license.txt for license info Copyright (c) 2006 - 2008 The Open Toolkit library.
*
* Implemented by Andy Gill Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/ */
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace OpenTK.Math namespace OpenTK.Math
@ -65,27 +79,7 @@ namespace OpenTK.Math
#endregion #endregion
#region Functions #region Public Members
#region public void Invert()
public void Invert()
{
this = Matrix4.Invert(this);
}
#endregion
#region public void Transpose()
public void Transpose()
{
this = Matrix4.Transpose(this);
}
#endregion
#endregion
#region Properties #region Properties
@ -140,32 +134,29 @@ namespace OpenTK.Math
#endregion #endregion
#region Operator overloads #region Instance
/// <summary> #region public void Invert()
/// Matrix multiplication
/// </summary>
/// <param name="left">left-hand operand</param>
/// <param name="right">right-hand operand</param>
/// <returns>A new Matrix44 which holds the result of the multiplication</returns>
public static Matrix4 operator *(Matrix4 left, Matrix4 right)
{
return Matrix4.Mult(left, right);
}
public static bool operator ==(Matrix4 left, Matrix4 right) public void Invert()
{ {
return left.Equals(right); this = Matrix4.Invert(this);
}
public static bool operator !=(Matrix4 left, Matrix4 right)
{
return !left.Equals(right);
} }
#endregion #endregion
#region Static functions #region public void Transpose()
public void Transpose()
{
this = Matrix4.Transpose(this);
}
#endregion
#endregion
#region Static
#region Scale Functions #region Scale Functions
@ -574,6 +565,33 @@ namespace OpenTK.Math
#endregion #endregion
#region Operators
/// <summary>
/// Matrix multiplication
/// </summary>
/// <param name="left">left-hand operand</param>
/// <param name="right">right-hand operand</param>
/// <returns>A new Matrix44 which holds the result of the multiplication</returns>
public static Matrix4 operator *(Matrix4 left, Matrix4 right)
{
return Matrix4.Mult(left, right);
}
public static bool operator ==(Matrix4 left, Matrix4 right)
{
return left.Equals(right);
}
public static bool operator !=(Matrix4 left, Matrix4 right)
{
return !left.Equals(right);
}
#endregion
#region Overrides
#region public override string ToString() #region public override string ToString()
/// <summary> /// <summary>
@ -617,6 +635,10 @@ namespace OpenTK.Math
#endregion #endregion
#endregion
#endregion
#region IEquatable<Matrix4> Members #region IEquatable<Matrix4> Members
/// <summary>Indicates whether the current matrix is equal to another matrix.</summary> /// <summary>Indicates whether the current matrix is equal to another matrix.</summary>

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,14 +1,28 @@
#region --- License --- #region --- License ---
/* Copyright (c) 2006, 2007 the OpenTK team /*
* See license.txt for license info Copyright (c) 2006 - 2008 The Open Toolkit library.
*
* Implemented by Andy Gill Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/ */
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace OpenTK.Math namespace OpenTK.Math
@ -26,13 +40,12 @@ namespace OpenTK.Math
/// The vector part of the quaternion /// The vector part of the quaternion
/// </summary> /// </summary>
public Vector3 XYZ; public Vector3 XYZ;
/// <summary> /// <summary>
/// The w component of the quaternion /// The w component of the quaternion
/// </summary> /// </summary>
public float W; public float W;
public static Quaternion Identity = new Quaternion(0, 0, 0, 1);
#endregion #endregion
#region Constructors #region Constructors
@ -63,7 +76,40 @@ namespace OpenTK.Math
#endregion #endregion
#region Functions #region Public Members
#region Properties
/// <summary>
/// Gets or sets the X component of this instance.
/// </summary>
public float X
{
get { return XYZ.X; }
set { XYZ.X = value; }
}
/// <summary>
/// Gets or sets the Y component of this instance.
/// </summary>
public float Y
{
get { return XYZ.Y; }
set { XYZ.Y = value; }
}
/// <summary>
/// Gets or sets the Z component of this instance.
/// </summary>
public float Z
{
get { return XYZ.Z; }
set { XYZ.Z = value; }
}
#endregion
#region Instance
#region pubilc void ToAxisAngle(out Vector3 axis, out float angle) #region pubilc void ToAxisAngle(out Vector3 axis, out float angle)
@ -148,48 +194,17 @@ namespace OpenTK.Math
#endregion #endregion
#region Operator overloads #region Static
public static Quaternion operator +(Quaternion left, Quaternion right) #region Fields
{
left.XYZ += right.XYZ;
left.W += right.W;
return left;
}
public static Quaternion operator -(Quaternion left, Quaternion right) /// <summary>
{ /// Defines the identity quaternion.
left.XYZ -= right.XYZ; /// </summary>
left.W -= right.W; public static Quaternion Identity = new Quaternion(0, 0, 0, 1);
return left;
}
public static Quaternion operator *(Quaternion left, Quaternion right)
{
float w = left.W * right.W - Vector3.Dot(left.XYZ, right.XYZ);
left.XYZ = right.W * left.XYZ + left.W * right.XYZ + Vector3.Cross(left.XYZ, right.XYZ);
left.W = w;
return left;
}
[CLSCompliant(false)]
unsafe public static explicit operator float*(Quaternion q)
{
return &q.XYZ.X;
}
public static explicit operator IntPtr(Quaternion q)
{
unsafe
{
return (IntPtr)(&q.XYZ.X);
}
}
#endregion #endregion
#region Static functions
#region Add #region Add
/// <summary> /// <summary>
@ -444,6 +459,48 @@ namespace OpenTK.Math
#endregion #endregion
#region Operators
public static Quaternion operator +(Quaternion left, Quaternion right)
{
left.XYZ += right.XYZ;
left.W += right.W;
return left;
}
public static Quaternion operator -(Quaternion left, Quaternion right)
{
left.XYZ -= right.XYZ;
left.W -= right.W;
return left;
}
public static Quaternion operator *(Quaternion left, Quaternion right)
{
float w = left.W * right.W - Vector3.Dot(left.XYZ, right.XYZ);
left.XYZ = right.W * left.XYZ + left.W * right.XYZ + Vector3.Cross(left.XYZ, right.XYZ);
left.W = w;
return left;
}
[CLSCompliant(false)]
unsafe public static explicit operator float*(Quaternion q)
{
return &q.XYZ.X;
}
public static explicit operator IntPtr(Quaternion q)
{
unsafe
{
return (IntPtr)(&q.XYZ.X);
}
}
#endregion
#region Overrides
#region public override string ToString() #region public override string ToString()
/// <summary> /// <summary>
@ -456,5 +513,9 @@ namespace OpenTK.Math
} }
#endregion #endregion
#endregion
#endregion
} }
} }

Двоичные данные
Source/OpenTK/Math/Quaterniond.cs

Двоичный файл не отображается.

Просмотреть файл

@ -1,14 +1,28 @@
#region --- License --- #region --- License ---
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos /*
* See license.txt for license info Copyright (c) 2006 - 2008 The Open Toolkit library.
*
* Contributions by Andy Gill, Georg ¤chter. Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/ */
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace OpenTK.Math namespace OpenTK.Math
@ -35,26 +49,6 @@ namespace OpenTK.Math
/// </summary> /// </summary>
public float Y; public float Y;
/// <summary>
/// Defines a unit-length Vector2 that points towards the X-axis.
/// </summary>
public static Vector2 UnitX = new Vector2(1, 0);
/// <summary>
/// Defines a unit-length Vector2 that points towards the Y-axis.
/// </summary>
public static Vector2 UnitY = new Vector2(0, 1);
/// <summary>
/// Defines a zero-length Vector2.
/// </summary>
public static Vector2 Zero = new Vector2(0, 0);
/// <summary>
/// Defines the size of the Vector2 struct in bytes.
/// </summary>
public static readonly int SizeInBytes = Marshal.SizeOf(new Vector2());
#endregion #endregion
#region Constructors #region Constructors
@ -74,6 +68,7 @@ namespace OpenTK.Math
/// Constructs a new Vector2 from the given Vector2. /// Constructs a new Vector2 from the given Vector2.
/// </summary> /// </summary>
/// <param name="v">The Vector2 to copy components from.</param> /// <param name="v">The Vector2 to copy components from.</param>
[Obsolete]
public Vector2(Vector2 v) public Vector2(Vector2 v)
{ {
X = v.X; X = v.X;
@ -84,6 +79,7 @@ namespace OpenTK.Math
/// Constructs a new Vector2 from the given Vector3. /// Constructs a new Vector2 from the given Vector3.
/// </summary> /// </summary>
/// <param name="v">The Vector3 to copy components from. Z is discarded.</param> /// <param name="v">The Vector3 to copy components from. Z is discarded.</param>
[Obsolete]
public Vector2(Vector3 v) public Vector2(Vector3 v)
{ {
X = v.X; X = v.X;
@ -94,6 +90,7 @@ namespace OpenTK.Math
/// Constructs a new Vector2 from the given Vector4. /// Constructs a new Vector2 from the given Vector4.
/// </summary> /// </summary>
/// <param name="v">The Vector4 to copy components from. Z and W are discarded.</param> /// <param name="v">The Vector4 to copy components from. Z and W are discarded.</param>
[Obsolete]
public Vector2(Vector4 v) public Vector2(Vector4 v)
{ {
X = v.X; X = v.X;
@ -102,7 +99,9 @@ namespace OpenTK.Math
#endregion #endregion
#region Functions #region Public Members
#region Instance
#region public float Length #region public float Length
@ -239,79 +238,32 @@ namespace OpenTK.Math
#endregion #endregion
#region Operator overloads #region Static
public static Vector2 operator +(Vector2 left, Vector2 right) #region Fields
{
left.X += right.X;
left.Y += right.Y;
return left;
}
public static Vector2 operator -(Vector2 left, Vector2 right) /// <summary>
{ /// Defines a unit-length Vector2 that points towards the X-axis.
left.X -= right.X; /// </summary>
left.Y -= right.Y; public static readonly Vector2 UnitX = new Vector2(1, 0);
return left;
}
public static Vector2 operator -(Vector2 vec) /// <summary>
{ /// Defines a unit-length Vector2 that points towards the Y-axis.
vec.X = -vec.X; /// </summary>
vec.Y = -vec.Y; public static readonly Vector2 UnitY = new Vector2(0, 1);
return vec;
}
public static Vector2 operator *(Vector2 vec, float f) /// <summary>
{ /// Defines a zero-length Vector2.
vec.X *= f; /// </summary>
vec.Y *= f; public static readonly Vector2 Zero = new Vector2(0, 0);
return vec;
}
public static Vector2 operator *(float f, Vector2 vec) /// <summary>
{ /// Defines the size of the Vector2 struct in bytes.
vec.X *= f; /// </summary>
vec.Y *= f; public static readonly int SizeInBytes = Marshal.SizeOf(new Vector2());
return vec;
}
public static Vector2 operator /(Vector2 vec, float f)
{
float mult = 1.0f / f;
vec.X *= mult;
vec.Y *= mult;
return vec;
}
public static bool operator ==(Vector2 left, Vector2 right)
{
return left.Equals(right);
}
public static bool operator !=(Vector2 left, Vector2 right)
{
return !left.Equals(right);
}
[CLSCompliant(false)]
unsafe public static explicit operator float*(Vector2 v)
{
return &v.X;
}
public static explicit operator IntPtr(Vector2 v)
{
unsafe
{
return (IntPtr)(&v.X);
}
}
#endregion #endregion
#region Static functions
#region Add #region Add
/// <summary> /// <summary>
@ -430,7 +382,7 @@ namespace OpenTK.Math
#endregion #endregion
#region Min #region ComponentMin
/// <summary> /// <summary>
/// Calculate the component-wise minimum of two vectors /// Calculate the component-wise minimum of two vectors
@ -438,7 +390,7 @@ namespace OpenTK.Math
/// <param name="a">First operand</param> /// <param name="a">First operand</param>
/// <param name="b">Second operand</param> /// <param name="b">Second operand</param>
/// <returns>The component-wise minimum</returns> /// <returns>The component-wise minimum</returns>
public static Vector2 Min(Vector2 a, Vector2 b) public static Vector2 ComponentMin(Vector2 a, Vector2 b)
{ {
a.X = a.X < b.X ? a.X : b.X; a.X = a.X < b.X ? a.X : b.X;
a.Y = a.Y < b.Y ? a.Y : b.Y; a.Y = a.Y < b.Y ? a.Y : b.Y;
@ -451,7 +403,7 @@ namespace OpenTK.Math
/// <param name="a">First operand</param> /// <param name="a">First operand</param>
/// <param name="b">Second operand</param> /// <param name="b">Second operand</param>
/// <param name="result">The component-wise minimum</param> /// <param name="result">The component-wise minimum</param>
public static void Min(ref Vector2 a, ref Vector2 b, out Vector2 result) public static void ComponentMin(ref Vector2 a, ref Vector2 b, out Vector2 result)
{ {
result.X = a.X < b.X ? a.X : b.X; result.X = a.X < b.X ? a.X : b.X;
result.Y = a.Y < b.Y ? a.Y : b.Y; result.Y = a.Y < b.Y ? a.Y : b.Y;
@ -459,7 +411,7 @@ namespace OpenTK.Math
#endregion #endregion
#region Max #region ComponentMax
/// <summary> /// <summary>
/// Calculate the component-wise maximum of two vectors /// Calculate the component-wise maximum of two vectors
@ -467,7 +419,7 @@ namespace OpenTK.Math
/// <param name="a">First operand</param> /// <param name="a">First operand</param>
/// <param name="b">Second operand</param> /// <param name="b">Second operand</param>
/// <returns>The component-wise maximum</returns> /// <returns>The component-wise maximum</returns>
public static Vector2 Max(Vector2 a, Vector2 b) public static Vector2 ComponentMax(Vector2 a, Vector2 b)
{ {
a.X = a.X > b.X ? a.X : b.X; a.X = a.X > b.X ? a.X : b.X;
a.Y = a.Y > b.Y ? a.Y : b.Y; a.Y = a.Y > b.Y ? a.Y : b.Y;
@ -480,7 +432,7 @@ namespace OpenTK.Math
/// <param name="a">First operand</param> /// <param name="a">First operand</param>
/// <param name="b">Second operand</param> /// <param name="b">Second operand</param>
/// <param name="result">The component-wise maximum</param> /// <param name="result">The component-wise maximum</param>
public static void Max(ref Vector2 a, ref Vector2 b, out Vector2 result) public static void ComponentMax(ref Vector2 a, ref Vector2 b, out Vector2 result)
{ {
result.X = a.X > b.X ? a.X : b.X; result.X = a.X > b.X ? a.X : b.X;
result.Y = a.Y > b.Y ? a.Y : b.Y; result.Y = a.Y > b.Y ? a.Y : b.Y;
@ -488,6 +440,36 @@ namespace OpenTK.Math
#endregion #endregion
#region Min
/// <summary>
/// Returns the Vector3 with the minimum magnitude
/// </summary>
/// <param name="left">Left operand</param>
/// <param name="right">Right operand</param>
/// <returns>The minimum Vector3</returns>
public static Vector2 Min(Vector2 left, Vector2 right)
{
return left.LengthSquared < right.LengthSquared ? left : right;
}
#endregion
#region Max
/// <summary>
/// Returns the Vector3 with the minimum magnitude
/// </summary>
/// <param name="left">Left operand</param>
/// <param name="right">Right operand</param>
/// <returns>The minimum Vector3</returns>
public static Vector2 Max(Vector2 left, Vector2 right)
{
return left.LengthSquared >= right.LengthSquared ? left : right;
}
#endregion
#region Clamp #region Clamp
/// <summary> /// <summary>
@ -630,6 +612,65 @@ namespace OpenTK.Math
#endregion #endregion
#region Operators
public static Vector2 operator +(Vector2 left, Vector2 right)
{
left.X += right.X;
left.Y += right.Y;
return left;
}
public static Vector2 operator -(Vector2 left, Vector2 right)
{
left.X -= right.X;
left.Y -= right.Y;
return left;
}
public static Vector2 operator -(Vector2 vec)
{
vec.X = -vec.X;
vec.Y = -vec.Y;
return vec;
}
public static Vector2 operator *(Vector2 vec, float f)
{
vec.X *= f;
vec.Y *= f;
return vec;
}
public static Vector2 operator *(float f, Vector2 vec)
{
vec.X *= f;
vec.Y *= f;
return vec;
}
public static Vector2 operator /(Vector2 vec, float f)
{
float mult = 1.0f / f;
vec.X *= mult;
vec.Y *= mult;
return vec;
}
public static bool operator ==(Vector2 left, Vector2 right)
{
return left.Equals(right);
}
public static bool operator !=(Vector2 left, Vector2 right)
{
return !left.Equals(right);
}
#endregion
#region Overrides
#region public override string ToString() #region public override string ToString()
/// <summary> /// <summary>
@ -673,6 +714,10 @@ namespace OpenTK.Math
#endregion #endregion
#endregion
#endregion
#region IEquatable<Vector2> Members #region IEquatable<Vector2> Members
/// <summary>Indicates whether the current vector is equal to another vector.</summary> /// <summary>Indicates whether the current vector is equal to another vector.</summary>

Двоичные данные
Source/OpenTK/Math/Vector2d.cs

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,337 @@
#region --- License ---
/*
Copyright (c) 2006 - 2008 The Open Toolkit library.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#endregion
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace OpenTK.Math
{
/// <summary>2-component Vector of the Half type. Occupies 4 Byte total.</summary>
[Serializable, StructLayout(LayoutKind.Sequential)]
public struct Vector2h : ISerializable, IEquatable<Vector2h>
{
#region Fields
/// <summary>The X component of the Half2.</summary>
public Half X;
/// <summary>The Y component of the Half2.</summary>
public Half Y;
#endregion
#region Constructors
/// <summary>
/// The new Half2 instance will avoid conversion and copy directly from the Half parameters.
/// </summary>
/// <param name="x">An Half instance of a 16-Bit half precision floating point number.</param>
/// <param name="y">An Half instance of a 16-Bit half precision floating point number.</param>
public Vector2h(Half x, Half y)
{
X = x;
Y = y;
}
/// <summary>
/// The new Half2 instance will convert the 2 parameters into 16-Bit Half precision floating point.
/// </summary>
/// <param name="x">32-Bit Single precision floating point number.</param>
/// <param name="y">32-Bit Single precision floating point number.</param>
public Vector2h(Single x, Single y)
{
X = new Half(x);
Y = new Half(y);
}
/// <summary>
/// The new Half2 instance will convert the 2 parameters into 16-Bit Half precision floating point.
/// </summary>
/// <param name="x">32-Bit Single precision floating point number.</param>
/// <param name="y">32-Bit Single precision floating point number.</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
public Vector2h(Single x, Single y, bool throwOnError)
{
X = new Half(x, throwOnError);
Y = new Half(y, throwOnError);
}
/// <summary>
/// The new Half2 instance will convert the Vector2 into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector2</param>
[CLSCompliant(false)]
public Vector2h(Vector2 v)
{
X = new Half(v.X);
Y = new Half(v.Y);
}
/// <summary>
/// The new Half2 instance will convert the Vector2 into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector2</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
[CLSCompliant(false)]
public Vector2h(Vector2 v, bool throwOnError)
{
X = new Half(v.X, throwOnError);
Y = new Half(v.Y, throwOnError);
}
/// <summary>
/// The new Half2 instance will convert the Vector2 into 16-Bit Half precision floating point.
/// This is the fastest constructor.
/// </summary>
/// <param name="v">OpenTK.Math.Vector2</param>
public Vector2h(ref Vector2 v)
{
X = new Half(v.X);
Y = new Half(v.Y);
}
/// <summary>
/// The new Half2 instance will convert the Vector2 into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector2</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
public Vector2h(ref Vector2 v, bool throwOnError)
{
X = new Half(v.X, throwOnError);
Y = new Half(v.Y, throwOnError);
}
/// <summary>
/// The new Half2 instance will convert the Vector2d into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector2d</param>
public Vector2h(Vector2d v)
{
X = new Half(v.X);
Y = new Half(v.Y);
}
/// <summary>
/// The new Half2 instance will convert the Vector2d into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector2d</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
public Vector2h(Vector2d v, bool throwOnError)
{
X = new Half(v.X, throwOnError);
Y = new Half(v.Y, throwOnError);
}
/// <summary>
/// The new Half2 instance will convert the Vector2d into 16-Bit Half precision floating point.
/// This is the faster constructor.
/// </summary>
/// <param name="v">OpenTK.Math.Vector2d</param>
[CLSCompliant(false)]
public Vector2h(ref Vector2d v)
{
X = new Half(v.X);
Y = new Half(v.Y);
}
/// <summary>
/// The new Half2 instance will convert the Vector2d into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector2d</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
[CLSCompliant(false)]
public Vector2h(ref Vector2d v, bool throwOnError)
{
X = new Half(v.X, throwOnError);
Y = new Half(v.Y, throwOnError);
}
#endregion Constructors
#region Half -> Single
/// <summary>
/// Returns this Half2 instance's contents as Vector2.
/// </summary>
/// <returns>OpenTK.Math.Vector2</returns>
public Vector2 ToVector2()
{
return new Vector2(X, Y);
}
/// <summary>
/// Returns this Half2 instance's contents as Vector2d.
/// </summary>
/// <param name="v">OpenTK.Math.Vector2d</param>
public Vector2d ToVector2d()
{
return new Vector2d(X, Y);
}
#endregion Half -> Single
#region Conversions
/// <summary>Converts OpenTK.Math.Vector2 to OpenTK.Math.Half2.</summary>
/// <param name="v4f">The Vector2 to convert.</param>
/// <returns>The resulting Half vector.</returns>
public static explicit operator Vector2h(Vector2 v)
{
return new Vector2h(v);
}
/// <summary>Converts OpenTK.Math.Vector2d to OpenTK.Math.Half2.</summary>
/// <param name="v4d">The Vector2d to convert.</param>
/// <returns>The resulting Half vector.</returns>
public static explicit operator Vector2h(Vector2d v)
{
return new Vector2h(v);
}
/// <summary>Converts OpenTK.Math.Half2 to OpenTK.Math.Vector2.</summary>
/// <param name="h4">The Half2 to convert.</param>
/// <returns>The resulting Vector2.</returns>
public static explicit operator Vector2(Vector2h h)
{
return new Vector2(h.X, h.Y);
}
/// <summary>Converts OpenTK.Math.Half2 to OpenTK.Math.Vector2d.</summary>
/// <param name="h4">The Half2 to convert.</param>
/// <returns>The resulting Vector2d.</returns>
public static explicit operator Vector2d(Vector2h h)
{
return new Vector2d(h.X, h.Y);
}
#endregion Conversions
#region Constants
/// <summary>The size in bytes for an instance of the Half2 struct is 4.</summary>
public static readonly int SizeInBytes = 4;
#endregion Constants
#region ISerializable
/// <summary>Constructor used by ISerializable to deserialize the object.</summary>
/// <param name="info"></param>
/// <param name="context"></param>
public Vector2h(SerializationInfo info, StreamingContext context)
{
this.X = (Half)info.GetValue("X", typeof(Half));
this.Y = (Half)info.GetValue("Y", typeof(Half));
}
/// <summary>Used by ISerialize to serialize the object.</summary>
/// <param name="info"></param>
/// <param name="context"></param>
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("X", this.X);
info.AddValue("Y", this.Y);
}
#endregion ISerializable
#region Binary dump
/// <summary>Updates the X and Y components of this instance by reading from a Stream.</summary>
/// <param name="bin">A BinaryReader instance associated with an open Stream.</param>
public void FromBinaryStream(BinaryReader bin)
{
X.FromBinaryStream(bin);
Y.FromBinaryStream(bin);
}
/// <summary>Writes the X and Y components of this instance into a Stream.</summary>
/// <param name="bin">A BinaryWriter instance associated with an open Stream.</param>
public void ToBinaryStream(BinaryWriter bin)
{
X.ToBinaryStream(bin);
Y.ToBinaryStream(bin);
}
#endregion Binary dump
#region IEquatable<Half2> Members
/// <summary>Returns a value indicating whether this instance is equal to a specified OpenTK.Math.Half2 vector.</summary>
/// <param name="other">OpenTK.Math.Half2 to compare to this instance..</param>
/// <returns>True, if other is equal to this instance; false otherwise.</returns>
public bool Equals(Vector2h other)
{
return (this.X.Equals(other.X) && this.Y.Equals(other.Y));
}
#endregion
#region ToString()
/// <summary>Returns a string that contains this Half2's numbers in human-legible form.</summary>
public override string ToString()
{
return String.Format("({0}, {1})", X.ToString(), Y.ToString());
}
#endregion ToString()
#region BitConverter
/// <summary>Returns the Half2 as an array of bytes.</summary>
/// <param name="h">The Half2 to convert.</param>
/// <returns>The input as byte array.</returns>
public static byte[] GetBytes(Vector2h h)
{
byte[] result = new byte[SizeInBytes];
byte[] temp = Half.GetBytes(h.X);
result[0] = temp[0];
result[1] = temp[1];
temp = Half.GetBytes(h.Y);
result[2] = temp[0];
result[3] = temp[1];
return result;
}
/// <summary>Converts an array of bytes into Half2.</summary>
/// <param name="value">A Half2 in it's byte[] representation.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A new Half2 instance.</returns>
public static Vector2h FromBytes(byte[] value, int startIndex)
{
Vector2h h2 = new Vector2h();
h2.X = Half.FromBytes(value, startIndex);
h2.Y = Half.FromBytes(value, startIndex + 2);
return h2;
}
#endregion BitConverter
}
}

Просмотреть файл

@ -1,14 +1,28 @@
#region --- License --- #region --- License ---
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos /*
* See license.txt for license info Copyright (c) 2006 - 2008 The Open Toolkit library.
*
* Contributions by Andy Gill. Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/ */
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace OpenTK.Math namespace OpenTK.Math
@ -37,31 +51,6 @@ namespace OpenTK.Math
/// </summary> /// </summary>
public float Z; public float Z;
/// <summary>
/// Defines a unit-length Vector3 that points towards the X-axis.
/// </summary>
public static readonly Vector3 UnitX = new Vector3(1, 0, 0);
/// <summary>
/// Defines a unit-length Vector3 that points towards the Y-axis.
/// </summary>
public static readonly Vector3 UnitY = new Vector3(0, 1, 0);
/// <summary>
/// /// Defines a unit-length Vector3 that points towards the Z-axis.
/// </summary>
public static readonly Vector3 UnitZ = new Vector3(0, 0, 1);
/// <summary>
/// Defines a zero-length Vector3.
/// </summary>
public static readonly Vector3 Zero = new Vector3(0, 0, 0);
/// <summary>
/// Defines the size of the Vector3 struct in bytes.
/// </summary>
public static readonly int SizeInBytes = Marshal.SizeOf(new Vector3());
#endregion #endregion
#region Constructors #region Constructors
@ -114,33 +103,9 @@ namespace OpenTK.Math
#endregion #endregion
#region Functions #region Public Members
#region This property #region Instance
public float this[int index]
{
get
{
switch (index)
{
case 0: return X;
case 1: return Y;
case 2: return Z;
default: throw new ArgumentOutOfRangeException("index", index, "Should be 0, 1 or 2.");
}
/*
unsafe
{
fixed (float* ptr = &this.X)
return *(ptr + index);
}
*/
}
}
#endregion
#region public float Length #region public float Length
@ -251,71 +216,37 @@ namespace OpenTK.Math
#endregion #endregion
#region Operator overloads #region Static
public static Vector3 operator +(Vector3 left, Vector3 right) #region Fields
{
left.X += right.X;
left.Y += right.Y;
left.Z += right.Z;
return left;
}
public static Vector3 operator -(Vector3 left, Vector3 right) /// <summary>
{ /// Defines a unit-length Vector3 that points towards the X-axis.
left.X -= right.X; /// </summary>
left.Y -= right.Y; public static readonly Vector3 UnitX = new Vector3(1, 0, 0);
left.Z -= right.Z;
return left;
}
public static Vector3 operator -(Vector3 vec) /// <summary>
{ /// Defines a unit-length Vector3 that points towards the Y-axis.
vec.X = -vec.X; /// </summary>
vec.Y = -vec.Y; public static readonly Vector3 UnitY = new Vector3(0, 1, 0);
vec.Z = -vec.Z;
return vec;
}
public static Vector3 operator *(Vector3 vec, float f) /// <summary>
{ /// /// Defines a unit-length Vector3 that points towards the Z-axis.
vec.X *= f; /// </summary>
vec.Y *= f; public static readonly Vector3 UnitZ = new Vector3(0, 0, 1);
vec.Z *= f;
return vec;
}
public static Vector3 operator *(float f, Vector3 vec) /// <summary>
{ /// Defines a zero-length Vector3.
vec.X *= f; /// </summary>
vec.Y *= f; public static readonly Vector3 Zero = new Vector3(0, 0, 0);
vec.Z *= f;
return vec;
}
public static Vector3 operator /(Vector3 vec, float f) /// <summary>
{ /// Defines the size of the Vector3 struct in bytes.
float mult = 1.0f / f; /// </summary>
vec.X *= mult; public static readonly int SizeInBytes = Marshal.SizeOf(new Vector3());
vec.Y *= mult;
vec.Z *= mult;
return vec;
}
public static bool operator ==(Vector3 left, Vector3 right)
{
return left.Equals(right);
}
public static bool operator !=(Vector3 left, Vector3 right)
{
return !left.Equals(right);
}
#endregion #endregion
#region Static functions
#region Add #region Add
/// <summary> /// <summary>
@ -834,6 +765,71 @@ namespace OpenTK.Math
#endregion #endregion
#region Operators
public static Vector3 operator +(Vector3 left, Vector3 right)
{
left.X += right.X;
left.Y += right.Y;
left.Z += right.Z;
return left;
}
public static Vector3 operator -(Vector3 left, Vector3 right)
{
left.X -= right.X;
left.Y -= right.Y;
left.Z -= right.Z;
return left;
}
public static Vector3 operator -(Vector3 vec)
{
vec.X = -vec.X;
vec.Y = -vec.Y;
vec.Z = -vec.Z;
return vec;
}
public static Vector3 operator *(Vector3 vec, float f)
{
vec.X *= f;
vec.Y *= f;
vec.Z *= f;
return vec;
}
public static Vector3 operator *(float f, Vector3 vec)
{
vec.X *= f;
vec.Y *= f;
vec.Z *= f;
return vec;
}
public static Vector3 operator /(Vector3 vec, float f)
{
float mult = 1.0f / f;
vec.X *= mult;
vec.Y *= mult;
vec.Z *= mult;
return vec;
}
public static bool operator ==(Vector3 left, Vector3 right)
{
return left.Equals(right);
}
public static bool operator !=(Vector3 left, Vector3 right)
{
return !left.Equals(right);
}
#endregion
#region Overrides
#region public override string ToString() #region public override string ToString()
/// <summary> /// <summary>
@ -877,6 +873,10 @@ namespace OpenTK.Math
#endregion #endregion
#endregion
#endregion
#region IEquatable<Vector3> Members #region IEquatable<Vector3> Members
/// <summary>Indicates whether the current vector is equal to another vector.</summary> /// <summary>Indicates whether the current vector is equal to another vector.</summary>

Двоичные данные
Source/OpenTK/Math/Vector3d.cs

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,370 @@
#region --- License ---
/*
Copyright (c) 2006 - 2008 The Open Toolkit library.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#endregion
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace OpenTK.Math
{
/// <summary>3-component Vector of the Half type. Occupies 6 Byte total.</summary>
[Serializable, StructLayout(LayoutKind.Sequential)]
public struct Vector3h : ISerializable, IEquatable<Vector3h>
{
#region Public Fields
/// <summary>The X component of the Half3.</summary>
public Half X;
/// <summary>The Y component of the Half3.</summary>
public Half Y;
/// <summary>The Z component of the Half3.</summary>
public Half Z;
#endregion Public Fields
#region Constructors
/// <summary>
/// The new Half3 instance will avoid conversion and copy directly from the Half parameters.
/// </summary>
/// <param name="x">An Half instance of a 16-Bit half precision floating point number.</param>
/// <param name="y">An Half instance of a 16-Bit half precision floating point number.</param>
/// <param name="z">An Half instance of a 16-Bit half precision floating point number.</param>
public Vector3h(Half x, Half y, Half z)
{
this.X = x;
this.Y = y;
this.Z = z;
}
/// <summary>
/// The new Half3 instance will convert the 3 parameters into 16-Bit Half precision floating point.
/// </summary>
/// <param name="x">32-Bit Single precision floating point number.</param>
/// <param name="y">32-Bit Single precision floating point number.</param>
/// <param name="z">32-Bit Single precision floating point number.</param>
public Vector3h(Single x, Single y, Single z)
{
X = new Half(x);
Y = new Half(y);
Z = new Half(z);
}
/// <summary>
/// The new Half3 instance will convert the 3 parameters into 16-Bit Half precision floating point.
/// </summary>
/// <param name="x">32-Bit Single precision floating point number.</param>
/// <param name="y">32-Bit Single precision floating point number.</param>
/// <param name="z">32-Bit Single precision floating point number.</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
public Vector3h(Single x, Single y, Single z, bool throwOnError)
{
X = new Half(x, throwOnError);
Y = new Half(y, throwOnError);
Z = new Half(z, throwOnError);
}
/// <summary>
/// The new Half3 instance will convert the Vector3 into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector3</param>
[CLSCompliant(false)]
public Vector3h(Vector3 v)
{
X = new Half(v.X);
Y = new Half(v.Y);
Z = new Half(v.Z);
}
/// <summary>
/// The new Half3 instance will convert the Vector3 into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector3</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
[CLSCompliant(false)]
public Vector3h(Vector3 v, bool throwOnError)
{
X = new Half(v.X, throwOnError);
Y = new Half(v.Y, throwOnError);
Z = new Half(v.Z, throwOnError);
}
/// <summary>
/// The new Half3 instance will convert the Vector3 into 16-Bit Half precision floating point.
/// This is the fastest constructor.
/// </summary>
/// <param name="v">OpenTK.Math.Vector3</param>
public Vector3h(ref Vector3 v)
{
X = new Half(v.X);
Y = new Half(v.Y);
Z = new Half(v.Z);
}
/// <summary>
/// The new Half3 instance will convert the Vector3 into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector3</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
public Vector3h(ref Vector3 v, bool throwOnError)
{
X = new Half(v.X, throwOnError);
Y = new Half(v.Y, throwOnError);
Z = new Half(v.Z, throwOnError);
}
/// <summary>
/// The new Half3 instance will convert the Vector3d into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector3d</param>
public Vector3h(Vector3d v)
{
X = new Half(v.X);
Y = new Half(v.Y);
Z = new Half(v.Z);
}
/// <summary>
/// The new Half3 instance will convert the Vector3d into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector3d</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
public Vector3h(Vector3d v, bool throwOnError)
{
X = new Half(v.X, throwOnError);
Y = new Half(v.Y, throwOnError);
Z = new Half(v.Z, throwOnError);
}
/// <summary>
/// The new Half3 instance will convert the Vector3d into 16-Bit Half precision floating point.
/// This is the faster constructor.
/// </summary>
/// <param name="v">OpenTK.Math.Vector3d</param>
[CLSCompliant(false)]
public Vector3h(ref Vector3d v)
{
X = new Half(v.X);
Y = new Half(v.Y);
Z = new Half(v.Z);
}
/// <summary>
/// The new Half3 instance will convert the Vector3d into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector3d</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
[CLSCompliant(false)]
public Vector3h(ref Vector3d v, bool throwOnError)
{
X = new Half(v.X, throwOnError);
Y = new Half(v.Y, throwOnError);
Z = new Half(v.Z, throwOnError);
}
#endregion Constructors
#region Half -> Single
/// <summary>
/// Returns this Half3 instance's contents as Vector3.
/// </summary>
/// <returns>OpenTK.Math.Vector3</returns>
public Vector3 ToVector3()
{
return new Vector3(X, Y, Z);
}
/// <summary>
/// Returns this Half3 instance's contents as Vector3d.
/// </summary>
/// <param name="v">OpenTK.Math.Vector3d</param>
public Vector3d ToVector3d()
{
return new Vector3d(X, Y, Z);
}
#endregion Half -> Single
#region Conversions
/// <summary>Converts OpenTK.Math.Vector3 to OpenTK.Math.Half3.</summary>
/// <param name="v4f">The Vector3 to convert.</param>
/// <returns>The resulting Half vector.</returns>
public static explicit operator Vector3h(Vector3 v3f)
{
return new Vector3h(v3f);
}
/// <summary>Converts OpenTK.Math.Vector3d to OpenTK.Math.Half3.</summary>
/// <param name="v4d">The Vector3d to convert.</param>
/// <returns>The resulting Half vector.</returns>
public static explicit operator Vector3h(Vector3d v3d)
{
return new Vector3h(v3d);
}
/// <summary>Converts OpenTK.Math.Half3 to OpenTK.Math.Vector3.</summary>
/// <param name="h4">The Half3 to convert.</param>
/// <returns>The resulting Vector3.</returns>
public static explicit operator Vector3(Vector3h h3)
{
Vector3 result = new Vector3();
result.X = h3.X.ToSingle();
result.Y = h3.Y.ToSingle();
result.Z = h3.Z.ToSingle();
return result;
}
/// <summary>Converts OpenTK.Math.Half3 to OpenTK.Math.Vector3d.</summary>
/// <param name="h4">The Half3 to convert.</param>
/// <returns>The resulting Vector3d.</returns>
public static explicit operator Vector3d(Vector3h h3)
{
Vector3d result = new Vector3d();
result.X = h3.X.ToSingle();
result.Y = h3.Y.ToSingle();
result.Z = h3.Z.ToSingle();
return result;
}
#endregion Conversions
#region Constants
/// <summary>The size in bytes for an instance of the Half3 struct is 6.</summary>
public static readonly int SizeInBytes = 6;
#endregion Constants
#region ISerializable
/// <summary>Constructor used by ISerializable to deserialize the object.</summary>
/// <param name="info"></param>
/// <param name="context"></param>
public Vector3h(SerializationInfo info, StreamingContext context)
{
this.X = (Half)info.GetValue("X", typeof(Half));
this.Y = (Half)info.GetValue("Y", typeof(Half));
this.Z = (Half)info.GetValue("Z", typeof(Half));
}
/// <summary>Used by ISerialize to serialize the object.</summary>
/// <param name="info"></param>
/// <param name="context"></param>
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("X", this.X);
info.AddValue("Y", this.Y);
info.AddValue("Z", this.Z);
}
#endregion ISerializable
#region Binary dump
/// <summary>Updates the X,Y and Z components of this instance by reading from a Stream.</summary>
/// <param name="bin">A BinaryReader instance associated with an open Stream.</param>
public void FromBinaryStream(BinaryReader bin)
{
X.FromBinaryStream(bin);
Y.FromBinaryStream(bin);
Z.FromBinaryStream(bin);
}
/// <summary>Writes the X,Y and Z components of this instance into a Stream.</summary>
/// <param name="bin">A BinaryWriter instance associated with an open Stream.</param>
public void ToBinaryStream(BinaryWriter bin)
{
X.ToBinaryStream(bin);
Y.ToBinaryStream(bin);
Z.ToBinaryStream(bin);
}
#endregion Binary dump
#region IEquatable<Half3> Members
/// <summary>Returns a value indicating whether this instance is equal to a specified OpenTK.Math.Half3 vector.</summary>
/// <param name="other">OpenTK.Math.Half3 to compare to this instance..</param>
/// <returns>True, if other is equal to this instance; false otherwise.</returns>
public bool Equals(Vector3h other)
{
return (this.X.Equals(other.X) && this.Y.Equals(other.Y) && this.Z.Equals(other.Z));
}
#endregion
#region ToString()
/// <summary>Returns a string that contains this Half3's numbers in human-legible form.</summary>
public override string ToString()
{
return String.Format("({0}, {1}, {2})", X.ToString(), Y.ToString(), Z.ToString());
}
#endregion ToString()
#region BitConverter
/// <summary>Returns the Half3 as an array of bytes.</summary>
/// <param name="h">The Half3 to convert.</param>
/// <returns>The input as byte array.</returns>
public static byte[] GetBytes(Vector3h h)
{
byte[] result = new byte[SizeInBytes];
byte[] temp = Half.GetBytes(h.X);
result[0] = temp[0];
result[1] = temp[1];
temp = Half.GetBytes(h.Y);
result[2] = temp[0];
result[3] = temp[1];
temp = Half.GetBytes(h.Z);
result[4] = temp[0];
result[5] = temp[1];
return result;
}
/// <summary>Converts an array of bytes into Half3.</summary>
/// <param name="value">A Half3 in it's byte[] representation.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A new Half3 instance.</returns>
public static Vector3h FromBytes(byte[] value, int startIndex)
{
Vector3h h3 = new Vector3h();
h3.X = Half.FromBytes(value, startIndex);
h3.Y = Half.FromBytes(value, startIndex + 2);
h3.Z = Half.FromBytes(value, startIndex + 4);
return h3;
}
#endregion BitConverter
}
}

Просмотреть файл

@ -1,14 +1,28 @@
#region --- License --- #region --- License ---
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos /*
* See license.txt for license info Copyright (c) 2006 - 2008 The Open Toolkit library.
*
* Contributions by Andy Gill. Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/ */
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace OpenTK.Math namespace OpenTK.Math
@ -129,7 +143,9 @@ namespace OpenTK.Math
#endregion #endregion
#region Functions #region Public Members
#region Instance
#region public float Length #region public float Length
@ -244,90 +260,7 @@ namespace OpenTK.Math
#endregion #endregion
#region Operator overloads #region Static
public static Vector4 operator +(Vector4 left, Vector4 right)
{
left.X += right.X;
left.Y += right.Y;
left.Z += right.Z;
left.W += right.W;
return left;
}
public static Vector4 operator -(Vector4 left, Vector4 right)
{
left.X -= right.X;
left.Y -= right.Y;
left.Z -= right.Z;
left.W -= right.W;
return left;
}
public static Vector4 operator -(Vector4 vec)
{
vec.X = -vec.X;
vec.Y = -vec.Y;
vec.Z = -vec.Z;
vec.W = -vec.W;
return vec;
}
public static Vector4 operator *(Vector4 vec, float f)
{
vec.X *= f;
vec.Y *= f;
vec.Z *= f;
vec.W *= f;
return vec;
}
public static Vector4 operator *(float f, Vector4 vec)
{
vec.X *= f;
vec.Y *= f;
vec.Z *= f;
vec.W *= f;
return vec;
}
public static Vector4 operator /(Vector4 vec, float f)
{
float mult = 1.0f / f;
vec.X *= mult;
vec.Y *= mult;
vec.Z *= mult;
vec.W *= mult;
return vec;
}
public static bool operator ==(Vector4 left, Vector4 right)
{
return left.Equals(right);
}
public static bool operator !=(Vector4 left, Vector4 right)
{
return !left.Equals(right);
}
[CLSCompliant(false)]
unsafe public static explicit operator float*(Vector4 v)
{
return &v.X;
}
public static explicit operator IntPtr(Vector4 v)
{
unsafe
{
return (IntPtr)(&v.X);
}
}
#endregion
#region Static functions
#region Add #region Add
@ -705,6 +638,91 @@ namespace OpenTK.Math
#endregion #endregion
#region Operators
public static Vector4 operator +(Vector4 left, Vector4 right)
{
left.X += right.X;
left.Y += right.Y;
left.Z += right.Z;
left.W += right.W;
return left;
}
public static Vector4 operator -(Vector4 left, Vector4 right)
{
left.X -= right.X;
left.Y -= right.Y;
left.Z -= right.Z;
left.W -= right.W;
return left;
}
public static Vector4 operator -(Vector4 vec)
{
vec.X = -vec.X;
vec.Y = -vec.Y;
vec.Z = -vec.Z;
vec.W = -vec.W;
return vec;
}
public static Vector4 operator *(Vector4 vec, float f)
{
vec.X *= f;
vec.Y *= f;
vec.Z *= f;
vec.W *= f;
return vec;
}
public static Vector4 operator *(float f, Vector4 vec)
{
vec.X *= f;
vec.Y *= f;
vec.Z *= f;
vec.W *= f;
return vec;
}
public static Vector4 operator /(Vector4 vec, float f)
{
float mult = 1.0f / f;
vec.X *= mult;
vec.Y *= mult;
vec.Z *= mult;
vec.W *= mult;
return vec;
}
public static bool operator ==(Vector4 left, Vector4 right)
{
return left.Equals(right);
}
public static bool operator !=(Vector4 left, Vector4 right)
{
return !left.Equals(right);
}
[CLSCompliant(false)]
unsafe public static explicit operator float*(Vector4 v)
{
return &v.X;
}
public static explicit operator IntPtr(Vector4 v)
{
unsafe
{
return (IntPtr)(&v.X);
}
}
#endregion
#region Overrides
#region public override string ToString() #region public override string ToString()
/// <summary> /// <summary>
@ -748,6 +766,10 @@ namespace OpenTK.Math
#endregion #endregion
#endregion
#endregion
#region IEquatable<Vector4> Members #region IEquatable<Vector4> Members
/// <summary>Indicates whether the current vector is equal to another vector.</summary> /// <summary>Indicates whether the current vector is equal to another vector.</summary>

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,397 @@
#region --- License ---
/*
Copyright (c) 2006 - 2008 The Open Toolkit library.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#endregion
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace OpenTK.Math
{
/// <summary>4-component Vector of the Half type. Occupies 8 Byte total.</summary>
[Serializable, StructLayout(LayoutKind.Sequential)]
public struct Vector4h : ISerializable, IEquatable<Vector4h>
{
#region Public Fields
/// <summary>The X component of the Half4.</summary>
public Half X;
/// <summary>The Y component of the Half4.</summary>
public Half Y;
/// <summary>The Z component of the Half4.</summary>
public Half Z;
/// <summary>The W component of the Half4.</summary>
public Half W;
#endregion Public Fields
#region Constructors
/// <summary>
/// The new Half4 instance will avoid conversion and copy directly from the Half parameters.
/// </summary>
/// <param name="x">An Half instance of a 16-Bit half precision floating point number.</param>
/// <param name="y">An Half instance of a 16-Bit half precision floating point number.</param>
/// <param name="z">An Half instance of a 16-Bit half precision floating point number.</param>
/// <param name="w">An Half instance of a 16-Bit half precision floating point number.</param>
public Vector4h(Half x, Half y, Half z, Half w)
{
this.X = x;
this.Y = y;
this.Z = z;
this.W = w;
}
/// <summary>
/// The new Half4 instance will convert the 4 parameters into 16-Bit Half precision floating point.
/// </summary>
/// <param name="x">32-Bit Single precision floating point number.</param>
/// <param name="y">32-Bit Single precision floating point number.</param>
/// <param name="z">32-Bit Single precision floating point number.</param>
/// <param name="w">32-Bit Single precision floating point number.</param>
public Vector4h(Single x, Single y, Single z, Single w)
{
X = new Half(x);
Y = new Half(y);
Z = new Half(z);
W = new Half(w);
}
/// <summary>
/// The new Half4 instance will convert the 4 parameters into 16-Bit Half precision floating point.
/// </summary>
/// <param name="x">32-Bit Single precision floating point number.</param>
/// <param name="y">32-Bit Single precision floating point number.</param>
/// <param name="z">32-Bit Single precision floating point number.</param>
/// <param name="w">32-Bit Single precision floating point number.</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
public Vector4h(Single x, Single y, Single z, Single w, bool throwOnError)
{
X = new Half(x, throwOnError);
Y = new Half(y, throwOnError);
Z = new Half(z, throwOnError);
W = new Half(w, throwOnError);
}
/// <summary>
/// The new Half4 instance will convert the Vector4 into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector4</param>
[CLSCompliant(false)]
public Vector4h(Vector4 v)
{
X = new Half(v.X);
Y = new Half(v.Y);
Z = new Half(v.Z);
W = new Half(v.W);
}
/// <summary>
/// The new Half4 instance will convert the Vector4 into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector4</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
[CLSCompliant(false)]
public Vector4h(Vector4 v, bool throwOnError)
{
X = new Half(v.X, throwOnError);
Y = new Half(v.Y, throwOnError);
Z = new Half(v.Z, throwOnError);
W = new Half(v.W, throwOnError);
}
/// <summary>
/// The new Half4 instance will convert the Vector4 into 16-Bit Half precision floating point.
/// This is the fastest constructor.
/// </summary>
/// <param name="v">OpenTK.Math.Vector4</param>
public Vector4h(ref Vector4 v)
{
X = new Half(v.X);
Y = new Half(v.Y);
Z = new Half(v.Z);
W = new Half(v.W);
}
/// <summary>
/// The new Half4 instance will convert the Vector4 into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector4</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
public Vector4h(ref Vector4 v, bool throwOnError)
{
X = new Half(v.X, throwOnError);
Y = new Half(v.Y, throwOnError);
Z = new Half(v.Z, throwOnError);
W = new Half(v.W, throwOnError);
}
/// <summary>
/// The new Half4 instance will convert the Vector4d into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector4d</param>
public Vector4h(Vector4d v)
{
X = new Half(v.X);
Y = new Half(v.Y);
Z = new Half(v.Z);
W = new Half(v.W);
}
/// <summary>
/// The new Half4 instance will convert the Vector4d into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector4d</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
public Vector4h(Vector4d v, bool throwOnError)
{
X = new Half(v.X, throwOnError);
Y = new Half(v.Y, throwOnError);
Z = new Half(v.Z, throwOnError);
W = new Half(v.W, throwOnError);
}
/// <summary>
/// The new Half4 instance will convert the Vector4d into 16-Bit Half precision floating point.
/// This is the faster constructor.
/// </summary>
/// <param name="v">OpenTK.Math.Vector4d</param>
[CLSCompliant(false)]
public Vector4h(ref Vector4d v)
{
X = new Half(v.X);
Y = new Half(v.Y);
Z = new Half(v.Z);
W = new Half(v.W);
}
/// <summary>
/// The new Half4 instance will convert the Vector4d into 16-Bit Half precision floating point.
/// </summary>
/// <param name="v">OpenTK.Math.Vector4d</param>
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
[CLSCompliant(false)]
public Vector4h(ref Vector4d v, bool throwOnError)
{
X = new Half(v.X, throwOnError);
Y = new Half(v.Y, throwOnError);
Z = new Half(v.Z, throwOnError);
W = new Half(v.W, throwOnError);
}
#endregion Constructors
#region Half -> Single
/// <summary>
/// Returns this Half4 instance's contents as Vector4.
/// </summary>
/// <returns>OpenTK.Math.Vector4</returns>
public Vector4 ToVector4()
{
return new Vector4(X, Y, Z, W);
}
/// <summary>
/// Returns this Half4 instance's contents as Vector4d.
/// </summary>
/// <param name="v">OpenTK.Math.Vector4d</param>
public Vector4d ToVector4d()
{
return new Vector4d(X, Y, Z, W);
}
#endregion Half -> Single
#region Conversions
/// <summary>Converts OpenTK.Math.Vector4 to OpenTK.Math.Half4.</summary>
/// <param name="v4f">The Vector4 to convert.</param>
/// <returns>The resulting Half vector.</returns>
public static explicit operator Vector4h(Vector4 v4f)
{
return new Vector4h(v4f);
}
/// <summary>Converts OpenTK.Math.Vector4d to OpenTK.Math.Half4.</summary>
/// <param name="v4d">The Vector4d to convert.</param>
/// <returns>The resulting Half vector.</returns>
public static explicit operator Vector4h(Vector4d v4d)
{
return new Vector4h(v4d);
}
/// <summary>Converts OpenTK.Math.Half4 to OpenTK.Math.Vector4.</summary>
/// <param name="h4">The Half4 to convert.</param>
/// <returns>The resulting Vector4.</returns>
public static explicit operator Vector4(Vector4h h4)
{
Vector4 result = new Vector4();
result.X = h4.X.ToSingle();
result.Y = h4.Y.ToSingle();
result.Z = h4.Z.ToSingle();
result.W = h4.W.ToSingle();
return result;
}
/// <summary>Converts OpenTK.Math.Half4 to OpenTK.Math.Vector4d.</summary>
/// <param name="h4">The Half4 to convert.</param>
/// <returns>The resulting Vector4d.</returns>
public static explicit operator Vector4d(Vector4h h4)
{
Vector4d result = new Vector4d();
result.X = h4.X.ToSingle();
result.Y = h4.Y.ToSingle();
result.Z = h4.Z.ToSingle();
result.W = h4.W.ToSingle();
return result;
}
#endregion Conversions
#region Constants
/// <summary>The size in bytes for an instance of the Half4 struct is 8.</summary>
public static readonly int SizeInBytes = 8;
#endregion Constants
#region ISerializable
/// <summary>Constructor used by ISerializable to deserialize the object.</summary>
/// <param name="info"></param>
/// <param name="context"></param>
public Vector4h(SerializationInfo info, StreamingContext context)
{
this.X = (Half)info.GetValue("X", typeof(Half));
this.Y = (Half)info.GetValue("Y", typeof(Half));
this.Z = (Half)info.GetValue("Z", typeof(Half));
this.W = (Half)info.GetValue("W", typeof(Half));
}
/// <summary>Used by ISerialize to serialize the object.</summary>
/// <param name="info"></param>
/// <param name="context"></param>
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("X", this.X);
info.AddValue("Y", this.Y);
info.AddValue("Z", this.Z);
info.AddValue("W", this.W);
}
#endregion ISerializable
#region Binary dump
/// <summary>Updates the X,Y,Z and W components of this instance by reading from a Stream.</summary>
/// <param name="bin">A BinaryReader instance associated with an open Stream.</param>
public void FromBinaryStream(BinaryReader bin)
{
X.FromBinaryStream(bin);
Y.FromBinaryStream(bin);
Z.FromBinaryStream(bin);
W.FromBinaryStream(bin);
}
/// <summary>Writes the X,Y,Z and W components of this instance into a Stream.</summary>
/// <param name="bin">A BinaryWriter instance associated with an open Stream.</param>
public void ToBinaryStream(BinaryWriter bin)
{
X.ToBinaryStream(bin);
Y.ToBinaryStream(bin);
Z.ToBinaryStream(bin);
W.ToBinaryStream(bin);
}
#endregion Binary dump
#region IEquatable<Half4> Members
/// <summary>Returns a value indicating whether this instance is equal to a specified OpenTK.Math.Half4 vector.</summary>
/// <param name="other">OpenTK.Math.Half4 to compare to this instance..</param>
/// <returns>True, if other is equal to this instance; false otherwise.</returns>
public bool Equals(Vector4h other)
{
return (this.X.Equals(other.X) && this.Y.Equals(other.Y) && this.Z.Equals(other.Z) && this.W.Equals(other.W));
}
#endregion
#region ToString()
/// <summary>Returns a string that contains this Half4's numbers in human-legible form.</summary>
public override string ToString()
{
return String.Format("({0}, {1}, {2}, {3})", X.ToString(), Y.ToString(), Z.ToString(), W.ToString());
}
#endregion ToString()
#region BitConverter
/// <summary>Returns the Half4 as an array of bytes.</summary>
/// <param name="h">The Half4 to convert.</param>
/// <returns>The input as byte array.</returns>
public static byte[] GetBytes(Vector4h h)
{
byte[] result = new byte[SizeInBytes];
byte[] temp = Half.GetBytes(h.X);
result[0] = temp[0];
result[1] = temp[1];
temp = Half.GetBytes(h.Y);
result[2] = temp[0];
result[3] = temp[1];
temp = Half.GetBytes(h.Z);
result[4] = temp[0];
result[5] = temp[1];
temp = Half.GetBytes(h.W);
result[6] = temp[0];
result[7] = temp[1];
return result;
}
/// <summary>Converts an array of bytes into Half4.</summary>
/// <param name="value">A Half4 in it's byte[] representation.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A new Half4 instance.</returns>
public static Vector4h FromBytes(byte[] value, int startIndex)
{
Vector4h h4 = new Vector4h();
h4.X = Half.FromBytes(value, startIndex);
h4.Y = Half.FromBytes(value, startIndex + 2);
h4.Z = Half.FromBytes(value, startIndex + 4);
h4.W = Half.FromBytes(value, startIndex + 6);
return h4;
}
#endregion BitConverter
}
}