This commit is contained in:
Ethan Lee 2013-04-15 15:49:17 -04:00
Родитель 52a649f5aa
Коммит 21cb7cb7b7
46 изменённых файлов: 23831 добавлений и 0 удалений

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

@ -6,6 +6,9 @@ License
-------
SDL2 and SDL2# are released under the zlib license. See LICENSE for details.
SDL2# currently uses parts of OpenTK, which is released under the MIT license.
See opentk.LICENSE for details.
About SDL2
----------
For more information about SDL2, visit the SDL wiki:

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

@ -38,6 +38,48 @@
<Compile Include="src\SDL2_image.cs" />
<Compile Include="src\SDL2_mixer.cs" />
<Compile Include="src\SDL2_ttf.cs" />
<Compile Include="src\MiniTK\BlittableValueType.cs" />
<Compile Include="src\MiniTK\ContextHandle.cs" />
<Compile Include="src\MiniTK\Audio\AudioCapture.cs" />
<Compile Include="src\MiniTK\Audio\AudioContext.cs" />
<Compile Include="src\MiniTK\Audio\AudioContextException.cs" />
<Compile Include="src\MiniTK\Audio\AudioDeviceEnumerator.cs" />
<Compile Include="src\MiniTK\Audio\AudioDeviceErrorChecker.cs" />
<Compile Include="src\MiniTK\Audio\AudioDeviceException.cs" />
<Compile Include="src\MiniTK\Audio\AudioException.cs" />
<Compile Include="src\MiniTK\Audio\AudioValueException.cs" />
<Compile Include="src\MiniTK\Audio\OpenAL\AL\AL.cs" />
<Compile Include="src\MiniTK\Audio\OpenAL\AL\ALEnums.cs" />
<Compile Include="src\MiniTK\Audio\OpenAL\AL\EffectsExtension.cs" />
<Compile Include="src\MiniTK\Audio\OpenAL\AL\EffectsExtensionEnums.cs" />
<Compile Include="src\MiniTK\Audio\OpenAL\AL\EffectsExtensionPresets.cs" />
<Compile Include="src\MiniTK\Audio\OpenAL\AL\XRamExtension.cs" />
<Compile Include="src\MiniTK\Audio\OpenAL\Alc\Alc.cs" />
<Compile Include="src\MiniTK\Audio\OpenAL\Alc\AlcEnums.cs" />
<Compile Include="src\MiniTK\Math\BezierCurve.cs" />
<Compile Include="src\MiniTK\Math\BezierCurveCubic.cs" />
<Compile Include="src\MiniTK\Math\BezierCurveQuadric.cs" />
<Compile Include="src\MiniTK\Math\Box2.cs" />
<Compile Include="src\MiniTK\Math\Functions.cs" />
<Compile Include="src\MiniTK\Math\Half.cs" />
<Compile Include="src\MiniTK\Math\MathHelper.cs" />
<Compile Include="src\MiniTK\Math\Matrix3d.cs" />
<Compile Include="src\MiniTK\Math\Matrix4.cs" />
<Compile Include="src\MiniTK\Math\Matrix4d.cs" />
<Compile Include="src\MiniTK\Math\Point.cs" />
<Compile Include="src\MiniTK\Math\Quaternion.cs" />
<Compile Include="src\MiniTK\Math\Quaterniond.cs" />
<Compile Include="src\MiniTK\Math\Rectangle.cs" />
<Compile Include="src\MiniTK\Math\Size.cs" />
<Compile Include="src\MiniTK\Math\Vector2.cs" />
<Compile Include="src\MiniTK\Math\Vector2d.cs" />
<Compile Include="src\MiniTK\Math\Vector2h.cs" />
<Compile Include="src\MiniTK\Math\Vector3.cs" />
<Compile Include="src\MiniTK\Math\Vector3d.cs" />
<Compile Include="src\MiniTK\Math\Vector3h.cs" />
<Compile Include="src\MiniTK\Math\Vector4.cs" />
<Compile Include="src\MiniTK\Math\Vector4d.cs" />
<Compile Include="src\MiniTK\Math\Vector4h.cs" />
</ItemGroup>
<ItemGroup>
<None Include="SDL2#.dll.config">
@ -46,6 +88,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="src\" />
<Folder Include="src\MiniTK\" />
</ItemGroup>
<ProjectExtensions>
<MonoDevelop>
@ -56,4 +99,8 @@
</Properties>
</MonoDevelop>
</ProjectExtensions>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
</Project>

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

@ -15,4 +15,8 @@
<dllmap dll="SDL2_ttf.dll" os="windows" target="SDL2_ttf.dll"/>
<dllmap dll="SDL2_ttf.dll" os="osx" target="libSDL2_ttf-2.0.0.dylib"/>
<dllmap dll="SDL2_ttf.dll" os="linux" target="libSDL2_ttf-2.0.so.0"/>
<dllmap dll="openal32.dll" os="windows" target="openal32.dll"/>
<dllmap dll="openal32.dll" os="osx" target="libopenal.1.dylib"/>
<dllmap dll="openal32.dll" os="linux" target="libopenal.so.1"/>
</configuration>

21
opentk.LICENSE Normal file
Просмотреть файл

@ -0,0 +1,21 @@
/*
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.
*/

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

@ -0,0 +1,415 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 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.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using OpenTK.Audio.OpenAL;
namespace OpenTK.Audio
{
/// <summary>
/// Provides methods to instantiate, use and destroy an audio device for recording.
/// Static methods are provided to list available devices known by the driver.
/// </summary>
public sealed class AudioCapture : IDisposable
{
#region Fields
// This must stay private info so the end-user cannot call any Alc commands for the recording device.
IntPtr Handle;
// Alc.CaptureStop should be called prior to device shutdown, this keeps track of Alc.CaptureStart/Stop calls.
bool _isrecording = false;
ALFormat sample_format;
int sample_frequency;
#endregion
#region Constructors
static AudioCapture()
{
if (AudioDeviceEnumerator.IsOpenALSupported) // forces enumeration
{
}
}
/// <summary>
/// Opens the default device for audio recording.
/// Implicitly set parameters are: 22050Hz, 16Bit Mono, 4096 samples ringbuffer.
/// </summary>
public AudioCapture()
: this(AudioCapture.DefaultDevice, 22050, ALFormat.Mono16, 4096)
{
}
/// <summary>Opens a device for audio recording.</summary>
/// <param name="deviceName">The device name.</param>
/// <param name="frequency">The frequency that the data should be captured at.</param>
/// <param name="sampleFormat">The requested capture buffer format.</param>
/// <param name="bufferSize">The size of OpenAL's capture internal ring-buffer. This value expects number of samples, not bytes.</param>
public AudioCapture(string deviceName, int frequency, ALFormat sampleFormat, int bufferSize)
{
if (!AudioDeviceEnumerator.IsOpenALSupported)
throw new DllNotFoundException("openal32.dll");
if (frequency <= 0)
throw new ArgumentOutOfRangeException("frequency");
if (bufferSize <= 0)
throw new ArgumentOutOfRangeException("bufferSize");
// Try to open specified device. If it fails, try to open default device.
device_name = deviceName;
Handle = Alc.CaptureOpenDevice(deviceName, frequency, sampleFormat, bufferSize);
if (Handle == IntPtr.Zero)
{
Debug.WriteLine(ErrorMessage(deviceName, frequency, sampleFormat, bufferSize));
device_name = "IntPtr.Zero";
Handle = Alc.CaptureOpenDevice(null, frequency, sampleFormat, bufferSize);
}
if (Handle == IntPtr.Zero)
{
Debug.WriteLine(ErrorMessage("IntPtr.Zero", frequency, sampleFormat, bufferSize));
device_name = AudioDeviceEnumerator.DefaultRecordingDevice;
Handle = Alc.CaptureOpenDevice(AudioDeviceEnumerator.DefaultRecordingDevice, frequency, sampleFormat, bufferSize);
}
if (Handle == IntPtr.Zero)
{
// Everything we tried failed. Capture may not be supported, bail out.
Debug.WriteLine(ErrorMessage(AudioDeviceEnumerator.DefaultRecordingDevice, frequency, sampleFormat, bufferSize));
device_name = "None";
throw new AudioDeviceException("All attempts to open capture devices returned IntPtr.Zero. See debug log for verbose list.");
}
// handle is not null, check for some Alc Error
CheckErrors();
SampleFormat = sampleFormat;
SampleFrequency = frequency;
}
#endregion Constructor
#region Public Members
#region CurrentDevice
private string device_name;
/// <summary>
/// The name of the device associated with this instance.
/// </summary>
public string CurrentDevice
{
get
{
return device_name;
}
}
#endregion
#region AvailableDevices
/// <summary>
/// Returns a list of strings containing all known recording devices.
/// </summary>
public static IList<string> AvailableDevices
{
get
{
return AudioDeviceEnumerator.AvailableRecordingDevices;
}
}
#endregion
#region DefaultDevice
/// <summary>
/// Returns the name of the device that will be used as recording default.
/// </summary>
public static string DefaultDevice
{
get
{
return AudioDeviceEnumerator.DefaultRecordingDevice;
}
}
#endregion
#region CheckErrors
/// <summary>
/// Checks for ALC error conditions.
/// </summary>
/// <exception cref="OutOfMemoryException">Raised when an out of memory error is detected.</exception>
/// <exception cref="AudioValueException">Raised when an invalid value is detected.</exception>
/// <exception cref="AudioDeviceException">Raised when an invalid device is detected.</exception>
/// <exception cref="AudioContextException">Raised when an invalid context is detected.</exception>
public void CheckErrors()
{
new AudioDeviceErrorChecker(Handle).Dispose();
}
#endregion
#region CurrentError
/// <summary>Returns the ALC error code for this device.</summary>
public AlcError CurrentError
{
get
{
return Alc.GetError(Handle);
}
}
#endregion
#region Start & Stop
/// <summary>
/// Start recording samples.
/// The number of available samples can be obtained through the <see cref="AvailableSamples"/> property.
/// The data can be queried with any <see cref="ReadSamples(IntPtr, int)"/> method.
/// </summary>
public void Start()
{
Alc.CaptureStart(Handle);
_isrecording = true;
}
/// <summary>Stop recording samples. This will not clear previously recorded samples.</summary>
public void Stop()
{
Alc.CaptureStop(Handle);
_isrecording = false;
}
#endregion Start & Stop Capture
#region AvailableSamples
/// <summary>Returns the number of available samples for capture.</summary>
public int AvailableSamples
{
get
{
// TODO: Investigate inconsistency between documentation and actual usage.
// Doc claims the 3rd param is Number-of-Bytes, but it appears to be Number-of-Int32s
int result;
Alc.GetInteger(Handle, AlcGetInteger.CaptureSamples, 1, out result);
return result;
}
}
#endregion Available samples property
#region ReadSamples
/// <summary>Fills the specified buffer with samples from the internal capture ring-buffer. This method does not block: it is an error to specify a sampleCount larger than AvailableSamples.</summary>
/// <param name="buffer">A pointer to a previously initialized and pinned array.</param>
/// <param name="sampleCount">The number of samples to be written to the buffer.</param>
public void ReadSamples(IntPtr buffer, int sampleCount)
{
Alc.CaptureSamples(Handle, buffer, sampleCount);
}
/// <summary>Fills the specified buffer with samples from the internal capture ring-buffer. This method does not block: it is an error to specify a sampleCount larger than AvailableSamples.</summary>
/// <param name="buffer">The buffer to fill.</param>
/// <param name="sampleCount">The number of samples to be written to the buffer.</param>
/// <exception cref="System.ArgumentNullException">Raised when buffer is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">Raised when sampleCount is larger than the buffer.</exception>
public void ReadSamples<TBuffer>(TBuffer[] buffer, int sampleCount)
where TBuffer : struct
{
if (buffer == null)
throw new ArgumentNullException("buffer");
int buffer_size = BlittableValueType<TBuffer>.Stride * buffer.Length;
// This is more of a heuristic than a 100% valid check. However, it will work
// correctly for 99.9% of all use cases.
// This should never produce a false positive, but a false negative might
// be produced with compressed sample formats (which are very rare).
// Still, this is better than no check at all.
if (sampleCount * GetSampleSize(SampleFormat) > buffer_size)
throw new ArgumentOutOfRangeException("sampleCount");
GCHandle buffer_ptr = GCHandle.Alloc(buffer, GCHandleType.Pinned);
try { ReadSamples(buffer_ptr.AddrOfPinnedObject(), sampleCount); }
finally { buffer_ptr.Free(); }
}
#endregion
#region SampleFormat & SampleFrequency
/// <summary>
/// Gets the OpenTK.Audio.ALFormat for this instance.
/// </summary>
public ALFormat SampleFormat
{
get { return sample_format; }
private set { sample_format = value; }
}
/// <summary>
/// Gets the sampling rate for this instance.
/// </summary>
public int SampleFrequency
{
get { return sample_frequency; }
private set { sample_frequency = value; }
}
#endregion
#region IsRunning
/// <summary>
/// Gets a value indicating whether this instance is currently capturing samples.
/// </summary>
public bool IsRunning
{
get { return _isrecording; }
}
#endregion
#endregion
#region Private Members
// Retrieves the sample size in bytes for various ALFormats.
// Compressed formats always return 1.
static int GetSampleSize(ALFormat format)
{
switch (format)
{
case ALFormat.Mono8: return 1;
case ALFormat.Mono16: return 2;
case ALFormat.Stereo8: return 2;
case ALFormat.Stereo16: return 4;
case ALFormat.MonoFloat32Ext: return 4;
case ALFormat.MonoDoubleExt: return 8;
case ALFormat.StereoFloat32Ext: return 8;
case ALFormat.StereoDoubleExt: return 16;
case ALFormat.MultiQuad8Ext: return 4;
case ALFormat.MultiQuad16Ext: return 8;
case ALFormat.MultiQuad32Ext: return 16;
case ALFormat.Multi51Chn8Ext: return 6;
case ALFormat.Multi51Chn16Ext: return 12;
case ALFormat.Multi51Chn32Ext: return 24;
case ALFormat.Multi61Chn8Ext: return 7;
case ALFormat.Multi71Chn16Ext: return 14;
case ALFormat.Multi71Chn32Ext: return 28;
case ALFormat.MultiRear8Ext: return 1;
case ALFormat.MultiRear16Ext: return 2;
case ALFormat.MultiRear32Ext: return 4;
default: return 1; // Unknown sample size.
}
}
// Converts an error code to an error string with additional information.
string ErrorMessage(string devicename, int frequency, ALFormat bufferformat, int buffersize)
{
string alcerrmsg;
AlcError alcerrcode = CurrentError;
switch (alcerrcode)
{
case AlcError.OutOfMemory:
alcerrmsg = alcerrcode.ToString() + ": The specified device is invalid, or can not capture audio.";
break;
case AlcError.InvalidValue:
alcerrmsg = alcerrcode.ToString() + ": One of the parameters has an invalid value.";
break;
default:
alcerrmsg = alcerrcode.ToString();
break;
}
return "The handle returned by Alc.CaptureOpenDevice is null." +
"\nAlc Error: " + alcerrmsg +
"\nDevice Name: " + devicename +
"\nCapture frequency: " + frequency +
"\nBuffer format: " + bufferformat +
"\nBuffer Size: " + buffersize;
}
#endregion
#region IDisposable Members
/// <summary>
/// Finalizes this instance.
/// </summary>
~AudioCapture()
{
Dispose();
}
private bool IsDisposed;
/// <summary>Closes the device and disposes the instance.</summary>
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool manual)
{
if (!this.IsDisposed)
{
if (this.Handle != IntPtr.Zero)
{
if (this._isrecording)
this.Stop();
Alc.CaptureCloseDevice(this.Handle);
}
this.IsDisposed = true;
}
}
#endregion Destructor
}
}

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

@ -0,0 +1,770 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 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.Collections.Generic;
using System.Text;
using System.Diagnostics;
using OpenTK.Audio.OpenAL;
namespace OpenTK.Audio
{
/// <summary>
/// Provides methods to instantiate, use and destroy an audio context for playback.
/// Static methods are provided to list available devices known by the driver.
/// </summary>
public sealed class AudioContext : IDisposable
{
#region --- Fields ---
bool disposed;
bool is_processing, is_synchronized;
IntPtr device_handle;
ContextHandle context_handle;
bool context_exists;
string device_name;
static object audio_context_lock = new object();
static Dictionary<ContextHandle, AudioContext> available_contexts = new Dictionary<ContextHandle, AudioContext>();
#endregion
#region --- Constructors ---
#region static AudioContext()
/// \internal
/// <summary>
/// Runs before the actual class constructor, to load available devices.
/// </summary>
static AudioContext()
{
if (AudioDeviceEnumerator.IsOpenALSupported) // forces enumeration
{ }
}
#endregion static AudioContext()
#region public AudioContext()
/// <summary>Constructs a new AudioContext, using the default audio device.</summary>
public AudioContext()
: this(null, 0, 0, false, true, MaxAuxiliarySends.UseDriverDefault) { }
#endregion
#region public AudioContext(string device)
/// <summary>
/// Constructs a new AudioContext instance.
/// </summary>
/// <param name="device">The device name that will host this instance.</param>
public AudioContext(string device) : this(device, 0, 0, false, true, MaxAuxiliarySends.UseDriverDefault) { }
#endregion
#region public AudioContext(string device, int freq)
/// <summary>Constructs a new AudioContext, using the specified audio device and device parameters.</summary>
/// <param name="device">The name of the audio device to use.</param>
/// <param name="freq">Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default.</param>
/// <remarks>
/// Use AudioContext.AvailableDevices to obtain a list of all available audio devices.
/// devices.
/// </remarks>
public AudioContext(string device, int freq) : this(device, freq, 0, false, true, MaxAuxiliarySends.UseDriverDefault) { }
#endregion
#region public AudioContext(string device, int freq, int refresh)
/// <summary>Constructs a new AudioContext, using the specified audio device and device parameters.</summary>
/// <param name="device">The name of the audio device to use.</param>
/// <param name="freq">Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default.</param>
/// <param name="refresh">Refresh intervals, in units of Hz. Pass 0 for driver default.</param>
/// <remarks>
/// Use AudioContext.AvailableDevices to obtain a list of all available audio devices.
/// devices.
/// </remarks>
public AudioContext(string device, int freq, int refresh)
: this(device, freq, refresh, false, true, MaxAuxiliarySends.UseDriverDefault) { }
#endregion
#region public AudioContext(string device, int freq, int refresh, bool sync)
/// <summary>Constructs a new AudioContext, using the specified audio device and device parameters.</summary>
/// <param name="device">The name of the audio device to use.</param>
/// <param name="freq">Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default.</param>
/// <param name="refresh">Refresh intervals, in units of Hz. Pass 0 for driver default.</param>
/// <param name="sync">Flag, indicating a synchronous context.</param>
/// <remarks>
/// Use AudioContext.AvailableDevices to obtain a list of all available audio devices.
/// devices.
/// </remarks>
public AudioContext(string device, int freq, int refresh, bool sync)
: this(AudioDeviceEnumerator.AvailablePlaybackDevices[0], freq, refresh, sync, true) { }
#endregion
#region public AudioContext(string device, int freq, int refresh, bool sync, bool enableEfx)
/// <summary>Creates the audio context using the specified device and device parameters.</summary>
/// <param name="device">The device descriptor obtained through AudioContext.AvailableDevices.</param>
/// <param name="freq">Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default.</param>
/// <param name="refresh">Refresh intervals, in units of Hz. Pass 0 for driver default.</param>
/// <param name="sync">Flag, indicating a synchronous context.</param>
/// <param name="enableEfx">Indicates whether the EFX extension should be initialized, if present.</param>
/// <exception cref="ArgumentNullException">Occurs when the device string is invalid.</exception>
/// <exception cref="ArgumentOutOfRangeException">Occurs when a specified parameter is invalid.</exception>
/// <exception cref="AudioDeviceException">
/// Occurs when the specified device is not available, or is in use by another program.
/// </exception>
/// <exception cref="AudioContextException">
/// Occurs when an audio context could not be created with the specified parameters.
/// </exception>
/// <exception cref="NotSupportedException">
/// Occurs when an AudioContext already exists.</exception>
/// <remarks>
/// <para>For maximum compatibility, you are strongly recommended to use the default constructor.</para>
/// <para>Multiple AudioContexts are not supported at this point.</para>
/// <para>
/// The number of auxilliary EFX sends depends on the audio hardware and drivers. Most Realtek devices, as well
/// as the Creative SB Live!, support 1 auxilliary send. Creative's Audigy and X-Fi series support 4 sends.
/// Values higher than supported will be clamped by the driver.
/// </para>
/// </remarks>
public AudioContext(string device, int freq, int refresh, bool sync, bool enableEfx)
{
CreateContext(device, freq, refresh, sync, enableEfx, MaxAuxiliarySends.UseDriverDefault);
}
#endregion
#region public AudioContext(string device, int freq, int refresh, bool sync, bool enableEfx, MaxAuxiliarySends efxMaxAuxSends)
/// <summary>Creates the audio context using the specified device and device parameters.</summary>
/// <param name="device">The device descriptor obtained through AudioContext.AvailableDevices.</param>
/// <param name="freq">Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default.</param>
/// <param name="refresh">Refresh intervals, in units of Hz. Pass 0 for driver default.</param>
/// <param name="sync">Flag, indicating a synchronous context.</param>
/// <param name="enableEfx">Indicates whether the EFX extension should be initialized, if present.</param>
/// <param name="efxMaxAuxSends">Requires EFX enabled. The number of desired Auxiliary Sends per source.</param>
/// <exception cref="ArgumentNullException">Occurs when the device string is invalid.</exception>
/// <exception cref="ArgumentOutOfRangeException">Occurs when a specified parameter is invalid.</exception>
/// <exception cref="AudioDeviceException">
/// Occurs when the specified device is not available, or is in use by another program.
/// </exception>
/// <exception cref="AudioContextException">
/// Occurs when an audio context could not be created with the specified parameters.
/// </exception>
/// <exception cref="NotSupportedException">
/// Occurs when an AudioContext already exists.</exception>
/// <remarks>
/// <para>For maximum compatibility, you are strongly recommended to use the default constructor.</para>
/// <para>Multiple AudioContexts are not supported at this point.</para>
/// <para>
/// The number of auxilliary EFX sends depends on the audio hardware and drivers. Most Realtek devices, as well
/// as the Creative SB Live!, support 1 auxilliary send. Creative's Audigy and X-Fi series support 4 sends.
/// Values higher than supported will be clamped by the driver.
/// </para>
/// </remarks>
public AudioContext(string device, int freq, int refresh, bool sync, bool enableEfx, MaxAuxiliarySends efxMaxAuxSends)
{
CreateContext(device, freq, refresh, sync, enableEfx, efxMaxAuxSends);
}
#endregion
#endregion --- Constructors ---
#region --- Private Methods ---
#region CreateContext
/// <summary>May be passed at context construction time to indicate the number of desired auxiliary effect slot sends per source.</summary>
public enum MaxAuxiliarySends:int
{
/// <summary>Will chose a reliably working parameter.</summary>
UseDriverDefault = 0,
/// <summary>One send per source.</summary>
One = 1,
/// <summary>Two sends per source.</summary>
Two = 2,
/// <summary>Three sends per source.</summary>
Three = 3,
/// <summary>Four sends per source.</summary>
Four = 4,
}
/// \internal
/// <summary>Creates the audio context using the specified device.</summary>
/// <param name="device">The device descriptor obtained through AudioContext.AvailableDevices, or null for the default device.</param>
/// <param name="freq">Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default.</param>
/// <param name="refresh">Refresh intervals, in units of Hz. Pass 0 for driver default.</param>
/// <param name="sync">Flag, indicating a synchronous context.</param>
/// <param name="enableEfx">Indicates whether the EFX extension should be initialized, if present.</param>
/// <param name="efxAuxiliarySends">Requires EFX enabled. The number of desired Auxiliary Sends per source.</param>
/// <exception cref="ArgumentOutOfRangeException">Occurs when a specified parameter is invalid.</exception>
/// <exception cref="AudioDeviceException">
/// Occurs when the specified device is not available, or is in use by another program.
/// </exception>
/// <exception cref="AudioContextException">
/// Occurs when an audio context could not be created with the specified parameters.
/// </exception>
/// <exception cref="NotSupportedException">
/// Occurs when an AudioContext already exists.</exception>
/// <remarks>
/// <para>For maximum compatibility, you are strongly recommended to use the default constructor.</para>
/// <para>Multiple AudioContexts are not supported at this point.</para>
/// <para>
/// The number of auxilliary EFX sends depends on the audio hardware and drivers. Most Realtek devices, as well
/// as the Creative SB Live!, support 1 auxilliary send. Creative's Audigy and X-Fi series support 4 sends.
/// Values higher than supported will be clamped by the driver.
/// </para>
/// </remarks>
void CreateContext(string device, int freq, int refresh, bool sync, bool enableEfx, MaxAuxiliarySends efxAuxiliarySends)
{
if (!AudioDeviceEnumerator.IsOpenALSupported)
throw new DllNotFoundException("openal32.dll");
if (AudioDeviceEnumerator.Version == AudioDeviceEnumerator.AlcVersion.Alc1_1 && AudioDeviceEnumerator.AvailablePlaybackDevices.Count == 0) // Alc 1.0 does not support device enumeration.
throw new NotSupportedException("No audio hardware is available.");
if (context_exists) throw new NotSupportedException("Multiple AudioContexts are not supported.");
if (freq < 0) throw new ArgumentOutOfRangeException("freq", freq, "Should be greater than zero.");
if (refresh < 0) throw new ArgumentOutOfRangeException("refresh", refresh, "Should be greater than zero.");
if (!String.IsNullOrEmpty(device))
{
device_name = device;
device_handle = Alc.OpenDevice(device); // try to open device by name
}
if (device_handle == IntPtr.Zero)
{
device_name = "IntPtr.Zero (null string)";
device_handle = Alc.OpenDevice(null); // try to open unnamed default device
}
if (device_handle == IntPtr.Zero)
{
device_name = AudioContext.DefaultDevice;
device_handle = Alc.OpenDevice(AudioContext.DefaultDevice); // try to open named default device
}
if (device_handle == IntPtr.Zero)
{
device_name = "None";
throw new AudioDeviceException(String.Format("Audio device '{0}' does not exist or is tied up by another application.",
String.IsNullOrEmpty(device) ? "default" : device));
}
CheckErrors();
// Build the attribute list
List<int> attributes = new List<int>();
if (freq != 0)
{
attributes.Add((int)AlcContextAttributes.Frequency);
attributes.Add(freq);
}
if (refresh != 0)
{
attributes.Add((int)AlcContextAttributes.Refresh);
attributes.Add(refresh);
}
attributes.Add((int)AlcContextAttributes.Sync);
attributes.Add(sync ? 1 : 0);
if (enableEfx && Alc.IsExtensionPresent(device_handle, "ALC_EXT_EFX"))
{
int num_slots;
switch (efxAuxiliarySends)
{
case MaxAuxiliarySends.One:
case MaxAuxiliarySends.Two:
case MaxAuxiliarySends.Three:
case MaxAuxiliarySends.Four:
num_slots = (int)efxAuxiliarySends;
break;
default:
case MaxAuxiliarySends.UseDriverDefault:
Alc.GetInteger(device_handle, AlcGetInteger.EfxMaxAuxiliarySends, 1, out num_slots);
break;
}
attributes.Add((int)AlcContextAttributes.EfxMaxAuxiliarySends);
attributes.Add(num_slots);
}
attributes.Add(0);
context_handle = Alc.CreateContext(device_handle, attributes.ToArray());
if (context_handle == ContextHandle.Zero)
{
Alc.CloseDevice(device_handle);
throw new AudioContextException("The audio context could not be created with the specified parameters.");
}
CheckErrors();
// HACK: OpenAL SI on Linux/ALSA crashes on MakeCurrent. This hack avoids calling MakeCurrent when
// an old OpenAL version is detect - it may affect outdated OpenAL versions different than OpenAL SI,
// but it looks like a good compromise for now.
if (AudioDeviceEnumerator.AvailablePlaybackDevices.Count > 0)
MakeCurrent();
CheckErrors();
device_name = Alc.GetString(device_handle, AlcGetString.DeviceSpecifier);
lock (audio_context_lock)
{
available_contexts.Add(this.context_handle, this);
context_exists = true;
}
}
#endregion --- Private Methods ---
#region static void MakeCurrent(AudioContext context)
/// \internal
/// <summary>Makes the specified AudioContext current in the calling thread.</summary>
/// <param name="context">The OpenTK.Audio.AudioContext to make current, or null.</param>
/// <exception cref="ObjectDisposedException">
/// Occurs if this function is called after the AudioContext has been disposed.
/// </exception>
/// <exception cref="AudioContextException">
/// Occurs when the AudioContext could not be made current.
/// </exception>
static void MakeCurrent(AudioContext context)
{
lock (audio_context_lock)
{
if (!Alc.MakeContextCurrent(context != null ? context.context_handle : ContextHandle.Zero))
throw new AudioContextException(String.Format("ALC {0} error detected at {1}.",
Alc.GetError(context != null ? (IntPtr)context.context_handle : IntPtr.Zero).ToString(),
context != null ? context.ToString() : "null"));
}
}
#endregion
#region internal bool IsCurrent
/// <summary>
/// Gets or sets a System.Boolean indicating whether the AudioContext
/// is current.
/// </summary>
/// <remarks>
/// Only one AudioContext can be current in the application at any time,
/// <b>regardless of the number of threads</b>.
/// </remarks>
internal bool IsCurrent
{
get
{
lock (audio_context_lock)
{
if (available_contexts.Count == 0)
return false;
else
{
return AudioContext.CurrentContext == this;
}
}
}
set
{
if (value) AudioContext.MakeCurrent(this);
else AudioContext.MakeCurrent(null);
}
}
#endregion
#region IntPtr Device
IntPtr Device { get { return device_handle; } }
#endregion
#endregion
#region --- Public Members ---
#region CheckErrors
/// <summary>
/// Checks for ALC error conditions.
/// </summary>
/// <exception cref="OutOfMemoryException">Raised when an out of memory error is detected.</exception>
/// <exception cref="AudioValueException">Raised when an invalid value is detected.</exception>
/// <exception cref="AudioDeviceException">Raised when an invalid device is detected.</exception>
/// <exception cref="AudioContextException">Raised when an invalid context is detected.</exception>
public void CheckErrors()
{
if (disposed)
throw new ObjectDisposedException(this.GetType().FullName);
new AudioDeviceErrorChecker(device_handle).Dispose();
}
#endregion
#region CurrentError
/// <summary>
/// Returns the ALC error code for this instance.
/// </summary>
public AlcError CurrentError
{
get
{
if (disposed)
throw new ObjectDisposedException(this.GetType().FullName);
return Alc.GetError(device_handle);
}
}
#endregion
#region MakeCurrent
/// <summary>Makes the AudioContext current in the calling thread.</summary>
/// <exception cref="ObjectDisposedException">
/// Occurs if this function is called after the AudioContext has been disposed.
/// </exception>
/// <exception cref="AudioContextException">
/// Occurs when the AudioContext could not be made current.
/// </exception>
/// <remarks>
/// Only one AudioContext can be current in the application at any time,
/// <b>regardless of the number of threads</b>.
/// </remarks>
public void MakeCurrent()
{
if (disposed)
throw new ObjectDisposedException(this.GetType().FullName);
AudioContext.MakeCurrent(this);
}
#endregion
#region IsProcessing
/// <summary>
/// Gets a System.Boolean indicating whether the AudioContext is
/// currently processing audio events.
/// </summary>
/// <seealso cref="Process"/>
/// <seealso cref="Suspend"/>
public bool IsProcessing
{
get
{
if (disposed)
throw new ObjectDisposedException(this.GetType().FullName);
return is_processing;
}
private set { is_processing = value; }
}
#endregion
#region IsSynchronized
/// <summary>
/// Gets a System.Boolean indicating whether the AudioContext is
/// synchronized.
/// </summary>
/// <seealso cref="Process"/>
public bool IsSynchronized
{
get
{
if (disposed)
throw new ObjectDisposedException(this.GetType().FullName);
return is_synchronized;
}
private set { is_synchronized = value; }
}
#endregion
#region public void Process
/// <summary>
/// Processes queued audio events.
/// </summary>
/// <remarks>
/// <para>
/// If AudioContext.IsSynchronized is true, this function will resume
/// the internal audio processing thread. If AudioContext.IsSynchronized is false,
/// you will need to call this function multiple times per second to process
/// audio events.
/// </para>
/// <para>
/// In some implementations this function may have no effect.
/// </para>
/// </remarks>
/// <exception cref="ObjectDisposedException">Occurs when this function is called after the AudioContext had been disposed.</exception>
/// <seealso cref="Suspend"/>
/// <seealso cref="IsProcessing"/>
/// <seealso cref="IsSynchronized"/>
public void Process()
{
if (disposed)
throw new ObjectDisposedException(this.GetType().FullName);
Alc.ProcessContext(this.context_handle);
IsProcessing = true;
}
#endregion
#region public void Suspend
/// <summary>
/// Suspends processing of audio events.
/// </summary>
/// <remarks>
/// <para>
/// To avoid audio artifacts when calling this function, set audio gain to zero before
/// suspending an AudioContext.
/// </para>
/// <para>
/// In some implementations, it can be faster to suspend processing before changing
/// AudioContext state.
/// </para>
/// <para>
/// In some implementations this function may have no effect.
/// </para>
/// </remarks>
/// <exception cref="ObjectDisposedException">Occurs when this function is called after the AudioContext had been disposed.</exception>
/// <seealso cref="Process"/>
/// <seealso cref="IsProcessing"/>
/// <seealso cref="IsSynchronized"/>
public void Suspend()
{
if (disposed)
throw new ObjectDisposedException(this.GetType().FullName);
Alc.SuspendContext(this.context_handle);
IsProcessing = false;
}
#endregion
#region public bool SupportsExtension(string extension)
/// <summary>
/// Checks whether the specified OpenAL extension is supported.
/// </summary>
/// <param name="extension">The name of the extension to check (e.g. "ALC_EXT_EFX").</param>
/// <returns>true if the extension is supported; false otherwise.</returns>
public bool SupportsExtension(string extension)
{
if (disposed)
throw new ObjectDisposedException(this.GetType().FullName);
return Alc.IsExtensionPresent(this.Device, extension);
}
#endregion
#region CurrentDevice
/// <summary>
/// Gets a System.String with the name of the device used in this context.
/// </summary>
public string CurrentDevice
{
get
{
if (disposed)
throw new ObjectDisposedException(this.GetType().FullName);
return device_name;
}
}
#endregion
#endregion --- Public Members ---
#region --- Static Members ---
#region public static AudioContext CurrentContext
/// <summary>
/// Gets the OpenTK.Audio.AudioContext which is current in the application.
/// </summary>
/// <remarks>
/// Only one AudioContext can be current in the application at any time,
/// <b>regardless of the number of threads</b>.
/// </remarks>
public static AudioContext CurrentContext
{
get
{
lock (audio_context_lock)
{
if (available_contexts.Count == 0)
return null;
else
{
AudioContext context;
AudioContext.available_contexts.TryGetValue(
(ContextHandle)Alc.GetCurrentContext(),
out context);
return context;
}
}
}
}
#endregion
#region AvailableDevices
/// <summary>
/// Returns a list of strings containing all known playback devices.
/// </summary>
public static IList<string> AvailableDevices
{
get
{
return AudioDeviceEnumerator.AvailablePlaybackDevices;
}
}
#endregion public static IList<string> AvailablePlaybackDevices
#region DefaultDevice
/// <summary>
/// Returns the name of the device that will be used as playback default.
/// </summary>
public static string DefaultDevice
{
get
{
return AudioDeviceEnumerator.DefaultPlaybackDevice;
}
}
#endregion
#endregion
#region --- IDisposable Members ---
/// <summary>
/// Disposes of the AudioContext, cleaning up all resources consumed by it.
/// </summary>
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
void Dispose(bool manual)
{
if (!disposed)
{
if (this.IsCurrent)
this.IsCurrent = false;
if (context_handle != ContextHandle.Zero)
{
available_contexts.Remove(context_handle);
Alc.DestroyContext(context_handle);
}
if (device_handle != IntPtr.Zero)
Alc.CloseDevice(device_handle);
if (manual)
{
}
disposed = true;
}
}
/// <summary>
/// Finalizes this instance.
/// </summary>
~AudioContext()
{
this.Dispose(false);
}
#endregion
#region --- Overrides ---
/// <summary>
/// Calculates the hash code for this instance.
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return base.GetHashCode();
}
/// <summary>
/// Compares this instance with another.
/// </summary>
/// <param name="obj">The instance to compare to.</param>
/// <returns>True, if obj refers to this instance; false otherwise.</returns>
public override bool Equals(object obj)
{
return base.Equals(obj);
}
/// <summary>
/// Returns a <see cref="System.String"/> that desrcibes this instance.
/// </summary>
/// <returns>A <see cref="System.String"/> that desrcibes this instance.</returns>
public override string ToString()
{
return String.Format("{0} (handle: {1}, device: {2})",
this.device_name, this.context_handle, this.device_handle);
}
#endregion
}
}

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

@ -0,0 +1,44 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 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.Collections.Generic;
using System.Text;
namespace OpenTK.Audio
{
/// <summary>Represents exceptions related to an OpenTK.Audio.AudioContext.</summary>
public class AudioContextException : AudioException
{
/// <summary>Constructs a new AudioContextException.</summary>
public AudioContextException() : base() { }
/// <summary>Constructs a new AudioContextException with the specified error message.</summary>
/// <param name="message">The error message of the AudioContextException.</param>
public AudioContextException(string message) : base(message) { }
}
}

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

@ -0,0 +1,218 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 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.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using OpenTK.Audio.OpenAL;
namespace OpenTK.Audio
{
internal static class AudioDeviceEnumerator
{
#region All device strings
private static readonly List<string> available_playback_devices = new List<string>();
private static readonly List<string> available_recording_devices = new List<string>();
internal static IList<string> AvailablePlaybackDevices
{
get
{
return available_playback_devices.AsReadOnly();
}
}
internal static IList<string> AvailableRecordingDevices
{
get
{
return available_recording_devices.AsReadOnly();
}
}
#endregion All device strings
#region Default device strings
private static string default_playback_device;
internal static string DefaultPlaybackDevice
{
get
{
return default_playback_device;
}
}
private static string default_recording_device;
internal static string DefaultRecordingDevice
{
get
{
return default_recording_device;
}
}
#endregion Default device strings
#region Is OpenAL supported?
private static bool openal_supported = true;
internal static bool IsOpenALSupported
{
get
{
return openal_supported;
}
}
#endregion Is OpenAL supported?
#region Alc Version number
internal enum AlcVersion
{
Alc1_0,
Alc1_1
}
private static AlcVersion version;
internal static AlcVersion Version
{
get
{
return version;
}
}
#endregion Alc Version number
#region Constructors
// Loads all available audio devices into the available_*_devices lists.
static AudioDeviceEnumerator()
{
IntPtr dummy_device = IntPtr.Zero;
ContextHandle dummy_context = ContextHandle.Zero;
try
{
Debug.WriteLine("Enumerating audio devices.");
Debug.Indent();
// need a dummy context for correct results
dummy_device = Alc.OpenDevice(null);
dummy_context = Alc.CreateContext(dummy_device, (int[])null);
bool dummy_success = Alc.MakeContextCurrent(dummy_context);
AlcError dummy_error = Alc.GetError(dummy_device);
if (!dummy_success || dummy_error != AlcError.NoError)
{
throw new AudioContextException("Failed to create dummy Context. Device (" + dummy_device.ToString() +
") Context (" + dummy_context.Handle.ToString() +
") MakeContextCurrent " + (dummy_success ? "succeeded" : "failed") +
", Alc Error (" + dummy_error.ToString() + ") " + Alc.GetString(IntPtr.Zero, (AlcGetString)dummy_error));
}
// Get a list of all known playback devices, using best extension available
if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT"))
{
version = AlcVersion.Alc1_1;
if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATE_ALL_EXT"))
{
available_playback_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.AllDevicesSpecifier));
default_playback_device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultAllDevicesSpecifier);
}
else
{
available_playback_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.DeviceSpecifier));
default_playback_device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultDeviceSpecifier);
}
}
else
{
version = AlcVersion.Alc1_0;
Debug.Print("Device enumeration extension not available. Failed to enumerate playback devices.");
}
AlcError playback_err = Alc.GetError(dummy_device);
if (playback_err != AlcError.NoError)
throw new AudioContextException("Alc Error occured when querying available playback devices. " + playback_err.ToString());
// Get a list of all known recording devices, at least ALC_ENUMERATION_EXT is needed too
if (version == AlcVersion.Alc1_1 && Alc.IsExtensionPresent(IntPtr.Zero, "ALC_EXT_CAPTURE"))
{
available_recording_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.CaptureDeviceSpecifier));
default_recording_device = Alc.GetString(IntPtr.Zero, AlcGetString.CaptureDefaultDeviceSpecifier);
}
else
{
Debug.Print("Capture extension not available. Failed to enumerate recording devices.");
}
AlcError record_err = Alc.GetError(dummy_device);
if (record_err != AlcError.NoError)
throw new AudioContextException("Alc Error occured when querying available recording devices. " + record_err.ToString());
#if DEBUG
Debug.WriteLine("Found playback devices:");
foreach (string s in available_playback_devices)
Debug.WriteLine(s);
Debug.WriteLine("Default playback device: " + default_playback_device);
Debug.WriteLine("Found recording devices:");
foreach (string s in available_recording_devices)
Debug.WriteLine(s);
Debug.WriteLine("Default recording device: " + default_recording_device);
#endif
}
catch (DllNotFoundException e)
{
Trace.WriteLine(e.ToString());
openal_supported = false;
}
catch (AudioContextException ace)
{
Trace.WriteLine(ace.ToString());
openal_supported = false;
}
finally
{
Debug.Unindent();
// clean up the dummy context
Alc.MakeContextCurrent(ContextHandle.Zero);
if (dummy_context != ContextHandle.Zero && dummy_context.Handle != IntPtr.Zero)
Alc.DestroyContext(dummy_context);
if (dummy_device != IntPtr.Zero)
Alc.CloseDevice(dummy_device);
}
}
#endregion
}
}

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

@ -0,0 +1,85 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 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.Collections.Generic;
using System.Text;
using OpenTK.Audio.OpenAL;
namespace OpenTK.Audio
{
struct AudioDeviceErrorChecker : IDisposable
{
#region Fields
readonly IntPtr Device;
static readonly string ErrorString = "Device {0} reported {1}.";
#endregion
#region Constructors
public AudioDeviceErrorChecker(IntPtr device)
{
if (device == IntPtr.Zero)
throw new AudioDeviceException();
Device = device;
}
#endregion
#region IDisposable Members
public void Dispose()
{
AlcError err = Alc.GetError(Device);
switch (err)
{
case AlcError.OutOfMemory:
throw new OutOfMemoryException(String.Format(ErrorString, Device, err));
case AlcError.InvalidValue:
throw new AudioValueException(String.Format(ErrorString, Device, err));
case AlcError.InvalidDevice:
throw new AudioDeviceException(String.Format(ErrorString, Device, err));
case AlcError.InvalidContext:
throw new AudioContextException(String.Format(ErrorString, Device, err));
case AlcError.NoError:
default:
// everything went fine, do nothing
break;
}
}
#endregion
}
}

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

@ -0,0 +1,44 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 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.Collections.Generic;
using System.Text;
namespace OpenTK.Audio
{
/// <summary>Represents exceptions related to an OpenTK.Audio device.</summary>
public class AudioDeviceException : AudioException
{
/// <summary>Constructs a new AudioDeviceException.</summary>
public AudioDeviceException() : base() { }
/// <summary>Constructs a new AudioDeviceException with the specified error message.</summary>
/// <param name="message">The error message of the AudioDeviceException.</param>
public AudioDeviceException(string message) : base(message) { }
}
}

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

@ -0,0 +1,44 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 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.Collections.Generic;
using System.Text;
namespace OpenTK.Audio
{
/// <summary>Represents exceptions related to the OpenTK.Audio subsystem.</summary>
public class AudioException : Exception
{
/// <summary>Constructs a new AudioException.</summary>
public AudioException() : base() { }
/// <summary>Constructs a new AudioException with the specified error message.</summary>
/// <param name="message">The error message of the AudioException.</param>
public AudioException(string message) : base(message) { }
}
}

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

@ -0,0 +1,43 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 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.Collections.Generic;
using System.Text;
namespace OpenTK.Audio
{
/// <summary>Represents exceptions related to invalid values.</summary>
public class AudioValueException : AudioException
{
/// <summary>Constructs a new instance.</summary>
public AudioValueException() : base() { }
/// <summary>Constructs a new instance with the specified error message.</summary>
/// <param name="message">The error message of the AudioContextException.</param>
public AudioValueException(string message) : base(message) { }
}
}

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

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

@ -0,0 +1,431 @@
#region --- OpenTK.OpenAL License ---
/* AlTokens.cs
* C header: \OpenAL 1.1 SDK\include\Al.h
* Spec: http://www.openal.org/openal_webstf/specs/OpenAL11Specification.pdf
* Copyright (c) 2008 Christoph Brandtner and Stefanos Apostolopoulos
* See license.txt for license details
* http://www.OpenTK.net */
#endregion
using System;
namespace OpenTK.Audio.OpenAL
{
///<summary>A list of valid Enable/Disable/IsEnabled parameters</summary>
public enum ALCapability : int
{
///<summary>Currently no state toggles exist for vanilla OpenAL and no Extension uses it.</summary>
Invalid = -1,
}
///<summary>A list of valid 32-bit Float Listener/GetListener parameters</summary>
public enum ALListenerf : int
{
///<summary>Indicate the gain (Volume amplification) applied. Type: float Range: [0.0f - ? ] A value of 1.0 means un-attenuated/unchanged. Each division by 2 equals an attenuation of -6dB. Each multiplicaton with 2 equals an amplification of +6dB. A value of 0.0f is interpreted as zero volume and the channel is effectively disabled.</summary>
Gain = 0x100A,
///<summary>(EFX Extension) This setting is critical if Air Absorption effects are enabled because the amount of Air Absorption applied is directly related to the real-world distance between the Source and the Listener. centimeters 0.01f meters 1.0f kilometers 1000.0f Range [float.MinValue .. float.MaxValue] Default: 1.0f</summary>
EfxMetersPerUnit = 0x20004,
}
///<summary>A list of valid Math.Vector3 Listener/GetListener parameters</summary>
public enum ALListener3f : int
{
///<summary>Specify the current location in three dimensional space. OpenAL, like OpenGL, uses a right handed coordinate system, where in a frontal default view X (thumb) points right, Y points up (index finger), and Z points towards the viewer/camera (middle finger). To switch from a left handed coordinate system, flip the sign on the Z coordinate. Listener position is always in the world coordinate system.</summary>
Position = 0x1004,
///<summary>Specify the current velocity in three dimensional space.</summary>
Velocity = 0x1006,
}
///<summary>A list of valid float[] Listener/GetListener parameters</summary>
public enum ALListenerfv : int
{
///<summary>Indicate Listener orientation. Expects two Vector3, At followed by Up.</summary>
Orientation = 0x100F,
}
///<summary>A list of valid 32-bit Float Source/GetSource parameters</summary>
public enum ALSourcef : int
{
///<summary>Source specific reference distance. Type: float Range: [0.0f - float.PositiveInfinity] At 0.0f, no distance attenuation occurs. Type: float Default: 1.0f.</summary>
ReferenceDistance = 0x1020,
///<summary>Indicate distance above which Sources are not attenuated using the inverse clamped distance model. Default: float.PositiveInfinity Type: float Range: [0.0f - float.PositiveInfinity]</summary>
MaxDistance = 0x1023,
///<summary>Source specific rolloff factor. Type: float Range: [0.0f - float.PositiveInfinity]</summary>
RolloffFactor = 0x1021,
///<summary>Specify the pitch to be applied, either at Source, or on mixer results, at Listener. Range: [0.5f - 2.0f] Default: 1.0f</summary>
Pitch = 0x1003,
///<summary>Indicate the gain (volume amplification) applied. Type: float. Range: [0.0f - ? ] A value of 1.0 means un-attenuated/unchanged. Each division by 2 equals an attenuation of -6dB. Each multiplicaton with 2 equals an amplification of +6dB. A value of 0.0f is meaningless with respect to a logarithmic scale; it is interpreted as zero volume - the channel is effectively disabled.</summary>
Gain = 0x100A,
///<summary>Indicate minimum Source attenuation. Type: float Range: [0.0f - 1.0f] (Logarthmic)</summary>
MinGain = 0x100D,
///<summary>Indicate maximum Source attenuation. Type: float Range: [0.0f - 1.0f] (Logarthmic)</summary>
MaxGain = 0x100E,
///<summary>Directional Source, inner cone angle, in degrees. Range: [0-360] Default: 360</summary>
ConeInnerAngle = 0x1001,
///<summary>Directional Source, outer cone angle, in degrees. Range: [0-360] Default: 360</summary>
ConeOuterAngle = 0x1002,
///<summary>Directional Source, outer cone gain. Default: 0.0f Range: [0.0f - 1.0] (Logarithmic)</summary>
ConeOuterGain = 0x1022,
/// <summary>The playback position, expressed in seconds.</summary>
SecOffset = 0x1024, // AL_EXT_OFFSET extension.
///<summary>(EFX Extension) This property is a multiplier on the amount of Air Absorption applied to the Source. The AL_AIR_ABSORPTION_FACTOR is multiplied by an internal Air Absorption Gain HF value of 0.994 (-0.05dB) per meter which represents normal atmospheric humidity and temperature. Range [0.0f .. 10.0f] Default: 0.0f</summary>
EfxAirAbsorptionFactor = 0x20007,
///<summary>(EFX Extension) This property is defined the same way as the Reverb Room Rolloff property: it is one of two methods available in the Effect Extension to attenuate the reflected sound (early reflections and reverberation) according to source-listener distance. Range [0.0f .. 10.0f] Default: 0.0f</summary>
EfxRoomRolloffFactor = 0x20008,
///<summary>(EFX Extension) A directed Source points in a specified direction. The Source sounds at full volume when the listener is directly in front of the source; it is attenuated as the listener circles the Source away from the front. Range [0.0f .. 1.0f] Default: 1.0f</summary>
EfxConeOuterGainHighFrequency = 0x20009,
}
///<summary>A list of valid Math.Vector3 Source/GetSource parameters</summary>
public enum ALSource3f : int
{
///<summary>Specify the current location in three dimensional space. OpenAL, like OpenGL, uses a right handed coordinate system, where in a frontal default view X (thumb) points right, Y points up (index finger), and Z points towards the viewer/camera (middle finger). To switch from a left handed coordinate system, flip the sign on the Z coordinate. Listener position is always in the world coordinate system.</summary>
Position = 0x1004,
///<summary>Specify the current velocity in three dimensional space.</summary>
Velocity = 0x1006,
///<summary>Specify the current direction vector.</summary>
Direction = 0x1005,
}
///<summary>A list of valid 8-bit boolean Source/GetSource parameters</summary>
public enum ALSourceb : int
{
///<summary>Indicate that the Source has relative coordinates. Type: bool Range: [True, False]</summary>
SourceRelative = 0x202,
///<summary>Indicate whether the Source is looping. Type: bool Range: [True, False] Default: False.</summary>
Looping = 0x1007,
///<summary>(EFX Extension) If this Source property is set to True, this Sources direct-path is automatically filtered according to the orientation of the source relative to the listener and the setting of the Source property Sourcef.ConeOuterGainHF. Type: bool Range [False, True] Default: True</summary>
EfxDirectFilterGainHighFrequencyAuto = 0x2000A,
///<summary>(EFX Extension) If this Source property is set to True, the intensity of this Sources reflected sound is automatically attenuated according to source-listener distance and source directivity (as determined by the cone parameters). If it is False, the reflected sound is not attenuated according to distance and directivity. Type: bool Range [False, True] Default: True</summary>
EfxAuxiliarySendFilterGainAuto = 0x2000B,
///<summary>(EFX Extension) If this Source property is AL_TRUE (its default value), the intensity of this Sources reflected sound at high frequencies will be automatically attenuated according to the high-frequency source directivity as set by the Sourcef.ConeOuterGainHF property. If this property is AL_FALSE, the Sources reflected sound is not filtered at all according to the Sources directivity. Type: bool Range [False, True] Default: True</summary>
EfxAuxiliarySendFilterGainHighFrequencyAuto = 0x2000C,
}
///<summary>A list of valid Int32 Source parameters</summary>
public enum ALSourcei : int
{
///<summary>The playback position, expressed in bytes.</summary>
ByteOffset = 0x1026, // AL_EXT_OFFSET extension.
///<summary>The playback position, expressed in samples.</summary>
SampleOffset = 0x1025, // AL_EXT_OFFSET extension.
///<summary>Indicate the Buffer to provide sound samples. Type: uint Range: any valid Buffer Handle.</summary>
Buffer = 0x1009,
///<summary>Source type (Static, Streaming or undetermined). Use enum AlSourceType for comparison</summary>
SourceType = 0x1027,
///<summary>(EFX Extension) This Source property is used to apply filtering on the direct-path (dry signal) of a Source.</summary>
EfxDirectFilter = 0x20005,
}
///<summary>A list of valid 3x Int32 Source/GetSource parameters</summary>
public enum ALSource3i : int
{
///<summary>(EFX Extension) This Source property is used to establish connections between Sources and Auxiliary Effect Slots. For a Source to feed an Effect that has been loaded into an Auxiliary Effect Slot the application must configure one of the Sources auxiliary sends. This process involves setting 3 variables – the destination Auxiliary Effect Slot ID, the Auxiliary Send number, and an optional Filter ID. Type: uint Range: any valid Filter Handle.</summary>
EfxAuxiliarySendFilter = 0x20006,
}
///<summary>A list of valid Int32 GetSource parameters</summary>
public enum ALGetSourcei : int
{
///<summary>The playback position, expressed in bytes. AL_EXT_OFFSET Extension.</summary>
ByteOffset = 0x1026,
///<summary>The playback position, expressed in samples. AL_EXT_OFFSET Extension.</summary>
SampleOffset = 0x1025,
///<summary>Indicate the Buffer to provide sound samples. Type: uint Range: any valid Buffer Handle.</summary>
Buffer = 0x1009,
/// <summary>The state of the source (Stopped, Playing, etc.) Use the enum AlSourceState for comparison.</summary>
SourceState = 0x1010,
/// <summary>The number of buffers queued on this source.</summary>
BuffersQueued = 0x1015,
/// <summary>The number of buffers in the queue that have been processed.</summary>
BuffersProcessed = 0x1016,
///<summary>Source type (Static, Streaming or undetermined). Use enum AlSourceType for comparison.</summary>
SourceType = 0x1027,
}
/*
public enum ALDeprecated : int
{
///<summary>Deprecated. Specify the channel mask. (Creative) Type: uint Range: [0 - 255]</summary>
ChannelMask = 0x3000,
}
*/
///<summary>Source state information, can be retrieved by AL.Source() with ALSourcei.SourceState.</summary>
public enum ALSourceState : int
{
///<summary>Default State when loaded, can be manually set with AL.SourceRewind().</summary>
Initial = 0x1011,
///<summary>The source is currently playing.</summary>
Playing = 0x1012,
///<summary>The source has paused playback.</summary>
Paused = 0x1013,
///<summary>The source is not playing.</summary>
Stopped = 0x1014,
}
///<summary>Source type information, can be retrieved by AL.Source() with ALSourcei.SourceType.</summary>
public enum ALSourceType : int
{
///<summary>Source is Static if a Buffer has been attached using AL.Source with the parameter Sourcei.Buffer.</summary>
Static = 0x1028,
///<summary>Source is Streaming if one or more Buffers have been attached using AL.SourceQueueBuffers</summary>
Streaming = 0x1029,
///<summary>Source is undetermined when it has a null Buffer attached</summary>
Undetermined = 0x1030,
}
///<summary>Sound samples: Format specifier.</summary>
public enum ALFormat : int
{
///<summary>1 Channel, 8 bits per sample.</summary>
Mono8 = 0x1100,
///<summary>1 Channel, 16 bits per sample.</summary>
Mono16 = 0x1101,
///<summary>2 Channels, 8 bits per sample each.</summary>
Stereo8 = 0x1102,
///<summary>2 Channels, 16 bits per sample each.</summary>
Stereo16 = 0x1103,
/// <summary>1 Channel, A-law encoded data. Requires Extension: AL_EXT_ALAW</summary>
MonoALawExt = 0x10016,
/// <summary>2 Channels, A-law encoded data. Requires Extension: AL_EXT_ALAW</summary>
StereoALawExt = 0x10017,
/// <summary>1 Channel, µ-law encoded data. Requires Extension: AL_EXT_MULAW</summary>
MonoMuLawExt = 0x10014,
/// <summary>2 Channels, µ-law encoded data. Requires Extension: AL_EXT_MULAW</summary>
StereoMuLawExt = 0x10015,
/// <summary>Ogg Vorbis encoded data. Requires Extension: AL_EXT_vorbis</summary>
VorbisExt = 0x10003,
/// <summary>MP3 encoded data. Requires Extension: AL_EXT_mp3</summary>
Mp3Ext = 0x10020,
/// <summary>1 Channel, IMA4 ADPCM encoded data. Requires Extension: AL_EXT_IMA4</summary>
MonoIma4Ext = 0x1300,
/// <summary>2 Channels, IMA4 ADPCM encoded data. Requires Extension: AL_EXT_IMA4</summary>
StereoIma4Ext = 0x1301,
/// <summary>1 Channel, single-precision floating-point data. Requires Extension: AL_EXT_float32</summary>
MonoFloat32Ext = 0x10010,
/// <summary>2 Channels, single-precision floating-point data. Requires Extension: AL_EXT_float32</summary>
StereoFloat32Ext = 0x10011,
/// <summary>1 Channel, double-precision floating-point data. Requires Extension: AL_EXT_double</summary>
MonoDoubleExt = 0x10012,
/// <summary>2 Channels, double-precision floating-point data. Requires Extension: AL_EXT_double</summary>
StereoDoubleExt = 0x10013,
/// <summary>Multichannel 5.1, 16-bit data. Requires Extension: AL_EXT_MCFORMATS</summary>
Multi51Chn16Ext = 0x120B,
/// <summary>Multichannel 5.1, 32-bit data. Requires Extension: AL_EXT_MCFORMATS</summary>
Multi51Chn32Ext = 0x120C,
/// <summary>Multichannel 5.1, 8-bit data. Requires Extension: AL_EXT_MCFORMATS</summary>
Multi51Chn8Ext = 0x120A,
/// <summary>Multichannel 6.1, 16-bit data. Requires Extension: AL_EXT_MCFORMATS</summary>
Multi61Chn16Ext = 0x120E,
/// <summary>Multichannel 6.1, 32-bit data. Requires Extension: AL_EXT_MCFORMATS</summary>
Multi61Chn32Ext = 0x120F,
/// <summary>Multichannel 6.1, 8-bit data. Requires Extension: AL_EXT_MCFORMATS</summary>
Multi61Chn8Ext = 0x120D,
/// <summary>Multichannel 7.1, 16-bit data. Requires Extension: AL_EXT_MCFORMATS</summary>
Multi71Chn16Ext = 0x1211,
/// <summary>Multichannel 7.1, 32-bit data. Requires Extension: AL_EXT_MCFORMATS</summary>
Multi71Chn32Ext = 0x1212,
/// <summary>Multichannel 7.1, 8-bit data. Requires Extension: AL_EXT_MCFORMATS</summary>
Multi71Chn8Ext = 0x1210,
/// <summary>Multichannel 4.0, 16-bit data. Requires Extension: AL_EXT_MCFORMATS</summary>
MultiQuad16Ext = 0x1205,
/// <summary>Multichannel 4.0, 32-bit data. Requires Extension: AL_EXT_MCFORMATS</summary>
MultiQuad32Ext = 0x1206,
/// <summary>Multichannel 4.0, 8-bit data. Requires Extension: AL_EXT_MCFORMATS</summary>
MultiQuad8Ext = 0x1204,
/// <summary>1 Channel rear speaker, 16-bit data. See Quadrophonic setups. Requires Extension: AL_EXT_MCFORMATS</summary>
MultiRear16Ext = 0x1208,
/// <summary>1 Channel rear speaker, 32-bit data. See Quadrophonic setups. Requires Extension: AL_EXT_MCFORMATS</summary>
MultiRear32Ext = 0x1209,
/// <summary>1 Channel rear speaker, 8-bit data. See Quadrophonic setups. Requires Extension: AL_EXT_MCFORMATS</summary>
MultiRear8Ext = 0x1207,
}
///<summary>A list of valid Int32 GetBuffer parameters</summary>
public enum ALGetBufferi : int
{
///<summary>Sound sample's frequency, in units of hertz [Hz]. This is the number of samples per second. Half of the sample frequency marks the maximum significant frequency component.</summary>
Frequency = 0x2001,
/// <summary>Bit depth of the buffer. Should be 8 or 16.</summary>
Bits = 0x2002,
/// <summary>Number of channels in buffer. > 1 is valid, but buffer wont be positioned when played. 1 for Mono, 2 for Stereo.</summary>
Channels = 0x2003,
/// <summary>size of the Buffer in bytes.</summary>
Size = 0x2004,
// Deprecated: From Manual, not in header: AL_DATA ( i, iv ) original location where buffer was copied from generally useless, as was probably freed after buffer creation
}
///<summary>Buffer state. Not supported for public use (yet).</summary>
public enum ALBufferState : int
{
///<summary>Buffer state. Not supported for public use (yet).</summary>
Unused = 0x2010,
///<summary>Buffer state. Not supported for public use (yet).</summary>
Pending = 0x2011,
///<summary>Buffer state. Not supported for public use (yet).</summary>
Processed = 0x2012,
}
/// <summary>Returned by AL.GetError</summary>
public enum ALError : int
{
///<summary>No OpenAL Error.</summary>
NoError = 0,
///<summary>Invalid Name paramater passed to OpenAL call.</summary>
InvalidName = 0xA001,
///<summary>Invalid parameter passed to OpenAL call.</summary>
IllegalEnum = 0xA002,
///<summary>Invalid parameter passed to OpenAL call.</summary>
InvalidEnum = 0xA002,
///<summary>Invalid OpenAL enum parameter value.</summary>
InvalidValue = 0xA003,
///<summary>Illegal OpenAL call.</summary>
IllegalCommand = 0xA004,
///<summary>Illegal OpenAL call.</summary>
InvalidOperation = 0xA004,
///<summary>No OpenAL memory left.</summary>
OutOfMemory = 0xA005,
}
///<summary>A list of valid string AL.Get() parameters</summary>
public enum ALGetString : int
{
/// <summary>Gets the Vendor name.</summary>
Vendor = 0xB001,
/// <summary>Gets the driver version.</summary>
Version = 0xB002,
/// <summary>Gets the renderer mode.</summary>
Renderer = 0xB003,
/// <summary>Gets a list of all available Extensions, separated with spaces.</summary>
Extensions = 0xB004,
}
///<summary>A list of valid 32-bit Float AL.Get() parameters</summary>
public enum ALGetFloat : int
{
///<summary>Doppler scale. Default 1.0f</summary>
DopplerFactor = 0xC000,
///<summary>Tweaks speed of propagation. This functionality is deprecated.</summary>
DopplerVelocity = 0xC001,
///<summary>Speed of Sound in units per second. Default: 343.3f</summary>
SpeedOfSound = 0xC003,
}
///<summary>A list of valid Int32 AL.Get() parameters</summary>
public enum ALGetInteger : int
{
///<summary>See enum ALDistanceModel.</summary><see cref="ALDistanceModel"/>
DistanceModel = 0xD000,
}
/// <summary>Used by AL.DistanceModel(), the distance model can be retrieved by AL.Get() with ALGetInteger.DistanceModel</summary>
public enum ALDistanceModel : int
{
///<summary>Bypasses all distance attenuation calculation for all Sources.</summary>
None = 0,
///<summary>InverseDistance is equivalent to the IASIG I3DL2 model with the exception that ALSourcef.ReferenceDistance does not imply any clamping.</summary>
InverseDistance = 0xD001,
///<summary>InverseDistanceClamped is the IASIG I3DL2 model, with ALSourcef.ReferenceDistance indicating both the reference distance and the distance below which gain will be clamped.</summary>
InverseDistanceClamped = 0xD002,
///<summary>AL_EXT_LINEAR_DISTANCE extension.</summary>
LinearDistance = 0xD003,
///<summary>AL_EXT_LINEAR_DISTANCE extension.</summary>
LinearDistanceClamped = 0xD004,
///<summary>AL_EXT_EXPONENT_DISTANCE extension.</summary>
ExponentDistance = 0xD005,
///<summary>AL_EXT_EXPONENT_DISTANCE extension.</summary>
ExponentDistanceClamped = 0xD006,
}
}

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

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

@ -0,0 +1,480 @@
#region --- OpenTK.OpenAL License ---
/* EfxTokens.cs
* C headers: \OpenAL 1.1 SDK\include\ "efx.h", "efx-creative.h", "Efx-Util.h"
* Spec: Effects Extension Guide.pdf (bundled with OpenAL SDK)
* Copyright (c) 2008 Christoph Brandtner and Stefanos Apostolopoulos
* See license.txt for license details
* http://www.OpenTK.net */
#endregion
using System;
namespace OpenTK.Audio.OpenAL
{
#region Effect
///<summary>A list of valid 32-bit Float Effect/GetEffect parameters</summary>
public enum EfxEffectf : int
{
///<summary>Reverb Modal Density controls the coloration of the late reverb. Lowering the value adds more coloration to the late reverb. Range [0.0f .. 1.0f] Default: 1.0f</summary>
ReverbDensity = 0x0001,
///<summary>The Reverb Diffusion property controls the echo density in the reverberation decay. The default 1.0f provides the highest density. Reducing diffusion gives the reverberation a more "grainy" character that is especially noticeable with percussive sound sources. If you set a diffusion value of 0.0f, the later reverberation sounds like a succession of distinct echoes. Range [0.0f .. 1.0f] Default: 1.0f</summary>
ReverbDiffusion = 0x0002,
///<summary>The Reverb Gain property is the master volume control for the reflected sound - both early reflections and reverberation - that the reverb effect adds to all sound sources. Ranges from 1.0 (0db) (the maximum amount) to 0.0 (-100db) (no reflected sound at all) are accepted. Units: Linear gain Range [0.0f .. 1.0f] Default: 0.32f</summary>
ReverbGain = 0x0003,
///<summary>The Reverb Gain HF property further tweaks reflected sound by attenuating it at high frequencies. It controls a low-pass filter that applies globally to the reflected sound of all sound sources feeding the particular instance of the reverb effect. Ranges from 1.0f (0db) (no filter) to 0.0f (-100db) (virtually no reflected sound) are accepted. Units: Linear gain Range [0.0f .. 1.0f] Default: 0.89f</summary>
ReverbGainHF = 0x0004,
///<summary>The Decay Time property sets the reverberation decay time. It ranges from 0.1f (typically a small room with very dead surfaces) to 20.0 (typically a large room with very live surfaces). Unit: Seconds Range [0.1f .. 20.0f] Default: 1.49f</summary>
ReverbDecayTime = 0x0005,
///<summary>The Decay HF Ratio property sets the spectral quality of the Decay Time parameter. It is the ratio of high-frequency decay time relative to the time set by Decay Time.. Unit: linear multiplier Range [0.1f .. 2.0f] Default: 0.83f</summary>
ReverbDecayHFRatio = 0x0006,
///<summary>The Reflections Gain property controls the overall amount of initial reflections relative to the Gain property. The value of Reflections Gain ranges from a maximum of 3.16f (+10 dB) to a minimum of 0.0f (-100 dB) (no initial reflections at all), and is corrected by the value of the Gain property. Unit: Linear gain Range [0.0f .. 3.16f] Default: 0.05f</summary>
ReverbReflectionsGain = 0x0007,
///<summary>The Reflections Delay property is the amount of delay between the arrival time of the direct path from the source to the first reflection from the source. It ranges from 0 to 300 milliseconds. Unit: Seconds Range [0.0f .. 0.3f] Default: 0.007f</summary>
ReverbReflectionsDelay = 0x0008,
///<summary>The Late Reverb Gain property controls the overall amount of later reverberation relative to the Gain property. The value of Late Reverb Gain ranges from a maximum of 10.0f (+20 dB) to a minimum of 0.0f (-100 dB) (no late reverberation at all). Unit: Linear gain Range [0.0f .. 10.0f] Default: 1.26f</summary>
ReverbLateReverbGain = 0x0009,
///<summary>The Late Reverb Delay property defines the begin time of the late reverberation relative to the time of the initial reflection (the first of the early reflections). It ranges from 0 to 100 milliseconds. Unit: Seconds Range [0.0f .. 0.1f] Default: 0.011f</summary>
ReverbLateReverbDelay = 0x000A,
///<summary>The Air Absorption Gain HF property controls the distance-dependent attenuation at high frequencies caused by the propagation medium and applies to reflected sound only. Unit: Linear gain per meter Range [0.892f .. 1.0f] Default: 0.994f</summary>
ReverbAirAbsorptionGainHF = 0x000B,
///<summary>The Room Rolloff Factor property is one of two methods available to attenuate the reflected sound (containing both reflections and reverberation) according to source-listener distance. It's defined the same way as OpenAL's Rolloff Factor, but operates on reverb sound instead of direct-path sound. Unit: Linear multiplier Range [0.0f .. 10.0f] Default: 0.0f</summary>
ReverbRoomRolloffFactor = 0x000C,
///<summary>This property sets the modulation rate of the low-frequency oscillator that controls the delay time of the delayed signals. Unit: Hz Range [0.0f .. 10.0f] Default: 1.1f</summary>
ChorusRate = 0x0003,
///<summary>This property controls the amount by which the delay time is modulated by the low-frequency oscillator. Range [0.0f .. 1.0f] Default: 0.1f</summary>
ChorusDepth = 0x0004,
///<summary>This property controls the amount of processed signal that is fed back to the input of the chorus effect. Negative values will reverse the phase of the feedback signal. At full magnitude the identical sample will repeat endlessly. Range [-1.0f .. +1.0f] Default: +0.25f</summary>
ChorusFeedback = 0x0005,
///<summary>This property controls the average amount of time the sample is delayed before it is played back, and with feedback, the amount of time between iterations of the sample. Larger values lower the pitch. Unit: Seconds Range [0.0f .. 0.016f] Default: 0.016f</summary>
ChorusDelay = 0x0006,
///<summary>This property controls the shape of the distortion. The higher the value for Edge, the "dirtier" and "fuzzier" the effect. Range [0.0f .. 1.0f] Default: 0.2f</summary>
DistortionEdge = 0x0001,
///<summary>This property allows you to attenuate the distorted sound. Range [0.01f .. 1.0f] Default: 0.05f</summary>
DistortionGain = 0x0002,
///<summary>Input signals can have a low pass filter applied, to limit the amount of high frequency signal feeding into the distortion effect. Unit: Hz Range [80.0f .. 24000.0f] Default: 8000.0f</summary>
DistortionLowpassCutoff = 0x0003,
///<summary>This property controls the frequency at which the post-distortion attenuation (Distortion Gain) is active. Unit: Hz Range [80.0f .. 24000.0f] Default: 3600.0f</summary>
DistortionEQCenter = 0x0004,
///<summary>This property controls the bandwidth of the post-distortion attenuation. Unit: Hz Range [80.0f .. 24000.0f] Default: 3600.0f</summary>
DistortionEQBandwidth = 0x0005,
///<summary>This property controls the delay between the original sound and the first "tap", or echo instance. Subsequently, the value for Echo Delay is used to determine the time delay between each "second tap" and the next "first tap". Unit: Seconds Range [0.0f .. 0.207f] Default: 0.1f</summary>
EchoDelay = 0x0001,
///<summary>This property controls the delay between the "first tap" and the "second tap". Subsequently, the value for Echo LR Delay is used to determine the time delay between each "first tap" and the next "second tap". Unit: Seconds Range [0.0f .. 0.404f] Default: 0.1f</summary>
EchoLRDelay = 0x0002,
///<summary>This property controls the amount of high frequency damping applied to each echo. As the sound is subsequently fed back for further echoes, damping results in an echo which progressively gets softer in tone as well as intensity. Range [0.0f .. 0.99f] Default: 0.5f</summary>
EchoDamping = 0x0003,
///<summary>This property controls the amount of feedback the output signal fed back into the input. Use this parameter to create "cascading" echoes. At full magnitude, the identical sample will repeat endlessly. Below full magnitude, the sample will repeat and fade. Range [0.0f .. 1.0f] Default: 0.5f</summary>
EchoFeedback = 0x0004,
///<summary>This property controls how hard panned the individual echoes are. With a value of 1.0f, the first "tap" will be panned hard left, and the second "tap" hard right. –1.0f gives the opposite result and values near to 0.0f result in less emphasized panning. Range [-1.0f .. +1.0f] Default: -1.0f</summary>
EchoSpread = 0x0005,
///<summary>The number of times per second the low-frequency oscillator controlling the amount of delay repeats. Range [0.0f .. 10.0f] Default: 0.27f</summary>
FlangerRate = 0x0003,
///<summary>The ratio by which the delay time is modulated by the low-frequency oscillator. Range [0.0f .. 1.0f] Default: 1.0f</summary>
FlangerDepth = 0x0004,
///<summary>This is the amount of the output signal level fed back into the effect's input. A negative value will reverse the phase of the feedback signal. Range [-1.0f .. +1.0f] Default: -0.5f</summary>
FlangerFeedback = 0x0005,
///<summary>The average amount of time the sample is delayed before it is played back. When used with the Feedback property it's the amount of time between iterations of the sample. Unit: Seconds Range [0.0f .. 0.004f] Default: 0.002f</summary>
FlangerDelay = 0x0006,
///<summary>This is the carrier frequency. For carrier frequencies below the audible range, the single sideband modulator may produce phaser effects, spatial effects or a slight pitch-shift. As the carrier frequency increases, the timbre of the sound is affected. Unit: Hz Range [0.0f .. 24000.0f] Default: 0.0f</summary>
FrequencyShifterFrequency = 0x0001,
///<summary>This controls the frequency of the low-frequency oscillator used to morph between the two phoneme filters. Unit: Hz Range [0.0f .. 10.0f] Default: 1.41f</summary>
VocalMorpherRate = 0x0006,
///<summary>This is the frequency of the carrier signal. If the carrier signal is slowly varying (less than 20 Hz), the result is a slow amplitude variation effect (tremolo). Unit: Hz Range [0.0f .. 8000.0f] Default: 440.0f</summary>
RingModulatorFrequency = 0x0001,
///<summary>This controls the cutoff frequency at which the input signal is high-pass filtered before being ring modulated. Unit: Hz Range [0.0f .. 24000.0f] Default: 800.0f</summary>
RingModulatorHighpassCutoff = 0x0002,
///<summary>This property controls the time the filtering effect takes to sweep from minimum to maximum center frequency when it is triggered by input signal. Unit: Seconds Range [0.0001f .. 1.0f] Default: 0.06f</summary>
AutowahAttackTime = 0x0001,
///<summary>This property controls the time the filtering effect takes to sweep from maximum back to base center frequency, when the input signal ends. Unit: Seconds Range [0.0001f .. 1.0f] Default: 0.06f</summary>
AutowahReleaseTime = 0x0002,
///<summary>This property controls the resonant peak, sometimes known as emphasis or Q, of the auto-wah band-pass filter. Range [2.0f .. 1000.0f] Default: 1000.0f</summary>
AutowahResonance = 0x0003,
///<summary>This property controls the input signal level at which the band-pass filter will be fully opened. Range [0.00003f .. 31621.0f] Default: 11.22f</summary>
AutowahPeakGain = 0x0004,
///<summary>This property controls amount of cut or boost on the low frequency range. Range [0.126f .. 7.943f] Default: 1.0f</summary>
EqualizerLowGain = 0x0001,
///<summary>This property controls the low frequency below which signal will be cut off. Unit: Hz Range [50.0f .. 800.0f] Default: 200.0f</summary>
EqualizerLowCutoff = 0x0002,
///<summary>This property allows you to cut/boost signal on the "mid1" range. Range [0.126f .. 7.943f] Default: 1.0f</summary>
EqualizerMid1Gain = 0x0003,
///<summary>This property sets the center frequency for the "mid1" range. Unit: Hz Range [200.0f .. 3000.0f] Default: 500.0f</summary>
EqualizerMid1Center = 0x0004,
///<summary>This property controls the width of the "mid1" range. Range [0.01f .. 1.0f] Default: 1.0f</summary>
EqualizerMid1Width = 0x0005,
///<summary>This property allows you to cut/boost signal on the "mid2" range. Range [0.126f .. 7.943f] Default: 1.0f</summary>
EqualizerMid2Gain = 0x0006,
///<summary>This property sets the center frequency for the "mid2" range. Unit: Hz Range [1000.0f .. 8000.0f] Default: 3000.0f</summary>
EqualizerMid2Center = 0x0007,
///<summary>This property controls the width of the "mid2" range. Range [0.01f .. 1.0f] Default: 1.0f</summary>
EqualizerMid2Width = 0x0008,
///<summary>This property allows to cut/boost the signal at high frequencies. Range [0.126f .. 7.943f] Default: 1.0f</summary>
EqualizerHighGain = 0x0009,
///<summary>This property controls the high frequency above which signal will be cut off. Unit: Hz Range [4000.0f .. 16000.0f] Default: 6000.0f</summary>
EqualizerHighCutoff = 0x000A,
///<summary>Reverb Modal Density controls the coloration of the late reverb. Range [0.0f .. 1.0f] Default: 1.0f</summary>
EaxReverbDensity = 0x0001,
///<summary>The Reverb Diffusion property controls the echo density in the reverberation decay. Range [0.0f .. 1.0f] Default: 1.0f</summary>
EaxReverbDiffusion = 0x0002,
///<summary>Reverb Gain controls the level of the reverberant sound in an environment. A high level of reverb is characteristic of rooms with highly reflective walls and/or small dimensions. Unit: Linear gain Range [0.0f .. 1.0f] Default: 0.32f</summary>
EaxReverbGain = 0x0003,
///<summary>Gain HF is used to attenuate the high frequency content of all the reflected sound in an environment. You can use this property to give a room specific spectral characteristic. Unit: Linear gain Range [0.0f .. 1.0f] Default: 0.89f</summary>
EaxReverbGainHF = 0x0004,
///<summary>Gain LF is the low frequency counterpart to Gain HF. Use this to reduce or boost the low frequency content in an environment. Unit: Linear gain Range [0.0f .. 1.0f] Default: 1.0f</summary>
EaxReverbGainLF = 0x0005,
///<summary>The Decay Time property sets the reverberation decay time. It ranges from 0.1f (typically a small room with very dead surfaces) to 20.0f (typically a large room with very live surfaces). Unit: Seconds Range [0.1f .. 20.0f] Default: 1.49f</summary>
EaxReverbDecayTime = 0x0006,
///<summary>Decay HF Ratio scales the decay time of high frequencies relative to the value of the Decay Time property. By changing this value, you are changing the amount of time it takes for the high frequencies to decay compared to the mid frequencies of the reverb. Range [0.1f .. 2.0f] Default: 0.83f</summary>
EaxReverbDecayHFRatio = 0x0007,
///<summary>Decay LF Ratio scales the decay time of low frequencies in the reverberation in the same manner that Decay HF Ratio handles high frequencies. Unit: Linear multiplier Range [0.1f .. 2.0f] Default: 1.0f</summary>
EaxReverbDecayLFRatio = 0x0008,
///<summary>Reflections Gain sets the level of the early reflections in an environment. Early reflections are used as a cue for determining the size of the environment we are in. Unit: Linear gain Range [0.0f .. 3.16f] Default: 0.05f</summary>
EaxReverbReflectionsGain = 0x0009,
///<summary>Reflections Delay controls the amount of time it takes for the first reflected wave front to reach the listener, relative to the arrival of the direct-path sound. Unit: Seconds Range [0.0f .. 0.3f] Default: 0.007f</summary>
EaxReverbReflectionsDelay = 0x000A,
///<summary>The Late Reverb Gain property controls the overall amount of later reverberation relative to the Gain property. Range [0.0f .. 10.0f] Default: 1.26f</summary>
EaxReverbLateReverbGain = 0x000C,
///<summary>The Late Reverb Delay property defines the begin time of the late reverberation relative to the time of the initial reflection (the first of the early reflections). It ranges from 0 to 100 milliseconds. Unit: Seconds Range [0.0f .. 0.1f] Default: 0.011f</summary>
EaxReverbLateReverbDelay = 0x000D,
///<summary>Echo Time controls the rate at which the cyclic echo repeats itself along the reverberation decay. Range [0.075f .. 0.25f] Default: 0.25f</summary>
EaxReverbEchoTime = 0x000F,
///<summary>Echo Depth introduces a cyclic echo in the reverberation decay, which will be noticeable with transient or percussive sounds. Range [0.0f .. 1.0f] Default: 0.0f</summary>
EaxReverbEchoDepth = 0x0010,
///<summary>Modulation Time controls the speed of the rate of periodic changes in pitch (vibrato). Range [0.04f .. 4.0f] Default: 0.25f</summary>
EaxReverbModulationTime = 0x0011,
///<summary>Modulation Depth controls the amount of pitch change. Low values of Diffusion will contribute to reinforcing the perceived effect by reducing the mixing of overlapping reflections in the reverberation decay. Range [0.0f .. 1.0f] Default: 0.0f</summary>
EaxReverbModulationDepth = 0x0012,
///<summary>The Air Absorption Gain HF property controls the distance-dependent attenuation at high frequencies caused by the propagation medium. It applies to reflected sound only. Range [0.892f .. 1.0f] Default: 0.994f</summary>
EaxReverbAirAbsorptionGainHF = 0x0013,
///<summary>The property HF reference determines the frequency at which the high-frequency effects created by Reverb properties are measured. Unit: Hz Range [1000.0f .. 20000.0f] Default: 5000.0f</summary>
EaxReverbHFReference = 0x0014,
///<summary>The property LF reference determines the frequency at which the low-frequency effects created by Reverb properties are measured. Unit: Hz Range [20.0f .. 1000.0f] Default: 250.0f</summary>
EaxReverbLFReference = 0x0015,
///<summary>The Room Rolloff Factor property is one of two methods available to attenuate the reflected sound (containing both reflections and reverberation) according to source-listener distance. It's defined the same way as OpenAL Rolloff Factor, but operates on reverb sound instead of direct-path sound. Range [0.0f .. 10.0f] Default: 0.0f</summary>
EaxReverbRoomRolloffFactor = 0x0016,
}
///<summary>A list of valid Math.Vector3 Effect/GetEffect parameters</summary>
public enum EfxEffect3f : int
{
/// <summary>Reverb Pan does for the Reverb what Reflections Pan does for the Reflections. Unit: Vector3 of length 0f to 1f Default: {0.0f, 0.0f, 0.0f}</summary>
EaxReverbLateReverbPan = 0x000E,
/// <summary>This Vector3 controls the spatial distribution of the cluster of early reflections. The direction of this vector controls the global direction of the reflections, while its magnitude controls how focused the reflections are towards this direction. For legacy reasons this Vector3 follows a left-handed co-ordinate system! Note that OpenAL uses a right-handed coordinate system. Unit: Vector3 of length 0f to 1f Default: {0.0f, 0.0f, 0.0f}</summary>
EaxReverbReflectionsPan = 0x000B,
}
///<summary>A list of valid Int32 Effect/GetEffect parameters</summary>
public enum EfxEffecti : int
{
///<summary>This property sets the waveform shape of the low-frequency oscillator that controls the delay time of the delayed signals. Unit: (0) Sinusoid, (1) Triangle Range [0 .. 1] Default: 1</summary>
ChorusWaveform = 0x0001,
///<summary>This property controls the phase difference between the left and right low-frequency oscillators. At zero degrees the two low-frequency oscillators are synchronized. Unit: Degrees Range [-180 .. 180] Default: 90</summary>
ChorusPhase = 0x0002,
///<summary>Selects the shape of the low-frequency oscillator waveform that controls the amount of the delay of the sampled signal. Unit: (0) Sinusoid, (1) Triangle Range [0 .. 1] Default: 1</summary>
FlangerWaveform = 0x0001,
///<summary>This changes the phase difference between the left and right low-frequency oscillator's. At zero degrees the two low-frequency oscillators are synchronized. Range [-180 .. +180] Default: 0</summary>
FlangerPhase = 0x0002,
///<summary>These select which internal signals are added together to produce the output. Unit: (0) Down, (1) Up, (2) Off Range [0 .. 2] Default: 0</summary>
FrequencyShifterLeftDirection = 0x0002,
///<summary>These select which internal signals are added together to produce the output. Unit: (0) Down, (1) Up, (2) Off Range [0 .. 2] Default: 0</summary>
FrequencyShifterRightDirection = 0x0003,
///<summary>Sets the vocal morpher 4-band formant filter A, used to impose vocal tract effects upon the input signal. The vocal morpher is not necessarily intended for use on voice signals; it is primarily intended for pitched noise effects, vocal-like wind effects, etc. Unit: Use enum EfxFormantFilterSettings Range [0 .. 29] Default: 0, "Phoneme A"</summary>
VocalMorpherPhonemeA = 0x0001,
///<summary>This is used to adjust the pitch of phoneme filter A in 1-semitone increments. Unit: Semitones Range [-24 .. +24] Default: 0</summary>
VocalMorpherPhonemeACoarseTuning = 0x0002,
///<summary>Sets the vocal morpher 4-band formant filter B, used to impose vocal tract effects upon the input signal. The vocal morpher is not necessarily intended for use on voice signals; it is primarily intended for pitched noise effects, vocal-like wind effects, etc. Unit: Use enum EfxFormantFilterSettings Range [0 .. 29] Default: 10, "Phoneme ER"</summary>
VocalMorpherPhonemeB = 0x0003,
///<summary>This is used to adjust the pitch of phoneme filter B in 1-semitone increments. Unit: Semitones Range [-24 .. +24] Default: 0</summary>
VocalMorpherPhonemeBCoarseTuning = 0x0004,
///<summary>This controls the shape of the low-frequency oscillator used to morph between the two phoneme filters. Unit: (0) Sinusoid, (1) Triangle, (2) Sawtooth Range [0 .. 2] Default: 0</summary>
VocalMorpherWaveform = 0x0005,
///<summary>This sets the number of semitones by which the pitch is shifted. There are 12 semitones per octave. Unit: Semitones Range [-12 .. +12] Default: +12</summary>
PitchShifterCoarseTune = 0x0001,
///<summary>This sets the number of cents between Semitones a pitch is shifted. A Cent is 1/100th of a Semitone. Unit: Cents Range [-50 .. +50] Default: 0</summary>
PitchShifterFineTune = 0x0002,
///<summary>This controls which waveform is used as the carrier signal. Traditional ring modulator and tremolo effects generally use a sinusoidal carrier. Unit: (0) Sinusoid, (1) Sawtooth, (2) Square Range [0 .. 2] Default: 0</summary>
RingModulatorWaveform = 0x0003,
///<summary>Enabling this will result in audio exhibiting smaller variation in intensity between the loudest and quietest portions. Unit: (0) Off, (1) On Range [0 .. 1] Default: 1</summary>
CompressorOnoff = 0x0001,
///<summary>When this flag is set, the high-frequency decay time automatically stays below a limit value that's derived from the setting of the property Air Absorption HF. Unit: (0) False, (1) True Range [False, True] Default: True</summary>
ReverbDecayHFLimit = 0x000D,
///<summary>When this flag is set, the high-frequency decay time automatically stays below a limit value that's derived from the setting of the property AirAbsorptionGainHF. Unit: (0) False, (1) True Range [False, True] Default: True</summary>
EaxReverbDecayHFLimit = 0x0017,
/// <summary>Used with the enum EfxEffectType as it's parameter.</summary>
EffectType = 0x8001,
}
///<summary>Vocal morpher effect parameters. If both parameters are set to the same phoneme, that determines the filtering effect that will be heard. If these two parameters are set to different phonemes, the filtering effect will morph between the two settings at a rate specified by EfxEffectf.VocalMorpherRate.</summary>
public enum EfxFormantFilterSettings : int
{
/// <summary>
/// The A phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeA = 0,
/// <summary>
/// The E phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeE = 1,
/// <summary>
/// The I phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeI = 2,
/// <summary>
/// The O phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeO = 3,
/// <summary>
/// The U phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeU = 4,
/// <summary>
/// The AA phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeAA = 5,
/// <summary>
/// The AE phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeAE = 6,
/// <summary>
/// The AH phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeAH = 7,
/// <summary>
/// The AO phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeAO = 8,
/// <summary>
/// The EH phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeEH = 9,
/// <summary>
/// The ER phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeER = 10,
/// <summary>
/// The IH phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeIH = 11,
/// <summary>
/// The IY phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeIY = 12,
/// <summary>
/// The UH phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeUH = 13,
/// <summary>
/// The UW phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeUW = 14,
/// <summary>
/// The B phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeB = 15,
/// <summary>
/// The D phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeD = 16,
/// <summary>
/// The F phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeF = 17,
/// <summary>
/// The G phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeG = 18,
/// <summary>
/// The J phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeJ = 19,
/// <summary>
/// The K phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeK = 20,
/// <summary>
/// The L phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeL = 21,
/// <summary>
/// The M phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeM = 22,
/// <summary>
/// The N phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeN = 23,
/// <summary>
/// The P phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeP = 24,
/// <summary>
/// The R phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeR = 25,
/// <summary>
/// The S phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeS = 26,
/// <summary>
/// The T phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeT = 27,
/// <summary>
/// The V phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeV = 28,
/// <summary>
/// The Z phoneme of the vocal morpher.
/// </summary>
VocalMorpherPhonemeZ = 29,
}
///<summary>Effect type definitions to be used with EfxEffecti.EffectType.</summary>
public enum EfxEffectType : int
{
///<summary>No Effect, disable. This Effect type is used when an Effect object is initially created.</summary>
Null = 0x0000,
///<summary>The Reverb effect is the standard Effects Extension's environmental reverberation effect. It is available on all Generic Software and Generic Hardware devices.</summary>
Reverb = 0x0001,
///<summary>The Chorus effect essentially replays the input audio accompanied by another slightly delayed version of the signal, creating a "doubling" effect.</summary>
Chorus = 0x0002,
///<summary>The Distortion effect simulates turning up (overdriving) the gain stage on a guitar amplifier or adding a distortion pedal to an instrument's output.</summary>
Distortion = 0x0003,
///<summary>The Echo effect generates discrete, delayed instances of the input signal.</summary>
Echo = 0x0004,
///<summary>The Flanger effect creates a "tearing" or "whooshing" sound, like a jet flying overhead.</summary>
Flanger = 0x0005,
///<summary>The Frequency shifter is a single-sideband modulator, which translates all the component frequencies of the input signal by an equal amount.</summary>
FrequencyShifter = 0x0006,
///<summary>The Vocal morpher consists of a pair of 4-band formant filters, used to impose vocal tract effects upon the input signal.</summary>
VocalMorpher = 0x0007,
///<summary>The Pitch shifter applies time-invariant pitch shifting to the input signal, over a one octave range and controllable at a semi-tone and cent resolution.</summary>
PitchShifter = 0x0008,
///<summary>The Ring modulator multiplies an input signal by a carrier signal in the time domain, resulting in tremolo or inharmonic effects.</summary>
RingModulator = 0x0009,
///<summary>The Auto-wah effect emulates the sound of a wah-wah pedal used with an electric guitar, or a mute on a brass instrument.</summary>
Autowah = 0x000A,
///<summary>The Compressor will boost quieter portions of the audio, while louder portions will stay the same or may even be reduced.</summary>
Compressor = 0x000B,
///<summary>The Equalizer is very flexible, providing tonal control over four different adjustable frequency ranges.</summary>
Equalizer = 0x000C,
///<summary>The EAX Reverb has a more advanced parameter set than EfxEffectType.Reverb, but is only natively supported on devices that support the EAX 3.0 or above.</summary>
EaxReverb = 0x8000,
}
#endregion Effect
#region Auxiliary Effect Slot
///<summary>A list of valid Int32 AuxiliaryEffectSlot/GetAuxiliaryEffectSlot parameters</summary>
public enum EfxAuxiliaryi : int
{
/// <summary>This property is used to attach an Effect object to the Auxiliary Effect Slot object. After the attachment, the Auxiliary Effect Slot object will contain the effect type and have the same effect parameters that were stored in the Effect object. Any Sources feeding the Auxiliary Effect Slot will immediate feed the new effect type and new effect parameters.</summary>
EffectslotEffect = 0x0001,
/// <summary>This property is used to enable or disable automatic send adjustments based on the physical positions of the sources and the listener. This property should be enabled when an application wishes to use a reverb effect to simulate the environment surrounding a listener or a collection of Sources. Range [False, True] Default: True </summary>
EffectslotAuxiliarySendAuto = 0x0003,
}
///<summary>A list of valid 32-bits Float AuxiliaryEffectSlot/GetAuxiliaryEffectSlot parameters</summary>
public enum EfxAuxiliaryf : int
{
/// <summary>This property is used to specify an output level for the Auxiliary Effect Slot. Setting the gain to 0.0f mutes the output. Range [0.0f .. 1.0f] Default: 1.0f</summary>
EffectslotGain = 0x0002,
}
#endregion Auxiliary Effect Slot
#region Filter Object
///<summary>A list of valid 32-bits Float Filter/GetFilter parameters</summary>
public enum EfxFilterf : int
{
///<summary>Range [0.0f .. 1.0f] Default: 1.0f</summary>
LowpassGain = 0x0001,
///<summary>Range [0.0f .. 1.0f] Default: 1.0f</summary>
LowpassGainHF = 0x0002,
///<summary>Range [0.0f .. 1.0f] Default: 1.0f</summary>
HighpassGain = 0x0001,
///<summary>Range [0.0f .. 1.0f] Default: 1.0f</summary>
HighpassGainLF = 0x0002,
///<summary>Range [0.0f .. 1.0f] Default: 1.0f</summary>
BandpassGain = 0x0001,
///<summary>Range [0.0f .. 1.0f] Default: 1.0f</summary>
BandpassGainLF = 0x0002,
///<summary>Range [0.0f .. 1.0f] Default: 1.0f</summary>
BandpassGainHF = 0x0003,
}
///<summary>A list of valid Int32 Filter/GetFilter parameters</summary>
public enum EfxFilteri : int
{
/// <summary>Used with the enum EfxFilterType as Parameter to select a filter logic.</summary>
FilterType = 0x8001,
}
///<summary>Filter type definitions to be used with EfxFilteri.FilterType.</summary>
public enum EfxFilterType : int
{
///<summary>No Filter, disable. This Filter type is used when a Filter object is initially created.</summary>
Null = 0x0000,
/// <summary>A low-pass filter is used to remove high frequency content from a signal.</summary>
Lowpass = 0x0001,
///<summary>Currently not implemented. A high-pass filter is used to remove low frequency content from a signal.</summary>
Highpass = 0x0002,
///<summary>Currently not implemented. A band-pass filter is used to remove high and low frequency content from a signal.</summary>
Bandpass = 0x0003,
}
#endregion Filter Object
}

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

@ -0,0 +1,374 @@
#region --- OpenTK.OpenAL License ---
/* EfxPresets.cs
* C headers: \OpenAL 1.1 SDK\include\ "efx.h", "efx-creative.h", "Efx-Util.h"
* Spec: Effects Extension Guide.pdf (bundled with OpenAL SDK)
* Copyright (c) 2008 Christoph Brandtner and Stefanos Apostolopoulos
* See license.txt for license details
* http://www.OpenTK.net */
#endregion
using System;
// flibit Added This!!!
#pragma warning disable 3021
namespace OpenTK.Audio.OpenAL
{
public partial class EffectsExtension
{
// Todo: Add documentation
// Todo: CLS compliance.
#pragma warning disable 1591
[CLSCompliant(false)]
public struct EaxReverb
{
public uint Environment; // TODO: EAX-EFX conversion
public float EnvironmentSize; // TODO: EAX-EFX conversion
public float EnvironmentDiffusion; // TODO: EAX-EFX conversion
public int Room; // TODO: EAX-EFX conversion
public int RoomHF; // TODO: EAX-EFX conversion
public int RoomLF; // TODO: EAX-EFX conversion
public float DecayTime;
public float DecayHFRatio;
public float DecayLFRatio;
public int Reflections; // TODO: EAX-EFX conversion
public float ReflectionsDelay;
public Vector3 ReflectionsPan;
public int Reverb; // TODO: EAX-EFX conversion
public float ReverbDelay;
public Vector3 ReverbPan;
public float EchoTime;
public float EchoDepth;
public float ModulationTime;
public float ModulationDepth;
public float AirAbsorptionHF;
public float HFReference;
public float LFReference;
public float RoomRolloffFactor;
public uint Flags; // TODO: EAX-EFX conversion
public EaxReverb(uint environment,
float environmentSize,
float environmentDiffusion,
int room,
int roomHF,
int roomLF,
float decayTime,
float decayHFRatio,
float decayLFRatio,
int reflections,
float reflectionsDelay,
float reflectionsPanX,
float reflectionsPanY,
float reflectionsPanZ,
int reverb,
float reverbDelay,
float reverbPanX,
float reverbPanY,
float reverbPanZ,
float echoTime,
float echoDepth,
float modulationTime,
float modulationDepth,
float airAbsorptionHF,
float hfReference,
float lfReference,
float roomRolloffFactor,
uint flags)
{
Environment = environment;
EnvironmentSize = environmentSize;
EnvironmentDiffusion = environmentDiffusion;
Room = room;
RoomHF = roomHF;
RoomLF = roomLF;
DecayTime = decayTime;
DecayHFRatio = decayHFRatio;
DecayLFRatio = decayLFRatio;
Reflections = reflections;
ReflectionsDelay = reflectionsDelay;
ReflectionsPan = new Vector3(reflectionsPanX, reflectionsPanY, reflectionsPanZ);
Reverb = reverb;
ReverbDelay = reverbDelay;
ReverbPan = new Vector3(reverbPanX, reverbPanY, reverbPanZ);
EchoTime = echoTime;
EchoDepth = echoDepth;
ModulationTime = modulationTime;
ModulationDepth = modulationDepth;
AirAbsorptionHF = airAbsorptionHF;
HFReference = hfReference;
LFReference = lfReference;
RoomRolloffFactor = roomRolloffFactor;
Flags = flags;
}
}
// TODO: CLS compliance.
[CLSCompliant(false)]
public static void GetEaxFromEfxEax(ref EaxReverb input, out EfxEaxReverb output)
{
output.AirAbsorptionGainHF = 0.995f; // input.AirAbsorptionHF * somegain?
output.RoomRolloffFactor = input.RoomRolloffFactor;
output.Density = 1f; // todo, currently default
output.Diffusion = 1f; // todo, currently default
output.DecayTime = input.DecayTime;
output.DecayHFLimit = 1; // todo, currently default
output.DecayHFRatio = input.DecayHFRatio;
output.DecayLFRatio = input.DecayLFRatio;
output.EchoDepth = input.EchoDepth;
output.EchoTime = input.EchoTime;
output.Gain = 0.32f; // todo, currently default
output.GainHF = 0.89f; // todo, currently default
output.GainLF = 1f;// todo, currently default
output.LFReference = input.LFReference;
output.HFReference = input.HFReference;
output.LateReverbDelay = input.ReverbDelay;
output.LateReverbGain = 1.26f; // todo, currently default
output.LateReverbPan = input.ReverbPan;
output.ModulationDepth = input.ModulationDepth;
output.ModulationTime = input.ModulationTime;
output.ReflectionsDelay = input.ReflectionsDelay;
output.ReflectionsGain = 0.05f; // todo, currently default
output.ReflectionsPan = input.ReflectionsPan;
}
public struct EfxEaxReverb
{
public float Density;
public float Diffusion;
public float Gain;
public float GainHF;
public float GainLF;
public float DecayTime;
public float DecayHFRatio;
public float DecayLFRatio;
public float ReflectionsGain;
public float ReflectionsDelay;
public Vector3 ReflectionsPan;
public float LateReverbGain;
public float LateReverbDelay;
public Vector3 LateReverbPan;
public float EchoTime;
public float EchoDepth;
public float ModulationTime;
public float ModulationDepth;
public float AirAbsorptionGainHF;
public float HFReference;
public float LFReference;
public float RoomRolloffFactor;
public int DecayHFLimit;
}
/*
public struct _EAXOBSTRUCTIONPROPERTIES
{
public int lObstruction;
public float flObstructionLFRatio;
}
_EAXOBSTRUCTIONPROPERTIES EAXOBSTRUCTIONPROPERTIES;//, *LPEAXOBSTRUCTIONPROPERTIES;
public struct _EAXOCCLUSIONPROPERTIES
{
public int lOcclusion;
public float flOcclusionLFRatio;
public float flOcclusionRoomRatio;
public float flOcclusionDirectRatio;
}
_EAXOCCLUSIONPROPERTIES EAXOCCLUSIONPROPERTIES;//, *LPEAXOCCLUSIONPROPERTIES;
public struct _EAXEXCLUSIONPROPERTIES
{
public int lExclusion;
public float flExclusionLFRatio;
}
_EAXEXCLUSIONPROPERTIES EAXEXCLUSIONPROPERTIES;//, *LPEAXEXCLUSIONPROPERTIES;
public struct _EFXLOWPASSFILTER
{
public float flGain;
public float flGainHF;
}
_EFXLOWPASSFILTER EFXLOWPASSFILTER;//, *LPEFXLOWPASSFILTER;
void ConvertReverbParameters(EAXREVERBPROPERTIES *pEAXProp, EFXEAXREVERBPROPERTIES *pEFXEAXReverb);
void ConvertObstructionParameters(EAXOBSTRUCTIONPROPERTIES *pObProp, EFXLOWPASSFILTER *pDirectLowPassFilter);
void ConvertExclusionParameters(EAXEXCLUSIONPROPERTIES *pExProp, EFXLOWPASSFILTER *pSendLowPassFilter);
void ConvertOcclusionParameters(EAXOCCLUSIONPROPERTIES *pOcProp, EFXLOWPASSFILTER *pDirectLowPassFilter, EFXLOWPASSFILTER *pSendLowPassFilter);
*/
// TODO: CLS compliance.
///<summary>EAX Reverb Presets in legacy format - use ConvertReverbParameters() to convert to EFX EAX Reverb Presets for use with the OpenAL Effects Extension.</summary>
[CLSCompliant(false)]
public static class ReverbPresets
{
// CASTLE PRESETS
public static EaxReverb CastleSmallRoom = new EaxReverb(26, 8.3f, 0.890f, -1000, -800, -2000, 1.22f, 0.83f, 0.31f, -100, 0.022f, 0f, 0f, 0f, 600, 0.011f, 0f, 0f, 0f, 0.138f, 0.080f, 0.250f, 0f, -5f, 5168.6f, 139.5f, 0f, 0x20);
public static EaxReverb CastleShortPassage = new EaxReverb(26, 8.3f, 0.890f, -1000, -1000, -2000, 2.32f, 0.83f, 0.31f, -100, 0.007f, 0f, 0f, 0f, 200, 0.023f, 0f, 0f, 0f, 0.138f, 0.080f, 0.250f, 0f, -5f, 5168.6f, 139.5f, 0f, 0x20);
public static EaxReverb CastleMediumroom = new EaxReverb(26, 8.3f, 0.930f, -1000, -1100, -2000, 2.04f, 0.83f, 0.46f, -400, 0.022f, 0f, 0f, 0f, 400, 0.011f, 0f, 0f, 0f, 0.155f, 0.030f, 0.250f, 0f, -5f, 5168.6f, 139.5f, 0f, 0x20);
public static EaxReverb CastleLongpassage = new EaxReverb(26, 8.3f, 0.890f, -1000, -800, -2000, 3.42f, 0.83f, 0.31f, -100, 0.007f, 0f, 0f, 0f, 300, 0.023f, 0f, 0f, 0f, 0.138f, 0.080f, 0.250f, 0f, -5f, 5168.6f, 139.5f, 0f, 0x20);
public static EaxReverb CastleLargeroom = new EaxReverb(26, 8.3f, 0.820f, -1000, -1100, -1800, 2.53f, 0.83f, 0.50f, -700, 0.034f, 0f, 0f, 0f, 200, 0.016f, 0f, 0f, 0f, 0.185f, 0.070f, 0.250f, 0f, -5f, 5168.6f, 139.5f, 0f, 0x20);
public static EaxReverb CastleHall = new EaxReverb(26, 8.3f, 0.810f, -1000, -1100, -1500, 3.14f, 0.79f, 0.62f, -1500, 0.056f, 0f, 0f, 0f, 100, 0.024f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5168.6f, 139.5f, 0f, 0x20);
public static EaxReverb CastleCupboard = new EaxReverb(26, 8.3f, 0.890f, -1000, -1100, -2000, 0.67f, 0.87f, 0.31f, 300, 0.010f, 0f, 0f, 0f, 1100, 0.007f, 0f, 0f, 0f, 0.138f, 0.080f, 0.250f, 0f, -5f, 5168.6f, 139.5f, 0f, 0x20);
public static EaxReverb CastleCourtyard = new EaxReverb(26, 8.3f, 0.420f, -1000, -700, -1400, 2.13f, 0.61f, 0.23f, -1300, 0.160f, 0f, 0f, 0f, -300, 0.036f, 0f, 0f, 0f, 0.250f, 0.370f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x1f);
public static EaxReverb CastleAlcove = new EaxReverb(26, 8.3f, 0.890f, -1000, -600, -2000, 1.64f, 0.87f, 0.31f, 00, 0.007f, 0f, 0f, 0f, 300, 0.034f, 0f, 0f, 0f, 0.138f, 0.080f, 0.250f, 0f, -5f, 5168.6f, 139.5f, 0f, 0x20);
// FACTORY PRESETS
public static EaxReverb FactoryAlcove = new EaxReverb(26, 1.8f, 0.590f, -1200, -200, -600, 3.14f, 0.65f, 1.31f, 300, 0.010f, 0f, 0f, 0f, 000, 0.038f, 0f, 0f, 0f, 0.114f, 0.100f, 0.250f, 0f, -5f, 3762.6f, 362.5f, 0f, 0x20);
public static EaxReverb FactoryShortpassage = new EaxReverb(26, 1.8f, 0.640f, -1200, -200, -600, 2.53f, 0.65f, 1.31f, 0, 0.010f, 0f, 0f, 0f, 200, 0.038f, 0f, 0f, 0f, 0.135f, 0.230f, 0.250f, 0f, -5f, 3762.6f, 362.5f, 0f, 0x20);
public static EaxReverb FactoryMediumroom = new EaxReverb(26, 1.9f, 0.820f, -1200, -200, -600, 2.76f, 0.65f, 1.31f, -1100, 0.022f, 0f, 0f, 0f, 300, 0.023f, 0f, 0f, 0f, 0.174f, 0.070f, 0.250f, 0f, -5f, 3762.6f, 362.5f, 0f, 0x20);
public static EaxReverb FactoryLongpassage = new EaxReverb(26, 1.8f, 0.640f, -1200, -200, -600, 4.06f, 0.65f, 1.31f, 0, 0.020f, 0f, 0f, 0f, 200, 0.037f, 0f, 0f, 0f, 0.135f, 0.230f, 0.250f, 0f, -5f, 3762.6f, 362.5f, 0f, 0x20);
public static EaxReverb FactoryLargeroom = new EaxReverb(26, 1.9f, 0.750f, -1200, -300, -400, 4.24f, 0.51f, 1.31f, -1500, 0.039f, 0f, 0f, 0f, 100, 0.023f, 0f, 0f, 0f, 0.231f, 0.070f, 0.250f, 0f, -5f, 3762.6f, 362.5f, 0f, 0x20);
public static EaxReverb FactoryHall = new EaxReverb(26, 1.9f, 0.750f, -1000, -300, -400, 7.43f, 0.51f, 1.31f, -2400, 0.073f, 0f, 0f, 0f, -100, 0.027f, 0f, 0f, 0f, 0.250f, 0.070f, 0.250f, 0f, -5f, 3762.6f, 362.5f, 0f, 0x20);
public static EaxReverb FactoryCupboard = new EaxReverb(26, 1.7f, 0.630f, -1200, -200, -600, 0.49f, 0.65f, 1.31f, 200, 0.010f, 0f, 0f, 0f, 600, 0.032f, 0f, 0f, 0f, 0.107f, 0.070f, 0.250f, 0f, -5f, 3762.6f, 362.5f, 0f, 0x20);
public static EaxReverb FactoryCourtyard = new EaxReverb(26, 1.7f, 0.570f, -1000, -1000, -400, 2.32f, 0.29f, 0.56f, -1300, 0.140f, 0f, 0f, 0f, -800, 0.039f, 0f, 0f, 0f, 0.250f, 0.290f, 0.250f, 0f, -5f, 3762.6f, 362.5f, 0f, 0x20);
public static EaxReverb FactorySmallroom = new EaxReverb(26, 1.8f, 0.820f, -1000, -200, -600, 1.72f, 0.65f, 1.31f, -300, 0.010f, 0f, 0f, 0f, 500, 0.024f, 0f, 0f, 0f, 0.119f, 0.070f, 0.250f, 0f, -5f, 3762.6f, 362.5f, 0f, 0x20);
// ICE PALACE PRESETS
public static EaxReverb IcepalaceAlcove = new EaxReverb(26, 2.7f, 0.840f, -1000, -500, -1100, 2.76f, 1.46f, 0.28f, 100, 0.010f, 0f, 0f, 0f, -100, 0.030f, 0f, 0f, 0f, 0.161f, 0.090f, 0.250f, 0f, -5f, 12428.5f, 99.6f, 0f, 0x20);
public static EaxReverb IcepalaceShortpassage = new EaxReverb(26, 2.7f, 0.750f, -1000, -500, -1100, 1.79f, 1.46f, 0.28f, -600, 0.010f, 0f, 0f, 0f, 100, 0.019f, 0f, 0f, 0f, 0.177f, 0.090f, 0.250f, 0f, -5f, 12428.5f, 99.6f, 0f, 0x20);
public static EaxReverb IcepalaceMediumroom = new EaxReverb(26, 2.7f, 0.870f, -1000, -500, -700, 2.22f, 1.53f, 0.32f, -800, 0.039f, 0f, 0f, 0f, 100, 0.027f, 0f, 0f, 0f, 0.186f, 0.120f, 0.250f, 0f, -5f, 12428.5f, 99.6f, 0f, 0x20);
public static EaxReverb IcepalaceLongpassage = new EaxReverb(26, 2.7f, 0.770f, -1000, -500, -800, 3.01f, 1.46f, 0.28f, -200, 0.012f, 0f, 0f, 0f, 200, 0.025f, 0f, 0f, 0f, 0.186f, 0.040f, 0.250f, 0f, -5f, 12428.5f, 99.6f, 0f, 0x20);
public static EaxReverb IcepalaceLargeroom = new EaxReverb(26, 2.9f, 0.810f, -1000, -500, -700, 3.14f, 1.53f, 0.32f, -1200, 0.039f, 0f, 0f, 0f, 000, 0.027f, 0f, 0f, 0f, 0.214f, 0.110f, 0.250f, 0f, -5f, 12428.5f, 99.6f, 0f, 0x20);
public static EaxReverb IcepalaceHall = new EaxReverb(26, 2.9f, 0.760f, -1000, -700, -500, 5.49f, 1.53f, 0.38f, -1900, 0.054f, 0f, 0f, 0f, -400, 0.052f, 0f, 0f, 0f, 0.226f, 0.110f, 0.250f, 0f, -5f, 12428.5f, 99.6f, 0f, 0x20);
public static EaxReverb IcepalaceCupboard = new EaxReverb(26, 2.7f, 0.830f, -1000, -600, -1300, 0.76f, 1.53f, 0.26f, 100, 0.012f, 0f, 0f, 0f, 600, 0.016f, 0f, 0f, 0f, 0.143f, 0.080f, 0.250f, 0f, -5f, 12428.5f, 99.6f, 0f, 0x20);
public static EaxReverb IcepalaceCourtyard = new EaxReverb(26, 2.9f, 0.590f, -1000, -1100, -1000, 2.04f, 1.20f, 0.38f, -1000, 0.173f, 0f, 0f, 0f, -1000, 0.043f, 0f, 0f, 0f, 0.235f, 0.480f, 0.250f, 0f, -5f, 12428.5f, 99.6f, 0f, 0x20);
public static EaxReverb IcepalaceSmallroom = new EaxReverb(26, 2.7f, 0.840f, -1000, -500, -1100, 1.51f, 1.53f, 0.27f, -100, 0.010f, 0f, 0f, 0f, 300, 0.011f, 0f, 0f, 0f, 0.164f, 0.140f, 0.250f, 0f, -5f, 12428.5f, 99.6f, 0f, 0x20);
// SPACE STATION PRESETS
public static EaxReverb SpacestationAlcove = new EaxReverb(26, 1.5f, 0.780f, -1000, -300, -100, 1.16f, 0.81f, 0.55f, 300, 0.007f, 0f, 0f, 0f, 000, 0.018f, 0f, 0f, 0f, 0.192f, 0.210f, 0.250f, 0f, -5f, 3316.1f, 458.2f, 0f, 0x20);
public static EaxReverb SpacestationMediumroom = new EaxReverb(26, 1.5f, 0.750f, -1000, -400, -100, 3.01f, 0.50f, 0.55f, -800, 0.034f, 0f, 0f, 0f, 100, 0.035f, 0f, 0f, 0f, 0.209f, 0.310f, 0.250f, 0f, -5f, 3316.1f, 458.2f, 0f, 0x20);
public static EaxReverb SpacestationShortpassage = new EaxReverb(26, 1.5f, 0.870f, -1000, -400, -100, 3.57f, 0.50f, 0.55f, 0, 0.012f, 0f, 0f, 0f, 100, 0.016f, 0f, 0f, 0f, 0.172f, 0.200f, 0.250f, 0f, -5f, 3316.1f, 458.2f, 0f, 0x20);
public static EaxReverb SpacestationLongpassage = new EaxReverb(26, 1.9f, 0.820f, -1000, -400, -100, 4.62f, 0.62f, 0.55f, 0, 0.012f, 0f, 0f, 0f, 200, 0.031f, 0f, 0f, 0f, 0.250f, 0.230f, 0.250f, 0f, -5f, 3316.1f, 458.2f, 0f, 0x20);
public static EaxReverb SpacestationLargeroom = new EaxReverb(26, 1.8f, 0.810f, -1000, -400, -100, 3.89f, 0.38f, 0.61f, -1000, 0.056f, 0f, 0f, 0f, -100, 0.035f, 0f, 0f, 0f, 0.233f, 0.280f, 0.250f, 0f, -5f, 3316.1f, 458.2f, 0f, 0x20);
public static EaxReverb SpacestationHall = new EaxReverb(26, 1.9f, 0.870f, -1000, -400, -100, 7.11f, 0.38f, 0.61f, -1500, 0.100f, 0f, 0f, 0f, -400, 0.047f, 0f, 0f, 0f, 0.250f, 0.250f, 0.250f, 0f, -5f, 3316.1f, 458.2f, 0f, 0x20);
public static EaxReverb SpacestationCupboard = new EaxReverb(26, 1.4f, 0.560f, -1000, -300, -100, 0.79f, 0.81f, 0.55f, 300, 0.007f, 0f, 0f, 0f, 500, 0.018f, 0f, 0f, 0f, 0.181f, 0.310f, 0.250f, 0f, -5f, 3316.1f, 458.2f, 0f, 0x20);
public static EaxReverb SpacestationSmallroom = new EaxReverb(26, 1.5f, 0.700f, -1000, -300, -100, 1.72f, 0.82f, 0.55f, -200, 0.007f, 0f, 0f, 0f, 300, 0.013f, 0f, 0f, 0f, 0.188f, 0.260f, 0.250f, 0f, -5f, 3316.1f, 458.2f, 0f, 0x20);
// WOODEN GALLEON PRESETS
public static EaxReverb WoodenAlcove = new EaxReverb(26, 7.5f, 1f, -1000, -1800, -1000, 1.22f, 0.62f, 0.91f, 100, 0.012f, 0f, 0f, 0f, -300, 0.024f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 4705f, 99.6f, 0f, 0x3f);
public static EaxReverb WoodenShortpassage = new EaxReverb(26, 7.5f, 1f, -1000, -1800, -1000, 1.75f, 0.50f, 0.87f, -100, 0.012f, 0f, 0f, 0f, -400, 0.024f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 4705f, 99.6f, 0f, 0x3f);
public static EaxReverb WoodenMediumroom = new EaxReverb(26, 7.5f, 1f, -1000, -2000, -1100, 1.47f, 0.42f, 0.82f, -100, 0.049f, 0f, 0f, 0f, -100, 0.029f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 4705f, 99.6f, 0f, 0x3f);
public static EaxReverb WoodenLongpassage = new EaxReverb(26, 7.5f, 1f, -1000, -2000, -1000, 1.99f, 0.40f, 0.79f, 000, 0.020f, 0f, 0f, 0f, -700, 0.036f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 4705f, 99.6f, 0f, 0x3f);
public static EaxReverb WoodenLargeroom = new EaxReverb(26, 7.5f, 1f, -1000, -2100, -1100, 2.65f, 0.33f, 0.82f, -100, 0.066f, 0f, 0f, 0f, -200, 0.049f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 4705f, 99.6f, 0f, 0x3f);
public static EaxReverb WoodenHall = new EaxReverb(26, 7.5f, 1f, -1000, -2200, -1100, 3.45f, 0.30f, 0.82f, -100, 0.088f, 0f, 0f, 0f, -200, 0.063f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 4705f, 99.6f, 0f, 0x3f);
public static EaxReverb WoodenCupboard = new EaxReverb(26, 7.5f, 1f, -1000, -1700, -1000, 0.56f, 0.46f, 0.91f, 100, 0.012f, 0f, 0f, 0f, 100, 0.028f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 4705f, 99.6f, 0f, 0x3f);
public static EaxReverb WoodenSmallroom = new EaxReverb(26, 7.5f, 1f, -1000, -1900, -1000, 0.79f, 0.32f, 0.87f, 00, 0.032f, 0f, 0f, 0f, -100, 0.029f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 4705f, 99.6f, 0f, 0x3f);
public static EaxReverb WoodenCourtyard = new EaxReverb(26, 7.5f, 0.650f, -1000, -2200, -1000, 1.79f, 0.35f, 0.79f, -500, 0.123f, 0f, 0f, 0f, -2000, 0.032f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 4705f, 99.6f, 0f, 0x3f);
// SPORTS PRESETS
public static EaxReverb SportEmptystadium = new EaxReverb(26, 7.2f, 1f, -1000, -700, -200, 6.26f, 0.51f, 1.10f, -2400, 0.183f, 0f, 0f, 0f, -800, 0.038f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x20);
public static EaxReverb SportSquashcourt = new EaxReverb(26, 7.5f, 0.750f, -1000, -1000, -200, 2.22f, 0.91f, 1.16f, -700, 0.007f, 0f, 0f, 0f, -200, 0.011f, 0f, 0f, 0f, 0.126f, 0.190f, 0.250f, 0f, -5f, 7176.9f, 211.2f, 0f, 0x20);
public static EaxReverb SportSmallswimmingpool = new EaxReverb(26, 36.2f, 0.700f, -1000, -200, -100, 2.76f, 1.25f, 1.14f, -400, 0.020f, 0f, 0f, 0f, -200, 0.030f, 0f, 0f, 0f, 0.179f, 0.150f, 0.895f, 0.190f, -5f, 5000f, 250f, 0f, 0x0);
public static EaxReverb SportLargeswimmingpool = new EaxReverb(26, 36.2f, 0.820f, -1000, -200, 0, 5.49f, 1.31f, 1.14f, -700, 0.039f, 0f, 0f, 0f, -600, 0.049f, 0f, 0f, 0f, 0.222f, 0.550f, 1.159f, 0.210f, -5f, 5000f, 250f, 0f, 0x0);
public static EaxReverb SportGymnasium = new EaxReverb(26, 7.5f, 0.810f, -1000, -700, -100, 3.14f, 1.06f, 1.35f, -800, 0.029f, 0f, 0f, 0f, -500, 0.045f, 0f, 0f, 0f, 0.146f, 0.140f, 0.250f, 0f, -5f, 7176.9f, 211.2f, 0f, 0x20);
public static EaxReverb SportFullstadium = new EaxReverb(26, 7.2f, 1f, -1000, -2300, -200, 5.25f, 0.17f, 0.80f, -2000, 0.188f, 0f, 0f, 0f, -1100, 0.038f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x20);
public static EaxReverb SportStadimtannoy = new EaxReverb(26, 3f, 0.780f, -1000, -500, -600, 2.53f, 0.88f, 0.68f, -1100, 0.230f, 0f, 0f, 0f, -600, 0.063f, 0f, 0f, 0f, 0.250f, 0.200f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x20);
// PREFAB PRESETS
public static EaxReverb PrefabWorkshop = new EaxReverb(26, 1.9f, 1f, -1000, -1700, -800, 0.76f, 1f, 1f, 0, 0.012f, 0f, 0f, 0f, 100, 0.012f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x0);
public static EaxReverb PrefabSchoolroom = new EaxReverb(26, 1.86f, 0.690f, -1000, -400, -600, 0.98f, 0.45f, 0.18f, 300, 0.017f, 0f, 0f, 0f, 300, 0.015f, 0f, 0f, 0f, 0.095f, 0.140f, 0.250f, 0f, -5f, 7176.9f, 211.2f, 0f, 0x20);
public static EaxReverb PrefabPractiseroom = new EaxReverb(26, 1.86f, 0.870f, -1000, -800, -600, 1.12f, 0.56f, 0.18f, 200, 0.010f, 0f, 0f, 0f, 300, 0.011f, 0f, 0f, 0f, 0.095f, 0.140f, 0.250f, 0f, -5f, 7176.9f, 211.2f, 0f, 0x20);
public static EaxReverb PrefabOuthouse = new EaxReverb(26, 80.3f, 0.820f, -1000, -1900, -1600, 1.38f, 0.38f, 0.35f, -100, 0.024f, 0f, 0f, -0f, -400, 0.044f, 0f, 0f, 0f, 0.121f, 0.170f, 0.250f, 0f, -5f, 2854.4f, 107.5f, 0f, 0x0);
public static EaxReverb PrefabCaravan = new EaxReverb(26, 8.3f, 1f, -1000, -2100, -1800, 0.43f, 1.50f, 1f, 0, 0.012f, 0f, 0f, 0f, 600, 0.012f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x1f);
// DOME AND PIPE PRESETS
public static EaxReverb DomeTomb = new EaxReverb(26, 51.8f, 0.790f, -1000, -900, -1300, 4.18f, 0.21f, 0.10f, -825, 0.030f, 0f, 0f, 0f, 450, 0.022f, 0f, 0f, 0f, 0.177f, 0.190f, 0.250f, 0f, -5f, 2854.4f, 20f, 0f, 0x0);
public static EaxReverb DomeSaintPauls = new EaxReverb(26, 50.3f, 0.870f, -1000, -900, -1300, 10.48f, 0.19f, 0.10f, -1500, 0.090f, 0f, 0f, 0f, 200, 0.042f, 0f, 0f, 0f, 0.250f, 0.120f, 0.250f, 0f, -5f, 2854.4f, 20f, 0f, 0x3f);
public static EaxReverb PipeSmall = new EaxReverb(26, 50.3f, 1f, -1000, -900, -1300, 5.04f, 0.10f, 0.10f, -600, 0.032f, 0f, 0f, 0f, 800, 0.015f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 2854.4f, 20f, 0f, 0x3f);
public static EaxReverb PipeLongthin = new EaxReverb(26, 1.6f, 0.910f, -1000, -700, -1100, 9.21f, 0.18f, 0.10f, -300, 0.010f, 0f, 0f, 0f, -300, 0.022f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 2854.4f, 20f, 0f, 0x0);
public static EaxReverb PipeLarge = new EaxReverb(26, 50.3f, 1f, -1000, -900, -1300, 8.45f, 0.10f, 0.10f, -800, 0.046f, 0f, 0f, 0f, 400, 0.032f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 2854.4f, 20f, 0f, 0x3f);
public static EaxReverb PipeResonant = new EaxReverb(26, 1.3f, 0.910f, -1000, -700, -1100, 6.81f, 0.18f, 0.10f, -300, 0.010f, 0f, 0f, 0f, 00, 0.022f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 2854.4f, 20f, 0f, 0x0);
// OUTDOORS PRESETS
public static EaxReverb OutdoorsBackyard = new EaxReverb(26, 80.3f, 0.450f, -1000, -1200, -600, 1.12f, 0.34f, 0.46f, -700, 0.069f, 0f, 0f, -0f, -300, 0.023f, 0f, 0f, 0f, 0.218f, 0.340f, 0.250f, 0f, -5f, 4399.1f, 242.9f, 0f, 0x0);
public static EaxReverb OutdoorsRollingplains = new EaxReverb(26, 80.3f, 0f, -1000, -3900, -400, 2.13f, 0.21f, 0.46f, -1500, 0.300f, 0f, 0f, -0f, -700, 0.019f, 0f, 0f, 0f, 0.250f, 1f, 0.250f, 0f, -5f, 4399.1f, 242.9f, 0f, 0x0);
public static EaxReverb OutdoorsDeepcanyon = new EaxReverb(26, 80.3f, 0.740f, -1000, -1500, -400, 3.89f, 0.21f, 0.46f, -1000, 0.223f, 0f, 0f, -0f, -900, 0.019f, 0f, 0f, 0f, 0.250f, 1f, 0.250f, 0f, -5f, 4399.1f, 242.9f, 0f, 0x0);
public static EaxReverb OutdoorsCreek = new EaxReverb(26, 80.3f, 0.350f, -1000, -1500, -600, 2.13f, 0.21f, 0.46f, -800, 0.115f, 0f, 0f, -0f, -1400, 0.031f, 0f, 0f, 0f, 0.218f, 0.340f, 0.250f, 0f, -5f, 4399.1f, 242.9f, 0f, 0x0);
public static EaxReverb OutdoorsValley = new EaxReverb(26, 80.3f, 0.280f, -1000, -3100, -1600, 2.88f, 0.26f, 0.35f, -1700, 0.263f, 0f, 0f, -0f, -800, 0.100f, 0f, 0f, 0f, 0.250f, 0.340f, 0.250f, 0f, -5f, 2854.4f, 107.5f, 0f, 0x0);
// MOOD PRESETS
public static EaxReverb MoodHeaven = new EaxReverb(26, 19.6f, 0.940f, -1000, -200, -700, 5.04f, 1.12f, 0.56f, -1230, 0.020f, 0f, 0f, 0f, 200, 0.029f, 0f, 0f, 0f, 0.250f, 0.080f, 2.742f, 0.050f, -2f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb MoodHell = new EaxReverb(26, 100f, 0.570f, -1000, -900, -700, 3.57f, 0.49f, 2f, -10000, 0.020f, 0f, 0f, 0f, 300, 0.030f, 0f, 0f, 0f, 0.110f, 0.040f, 2.109f, 0.520f, -5f, 5000f, 139.5f, 0f, 0x40);
public static EaxReverb MoodMemory = new EaxReverb(26, 8f, 0.850f, -1000, -400, -900, 4.06f, 0.82f, 0.56f, -2800, 0f, 0f, 0f, 0f, 100, 0f, 0f, 0f, 0f, 0.250f, 0f, 0.474f, 0.450f, -10f, 5000f, 250f, 0f, 0x0);
// DRIVING SIMULATION PRESETS
public static EaxReverb DrivingCommentator = new EaxReverb(26, 3f, 0f, 1000, -500, -600, 2.42f, 0.88f, 0.68f, -1400, 0.093f, 0f, 0f, 0f, -1200, 0.017f, 0f, 0f, 0f, 0.250f, 1f, 0.250f, 0f, -10f, 5000f, 250f, 0f, 0x20);
public static EaxReverb DrivingPitgarage = new EaxReverb(26, 1.9f, 0.590f, -1000, -300, -500, 1.72f, 0.93f, 0.87f, -500, 0f, 0f, 0f, 0f, 200, 0.016f, 0f, 0f, 0f, 0.250f, 0.110f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x0);
public static EaxReverb DrivingIncarRacer = new EaxReverb(26, 1.1f, 0.800f, -1000, 0, -200, 0.17f, 2f, 0.41f, 500, 0.007f, 0f, 0f, 0f, -300, 0.015f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 10268.2f, 251f, 0f, 0x20);
public static EaxReverb DrivingIncarSports = new EaxReverb(26, 1.1f, 0.800f, -1000, -400, 0, 0.17f, 0.75f, 0.41f, 0, 0.010f, 0f, 0f, 0f, -500, 0f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 10268.2f, 251f, 0f, 0x20);
public static EaxReverb DrivingIncarLuxury = new EaxReverb(26, 1.6f, 1f, -1000, -2000, -600, 0.13f, 0.41f, 0.46f, -200, 0.010f, 0f, 0f, 0f, 400, 0.010f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 10268.2f, 251f, 0f, 0x20);
public static EaxReverb DrivingFullgrandstand = new EaxReverb(26, 8.3f, 1f, -1000, -1100, -400, 3.01f, 1.37f, 1.28f, -900, 0.090f, 0f, 0f, 0f, -1500, 0.049f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 10420.2f, 250f, 0f, 0x1f);
public static EaxReverb DrivingEmptygrandstand = new EaxReverb(26, 8.3f, 1f, -1000, 0, -200, 4.62f, 1.75f, 1.40f, -1363, 0.090f, 0f, 0f, 0f, -1200, 0.049f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 10420.2f, 250f, 0f, 0x1f);
public static EaxReverb DrivingTunnel = new EaxReverb(26, 3.1f, 0.810f, -1000, -800, -100, 3.42f, 0.94f, 1.31f, -300, 0.051f, 0f, 0f, 0f, -300, 0.047f, 0f, 0f, 0f, 0.214f, 0.050f, 0.250f, 0f, -5f, 5000f, 155.3f, 0f, 0x20);
// CITY PRESETS
public static EaxReverb CityStreets = new EaxReverb(26, 3f, 0.780f, -1000, -300, -100, 1.79f, 1.12f, 0.91f, -1100, 0.046f, 0f, 0f, 0f, -1400, 0.028f, 0f, 0f, 0f, 0.250f, 0.200f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x20);
public static EaxReverb CitySubway = new EaxReverb(26, 3f, 0.740f, -1000, -300, -100, 3.01f, 1.23f, 0.91f, -300, 0.046f, 0f, 0f, 0f, 200, 0.028f, 0f, 0f, 0f, 0.125f, 0.210f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x20);
public static EaxReverb CityMuseum = new EaxReverb(26, 80.3f, 0.820f, -1000, -1500, -1500, 3.28f, 1.40f, 0.57f, -1200, 0.039f, 0f, 0f, -0f, -100, 0.034f, 0f, 0f, 0f, 0.130f, 0.170f, 0.250f, 0f, -5f, 2854.4f, 107.5f, 0f, 0x0);
public static EaxReverb CityLibrary = new EaxReverb(26, 80.3f, 0.820f, -1000, -1100, -2100, 2.76f, 0.89f, 0.41f, -900, 0.029f, 0f, 0f, -0f, -100, 0.020f, 0f, 0f, 0f, 0.130f, 0.170f, 0.250f, 0f, -5f, 2854.4f, 107.5f, 0f, 0x0);
public static EaxReverb CityUnderpass = new EaxReverb(26, 3f, 0.820f, -1000, -700, -100, 3.57f, 1.12f, 0.91f, -800, 0.059f, 0f, 0f, 0f, -100, 0.037f, 0f, 0f, 0f, 0.250f, 0.140f, 0.250f, 0f, -7f, 5000f, 250f, 0f, 0x20);
public static EaxReverb CityAbandoned = new EaxReverb(26, 3f, 0.690f, -1000, -200, -100, 3.28f, 1.17f, 0.91f, -700, 0.044f, 0f, 0f, 0f, -1100, 0.024f, 0f, 0f, 0f, 0.250f, 0.200f, 0.250f, 0f, -3f, 5000f, 250f, 0f, 0x20);
// MISC ROOMS
public static EaxReverb Generic = new EaxReverb(0, 7.5f, 1f, -1000, -100, 0, 1.49f, 0.83f, 1f, -2602, 0.007f, 0f, 0f, 0f, 200, 0.011f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Paddedcell = new EaxReverb(1, 1.4f, 1f, -1000, -6000, 0, 0.17f, 0.10f, 1f, -1204, 0.001f, 0f, 0f, 0f, 207, 0.002f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Room = new EaxReverb(2, 1.9f, 1f, -1000, -454, 0, 0.40f, 0.83f, 1f, -1646, 0.002f, 0f, 0f, 0f, 53, 0.003f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Bathroom = new EaxReverb(3, 1.4f, 1f, -1000, -1200, 0, 1.49f, 0.54f, 1f, -370, 0.007f, 0f, 0f, 0f, 1030, 0.011f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Livingroom = new EaxReverb(4, 2.5f, 1f, -1000, -6000, 0, 0.50f, 0.10f, 1f, -1376, 0.003f, 0f, 0f, 0f, -1104, 0.004f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Stoneroom = new EaxReverb(5, 11.6f, 1f, -1000, -300, 0, 2.31f, 0.64f, 1f, -711, 0.012f, 0f, 0f, 0f, 83, 0.017f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Auditorium = new EaxReverb(6, 21.6f, 1f, -1000, -476, 0, 4.32f, 0.59f, 1f, -789, 0.020f, 0f, 0f, 0f, -289, 0.030f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Concerthall = new EaxReverb(7, 19.6f, 1f, -1000, -500, 0, 3.92f, 0.70f, 1f, -1230, 0.020f, 0f, 0f, 0f, -02, 0.029f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Cave = new EaxReverb(8, 14.6f, 1f, -1000, 0, 0, 2.91f, 1.30f, 1f, -602, 0.015f, 0f, 0f, 0f, -302, 0.022f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x1f);
public static EaxReverb Arena = new EaxReverb(9, 36.2f, 1f, -1000, -698, 0, 7.24f, 0.33f, 1f, -1166, 0.020f, 0f, 0f, 0f, 16, 0.030f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Hangar = new EaxReverb(10, 50.3f, 1f, -1000, -1000, 0, 10.05f, 0.23f, 1f, -602, 0.020f, 0f, 0f, 0f, 198, 0.030f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Carpettedhallway = new EaxReverb(11, 1.9f, 1f, -1000, -4000, 0, 0.30f, 0.10f, 1f, -1831, 0.002f, 0f, 0f, 0f, -1630, 0.030f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Hallway = new EaxReverb(12, 1.8f, 1f, -1000, -300, 0, 1.49f, 0.59f, 1f, -1219, 0.007f, 0f, 0f, 0f, 441, 0.011f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Stonecorridor = new EaxReverb(13, 13.5f, 1f, -1000, -237, 0, 2.70f, 0.79f, 1f, -1214, 0.013f, 0f, 0f, 0f, 395, 0.020f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Alley = new EaxReverb(14, 7.5f, 0.300f, -1000, -270, 0, 1.49f, 0.86f, 1f, -1204, 0.007f, 0f, 0f, 0f, -4, 0.011f, 0f, 0f, 0f, 0.125f, 0.950f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Forest = new EaxReverb(15, 38f, 0.300f, -1000, -3300, 0, 1.49f, 0.54f, 1f, -2560, 0.162f, 0f, 0f, 0f, -229, 0.088f, 0f, 0f, 0f, 0.125f, 1f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb City = new EaxReverb(16, 7.5f, 0.500f, -1000, -800, 0, 1.49f, 0.67f, 1f, -2273, 0.007f, 0f, 0f, 0f, -1691, 0.011f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Mountains = new EaxReverb(17, 100f, 0.270f, -1000, -2500, 0, 1.49f, 0.21f, 1f, -2780, 0.300f, 0f, 0f, 0f, -1434, 0.100f, 0f, 0f, 0f, 0.250f, 1f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x1f);
public static EaxReverb Quarry = new EaxReverb(18, 17.5f, 1f, -1000, -1000, 0, 1.49f, 0.83f, 1f, -10000, 0.061f, 0f, 0f, 0f, 500, 0.025f, 0f, 0f, 0f, 0.125f, 0.700f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Plain = new EaxReverb(19, 42.5f, 0.210f, -1000, -2000, 0, 1.49f, 0.50f, 1f, -2466, 0.179f, 0f, 0f, 0f, -1926, 0.100f, 0f, 0f, 0f, 0.250f, 1f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Parkinglot = new EaxReverb(20, 8.3f, 1f, -1000, 0, 0, 1.65f, 1.50f, 1f, -1363, 0.008f, 0f, 0f, 0f, -1153, 0.012f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x1f);
public static EaxReverb Sewerpipe = new EaxReverb(21, 1.7f, 0.800f, -1000, -1000, 0, 2.81f, 0.14f, 1f, 429, 0.014f, 0f, 0f, 0f, 1023, 0.021f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Underwater = new EaxReverb(22, 1.8f, 1f, -1000, -4000, 0, 1.49f, 0.10f, 1f, -449, 0.007f, 0f, 0f, 0f, 1700, 0.011f, 0f, 0f, 0f, 0.250f, 0f, 1.180f, 0.348f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Drugged = new EaxReverb(23, 1.9f, 0.500f, -1000, 0, 0, 8.39f, 1.39f, 1f, -115, 0.002f, 0f, 0f, 0f, 985, 0.030f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 1f, -5f, 5000f, 250f, 0f, 0x1f);
public static EaxReverb Dizzy = new EaxReverb(24, 1.8f, 0.600f, -1000, -400, 0, 17.23f, 0.56f, 1f, -1713, 0.020f, 0f, 0f, 0f, -613, 0.030f, 0f, 0f, 0f, 0.250f, 1f, 0.810f, 0.310f, -5f, 5000f, 250f, 0f, 0x1f);
public static EaxReverb Psychotic = new EaxReverb(25, 1f, 0.500f, -1000, -151, 0, 7.56f, 0.91f, 1f, -626, 0.020f, 0f, 0f, 0f, 774, 0.030f, 0f, 0f, 0f, 0.250f, 0f, 4f, 1f, -5f, 5000f, 250f, 0f, 0x1f);
public static EaxReverb Dustyroom = new EaxReverb(26, 1.8f, 0.560f, -1000, -200, -300, 1.79f, 0.38f, 0.21f, -600, 0.002f, 0f, 0f, 0f, 200, 0.006f, 0f, 0f, 0f, 0.202f, 0.050f, 0.250f, 0f, -10f, 13046f, 163.3f, 0f, 0x20);
public static EaxReverb Chapel = new EaxReverb(26, 19.6f, 0.840f, -1000, -500, 0, 4.62f, 0.64f, 1.23f, -700, 0.032f, 0f, 0f, 0f, -200, 0.049f, 0f, 0f, 0f, 0.250f, 0f, 0.250f, 0.110f, -5f, 5000f, 250f, 0f, 0x3f);
public static EaxReverb Smallwaterroom = new EaxReverb(26, 36.2f, 0.700f, -1000, -698, 0, 1.51f, 1.25f, 1.14f, -100, 0.020f, 0f, 0f, 0f, 300, 0.030f, 0f, 0f, 0f, 0.179f, 0.150f, 0.895f, 0.190f, -7f, 5000f, 250f, 0f, 0x0);
}
#pragma warning restore 1591
}
}
// flibit Added This!!!
#pragma warning restore 3021

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

@ -0,0 +1,208 @@
#region --- OpenTK.OpenAL License ---
/* XRamExtension.cs
* C header: \OpenAL 1.1 SDK\include\xram.h
* Spec: ?
* Copyright (c) 2008 Christoph Brandtner and Stefanos Apostolopoulos
* See license.txt for license details (MIT)
* http://www.OpenTK.net */
#endregion
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
// flibit Added This!!!
#pragma warning disable 3021
#pragma warning disable 3014
#pragma warning disable 3003
namespace OpenTK.Audio.OpenAL
{
///<summary>
///The X-Ram Extension is provided on the top-end Sound Blaster X-Fi solutions (Sound Blaster X-Fi Fatal1ty, Sound Blaster X-Fi Elite Pro, or later).
///These products feature 64MB of X-Ram that can only be used for audio purposes, which can be controlled by this Extension.
///</summary>
[CLSCompliant(true)]
public sealed class XRamExtension
{
#region Instance state
private bool _valid = false;
/// <summary>Returns True if the X-Ram Extension has been found and could be initialized.</summary>
public bool IsInitialized
{
get { return _valid; }
}
#endregion Instance state
#region X-RAM Function pointer definitions
// [CLSCompliant(false)]
private delegate bool Delegate_SetBufferMode(int n, ref uint buffers, int value);
//typedef ALboolean (__cdecl *EAXSetBufferMode)(ALsizei n, ALuint *buffers, ALint value);
// [CLSCompliant( false )]
private delegate int Delegate_GetBufferMode(uint buffer, IntPtr value);
//typedef ALenum (__cdecl *EAXGetBufferMode)(ALuint buffer, ALint *value);
//[CLSCompliant(false)]
private Delegate_SetBufferMode Imported_SetBufferMode;
//[CLSCompliant(false)]
private Delegate_GetBufferMode Imported_GetBufferMode;
#endregion X-RAM Function pointer definitions
#region X-RAM Tokens
private int AL_EAX_RAM_SIZE, AL_EAX_RAM_FREE,
AL_STORAGE_AUTOMATIC, AL_STORAGE_HARDWARE, AL_STORAGE_ACCESSIBLE;
#endregion X-RAM Tokens
#region Constructor / Extension Loading
/// <summary>
/// Constructs a new XRamExtension instance.
/// </summary>
public XRamExtension()
{ // Query if Extension supported and retrieve Tokens/Pointers if it is.
_valid = false;
if (AL.IsExtensionPresent("EAX-RAM") == false)
return;
AL_EAX_RAM_SIZE = AL.GetEnumValue("AL_EAX_RAM_SIZE");
AL_EAX_RAM_FREE = AL.GetEnumValue("AL_EAX_RAM_FREE");
AL_STORAGE_AUTOMATIC = AL.GetEnumValue("AL_STORAGE_AUTOMATIC");
AL_STORAGE_HARDWARE = AL.GetEnumValue("AL_STORAGE_HARDWARE");
AL_STORAGE_ACCESSIBLE = AL.GetEnumValue("AL_STORAGE_ACCESSIBLE");
// Console.WriteLine("RamSize: {0} RamFree: {1} StorageAuto: {2} StorageHW: {3} StorageAccess: {4}",AL_EAX_RAM_SIZE,AL_EAX_RAM_FREE,AL_STORAGE_AUTOMATIC,AL_STORAGE_HARDWARE,AL_STORAGE_ACCESSIBLE);
if (AL_EAX_RAM_SIZE == 0 ||
AL_EAX_RAM_FREE == 0 ||
AL_STORAGE_AUTOMATIC == 0 ||
AL_STORAGE_HARDWARE == 0 ||
AL_STORAGE_ACCESSIBLE == 0)
{
Debug.WriteLine("X-Ram: Token values could not be retrieved.");
return;
}
// Console.WriteLine("Free Ram: {0} / {1}",GetRamFree( ),GetRamSize( ));
try
{
Imported_GetBufferMode = (Delegate_GetBufferMode)Marshal.GetDelegateForFunctionPointer(AL.GetProcAddress("EAXGetBufferMode"), typeof(Delegate_GetBufferMode));
Imported_SetBufferMode = (Delegate_SetBufferMode)Marshal.GetDelegateForFunctionPointer(AL.GetProcAddress("EAXSetBufferMode"), typeof(Delegate_SetBufferMode));
}
catch (Exception e)
{
Debug.WriteLine("X-Ram: Attempt to marshal function pointers with AL.GetProcAddress failed. " + e.ToString());
return;
}
_valid = true;
}
#endregion Constructor / Extension Loading
#region Public Methods
/// <summary>Query total amount of X-RAM in bytes.</summary>
public int GetRamSize
{
get
{
return AL.Get((ALGetInteger)AL_EAX_RAM_SIZE);
}
}
/// <summary>Query free X-RAM available in bytes.</summary>
public int GetRamFree
{
get
{
return AL.Get((ALGetInteger)AL_EAX_RAM_FREE);
}
}
/// <summary>This enum is used to abstract the need of using AL.GetEnumValue() with the Extension. The values do NOT correspond to AL_STORAGE_* tokens!</summary>
public enum XRamStorage : byte
{
/// <summary>Put an Open AL Buffer into X-RAM if memory is available, otherwise use host RAM. This is the default mode.</summary>
Automatic = 0,
/// <summary>Force an Open AL Buffer into X-RAM, good for non-streaming buffers.</summary>
Hardware = 1,
/// <summary>Force an Open AL Buffer into 'accessible' (currently host) RAM, good for streaming buffers.</summary>
Accessible = 2,
}
/// <summary>This function is used to set the storage Mode of an array of OpenAL Buffers.</summary>
/// <param name="n">The number of OpenAL Buffers pointed to by buffer.</param>
/// <param name="buffer">An array of OpenAL Buffer handles.</param>
/// <param name="mode">The storage mode that should be used for all the given buffers. Should be the value of one of the following enum names: XRamStorage.Automatic, XRamStorage.Hardware, XRamStorage.Accessible</param>
/// <returns>True if all the Buffers were successfully set to the requested storage mode, False otherwise.</returns>
[CLSCompliant(false)]
public bool SetBufferMode(int n, ref uint buffer, XRamStorage mode)
{
switch (mode)
{
case XRamStorage.Accessible:
return Imported_SetBufferMode(n, ref buffer, AL_STORAGE_ACCESSIBLE);
case XRamStorage.Hardware:
return Imported_SetBufferMode(n, ref buffer, AL_STORAGE_HARDWARE);
default:
return Imported_SetBufferMode(n, ref buffer, AL_STORAGE_AUTOMATIC);
}
}
/// <summary>This function is used to set the storage Mode of an array of OpenAL Buffers.</summary>
/// <param name="n">The number of OpenAL Buffers pointed to by buffer.</param>
/// <param name="buffer">An array of OpenAL Buffer handles.</param>
/// <param name="mode">The storage mode that should be used for all the given buffers. Should be the value of one of the following enum names: XRamStorage.Automatic, XRamStorage.Hardware, XRamStorage.Accessible</param>
/// <returns>True if all the Buffers were successfully set to the requested storage mode, False otherwise.</returns>
[CLSCompliant(true)]
public bool SetBufferMode(int n, ref int buffer, XRamStorage mode)
{
uint temp = (uint)buffer;
return SetBufferMode(n, ref temp, mode);
}
/// <summary>This function is used to retrieve the storage Mode of a single OpenAL Buffer.</summary>
/// <param name="buffer">The handle of an OpenAL Buffer.</param>
/// <returns>The current Mode of the Buffer.</returns>
[CLSCompliant(false)]
public XRamStorage GetBufferMode(ref uint buffer)
{
int tempresult = Imported_GetBufferMode(buffer, IntPtr.Zero); // IntPtr.Zero due to the parameter being unused/reserved atm
if (tempresult == AL_STORAGE_ACCESSIBLE)
return XRamStorage.Accessible;
if (tempresult == AL_STORAGE_HARDWARE)
return XRamStorage.Hardware;
// default:
return XRamStorage.Automatic;
}
/// <summary>This function is used to retrieve the storage Mode of a single OpenAL Buffer.</summary>
/// <param name="buffer">The handle of an OpenAL Buffer.</param>
/// <returns>The current Mode of the Buffer.</returns>
[CLSCompliant(true)]
public XRamStorage GetBufferMode(ref int buffer)
{
uint temp = (uint)buffer;
return GetBufferMode(ref temp);
}
#endregion Public Methods
}
}
// flibit Added This!!!
#pragma warning restore 3021
#pragma warning restore 3014
#pragma warning restore 3003

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

@ -0,0 +1,448 @@
#region --- OpenTK.OpenAL License ---
/* AlcFunctions.cs
* C header: \OpenAL 1.1 SDK\include\Alc.h
* Spec: http://www.openal.org/openal_webstf/specs/OpenAL11Specification.pdf
* Copyright (c) 2008 Christoph Brandtner and Stefanos Apostolopoulos
* See license.txt for license details
* http://www.OpenTK.net */
#endregion
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security;
// flibit Added This!!!
#pragma warning disable 3021
/* Type Mapping
// 8-bit boolean
typedef char ALCboolean;
* byte
// character
typedef char ALCchar;
* byte
// signed 8-bit 2's complement integer
typedef char ALCbyte;
* byte
// unsigned 8-bit integer
typedef unsigned char ALCubyte;
* ubyte
// signed 16-bit 2's complement integer
typedef short ALCshort;
* short
// unsigned 16-bit integer
typedef unsigned short ALCushort;
* ushort
// unsigned 32-bit integer
typedef unsigned int ALCuint;
* uint
// signed 32-bit 2's complement integer
typedef int ALCint;
* int
// non-negative 32-bit binary integer size
typedef int ALCsizei;
* int
// enumerated 32-bit value
typedef int ALCenum;
* int
// 32-bit IEEE754 floating-point
typedef float ALCfloat;
* float
// 64-bit IEEE754 floating-point
typedef double ALCdouble;
* double
// void type (for opaque pointers only)
typedef void ALCvoid;
* void
* ALCdevice
* ALCcontext *context
* IntPtr
*/
namespace OpenTK.Audio.OpenAL
{
/// <summary>Alc = Audio Library Context</summary>
public static class Alc
{
#region Constants
private const string Lib = AL.Lib;
private const CallingConvention Style = CallingConvention.Cdecl;
#endregion Constants
#region Context Management
#region CreateContext
[DllImport(Alc.Lib, EntryPoint = "alcCreateContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity]
unsafe static extern IntPtr sys_CreateContext([In] IntPtr device, [In] int* attrlist);
/// <summary>This function creates a context using a specified device.</summary>
/// <param name="device">a pointer to a device</param>
/// <param name="attrlist">a pointer to a set of attributes: ALC_FREQUENCY, ALC_MONO_SOURCES, ALC_REFRESH, ALC_STEREO_SOURCES, ALC_SYNC</param>
/// <returns>Returns a pointer to the new context (NULL on failure). The attribute list can be NULL, or a zero terminated list of integer pairs composed of valid ALC attribute tokens and requested values.</returns>
[CLSCompliant(false)]
unsafe public static ContextHandle CreateContext([In] IntPtr device, [In] int* attrlist)
{
return new ContextHandle(sys_CreateContext(device, attrlist));
}
// ALC_API ALCcontext * ALC_APIENTRY alcCreateContext( ALCdevice *device, const ALCint* attrlist );
/// <summary>This function creates a context using a specified device.</summary>
/// <param name="device">a pointer to a device</param>
/// <param name="attriblist">an array of a set of attributes: ALC_FREQUENCY, ALC_MONO_SOURCES, ALC_REFRESH, ALC_STEREO_SOURCES, ALC_SYNC</param>
/// <returns>Returns a pointer to the new context (NULL on failure).</returns>
/// <remarks>The attribute list can be NULL, or a zero terminated list of integer pairs composed of valid ALC attribute tokens and requested values.</remarks>
public static ContextHandle CreateContext(IntPtr device, int[] attriblist)
{
unsafe
{
fixed (int* attriblist_ptr = attriblist)
{
return CreateContext(device, attriblist_ptr);
}
}
}
#endregion
[DllImport(Alc.Lib, EntryPoint = "alcMakeContextCurrent", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
static extern bool MakeContextCurrent(IntPtr context);
/// <summary>This function makes a specified context the current context.</summary>
/// <param name="context">A pointer to the new context.</param>
/// <returns>Returns True on success, or False on failure.</returns>
public static bool MakeContextCurrent(ContextHandle context)
{
return MakeContextCurrent(context.Handle);
}
// ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent( ALCcontext *context );
[DllImport(Alc.Lib, EntryPoint = "alcProcessContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
static extern void ProcessContext(IntPtr context);
/// <summary>This function tells a context to begin processing. When a context is suspended, changes in OpenAL state will be accepted but will not be processed. alcSuspendContext can be used to suspend a context, and then all the OpenAL state changes can be applied at once, followed by a call to alcProcessContext to apply all the state changes immediately. In some cases, this procedure may be more efficient than application of properties in a non-suspended state. In some implementations, process and suspend calls are each a NOP.</summary>
/// <param name="context">a pointer to the new context</param>
public static void ProcessContext(ContextHandle context)
{
ProcessContext(context.Handle);
}
// ALC_API void ALC_APIENTRY alcProcessContext( ALCcontext *context );
[DllImport(Alc.Lib, EntryPoint = "alcSuspendContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
static extern void SuspendContext(IntPtr context);
/// <summary>This function suspends processing on a specified context. When a context is suspended, changes in OpenAL state will be accepted but will not be processed. A typical use of alcSuspendContext would be to suspend a context, apply all the OpenAL state changes at once, and then call alcProcessContext to apply all the state changes at once. In some cases, this procedure may be more efficient than application of properties in a non-suspended state. In some implementations, process and suspend calls are each a NOP.</summary>
/// <param name="context">a pointer to the context to be suspended.</param>
public static void SuspendContext(ContextHandle context)
{
SuspendContext(context.Handle);
}
// ALC_API void ALC_APIENTRY alcSuspendContext( ALCcontext *context );
[DllImport(Alc.Lib, EntryPoint = "alcDestroyContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
static extern void DestroyContext(IntPtr context);
/// <summary>This function destroys a context.</summary>
/// <param name="context">a pointer to the new context.</param>
public static void DestroyContext(ContextHandle context)
{
DestroyContext(context.Handle);
}
// ALC_API void ALC_APIENTRY alcDestroyContext( ALCcontext *context );
[DllImport(Alc.Lib, EntryPoint = "alcGetCurrentContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
private static extern IntPtr sys_GetCurrentContext();
/// <summary>This function retrieves the current context.</summary>
/// <returns>Returns a pointer to the current context.</returns>
public static ContextHandle GetCurrentContext()
{
return new ContextHandle(sys_GetCurrentContext());
}
// ALC_API ALCcontext * ALC_APIENTRY alcGetCurrentContext( void );
[DllImport(Alc.Lib, EntryPoint = "alcGetContextsDevice", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
static extern IntPtr GetContextsDevice(IntPtr context);
/// <summary>This function retrieves a context's device pointer.</summary>
/// <param name="context">a pointer to a context.</param>
/// <returns>Returns a pointer to the specified context's device.</returns>
public static IntPtr GetContextsDevice(ContextHandle context)
{
return GetContextsDevice(context.Handle);
}
// ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice( ALCcontext *context );
#endregion Context Management
#region Device Management
/// <summary>This function opens a device by name.</summary>
/// <param name="devicename">a null-terminated string describing a device.</param>
/// <returns>Returns a pointer to the opened device. The return value will be NULL if there is an error.</returns>
[DllImport(Alc.Lib, EntryPoint = "alcOpenDevice", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
public static extern IntPtr OpenDevice([In] string devicename);
// ALC_API ALCdevice * ALC_APIENTRY alcOpenDevice( const ALCchar *devicename );
/// <summary>This function closes a device by name.</summary>
/// <param name="device">a pointer to an opened device</param>
/// <returns>True will be returned on success or False on failure. Closing a device will fail if the device contains any contexts or buffers.</returns>
[DllImport(Alc.Lib, EntryPoint = "alcCloseDevice", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
public static extern bool CloseDevice([In] IntPtr device);
// ALC_API ALCboolean ALC_APIENTRY alcCloseDevice( ALCdevice *device );
#endregion Device Management
#region Error support.
/// <summary>This function retrieves the current context error state.</summary>
/// <param name="device">a pointer to the device to retrieve the error state from</param>
/// <returns>Errorcode Int32.</returns>
[DllImport(Alc.Lib, EntryPoint = "alcGetError", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
public static extern AlcError GetError([In] IntPtr device);
// ALC_API ALCenum ALC_APIENTRY alcGetError( ALCdevice *device );
#endregion Error support.
#region Extension support.
/// <summary>This function queries if a specified context extension is available.</summary>
/// <param name="device">a pointer to the device to be queried for an extension.</param>
/// <param name="extname">a null-terminated string describing the extension.</param>
/// <returns>Returns True if the extension is available, False if the extension is not available.</returns>
[DllImport(Alc.Lib, EntryPoint = "alcIsExtensionPresent", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
public static extern bool IsExtensionPresent([In] IntPtr device, [In] string extname);
// ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent( ALCdevice *device, const ALCchar *extname );
/// <summary>This function retrieves the address of a specified context extension function.</summary>
/// <param name="device">a pointer to the device to be queried for the function.</param>
/// <param name="funcname">a null-terminated string describing the function.</param>
/// <returns>Returns the address of the function, or NULL if it is not found.</returns>
[DllImport(Alc.Lib, EntryPoint = "alcGetProcAddress", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
public static extern IntPtr GetProcAddress([In] IntPtr device, [In] string funcname);
// ALC_API void * ALC_APIENTRY alcGetProcAddress( ALCdevice *device, const ALCchar *funcname );
/// <summary>This function retrieves the enum value for a specified enumeration name.</summary>
/// <param name="device">a pointer to the device to be queried.</param>
/// <param name="enumname">a null terminated string describing the enum value.</param>
/// <returns>Returns the enum value described by the enumName string. This is most often used for querying an enum value for an ALC extension.</returns>
[DllImport(Alc.Lib, EntryPoint = "alcGetEnumValue", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
public static extern int GetEnumValue([In] IntPtr device, [In] string enumname);
// ALC_API ALCenum ALC_APIENTRY alcGetEnumValue( ALCdevice *device, const ALCchar *enumname );
#endregion Extension support.
#region Query functions
[DllImport(Alc.Lib, EntryPoint = "alcGetString", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
private static extern IntPtr GetStringPrivate([In] IntPtr device, AlcGetString param);
// ALC_API const ALCchar * ALC_APIENTRY alcGetString( ALCdevice *device, ALCenum param );
/// <summary>This function returns pointers to strings related to the context.</summary>
/// <remarks>
/// ALC_DEFAULT_DEVICE_SPECIFIER will return the name of the default output device.
/// ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER will return the name of the default capture device.
/// ALC_DEVICE_SPECIFIER will return the name of the specified output device if a pointer is supplied, or will return a list of all available devices if a NULL device pointer is supplied. A list is a pointer to a series of strings separated by NULL characters, with the list terminated by two NULL characters. See Enumeration Extension for more details.
/// ALC_CAPTURE_DEVICE_SPECIFIER will return the name of the specified capture device if a pointer is supplied, or will return a list of all available devices if a NULL device pointer is supplied.
/// ALC_EXTENSIONS returns a list of available context extensions, with each extension separated by a space and the list terminated by a NULL character.
/// </remarks>
/// <param name="device">a pointer to the device to be queried.</param>
/// <param name="param">an attribute to be retrieved: ALC_DEFAULT_DEVICE_SPECIFIER, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER, ALC_DEVICE_SPECIFIER, ALC_CAPTURE_DEVICE_SPECIFIER, ALC_EXTENSIONS</param>
/// <returns>A string containing the name of the Device.</returns>
public static string GetString(IntPtr device, AlcGetString param)
{
return Marshal.PtrToStringAnsi(GetStringPrivate(device, param));
}
/// <summary>This function returns a List of strings related to the context.</summary>
/// <remarks>
/// ALC_DEVICE_SPECIFIER will return the name of the specified output device if a pointer is supplied, or will return a list of all available devices if a NULL device pointer is supplied. A list is a pointer to a series of strings separated by NULL characters, with the list terminated by two NULL characters. See Enumeration Extension for more details.
/// ALC_CAPTURE_DEVICE_SPECIFIER will return the name of the specified capture device if a pointer is supplied, or will return a list of all available devices if a NULL device pointer is supplied.
/// ALC_EXTENSIONS returns a list of available context extensions, with each extension separated by a space and the list terminated by a NULL character.
/// </remarks>
/// <param name="device">a pointer to the device to be queried.</param>
/// <param name="param">an attribute to be retrieved: ALC_DEVICE_SPECIFIER, ALC_CAPTURE_DEVICE_SPECIFIER, ALC_ALL_DEVICES_SPECIFIER</param>
/// <returns>A List of strings containing the names of the Devices.</returns>
public static IList<string> GetString(IntPtr device, AlcGetStringList param)
{
List<string> result = new List<string>();
IntPtr t = GetStringPrivate(IntPtr.Zero, (AlcGetString)param);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
byte b;
int offset = 0;
do
{
b = Marshal.ReadByte(t, offset++);
if (b != 0)
sb.Append((char)b);
if (b == 0)
{
result.Add(sb.ToString());
if (Marshal.ReadByte(t, offset) == 0) // offset already properly increased through ++
break; // 2x null
else
sb.Remove(0, sb.Length); // 1x null
}
} while (true);
return (IList<string>)result;
}
[DllImport(Alc.Lib, EntryPoint = "alcGetIntegerv", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
unsafe static extern void GetInteger(IntPtr device, AlcGetInteger param, int size, int* data);
// ALC_API void ALC_APIENTRY alcGetIntegerv( ALCdevice *device, ALCenum param, ALCsizei size, ALCint *buffer );
/// <summary>This function returns integers related to the context.</summary>
/// <param name="device">a pointer to the device to be queried.</param>
/// <param name="param">an attribute to be retrieved: ALC_MAJOR_VERSION, ALC_MINOR_VERSION, ALC_ATTRIBUTES_SIZE, ALC_ALL_ATTRIBUTES</param>
/// <param name="size">the size of the destination buffer provided, in number of integers.</param>
/// <param name="data">a pointer to the buffer to be returned</param>
public static void GetInteger(IntPtr device, AlcGetInteger param, int size, out int data)
{
unsafe
{
fixed (int* data_ptr = &data)
{
GetInteger(device, param, size, data_ptr);
}
}
}
/// <summary>This function returns integers related to the context.</summary>
/// <param name="device">a pointer to the device to be queried.</param>
/// <param name="param">an attribute to be retrieved: ALC_MAJOR_VERSION, ALC_MINOR_VERSION, ALC_ATTRIBUTES_SIZE, ALC_ALL_ATTRIBUTES</param>
/// <param name="size">the size of the destination buffer provided, in number of integers.</param>
/// <param name="data">a pointer to the buffer to be returned</param>
public static void GetInteger(IntPtr device, AlcGetInteger param, int size, int[] data)
{
unsafe
{
fixed (int* data_ptr = data)
{
GetInteger(device, param, size, data_ptr);
}
}
}
#endregion Query functions
#region Capture functions
/// <summary>This function opens a capture device by name. </summary>
/// <param name="devicename">a pointer to a device name string.</param>
/// <param name="frequency">the frequency that the buffer should be captured at.</param>
/// <param name="format">the requested capture buffer format.</param>
/// <param name="buffersize">the size of the capture buffer in samples, not bytes.</param>
/// <returns>Returns the capture device pointer, or NULL on failure.</returns>
[CLSCompliant(false), DllImport(Alc.Lib, EntryPoint = "alcCaptureOpenDevice", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
public static extern IntPtr CaptureOpenDevice(string devicename, uint frequency, ALFormat format, int buffersize);
/// <summary>This function opens a capture device by name. </summary>
/// <param name="devicename">a pointer to a device name string.</param>
/// <param name="frequency">the frequency that the buffer should be captured at.</param>
/// <param name="format">the requested capture buffer format.</param>
/// <param name="buffersize">the size of the capture buffer in samples, not bytes.</param>
/// <returns>Returns the capture device pointer, or NULL on failure.</returns>
[DllImport(Alc.Lib, EntryPoint = "alcCaptureOpenDevice", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
public static extern IntPtr CaptureOpenDevice(string devicename, int frequency, ALFormat format, int buffersize);
// ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice( const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize );
/// <summary>This function closes the specified capture device.</summary>
/// <param name="device">a pointer to a capture device.</param>
/// <returns>Returns True if the close operation was successful, False on failure.</returns>
[DllImport(Alc.Lib, EntryPoint = "alcCaptureCloseDevice", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
public static extern bool CaptureCloseDevice([In] IntPtr device);
// ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice( ALCdevice *device );
/// <summary>This function begins a capture operation.</summary>
/// <remarks>alcCaptureStart will begin recording to an internal ring buffer of the size specified when opening the capture device. The application can then retrieve the number of samples currently available using the ALC_CAPTURE_SAPMPLES token with alcGetIntegerv. When the application determines that enough samples are available for processing, then it can obtain them with a call to alcCaptureSamples.</remarks>
/// <param name="device">a pointer to a capture device.</param>
[DllImport(Alc.Lib, EntryPoint = "alcCaptureStart", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
public static extern void CaptureStart([In] IntPtr device);
// ALC_API void ALC_APIENTRY alcCaptureStart( ALCdevice *device );
/// <summary>This function stops a capture operation.</summary>
/// <param name="device">a pointer to a capture device.</param>
[DllImport(Alc.Lib, EntryPoint = "alcCaptureStop", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
public static extern void CaptureStop([In] IntPtr device);
// ALC_API void ALC_APIENTRY alcCaptureStop( ALCdevice *device );
/// <summary>This function completes a capture operation, and does not block.</summary>
/// <param name="device">a pointer to a capture device.</param>
/// <param name="buffer">a pointer to a buffer, which must be large enough to accommodate the number of samples.</param>
/// <param name="samples">the number of samples to be retrieved.</param>
[DllImport(Alc.Lib, EntryPoint = "alcCaptureSamples", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
public static extern void CaptureSamples(IntPtr device, IntPtr buffer, int samples);
// ALC_API void ALC_APIENTRY alcCaptureSamples( ALCdevice *device, ALCvoid *buffer, ALCsizei samples );
/// <summary>This function completes a capture operation, and does not block.</summary>
/// <param name="device">a pointer to a capture device.</param>
/// <param name="buffer">a reference to a buffer, which must be large enough to accommodate the number of samples.</param>
/// <param name="samples">the number of samples to be retrieved.</param>
public static void CaptureSamples<T>(IntPtr device, ref T buffer, int samples)
where T : struct
{
GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
try
{
CaptureSamples(device, handle.AddrOfPinnedObject(), samples);
}
finally
{
handle.Free();
}
}
/// <summary>This function completes a capture operation, and does not block.</summary>
/// <param name="device">a pointer to a capture device.</param>
/// <param name="buffer">a buffer, which must be large enough to accommodate the number of samples.</param>
/// <param name="samples">the number of samples to be retrieved.</param>
public static void CaptureSamples<T>(IntPtr device, T[] buffer, int samples)
where T : struct
{
CaptureSamples(device, ref buffer[0], samples);
}
/// <summary>This function completes a capture operation, and does not block.</summary>
/// <param name="device">a pointer to a capture device.</param>
/// <param name="buffer">a buffer, which must be large enough to accommodate the number of samples.</param>
/// <param name="samples">the number of samples to be retrieved.</param>
public static void CaptureSamples<T>(IntPtr device, T[,] buffer, int samples)
where T : struct
{
CaptureSamples(device, ref buffer[0, 0], samples);
}
/// <summary>This function completes a capture operation, and does not block.</summary>
/// <param name="device">a pointer to a capture device.</param>
/// <param name="buffer">a buffer, which must be large enough to accommodate the number of samples.</param>
/// <param name="samples">the number of samples to be retrieved.</param>
public static void CaptureSamples<T>(IntPtr device, T[, ,] buffer, int samples)
where T : struct
{
CaptureSamples(device, ref buffer[0, 0, 0], samples);
}
#endregion Capture functions
}
}
// flibit Added This!!!
#pragma warning restore 3021

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

@ -0,0 +1,135 @@
#region --- OpenTK.OpenAL License ---
/* AlcTokens.cs
* C header: \OpenAL 1.1 SDK\include\Alc.h
* Spec: http://www.openal.org/openal_webstf/specs/OpenAL11Specification.pdf
* Copyright (c) 2008 Christoph Brandtner and Stefanos Apostolopoulos
* See license.txt for license details
* http://www.OpenTK.net */
#endregion
using System;
namespace OpenTK.Audio.OpenAL
{
/// <summary>
/// Defines available context attributes.
/// </summary>
public enum AlcContextAttributes : int
{
///<summary>Followed by System.Int32 Hz</summary>
Frequency = 0x1007,
///<summary>Followed by System.Int32 Hz</summary>
Refresh = 0x1008,
///<summary>Followed by AlBoolean.True, or AlBoolean.False</summary>
Sync = 0x1009,
///<summary>Followed by System.Int32 Num of requested Mono (3D) Sources</summary>
MonoSources = 0x1010,
///<summary>Followed by System.Int32 Num of requested Stereo Sources</summary>
StereoSources = 0x1011,
/// <summary>(EFX Extension) This Context property can be passed to OpenAL during Context creation (alcCreateContext) to request a maximum number of Auxiliary Sends desired on each Source. It is not guaranteed that the desired number of sends will be available, so an application should query this property after creating the context using alcGetIntergerv. Default: 2</summary>
EfxMaxAuxiliarySends = 0x20003,
}
/// <summary>
/// Defines OpenAL context errors.
/// </summary>
public enum AlcError : int
{
///<summary>There is no current error.</summary>
NoError = 0,
///<summary>No Device. The device handle or specifier names an inaccessible driver/server.</summary>
InvalidDevice = 0xA001,
///<summary>Invalid context ID. The Context argument does not name a valid context.</summary>
InvalidContext = 0xA002,
///<summary>Bad enum. A token used is not valid, or not applicable.</summary>
InvalidEnum = 0xA003,
///<summary>Bad value. A value (e.g. Attribute) is not valid, or not applicable.</summary>
InvalidValue = 0xA004,
///<summary>Out of memory. Unable to allocate memory.</summary>
OutOfMemory = 0xA005,
}
/// <summary>
/// Defines available parameters for <see cref="OpenTK.Audio.OpenAL.Alc.GetString(IntPtr, AlcGetString)"/>.
/// </summary>
public enum AlcGetString : int
{
///<summary>The specifier string for the default device.</summary>
DefaultDeviceSpecifier = 0x1004,
///<summary>A list of available context extensions separated by spaces.</summary>
Extensions = 0x1006,
///<summary>The name of the default capture device</summary>
CaptureDefaultDeviceSpecifier = 0x311, // ALC_EXT_CAPTURE extension.
/// <summary>a list of the default devices.</summary>
DefaultAllDevicesSpecifier = 0x1012,
// duplicates from AlcGetStringList:
///<summary>Will only return the first Device, not a list. Use AlcGetStringList.CaptureDeviceSpecifier. ALC_EXT_CAPTURE_EXT </summary>
CaptureDeviceSpecifier = 0x310,
///<summary>Will only return the first Device, not a list. Use AlcGetStringList.DeviceSpecifier</summary>
DeviceSpecifier = 0x1005,
/// <summary>Will only return the first Device, not a list. Use AlcGetStringList.AllDevicesSpecifier</summary>
AllDevicesSpecifier = 0x1013,
}
/// <summary>
/// Defines available parameters for <see cref="Alc.GetString(IntPtr, AlcGetStringList)"/>.
/// </summary>
public enum AlcGetStringList : int
{
///<summary>The name of the specified capture device, or a list of all available capture devices if no capture device is specified. ALC_EXT_CAPTURE_EXT </summary>
CaptureDeviceSpecifier = 0x310,
///<summary>The specifier strings for all available devices. ALC_ENUMERATION_EXT</summary>
DeviceSpecifier = 0x1005,
/// <summary>The specifier strings for all available devices. ALC_ENUMERATE_ALL_EXT</summary>
AllDevicesSpecifier = 0x1013,
}
/// <summary>
/// Defines available parameters for <see cref="Alc.GetInteger(IntPtr, AlcGetInteger, int, int[])"/>.
/// </summary>
public enum AlcGetInteger : int
{
///<summary>The specification revision for this implementation (major version). NULL is an acceptable device.</summary>
MajorVersion = 0x1000,
///<summary>The specification revision for this implementation (minor version). NULL is an acceptable device.</summary>
MinorVersion = 0x1001,
///<summary>The size (number of ALCint values) required for a zero-terminated attributes list, for the current context. NULL is an invalid device.</summary>
AttributesSize = 0x1002,
///<summary>Expects a destination of ALC_ATTRIBUTES_SIZE, and provides an attribute list for the current context of the specified device. NULL is an invalid device.</summary>
AllAttributes = 0x1003,
///<summary>The number of capture samples available. NULL is an invalid device.</summary>
CaptureSamples = 0x312,
/// <summary>(EFX Extension) This property can be used by the application to retrieve the Major version number of the Effects Extension supported by this OpenAL implementation. As this is a Context property is should be retrieved using alcGetIntegerv.</summary>
EfxMajorVersion = 0x20001,
/// <summary>(EFX Extension) This property can be used by the application to retrieve the Minor version number of the Effects Extension supported by this OpenAL implementation. As this is a Context property is should be retrieved using alcGetIntegerv.</summary>
EfxMinorVersion = 0x20002,
/// <summary>(EFX Extension) This Context property can be passed to OpenAL during Context creation (alcCreateContext) to request a maximum number of Auxiliary Sends desired on each Source. It is not guaranteed that the desired number of sends will be available, so an application should query this property after creating the context using alcGetIntergerv. Default: 2</summary>
EfxMaxAuxiliarySends = 0x20003,
}
}

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

@ -0,0 +1,291 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2010 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.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Reflection;
// flibit Added This!!!
#pragma warning disable 3021
namespace OpenTK
{
#region BlittableValueType<T>
/// <summary>
/// Checks whether the specified type parameter is a blittable value type.
/// </summary>
/// <remarks>
/// A blittable value type is a struct that only references other value types recursively,
/// which allows it to be passed to unmanaged code directly.
/// </remarks>
public static class BlittableValueType<T>
{
#region Fields
static readonly Type Type;
static readonly int stride;
#endregion
#region Constructors
static BlittableValueType()
{
Type = typeof(T);
if (Type.IsValueType && !Type.IsGenericType)
{
// Does this support generic types? On Mono 2.4.3 it does
// On .Net it doesn't.
// http://msdn.microsoft.com/en-us/library/5s4920fa.aspx
stride = Marshal.SizeOf(typeof(T));
}
}
#endregion
#region Public Members
/// <summary>
/// Gets the size of the type in bytes or 0 for non-blittable types.
/// </summary>
/// <remarks>
/// This property returns 0 for non-blittable types.
/// </remarks>
public static int Stride { get { return stride; } }
#region Check
/// <summary>
/// Checks whether the current typename T is blittable.
/// </summary>
/// <returns>True if T is blittable; false otherwise.</returns>
public static bool Check()
{
return Check(Type);
}
/// <summary>
/// Checks whether type is a blittable value type.
/// </summary>
/// <param name="type">A System.Type to check.</param>
/// <returns>True if T is blittable; false otherwise.</returns>
public static bool Check(Type type)
{
if (!CheckStructLayoutAttribute(type))
Debug.Print("Warning: type {0} does not specify a StructLayoutAttribute with Pack=1. The memory layout of the struct may change between platforms.", type.Name);
return CheckType(type);
}
#endregion
#endregion
#region Private Members
// Checks whether the parameter is a primitive type or consists of primitive types recursively.
// Throws a NotSupportedException if it is not.
static bool CheckType(Type type)
{
//Debug.Print("Checking type {0} (size: {1} bytes).", type.Name, Marshal.SizeOf(type));
if (type.IsPrimitive)
return true;
if (!type.IsValueType)
return false;
FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
Debug.Indent();
foreach (FieldInfo field in fields)
{
if (!CheckType(field.FieldType))
return false;
}
Debug.Unindent();
return Stride != 0;
}
// Checks whether the specified struct defines [StructLayout(LayoutKind.Sequential, Pack=1)]
// or [StructLayout(LayoutKind.Explicit)]
static bool CheckStructLayoutAttribute(Type type)
{
StructLayoutAttribute[] attr = (StructLayoutAttribute[])
type.GetCustomAttributes(typeof(StructLayoutAttribute), true);
if ((attr == null) ||
(attr != null && attr.Length > 0 && attr[0].Value != LayoutKind.Explicit && attr[0].Pack != 1))
return false;
return true;
}
#endregion
}
#endregion
#region BlittableValueType
/// <summary>
/// Checks whether the specified type parameter is a blittable value type.
/// </summary>
/// <remarks>
/// A blittable value type is a struct that only references other value types recursively,
/// which allows it to be passed to unmanaged code directly.
/// </remarks>
public static class BlittableValueType
{
#region Check
/// <summary>
/// Checks whether type is a blittable value type.
/// </summary>
/// <param name="type">An instance of the type to check.</param>
/// <returns>True if T is blittable; false otherwise.</returns>
public static bool Check<T>(T type)
{
return BlittableValueType<T>.Check();
}
/// <summary>
/// Checks whether type is a blittable value type.
/// </summary>
/// <param name="type">An instance of the type to check.</param>
/// <returns>True if T is blittable; false otherwise.</returns>
public static bool Check<T>(T[] type)
{
return BlittableValueType<T>.Check();
}
/// <summary>
/// Checks whether type is a blittable value type.
/// </summary>
/// <param name="type">An instance of the type to check.</param>
/// <returns>True if T is blittable; false otherwise.</returns>
public static bool Check<T>(T[,] type)
{
return BlittableValueType<T>.Check();
}
/// <summary>
/// Checks whether type is a blittable value type.
/// </summary>
/// <param name="type">An instance of the type to check.</param>
/// <returns>True if T is blittable; false otherwise.</returns>
public static bool Check<T>(T[, ,] type)
{
return BlittableValueType<T>.Check();
}
/// <summary>
/// Checks whether type is a blittable value type.
/// </summary>
/// <param name="type">An instance of the type to check.</param>
/// <returns>True if T is blittable; false otherwise.</returns>
[CLSCompliant(false)]
public static bool Check<T>(T[][] type)
{
return BlittableValueType<T>.Check();
}
#endregion
#region StrideOf
/// <summary>
/// Returns the size of the specified value type in bytes or 0 if the type is not blittable.
/// </summary>
/// <typeparam name="T">The value type. Must be blittable.</typeparam>
/// <param name="type">An instance of the value type.</param>
/// <returns>An integer, specifying the size of the type in bytes.</returns>
/// <exception cref="System.ArgumentException">Occurs when type is not blittable.</exception>
public static int StrideOf<T>(T type)
{
if (!Check(type))
throw new ArgumentException("type");
return BlittableValueType<T>.Stride;
}
/// <summary>
/// Returns the size of a single array element in bytes or 0 if the element is not blittable.
/// </summary>
/// <typeparam name="T">The value type.</typeparam>
/// <param name="type">An instance of the value type.</param>
/// <returns>An integer, specifying the size of the type in bytes.</returns>
/// <exception cref="System.ArgumentException">Occurs when type is not blittable.</exception>
public static int StrideOf<T>(T[] type)
{
if (!Check(type))
throw new ArgumentException("type");
return BlittableValueType<T>.Stride;
}
/// <summary>
/// Returns the size of a single array element in bytes or 0 if the element is not blittable.
/// </summary>
/// <typeparam name="T">The value type.</typeparam>
/// <param name="type">An instance of the value type.</param>
/// <returns>An integer, specifying the size of the type in bytes.</returns>
/// <exception cref="System.ArgumentException">Occurs when type is not blittable.</exception>
public static int StrideOf<T>(T[,] type)
{
if (!Check(type))
throw new ArgumentException("type");
return BlittableValueType<T>.Stride;
}
/// <summary>
/// Returns the size of a single array element in bytes or 0 if the element is not blittable.
/// </summary>
/// <typeparam name="T">The value type.</typeparam>
/// <param name="type">An instance of the value type.</param>
/// <returns>An integer, specifying the size of the type in bytes.</returns>
/// <exception cref="System.ArgumentException">Occurs when type is not blittable.</exception>
public static int StrideOf<T>(T[, ,] type)
{
if (!Check(type))
throw new ArgumentException("type");
return BlittableValueType<T>.Stride;
}
#endregion
}
#endregion
}
// flibit Added This!!!
#pragma warning restore 3021

177
src/MiniTK/ContextHandle.cs Normal file
Просмотреть файл

@ -0,0 +1,177 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2006-2008 the OpenTK Team.
* This notice may not be removed from any source distribution.
* See license.txt for licensing detailed licensing details.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenTK
{
/// <summary>
/// Represents a handle to an OpenGL or OpenAL context.
/// </summary>
public struct ContextHandle : IComparable<ContextHandle>, IEquatable<ContextHandle>
{
#region Fields
IntPtr handle;
/// <summary>
/// Gets a System.IntPtr that represents the handle of this ContextHandle.
/// </summary>
public IntPtr Handle { get { return handle; } }
/// <summary>A read-only field that represents a handle that has been initialized to zero.</summary>
public static readonly ContextHandle Zero = new ContextHandle(IntPtr.Zero);
#endregion
#region Constructors
/// <summary>
/// Constructs a new instance with the specified handle.
/// </summary>
/// <param name="h">A System.IntPtr containing the value for this instance.</param>
public ContextHandle(IntPtr h) { handle = h; }
#endregion
#region Public Members
#region ToString
/// <summary>
/// Converts this instance to its equivalent string representation.
/// </summary>
/// <returns>A System.String that contains the string representation of this instance.</returns>
public override string ToString()
{
return Handle.ToString();
}
#endregion
#region Equals
/// <summary>
/// Compares this instance to the specified object.
/// </summary>
/// <param name="obj">The System.Object to compare to.</param>
/// <returns>True if obj is a ContextHandle that is equal to this instance; false otherwise.</returns>
public override bool Equals(object obj)
{
if (obj is ContextHandle)
return this.Equals((ContextHandle)obj);
return false;
}
#endregion
#region GetHashCode
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A System.Int32 with the hash code of this instance.</returns>
public override int GetHashCode()
{
return Handle.GetHashCode();
}
#endregion
#region public static explicit operator IntPtr(ContextHandle c)
/// <summary>
/// Converts the specified ContextHandle to the equivalent IntPtr.
/// </summary>
/// <param name="c">The ContextHandle to convert.</param>
/// <returns>A System.IntPtr equivalent to the specified ContextHandle.</returns>
public static explicit operator IntPtr(ContextHandle c)
{
return c != ContextHandle.Zero ? c.handle : IntPtr.Zero;
}
#endregion
#region public static explicit operator ContextHandle(IntPtr p)
/// <summary>
/// Converts the specified IntPtr to the equivalent ContextHandle.
/// </summary>
/// <param name="p">The System.IntPtr to convert.</param>
/// <returns>A ContextHandle equivalent to the specified IntPtr.</returns>
public static explicit operator ContextHandle(IntPtr p)
{
return new ContextHandle(p);
}
#endregion
#region public static bool operator ==(ContextHandle left, ContextHandle right)
/// <summary>
/// Compares two ContextHandles for equality.
/// </summary>
/// <param name="left">The ContextHandle to compare.</param>
/// <param name="right">The ContextHandle to compare to.</param>
/// <returns>True if left is equal to right; false otherwise.</returns>
public static bool operator ==(ContextHandle left, ContextHandle right)
{
return left.Equals(right);
}
#endregion
#region public static bool operator !=(ContextHandle left, ContextHandle right)
/// <summary>
/// Compares two ContextHandles for inequality.
/// </summary>
/// <param name="left">The ContextHandle to compare.</param>
/// <param name="right">The ContextHandle to compare to.</param>
/// <returns>True if left is not equal to right; false otherwise.</returns>
public static bool operator !=(ContextHandle left, ContextHandle right)
{
return !left.Equals(right);
}
#endregion
#endregion
#region IComparable<ContextHandle> Members
/// <summary>
/// Compares the numerical value of this instance to the specified ContextHandle and
/// returns a value indicating their relative order.
/// </summary>
/// <param name="other">The ContextHandle to compare to.</param>
/// <returns>Less than 0, if this instance is less than other; 0 if both are equal; Greater than 0 if other is greater than this instance.</returns>
public int CompareTo(ContextHandle other)
{
unsafe { return (int)((int*)other.handle.ToPointer() - (int*)this.handle.ToPointer()); }
}
#endregion
#region IEquatable<ContextHandle> Members
/// <summary>
/// Compares this instance to the specified ContextHandle for equality.
/// </summary>
/// <param name="other">The ContextHandle to compare to.</param>
/// <returns>True if this instance is equal to other; false otherwise.</returns>
public bool Equals(ContextHandle other)
{
return Handle == other.Handle;
}
#endregion
}
}

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

@ -0,0 +1,261 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2006-2008 the OpenTK Team.
* This notice may not be removed from any source distribution.
* See license.txt for licensing detailed licensing details.
*
* Contributions by Georg W<EFBFBD>chter.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenTK
{
/// <summary>
/// Represents a bezier curve with as many points as you want.
/// </summary>
[Serializable]
public struct BezierCurve
{
#region Fields
private List<Vector2> points;
/// <summary>
/// The parallel value.
/// </summary>
/// <remarks>This value defines whether the curve should be calculated as a
/// parallel curve to the original bezier curve. A value of 0.0f represents
/// the original curve, 5.0f i.e. stands for a curve that has always a distance
/// of 5.0f to the orignal curve at any point.</remarks>
public float Parallel;
#endregion
#region Properties
/// <summary>
/// Gets the points of this curve.
/// </summary>
/// <remarks>The first point and the last points represent the anchor points.</remarks>
public IList<Vector2> Points
{
get
{
return points;
}
}
#endregion
#region Constructors
/// <summary>
/// Constructs a new <see cref="BezierCurve"/>.
/// </summary>
/// <param name="points">The points.</param>
public BezierCurve(IEnumerable<Vector2> points)
{
if (points == null)
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
this.points = new List<Vector2>(points);
this.Parallel = 0.0f;
}
/// <summary>
/// Constructs a new <see cref="BezierCurve"/>.
/// </summary>
/// <param name="points">The points.</param>
public BezierCurve(params Vector2[] points)
{
if (points == null)
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
this.points = new List<Vector2>(points);
this.Parallel = 0.0f;
}
/// <summary>
/// Constructs a new <see cref="BezierCurve"/>.
/// </summary>
/// <param name="parallel">The parallel value.</param>
/// <param name="points">The points.</param>
public BezierCurve(float parallel, params Vector2[] points)
{
if (points == null)
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
this.Parallel = parallel;
this.points = new List<Vector2>(points);
}
/// <summary>
/// Constructs a new <see cref="BezierCurve"/>.
/// </summary>
/// <param name="parallel">The parallel value.</param>
/// <param name="points">The points.</param>
public BezierCurve(float parallel, IEnumerable<Vector2> points)
{
if (points == null)
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
this.Parallel = parallel;
this.points = new List<Vector2>(points);
}
#endregion
#region Functions
/// <summary>
/// Calculates the point with the specified t.
/// </summary>
/// <param name="t">The t value, between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
public Vector2 CalculatePoint(float t)
{
return BezierCurve.CalculatePoint(points, t, Parallel);
}
/// <summary>
/// Calculates the length of this bezier curve.
/// </summary>
/// <param name="precision">The precision.</param>
/// <returns>Length of curve.</returns>
/// <remarks>The precision gets better as the <paramref name="precision"/>
/// value gets smaller.</remarks>
public float CalculateLength(float precision)
{
return BezierCurve.CalculateLength(points, precision, Parallel);
}
#region Static methods
/// <summary>
/// Calculates the length of the specified bezier curve.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="precision">The precision value.</param>
/// <returns>The precision gets better as the <paramref name="precision"/>
/// value gets smaller.</returns>
public static float CalculateLength(IList<Vector2> points, float precision)
{
return BezierCurve.CalculateLength(points, precision, 0.0f);
}
/// <summary>
/// Calculates the length of the specified bezier curve.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="precision">The precision value.</param>
/// <param name="parallel">The parallel value.</param>
/// <returns>Length of curve.</returns>
/// <remarks><para>The precision gets better as the <paramref name="precision"/>
/// value gets smaller.</para>
/// <para>The <paramref name="parallel"/> parameter defines whether the curve should be calculated as a
/// parallel curve to the original bezier curve. A value of 0.0f represents
/// the original curve, 5.0f represents a curve that has always a distance
/// of 5.0f to the orignal curve.</para></remarks>
public static float CalculateLength(IList<Vector2> points, float precision, float parallel)
{
float length = 0.0f;
Vector2 old = BezierCurve.CalculatePoint(points, 0.0f, parallel);
for (float i = precision; i < (1.0f + precision); i += precision)
{
Vector2 n = CalculatePoint(points, i, parallel);
length += (n - old).Length;
old = n;
}
return length;
}
/// <summary>
/// Calculates the point on the given bezier curve with the specified t parameter.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="t">The t parameter, a value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
public static Vector2 CalculatePoint(IList<Vector2> points, float t)
{
return BezierCurve.CalculatePoint(points, t, 0.0f);
}
/// <summary>
/// Calculates the point on the given bezier curve with the specified t parameter.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="t">The t parameter, a value between 0.0f and 1.0f.</param>
/// <param name="parallel">The parallel value.</param>
/// <returns>Resulting point.</returns>
/// <remarks>The <paramref name="parallel"/> parameter defines whether the curve should be calculated as a
/// parallel curve to the original bezier curve. A value of 0.0f represents
/// the original curve, 5.0f represents a curve that has always a distance
/// of 5.0f to the orignal curve.</remarks>
public static Vector2 CalculatePoint(IList<Vector2> points, float t, float parallel)
{
Vector2 r = new Vector2();
double c = 1.0d - (double)t;
float temp;
int i = 0;
foreach (Vector2 pt in points)
{
temp = (float)MathHelper.BinomialCoefficient(points.Count - 1, i) * (float)(System.Math.Pow(t, i) *
System.Math.Pow(c, (points.Count - 1) - i));
r.X += temp * pt.X;
r.Y += temp * pt.Y;
i++;
}
if (parallel == 0.0f)
return r;
Vector2 perpendicular = new Vector2();
if (t != 0.0f)
perpendicular = r - BezierCurve.CalculatePointOfDerivative(points, t);
else
perpendicular = points[1] - points[0];
return r + Vector2.Normalize(perpendicular).PerpendicularRight * parallel;
}
/// <summary>
/// Calculates the point with the specified t of the derivative of the given bezier function.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="t">The t parameter, value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
private static Vector2 CalculatePointOfDerivative(IList<Vector2> points, float t)
{
Vector2 r = new Vector2();
double c = 1.0d - (double)t;
float temp;
int i = 0;
foreach (Vector2 pt in points)
{
temp = (float)MathHelper.BinomialCoefficient(points.Count - 2, i) * (float)(System.Math.Pow(t, i) *
System.Math.Pow(c, (points.Count - 2) - i));
r.X += temp * pt.X;
r.Y += temp * pt.Y;
i++;
}
return r;
}
#endregion
#endregion
}
}

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

@ -0,0 +1,163 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2006-2008 the OpenTK Team.
* This notice may not be removed from any source distribution.
* See license.txt for licensing detailed licensing details.
*
* Contributions by Georg W<EFBFBD>chter.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenTK
{
/// <summary>
/// Represents a cubic bezier curve with two anchor and two control points.
/// </summary>
[Serializable]
public struct BezierCurveCubic
{
#region Fields
/// <summary>
/// Start anchor point.
/// </summary>
public Vector2 StartAnchor;
/// <summary>
/// End anchor point.
/// </summary>
public Vector2 EndAnchor;
/// <summary>
/// First control point, controls the direction of the curve start.
/// </summary>
public Vector2 FirstControlPoint;
/// <summary>
/// Second control point, controls the direction of the curve end.
/// </summary>
public Vector2 SecondControlPoint;
/// <summary>
/// Gets or sets the parallel value.
/// </summary>
/// <remarks>This value defines whether the curve should be calculated as a
/// parallel curve to the original bezier curve. A value of 0.0f represents
/// the original curve, 5.0f i.e. stands for a curve that has always a distance
/// of 5.f to the orignal curve at any point.</remarks>
public float Parallel;
#endregion
#region Constructors
/// <summary>
/// Constructs a new <see cref="BezierCurveCubic"/>.
/// </summary>
/// <param name="startAnchor">The start anchor point.</param>
/// <param name="endAnchor">The end anchor point.</param>
/// <param name="firstControlPoint">The first control point.</param>
/// <param name="secondControlPoint">The second control point.</param>
public BezierCurveCubic(Vector2 startAnchor, Vector2 endAnchor, Vector2 firstControlPoint, Vector2 secondControlPoint)
{
this.StartAnchor = startAnchor;
this.EndAnchor = endAnchor;
this.FirstControlPoint = firstControlPoint;
this.SecondControlPoint = secondControlPoint;
this.Parallel = 0.0f;
}
/// <summary>
/// Constructs a new <see cref="BezierCurveCubic"/>.
/// </summary>
/// <param name="parallel">The parallel value.</param>
/// <param name="startAnchor">The start anchor point.</param>
/// <param name="endAnchor">The end anchor point.</param>
/// <param name="firstControlPoint">The first control point.</param>
/// <param name="secondControlPoint">The second control point.</param>
public BezierCurveCubic(float parallel, Vector2 startAnchor, Vector2 endAnchor, Vector2 firstControlPoint, Vector2 secondControlPoint)
{
this.Parallel = parallel;
this.StartAnchor = startAnchor;
this.EndAnchor = endAnchor;
this.FirstControlPoint = firstControlPoint;
this.SecondControlPoint = secondControlPoint;
}
#endregion
#region Functions
/// <summary>
/// Calculates the point with the specified t.
/// </summary>
/// <param name="t">The t value, between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
public Vector2 CalculatePoint(float t)
{
Vector2 r = new Vector2();
float c = 1.0f - t;
r.X = (StartAnchor.X * c * c * c) + (FirstControlPoint.X * 3 * t * c * c) + (SecondControlPoint.X * 3 * t * t * c)
+ EndAnchor.X * t * t * t;
r.Y = (StartAnchor.Y * c * c * c) + (FirstControlPoint.Y * 3 * t * c * c) + (SecondControlPoint.Y * 3 * t * t * c)
+ EndAnchor.Y * t * t * t;
if (Parallel == 0.0f)
return r;
Vector2 perpendicular = new Vector2();
if (t == 0.0f)
perpendicular = FirstControlPoint - StartAnchor;
else
perpendicular = r - CalculatePointOfDerivative(t);
return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel;
}
/// <summary>
/// Calculates the point with the specified t of the derivative of this function.
/// </summary>
/// <param name="t">The t, value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
private Vector2 CalculatePointOfDerivative(float t)
{
Vector2 r = new Vector2();
float c = 1.0f - t;
r.X = (c * c * StartAnchor.X) + (2 * t * c * FirstControlPoint.X) + (t * t * SecondControlPoint.X);
r.Y = (c * c * StartAnchor.Y) + (2 * t * c * FirstControlPoint.Y) + (t * t * SecondControlPoint.Y);
return r;
}
/// <summary>
/// Calculates the length of this bezier curve.
/// </summary>
/// <param name="precision">The precision.</param>
/// <returns>Length of the curve.</returns>
/// <remarks>The precision gets better when the <paramref name="precision"/>
/// value gets smaller.</remarks>
public float CalculateLength(float precision)
{
float length = 0.0f;
Vector2 old = CalculatePoint(0.0f);
for (float i = precision; i < (1.0f + precision); i += precision)
{
Vector2 n = CalculatePoint(i);
length += (n - old).Length;
old = n;
}
return length;
}
#endregion
}
}

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

@ -0,0 +1,151 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2006-2008 the OpenTK Team.
* This notice may not be removed from any source distribution.
* See license.txt for licensing detailed licensing details.
*
* Contributions by Georg W<EFBFBD>chter.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenTK
{
/// <summary>
/// Represents a quadric bezier curve with two anchor and one control point.
/// </summary>
[Serializable]
public struct BezierCurveQuadric
{
#region Fields
/// <summary>
/// Start anchor point.
/// </summary>
public Vector2 StartAnchor;
/// <summary>
/// End anchor point.
/// </summary>
public Vector2 EndAnchor;
/// <summary>
/// Control point, controls the direction of both endings of the curve.
/// </summary>
public Vector2 ControlPoint;
/// <summary>
/// The parallel value.
/// </summary>
/// <remarks>This value defines whether the curve should be calculated as a
/// parallel curve to the original bezier curve. A value of 0.0f represents
/// the original curve, 5.0f i.e. stands for a curve that has always a distance
/// of 5.f to the orignal curve at any point.</remarks>
public float Parallel;
#endregion
#region Constructors
/// <summary>
/// Constructs a new <see cref="BezierCurveQuadric"/>.
/// </summary>
/// <param name="startAnchor">The start anchor.</param>
/// <param name="endAnchor">The end anchor.</param>
/// <param name="controlPoint">The control point.</param>
public BezierCurveQuadric(Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint)
{
this.StartAnchor = startAnchor;
this.EndAnchor = endAnchor;
this.ControlPoint = controlPoint;
this.Parallel = 0.0f;
}
/// <summary>
/// Constructs a new <see cref="BezierCurveQuadric"/>.
/// </summary>
/// <param name="parallel">The parallel value.</param>
/// <param name="startAnchor">The start anchor.</param>
/// <param name="endAnchor">The end anchor.</param>
/// <param name="controlPoint">The control point.</param>
public BezierCurveQuadric(float parallel, Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint)
{
this.Parallel = parallel;
this.StartAnchor = startAnchor;
this.EndAnchor = endAnchor;
this.ControlPoint = controlPoint;
}
#endregion
#region Functions
/// <summary>
/// Calculates the point with the specified t.
/// </summary>
/// <param name="t">The t value, between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
public Vector2 CalculatePoint(float t)
{
Vector2 r = new Vector2();
float c = 1.0f - t;
r.X = (c * c * StartAnchor.X) + (2 * t * c * ControlPoint.X) + (t * t * EndAnchor.X);
r.Y = (c * c * StartAnchor.Y) + (2 * t * c * ControlPoint.Y) + (t * t * EndAnchor.Y);
if (Parallel == 0.0f)
return r;
Vector2 perpendicular = new Vector2();
if (t == 0.0f)
perpendicular = ControlPoint - StartAnchor;
else
perpendicular = r - CalculatePointOfDerivative(t);
return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel;
}
/// <summary>
/// Calculates the point with the specified t of the derivative of this function.
/// </summary>
/// <param name="t">The t, value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
private Vector2 CalculatePointOfDerivative(float t)
{
Vector2 r = new Vector2();
r.X = (1.0f - t) * StartAnchor.X + t * ControlPoint.X;
r.Y = (1.0f - t) * StartAnchor.Y + t * ControlPoint.Y;
return r;
}
/// <summary>
/// Calculates the length of this bezier curve.
/// </summary>
/// <param name="precision">The precision.</param>
/// <returns>Length of curve.</returns>
/// <remarks>The precision gets better when the <paramref name="precision"/>
/// value gets smaller.</remarks>
public float CalculateLength(float precision)
{
float length = 0.0f;
Vector2 old = CalculatePoint(0.0f);
for (float i = precision; i < (1.0f + precision); i += precision)
{
Vector2 n = CalculatePoint(i);
length += (n - old).Length;
old = n;
}
return length;
}
#endregion
}
}

99
src/MiniTK/Math/Box2.cs Normal file
Просмотреть файл

@ -0,0 +1,99 @@
#region --- License ---
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
* See license.txt for license info
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace OpenTK
{
/// <summary>
/// Defines a 2d box (rectangle).
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct Box2
{
/// <summary>
/// The left boundary of the structure.
/// </summary>
public float Left;
/// <summary>
/// The right boundary of the structure.
/// </summary>
public float Right;
/// <summary>
/// The top boundary of the structure.
/// </summary>
public float Top;
/// <summary>
/// The bottom boundary of the structure.
/// </summary>
public float Bottom;
/// <summary>
/// Constructs a new Box2 with the specified dimensions.
/// </summary>
/// <param name="topLeft">AnOpenTK.Vector2 describing the top-left corner of the Box2.</param>
/// <param name="bottomRight">An OpenTK.Vector2 describing the bottom-right corner of the Box2.</param>
public Box2(Vector2 topLeft, Vector2 bottomRight)
{
Left = topLeft.X;
Top = topLeft.Y;
Right = bottomRight.X;
Bottom = bottomRight.Y;
}
/// <summary>
/// Constructs a new Box2 with the specified dimensions.
/// </summary>
/// <param name="left">The position of the left boundary.</param>
/// <param name="top">The position of the top boundary.</param>
/// <param name="right">The position of the right boundary.</param>
/// <param name="bottom">The position of the bottom boundary.</param>
public Box2(float left, float top, float right, float bottom)
{
Left = left;
Top = top;
Right = right;
Bottom = bottom;
}
/// <summary>
/// Creates a new Box2 with the specified dimensions.
/// </summary>
/// <param name="top">The position of the top boundary.</param>
/// <param name="left">The position of the left boundary.</param>
/// <param name="right">The position of the right boundary.</param>
/// <param name="bottom">The position of the bottom boundary.</param>
/// <returns>A new OpenTK.Box2 with the specfied dimensions.</returns>
public static Box2 FromTLRB(float top, float left, float right, float bottom)
{
return new Box2(left, top, right, bottom);
}
/// <summary>
/// Gets a float describing the width of the Box2 structure.
/// </summary>
public float Width { get { return (float)System.Math.Abs(Right - Left); } }
/// <summary>
/// Gets a float describing the height of the Box2 structure.
/// </summary>
public float Height { get { return (float)System.Math.Abs(Bottom - Top); } }
/// <summary>
/// Returns a <see cref="System.String"/> describing the current instance.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return String.Format("({0},{1})-({2},{3})", Left, Top, Right, Bottom);
}
}
}

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

@ -0,0 +1,371 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2006-2008 the OpenTK Team.
* This notice may not be removed from any source distribution.
* See license.txt for licensing detailed licensing details.
*
* Contributions by Andy Gill, James Talton and Georg Wächter.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenTK
{
/// <summary>
/// Contains mathematical functions for the OpenTK.Math toolkit.
/// </summary>
[Obsolete("Use OpenTK.MathHelper instead.")]
public static class Functions
{
#region NextPowerOfTwo
/// <summary>
/// Returns the next power of two that is larger than the specified number.
/// </summary>
/// <param name="n">The specified number.</param>
/// <returns>The next power of two.</returns>
public static long NextPowerOfTwo(long n)
{
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
return (long)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
/// <summary>
/// Returns the next power of two that is larger than the specified number.
/// </summary>
/// <param name="n">The specified number.</param>
/// <returns>The next power of two.</returns>
public static int NextPowerOfTwo(int n)
{
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
return (int)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
/// <summary>
/// Returns the next power of two that is larger than the specified number.
/// </summary>
/// <param name="n">The specified number.</param>
/// <returns>The next power of two.</returns>
public static float NextPowerOfTwo(float n)
{
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
/// <summary>
/// Returns the next power of two that is larger than the specified number.
/// </summary>
/// <param name="n">The specified number.</param>
/// <returns>The next power of two.</returns>
public static double NextPowerOfTwo(double n)
{
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
return System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
#endregion
#region Factorial
/// <summary>Calculates the factorial of a given natural number.
/// </summary>
/// <param name="n">The number.</param>
/// <returns>n!</returns>
public static long Factorial(int n)
{
long result = 1;
for (; n > 1; n--)
result *= n;
return result;
}
#endregion
#region BinomialCoefficient
/// <summary>
/// Calculates the binomial coefficient <paramref name="n"/> above <paramref name="k"/>.
/// </summary>
/// <param name="n">The n.</param>
/// <param name="k">The k.</param>
/// <returns>n! / (k! * (n - k)!)</returns>
public static long BinomialCoefficient(int n, int k)
{
return Factorial(n) / (Factorial(k) * Factorial(n - k));
}
#endregion
#region InverseSqrtFast
/// <summary>
/// Returns an approximation of the inverse square root of left number.
/// </summary>
/// <param name="x">A number.</param>
/// <returns>An approximation of the inverse square root of the specified number, with an upper error bound of 0.001</returns>
/// <remarks>
/// This is an improved implementation of the the method known as Carmack's inverse square root
/// which is found in the Quake III source code. This implementation comes from
/// http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see
/// http://www.beyond3d.com/content/articles/8/
/// </remarks>
public static float InverseSqrtFast(float x)
{
unsafe
{
float xhalf = 0.5f * x;
int i = *(int*)&x; // Read bits as integer.
i = 0x5f375a86 - (i >> 1); // Make an initial guess for Newton-Raphson approximation
x = *(float*)&i; // Convert bits back to float
x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step.
return x;
}
}
/// <summary>
/// Returns an approximation of the inverse square root of left number.
/// </summary>
/// <param name="x">A number.</param>
/// <returns>An approximation of the inverse square root of the specified number, with an upper error bound of 0.001</returns>
/// <remarks>
/// This is an improved implementation of the the method known as Carmack's inverse square root
/// which is found in the Quake III source code. This implementation comes from
/// http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see
/// http://www.beyond3d.com/content/articles/8/
/// </remarks>
public static double InverseSqrtFast(double x)
{
return InverseSqrtFast((float)x);
// TODO: The following code is wrong. Fix it, to improve precision.
#if false
unsafe
{
double xhalf = 0.5f * x;
int i = *(int*)&x; // Read bits as integer.
i = 0x5f375a86 - (i >> 1); // Make an initial guess for Newton-Raphson approximation
x = *(float*)&i; // Convert bits back to float
x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step.
return x;
}
#endif
}
#endregion
#region DegreesToRadians
/// <summary>
/// Convert degrees to radians
/// </summary>
/// <param name="degrees">An angle in degrees</param>
/// <returns>The angle expressed in radians</returns>
public static float DegreesToRadians(float degrees)
{
const float degToRad = (float)System.Math.PI / 180.0f;
return degrees * degToRad;
}
/// <summary>
/// Convert radians to degrees
/// </summary>
/// <param name="radians">An angle in radians</param>
/// <returns>The angle expressed in degrees</returns>
public static float RadiansToDegrees(float radians)
{
const float radToDeg = 180.0f / (float)System.Math.PI;
return radians * radToDeg;
}
#endregion
#region Mathematical constants
/// <summary>
/// Obsolete. Do not use.
/// </summary>
public static readonly float PIF = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930382f;
/// <summary>
/// Obsolete. Do not use.
/// </summary>
public static readonly float RTODF = 180.0f / PIF;
/// <summary>
/// Obsolete. Do not use.
/// </summary>
public static readonly float DTORF = PIF / 180.0f;
/// <summary>
/// Obsolete. Do not use.
/// </summary>
public static readonly double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930382d;
/// <summary>
/// Obsolete. Do not use.
/// </summary>
public static readonly double RTOD = 180.0d / PIF;
/// <summary>
/// Obsolete. Do not use.
/// </summary>
public static readonly double DTOR = PIF / 180.0d;
#endregion
#region Swap
/// <summary>
/// Swaps two float values.
/// </summary>
/// <param name="a">The first value.</param>
/// <param name="b">The second value.</param>
public static void Swap(ref double a, ref double b)
{
double temp = a;
a = b;
b = temp;
}
/// <summary>
/// Swaps two float values.
/// </summary>
/// <param name="a">The first value.</param>
/// <param name="b">The second value.</param>
public static void Swap(ref float a, ref float b)
{
float temp = a;
a = b;
b = temp;
}
#endregion
}
#if false
public static partial class Math
{
#region --- Vectors ---
#region --- Addition ---
/// <summary>
/// Adds the given Vector2 to the current Vector3.
/// </summary>
/// <param name="right">The right operand of the addition.</param>
/// <returns>A new Vector3 containing the result of the addition.</returns>
public static Vector2 Add(Vector2 left, Vector2 right)
{
return new Vector2(left).Add(right);
}
/// <summary>
/// Adds the given Vector3 to the current Vector3.
/// </summary>
/// <param name="right">The right operand of the addition.</param>
/// <returns>A new Vector3 containing the result of the addition.</returns>
public static Vector3 Add(Vector2 left, Vector3 right)
{
return new Vector3(left).Add(right);
}
/// <summary>
/// Adds the given Vector4 to the current Vector3. W-coordinate remains unaffected.
/// </summary>
/// <param name="right">The right operand of the addition.</param>
/// <returns>A new Vector4 containing the result of the addition.</returns>
public static Vector4 Add(Vector2 left, Vector4 right)
{
return new Vector4(left).Add(right);
}
/// <summary>
/// Adds the given Vector2 to the current Vector3.
/// </summary>
/// <param name="right">The right operand of the addition.</param>
/// <returns>A new Vector3 containing the result of the addition.</returns>
public static Vector3 Add(Vector3 left, Vector2 right)
{
return new Vector3(left).Add(right);
}
/// <summary>
/// Adds the given Vector3 to the current Vector3.
/// </summary>
/// <param name="right">The right operand of the addition.</param>
/// <returns>A new Vector3 containing the result of the addition.</returns>
public static Vector3 Add(Vector3 left, Vector3 right)
{
return new Vector3(left).Add(right);
}
/// <summary>
/// Adds the given Vector4 to the current Vector3. W-coordinate remains unaffected.
/// </summary>
/// <param name="right">The right operand of the addition.</param>
/// <returns>A new Vector4 containing the result of the addition.</returns>
public static Vector4 Add(Vector3 left, Vector4 right)
{
return new Vector4(left).Add(right);
}
/// <summary>
/// Adds the given Vector2 to the current Vector3.
/// </summary>
/// <param name="right">The right operand of the addition.</param>
/// <returns>A new Vector3 containing the result of the addition.</returns>
public static Vector4 Add(Vector4 left, Vector2 right)
{
return new Vector4(left).Add(right);
}
/// <summary>
/// Adds the given Vector3 to the current Vector3.
/// </summary>
/// <param name="right">The right operand of the addition.</param>
/// <returns>A new Vector3 containing the result of the addition.</returns>
public static Vector4 Add(Vector4 left, Vector3 right)
{
return new Vector4(left).Add(right);
}
/// <summary>
/// Adds the given Vector4 to the current Vector3. W-coordinate remains unaffected.
/// </summary>
/// <param name="right">The right operand of the addition.</param>
/// <returns>A new Vector4 containing the result of the addition.</returns>
public static Vector4 Add(Vector4 left, Vector4 right)
{
return new Vector4(left).Add(right);
}
#endregion
#region --- Subtraction ---
#endregion
#region --- Cross ---
/// <summary>
/// Computes the cross product between the current and the given Vector3. The current Vector3 is set to the result of the computation.
/// </summary>
/// <param name="right">The right operand of the cross product</param>
/// <returns>The current </returns>
public static Vector3 Cross(Vector3 left, Vector3 right)
{
return new Vector3(left).Cross(right);
}
#endregion
#endregion
}
#endif
}

588
src/MiniTK/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
{
/// <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 positive infinity.");
if (Single.IsNegativeInfinity(f)) throw new ArithmeticException("Half: Input is negative 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.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.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.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.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.Half value.
/// </summary>
/// <param name="other">OpenTK.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.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.Half.NaN), OpenTK.Half.PositiveInfinity, or
/// OpenTK.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.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
}
}

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

@ -0,0 +1,293 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2006-2008 the OpenTK Team.
* This notice may not be removed from any source distribution.
* See license.txt for licensing detailed licensing details.
*
* Contributions by Andy Gill, James Talton and Georg Wächter.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenTK
{
/// <summary>
/// Contains common mathematical functions and constants.
/// </summary>
public static class MathHelper
{
#region Fields
/// <summary>
/// Defines the value of Pi as a <see cref="System.Single"/>.
/// </summary>
public const float Pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930382f;
/// <summary>
/// Defines the value of Pi divided by two as a <see cref="System.Single"/>.
/// </summary>
public const float PiOver2 = Pi / 2;
/// <summary>
/// Defines the value of Pi divided by three as a <see cref="System.Single"/>.
/// </summary>
public const float PiOver3 = Pi / 3;
/// <summary>
/// Definesthe value of Pi divided by four as a <see cref="System.Single"/>.
/// </summary>
public const float PiOver4 = Pi / 4;
/// <summary>
/// Defines the value of Pi divided by six as a <see cref="System.Single"/>.
/// </summary>
public const float PiOver6 = Pi / 6;
/// <summary>
/// Defines the value of Pi multiplied by two as a <see cref="System.Single"/>.
/// </summary>
public const float TwoPi = 2 * Pi;
/// <summary>
/// Defines the value of Pi multiplied by 3 and divided by two as a <see cref="System.Single"/>.
/// </summary>
public const float ThreePiOver2 = 3 * Pi / 2;
/// <summary>
/// Defines the value of E as a <see cref="System.Single"/>.
/// </summary>
public const float E = 2.71828182845904523536f;
/// <summary>
/// Defines the base-10 logarithm of E.
/// </summary>
public const float Log10E = 0.434294482f;
/// <summary>
/// Defines the base-2 logarithm of E.
/// </summary>
public const float Log2E = 1.442695041f;
#endregion
#region Public Members
#region NextPowerOfTwo
/// <summary>
/// Returns the next power of two that is larger than the specified number.
/// </summary>
/// <param name="n">The specified number.</param>
/// <returns>The next power of two.</returns>
public static long NextPowerOfTwo(long n)
{
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
return (long)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
/// <summary>
/// Returns the next power of two that is larger than the specified number.
/// </summary>
/// <param name="n">The specified number.</param>
/// <returns>The next power of two.</returns>
public static int NextPowerOfTwo(int n)
{
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
return (int)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
/// <summary>
/// Returns the next power of two that is larger than the specified number.
/// </summary>
/// <param name="n">The specified number.</param>
/// <returns>The next power of two.</returns>
public static float NextPowerOfTwo(float n)
{
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
/// <summary>
/// Returns the next power of two that is larger than the specified number.
/// </summary>
/// <param name="n">The specified number.</param>
/// <returns>The next power of two.</returns>
public static double NextPowerOfTwo(double n)
{
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
return System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
#endregion
#region Factorial
/// <summary>Calculates the factorial of a given natural number.
/// </summary>
/// <param name="n">The number.</param>
/// <returns>n!</returns>
public static long Factorial(int n)
{
long result = 1;
for (; n > 1; n--)
result *= n;
return result;
}
#endregion
#region BinomialCoefficient
/// <summary>
/// Calculates the binomial coefficient <paramref name="n"/> above <paramref name="k"/>.
/// </summary>
/// <param name="n">The n.</param>
/// <param name="k">The k.</param>
/// <returns>n! / (k! * (n - k)!)</returns>
public static long BinomialCoefficient(int n, int k)
{
return Factorial(n) / (Factorial(k) * Factorial(n - k));
}
#endregion
#region InverseSqrtFast
/// <summary>
/// Returns an approximation of the inverse square root of left number.
/// </summary>
/// <param name="x">A number.</param>
/// <returns>An approximation of the inverse square root of the specified number, with an upper error bound of 0.001</returns>
/// <remarks>
/// This is an improved implementation of the the method known as Carmack's inverse square root
/// which is found in the Quake III source code. This implementation comes from
/// http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see
/// http://www.beyond3d.com/content/articles/8/
/// </remarks>
public static float InverseSqrtFast(float x)
{
unsafe
{
float xhalf = 0.5f * x;
int i = *(int*)&x; // Read bits as integer.
i = 0x5f375a86 - (i >> 1); // Make an initial guess for Newton-Raphson approximation
x = *(float*)&i; // Convert bits back to float
x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step.
return x;
}
}
/// <summary>
/// Returns an approximation of the inverse square root of left number.
/// </summary>
/// <param name="x">A number.</param>
/// <returns>An approximation of the inverse square root of the specified number, with an upper error bound of 0.001</returns>
/// <remarks>
/// This is an improved implementation of the the method known as Carmack's inverse square root
/// which is found in the Quake III source code. This implementation comes from
/// http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see
/// http://www.beyond3d.com/content/articles/8/
/// </remarks>
public static double InverseSqrtFast(double x)
{
return InverseSqrtFast((float)x);
// TODO: The following code is wrong. Fix it, to improve precision.
#if false
unsafe
{
double xhalf = 0.5f * x;
int i = *(int*)&x; // Read bits as integer.
i = 0x5f375a86 - (i >> 1); // Make an initial guess for Newton-Raphson approximation
x = *(float*)&i; // Convert bits back to float
x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step.
return x;
}
#endif
}
#endregion
#region DegreesToRadians
/// <summary>
/// Convert degrees to radians
/// </summary>
/// <param name="degrees">An angle in degrees</param>
/// <returns>The angle expressed in radians</returns>
public static float DegreesToRadians(float degrees)
{
const float degToRad = (float)System.Math.PI / 180.0f;
return degrees * degToRad;
}
/// <summary>
/// Convert radians to degrees
/// </summary>
/// <param name="radians">An angle in radians</param>
/// <returns>The angle expressed in degrees</returns>
public static float RadiansToDegrees(float radians)
{
const float radToDeg = 180.0f / (float)System.Math.PI;
return radians * radToDeg;
}
/// <summary>
/// Convert degrees to radians
/// </summary>
/// <param name="degrees">An angle in degrees</param>
/// <returns>The angle expressed in radians</returns>
public static double DegreesToRadians(double degrees)
{
const double degToRad = System.Math.PI / 180.0;
return degrees * degToRad;
}
/// <summary>
/// Convert radians to degrees
/// </summary>
/// <param name="radians">An angle in radians</param>
/// <returns>The angle expressed in degrees</returns>
public static double RadiansToDegrees(double radians)
{
const double radToDeg = 180.0 / System.Math.PI;
return radians * radToDeg;
}
#endregion
#region Swap
/// <summary>
/// Swaps two double values.
/// </summary>
/// <param name="a">The first value.</param>
/// <param name="b">The second value.</param>
public static void Swap(ref double a, ref double b)
{
double temp = a;
a = b;
b = temp;
}
/// <summary>
/// Swaps two float values.
/// </summary>
/// <param name="a">The first value.</param>
/// <param name="b">The second value.</param>
public static void Swap(ref float a, ref float b)
{
float temp = a;
a = b;
b = temp;
}
#endregion
#endregion
}
}

828
src/MiniTK/Math/Matrix3d.cs Normal file
Просмотреть файл

@ -0,0 +1,828 @@
#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.Runtime.InteropServices;
namespace OpenTK
{
// Todo: Remove this warning when the code goes public.
#pragma warning disable 3019
#if false
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct Matrix3d : IEquatable<Matrix3d>
{
#region Fields & Access
/// <summary>Row 0, Column 0</summary>
public double R0C0;
/// <summary>Row 0, Column 1</summary>
public double R0C1;
/// <summary>Row 0, Column 2</summary>
public double R0C2;
/// <summary>Row 1, Column 0</summary>
public double R1C0;
/// <summary>Row 1, Column 1</summary>
public double R1C1;
/// <summary>Row 1, Column 2</summary>
public double R1C2;
/// <summary>Row 2, Column 0</summary>
public double R2C0;
/// <summary>Row 2, Column 1</summary>
public double R2C1;
/// <summary>Row 2, Column 2</summary>
public double R2C2;
/// <summary>Gets the component at the given row and column in the matrix.</summary>
/// <param name="row">The row of the matrix.</param>
/// <param name="column">The column of the matrix.</param>
/// <returns>The component at the given row and column in the matrix.</returns>
public double this[int row, int column]
{
get
{
switch( row )
{
case 0:
switch (column)
{
case 0: return R0C0;
case 1: return R0C1;
case 2: return R0C2;
}
break;
case 1:
switch (column)
{
case 0: return R1C0;
case 1: return R1C1;
case 2: return R1C2;
}
break;
case 2:
switch (column)
{
case 0: return R2C0;
case 1: return R2C1;
case 2: return R2C2;
}
break;
}
throw new IndexOutOfRangeException();
}
set
{
switch( row )
{
case 0:
switch (column)
{
case 0: R0C0 = value; return;
case 1: R0C1 = value; return;
case 2: R0C2 = value; return;
}
break;
case 1:
switch (column)
{
case 0: R1C0 = value; return;
case 1: R1C1 = value; return;
case 2: R1C2 = value; return;
}
break;
case 2:
switch (column)
{
case 0: R2C0 = value; return;
case 1: R2C1 = value; return;
case 2: R2C2 = value; return;
}
break;
}
throw new IndexOutOfRangeException();
}
}
/// <summary>Gets the component at the index into the matrix.</summary>
/// <param name="index">The index into the components of the matrix.</param>
/// <returns>The component at the given index into the matrix.</returns>
public double this[int index]
{
get
{
switch (index)
{
case 0: return R0C0;
case 1: return R0C1;
case 2: return R0C2;
case 3: return R1C0;
case 4: return R1C1;
case 5: return R1C2;
case 6: return R2C0;
case 7: return R2C1;
case 8: return R2C2;
default: throw new IndexOutOfRangeException();
}
}
set
{
switch (index)
{
case 0: R0C0 = value; return;
case 1: R0C1 = value; return;
case 2: R0C2 = value; return;
case 3: R1C0 = value; return;
case 4: R1C1 = value; return;
case 5: R1C2 = value; return;
case 6: R2C0 = value; return;
case 7: R2C1 = value; return;
case 8: R2C2 = value; return;
default: throw new IndexOutOfRangeException();
}
}
}
/// <summary>Converts the matrix into an IntPtr.</summary>
/// <param name="matrix">The matrix to convert.</param>
/// <returns>An IntPtr for the matrix.</returns>
public static explicit operator IntPtr(Matrix3d matrix)
{
unsafe
{
return (IntPtr)(&matrix.R0C0);
}
}
/// <summary>Converts the matrix into left double*.</summary>
/// <param name="matrix">The matrix to convert.</param>
/// <returns>A double* for the matrix.</returns>
[CLSCompliant(false)]
unsafe public static explicit operator double*(Matrix3d matrix)
{
return &matrix.R0C0;
}
/// <summary>Converts the matrix into an array of doubles.</summary>
/// <param name="matrix">The matrix to convert.</param>
/// <returns>An array of doubles for the matrix.</returns>
public static explicit operator double[](Matrix3d matrix)
{
return new double[9]
{
matrix.R0C0,
matrix.R0C1,
matrix.R0C2,
matrix.R1C0,
matrix.R1C1,
matrix.R1C2,
matrix.R2C0,
matrix.R2C1,
matrix.R2C2
};
}
#endregion
#region Constructors
/// <summary>Constructs left matrix with the same components as the given matrix.</summary>
/// <param name="vector">The matrix whose components to copy.</param>
public Matrix3d(ref Matrix3d matrix)
{
this.R0C0 = matrix.R0C0;
this.R0C1 = matrix.R0C1;
this.R0C2 = matrix.R0C2;
this.R1C0 = matrix.R1C0;
this.R1C1 = matrix.R1C1;
this.R1C2 = matrix.R1C2;
this.R2C0 = matrix.R2C0;
this.R2C1 = matrix.R2C1;
this.R2C2 = matrix.R2C2;
}
/// <summary>Constructs left matrix with the given values.</summary>
/// <param name="r0c0">The value for row 0 column 0.</param>
/// <param name="r0c1">The value for row 0 column 1.</param>
/// <param name="r0c2">The value for row 0 column 2.</param>
/// <param name="r1c0">The value for row 1 column 0.</param>
/// <param name="r1c1">The value for row 1 column 1.</param>
/// <param name="r1c2">The value for row 1 column 2.</param>
/// <param name="r2c0">The value for row 2 column 0.</param>
/// <param name="r2c1">The value for row 2 column 1.</param>
/// <param name="r2c2">The value for row 2 column 2.</param>
public Matrix3d
(
double r0c0,
double r0c1,
double r0c2,
double r1c0,
double r1c1,
double r1c2,
double r2c0,
double r2c1,
double r2c2
)
{
this.R0C0 = r0c0;
this.R0C1 = r0c1;
this.R0C2 = r0c2;
this.R1C0 = r1c0;
this.R1C1 = r1c1;
this.R1C2 = r1c2;
this.R2C0 = r2c0;
this.R2C1 = r2c1;
this.R2C2 = r2c2;
}
/// <summary>Constructs left matrix from the given array of double-precision floating-point numbers.</summary>
/// <param name="doubleArray">The array of doubles for the components of the matrix.</param>
public Matrix3d(double[] doubleArray)
{
if (doubleArray == null || doubleArray.GetLength(0) < 9) throw new MissingFieldException();
this.R0C0 = doubleArray[0];
this.R0C1 = doubleArray[1];
this.R0C2 = doubleArray[2];
this.R1C0 = doubleArray[3];
this.R1C1 = doubleArray[4];
this.R1C2 = doubleArray[5];
this.R2C0 = doubleArray[6];
this.R2C1 = doubleArray[7];
this.R2C2 = doubleArray[8];
}
/// <summary>Constructs left matrix from the given quaternion.</summary>
/// <param name="quaternion">The quaternion to use to construct the martix.</param>
public Matrix3d(Quaterniond quaternion)
{
quaternion.Normalize();
double xx = quaternion.X * quaternion.X;
double yy = quaternion.Y * quaternion.Y;
double zz = quaternion.Z * quaternion.Z;
double xy = quaternion.X * quaternion.Y;
double xz = quaternion.X * quaternion.Z;
double yz = quaternion.Y * quaternion.Z;
double wx = quaternion.W * quaternion.X;
double wy = quaternion.W * quaternion.Y;
double wz = quaternion.W * quaternion.Z;
R0C0 = 1 - 2 * (yy + zz);
R0C1 = 2 * (xy - wz);
R0C2 = 2 * (xz + wy);
R1C0 = 2 * (xy + wz);
R1C1 = 1 - 2 * (xx + zz);
R1C2 = 2 * (yz - wx);
R2C0 = 2 * (xz - wy);
R2C1 = 2 * (yz + wx);
R2C2 = 1 - 2 * (xx + yy);
}
#endregion
#region Equality
/// <summary>Indicates whether the current matrix is equal to another matrix.</summary>
/// <param name="matrix">The OpenTK.Matrix3d structure to compare with.</param>
/// <returns>true if the current matrix is equal to the matrix parameter; otherwise, false.</returns>
[CLSCompliant(false)]
public bool Equals(Matrix3d matrix)
{
return
R0C0 == matrix.R0C0 &&
R0C1 == matrix.R0C1 &&
R0C2 == matrix.R0C2 &&
R1C0 == matrix.R1C0 &&
R1C1 == matrix.R1C1 &&
R1C2 == matrix.R1C2 &&
R2C0 == matrix.R2C0 &&
R2C1 == matrix.R2C1 &&
R2C2 == matrix.R2C2;
}
/// <summary>Indicates whether the current matrix is equal to another matrix.</summary>
/// <param name="matrix">The OpenTK.Matrix3d structure to compare to.</param>
/// <returns>true if the current matrix is equal to the matrix parameter; otherwise, false.</returns>
public bool Equals(ref Matrix3d matrix)
{
return
R0C0 == matrix.R0C0 &&
R0C1 == matrix.R0C1 &&
R0C2 == matrix.R0C2 &&
R1C0 == matrix.R1C0 &&
R1C1 == matrix.R1C1 &&
R1C2 == matrix.R1C2 &&
R2C0 == matrix.R2C0 &&
R2C1 == matrix.R2C1 &&
R2C2 == matrix.R2C2;
}
/// <summary>Indicates whether the current matrix is equal to another matrix.</summary>
/// <param name="left">The left-hand operand.</param>
/// <param name="right">The right-hand operand.</param>
/// <returns>true if the current matrix is equal to the matrix parameter; otherwise, false.</returns>
public static bool Equals(ref Matrix3d left, ref Matrix3d right)
{
return
left.R0C0 == right.R0C0 &&
left.R0C1 == right.R0C1 &&
left.R0C2 == right.R0C2 &&
left.R1C0 == right.R1C0 &&
left.R1C1 == right.R1C1 &&
left.R1C2 == right.R1C2 &&
left.R2C0 == right.R2C0 &&
left.R2C1 == right.R2C1 &&
left.R2C2 == right.R2C2;
}
/// <summary>Indicates whether the current matrix is approximately equal to another matrix.</summary>
/// <param name="matrix">The OpenTK.Matrix3d structure to compare with.</param>
/// <param name="tolerance">The limit below which the matrices are considered equal.</param>
/// <returns>true if the current matrix is approximately equal to the matrix parameter; otherwise, false.</returns>
public bool EqualsApprox(ref Matrix3d matrix, double tolerance)
{
return
System.Math.Abs(R0C0 - matrix.R0C0) <= tolerance &&
System.Math.Abs(R0C1 - matrix.R0C1) <= tolerance &&
System.Math.Abs(R0C2 - matrix.R0C2) <= tolerance &&
System.Math.Abs(R1C0 - matrix.R1C0) <= tolerance &&
System.Math.Abs(R1C1 - matrix.R1C1) <= tolerance &&
System.Math.Abs(R1C2 - matrix.R1C2) <= tolerance &&
System.Math.Abs(R2C0 - matrix.R2C0) <= tolerance &&
System.Math.Abs(R2C1 - matrix.R2C1) <= tolerance &&
System.Math.Abs(R2C2 - matrix.R2C2) <= tolerance;
}
/// <summary>Indicates whether the current matrix is approximately equal to another matrix.</summary>
/// <param name="left">The left-hand operand.</param>
/// <param name="right">The right-hand operand.</param>
/// <param name="tolerance">The limit below which the matrices are considered equal.</param>
/// <returns>true if the current matrix is approximately equal to the matrix parameter; otherwise, false.</returns>
public static bool EqualsApprox(ref Matrix3d left, ref Matrix3d right, double tolerance)
{
return
System.Math.Abs(left.R0C0 - right.R0C0) <= tolerance &&
System.Math.Abs(left.R0C1 - right.R0C1) <= tolerance &&
System.Math.Abs(left.R0C2 - right.R0C2) <= tolerance &&
System.Math.Abs(left.R1C0 - right.R1C0) <= tolerance &&
System.Math.Abs(left.R1C1 - right.R1C1) <= tolerance &&
System.Math.Abs(left.R1C2 - right.R1C2) <= tolerance &&
System.Math.Abs(left.R2C0 - right.R2C0) <= tolerance &&
System.Math.Abs(left.R2C1 - right.R2C1) <= tolerance &&
System.Math.Abs(left.R2C2 - right.R2C2) <= tolerance;
}
#endregion
#region Arithmetic Operators
/// <summary>Add left matrix to this matrix.</summary>
/// <param name="matrix">The matrix to add.</param>
public void Add(ref Matrix3d matrix)
{
R0C0 = R0C0 + matrix.R0C0;
R0C1 = R0C1 + matrix.R0C1;
R0C2 = R0C2 + matrix.R0C2;
R1C0 = R1C0 + matrix.R1C0;
R1C1 = R1C1 + matrix.R1C1;
R1C2 = R1C2 + matrix.R1C2;
R2C0 = R2C0 + matrix.R2C0;
R2C1 = R2C1 + matrix.R2C1;
R2C2 = R2C2 + matrix.R2C2;
}
/// <summary>Add left matrix to this matrix.</summary>
/// <param name="matrix">The matrix to add.</param>
/// <param name="result">The resulting matrix of the addition.</param>
public void Add(ref Matrix3d matrix, out Matrix3d result)
{
result.R0C0 = R0C0 + matrix.R0C0;
result.R0C1 = R0C1 + matrix.R0C1;
result.R0C2 = R0C2 + matrix.R0C2;
result.R1C0 = R1C0 + matrix.R1C0;
result.R1C1 = R1C1 + matrix.R1C1;
result.R1C2 = R1C2 + matrix.R1C2;
result.R2C0 = R2C0 + matrix.R2C0;
result.R2C1 = R2C1 + matrix.R2C1;
result.R2C2 = R2C2 + matrix.R2C2;
}
/// <summary>Add left matrix to left matrix.</summary>
/// <param name="matrix">The matrix on the matrix side of the equation.</param>
/// <param name="right">The matrix on the right side of the equation</param>
/// <param name="result">The resulting matrix of the addition.</param>
public static void Add(ref Matrix3d left, ref Matrix3d right, out Matrix3d result)
{
result.R0C0 = left.R0C0 + right.R0C0;
result.R0C1 = left.R0C1 + right.R0C1;
result.R0C2 = left.R0C2 + right.R0C2;
result.R1C0 = left.R1C0 + right.R1C0;
result.R1C1 = left.R1C1 + right.R1C1;
result.R1C2 = left.R1C2 + right.R1C2;
result.R2C0 = left.R2C0 + right.R2C0;
result.R2C1 = left.R2C1 + right.R2C1;
result.R2C2 = left.R2C2 + right.R2C2;
}
/// <summary>Subtract left matrix from this matrix.</summary>
/// <param name="matrix">The matrix to subtract.</param>
public void Subtract(ref Matrix3d matrix)
{
R0C0 = R0C0 + matrix.R0C0;
R0C1 = R0C1 + matrix.R0C1;
R0C2 = R0C2 + matrix.R0C2;
R1C0 = R1C0 + matrix.R1C0;
R1C1 = R1C1 + matrix.R1C1;
R1C2 = R1C2 + matrix.R1C2;
R2C0 = R2C0 + matrix.R2C0;
R2C1 = R2C1 + matrix.R2C1;
R2C2 = R2C2 + matrix.R2C2;
}
/// <summary>Subtract left matrix from this matrix.</summary>
/// <param name="matrix">The matrix to subtract.</param>
/// <param name="result">The resulting matrix of the subtraction.</param>
public void Subtract(ref Matrix3d matrix, out Matrix3d result)
{
result.R0C0 = R0C0 + matrix.R0C0;
result.R0C1 = R0C1 + matrix.R0C1;
result.R0C2 = R0C2 + matrix.R0C2;
result.R1C0 = R1C0 + matrix.R1C0;
result.R1C1 = R1C1 + matrix.R1C1;
result.R1C2 = R1C2 + matrix.R1C2;
result.R2C0 = R2C0 + matrix.R2C0;
result.R2C1 = R2C1 + matrix.R2C1;
result.R2C2 = R2C2 + matrix.R2C2;
}
/// <summary>Subtract left matrix from left matrix.</summary>
/// <param name="matrix">The matrix on the matrix side of the equation.</param>
/// <param name="right">The matrix on the right side of the equation</param>
/// <param name="result">The resulting matrix of the subtraction.</param>
public static void Subtract(ref Matrix3d left, ref Matrix3d right, out Matrix3d result)
{
result.R0C0 = left.R0C0 + right.R0C0;
result.R0C1 = left.R0C1 + right.R0C1;
result.R0C2 = left.R0C2 + right.R0C2;
result.R1C0 = left.R1C0 + right.R1C0;
result.R1C1 = left.R1C1 + right.R1C1;
result.R1C2 = left.R1C2 + right.R1C2;
result.R2C0 = left.R2C0 + right.R2C0;
result.R2C1 = left.R2C1 + right.R2C1;
result.R2C2 = left.R2C2 + right.R2C2;
}
/// <summary>Multiply left martix times this matrix.</summary>
/// <param name="matrix">The matrix to multiply.</param>
public void Multiply(ref Matrix3d matrix)
{
double r0c0 = matrix.R0C0 * R0C0 + matrix.R0C1 * R1C0 + matrix.R0C2 * R2C0;
double r0c1 = matrix.R0C0 * R0C1 + matrix.R0C1 * R1C1 + matrix.R0C2 * R2C1;
double r0c2 = matrix.R0C0 * R0C2 + matrix.R0C1 * R1C2 + matrix.R0C2 * R2C2;
double r1c0 = matrix.R1C0 * R0C0 + matrix.R1C1 * R1C0 + matrix.R1C2 * R2C0;
double r1c1 = matrix.R1C0 * R0C1 + matrix.R1C1 * R1C1 + matrix.R1C2 * R2C1;
double r1c2 = matrix.R1C0 * R0C2 + matrix.R1C1 * R1C2 + matrix.R1C2 * R2C2;
R2C0 = matrix.R2C0 * R0C0 + matrix.R2C1 * R1C0 + matrix.R2C2 * R2C0;
R2C1 = matrix.R2C0 * R0C1 + matrix.R2C1 * R1C1 + matrix.R2C2 * R2C1;
R2C2 = matrix.R2C0 * R0C2 + matrix.R2C1 * R1C2 + matrix.R2C2 * R2C2;
R0C0 = r0c0;
R0C1 = r0c1;
R0C2 = r0c2;
R1C0 = r1c0;
R1C1 = r1c1;
R1C2 = r1c2;
}
/// <summary>Multiply matrix times this matrix.</summary>
/// <param name="matrix">The matrix to multiply.</param>
/// <param name="result">The resulting matrix of the multiplication.</param>
public void Multiply(ref Matrix3d matrix, out Matrix3d result)
{
result.R0C0 = matrix.R0C0 * R0C0 + matrix.R0C1 * R1C0 + matrix.R0C2 * R2C0;
result.R0C1 = matrix.R0C0 * R0C1 + matrix.R0C1 * R1C1 + matrix.R0C2 * R2C1;
result.R0C2 = matrix.R0C0 * R0C2 + matrix.R0C1 * R1C2 + matrix.R0C2 * R2C2;
result.R1C0 = matrix.R1C0 * R0C0 + matrix.R1C1 * R1C0 + matrix.R1C2 * R2C0;
result.R1C1 = matrix.R1C0 * R0C1 + matrix.R1C1 * R1C1 + matrix.R1C2 * R2C1;
result.R1C2 = matrix.R1C0 * R0C2 + matrix.R1C1 * R1C2 + matrix.R1C2 * R2C2;
result.R2C0 = matrix.R2C0 * R0C0 + matrix.R2C1 * R1C0 + matrix.R2C2 * R2C0;
result.R2C1 = matrix.R2C0 * R0C1 + matrix.R2C1 * R1C1 + matrix.R2C2 * R2C1;
result.R2C2 = matrix.R2C0 * R0C2 + matrix.R2C1 * R1C2 + matrix.R2C2 * R2C2;
}
/// <summary>Multiply left matrix times left matrix.</summary>
/// <param name="matrix">The matrix on the matrix side of the equation.</param>
/// <param name="right">The matrix on the right side of the equation</param>
/// <param name="result">The resulting matrix of the multiplication.</param>
public static void Multiply(ref Matrix3d left, ref Matrix3d right, out Matrix3d result)
{
result.R0C0 = right.R0C0 * left.R0C0 + right.R0C1 * left.R1C0 + right.R0C2 * left.R2C0;
result.R0C1 = right.R0C0 * left.R0C1 + right.R0C1 * left.R1C1 + right.R0C2 * left.R2C1;
result.R0C2 = right.R0C0 * left.R0C2 + right.R0C1 * left.R1C2 + right.R0C2 * left.R2C2;
result.R1C0 = right.R1C0 * left.R0C0 + right.R1C1 * left.R1C0 + right.R1C2 * left.R2C0;
result.R1C1 = right.R1C0 * left.R0C1 + right.R1C1 * left.R1C1 + right.R1C2 * left.R2C1;
result.R1C2 = right.R1C0 * left.R0C2 + right.R1C1 * left.R1C2 + right.R1C2 * left.R2C2;
result.R2C0 = right.R2C0 * left.R0C0 + right.R2C1 * left.R1C0 + right.R2C2 * left.R2C0;
result.R2C1 = right.R2C0 * left.R0C1 + right.R2C1 * left.R1C1 + right.R2C2 * left.R2C1;
result.R2C2 = right.R2C0 * left.R0C2 + right.R2C1 * left.R1C2 + right.R2C2 * left.R2C2;
}
/// <summary>Multiply matrix times this matrix.</summary>
/// <param name="matrix">The matrix to multiply.</param>
public void Multiply(double scalar)
{
R0C0 = scalar * R0C0;
R0C1 = scalar * R0C1;
R0C2 = scalar * R0C2;
R1C0 = scalar * R1C0;
R1C1 = scalar * R1C1;
R1C2 = scalar * R1C2;
R2C0 = scalar * R2C0;
R2C1 = scalar * R2C1;
R2C2 = scalar * R2C2;
}
/// <summary>Multiply matrix times this matrix.</summary>
/// <param name="matrix">The matrix to multiply.</param>
/// <param name="result">The resulting matrix of the multiplication.</param>
public void Multiply(double scalar, out Matrix3d result)
{
result.R0C0 = scalar * R0C0;
result.R0C1 = scalar * R0C1;
result.R0C2 = scalar * R0C2;
result.R1C0 = scalar * R1C0;
result.R1C1 = scalar * R1C1;
result.R1C2 = scalar * R1C2;
result.R2C0 = scalar * R2C0;
result.R2C1 = scalar * R2C1;
result.R2C2 = scalar * R2C2;
}
/// <summary>Multiply left matrix times left matrix.</summary>
/// <param name="matrix">The matrix on the matrix side of the equation.</param>
/// <param name="right">The matrix on the right side of the equation</param>
/// <param name="result">The resulting matrix of the multiplication.</param>
public static void Multiply(ref Matrix3d matrix, double scalar, out Matrix3d result)
{
result.R0C0 = scalar * matrix.R0C0;
result.R0C1 = scalar * matrix.R0C1;
result.R0C2 = scalar * matrix.R0C2;
result.R1C0 = scalar * matrix.R1C0;
result.R1C1 = scalar * matrix.R1C1;
result.R1C2 = scalar * matrix.R1C2;
result.R2C0 = scalar * matrix.R2C0;
result.R2C1 = scalar * matrix.R2C1;
result.R2C2 = scalar * matrix.R2C2;
}
#endregion
#region Functions
public double Determinant
{
get
{
return R0C0 * R1C1 * R2C2 - R0C0 * R1C2 * R2C1 - R0C1 * R1C0 * R2C2 + R0C2 * R1C0 * R2C1 + R0C1 * R1C2 * R2C0 - R0C2 * R1C1 * R2C0;
}
}
public void Transpose()
{
Functions.Swap(ref R0C1, ref R1C0);
Functions.Swap(ref R0C2, ref R2C0);
Functions.Swap(ref R1C2, ref R2C1);
}
public void Transpose(out Matrix3d result)
{
result.R0C0 = R0C0;
result.R0C1 = R1C0;
result.R0C2 = R2C0;
result.R1C0 = R0C1;
result.R1C1 = R1C1;
result.R1C2 = R2C1;
result.R2C0 = R0C2;
result.R2C1 = R1C2;
result.R2C2 = R2C2;
}
public static void Transpose(ref Matrix3d matrix, out Matrix3d result)
{
result.R0C0 = matrix.R0C0;
result.R0C1 = matrix.R1C0;
result.R0C2 = matrix.R2C0;
result.R1C0 = matrix.R0C1;
result.R1C1 = matrix.R1C1;
result.R1C2 = matrix.R2C1;
result.R2C0 = matrix.R0C2;
result.R2C1 = matrix.R1C2;
result.R2C2 = matrix.R2C2;
}
#endregion
#region Transformation Functions
public void Transform(ref Vector3d vector)
{
double x = R0C0 * vector.X + R0C1 * vector.Y + R0C2 * vector.Z;
double y = R1C0 * vector.X + R1C1 * vector.Y + R1C2 * vector.Z;
vector.Z = R2C0 * vector.X + R2C1 * vector.Y + R2C2 * vector.Z;
vector.X = x;
vector.Y = y;
}
public static void Transform(ref Matrix3d matrix, ref Vector3d vector)
{
double x = matrix.R0C0 * vector.X + matrix.R0C1 * vector.Y + matrix.R0C2 * vector.Z;
double y = matrix.R1C0 * vector.X + matrix.R1C1 * vector.Y + matrix.R1C2 * vector.Z;
vector.Z = matrix.R2C0 * vector.X + matrix.R2C1 * vector.Y + matrix.R2C2 * vector.Z;
vector.X = x;
vector.Y = y;
}
public void Transform(ref Vector3d vector, out Vector3d result)
{
result.X = R0C0 * vector.X + R0C1 * vector.Y + R0C2 * vector.Z;
result.Y = R1C0 * vector.X + R1C1 * vector.Y + R1C2 * vector.Z;
result.Z = R2C0 * vector.X + R2C1 * vector.Y + R2C2 * vector.Z;
}
public static void Transform(ref Matrix3d matrix, ref Vector3d vector, out Vector3d result)
{
result.X = matrix.R0C0 * vector.X + matrix.R0C1 * vector.Y + matrix.R0C2 * vector.Z;
result.Y = matrix.R1C0 * vector.X + matrix.R1C1 * vector.Y + matrix.R1C2 * vector.Z;
result.Z = matrix.R2C0 * vector.X + matrix.R2C1 * vector.Y + matrix.R2C2 * vector.Z;
}
public void Rotate(double angle)
{
double angleRadians = Functions.DTOR * angle;
double sin = (double)System.Math.Sin(angleRadians);
double cos = (double)System.Math.Cos(angleRadians);
double r0c0 = cos * R0C0 + sin * R1C0;
double r0c1 = cos * R0C1 + sin * R1C1;
double r0c2 = cos * R0C2 + sin * R1C2;
R1C0 = cos * R1C0 - sin * R0C0;
R1C1 = cos * R1C1 - sin * R0C1;
R1C2 = cos * R1C2 - sin * R0C2;
R0C0 = r0c0;
R0C1 = r0c1;
R0C2 = r0c2;
}
public void Rotate(double angle, out Matrix3d result)
{
double angleRadians = Functions.DTOR * angle;
double sin = (double)System.Math.Sin(angleRadians);
double cos = (double)System.Math.Cos(angleRadians);
result.R0C0 = cos * R0C0 + sin * R1C0;
result.R0C1 = cos * R0C1 + sin * R1C1;
result.R0C2 = cos * R0C2 + sin * R1C2;
result.R1C0 = cos * R1C0 - sin * R0C0;
result.R1C1 = cos * R1C1 - sin * R0C1;
result.R1C2 = cos * R1C2 - sin * R0C2;
result.R2C0 = R2C0;
result.R2C1 = R2C1;
result.R2C2 = R2C2;
}
public static void Rotate(ref Matrix3d matrix, double angle, out Matrix3d result)
{
double angleRadians = Functions.DTOR * angle;
double sin = (double)System.Math.Sin(angleRadians);
double cos = (double)System.Math.Cos(angleRadians);
result.R0C0 = cos * matrix.R0C0 + sin * matrix.R1C0;
result.R0C1 = cos * matrix.R0C1 + sin * matrix.R1C1;
result.R0C2 = cos * matrix.R0C2 + sin * matrix.R1C2;
result.R1C0 = cos * matrix.R1C0 - sin * matrix.R0C0;
result.R1C1 = cos * matrix.R1C1 - sin * matrix.R0C1;
result.R1C2 = cos * matrix.R1C2 - sin * matrix.R0C2;
result.R2C0 = matrix.R2C0;
result.R2C1 = matrix.R2C1;
result.R2C2 = matrix.R2C2;
}
public static void RotateMatrix(double angle, out Matrix3d result)
{
double angleRadians = Functions.DTOR * angle;
double sin = (double)System.Math.Sin(angleRadians);
double cos = (double)System.Math.Cos(angleRadians);
result.R0C0 = cos;
result.R0C1 = sin;
result.R0C2 = 0;
result.R1C0 = -sin;
result.R1C1 = cos;
result.R1C2 = 0;
result.R2C0 = 0;
result.R2C1 = 0;
result.R2C2 = 1;
}
public Quaterniond ToQuaternion()
{
//return new Quaterniond(ref this);
}
#endregion
#region Constants
/// <summary>The identity matrix.</summary>
public static readonly Matrix3d Identity = new Matrix3d
(
1, 0, 0,
0, 1, 0,
0, 0, 1
);
/// <summary>A matrix of all zeros.</summary>
public static readonly Matrix3d Zero = new Matrix3d
(
0, 0, 0,
0, 0, 0,
0, 0, 0
);
#endregion
#region HashCode
/// <summary>Returns the hash code for this instance.</summary>
/// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
public override int GetHashCode()
{
return
R0C0.GetHashCode() ^ R0C1.GetHashCode() ^ R0C2.GetHashCode() ^
R1C0.GetHashCode() ^ R1C1.GetHashCode() ^ R1C2.GetHashCode() ^
R2C0.GetHashCode() ^ R2C1.GetHashCode() ^ R2C2.GetHashCode();
}
#endregion
#region String
/// <summary>Returns the fully qualified type name of this instance.</summary>
/// <returns>A System.String containing left fully qualified type name.</returns>
public override string ToString()
{
return String.Format(
"|{00}, {01}, {02}|\n" +
"|{03}, {04}, {05}|\n" +
"|{06}, {07}, {18}|\n" +
R0C0, R0C1, R0C2,
R1C0, R1C1, R1C2,
R2C0, R2C1, R2C2);
}
#endregion
}
#endif
#pragma warning restore 3019
}

1229
src/MiniTK/Math/Matrix4.cs Normal file

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

1223
src/MiniTK/Math/Matrix4d.cs Normal file

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

235
src/MiniTK/Math/Point.cs Normal file
Просмотреть файл

@ -0,0 +1,235 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 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.Collections.Generic;
using System.Text;
namespace OpenTK
{
#if NO_SYSDRAWING
/// <summary>
/// Defines a point on a two-dimensional plane.
/// </summary>
public struct Point : IEquatable<Point>
{
#region Fields
int x, y;
#endregion
#region Constructors
/// <summary>
/// Constructs a new Point instance.
/// </summary>
/// <param name="x">The X coordinate of this instance.</param>
/// <param name="y">The Y coordinate of this instance.</param>
public Point(int x, int y)
: this()
{
X = x;
Y = y;
}
#endregion
#region Public Members
/// <summary>
/// Gets a <see cref="System.Boolean"/> that indicates whether this instance is empty or zero.
/// </summary>
public bool IsEmpty { get { return X == 0 && Y == 0; } }
/// <summary>
/// Gets or sets the X coordinate of this instance.
/// </summary>
public int X { get { return x; } set { x = value; } }
/// <summary>
/// Gets or sets the Y coordinate of this instance.
/// </summary>
public int Y { get { return y; } set { y = value; } }
/// <summary>
/// Returns the Point (0, 0).
/// </summary>
public static readonly Point Zero = new Point();
/// <summary>
/// Returns the Point (0, 0).
/// </summary>
public static readonly Point Empty = new Point();
/// <summary>
/// Translates the specified Point by the specified Size.
/// </summary>
/// <param name="point">
/// The <see cref="Point"/> instance to translate.
/// </param>
/// <param name="size">
/// The <see cref="Size"/> instance to translate point with.
/// </param>
/// <returns>
/// A new <see cref="Point"/> instance translated by size.
/// </returns>
public static Point operator +(Point point, Size size)
{
return new Point(point.X + size.Width, point.Y + size.Height);
}
/// <summary>
/// Translates the specified Point by the negative of the specified Size.
/// </summary>
/// <param name="point">
/// The <see cref="Point"/> instance to translate.
/// </param>
/// <param name="size">
/// The <see cref="Size"/> instance to translate point with.
/// </param>
/// <returns>
/// A new <see cref="Point"/> instance translated by size.
/// </returns>
public static Point operator -(Point point, Size size)
{
return new Point(point.X - size.Width, point.Y - size.Height);
}
/// <summary>
/// Compares two instances for equality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>True, if left is equal to right; false otherwise.</returns>
public static bool operator ==(Point left, Point right)
{
return left.Equals(right);
}
/// <summary>
/// Compares two instances for inequality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>True, if left is not equal to right; false otherwise.</returns>
public static bool operator !=(Point left, Point right)
{
return !left.Equals(right);
}
/// <summary>
/// Converts an OpenTK.Point instance to a System.Drawing.Point.
/// </summary>
/// <param name="point">
/// The <see cref="Point"/> instance to convert.
/// </param>
/// <returns>
/// A <see cref="System.Drawing.Point"/> instance equivalent to point.
/// </returns>
public static implicit operator System.Drawing.Point(Point point)
{
return new System.Drawing.Point(point.X, point.Y);
}
/// <summary>
/// Converts a System.Drawing.Point instance to an OpenTK.Point.
/// </summary>
/// <param name="point">
/// The <see cref="System.Drawing.Point"/> instance to convert.
/// </param>
/// <returns>
/// A <see cref="Point"/> instance equivalent to point.
/// </returns>
public static implicit operator Point(System.Drawing.Point point)
{
return new Point(point.X, point.Y);
}
/// <summary>
/// Converts an OpenTK.Point instance to a System.Drawing.PointF.
/// </summary>
/// <param name="point">
/// The <see cref="Point"/> instance to convert.
/// </param>
/// <returns>
/// A <see cref="System.Drawing.PointF"/> instance equivalent to point.
/// </returns>
public static implicit operator System.Drawing.PointF(Point point)
{
return new System.Drawing.PointF(point.X, point.Y);
}
/// <summary>
/// Indicates whether this instance is equal to the specified object.
/// </summary>
/// <param name="obj">The object instance to compare to.</param>
/// <returns>True, if both instances are equal; false otherwise.</returns>
public override bool Equals(object obj)
{
if (obj is Point)
return Equals((Point)obj);
return false;
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A <see cref="System.Int32"/> that represents the hash code for this instance./></returns>
public override int GetHashCode()
{
return X.GetHashCode() ^ Y.GetHashCode();
}
/// <summary>
/// Returns a <see cref="System.String"/> that describes this instance.
/// </summary>
/// <returns>A <see cref="System.String"/> that describes this instance.</returns>
public override string ToString()
{
return String.Format("{{{0}, {1}}}", X, Y);
}
#endregion
#region IEquatable<Point> Members
/// <summary>
/// Indicates whether this instance is equal to the specified Point.
/// </summary>
/// <param name="other">The instance to compare to.</param>
/// <returns>True, if both instances are equal; false otherwise.</returns>
public bool Equals(Point other)
{
return X == other.X && Y == other.Y;
}
#endregion
}
#endif
}

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

@ -0,0 +1,705 @@
#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.Runtime.InteropServices;
using System.ComponentModel;
using System.Xml.Serialization;
// flibit Added This!!!
#pragma warning disable 3021
namespace OpenTK
{
/// <summary>
/// Represents a Quaternion.
/// </summary>
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct Quaternion : IEquatable<Quaternion>
{
#region Fields
Vector3 xyz;
float w;
#endregion
#region Constructors
/// <summary>
/// Construct a new Quaternion from vector and w components
/// </summary>
/// <param name="v">The vector part</param>
/// <param name="w">The w part</param>
public Quaternion(Vector3 v, float w)
{
this.xyz = v;
this.w = w;
}
/// <summary>
/// Construct a new Quaternion
/// </summary>
/// <param name="x">The x component</param>
/// <param name="y">The y component</param>
/// <param name="z">The z component</param>
/// <param name="w">The w component</param>
public Quaternion(float x, float y, float z, float w)
: this(new Vector3(x, y, z), w)
{ }
#endregion
#region Public Members
#region Properties
/// <summary>
/// Gets or sets an OpenTK.Vector3 with the X, Y and Z components of this instance.
/// </summary>
[Obsolete("Use Xyz property instead.")]
[CLSCompliant(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XmlIgnore]
public Vector3 XYZ { get { return Xyz; } set { Xyz = value; } }
/// <summary>
/// Gets or sets an OpenTK.Vector3 with the X, Y and Z components of this instance.
/// </summary>
public Vector3 Xyz { get { return xyz; } set { xyz = value; } }
/// <summary>
/// Gets or sets the X component of this instance.
/// </summary>
[XmlIgnore]
public float X { get { return xyz.X; } set { xyz.X = value; } }
/// <summary>
/// Gets or sets the Y component of this instance.
/// </summary>
[XmlIgnore]
public float Y { get { return xyz.Y; } set { xyz.Y = value; } }
/// <summary>
/// Gets or sets the Z component of this instance.
/// </summary>
[XmlIgnore]
public float Z { get { return xyz.Z; } set { xyz.Z = value; } }
/// <summary>
/// Gets or sets the W component of this instance.
/// </summary>
public float W { get { return w; } set { w = value; } }
#endregion
#region Instance
#region ToAxisAngle
/// <summary>
/// Convert the current quaternion to axis angle representation
/// </summary>
/// <param name="axis">The resultant axis</param>
/// <param name="angle">The resultant angle</param>
public void ToAxisAngle(out Vector3 axis, out float angle)
{
Vector4 result = ToAxisAngle();
axis = result.Xyz;
angle = result.W;
}
/// <summary>
/// Convert this instance to an axis-angle representation.
/// </summary>
/// <returns>A Vector4 that is the axis-angle representation of this quaternion.</returns>
public Vector4 ToAxisAngle()
{
Quaternion q = this;
if (Math.Abs(q.W) > 1.0f)
q.Normalize();
Vector4 result = new Vector4();
result.W = 2.0f * (float)System.Math.Acos(q.W); // angle
float den = (float)System.Math.Sqrt(1.0 - q.W * q.W);
if (den > 0.0001f)
{
result.Xyz = q.Xyz / den;
}
else
{
// This occurs when the angle is zero.
// Not a problem: just set an arbitrary normalized axis.
result.Xyz = Vector3.UnitX;
}
return result;
}
#endregion
#region public float Length
/// <summary>
/// Gets the length (magnitude) of the quaternion.
/// </summary>
/// <seealso cref="LengthSquared"/>
public float Length
{
get
{
return (float)System.Math.Sqrt(W * W + Xyz.LengthSquared);
}
}
#endregion
#region public float LengthSquared
/// <summary>
/// Gets the square of the quaternion length (magnitude).
/// </summary>
public float LengthSquared
{
get
{
return W * W + Xyz.LengthSquared;
}
}
#endregion
#region public void Normalize()
/// <summary>
/// Scales the Quaternion to unit length.
/// </summary>
public void Normalize()
{
float scale = 1.0f / this.Length;
Xyz *= scale;
W *= scale;
}
#endregion
#region public void Conjugate()
/// <summary>
/// Convert this quaternion to its conjugate
/// </summary>
public void Conjugate()
{
Xyz = -Xyz;
}
#endregion
#endregion
#region Static
#region Fields
/// <summary>
/// Defines the identity quaternion.
/// </summary>
public static Quaternion Identity = new Quaternion(0, 0, 0, 1);
#endregion
#region Add
/// <summary>
/// Add two quaternions
/// </summary>
/// <param name="left">The first operand</param>
/// <param name="right">The second operand</param>
/// <returns>The result of the addition</returns>
public static Quaternion Add(Quaternion left, Quaternion right)
{
return new Quaternion(
left.Xyz + right.Xyz,
left.W + right.W);
}
/// <summary>
/// Add two quaternions
/// </summary>
/// <param name="left">The first operand</param>
/// <param name="right">The second operand</param>
/// <param name="result">The result of the addition</param>
public static void Add(ref Quaternion left, ref Quaternion right, out Quaternion result)
{
result = new Quaternion(
left.Xyz + right.Xyz,
left.W + right.W);
}
#endregion
#region Sub
/// <summary>
/// Subtracts two instances.
/// </summary>
/// <param name="left">The left instance.</param>
/// <param name="right">The right instance.</param>
/// <returns>The result of the operation.</returns>
public static Quaternion Sub(Quaternion left, Quaternion right)
{
return new Quaternion(
left.Xyz - right.Xyz,
left.W - right.W);
}
/// <summary>
/// Subtracts two instances.
/// </summary>
/// <param name="left">The left instance.</param>
/// <param name="right">The right instance.</param>
/// <param name="result">The result of the operation.</param>
public static void Sub(ref Quaternion left, ref Quaternion right, out Quaternion result)
{
result = new Quaternion(
left.Xyz - right.Xyz,
left.W - right.W);
}
#endregion
#region Mult
/// <summary>
/// Multiplies two instances.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>A new instance containing the result of the calculation.</returns>
[Obsolete("Use Multiply instead.")]
public static Quaternion Mult(Quaternion left, Quaternion right)
{
return new Quaternion(
right.W * left.Xyz + left.W * right.Xyz + Vector3.Cross(left.Xyz, right.Xyz),
left.W * right.W - Vector3.Dot(left.Xyz, right.Xyz));
}
/// <summary>
/// Multiplies two instances.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <param name="result">A new instance containing the result of the calculation.</param>
[Obsolete("Use Multiply instead.")]
public static void Mult(ref Quaternion left, ref Quaternion right, out Quaternion result)
{
result = new Quaternion(
right.W * left.Xyz + left.W * right.Xyz + Vector3.Cross(left.Xyz, right.Xyz),
left.W * right.W - Vector3.Dot(left.Xyz, right.Xyz));
}
/// <summary>
/// Multiplies two instances.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>A new instance containing the result of the calculation.</returns>
public static Quaternion Multiply(Quaternion left, Quaternion right)
{
Quaternion result;
Multiply(ref left, ref right, out result);
return result;
}
/// <summary>
/// Multiplies two instances.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <param name="result">A new instance containing the result of the calculation.</param>
public static void Multiply(ref Quaternion left, ref Quaternion right, out Quaternion result)
{
result = new Quaternion(
right.W * left.Xyz + left.W * right.Xyz + Vector3.Cross(left.Xyz, right.Xyz),
left.W * right.W - Vector3.Dot(left.Xyz, right.Xyz));
}
/// <summary>
/// Multiplies an instance by a scalar.
/// </summary>
/// <param name="quaternion">The instance.</param>
/// <param name="scale">The scalar.</param>
/// <param name="result">A new instance containing the result of the calculation.</param>
public static void Multiply(ref Quaternion quaternion, float scale, out Quaternion result)
{
result = new Quaternion(quaternion.X * scale, quaternion.Y * scale, quaternion.Z * scale, quaternion.W * scale);
}
/// <summary>
/// Multiplies an instance by a scalar.
/// </summary>
/// <param name="quaternion">The instance.</param>
/// <param name="scale">The scalar.</param>
/// <returns>A new instance containing the result of the calculation.</returns>
public static Quaternion Multiply(Quaternion quaternion, float scale)
{
return new Quaternion(quaternion.X * scale, quaternion.Y * scale, quaternion.Z * scale, quaternion.W * scale);
}
#endregion
#region Conjugate
/// <summary>
/// Get the conjugate of the given quaternion
/// </summary>
/// <param name="q">The quaternion</param>
/// <returns>The conjugate of the given quaternion</returns>
public static Quaternion Conjugate(Quaternion q)
{
return new Quaternion(-q.Xyz, q.W);
}
/// <summary>
/// Get the conjugate of the given quaternion
/// </summary>
/// <param name="q">The quaternion</param>
/// <param name="result">The conjugate of the given quaternion</param>
public static void Conjugate(ref Quaternion q, out Quaternion result)
{
result = new Quaternion(-q.Xyz, q.W);
}
#endregion
#region Invert
/// <summary>
/// Get the inverse of the given quaternion
/// </summary>
/// <param name="q">The quaternion to invert</param>
/// <returns>The inverse of the given quaternion</returns>
public static Quaternion Invert(Quaternion q)
{
Quaternion result;
Invert(ref q, out result);
return result;
}
/// <summary>
/// Get the inverse of the given quaternion
/// </summary>
/// <param name="q">The quaternion to invert</param>
/// <param name="result">The inverse of the given quaternion</param>
public static void Invert(ref Quaternion q, out Quaternion result)
{
float lengthSq = q.LengthSquared;
if (lengthSq != 0.0)
{
float i = 1.0f / lengthSq;
result = new Quaternion(q.Xyz * -i, q.W * i);
}
else
{
result = q;
}
}
#endregion
#region Normalize
/// <summary>
/// Scale the given quaternion to unit length
/// </summary>
/// <param name="q">The quaternion to normalize</param>
/// <returns>The normalized quaternion</returns>
public static Quaternion Normalize(Quaternion q)
{
Quaternion result;
Normalize(ref q, out result);
return result;
}
/// <summary>
/// Scale the given quaternion to unit length
/// </summary>
/// <param name="q">The quaternion to normalize</param>
/// <param name="result">The normalized quaternion</param>
public static void Normalize(ref Quaternion q, out Quaternion result)
{
float scale = 1.0f / q.Length;
result = new Quaternion(q.Xyz * scale, q.W * scale);
}
#endregion
#region FromAxisAngle
/// <summary>
/// Build a quaternion from the given axis and angle
/// </summary>
/// <param name="axis">The axis to rotate about</param>
/// <param name="angle">The rotation angle in radians</param>
/// <returns></returns>
public static Quaternion FromAxisAngle(Vector3 axis, float angle)
{
if (axis.LengthSquared == 0.0f)
return Identity;
Quaternion result = Identity;
angle *= 0.5f;
axis.Normalize();
result.Xyz = axis * (float)System.Math.Sin(angle);
result.W = (float)System.Math.Cos(angle);
return Normalize(result);
}
#endregion
#region Slerp
/// <summary>
/// Do Spherical linear interpolation between two quaternions
/// </summary>
/// <param name="q1">The first quaternion</param>
/// <param name="q2">The second quaternion</param>
/// <param name="blend">The blend factor</param>
/// <returns>A smooth blend between the given quaternions</returns>
public static Quaternion Slerp(Quaternion q1, Quaternion q2, float blend)
{
// if either input is zero, return the other.
if (q1.LengthSquared == 0.0f)
{
if (q2.LengthSquared == 0.0f)
{
return Identity;
}
return q2;
}
else if (q2.LengthSquared == 0.0f)
{
return q1;
}
float cosHalfAngle = q1.W * q2.W + Vector3.Dot(q1.Xyz, q2.Xyz);
if (cosHalfAngle >= 1.0f || cosHalfAngle <= -1.0f)
{
// angle = 0.0f, so just return one input.
return q1;
}
else if (cosHalfAngle < 0.0f)
{
q2.Xyz = -q2.Xyz;
q2.W = -q2.W;
cosHalfAngle = -cosHalfAngle;
}
float blendA;
float blendB;
if (cosHalfAngle < 0.99f)
{
// do proper slerp for big angles
float halfAngle = (float)System.Math.Acos(cosHalfAngle);
float sinHalfAngle = (float)System.Math.Sin(halfAngle);
float oneOverSinHalfAngle = 1.0f / sinHalfAngle;
blendA = (float)System.Math.Sin(halfAngle * (1.0f - blend)) * oneOverSinHalfAngle;
blendB = (float)System.Math.Sin(halfAngle * blend) * oneOverSinHalfAngle;
}
else
{
// do lerp if angle is really small.
blendA = 1.0f - blend;
blendB = blend;
}
Quaternion result = new Quaternion(blendA * q1.Xyz + blendB * q2.Xyz, blendA * q1.W + blendB * q2.W);
if (result.LengthSquared > 0.0f)
return Normalize(result);
else
return Identity;
}
#endregion
#endregion
#region Operators
/// <summary>
/// Adds two instances.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>The result of the calculation.</returns>
public static Quaternion operator +(Quaternion left, Quaternion right)
{
left.Xyz += right.Xyz;
left.W += right.W;
return left;
}
/// <summary>
/// Subtracts two instances.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>The result of the calculation.</returns>
public static Quaternion operator -(Quaternion left, Quaternion right)
{
left.Xyz -= right.Xyz;
left.W -= right.W;
return left;
}
/// <summary>
/// Multiplies two instances.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>The result of the calculation.</returns>
public static Quaternion operator *(Quaternion left, Quaternion right)
{
Multiply(ref left, ref right, out left);
return left;
}
/// <summary>
/// Multiplies an instance by a scalar.
/// </summary>
/// <param name="quaternion">The instance.</param>
/// <param name="scale">The scalar.</param>
/// <returns>A new instance containing the result of the calculation.</returns>
public static Quaternion operator *(Quaternion quaternion, float scale)
{
Multiply(ref quaternion, scale, out quaternion);
return quaternion;
}
/// <summary>
/// Multiplies an instance by a scalar.
/// </summary>
/// <param name="quaternion">The instance.</param>
/// <param name="scale">The scalar.</param>
/// <returns>A new instance containing the result of the calculation.</returns>
public static Quaternion operator *(float scale, Quaternion quaternion)
{
return new Quaternion(quaternion.X * scale, quaternion.Y * scale, quaternion.Z * scale, quaternion.W * scale);
}
/// <summary>
/// Compares two instances for equality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>True, if left equals right; false otherwise.</returns>
public static bool operator ==(Quaternion left, Quaternion right)
{
return left.Equals(right);
}
/// <summary>
/// Compares two instances for inequality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>True, if left does not equal right; false otherwise.</returns>
public static bool operator !=(Quaternion left, Quaternion right)
{
return !left.Equals(right);
}
#endregion
#region Overrides
#region public override string ToString()
/// <summary>
/// Returns a System.String that represents the current Quaternion.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return String.Format("V: {0}, W: {1}", Xyz, W);
}
#endregion
#region public override bool Equals (object o)
/// <summary>
/// Compares this object instance to another object for equality.
/// </summary>
/// <param name="other">The other object to be used in the comparison.</param>
/// <returns>True if both objects are Quaternions of equal value. Otherwise it returns false.</returns>
public override bool Equals(object other)
{
if (other is Quaternion == false) return false;
return this == (Quaternion)other;
}
#endregion
#region public override int GetHashCode ()
/// <summary>
/// Provides the hash code for this object.
/// </summary>
/// <returns>A hash code formed from the bitwise XOR of this objects members.</returns>
public override int GetHashCode()
{
return Xyz.GetHashCode() ^ W.GetHashCode();
}
#endregion
#endregion
#endregion
#region IEquatable<Quaternion> Members
/// <summary>
/// Compares this Quaternion instance to another Quaternion for equality.
/// </summary>
/// <param name="other">The other Quaternion to be used in the comparison.</param>
/// <returns>True if both instances are equal; false otherwise.</returns>
public bool Equals(Quaternion other)
{
return Xyz == other.Xyz && W == other.W;
}
#endregion
}
}
// flibit Added This!!!
#pragma warning restore 3021

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

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

@ -0,0 +1,323 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 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.Collections.Generic;
using System.Text;
namespace OpenTK
{
#if NO_SYSDRAWING
/// <summary>
/// Represents a rectangular region on a two-dimensional plane.
/// </summary>
public struct Rectangle : IEquatable<Rectangle>
{
#region Fields
Point location;
Size size;
#endregion
#region Constructors
/// <summary>
/// Constructs a new Rectangle instance.
/// </summary>
/// <param name="location">The top-left corner of the Rectangle.</param>
/// <param name="size">The width and height of the Rectangle.</param>
public Rectangle(Point location, Size size)
: this()
{
Location = location;
Size = size;
}
/// <summary>
/// Constructs a new Rectangle instance.
/// </summary>
/// <param name="x">The x coordinate of the Rectangle.</param>
/// <param name="y">The y coordinate of the Rectangle.</param>
/// <param name="width">The width coordinate of the Rectangle.</param>
/// <param name="height">The height coordinate of the Rectangle.</param>
public Rectangle(int x, int y, int width, int height)
: this(new Point(x, y), new Size(width, height))
{ }
#endregion
#region Public Members
/// <summary>
/// Gets or sets the x coordinate of the Rectangle.
/// </summary>
public int X
{
get { return Location.X; }
set { Location = new Point (value, Y); }
}
/// <summary>
/// Gets or sets the y coordinate of the Rectangle.
/// </summary>
public int Y
{
get { return Location.Y; }
set { Location = new Point (X, value); }
}
/// <summary>
/// Gets or sets the width of the Rectangle.
/// </summary>
public int Width
{
get { return Size.Width; }
set { Size = new Size (value, Height); }
}
/// <summary>
/// Gets or sets the height of the Rectangle.
/// </summary>
public int Height
{
get { return Size.Height; }
set { Size = new Size(Width, value); }
}
/// <summary>
/// Gets or sets a <see cref="Point"/> representing the x and y coordinates
/// of the Rectangle.
/// </summary>
public Point Location
{
get { return location; }
set { location = value; }
}
/// <summary>
/// Gets or sets a <see cref="Size"/> representing the width and height
/// of the Rectangle.
/// </summary>
public Size Size
{
get { return size; }
set { size = value; }
}
/// <summary>
/// Gets the y coordinate of the top edge of this Rectangle.
/// </summary>
public int Top { get { return Y; } }
/// <summary>
/// Gets the x coordinate of the right edge of this Rectangle.
/// </summary>
public int Right { get { return X + Width; } }
/// <summary>
/// Gets the y coordinate of the bottom edge of this Rectangle.
/// </summary>
public int Bottom { get { return Y + Height; } }
/// <summary>
/// Gets the x coordinate of the left edge of this Rectangle.
/// </summary>
public int Left { get { return X; } }
/// <summary>
/// Gets a <see cref="System.Boolean"/> that indicates whether this
/// Rectangle is equal to the empty Rectangle.
/// </summary>
public bool IsEmpty
{
get { return Location.IsEmpty && Size.IsEmpty; }
}
/// <summary>
/// Defines the empty Rectangle.
/// </summary>
public static readonly Rectangle Zero = new Rectangle();
/// <summary>
/// Defines the empty Rectangle.
/// </summary>
public static readonly Rectangle Empty = new Rectangle();
/// <summary>
/// Constructs a new instance with the specified edges.
/// </summary>
/// <param name="left">The left edge of the Rectangle.</param>
/// <param name="top">The top edge of the Rectangle.</param>
/// <param name="right">The right edge of the Rectangle.</param>
/// <param name="bottom">The bottom edge of the Rectangle.</param>
/// <returns>A new Rectangle instance with the specified edges.</returns>
public static Rectangle FromLTRB(int left, int top, int right, int bottom)
{
return new Rectangle(new Point(left, top), new Size(right - left, bottom - top));
}
/// <summary>
/// Tests whether this instance contains the specified Point.
/// </summary>
/// <param name="point">The <see cref="Point"/> to test.</param>
/// <returns>True if this instance contains point; false otherwise.</returns>
/// <remarks>The left and top edges are inclusive. The right and bottom edges
/// are exclusive.</remarks>
public bool Contains(Point point)
{
return point.X >= Left && point.X < Right &&
point.Y >= Top && point.Y < Bottom;
}
/// <summary>
/// Tests whether this instance contains the specified Rectangle.
/// </summary>
/// <param name="rect">The <see cref="Rectangle"/> to test.</param>
/// <returns>True if this instance contains rect; false otherwise.</returns>
/// <remarks>The left and top edges are inclusive. The right and bottom edges
/// are exclusive.</remarks>
public bool Contains(Rectangle rect)
{
return Contains(rect.Location) && Contains(rect.Location + rect.Size);
}
/// <summary>
/// Compares two instances for equality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>True, if left is equal to right; false otherwise.</returns>
public static bool operator ==(Rectangle left, Rectangle right)
{
return left.Equals(right);
}
/// <summary>
/// Compares two instances for inequality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>True, if left is not equal to right; false otherwise.</returns>
public static bool operator !=(Rectangle left, Rectangle right)
{
return !left.Equals(right);
}
/// <summary>
/// Converts an OpenTK.Rectangle instance to a System.Drawing.Rectangle.
/// </summary>
/// <param name="rect">
/// The <see cref="Rectangle"/> instance to convert.
/// </param>
/// <returns>
/// A <see cref="System.Drawing.Rectangle"/> instance equivalent to rect.
/// </returns>
public static implicit operator System.Drawing.Rectangle(Rectangle rect)
{
return new System.Drawing.Rectangle(rect.Location, rect.Size);
}
/// <summary>
/// Converts a System.Drawing.Rectangle instance to an OpenTK.Rectangle.
/// </summary>
/// <param name="rect">
/// The <see cref="System.Drawing.Rectangle"/> instance to convert.
/// </param>
/// <returns>
/// A <see cref="Rectangle"/> instance equivalent to point.
/// </returns>
public static implicit operator Rectangle(System.Drawing.Rectangle rect)
{
return new Rectangle(rect.Location, rect.Size);
}
/// <summary>
/// Converts an OpenTK.Rectangle instance to a System.Drawing.RectangleF.
/// </summary>
/// <param name="rect">
/// The <see cref="Rectangle"/> instance to convert.
/// </param>
/// <returns>
/// A <see cref="System.Drawing.RectangleF"/> instance equivalent to rect.
/// </returns>
public static implicit operator System.Drawing.RectangleF(Rectangle rect)
{
return new System.Drawing.RectangleF(rect.Location, rect.Size);
}
/// <summary>
/// Indicates whether this instance is equal to the specified object.
/// </summary>
/// <param name="obj">The object instance to compare to.</param>
/// <returns>True, if both instances are equal; false otherwise.</returns>
public override bool Equals(object obj)
{
if (obj is Rectangle)
return Equals((Rectangle)obj);
return false;
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A <see cref="System.Int32"/> that represents the hash code for this instance./></returns>
public override int GetHashCode()
{
return Location.GetHashCode() & Size.GetHashCode();
}
/// <summary>
/// Returns a <see cref="System.String"/> that describes this instance.
/// </summary>
/// <returns>A <see cref="System.String"/> that describes this instance.</returns>
public override string ToString()
{
return String.Format("{{{0}-{1}}}", Location, Location + Size);
}
#endregion
#region IEquatable<Rectangle> Members
/// <summary>
/// Indicates whether this instance is equal to the specified Rectangle.
/// </summary>
/// <param name="other">The instance to compare to.</param>
/// <returns>True, if both instances are equal; false otherwise.</returns>
public bool Equals(Rectangle other)
{
return Location.Equals(other.Location) &&
Size.Equals(other.Size);
}
#endregion
}
#endif
}

222
src/MiniTK/Math/Size.cs Normal file
Просмотреть файл

@ -0,0 +1,222 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 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.Collections.Generic;
using System.Text;
namespace OpenTK
{
#if NO_SYSDRAWING
/// <summary>
/// Stores the width and height of a rectangle.
/// </summary>
public struct Size : IEquatable<Size>
{
#region Fields
int width, height;
#endregion
#region Constructors
/// <summary>
/// Constructs a new Size instance.
/// </summary>
/// <param name="width">The width of this instance.</param>
/// <param name="height">The height of this instance.</param>
public Size(int width, int height)
: this()
{
Width = width;
Height = height;
}
#endregion
#region Public Members
/// <summary>
/// Gets or sets the width of this instance.
/// </summary>
public int Width
{
get { return width; }
set
{
if (width < 0)
throw new ArgumentOutOfRangeException();
width = value;
}
}
/// <summary>
/// Gets or sets the height of this instance.
/// </summary>
public int Height
{
get { return height; }
set
{
if (height < 0)
throw new ArgumentOutOfRangeException();
height = value;
}
}
/// <summary>
/// Gets a <see cref="System.Boolean"/> that indicates whether this instance is empty or zero.
/// </summary>
public bool IsEmpty
{
get { return Width == 0 && Height == 0; }
}
/// <summary>
/// Returns a Size instance equal to (0, 0).
/// </summary>
public static readonly Size Empty = new Size();
/// <summary>
/// Returns a Size instance equal to (0, 0).
/// </summary>
public static readonly Size Zero = new Size();
/// <summary>
/// Compares two instances for equality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>True, if left is equal to right; false otherwise.</returns>
public static bool operator ==(Size left, Size right)
{
return left.Equals(right);
}
/// <summary>
/// Compares two instances for inequality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>True, if left is not equal to right; false otherwise.</returns>
public static bool operator !=(Size left, Size right)
{
return !left.Equals(right);
}
/// <summary>
/// Converts an OpenTK.Size instance to a System.Drawing.Size.
/// </summary>
/// <param name="size">
/// The <see cref="Size"/> instance to convert.
/// </param>
/// <returns>
/// A <see cref="System.Drawing.Size"/> instance equivalent to size.
/// </returns>
public static implicit operator System.Drawing.Size(Size size)
{
return new System.Drawing.Size(size.Width, size.Height);
}
/// <summary>
/// Converts a System.Drawing.Size instance to an OpenTK.Size.
/// </summary>
/// <param name="size">
/// The <see cref="System.Drawing.Size"/> instance to convert.
/// </param>
/// <returns>
/// A <see cref="Size"/> instance equivalent to size.
/// </returns>
public static implicit operator Size(System.Drawing.Size size)
{
return new Size(size.Width, size.Height);
}
/// <summary>
/// Converts an OpenTK.Point instance to a System.Drawing.SizeF.
/// </summary>
/// <param name="size">
/// The <see cref="Size"/> instance to convert.
/// </param>
/// <returns>
/// A <see cref="System.Drawing.SizeF"/> instance equivalent to size.
/// </returns>
public static implicit operator System.Drawing.SizeF(Size size)
{
return new System.Drawing.SizeF(size.Width, size.Height);
}
/// <summary>
/// Indicates whether this instance is equal to the specified object.
/// </summary>
/// <param name="obj">The object instance to compare to.</param>
/// <returns>True, if both instances are equal; false otherwise.</returns>
public override bool Equals(object obj)
{
if (obj is Size)
return Equals((Size)obj);
return false;
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A <see cref="System.Int32"/> that represents the hash code for this instance./></returns>
public override int GetHashCode()
{
return Width.GetHashCode() ^ Height.GetHashCode();
}
/// <summary>
/// Returns a <see cref="System.String"/> that describes this instance.
/// </summary>
/// <returns>A <see cref="System.String"/> that describes this instance.</returns>
public override string ToString()
{
return String.Format("{{{0}, {1}}}", Width, Height);
}
#endregion
#region IEquatable<Size> Members
/// <summary>
/// Indicates whether this instance is equal to the specified Size.
/// </summary>
/// <param name="other">The instance to compare to.</param>
/// <returns>True, if both instances are equal; false otherwise.</returns>
public bool Equals(Size other)
{
return Width == other.Width && Height == other.Height;
}
#endregion
}
#endif
}

1107
src/MiniTK/Math/Vector2.cs Normal file

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

1010
src/MiniTK/Math/Vector2d.cs Normal file

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

362
src/MiniTK/Math/Vector2h.cs Normal file
Просмотреть файл

@ -0,0 +1,362 @@
#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;
// flibit Added This!!!
#pragma warning disable 3021
namespace OpenTK
{
/// <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>
/// Constructs a new instance.
/// </summary>
/// <param name="value">The value that will initialize this instance.</param>
public Vector2h(Half value)
{
X = value;
Y = value;
}
/// <summary>
/// Constructs a new instance.
/// </summary>
/// <param name="value">The value that will initialize this instance.</param>
public Vector2h(Single value)
{
X = new Half(value);
Y = new Half(value);
}
/// <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.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.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.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.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.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.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.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.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.Vector2</returns>
public Vector2 ToVector2()
{
return new Vector2(X, Y);
}
/// <summary>
/// Returns this Half2 instance's contents as Vector2d.
/// </summary>
public Vector2d ToVector2d()
{
return new Vector2d(X, Y);
}
#endregion Half -> Single
#region Conversions
/// <summary>Converts OpenTK.Vector2 to OpenTK.Half2.</summary>
/// <param name="v">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.Vector2d to OpenTK.Half2.</summary>
/// <param name="v">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.Half2 to OpenTK.Vector2.</summary>
/// <param name="h">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.Half2 to OpenTK.Vector2d.</summary>
/// <param name="h">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.Half2 vector.</summary>
/// <param name="other">OpenTK.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
}
}
// flibit Added This!!!
#pragma warning restore 3021

1387
src/MiniTK/Math/Vector3.cs Normal file

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

1400
src/MiniTK/Math/Vector3d.cs Normal file

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

409
src/MiniTK/Math/Vector3h.cs Normal file
Просмотреть файл

@ -0,0 +1,409 @@
#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;
using System.Xml.Serialization;
// flibit Added This!!!
#pragma warning disable 3021
namespace OpenTK
{
/// <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>
/// Constructs a new instance.
/// </summary>
/// <param name="value">The value that will initialize this instance.</param>
public Vector3h(Half value)
{
X = value;
Y = value;
Z = value;
}
/// <summary>
/// Constructs a new instance.
/// </summary>
/// <param name="value">The value that will initialize this instance.</param>
public Vector3h(Single value)
{
X = new Half(value);
Y = new Half(value);
Z = new Half(value);
}
/// <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.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.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.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.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.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.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.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.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 Swizzle
/// <summary>
/// Gets or sets an OpenTK.Vector2h with the X and Y components of this instance.
/// </summary>
[XmlIgnore]
public Vector2h Xy { get { return new Vector2h(X, Y); } set { X = value.X; Y = value.Y; } }
#endregion
#region Half -> Single
/// <summary>
/// Returns this Half3 instance's contents as Vector3.
/// </summary>
/// <returns>OpenTK.Vector3</returns>
public Vector3 ToVector3()
{
return new Vector3(X, Y, Z);
}
/// <summary>
/// Returns this Half3 instance's contents as Vector3d.
/// </summary>
public Vector3d ToVector3d()
{
return new Vector3d(X, Y, Z);
}
#endregion Half -> Single
#region Conversions
/// <summary>Converts OpenTK.Vector3 to OpenTK.Half3.</summary>
/// <param name="v3f">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.Vector3d to OpenTK.Half3.</summary>
/// <param name="v3d">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.Half3 to OpenTK.Vector3.</summary>
/// <param name="h3">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.Half3 to OpenTK.Vector3d.</summary>
/// <param name="h3">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.Half3 vector.</summary>
/// <param name="other">OpenTK.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
}
}
// flibit Added This!!!
#pragma warning restore 3021

1220
src/MiniTK/Math/Vector4.cs Normal file

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

1238
src/MiniTK/Math/Vector4d.cs Normal file

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

444
src/MiniTK/Math/Vector4h.cs Normal file
Просмотреть файл

@ -0,0 +1,444 @@
#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;
using System.Xml.Serialization;
// flibit Added This!!!
#pragma warning disable 3021
namespace OpenTK
{
/// <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>
/// Constructs a new instance.
/// </summary>
/// <param name="value">The value that will initialize this instance.</param>
public Vector4h(Half value)
{
X = value;
Y = value;
Z = value;
W = value;
}
/// <summary>
/// Constructs a new instance.
/// </summary>
/// <param name="value">The value that will initialize this instance.</param>
public Vector4h(Single value)
{
X = new Half(value);
Y = new Half(value);
Z = new Half(value);
W = new Half(value);
}
/// <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.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.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.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.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.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.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.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.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 Swizzle
/// <summary>
/// Gets or sets an OpenTK.Vector2h with the X and Y components of this instance.
/// </summary>
[XmlIgnore]
public Vector2h Xy { get { return new Vector2h(X, Y); } set { X = value.X; Y = value.Y; } }
/// <summary>
/// Gets or sets an OpenTK.Vector3h with the X, Y and Z components of this instance.
/// </summary>
[XmlIgnore]
public Vector3h Xyz { get { return new Vector3h(X, Y, Z); } set { X = value.X; Y = value.Y; Z = value.Z; } }
#endregion
#region Half -> Single
/// <summary>
/// Returns this Half4 instance's contents as Vector4.
/// </summary>
/// <returns>OpenTK.Vector4</returns>
public Vector4 ToVector4()
{
return new Vector4(X, Y, Z, W);
}
/// <summary>
/// Returns this Half4 instance's contents as Vector4d.
/// </summary>
public Vector4d ToVector4d()
{
return new Vector4d(X, Y, Z, W);
}
#endregion Half -> Single
#region Conversions
/// <summary>Converts OpenTK.Vector4 to OpenTK.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.Vector4d to OpenTK.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.Half4 to OpenTK.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.Half4 to OpenTK.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.Half4 vector.</summary>
/// <param name="other">OpenTK.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
}
}
// flibit Added This!!!
#pragma warning restore 3021