Removed OpenTK.Compatibility
This commit is contained in:
parent
5e444a6bd9
commit
0d9b1115f3
112 changed files with 0 additions and 329573 deletions
17
OpenTK.sln
17
OpenTK.sln
|
@ -9,11 +9,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTK", "Source\OpenTK\Ope
|
||||||
{C426C9D1-8857-4E52-BAC7-4C05EE6070AB} = {C426C9D1-8857-4E52-BAC7-4C05EE6070AB}
|
{C426C9D1-8857-4E52-BAC7-4C05EE6070AB} = {C426C9D1-8857-4E52-BAC7-4C05EE6070AB}
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTK.Compatibility", "Source\Compatibility\OpenTK.Compatibility.csproj", "{62C0DB35-0000-0000-0000-000000000000}"
|
|
||||||
ProjectSection(ProjectDependencies) = postProject
|
|
||||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8}
|
|
||||||
EndProjectSection
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTK.Examples", "Source\Examples\OpenTK.Examples.csproj", "{868E37B3-0000-0000-0000-000000000000}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTK.Examples", "Source\Examples\OpenTK.Examples.csproj", "{868E37B3-0000-0000-0000-000000000000}"
|
||||||
ProjectSection(ProjectDependencies) = postProject
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8}
|
{75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8}
|
||||||
|
@ -27,7 +22,6 @@ EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build.Installer.Nsis", "Installers\Nsis\Build.Installer.Nsis.csproj", "{ADC34399-7613-44D2-90B2-19250F06FE7A}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build.Installer.Nsis", "Installers\Nsis\Build.Installer.Nsis.csproj", "{ADC34399-7613-44D2-90B2-19250F06FE7A}"
|
||||||
ProjectSection(ProjectDependencies) = postProject
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
{A37A7E14-0000-0000-0000-000000000000} = {A37A7E14-0000-0000-0000-000000000000}
|
{A37A7E14-0000-0000-0000-000000000000} = {A37A7E14-0000-0000-0000-000000000000}
|
||||||
{62C0DB35-0000-0000-0000-000000000000} = {62C0DB35-0000-0000-0000-000000000000}
|
|
||||||
{650C6F3D-33B5-4216-9536-956AB42C0624} = {650C6F3D-33B5-4216-9536-956AB42C0624}
|
{650C6F3D-33B5-4216-9536-956AB42C0624} = {650C6F3D-33B5-4216-9536-956AB42C0624}
|
||||||
{A625BE88-0000-0000-0000-000000000000} = {A625BE88-0000-0000-0000-000000000000}
|
{A625BE88-0000-0000-0000-000000000000} = {A625BE88-0000-0000-0000-000000000000}
|
||||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8}
|
{75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8}
|
||||||
|
@ -54,7 +48,6 @@ EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build.Installer.Zip", "Installers\Zip\Build.Installer.Zip.csproj", "{ADC34399-7613-44D2-90B2-19250F06FE7B}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build.Installer.Zip", "Installers\Zip\Build.Installer.Zip.csproj", "{ADC34399-7613-44D2-90B2-19250F06FE7B}"
|
||||||
ProjectSection(ProjectDependencies) = postProject
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
{A37A7E14-0000-0000-0000-000000000000} = {A37A7E14-0000-0000-0000-000000000000}
|
{A37A7E14-0000-0000-0000-000000000000} = {A37A7E14-0000-0000-0000-000000000000}
|
||||||
{62C0DB35-0000-0000-0000-000000000000} = {62C0DB35-0000-0000-0000-000000000000}
|
|
||||||
{650C6F3D-33B5-4216-9536-956AB42C0624} = {650C6F3D-33B5-4216-9536-956AB42C0624}
|
{650C6F3D-33B5-4216-9536-956AB42C0624} = {650C6F3D-33B5-4216-9536-956AB42C0624}
|
||||||
{A625BE88-0000-0000-0000-000000000000} = {A625BE88-0000-0000-0000-000000000000}
|
{A625BE88-0000-0000-0000-000000000000} = {A625BE88-0000-0000-0000-000000000000}
|
||||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8}
|
{75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8}
|
||||||
|
@ -64,7 +57,6 @@ EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build.Installer.Nuget", "Installers\Nuget\Build.Installer.Nuget.csproj", "{ADC34399-7613-44D2-90B2-19250F12FE7B}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build.Installer.Nuget", "Installers\Nuget\Build.Installer.Nuget.csproj", "{ADC34399-7613-44D2-90B2-19250F12FE7B}"
|
||||||
ProjectSection(ProjectDependencies) = postProject
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
{A37A7E14-0000-0000-0000-000000000000} = {A37A7E14-0000-0000-0000-000000000000}
|
{A37A7E14-0000-0000-0000-000000000000} = {A37A7E14-0000-0000-0000-000000000000}
|
||||||
{62C0DB35-0000-0000-0000-000000000000} = {62C0DB35-0000-0000-0000-000000000000}
|
|
||||||
{650C6F3D-33B5-4216-9536-956AB42C0624} = {650C6F3D-33B5-4216-9536-956AB42C0624}
|
{650C6F3D-33B5-4216-9536-956AB42C0624} = {650C6F3D-33B5-4216-9536-956AB42C0624}
|
||||||
{A625BE88-0000-0000-0000-000000000000} = {A625BE88-0000-0000-0000-000000000000}
|
{A625BE88-0000-0000-0000-000000000000} = {A625BE88-0000-0000-0000-000000000000}
|
||||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8}
|
{75DC22B1-113F-4A66-96B9-2FF8208C10E8} = {75DC22B1-113F-4A66-96B9-2FF8208C10E8}
|
||||||
|
@ -105,15 +97,6 @@ Global
|
||||||
{A37A7E14-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU
|
{A37A7E14-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{A37A7E14-0000-0000-0000-000000000000}.ReleaseMinimal|Any CPU.ActiveCfg = ReleaseMinimal|Any CPU
|
{A37A7E14-0000-0000-0000-000000000000}.ReleaseMinimal|Any CPU.ActiveCfg = ReleaseMinimal|Any CPU
|
||||||
{A37A7E14-0000-0000-0000-000000000000}.ReleaseMinimal|Any CPU.Build.0 = ReleaseMinimal|Any CPU
|
{A37A7E14-0000-0000-0000-000000000000}.ReleaseMinimal|Any CPU.Build.0 = ReleaseMinimal|Any CPU
|
||||||
{62C0DB35-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{62C0DB35-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{62C0DB35-0000-0000-0000-000000000000}.DebugMinimal|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{62C0DB35-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
|
|
||||||
{62C0DB35-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU
|
|
||||||
{62C0DB35-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU
|
|
||||||
{62C0DB35-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{62C0DB35-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{62C0DB35-0000-0000-0000-000000000000}.ReleaseMinimal|Any CPU.ActiveCfg = ReleaseMinimal|Any CPU
|
|
||||||
{868E37B3-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{868E37B3-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{868E37B3-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{868E37B3-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{868E37B3-0000-0000-0000-000000000000}.DebugMinimal|Any CPU.ActiveCfg = Debug|Any CPU
|
{868E37B3-0000-0000-0000-000000000000}.DebugMinimal|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
|
|
@ -1,235 +0,0 @@
|
||||||
#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 details.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace OpenTK.Audio
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Encapsulates a sound stream and provides decoding and streaming capabilities.
|
|
||||||
/// </summary>
|
|
||||||
public class AudioReader : IDisposable
|
|
||||||
{
|
|
||||||
static object reader_lock = new object();
|
|
||||||
static List<AudioReader> readers = new List<AudioReader>();
|
|
||||||
|
|
||||||
bool disposed;
|
|
||||||
Stream stream;
|
|
||||||
AudioReader implementation;
|
|
||||||
|
|
||||||
#region --- Constructors ---
|
|
||||||
|
|
||||||
#region static AudioReader()
|
|
||||||
|
|
||||||
static AudioReader()
|
|
||||||
{
|
|
||||||
// TODO: Plugin architecture for sound formats. This is overkill now that we only have a WaveReader (future proofing).
|
|
||||||
readers.Add(new WaveReader());
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region protected AudioReader()
|
|
||||||
|
|
||||||
protected AudioReader() { }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public AudioReader(string filename)
|
|
||||||
|
|
||||||
/// <summary>Creates a new AudioReader that can read the specified sound file.</summary>
|
|
||||||
/// <param name="filename">The path to the sound file.</param>
|
|
||||||
/// <returns>A new OpenTK.Audio.AudioReader, which can be used to read from the specified sound file.</returns>
|
|
||||||
public AudioReader(string filename)
|
|
||||||
: this(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
|
||||||
{ }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public AudioReader(Stream s)
|
|
||||||
|
|
||||||
/// <summary>Creates a new AudioReader that can read the specified soundstream.</summary>
|
|
||||||
/// <param name="s">The System.IO.Stream to read from.</param>
|
|
||||||
/// <returns>A new OpenTK.Audio.AudioReader, which can be used to read from the specified sound stream.</returns>
|
|
||||||
public AudioReader(Stream s)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
lock (reader_lock)
|
|
||||||
{
|
|
||||||
foreach (AudioReader reader in readers)
|
|
||||||
{
|
|
||||||
long pos = s.Position;
|
|
||||||
if (reader.Supports(s))
|
|
||||||
{
|
|
||||||
s.Position = pos;
|
|
||||||
implementation = (AudioReader)
|
|
||||||
reader.GetType().GetConstructor(
|
|
||||||
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public |
|
|
||||||
System.Reflection.BindingFlags.Instance,
|
|
||||||
null,
|
|
||||||
new Type[] { typeof(Stream) },
|
|
||||||
null)
|
|
||||||
.Invoke(new object[] { s });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
s.Position = pos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
s.Close();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
throw new NotSupportedException("Could not find a decoder for the specified sound stream.");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- Public Members ---
|
|
||||||
|
|
||||||
#region public virtual bool Supports(Stream s)
|
|
||||||
|
|
||||||
/// <summary>When overriden in a derived class, checks if the decoder supports the specified sound stream.</summary>
|
|
||||||
/// <param name="s">The System.IO.Stream to check.</param>
|
|
||||||
/// <returns>True if the sound stream is supported; false otherwise.</returns>
|
|
||||||
public virtual bool Supports(Stream s)
|
|
||||||
{
|
|
||||||
if (implementation != null)
|
|
||||||
return implementation.Supports(s);
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public virtual SoundData<SampleType> ReadSamples(long count)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// When overriden in a derived class, reads and decodes the specified number of samples from the sound stream.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="count">The number of samples to read and decode.</param>
|
|
||||||
/// <returns>An OpenTK.Audio.SoundData object that contains the decoded buffer.</returns>
|
|
||||||
public virtual SoundData ReadSamples(long count)
|
|
||||||
{
|
|
||||||
if (implementation != null)
|
|
||||||
return implementation.ReadSamples(count);
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public virtual SoundData<SampleType> ReadToEnd()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// When overriden in a derived class, reads and decodes the sound stream.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>An OpenTK.Audio.SoundData object that contains the decoded buffer.</returns>
|
|
||||||
public virtual SoundData ReadToEnd()
|
|
||||||
{
|
|
||||||
if (implementation != null)
|
|
||||||
return implementation.ReadToEnd();
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public virtual int Frequency
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public virtual int Frequency
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (implementation != null)
|
|
||||||
return implementation.Frequency;
|
|
||||||
else
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
protected set
|
|
||||||
{
|
|
||||||
if (implementation != null)
|
|
||||||
implementation.Frequency = value;
|
|
||||||
else
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public virtual bool EndOfFile
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns true if the AudioReader has reached the end of the file.
|
|
||||||
/// </summary>
|
|
||||||
public virtual bool EndOfFile
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (implementation != null)
|
|
||||||
return implementation.EndOfFile;
|
|
||||||
|
|
||||||
return this.Stream.Position >= this.Stream.Length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- Protected Members ---
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the input <see cref="System.IO.Stream"/> of the AudioReader.
|
|
||||||
/// </summary>
|
|
||||||
protected virtual Stream Stream
|
|
||||||
{
|
|
||||||
get { return stream; }
|
|
||||||
set { stream = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
/// <summary>Closes the underlying Stream and disposes of the AudioReader resources.</summary>
|
|
||||||
public virtual void Dispose()
|
|
||||||
{
|
|
||||||
this.Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Dispose(bool manual)
|
|
||||||
{
|
|
||||||
if (!disposed)
|
|
||||||
{
|
|
||||||
if (manual)
|
|
||||||
if (this.Stream != null)
|
|
||||||
this.Stream.Close();
|
|
||||||
|
|
||||||
disposed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Finalizes this AudioReader.
|
|
||||||
/// </summary>
|
|
||||||
~AudioReader()
|
|
||||||
{
|
|
||||||
this.Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
#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 details.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OpenTK.Audio
|
|
||||||
{
|
|
||||||
/// <summary>Represents exceptions related to OpenTK.Audio.AudioReader objects.</summary>
|
|
||||||
public class AudioReaderException : AudioException
|
|
||||||
{
|
|
||||||
/// <summary>Constructs a new AudioReaderException.</summary>
|
|
||||||
public AudioReaderException() : base() { }
|
|
||||||
/// <summary>Constructs a new AudioReaderException with the specified error message.</summary>
|
|
||||||
/// <param name="message">The error message of the AudioReaderException.</param>
|
|
||||||
public AudioReaderException(string message) : base(message) { }
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,431 +0,0 @@
|
||||||
#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
|
|
||||||
{
|
|
||||||
|
|
||||||
///<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 Source’s 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 Source’s 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 Source’s 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 Source’s reflected sound is not filtered at all according to the Source’s 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 Source’s 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 won’t 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,
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,361 +0,0 @@
|
||||||
#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
|
|
||||||
{
|
|
||||||
#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
|
|
||||||
{
|
|
||||||
VocalMorpherPhonemeA = 0,
|
|
||||||
VocalMorpherPhonemeE = 1,
|
|
||||||
VocalMorpherPhonemeI = 2,
|
|
||||||
VocalMorpherPhonemeO = 3,
|
|
||||||
VocalMorpherPhonemeU = 4,
|
|
||||||
VocalMorpherPhonemeAA = 5,
|
|
||||||
VocalMorpherPhonemeAE = 6,
|
|
||||||
VocalMorpherPhonemeAH = 7,
|
|
||||||
VocalMorpherPhonemeAO = 8,
|
|
||||||
VocalMorpherPhonemeEH = 9,
|
|
||||||
VocalMorpherPhonemeER = 10,
|
|
||||||
VocalMorpherPhonemeIH = 11,
|
|
||||||
VocalMorpherPhonemeIY = 12,
|
|
||||||
VocalMorpherPhonemeUH = 13,
|
|
||||||
VocalMorpherPhonemeUW = 14,
|
|
||||||
VocalMorpherPhonemeB = 15,
|
|
||||||
VocalMorpherPhonemeD = 16,
|
|
||||||
VocalMorpherPhonemeF = 17,
|
|
||||||
VocalMorpherPhonemeG = 18,
|
|
||||||
VocalMorpherPhonemeJ = 19,
|
|
||||||
VocalMorpherPhonemeK = 20,
|
|
||||||
VocalMorpherPhonemeL = 21,
|
|
||||||
VocalMorpherPhonemeM = 22,
|
|
||||||
VocalMorpherPhonemeN = 23,
|
|
||||||
VocalMorpherPhonemeP = 24,
|
|
||||||
VocalMorpherPhonemeR = 25,
|
|
||||||
VocalMorpherPhonemeS = 26,
|
|
||||||
VocalMorpherPhonemeT = 27,
|
|
||||||
VocalMorpherPhonemeV = 28,
|
|
||||||
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
|
|
||||||
}
|
|
|
@ -1,367 +0,0 @@
|
||||||
#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;
|
|
||||||
|
|
||||||
|
|
||||||
namespace OpenTK.Audio
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,193 +0,0 @@
|
||||||
#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;
|
|
||||||
|
|
||||||
namespace OpenTK.Audio
|
|
||||||
{
|
|
||||||
|
|
||||||
///<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
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,406 +0,0 @@
|
||||||
#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;
|
|
||||||
|
|
||||||
/* 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
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <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
|
|
||||||
|
|
||||||
/// <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>
|
|
||||||
[DllImport(Alc.Lib, EntryPoint = "alcCreateContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity]
|
|
||||||
[CLSCompliant(false)]
|
|
||||||
unsafe public static extern ContextHandle CreateContext([In] IntPtr device, [In] int* 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
|
|
||||||
|
|
||||||
/// <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>
|
|
||||||
[DllImport(Alc.Lib, EntryPoint = "alcMakeContextCurrent", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern bool MakeContextCurrent([In] ContextHandle context);
|
|
||||||
// ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent( ALCcontext *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>
|
|
||||||
[DllImport(Alc.Lib, EntryPoint = "alcProcessContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern void ProcessContext([In] ContextHandle context);
|
|
||||||
// ALC_API void ALC_APIENTRY alcProcessContext( ALCcontext *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>
|
|
||||||
[DllImport(Alc.Lib, EntryPoint = "alcSuspendContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern void SuspendContext([In] ContextHandle context);
|
|
||||||
// ALC_API void ALC_APIENTRY alcSuspendContext( ALCcontext *context );
|
|
||||||
|
|
||||||
/// <summary>This function destroys a context.</summary>
|
|
||||||
/// <param name="context">a pointer to the new context.</param>
|
|
||||||
[DllImport(Alc.Lib, EntryPoint = "alcDestroyContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern void DestroyContext([In] ContextHandle context);
|
|
||||||
// ALC_API void ALC_APIENTRY alcDestroyContext( ALCcontext *context );
|
|
||||||
|
|
||||||
/// <summary>This function retrieves the current context.</summary>
|
|
||||||
/// <returns>Returns a pointer to the current context.</returns>
|
|
||||||
[DllImport(Alc.Lib, EntryPoint = "alcGetCurrentContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern ContextHandle GetCurrentContext();
|
|
||||||
// ALC_API ALCcontext * ALC_APIENTRY alcGetCurrentContext( void );
|
|
||||||
|
|
||||||
/// <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>
|
|
||||||
[DllImport(Alc.Lib, EntryPoint = "alcGetContextsDevice", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern IntPtr GetContextsDevice([In] ContextHandle context);
|
|
||||||
// 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
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,135 +0,0 @@
|
||||||
#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
|
|
||||||
{
|
|
||||||
/// <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.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="OpenTK.Audio.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="OpenTK.Audio.Alc.GetInteger(IntPtr, AlcGetInteger, int, out 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,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,172 +0,0 @@
|
||||||
#region --- OpenTK.OpenAL License ---
|
|
||||||
/* AlutFunctions.cs
|
|
||||||
* C header: \freealut-1.1.0-src\include\AL\Alut.h
|
|
||||||
* Spec: http://www.openal.org/openal_webstf/specs/alut.html
|
|
||||||
* Copyright (c) 2008 Christoph Brandtner and Stefanos Apostolopoulos
|
|
||||||
* See license.txt for license details
|
|
||||||
* http://www.OpenTK.net */
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Security;
|
|
||||||
|
|
||||||
namespace OpenTK.Audio
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>Alut, FreeAlut = Free Audio Library Utilities</summary>
|
|
||||||
[Obsolete("Use OpenTK.Audio.AudioContext and OpenTK.Audio.Alc instead.")]
|
|
||||||
public static class Alut
|
|
||||||
{
|
|
||||||
#region Constants
|
|
||||||
|
|
||||||
private const string Lib = "alut.dll";
|
|
||||||
private const CallingConvention Style = CallingConvention.Cdecl;
|
|
||||||
|
|
||||||
#endregion Constants
|
|
||||||
|
|
||||||
#region Init/Exit
|
|
||||||
|
|
||||||
/// <summary>Alut.Init initializes the ALUT internals and creates an OpenAL context on the default device and makes it the current OpenAL context. If you want something more complex than that (e.g. running on a non-default device or opening multiple contexts on multiple devices), you can use alutInitWithoutContext instead. alutInit examines the commandline arguments passed to it and remove those it recognizes. It is acceptable to pass two NULL pointers in settings where no useful information can be obtained from argc and argv.</summary>
|
|
||||||
/// <param name="argcp">Application Main Parameters. Can be IntPtr.Zero.</param>
|
|
||||||
/// <param name="argv">Application Main Parameters. Can be IntPtr.Zero.</param>
|
|
||||||
/// <returns>Success.</returns>
|
|
||||||
[DllImport(Alut.Lib, EntryPoint = "alutInit", ExactSpelling = true, CallingConvention = Alut.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern bool Init([In] IntPtr argcp, [In] IntPtr argv);
|
|
||||||
// ALUT_API ALboolean ALUT_APIENTRY alutInit (int *argcp, char **argv);
|
|
||||||
|
|
||||||
/// <summary>Parameterless function for convenience. Internally passes IntPtr.Zero as parameters.</summary>
|
|
||||||
/// <returns>Success.</returns>
|
|
||||||
public static bool Init() // overload for convenience
|
|
||||||
{
|
|
||||||
return Init(IntPtr.Zero, IntPtr.Zero);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Alut.InitWithoutContext initializes the ALUT internals. It does not create any OpenAL context or device, so this has to be done via the usual ALC calls. alutInitWithoutContext examines the commandline arguments passed to it and remove those it recognizes. It is acceptable to pass two NULL pointers in settings where no useful information can be obtained from argc and argv.</summary>
|
|
||||||
/// <param name="argcp">Application Main Parameters</param>
|
|
||||||
/// <param name="argv">Application Main Parameters</param>
|
|
||||||
/// <returns>Success.</returns>
|
|
||||||
[DllImport(Alut.Lib, EntryPoint = "alutInitWithoutContext", ExactSpelling = true, CallingConvention = Alut.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern bool InitWithoutContext([In] IntPtr argcp, [In] IntPtr argv);
|
|
||||||
// ALUT_API ALboolean ALUT_APIENTRY alutInitWithoutContext (int *argcp, char **argv);
|
|
||||||
|
|
||||||
/// <summary>Alut.InitWithoutContext initializes the ALUT internals. It does not create any OpenAL context or device, so this has to be done via the usual ALC calls. alutInitWithoutContext examines the commandline arguments passed to it and remove those it recognizes. It is acceptable to pass two NULL pointers in settings where no useful information can be obtained from argc and argv.</summary>
|
|
||||||
/// <returns>Success.</returns>
|
|
||||||
public static bool InitWithoutContext() // overload for convenience
|
|
||||||
{
|
|
||||||
return InitWithoutContext(IntPtr.Zero, IntPtr.Zero);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>When the application has finished playing audio, it should shut down ALUT using Alut.Exit. This closes any OpenAL device/context that ALUT may have created in alutInit (but not any that the application created using ALC). After calling alutExit, you may subsequently call alutInit or alutInitWithoutContext again. Note that under well-behaved operating systems, it should be acceptable to simply exit from your program without bothering to call alutExit, relying on the OS to clean up after you. However, it is dangerous to rely on this behavior if portable operation is expected.</summary>
|
|
||||||
/// <returns>Success.</returns>
|
|
||||||
[DllImport(Alut.Lib, EntryPoint = "alutExit", ExactSpelling = true, CallingConvention = Alut.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern bool Exit();
|
|
||||||
// ALUT_API ALboolean ALUT_APIENTRY alutExit (void);
|
|
||||||
|
|
||||||
#endregion Init/Exit
|
|
||||||
|
|
||||||
#region Error Checking
|
|
||||||
|
|
||||||
/// <summary>Any ALUT routine that fails will return AL_FALSE / AL_NONE / NULL and set the global error state. If a subsequent error occurs while there is still an error recorded internally, the second error will simply be ignored. Calling alutGetError will reset the error code to ALUT_ERROR_NO_ERROR. Note that the error state is not cleared by other successful ALUT calls. Alut.GetError can be called in any ALUT state and will never fail.</summary>
|
|
||||||
/// <returns><see cref="AlutError"/></returns>
|
|
||||||
[DllImport(Alut.Lib, EntryPoint = "alutGetError", ExactSpelling = true, CallingConvention = Alut.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern AlutError GetError();
|
|
||||||
// ALUT_API ALenum ALUT_APIENTRY alutGetError (void);
|
|
||||||
|
|
||||||
[DllImport(Alut.Lib, EntryPoint = "alutGetErrorString", ExactSpelling = true, CallingConvention = Alut.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
|
|
||||||
private static extern IntPtr GetErrorStringPrivate(AlutError error);
|
|
||||||
// ALUT_API const char *ALUT_APIENTRY alutGetErrorString (ALenum error);
|
|
||||||
|
|
||||||
/// <summary>Alut.GetErrorString can be used to convert an error code into a human-readable description. The precise text of these descriptions may vary from implementation to implementation and should not be relied upon by the application.</summary>
|
|
||||||
/// <param name="error">Retrieve first occured error with Alut.GetError</param>
|
|
||||||
/// <returns>A human-readable description of the Error.</returns>
|
|
||||||
public static string GetErrorString(AlutError error)
|
|
||||||
{
|
|
||||||
return Marshal.PtrToStringAnsi(GetErrorStringPrivate(error));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion Error Checking
|
|
||||||
|
|
||||||
#region File Loading
|
|
||||||
|
|
||||||
/// <summary>Alut.CreateBufferFromFile tries to guess the sound buffer format by looking at the filename and/or the file contents and loads the sound buffer into an OpenAL buffer.</summary>
|
|
||||||
/// <param name="filename">The file to be loaded</param>
|
|
||||||
/// <returns>OpenAL Buffer, 0 on failure.</returns>
|
|
||||||
[CLSCompliant(false), DllImport(Alut.Lib, EntryPoint = "alutCreateBufferFromFile", ExactSpelling = true, CallingConvention = Alut.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern uint CreateBufferFromFile([In] string filename);
|
|
||||||
// ALUT_API ALuint ALUT_APIENTRY alutCreateBufferFromFile (const char *fileName);
|
|
||||||
|
|
||||||
/// <summary>Alut.CreateBufferFromFileImage tries to guess the sound buffer format by looking at the contents of the memory region given as parameters and loads the sound buffer into an OpenAL buffer.</summary>
|
|
||||||
/// <param name="buffer">A Pointer to the sound buffer in memory.</param>
|
|
||||||
/// <param name="length">Size in Bytes of the sound buffer.</param>
|
|
||||||
/// <returns>OpenAL Buffer, 0 on failure.</returns>
|
|
||||||
[CLSCompliant(false), DllImport(Alut.Lib, EntryPoint = "alutCreateBufferFromFileImage", ExactSpelling = true, CallingConvention = Alut.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern uint CreateBufferFromFileImage([In] IntPtr buffer, int length);
|
|
||||||
// ALUT_API ALuint ALUT_APIENTRY alutCreateBufferFromFileImage (const ALvoid *buffer, ALsizei length);
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>Alut.CreateBufferHelloWorld returns a handle to an OpenAL buffer containing the sound of someone saying 'Hello, world!'.</summary>
|
|
||||||
/// <returns>OpenAL Buffer, 0 on failure.</returns>
|
|
||||||
[CLSCompliant(false), DllImport(Alut.Lib, EntryPoint = "alutCreateBufferHelloWorld", ExactSpelling = true, CallingConvention = Alut.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern uint CreateBufferHelloWorld();
|
|
||||||
//ALUT_API ALuint ALUT_APIENTRY alutCreateBufferHelloWorld (void);
|
|
||||||
|
|
||||||
/// <summary>Alut.CreateBufferWaveform returns a handle to an OpenAL buffer containing a snippet of audio with the specified waveshape at the specified frequency (in hertz), phase (in degrees: -180 to +180) and duration (in seconds).</summary>
|
|
||||||
/// <param name="waveshape"></param>
|
|
||||||
/// <param name="frequency">Frequency in hertz [Hz].</param>
|
|
||||||
/// <param name="phase">Phase (in degrees: -180 to +180)</param>
|
|
||||||
/// <param name="duration">Duration (in seconds)</param>
|
|
||||||
/// <returns>OpenAL Buffer, 0 on failure.</returns>
|
|
||||||
[CLSCompliant(false), DllImport(Alut.Lib, EntryPoint = "alutCreateBufferWaveform", ExactSpelling = true, CallingConvention = Alut.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern uint CreateBufferWaveform(AlutWaveform waveshape, float frequency, float phase, float duration);
|
|
||||||
// ALUT_API ALuint ALUT_APIENTRY alutCreateBufferWaveform (ALenum waveshape, ALfloat frequency, ALfloat phase, ALfloat duration);
|
|
||||||
|
|
||||||
// Warning: these leak memory if not properly free'd
|
|
||||||
// ALUT_API ALvoid *ALUT_APIENTRY alutLoadMemoryFromFile (const char *fileName, ALenum *format, ALsizei *size, ALfloat *frequency);
|
|
||||||
// ALUT_API ALvoid *ALUT_APIENTRY alutLoadMemoryFromFileImage (const ALvoid *buffer, ALsizei length, ALenum *format, ALsizei *size, ALfloat *frequency);
|
|
||||||
// ALUT_API ALvoid *ALUT_APIENTRY alutLoadMemoryHelloWorld (ALenum *format, ALsizei *size, ALfloat *frequency);
|
|
||||||
// ALUT_API ALvoid *ALUT_APIENTRY alutLoadMemoryWaveform (ALenum waveshape, ALfloat frequency, ALfloat phase, ALfloat duration, ALenum *format, ALsizei *size, ALfloat *freq);
|
|
||||||
|
|
||||||
#endregion File Loading
|
|
||||||
|
|
||||||
#region Misc
|
|
||||||
[DllImport(Alut.Lib, EntryPoint = "alutGetMIMETypes", ExactSpelling = true, CallingConvention = Alut.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
|
|
||||||
private static extern IntPtr GetMIMETypesPrivate(AlutLoader loader);
|
|
||||||
// ALUT_API const char *ALUT_APIENTRY alutGetMIMETypes (ALenum loader);
|
|
||||||
|
|
||||||
/// <summary>Alut.GetMIMETypes returns a comma-separated list of supported MIME types for the given loader type, e.g. something like "audio/basic,audio/mpeg,audio/x-wav".
|
|
||||||
/// It is possible that AlutLoader.Memory loaders will be unable to support some file types that AlutLoader.Buffer loaders can support (although the reverse is never the case). Furthermore, it is possible that for some file types (notably audio/x-wav) the support may be only for a few sub-formats. For example, an implementation may advertise that audio/x-wav is supported when in fact it only supports uncompressed (i.e. PCM) WAV files and not any of the compressed subformats. In this event, the various ALUT loaders may return an error and set ALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE rather than ALUT_ERROR_UNSUPPORTED_FILE_TYPE which would indicate that no files of this type are allowed.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="loader"><see cref="AlutLoader"/></param>
|
|
||||||
/// <returns>A comma-separated list of supported MIME types.</returns>
|
|
||||||
public static string GetMIMETypes(AlutLoader loader)
|
|
||||||
{
|
|
||||||
return Marshal.PtrToStringAnsi(GetMIMETypesPrivate(loader));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Alut.GetMajorVersion returns the major version number of the ALUT in use, which will match the major version number of the corresponding ALUT specification document. Can be compared using AlutVersions.</summary>
|
|
||||||
/// <returns>Major Version Number.</returns>
|
|
||||||
[DllImport(Alut.Lib, EntryPoint = "alutGetMajorVersion", ExactSpelling = true, CallingConvention = Alut.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern int GetMajorVersion();
|
|
||||||
// ALUT_API ALint ALUT_APIENTRY alutGetMajorVersion (void);
|
|
||||||
|
|
||||||
/// <summary>Alut.GetMinorVersion returns the minor version number of the ALUT in use, which will match the minor version number of the corresponding ALUT specification document. Can be compared using AlutVersions.</summary>
|
|
||||||
/// <returns>Minor Version Number.</returns>
|
|
||||||
[DllImport(Alut.Lib, EntryPoint = "alutGetMinorVersion", ExactSpelling = true, CallingConvention = Alut.Style), SuppressUnmanagedCodeSecurity()]
|
|
||||||
public static extern int GetMinorVersion();
|
|
||||||
// ALUT_API ALint ALUT_APIENTRY alutGetMinorVersion (void);
|
|
||||||
|
|
||||||
/*
|
|
||||||
/// <summary>Alut.Sleep will delay the execution of the current thread for at least the given amount of seconds. It will only return earlier if a signal has been delivered to the thread, but this does not count as an error. Note that sleeping for zero seconds will give other runnable threads a chance to run.
|
|
||||||
/// Having a general utility function like the following in an audio-related toolkit might seem strange at first, but sleeping is a common task in a lot of audio demos and it can't be done portably without cluttering the source code with #ifdefs.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="duration">Number of seconds. May not be negative.</param>
|
|
||||||
/// <returns>Success.</returns>
|
|
||||||
[DllImport( Alut.Lib, EntryPoint = "alutSleep", ExactSpelling = true, CallingConvention = Alut.Style ), SuppressUnmanagedCodeSecurity( )]
|
|
||||||
public static extern bool Sleep( float duration );
|
|
||||||
// ALUT_API ALboolean ALUT_APIENTRY alutSleep (ALfloat duration);
|
|
||||||
*/
|
|
||||||
#endregion Misc
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,98 +0,0 @@
|
||||||
#region --- OpenTK.OpenAL License ---
|
|
||||||
/* AlutTokens.cs
|
|
||||||
* C header: \freealut-1.1.0-src\include\AL\Alut.h
|
|
||||||
* Spec: http://www.openal.org/openal_webstf/specs/alut.html
|
|
||||||
* Copyright (c) 2008 Christoph Brandtner and Stefanos Apostolopoulos
|
|
||||||
* See license.txt for license details
|
|
||||||
* http://www.OpenTK.net */
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace OpenTK.Audio
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Defines the version of the Alut library.
|
|
||||||
/// </summary>
|
|
||||||
public enum AlutVersions : int
|
|
||||||
{
|
|
||||||
/// <summary>Defines the A in OpenAL A.B</summary>
|
|
||||||
ApiMajorVersion = 1,
|
|
||||||
/// <summary>Defines the B in OpenAL A.B</summary>
|
|
||||||
ApiMinorVersion = 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines available alut error codes.
|
|
||||||
/// </summary>
|
|
||||||
public enum AlutError : int
|
|
||||||
{
|
|
||||||
/// <summary>No ALUT error found.</summary>
|
|
||||||
NoError = 0,
|
|
||||||
/// <summary>ALUT ran out of memory.</summary>
|
|
||||||
OutOfMemory = 0x200,
|
|
||||||
/// <summary>ALUT was given an invalid enumeration token.</summary>
|
|
||||||
InvalidEnum = 0x201,
|
|
||||||
/// <summary>ALUT was given an invalid value.</summary>
|
|
||||||
InvalidValue = 0x202,
|
|
||||||
/// <summary>The operation is invalid in the current ALUT state.</summary>
|
|
||||||
InvalidOperation = 0x203,
|
|
||||||
/// <summary>There is no current AL context.</summary>
|
|
||||||
NoCurrentContext = 0x204,
|
|
||||||
/// <summary>There was already an AL error on entry to an ALUT function.</summary>
|
|
||||||
AlErrorOnEntry = 0x205,
|
|
||||||
/// <summary>There was already an ALC error on entry to an ALUT function.</summary>
|
|
||||||
AlcErrorOnEntry = 0x206,
|
|
||||||
/// <summary>There was an error opening the ALC device.</summary>
|
|
||||||
OpenDevice = 0x207,
|
|
||||||
/// <summary>There was an error closing the ALC device.</summary>
|
|
||||||
CloseDevice = 0x208,
|
|
||||||
/// <summary>There was an error creating an ALC context.</summary>
|
|
||||||
CreateContext = 0x209,
|
|
||||||
/// <summary>Could not change the current ALC context.</summary>
|
|
||||||
MakeContextCurrent = 0x20A,
|
|
||||||
/// <summary>There was an error destroying the ALC context.</summary>
|
|
||||||
DestroyContext = 0x20B,
|
|
||||||
/// <summary>There was an error generating an AL buffer.</summary>
|
|
||||||
GenBuffers = 0x20C,
|
|
||||||
/// <summary>There was an error passing buffer buffer to AL.</summary>
|
|
||||||
BufferData = 0x20D,
|
|
||||||
/// <summary>I/O error, consult errno for more details.</summary>
|
|
||||||
IoError = 0x20E,
|
|
||||||
/// <summary>Unsupported file type.</summary>
|
|
||||||
UnsupportedFileType = 0x20F,
|
|
||||||
/// <summary>Unsupported mode within an otherwise usable file type.</summary>
|
|
||||||
UnsupportedFileSubtype = 0x210,
|
|
||||||
/// <summary>The sound buffer was corrupt or truncated.</summary>
|
|
||||||
CorruptOrTruncatedData = 0x211,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines available alut waveform types.
|
|
||||||
/// </summary>
|
|
||||||
public enum AlutWaveform : int
|
|
||||||
{
|
|
||||||
/// <summary>A sine waveform</summary>
|
|
||||||
Sine = 0x100,
|
|
||||||
/// <summary>A square waveform</summary>
|
|
||||||
Square = 0x101,
|
|
||||||
/// <summary>A sawtooth waveform</summary>
|
|
||||||
SawTooth = 0x102,
|
|
||||||
/// <summary>A waveform containing white noise</summary>
|
|
||||||
WhiteNoise = 0x103,
|
|
||||||
/// <summary>A waveform containing an impusle</summary>
|
|
||||||
Impulse = 0x104,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines parameters for alut loaders.
|
|
||||||
/// </summary>
|
|
||||||
public enum AlutLoader : int
|
|
||||||
{
|
|
||||||
///<summary>For the loaders returning sound buffer in an OpenAL buffer, e.g. Alut.CreateBufferFromFile and Alut.CreateBufferFromFileImage</summary>
|
|
||||||
Buffer = 0x300,
|
|
||||||
///<summary>For the loaders returning sound buffer in a newly allocated memory region, e.g. Alut.LoadMemoryFromFile and Alut.LoadMemoryFromFileImage.</summary>
|
|
||||||
Memory = 0x301,
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,87 +0,0 @@
|
||||||
#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 details.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace OpenTK.Audio
|
|
||||||
{
|
|
||||||
#if false
|
|
||||||
/// <summary>Defines methods to load and hold sound buffer.</summary>
|
|
||||||
public class Sound<SampleType> : IDisposable
|
|
||||||
{
|
|
||||||
bool disposed;
|
|
||||||
SoundReader<SampleType> reader;
|
|
||||||
SoundData<SampleType> data;
|
|
||||||
|
|
||||||
public Sound(Stream s)
|
|
||||||
{
|
|
||||||
if (s == null) throw new ArgumentNullException("s", "Must be a valid System.IO.Stream.");
|
|
||||||
|
|
||||||
reader = SoundReader.Create(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Sound(string filename)
|
|
||||||
{
|
|
||||||
if (String.IsNullOrEmpty(filename)) throw new ArgumentNullException("s", "Must be a valid System.IO.Stream.");
|
|
||||||
|
|
||||||
reader = SoundReader.Create(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region --- Public Members ---
|
|
||||||
|
|
||||||
public SoundData ReadSamples(int count)
|
|
||||||
{
|
|
||||||
if (count <= 0) throw new ArgumentOutOfRangeException("count", "Must be larger than zero.");
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SoundData ReadToEnd()
|
|
||||||
{
|
|
||||||
return reader.ReadToEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SoundData SoundData { get { return data; } }
|
|
||||||
|
|
||||||
public void WriteToBuffer(int buffer, int length)
|
|
||||||
{
|
|
||||||
if (buffer == 0) throw new ArgumentOutOfRangeException("buffer", "May not be zero.");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- IDisposable Members ---
|
|
||||||
|
|
||||||
/// <summary>Disposes of the sound buffer.</summary>
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
this.Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Dispose(bool manual)
|
|
||||||
{
|
|
||||||
if (!disposed)
|
|
||||||
{
|
|
||||||
if (manual)
|
|
||||||
reader.Dispose();
|
|
||||||
disposed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~Sound()
|
|
||||||
{
|
|
||||||
this.Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
#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>Encapsulates a pointer to a decoded sound buffer.</summary>
|
|
||||||
public class SoundData
|
|
||||||
{
|
|
||||||
byte[] buffer;
|
|
||||||
SoundFormat format;
|
|
||||||
|
|
||||||
#region --- Constructors ---
|
|
||||||
|
|
||||||
/// <internal />
|
|
||||||
/// <summary>Constructs a new SoundData object.</summary>
|
|
||||||
/// <param name="format">The SoundFormat of these SoundData.</param>
|
|
||||||
/// <param name="data">An array of PCM buffer.</param>
|
|
||||||
internal SoundData(SoundFormat format, byte[] data)
|
|
||||||
{
|
|
||||||
if (data == null) throw new ArgumentNullException("buffer", "Must be a valid array of samples.");
|
|
||||||
if (data.Length == 0) throw new ArgumentOutOfRangeException("buffer", "Data length must be higher than 0.");
|
|
||||||
|
|
||||||
this.SoundFormat = format;
|
|
||||||
|
|
||||||
buffer = new byte[data.Length];
|
|
||||||
Array.Copy(data, buffer, data.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/// <summary>Gets the raw PCM buffer.</summary>
|
|
||||||
public byte[] Data { get { return buffer; } internal set { buffer = value; } }
|
|
||||||
|
|
||||||
/// <summary>Gets the SoundFormat of the SoundData.</summary>
|
|
||||||
public SoundFormat SoundFormat { get { return format; } internal set { format = value; } }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,105 +0,0 @@
|
||||||
#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;
|
|
||||||
|
|
||||||
namespace OpenTK.Audio
|
|
||||||
{
|
|
||||||
/// <summary>Describes the format of the SoundData.</summary>
|
|
||||||
public struct SoundFormat
|
|
||||||
{
|
|
||||||
#region --- Constructors ---
|
|
||||||
|
|
||||||
/// <summary>Constructs a new SoundFormat.</summary>
|
|
||||||
public SoundFormat(int channels, int bitsPerSample, int sampleRate)
|
|
||||||
{
|
|
||||||
if (sampleRate <= 0) throw new ArgumentOutOfRangeException("sampleRate", "Must be higher than 0.");
|
|
||||||
|
|
||||||
SampleFormat = 0;
|
|
||||||
|
|
||||||
switch (channels)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
if (bitsPerSample == 8) SampleFormat = SampleFormat.Mono8;
|
|
||||||
else if (bitsPerSample == 16) SampleFormat = SampleFormat.Mono16;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
if (bitsPerSample == 8) SampleFormat = SampleFormat.Stereo8;
|
|
||||||
else if (bitsPerSample == 16) SampleFormat = SampleFormat.Stereo16;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
SampleRate = sampleRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- Public Members ---
|
|
||||||
|
|
||||||
/// <summary>Describes the SampleFormat of the SoundData.</summary>
|
|
||||||
public readonly SampleFormat SampleFormat;
|
|
||||||
|
|
||||||
/// <summary>Describes the sample rate (frequency) of the SoundData.</summary>
|
|
||||||
public readonly int SampleRate;
|
|
||||||
|
|
||||||
/// <summary>Gets the SampleFormat of the buffer as an OpenTK.Audio.ALFormat enumeration.</summary>
|
|
||||||
public OpenTK.Audio.ALFormat SampleFormatAsOpenALFormat
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
switch (SampleFormat)
|
|
||||||
{
|
|
||||||
case SampleFormat.Mono8: return OpenTK.Audio.ALFormat.Mono8;
|
|
||||||
case SampleFormat.Mono16: return OpenTK.Audio.ALFormat.Mono16;
|
|
||||||
case SampleFormat.Stereo8: return OpenTK.Audio.ALFormat.Stereo8;
|
|
||||||
case SampleFormat.Stereo16: return OpenTK.Audio.ALFormat.Stereo16;
|
|
||||||
default: throw new NotSupportedException("Unknown PCM SampleFormat.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
#region public enum SampleFormat
|
|
||||||
|
|
||||||
/// <summary>Defines the available formats for SoundData.</summary>
|
|
||||||
public enum SampleFormat
|
|
||||||
{
|
|
||||||
/// <summary>8 bits per sample, 1 channel.</summary>
|
|
||||||
Mono8 = OpenTK.Audio.ALFormat.Mono8,
|
|
||||||
/// <summary>16 bits per sample, 1 channel.</summary>
|
|
||||||
Mono16 = OpenTK.Audio.ALFormat.Mono16,
|
|
||||||
/// <summary>8 bits per sample, 2 channels.</summary>
|
|
||||||
Stereo8 = OpenTK.Audio.ALFormat.Stereo8,
|
|
||||||
/// <summary>16 bits per sample, 2 channels.</summary>
|
|
||||||
Stereo16 = OpenTK.Audio.ALFormat.Stereo16
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
|
@ -1,266 +0,0 @@
|
||||||
#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 details.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
using OpenTK.Audio;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace OpenTK.Audio
|
|
||||||
{
|
|
||||||
internal sealed class WaveReader : AudioReader
|
|
||||||
{
|
|
||||||
SoundData decoded_data;
|
|
||||||
|
|
||||||
//RIFF header
|
|
||||||
string signature;
|
|
||||||
int riff_chunck_size;
|
|
||||||
string format;
|
|
||||||
|
|
||||||
//WAVE header
|
|
||||||
string format_signature;
|
|
||||||
int format_chunk_size;
|
|
||||||
short audio_format;
|
|
||||||
short channels;
|
|
||||||
int sample_rate;
|
|
||||||
int byte_rate;
|
|
||||||
short block_align;
|
|
||||||
short bits_per_sample;
|
|
||||||
|
|
||||||
//DATA header
|
|
||||||
string data_signature;
|
|
||||||
int data_chunk_size;
|
|
||||||
|
|
||||||
BinaryReader reader;
|
|
||||||
|
|
||||||
internal WaveReader() { }
|
|
||||||
|
|
||||||
internal WaveReader(Stream s)
|
|
||||||
{
|
|
||||||
if (s == null) throw new ArgumentNullException();
|
|
||||||
if (!s.CanRead) throw new ArgumentException("Cannot read from specified Stream.");
|
|
||||||
|
|
||||||
reader = new BinaryReader(s);
|
|
||||||
this.Stream = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if false
|
|
||||||
/// <summary>
|
|
||||||
/// Writes the WaveSound's data to the specified OpenAL buffer in the correct format.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="bid">
|
|
||||||
/// A <see cref="System.UInt32"/>
|
|
||||||
/// </param>
|
|
||||||
public void WriteToBuffer(uint bid)
|
|
||||||
{
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
//fix the array as a byte
|
|
||||||
fixed (byte* p_Data = _Data)
|
|
||||||
{
|
|
||||||
if (Channels == 1)
|
|
||||||
{
|
|
||||||
if (BitsPerSample == 16)
|
|
||||||
{
|
|
||||||
Console.Write("Uploading 16-bit mono data to OpenAL...");
|
|
||||||
AL.BufferData(bid, ALFormat.Mono16, (IntPtr)p_Data, _Data.Length, SampleRate);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (BitsPerSample == 8)
|
|
||||||
{
|
|
||||||
Console.Write("Uploading 8-bit mono data to OpenAL...");
|
|
||||||
AL.BufferData(bid, ALFormat.Mono8, (IntPtr)p_Data, _Data.Length, SampleRate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Channels == 2)
|
|
||||||
{
|
|
||||||
if (BitsPerSample == 16)
|
|
||||||
{
|
|
||||||
Console.Write("Uploading 16-bit stereo data to OpenAL...");
|
|
||||||
AL.BufferData(bid, ALFormat.Stereo16, (IntPtr)p_Data, _Data.Length, SampleRate);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (BitsPerSample == 8)
|
|
||||||
{
|
|
||||||
Console.Write("Uploading 8-bit stereo data to OpenAL...");
|
|
||||||
AL.BufferData(bid, ALFormat.Stereo8, (IntPtr)p_Data, _Data.Length, SampleRate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Writes all relevent information about the WaveSound to the console window.
|
|
||||||
/// </summary>
|
|
||||||
public void DumpParamsToConsole()
|
|
||||||
{
|
|
||||||
Console.WriteLine("AudioFormat:" + AudioFormat);
|
|
||||||
Console.WriteLine("Channels:" + Channels);
|
|
||||||
Console.WriteLine("SampleRate:" + SampleRate);
|
|
||||||
Console.WriteLine("ByteRate:" + ByteRate);
|
|
||||||
Console.WriteLine("BlockAlign:" + BlockAlign);
|
|
||||||
Console.WriteLine("BitsPerSample:" + BitsPerSample);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <value>
|
|
||||||
/// Returns the WaveSound's raw sound data as an array of bytes.
|
|
||||||
/// </value>
|
|
||||||
public byte[] Data
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _Data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#region --- Public Members ---
|
|
||||||
|
|
||||||
#region public override bool Supports(Stream s)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks whether the specified stream contains valid WAVE/RIFF buffer.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="s">The System.IO.Stream to check.</param>
|
|
||||||
/// <returns>True if the stream is a valid WAVE/RIFF file; false otherwise.</returns>
|
|
||||||
public override bool Supports(Stream s)
|
|
||||||
{
|
|
||||||
BinaryReader reader = new BinaryReader(s);
|
|
||||||
return this.ReadHeaders(reader);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override SoundData ReadSamples(int samples)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reads and decodes the specified number of samples from the sound stream.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="samples">The number of samples to read and decode.</param>
|
|
||||||
/// <returns>An OpenTK.Audio.SoundData object that contains the decoded buffer.</returns>
|
|
||||||
public override SoundData ReadSamples(long samples)
|
|
||||||
{
|
|
||||||
if (samples > reader.BaseStream.Length - reader.BaseStream.Position)
|
|
||||||
samples = reader.BaseStream.Length - reader.BaseStream.Position;
|
|
||||||
|
|
||||||
//while (samples > decoded_data.Data.Length * (bits_per_sample / 8))
|
|
||||||
// Array.Resize<byte>(ref decoded_data.Data, decoded_data.Data.Length * 2);
|
|
||||||
|
|
||||||
decoded_data = new SoundData(new SoundFormat(channels, bits_per_sample, sample_rate),
|
|
||||||
reader.ReadBytes((int)samples));
|
|
||||||
|
|
||||||
return decoded_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override SoundData ReadToEnd()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reads and decodes the sound stream.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>An OpenTK.Audio.SoundData object that contains the decoded buffer.</returns>
|
|
||||||
public override SoundData ReadToEnd()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//read the buffer into a byte array, even if the format is 16 bit
|
|
||||||
//decoded_data = new byte[data_chunk_size];
|
|
||||||
|
|
||||||
decoded_data = new SoundData(new SoundFormat(channels, bits_per_sample, sample_rate),
|
|
||||||
reader.ReadBytes((int)reader.BaseStream.Length));
|
|
||||||
|
|
||||||
Debug.WriteLine("decoded!");
|
|
||||||
|
|
||||||
//return new SoundData(decoded_data, new SoundFormat(channels, bits_per_sample, sample_rate));
|
|
||||||
return decoded_data;
|
|
||||||
}
|
|
||||||
catch (AudioReaderException)
|
|
||||||
{
|
|
||||||
reader.Close();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- Protected Members ---
|
|
||||||
|
|
||||||
protected override Stream Stream
|
|
||||||
{
|
|
||||||
get { return base.Stream; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
base.Stream = value;
|
|
||||||
if (!ReadHeaders(reader))
|
|
||||||
throw new AudioReaderException("Invalid WAVE/RIFF file: invalid or corrupt signature.");
|
|
||||||
|
|
||||||
Debug.Write(String.Format("Opened WAVE/RIFF file: ({0}, {1}, {2}, {3}) ", sample_rate.ToString(), bits_per_sample.ToString(),
|
|
||||||
channels.ToString(), audio_format.ToString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- Private Members ---
|
|
||||||
|
|
||||||
// Tries to read the WAVE/RIFF headers, and returns true if they are valid.
|
|
||||||
bool ReadHeaders(BinaryReader reader)
|
|
||||||
{
|
|
||||||
// Don't explicitly call reader.Close()/.Dispose(), as that will close the inner stream.
|
|
||||||
// There's no such danger if the BinaryReader isn't explicitly destroyed.
|
|
||||||
|
|
||||||
// RIFF header
|
|
||||||
signature = new string(reader.ReadChars(4));
|
|
||||||
if (signature != "RIFF")
|
|
||||||
return false;
|
|
||||||
|
|
||||||
riff_chunck_size = reader.ReadInt32();
|
|
||||||
|
|
||||||
format = new string(reader.ReadChars(4));
|
|
||||||
if (format != "WAVE")
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// WAVE header
|
|
||||||
format_signature = new string(reader.ReadChars(4));
|
|
||||||
if (format_signature != "fmt ")
|
|
||||||
return false;
|
|
||||||
|
|
||||||
format_chunk_size = reader.ReadInt32();
|
|
||||||
audio_format = reader.ReadInt16();
|
|
||||||
channels = reader.ReadInt16();
|
|
||||||
sample_rate = reader.ReadInt32();
|
|
||||||
byte_rate = reader.ReadInt32();
|
|
||||||
block_align = reader.ReadInt16();
|
|
||||||
bits_per_sample = reader.ReadInt16();
|
|
||||||
|
|
||||||
data_signature = new string(reader.ReadChars(4));
|
|
||||||
if (data_signature != "data")
|
|
||||||
return false;
|
|
||||||
|
|
||||||
data_chunk_size = reader.ReadInt32();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
#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 OpenTK.Graphics.OpenGL;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
[Obsolete()]
|
|
||||||
class DisplayListTextHandle : TextHandle
|
|
||||||
{
|
|
||||||
public DisplayListTextHandle(int handle) : base(handle) { }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return String.Format("TextHandle (display list): {0}", Handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Dispose(bool manual)
|
|
||||||
{
|
|
||||||
if (!disposed)
|
|
||||||
{
|
|
||||||
if (manual)
|
|
||||||
{
|
|
||||||
GL.DeleteLists(Handle, 1);
|
|
||||||
}
|
|
||||||
disposed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
#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 OpenTK.Graphics.OpenGL;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Provides text printing through OpenGL 1.1 Display Lists.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete()]
|
|
||||||
class DisplayListTextPrinter : ITextPrinterImplementation
|
|
||||||
{
|
|
||||||
#region IPrinter Members
|
|
||||||
|
|
||||||
public TextHandle Load(Vector2[] vertices, ushort[] indices, int index_count)
|
|
||||||
{
|
|
||||||
DisplayListTextHandle handle = new DisplayListTextHandle(GL.GenLists(1));
|
|
||||||
|
|
||||||
GL.NewList(handle.Handle, ListMode.Compile);
|
|
||||||
|
|
||||||
this.Draw(vertices, indices, index_count);
|
|
||||||
|
|
||||||
GL.EndList();
|
|
||||||
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Draw(TextHandle handle)
|
|
||||||
{
|
|
||||||
GL.CallList(handle.Handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Draw(Vector2[] vertices, ushort[] indices, int index_count)
|
|
||||||
{
|
|
||||||
GL.Begin(BeginMode.Triangles);
|
|
||||||
|
|
||||||
for (int i = 0; i < index_count; i++)
|
|
||||||
//foreach (ushort index in indices)
|
|
||||||
{
|
|
||||||
GL.TexCoord2(vertices[indices[i] + 1]);
|
|
||||||
GL.Vertex2(vertices[indices[i]]);
|
|
||||||
}
|
|
||||||
|
|
||||||
GL.End();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,176 +0,0 @@
|
||||||
#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.Drawing;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
using Graphics = System.Drawing.Graphics;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a single character of a specific Font.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete]
|
|
||||||
struct Glyph : IPackable<Glyph>
|
|
||||||
{
|
|
||||||
char character;
|
|
||||||
Font font;
|
|
||||||
SizeF size;
|
|
||||||
|
|
||||||
#region --- Constructors ---
|
|
||||||
|
|
||||||
// Constructs a new Glyph that represents the given character and Font.
|
|
||||||
public Glyph(char c, Font f, SizeF s)
|
|
||||||
{
|
|
||||||
if (f == null)
|
|
||||||
throw new ArgumentNullException("f", "You must specify a valid font");
|
|
||||||
character = c;
|
|
||||||
font = f;
|
|
||||||
size = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- Public Methods ---
|
|
||||||
|
|
||||||
#region public char Character
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the character represented by this Glyph.
|
|
||||||
/// </summary>
|
|
||||||
public char Character
|
|
||||||
{
|
|
||||||
get { return character; }
|
|
||||||
private set { character = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public Font Font
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the Font of this Glyph.
|
|
||||||
/// </summary>
|
|
||||||
public Font Font
|
|
||||||
{
|
|
||||||
get { return font; }
|
|
||||||
private set
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
throw new ArgumentNullException("Font", "Glyph font cannot be null");
|
|
||||||
|
|
||||||
font = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override bool Equals(object obj)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks whether the given object is equal (memberwise) to the current Glyph.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="obj">The obj to check.</param>
|
|
||||||
/// <returns>True, if the object is identical to the current Glyph.</returns>
|
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
|
||||||
if (obj is Glyph)
|
|
||||||
return this.Equals((Glyph)obj);
|
|
||||||
return base.Equals(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override string ToString()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Describes this Glyph object.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Returns a System.String describing this Glyph.</returns>
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return String.Format("'{0}', {1} {2}, {3} {4}, ({5}, {6})", Character, Font.Name, font.Style, font.Size, font.Unit, Width, Height);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override int GetHashCode()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculates the hashcode for this Glyph.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>A System.Int32 containing a hashcode that uniquely identifies this Glyph.</returns>
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return character.GetHashCode() ^ font.GetHashCode() ^ size.GetHashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public SizeF Size
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the size of this Glyph.
|
|
||||||
/// </summary>
|
|
||||||
public SizeF Size { get { return size; } }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public RectangleF Rectangle
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the bounding box of this Glyph.
|
|
||||||
/// </summary>
|
|
||||||
public RectangleF Rectangle { get { return new RectangleF(PointF.Empty, Size); } }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- IPackable<T> Members ---
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets an integer representing the width of the Glyph in pixels.
|
|
||||||
/// </summary>
|
|
||||||
public int Width
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return (int)System.Math.Ceiling(size.Width);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets an integer representing the height of the Glyph in pixels.
|
|
||||||
/// </summary>
|
|
||||||
public int Height
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return (int)System.Math.Ceiling(size.Height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- IEquatable<Glyph> Members ---
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Compares the current Glyph with the given Glyph.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="other">The Glyph to compare to.</param>
|
|
||||||
/// <returns>True if both Glyphs represent the same character of the same Font, false otherwise.</returns>
|
|
||||||
public bool Equals(Glyph other)
|
|
||||||
{
|
|
||||||
return Character == other.Character && Font == other.Font && Size == other.Size;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
#region --- License ---
|
|
||||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
||||||
* See license.txt for license info
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
[Obsolete]
|
|
||||||
public interface IFont : IDisposable
|
|
||||||
{
|
|
||||||
void LoadGlyphs(string glyphs);
|
|
||||||
float Height { get; }
|
|
||||||
void MeasureString(string str, out float width, out float height);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
#region --- License ---
|
|
||||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
||||||
* See license.txt for license info
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Defines the interface for TextPrinter implementations.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("Use ITextOutputProvider instead")]
|
|
||||||
[CLSCompliant(false)]
|
|
||||||
public interface ITextPrinterImplementation
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Caches a text fragment for future use.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vertices">The vertex array for the text fragment.</param>
|
|
||||||
/// <param name="indices">The index array for the text fragment. Please use the indexCount parameter
|
|
||||||
/// instead of indices.Count, as the indices array may be larger than necessary for performance reasons.</param>
|
|
||||||
/// <param name="indexCount">The actual number of indices in the text fragment.</param>
|
|
||||||
/// <returns>A TextHandle that can be used to draw the text fragment.</returns>
|
|
||||||
TextHandle Load(Vector2[] vertices, ushort[] indices, int indexCount);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Draws the specified cached text fragment.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="handle">The TextHandle corresponding to the desired text fragment.</param>
|
|
||||||
void Draw(TextHandle handle);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Draws a text fragment, without caching.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vertices">The vertex array for the text fragment.</param>
|
|
||||||
/// <param name="indices">The index array for the text fragment. Please use the indexCount parameter
|
|
||||||
/// instead of indices.Count, as the indices array may be larger than necessary for performance reasons.</param>
|
|
||||||
/// <param name="indexCount">The actual number of indices in the text fragment.</param>
|
|
||||||
void Draw(Vector2[] vertices, ushort[] indices, int indexCount);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,89 +0,0 @@
|
||||||
#region --- License ---
|
|
||||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
||||||
* See license.txt for license info
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a handle to cached text.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("Use TextPrinter.Print instead")]
|
|
||||||
public class TextHandle : IDisposable
|
|
||||||
{
|
|
||||||
internal string Text;
|
|
||||||
internal System.Drawing.Font GdiPFont;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new TextHandle,
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="handle"></param>
|
|
||||||
internal TextHandle(int handle)
|
|
||||||
{
|
|
||||||
Handle = handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal TextHandle(string text, System.Drawing.Font font)
|
|
||||||
{
|
|
||||||
Text = text;
|
|
||||||
GdiPFont = font;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int handle;
|
|
||||||
[CLSCompliant(false)]
|
|
||||||
protected TextureFont font;
|
|
||||||
protected bool disposed;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the handle of the cached text run. Call the OpenTK.Graphics.ITextPrinter.Draw() method
|
|
||||||
/// to draw the text represented by this TextHandle.
|
|
||||||
/// </summary>
|
|
||||||
public int Handle
|
|
||||||
{
|
|
||||||
get { return handle; }
|
|
||||||
protected set { handle = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the TextureFont used for this text run.
|
|
||||||
/// </summary>
|
|
||||||
public TextureFont Font
|
|
||||||
{
|
|
||||||
get { return font; }
|
|
||||||
internal set { font = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#region public override string ToString()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a System.String that represents the current TextHandle.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>a System.String that descibes the current TextHandle.</returns>
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return String.Format("TextHandle: {0}", Handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- IDisposable Members ---
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Frees the resource consumed by the TextHandle.
|
|
||||||
/// </summary>
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
this.Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
protected virtual void Dispose(bool manual) { }
|
|
||||||
~TextHandle() { this.Dispose(false); }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,563 +0,0 @@
|
||||||
#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.Drawing.Text;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Drawing.Imaging;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
using OpenTK.Graphics.OpenGL;
|
|
||||||
using OpenTK.Platform;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
using Graphics = System.Drawing.Graphics;
|
|
||||||
using PixelFormat = OpenTK.Graphics.OpenGL.PixelFormat;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
[Obsolete("Use System.Drawing.Font instead")]
|
|
||||||
public class TextureFont : IFont
|
|
||||||
{
|
|
||||||
internal Font font;
|
|
||||||
Dictionary<char, RectangleF> loaded_glyphs = new Dictionary<char, RectangleF>(64);
|
|
||||||
|
|
||||||
Bitmap bmp;
|
|
||||||
Graphics gfx;
|
|
||||||
// TODO: We need to be able to use multiple font sheets.
|
|
||||||
static int texture;
|
|
||||||
static TexturePacker<Glyph> pack;
|
|
||||||
static int texture_width, texture_height;
|
|
||||||
static readonly StringFormat default_string_format = StringFormat.GenericTypographic; // Check the constructor, too, for additional flags.
|
|
||||||
static readonly StringFormat load_glyph_string_format = StringFormat.GenericDefault;
|
|
||||||
static SizeF maximum_graphics_size;
|
|
||||||
|
|
||||||
int[] data = new int[256]; // Used to upload the glyph buffer to the OpenGL texture.
|
|
||||||
|
|
||||||
object upload_lock = new object();
|
|
||||||
|
|
||||||
static readonly char[] newline_characters = new char[] { '\n', '\r' };
|
|
||||||
|
|
||||||
#region --- Constructor ---
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new TextureFont, using the specified System.Drawing.Font.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="font">The System.Drawing.Font to use.</param>
|
|
||||||
public TextureFont(Font font)
|
|
||||||
{
|
|
||||||
if (font == null)
|
|
||||||
throw new ArgumentNullException("font", "Argument to TextureFont constructor cannot be null.");
|
|
||||||
|
|
||||||
this.font = font;
|
|
||||||
|
|
||||||
bmp = new Bitmap(font.Height * 2, font.Height * 2);
|
|
||||||
gfx = Graphics.FromImage(bmp);
|
|
||||||
maximum_graphics_size = gfx.ClipBounds.Size;
|
|
||||||
|
|
||||||
// Adjust font rendering mode. Small sizes look blurry without gridfitting, so turn
|
|
||||||
// that on. Increasing contrast also seems to help.
|
|
||||||
if (font.Size <= 18.0f)
|
|
||||||
{
|
|
||||||
gfx.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
|
||||||
//gfx.TextContrast = 11;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gfx.TextRenderingHint = TextRenderingHint.AntiAlias;
|
|
||||||
//gfx.TextContrast = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
default_string_format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new TextureFont, using the specified parameters.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="family">The System.Drawing.FontFamily to use for the typeface.</param>
|
|
||||||
/// <param name="emSize">The em size to use for the typeface.</param>
|
|
||||||
public TextureFont(FontFamily family, float emSize)
|
|
||||||
: this(new Font(family, emSize))
|
|
||||||
{ }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new TextureFont, using the specified parameters.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="family">The System.Drawing.FontFamily to use for the typeface.</param>
|
|
||||||
/// <param name="emSize">The em size to use for the typeface.</param>
|
|
||||||
/// <param name="style">The style to use for the typeface.</param>
|
|
||||||
public TextureFont(FontFamily family, float emSize, FontStyle style)
|
|
||||||
: this(new Font(family, emSize, style))
|
|
||||||
{ }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- Public Methods ---
|
|
||||||
|
|
||||||
#region public void LoadGlyphs(string glyphs)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prepares the specified glyphs for rendering.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="glyphs">The glyphs to prepare for rendering.</param>
|
|
||||||
public void LoadGlyphs(string glyphs)
|
|
||||||
{
|
|
||||||
RectangleF rect = new RectangleF();
|
|
||||||
foreach (char c in glyphs)
|
|
||||||
{
|
|
||||||
if (Char.IsWhiteSpace(c))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!loaded_glyphs.ContainsKey(c))
|
|
||||||
LoadGlyph(c, out rect);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Debug.Print(e.ToString());
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public void LoadGlyph(char glyph)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prepares the specified glyph for rendering.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="glyph">The glyph to prepare for rendering.</param>
|
|
||||||
public void LoadGlyph(char glyph)
|
|
||||||
{
|
|
||||||
RectangleF rect = new RectangleF();
|
|
||||||
if (!loaded_glyphs.ContainsKey(glyph))
|
|
||||||
LoadGlyph(glyph, out rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public bool GlyphData(char glyph, out float width, out float height, out RectangleF textureRectangle, out int texture)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the characteristics of a loaded glyph.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="glyph">The character corresponding to this glyph.</param>
|
|
||||||
/// <param name="width">The width of this glyph.</param>
|
|
||||||
/// <param name="height">The height of this glyph (line spacing).</param>
|
|
||||||
/// <param name="textureRectangle">The bounding box of the texture buffer of this glyph.</param>
|
|
||||||
/// <param name="texture">The handle to the texture that contains this glyph.</param>
|
|
||||||
/// <returns>True if the glyph has been loaded, false otherwise.</returns>
|
|
||||||
/// <seealso cref="LoadGlyphs"/>
|
|
||||||
public bool GlyphData(char glyph, out float width, out float height, out RectangleF textureRectangle, out int texture)
|
|
||||||
{
|
|
||||||
if (loaded_glyphs.TryGetValue(glyph, out textureRectangle))
|
|
||||||
{
|
|
||||||
width = textureRectangle.Width * texture_width;
|
|
||||||
height = textureRectangle.Height * texture_height;
|
|
||||||
texture = TextureFont.texture;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
width = height = texture = 0;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public float Height
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a float indicating the default line spacing of this font.
|
|
||||||
/// </summary>
|
|
||||||
public float Height
|
|
||||||
{
|
|
||||||
get { return font.Height; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public float Width
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a float indicating the default size of this font, in points.
|
|
||||||
/// </summary>
|
|
||||||
public float Width
|
|
||||||
{
|
|
||||||
get { return font.SizeInPoints; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public void MeasureString(string str, out float width, out float height, bool accountForOverhangs)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Measures the width of the specified string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">The string to measure.</param>
|
|
||||||
/// <param name="width">The measured width.</param>
|
|
||||||
/// <param name="height">The measured height.</param>
|
|
||||||
/// <param name="accountForOverhangs">If true, adds space to account for glyph overhangs. Set to true if you wish to measure a complete string. Set to false if you wish to perform layout on adjacent strings.</param>
|
|
||||||
[Obsolete("Returns invalid results - use MeasureText() instead")]
|
|
||||||
public void MeasureString(string str, out float width, out float height, bool accountForOverhangs)
|
|
||||||
{
|
|
||||||
System.Drawing.StringFormat format = accountForOverhangs ? System.Drawing.StringFormat.GenericDefault : System.Drawing.StringFormat.GenericTypographic;
|
|
||||||
|
|
||||||
System.Drawing.SizeF size = gfx.MeasureString(str, font, 16384, format);
|
|
||||||
height = size.Height;
|
|
||||||
width = size.Width;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public void MeasureString(string str, out float width, out float height)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Measures the width of the specified string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">The string to measure.</param>
|
|
||||||
/// <param name="width">The measured width.</param>
|
|
||||||
/// <param name="height">The measured height.</param>
|
|
||||||
/// <seealso cref="MeasureString(string, out float, out float, bool)"/>
|
|
||||||
[Obsolete("Returns invalid results - use MeasureText() instead")]
|
|
||||||
public void MeasureString(string str, out float width, out float height)
|
|
||||||
{
|
|
||||||
MeasureString(str, out width, out height, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public RectangleF MeasureText(string text)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculates size information for the specified text.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The string to measure.</param>
|
|
||||||
/// <returns>A RectangleF containing the bounding box for the specified text.</returns>
|
|
||||||
public RectangleF MeasureText(string text)
|
|
||||||
{
|
|
||||||
return MeasureText(text, SizeF.Empty, default_string_format, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public RectangleF MeasureText(string text, SizeF bounds)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculates size information for the specified text.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The string to measure.</param>
|
|
||||||
/// <param name="bounds">A SizeF structure containing the maximum desired width and height of the text. Default is SizeF.Empty.</param>
|
|
||||||
/// <returns>A RectangleF containing the bounding box for the specified text.</returns>
|
|
||||||
public RectangleF MeasureText(string text, SizeF bounds)
|
|
||||||
{
|
|
||||||
return MeasureText(text, bounds, default_string_format, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public RectangleF MeasureText(string text, SizeF bounds, StringFormat format)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculates size information for the specified text.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The string to measure.</param>
|
|
||||||
/// <param name="bounds">A SizeF structure containing the maximum desired width and height of the text. Pass SizeF.Empty to disable wrapping calculations. A width or height of 0 disables the relevant calculation.</param>
|
|
||||||
/// <param name="format">A StringFormat object which specifies the measurement format of the string. Pass null to use the default StringFormat (StringFormat.GenericTypographic).</param>
|
|
||||||
/// <returns>A RectangleF containing the bounding box for the specified text.</returns>
|
|
||||||
public RectangleF MeasureText(string text, SizeF bounds, StringFormat format)
|
|
||||||
{
|
|
||||||
return MeasureText(text, bounds, format, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public RectangleF MeasureText(string text, SizeF bounds, StringFormat format, IList<RectangleF> ranges)
|
|
||||||
|
|
||||||
IntPtr[] regions = new IntPtr[GdiPlus.MaxMeasurableCharacterRanges];
|
|
||||||
CharacterRange[] characterRanges = new CharacterRange[GdiPlus.MaxMeasurableCharacterRanges];
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculates size information for the specified text.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The string to measure.</param>
|
|
||||||
/// <param name="bounds">A SizeF structure containing the maximum desired width and height of the text. Pass SizeF.Empty to disable wrapping calculations. A width or height of 0 disables the relevant calculation.</param>
|
|
||||||
/// <param name="format">A StringFormat object which specifies the measurement format of the string. Pass null to use the default StringFormat (StringFormat.GenericDefault).</param>
|
|
||||||
/// <param name="ranges">Fills the specified IList of RectangleF structures with position information for individual characters. If this argument is null, these calculations are skipped.</param>
|
|
||||||
/// <returns>A RectangleF containing the bounding box for the specified text.</returns>
|
|
||||||
public RectangleF MeasureText(string text, SizeF bounds, StringFormat format, List<RectangleF> ranges)
|
|
||||||
{
|
|
||||||
if (String.IsNullOrEmpty(text))
|
|
||||||
return RectangleF.Empty;
|
|
||||||
|
|
||||||
if (bounds == SizeF.Empty)
|
|
||||||
bounds = maximum_graphics_size;
|
|
||||||
|
|
||||||
if (format == null)
|
|
||||||
format = default_string_format;
|
|
||||||
|
|
||||||
// TODO: What should we do in this case?
|
|
||||||
if (ranges == null)
|
|
||||||
ranges = new List<RectangleF>();
|
|
||||||
|
|
||||||
ranges.Clear();
|
|
||||||
|
|
||||||
PointF origin = PointF.Empty;
|
|
||||||
SizeF size = SizeF.Empty;
|
|
||||||
|
|
||||||
IntPtr native_graphics = GdiPlus.GetNativeGraphics(gfx);
|
|
||||||
IntPtr native_font = GdiPlus.GetNativeFont(font);
|
|
||||||
IntPtr native_string_format = GdiPlus.GetNativeStringFormat(format);
|
|
||||||
|
|
||||||
RectangleF layoutRect = new RectangleF(PointF.Empty, bounds);
|
|
||||||
|
|
||||||
int height = 0;
|
|
||||||
|
|
||||||
// It seems that the mere presence of \n and \r characters
|
|
||||||
// is enough for Mono to botch the layout (even if these
|
|
||||||
// characters are not processed.) We'll need to find a
|
|
||||||
// different way to perform layout on Mono, probably
|
|
||||||
// through Pango.
|
|
||||||
// Todo: This workaround allocates memory.
|
|
||||||
//if (Configuration.RunningOnMono)
|
|
||||||
{
|
|
||||||
string[] lines = text.Replace("\r", String.Empty).Split(newline_characters);
|
|
||||||
foreach (string s in lines)
|
|
||||||
{
|
|
||||||
ranges.AddRange(GetCharExtents(
|
|
||||||
s, height, 0, s.Length, layoutRect,
|
|
||||||
native_graphics, native_font, native_string_format));
|
|
||||||
height += font.Height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new RectangleF(ranges[0].X, ranges[0].Y, ranges[ranges.Count - 1].Right, ranges[ranges.Count - 1].Bottom);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- Private Methods ---
|
|
||||||
|
|
||||||
#region private void PrepareTexturePacker()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculates the optimal size for the font texture and TexturePacker, and creates both.
|
|
||||||
/// </summary>
|
|
||||||
private void PrepareTexturePacker()
|
|
||||||
{
|
|
||||||
// Calculate the size of the texture packer. We want a power-of-two size
|
|
||||||
// that is less than 1024 (supported in Geforce256-era cards), but large
|
|
||||||
// enough to hold at least 256 (16*16) font glyphs.
|
|
||||||
// TODO: Find the actual card limits, maybe?
|
|
||||||
int size = (int)(font.Size * 16);
|
|
||||||
size = (int)System.Math.Pow(2.0, System.Math.Ceiling(System.Math.Log((double)size, 2.0)));
|
|
||||||
if (size > 1024)
|
|
||||||
size = 1024;
|
|
||||||
|
|
||||||
texture_width = size;
|
|
||||||
texture_height = size;
|
|
||||||
pack = new TexturePacker<Glyph>(texture_width, texture_height);
|
|
||||||
|
|
||||||
GL.GenTextures(1, out texture);
|
|
||||||
GL.BindTexture(TextureTarget.Texture2D, texture);
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear);
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);
|
|
||||||
if (GL.SupportsExtension("Version12"))
|
|
||||||
{
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.ClampToEdge);
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.ClampToEdge);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.Clamp);
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.Clamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Alpha, texture_width, texture_height, 0,
|
|
||||||
OpenTK.Graphics.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region private void LoadGlyph(char c, out RectangleF rectangle)
|
|
||||||
|
|
||||||
// Adds the specified caharacter to the texture packer.
|
|
||||||
private void LoadGlyph(char c, out RectangleF rectangle)
|
|
||||||
{
|
|
||||||
if (pack == null)
|
|
||||||
PrepareTexturePacker();
|
|
||||||
|
|
||||||
RectangleF glyph_rect = MeasureText(c.ToString(), SizeF.Empty, load_glyph_string_format);
|
|
||||||
SizeF glyph_size = new SizeF(glyph_rect.Right, glyph_rect.Bottom); // We need to do this, since the origin might not be (0, 0)
|
|
||||||
Glyph g = new Glyph(c, font, glyph_size);
|
|
||||||
Rectangle rect;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pack.Add(g, out rect);
|
|
||||||
}
|
|
||||||
catch (InvalidOperationException expt)
|
|
||||||
{
|
|
||||||
// TODO: The TexturePacker is full, create a new font sheet.
|
|
||||||
Trace.WriteLine(expt);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
GL.BindTexture(TextureTarget.Texture2D, texture);
|
|
||||||
|
|
||||||
gfx.Clear(System.Drawing.Color.Transparent);
|
|
||||||
gfx.DrawString(g.Character.ToString(), g.Font, System.Drawing.Brushes.White, 0.0f, 0.0f, default_string_format);
|
|
||||||
|
|
||||||
BitmapData bitmap_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly,
|
|
||||||
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
|
||||||
|
|
||||||
GL.PushClientAttrib(ClientAttribMask.ClientPixelStoreBit);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1.0f);
|
|
||||||
GL.PixelStore(PixelStoreParameter.UnpackRowLength, bmp.Width);
|
|
||||||
GL.TexSubImage2D(TextureTarget.Texture2D, 0, (int)rect.Left, (int)rect.Top,
|
|
||||||
rect.Width, rect.Height,
|
|
||||||
OpenTK.Graphics.PixelFormat.Rgba,
|
|
||||||
PixelType.UnsignedByte, bitmap_data.Scan0);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
GL.PopClientAttrib();
|
|
||||||
}
|
|
||||||
|
|
||||||
bmp.UnlockBits(bitmap_data);
|
|
||||||
|
|
||||||
rectangle = RectangleF.FromLTRB(
|
|
||||||
rect.Left / (float)texture_width,
|
|
||||||
rect.Top / (float)texture_height,
|
|
||||||
rect.Right / (float)texture_width,
|
|
||||||
rect.Bottom / (float)texture_height);
|
|
||||||
|
|
||||||
loaded_glyphs.Add(g.Character, rectangle);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region GetCharExtents
|
|
||||||
|
|
||||||
// Gets the bounds of each character in a line of text.
|
|
||||||
// The line is processed in blocks of 32 characters (GdiPlus.MaxMeasurableCharacterRanges).
|
|
||||||
IEnumerable<RectangleF> GetCharExtents(string text, int height, int line_start, int line_length,
|
|
||||||
RectangleF layoutRect, IntPtr native_graphics, IntPtr native_font, IntPtr native_string_format)
|
|
||||||
{
|
|
||||||
RectangleF rect = new RectangleF();
|
|
||||||
int line_end = line_start + line_length;
|
|
||||||
while (line_start < line_end)
|
|
||||||
{
|
|
||||||
//if (text[line_start] == '\n' || text[line_start] == '\r')
|
|
||||||
//{
|
|
||||||
// line_start++;
|
|
||||||
// continue;
|
|
||||||
//}
|
|
||||||
|
|
||||||
int num_characters = (line_end - line_start) > GdiPlus.MaxMeasurableCharacterRanges ?
|
|
||||||
GdiPlus.MaxMeasurableCharacterRanges :
|
|
||||||
line_end - line_start;
|
|
||||||
int status = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < num_characters; i++)
|
|
||||||
{
|
|
||||||
characterRanges[i] = new CharacterRange(line_start + i, 1);
|
|
||||||
|
|
||||||
IntPtr region;
|
|
||||||
status = GdiPlus.CreateRegion(out region);
|
|
||||||
regions[i] = region;
|
|
||||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
|
||||||
}
|
|
||||||
|
|
||||||
status = GdiPlus.SetStringFormatMeasurableCharacterRanges(native_string_format, num_characters, characterRanges);
|
|
||||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
|
||||||
|
|
||||||
status = GdiPlus.MeasureCharacterRanges(native_graphics, text, text.Length,
|
|
||||||
native_font, ref layoutRect, native_string_format, num_characters, regions);
|
|
||||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
|
||||||
|
|
||||||
for (int i = 0; i < num_characters; i++)
|
|
||||||
{
|
|
||||||
GdiPlus.GetRegionBounds(regions[i], native_graphics, ref rect);
|
|
||||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
|
||||||
GdiPlus.DeleteRegion(regions[i]);
|
|
||||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
|
||||||
|
|
||||||
rect.Y += height;
|
|
||||||
yield return rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
line_start += num_characters;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- Internal Methods ---
|
|
||||||
|
|
||||||
#region internal int Texture
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the handle to the texture were this font resides.
|
|
||||||
/// </summary>
|
|
||||||
internal int Texture
|
|
||||||
{
|
|
||||||
get { return TextureFont.texture; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- IDisposable Members ---
|
|
||||||
|
|
||||||
bool disposed;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Releases all resources used by this OpenTK.Graphics.TextureFont.
|
|
||||||
/// </summary>
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
Dispose(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Dispose(bool manual)
|
|
||||||
{
|
|
||||||
if (!disposed)
|
|
||||||
{
|
|
||||||
pack = null;
|
|
||||||
if (manual)
|
|
||||||
{
|
|
||||||
GL.DeleteTextures(1, ref texture);
|
|
||||||
font.Dispose();
|
|
||||||
gfx.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
disposed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Finalizes this TextureFont.
|
|
||||||
/// </summary>
|
|
||||||
~TextureFont()
|
|
||||||
{
|
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,104 +0,0 @@
|
||||||
#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;
|
|
||||||
|
|
||||||
using OpenTK.Graphics.OpenGL;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Provides text printing through OpenGL 1.5 vertex buffer objects.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete]
|
|
||||||
class VboTextPrinter : ITextPrinterImplementation
|
|
||||||
{
|
|
||||||
static int allocated_handles;
|
|
||||||
static int vector2_size = Marshal.SizeOf(new Vector2());
|
|
||||||
|
|
||||||
#region --- IPrinter Members ---
|
|
||||||
|
|
||||||
public TextHandle Load(Vector2[] vertices, ushort[] indices, int index_count)
|
|
||||||
{
|
|
||||||
VboTextHandle handle = new VboTextHandle(++allocated_handles);
|
|
||||||
|
|
||||||
GL.GenBuffers(1, out handle.vbo_id);
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, handle.vbo_id);
|
|
||||||
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * vector2_size), vertices,
|
|
||||||
BufferUsageHint.StaticDraw);
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
|
||||||
|
|
||||||
GL.GenBuffers(1, out handle.ebo_id);
|
|
||||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, handle.ebo_id);
|
|
||||||
GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(ushort)), indices,
|
|
||||||
BufferUsageHint.StaticDraw);
|
|
||||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
|
|
||||||
|
|
||||||
handle.element_count = indices.Length;
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Draw(TextHandle handle)
|
|
||||||
{
|
|
||||||
VboTextHandle vbo = (VboTextHandle)handle;
|
|
||||||
|
|
||||||
//GL.PushClientAttrib(ClientAttribMask.ClientVertexArrayBit);
|
|
||||||
|
|
||||||
//GL.EnableClientState(EnableCap.TextureCoordArray);
|
|
||||||
GL.EnableClientState(EnableCap.VertexArray);
|
|
||||||
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo.vbo_id);
|
|
||||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, vbo.ebo_id);
|
|
||||||
|
|
||||||
GL.TexCoordPointer(2, TexCoordPointerType.Float, vector2_size, (IntPtr)vector2_size);
|
|
||||||
GL.VertexPointer(2, VertexPointerType.Float, vector2_size, IntPtr.Zero);
|
|
||||||
|
|
||||||
GL.DrawElements(BeginMode.Triangles, vbo.element_count, DrawElementsType.UnsignedShort, IntPtr.Zero);
|
|
||||||
//GL.DrawArrays(BeginMode.LineLoop, 0, vbo.element_count);
|
|
||||||
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
|
||||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
|
|
||||||
|
|
||||||
GL.DisableClientState(EnableCap.VertexArray);
|
|
||||||
//GL.DisableClientState(EnableCap.TextureCoordArray);
|
|
||||||
|
|
||||||
//GL.PopClientAttrib();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Draw(Vector2[] vertices, ushort[] indices, int index_count)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
#region class VboTextHandle : TextHandle
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Contains the necessary information to print text through the VboTextPrinter implementation.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete]
|
|
||||||
class VboTextHandle : TextHandle
|
|
||||||
{
|
|
||||||
public VboTextHandle(int handle) : base(handle) { }
|
|
||||||
|
|
||||||
internal int vbo_id; // vertex buffer object id.
|
|
||||||
internal int ebo_id; // index buffer object id.
|
|
||||||
internal int element_count; // Number of elements in the ebo.
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return String.Format("TextHandle (vbo): {0} ({1} element(s), vbo id: {2}, ebo id: {3}",
|
|
||||||
Handle, element_count / 6, vbo_id, ebo_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
using System.Drawing.Imaging;
|
|
||||||
using OpenTK.Graphics.OpenGL;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Encapsulates an OpenGL texture.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete]
|
|
||||||
class AlphaTexture2D : Texture2D
|
|
||||||
{
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new Texture.
|
|
||||||
/// </summary>
|
|
||||||
public AlphaTexture2D(int width, int height)
|
|
||||||
: base(width, height)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Protected Members
|
|
||||||
|
|
||||||
protected override PixelInternalFormat InternalFormat
|
|
||||||
{
|
|
||||||
get { return PixelInternalFormat.Alpha; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,135 +0,0 @@
|
||||||
#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;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
// Used in debug-mode only, for automatic OpenGL error-checking.
|
|
||||||
//
|
|
||||||
// Works like this: an instance is created before each OpenGL function is called.
|
|
||||||
// The constructor resets the OpenGL error state. Once the native function returns,
|
|
||||||
// the error state is checked again, raising the relevant exceptions.
|
|
||||||
//
|
|
||||||
// A using-region is used to ensure Dispose() is called.
|
|
||||||
//
|
|
||||||
// Make sure that no error checking is added to the GetError function,
|
|
||||||
// as that would cause infinite recursion!
|
|
||||||
[Obsolete]
|
|
||||||
struct ErrorHelper : IDisposable
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
static readonly object SyncRoot = new object();
|
|
||||||
static readonly Dictionary<GraphicsContext, List<ErrorCode>> ContextErrors =
|
|
||||||
new Dictionary<GraphicsContext, List<ErrorCode>>();
|
|
||||||
readonly GraphicsContext Context;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
public ErrorHelper(IGraphicsContext context)
|
|
||||||
{
|
|
||||||
if (context == null)
|
|
||||||
throw new GraphicsContextMissingException();
|
|
||||||
|
|
||||||
Context = (GraphicsContext)context;
|
|
||||||
lock (SyncRoot)
|
|
||||||
{
|
|
||||||
if (!ContextErrors.ContainsKey(Context))
|
|
||||||
ContextErrors.Add(Context, new List<ErrorCode>());
|
|
||||||
}
|
|
||||||
ResetErrors();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Members
|
|
||||||
|
|
||||||
// Retrieve all OpenGL errors to clear the error list.
|
|
||||||
// See http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/geterror.html
|
|
||||||
[Conditional("DEBUG")]
|
|
||||||
internal void ResetErrors()
|
|
||||||
{
|
|
||||||
if (Context.ErrorChecking)
|
|
||||||
{
|
|
||||||
while (GL.GetError() != ErrorCode.NoError)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve all OpenGL errors and throw an exception if anything other than NoError is returned.
|
|
||||||
[Conditional("DEBUG")]
|
|
||||||
internal void CheckErrors()
|
|
||||||
{
|
|
||||||
if (Context.ErrorChecking)
|
|
||||||
{
|
|
||||||
List<ErrorCode> error_list = ContextErrors[Context];
|
|
||||||
error_list.Clear();
|
|
||||||
ErrorCode error;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
error = GL.GetError();
|
|
||||||
error_list.Add(error);
|
|
||||||
} while (error != ErrorCode.NoError);
|
|
||||||
|
|
||||||
if (error_list.Count != 1)
|
|
||||||
{
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
foreach (ErrorCode e in error_list)
|
|
||||||
{
|
|
||||||
if (e != ErrorCode.NoError)
|
|
||||||
{
|
|
||||||
sb.Append(e.ToString());
|
|
||||||
sb.Append(", ");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sb.Remove(sb.Length - 2, 2); // Remove the last comma
|
|
||||||
|
|
||||||
throw new GraphicsErrorException(sb.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
CheckErrors();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,190 +0,0 @@
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
#pragma warning disable 3019
|
|
||||||
#pragma warning disable 1591
|
|
||||||
|
|
||||||
partial class Glu
|
|
||||||
{
|
|
||||||
[Obsolete]
|
|
||||||
internal static partial class Imports
|
|
||||||
{
|
|
||||||
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluBeginCurve", ExactSpelling = true)]
|
|
||||||
internal extern static void BeginCurve(IntPtr nurb);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluBeginPolygon", ExactSpelling = true)]
|
|
||||||
internal extern static void BeginPolygon(IntPtr tess);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluBeginSurface", ExactSpelling = true)]
|
|
||||||
internal extern static void BeginSurface(IntPtr nurb);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluBeginTrim", ExactSpelling = true)]
|
|
||||||
internal extern static void BeginTrim(IntPtr nurb);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluBuild1DMipmapLevels", ExactSpelling = true)]
|
|
||||||
internal extern static Int32 Build1DMipmapLevels(TextureTarget target, Int32 internalFormat, Int32 width, PixelFormat format, PixelType type, Int32 level, Int32 @base, Int32 max, IntPtr data);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluBuild1DMipmaps", ExactSpelling = true)]
|
|
||||||
internal extern static Int32 Build1DMipmaps(TextureTarget target, Int32 internalFormat, Int32 width, PixelFormat format, PixelType type, IntPtr data);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluBuild2DMipmapLevels", ExactSpelling = true)]
|
|
||||||
internal extern static Int32 Build2DMipmapLevels(TextureTarget target, Int32 internalFormat, Int32 width, Int32 height, PixelFormat format, PixelType type, Int32 level, Int32 @base, Int32 max, IntPtr data);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluBuild2DMipmaps", ExactSpelling = true)]
|
|
||||||
internal extern static Int32 Build2DMipmaps(TextureTarget target, Int32 internalFormat, Int32 width, Int32 height, PixelFormat format, PixelType type, IntPtr data);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluBuild3DMipmapLevels", ExactSpelling = true)]
|
|
||||||
internal extern static Int32 Build3DMipmapLevels(TextureTarget target, Int32 internalFormat, Int32 width, Int32 height, Int32 depth, PixelFormat format, PixelType type, Int32 level, Int32 @base, Int32 max, IntPtr data);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluBuild3DMipmaps", ExactSpelling = true)]
|
|
||||||
internal extern static Int32 Build3DMipmaps(TextureTarget target, Int32 internalFormat, Int32 width, Int32 height, Int32 depth, PixelFormat format, PixelType type, IntPtr data);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluCheckExtension", ExactSpelling = true)]
|
|
||||||
internal extern static unsafe bool CheckExtension(Byte* extName, Byte* extString);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluCylinder", ExactSpelling = true)]
|
|
||||||
internal extern static void Cylinder(IntPtr quad, double @base, double top, double height, Int32 slices, Int32 stacks);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluDeleteNurbsRenderer", ExactSpelling = true)]
|
|
||||||
internal extern static void DeleteNurbsRenderer(IntPtr nurb);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluDeleteQuadric", ExactSpelling = true)]
|
|
||||||
internal extern static void DeleteQuadric(IntPtr quad);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluDeleteTess", ExactSpelling = true)]
|
|
||||||
internal extern static void DeleteTess(IntPtr tess);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluDisk", ExactSpelling = true)]
|
|
||||||
internal extern static void Disk(IntPtr quad, double inner, double outer, Int32 slices, Int32 loops);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluEndCurve", ExactSpelling = true)]
|
|
||||||
internal extern static void EndCurve(IntPtr nurb);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluEndPolygon", ExactSpelling = true)]
|
|
||||||
internal extern static void EndPolygon(IntPtr tess);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluEndSurface", ExactSpelling = true)]
|
|
||||||
internal extern static void EndSurface(IntPtr nurb);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluEndTrim", ExactSpelling = true)]
|
|
||||||
internal extern static void EndTrim(IntPtr nurb);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluErrorString", ExactSpelling = true)]
|
|
||||||
internal extern static IntPtr ErrorString(OpenTK.Graphics.GluErrorCode error);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluGetString", ExactSpelling = true)]
|
|
||||||
internal extern static IntPtr GetString(OpenTK.Graphics.GluStringName name);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluGetNurbsProperty", ExactSpelling = true)]
|
|
||||||
internal extern static unsafe void GetNurbsProperty(IntPtr nurb, OpenTK.Graphics.NurbsProperty property, [Out] float* data);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluGetTessProperty", ExactSpelling = true)]
|
|
||||||
internal extern static unsafe void GetTessProperty(IntPtr tess, OpenTK.Graphics.TessParameter which, [Out] double* data);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluLoadSamplingMatrices", ExactSpelling = true)]
|
|
||||||
internal extern static unsafe void LoadSamplingMatrices(IntPtr nurb, float* model, float* perspective, Int32* view);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluLookAt", ExactSpelling = true)]
|
|
||||||
internal extern static void LookAt(double eyeX, double eyeY, double eyeZ, double centerX, double centerY, double centerZ, double upX, double upY, double upZ);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluNewNurbsRenderer", ExactSpelling = true)]
|
|
||||||
internal extern static IntPtr NewNurbsRenderer();
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluNewQuadric", ExactSpelling = true)]
|
|
||||||
internal extern static IntPtr NewQuadric();
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluNewTess", ExactSpelling = true)]
|
|
||||||
internal extern static IntPtr NewTess();
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluNextContour", ExactSpelling = true)]
|
|
||||||
internal extern static void NextContour(IntPtr tess, OpenTK.Graphics.TessContour type);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluNurbsCallback", ExactSpelling = true)]
|
|
||||||
internal extern static void NurbsCallback(IntPtr nurb, OpenTK.Graphics.NurbsCallback which, Delegate CallBackFunc);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluNurbsCallbackData", ExactSpelling = true)]
|
|
||||||
internal extern static void NurbsCallbackData(IntPtr nurb, IntPtr userData);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluNurbsCurve", ExactSpelling = true)]
|
|
||||||
internal extern static unsafe void NurbsCurve(IntPtr nurb, Int32 knotCount, [Out] float* knots, Int32 stride, [Out] float* control, Int32 order, MapTarget type);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluNurbsProperty", ExactSpelling = true)]
|
|
||||||
internal extern static void NurbsProperty(IntPtr nurb, OpenTK.Graphics.NurbsProperty property, float value);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluNurbsSurface", ExactSpelling = true)]
|
|
||||||
internal extern static unsafe void NurbsSurface(IntPtr nurb, Int32 sKnotCount, float* sKnots, Int32 tKnotCount, float* tKnots, Int32 sStride, Int32 tStride, float* control, Int32 sOrder, Int32 tOrder, MapTarget type);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluOrtho2D", ExactSpelling = true)]
|
|
||||||
internal extern static void Ortho2D(double left, double right, double bottom, double top);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluPartialDisk", ExactSpelling = true)]
|
|
||||||
internal extern static void PartialDisk(IntPtr quad, double inner, double outer, Int32 slices, Int32 loops, double start, double sweep);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluPerspective", ExactSpelling = true)]
|
|
||||||
internal extern static void Perspective(double fovy, double aspect, double zNear, double zFar);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluPickMatrix", ExactSpelling = true)]
|
|
||||||
internal extern static unsafe void PickMatrix(double x, double y, double delX, double delY, [Out] Int32* viewport);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluProject", ExactSpelling = true)]
|
|
||||||
internal extern static unsafe Int32 Project(double objX, double objY, double objZ, double* model, double* proj, Int32* view, double* winX, double* winY, double* winZ);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluPwlCurve", ExactSpelling = true)]
|
|
||||||
internal extern static unsafe void PwlCurve(IntPtr nurb, Int32 count, float* data, Int32 stride, OpenTK.Graphics.NurbsTrim type);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluQuadricCallback", ExactSpelling = true)]
|
|
||||||
internal extern static void QuadricCallback(IntPtr quad, OpenTK.Graphics.QuadricCallback which, Delegate CallBackFunc);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluQuadricDrawStyle", ExactSpelling = true)]
|
|
||||||
internal extern static void QuadricDrawStyle(IntPtr quad, OpenTK.Graphics.QuadricDrawStyle draw);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluQuadricNormals", ExactSpelling = true)]
|
|
||||||
internal extern static void QuadricNormals(IntPtr quad, OpenTK.Graphics.QuadricNormal normal);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluQuadricOrientation", ExactSpelling = true)]
|
|
||||||
internal extern static void QuadricOrientation(IntPtr quad, OpenTK.Graphics.QuadricOrientation orientation);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluQuadricTexture", ExactSpelling = true)]
|
|
||||||
internal extern static void QuadricTexture(IntPtr quad, bool texture);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluScaleImage", ExactSpelling = true)]
|
|
||||||
internal extern static Int32 ScaleImage(PixelFormat format, Int32 wIn, Int32 hIn, PixelType typeIn, IntPtr dataIn, Int32 wOut, Int32 hOut, PixelType typeOut, [Out] IntPtr dataOut);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluSphere", ExactSpelling = true)]
|
|
||||||
internal extern static void Sphere(IntPtr quad, double radius, Int32 slices, Int32 stacks);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluTessBeginContour", ExactSpelling = true)]
|
|
||||||
internal extern static void TessBeginContour(IntPtr tess);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluTessBeginPolygon", ExactSpelling = true)]
|
|
||||||
internal extern static void TessBeginPolygon(IntPtr tess, IntPtr data);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluTessCallback", ExactSpelling = true)]
|
|
||||||
internal extern static void TessCallback(IntPtr tess, OpenTK.Graphics.TessCallback which, Delegate CallBackFunc);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluTessEndContour", ExactSpelling = true)]
|
|
||||||
internal extern static void TessEndContour(IntPtr tess);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluTessEndPolygon", ExactSpelling = true)]
|
|
||||||
internal extern static void TessEndPolygon(IntPtr tess);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluTessNormal", ExactSpelling = true)]
|
|
||||||
internal extern static void TessNormal(IntPtr tess, double valueX, double valueY, double valueZ);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluTessProperty", ExactSpelling = true)]
|
|
||||||
internal extern static void TessProperty(IntPtr tess, OpenTK.Graphics.TessParameter which, double data);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluTessVertex", ExactSpelling = true)]
|
|
||||||
internal extern static unsafe void TessVertex(IntPtr tess, double* location, IntPtr data);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluUnProject", ExactSpelling = true)]
|
|
||||||
internal extern static unsafe Int32 UnProject(double winX, double winY, double winZ, double* model, double* proj, Int32* view, double* objX, double* objY, double* objZ);
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
[System.Runtime.InteropServices.DllImport(Glu.Library, EntryPoint = "gluUnProject4", ExactSpelling = true)]
|
|
||||||
internal extern static unsafe Int32 UnProject4(double winX, double winY, double winZ, double clipW, double* model, double* proj, Int32* view, double near, double far, double* objX, double* objY, double* objZ, double* objW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,195 +0,0 @@
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
#pragma warning disable 0649
|
|
||||||
#pragma warning disable 3019
|
|
||||||
#pragma warning disable 1591
|
|
||||||
|
|
||||||
partial class Glu
|
|
||||||
{
|
|
||||||
internal static partial class Delegates
|
|
||||||
{
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void BeginCurve(IntPtr nurb);
|
|
||||||
internal static BeginCurve gluBeginCurve;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void BeginPolygon(IntPtr tess);
|
|
||||||
internal static BeginPolygon gluBeginPolygon;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void BeginSurface(IntPtr nurb);
|
|
||||||
internal static BeginSurface gluBeginSurface;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void BeginTrim(IntPtr nurb);
|
|
||||||
internal static BeginTrim gluBeginTrim;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate Int32 Build1DMipmapLevels(TextureTarget target, Int32 internalFormat, Int32 width, PixelFormat format, PixelType type, Int32 level, Int32 @base, Int32 max, IntPtr data);
|
|
||||||
internal static Build1DMipmapLevels gluBuild1DMipmapLevels;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate Int32 Build1DMipmaps(TextureTarget target, Int32 internalFormat, Int32 width, PixelFormat format, PixelType type, IntPtr data);
|
|
||||||
internal static Build1DMipmaps gluBuild1DMipmaps;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate Int32 Build2DMipmapLevels(TextureTarget target, Int32 internalFormat, Int32 width, Int32 height, PixelFormat format, PixelType type, Int32 level, Int32 @base, Int32 max, IntPtr data);
|
|
||||||
internal static Build2DMipmapLevels gluBuild2DMipmapLevels;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate Int32 Build2DMipmaps(TextureTarget target, Int32 internalFormat, Int32 width, Int32 height, PixelFormat format, PixelType type, IntPtr data);
|
|
||||||
internal static Build2DMipmaps gluBuild2DMipmaps;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate Int32 Build3DMipmapLevels(TextureTarget target, Int32 internalFormat, Int32 width, Int32 height, Int32 depth, PixelFormat format, PixelType type, Int32 level, Int32 @base, Int32 max, IntPtr data);
|
|
||||||
internal static Build3DMipmapLevels gluBuild3DMipmapLevels;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate Int32 Build3DMipmaps(TextureTarget target, Int32 internalFormat, Int32 width, Int32 height, Int32 depth, PixelFormat format, PixelType type, IntPtr data);
|
|
||||||
internal static Build3DMipmaps gluBuild3DMipmaps;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate bool CheckExtension(Byte* extName, Byte* extString);
|
|
||||||
internal unsafe static CheckExtension gluCheckExtension;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void Cylinder(IntPtr quad, double @base, double top, double height, Int32 slices, Int32 stacks);
|
|
||||||
internal static Cylinder gluCylinder;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void DeleteNurbsRenderer(IntPtr nurb);
|
|
||||||
internal static DeleteNurbsRenderer gluDeleteNurbsRenderer;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void DeleteQuadric(IntPtr quad);
|
|
||||||
internal static DeleteQuadric gluDeleteQuadric;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void DeleteTess(IntPtr tess);
|
|
||||||
internal static DeleteTess gluDeleteTess;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void Disk(IntPtr quad, double inner, double outer, Int32 slices, Int32 loops);
|
|
||||||
internal static Disk gluDisk;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void EndCurve(IntPtr nurb);
|
|
||||||
internal static EndCurve gluEndCurve;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void EndPolygon(IntPtr tess);
|
|
||||||
internal static EndPolygon gluEndPolygon;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void EndSurface(IntPtr nurb);
|
|
||||||
internal static EndSurface gluEndSurface;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void EndTrim(IntPtr nurb);
|
|
||||||
internal static EndTrim gluEndTrim;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate IntPtr ErrorString(OpenTK.Graphics.GluErrorCode error);
|
|
||||||
internal static ErrorString gluErrorString;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate IntPtr GetString(OpenTK.Graphics.GluStringName name);
|
|
||||||
internal static GetString gluGetString;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void GetNurbsProperty(IntPtr nurb, OpenTK.Graphics.NurbsProperty property, [Out] float* data);
|
|
||||||
internal unsafe static GetNurbsProperty gluGetNurbsProperty;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void GetTessProperty(IntPtr tess, OpenTK.Graphics.TessParameter which, [Out] double* data);
|
|
||||||
internal unsafe static GetTessProperty gluGetTessProperty;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void LoadSamplingMatrices(IntPtr nurb, float* model, float* perspective, Int32* view);
|
|
||||||
internal unsafe static LoadSamplingMatrices gluLoadSamplingMatrices;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void LookAt(double eyeX, double eyeY, double eyeZ, double centerX, double centerY, double centerZ, double upX, double upY, double upZ);
|
|
||||||
internal static LookAt gluLookAt;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate IntPtr NewNurbsRenderer();
|
|
||||||
internal static NewNurbsRenderer gluNewNurbsRenderer;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate IntPtr NewQuadric();
|
|
||||||
internal static NewQuadric gluNewQuadric;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate IntPtr NewTess();
|
|
||||||
internal static NewTess gluNewTess;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void NextContour(IntPtr tess, OpenTK.Graphics.TessContour type);
|
|
||||||
internal static NextContour gluNextContour;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void NurbsCallback(IntPtr nurb, OpenTK.Graphics.NurbsCallback which, Delegate CallBackFunc);
|
|
||||||
internal static NurbsCallback gluNurbsCallback;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void NurbsCallbackData(IntPtr nurb, IntPtr userData);
|
|
||||||
internal static NurbsCallbackData gluNurbsCallbackData;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void NurbsCallbackDataEXT(IntPtr nurb, IntPtr userData);
|
|
||||||
internal static NurbsCallbackDataEXT gluNurbsCallbackDataEXT;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void NurbsCurve(IntPtr nurb, Int32 knotCount, [Out] float* knots, Int32 stride, [Out] float* control, Int32 order, MapTarget type);
|
|
||||||
internal unsafe static NurbsCurve gluNurbsCurve;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void NurbsProperty(IntPtr nurb, OpenTK.Graphics.NurbsProperty property, float value);
|
|
||||||
internal static NurbsProperty gluNurbsProperty;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void NurbsSurface(IntPtr nurb, Int32 sKnotCount, float* sKnots, Int32 tKnotCount, float* tKnots, Int32 sStride, Int32 tStride, float* control, Int32 sOrder, Int32 tOrder, MapTarget type);
|
|
||||||
internal unsafe static NurbsSurface gluNurbsSurface;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void Ortho2D(double left, double right, double bottom, double top);
|
|
||||||
internal static Ortho2D gluOrtho2D;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void PartialDisk(IntPtr quad, double inner, double outer, Int32 slices, Int32 loops, double start, double sweep);
|
|
||||||
internal static PartialDisk gluPartialDisk;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void Perspective(double fovy, double aspect, double zNear, double zFar);
|
|
||||||
internal static Perspective gluPerspective;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void PickMatrix(double x, double y, double delX, double delY, [Out] Int32* viewport);
|
|
||||||
internal unsafe static PickMatrix gluPickMatrix;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate Int32 Project(double objX, double objY, double objZ, double* model, double* proj, Int32* view, double* winX, double* winY, double* winZ);
|
|
||||||
internal unsafe static Project gluProject;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void PwlCurve(IntPtr nurb, Int32 count, float* data, Int32 stride, OpenTK.Graphics.NurbsTrim type);
|
|
||||||
internal unsafe static PwlCurve gluPwlCurve;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void QuadricCallback(IntPtr quad, OpenTK.Graphics.QuadricCallback which, Delegate CallBackFunc);
|
|
||||||
internal static QuadricCallback gluQuadricCallback;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void QuadricDrawStyle(IntPtr quad, OpenTK.Graphics.QuadricDrawStyle draw);
|
|
||||||
internal static QuadricDrawStyle gluQuadricDrawStyle;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void QuadricNormals(IntPtr quad, OpenTK.Graphics.QuadricNormal normal);
|
|
||||||
internal static QuadricNormals gluQuadricNormals;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void QuadricOrientation(IntPtr quad, OpenTK.Graphics.QuadricOrientation orientation);
|
|
||||||
internal static QuadricOrientation gluQuadricOrientation;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void QuadricTexture(IntPtr quad, bool texture);
|
|
||||||
internal static QuadricTexture gluQuadricTexture;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate Int32 ScaleImage(PixelFormat format, Int32 wIn, Int32 hIn, PixelType typeIn, IntPtr dataIn, Int32 wOut, Int32 hOut, PixelType typeOut, [Out] IntPtr dataOut);
|
|
||||||
internal static ScaleImage gluScaleImage;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void Sphere(IntPtr quad, double radius, Int32 slices, Int32 stacks);
|
|
||||||
internal static Sphere gluSphere;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void TessBeginContour(IntPtr tess);
|
|
||||||
internal static TessBeginContour gluTessBeginContour;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void TessBeginPolygon(IntPtr tess, IntPtr data);
|
|
||||||
internal static TessBeginPolygon gluTessBeginPolygon;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void TessCallback(IntPtr tess, OpenTK.Graphics.TessCallback which, Delegate CallBackFunc);
|
|
||||||
internal static TessCallback gluTessCallback;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void TessEndContour(IntPtr tess);
|
|
||||||
internal static TessEndContour gluTessEndContour;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void TessEndPolygon(IntPtr tess);
|
|
||||||
internal static TessEndPolygon gluTessEndPolygon;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void TessNormal(IntPtr tess, double valueX, double valueY, double valueZ);
|
|
||||||
internal static TessNormal gluTessNormal;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void TessProperty(IntPtr tess, OpenTK.Graphics.TessParameter which, double data);
|
|
||||||
internal static TessProperty gluTessProperty;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void TessVertex(IntPtr tess, double* location, IntPtr data);
|
|
||||||
internal unsafe static TessVertex gluTessVertex;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate Int32 TexFilterFuncSGI(TextureTarget target, SgisTextureFilter4 filtertype, float* parms, Int32 n, [Out] float* weights);
|
|
||||||
internal unsafe static TexFilterFuncSGI gluTexFilterFuncSGI;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate Int32 UnProject(double winX, double winY, double winZ, double* model, double* proj, Int32* view, double* objX, double* objY, double* objZ);
|
|
||||||
internal unsafe static UnProject gluUnProject;
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate Int32 UnProject4(double winX, double winY, double winZ, double clipW, double* model, double* proj, Int32* view, double near, double far, double* objX, double* objY, double* objZ, double* objW);
|
|
||||||
internal unsafe static UnProject4 gluUnProject4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,390 +0,0 @@
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
#pragma warning disable 1591
|
|
||||||
|
|
||||||
public enum GluVersion
|
|
||||||
{
|
|
||||||
Version11 = ((int)1),
|
|
||||||
Version13 = ((int)1),
|
|
||||||
Version12 = ((int)1),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum GluStringName
|
|
||||||
{
|
|
||||||
Version = ((int)100800),
|
|
||||||
Extensions = ((int)100801),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum GluErrorCode
|
|
||||||
{
|
|
||||||
OutOfMemory = ((int)100902),
|
|
||||||
InvalidEnum = ((int)100900),
|
|
||||||
InvalidValue = ((int)100901),
|
|
||||||
InvalidOperation = ((int)100904),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Filter4TypeSGIS
|
|
||||||
{
|
|
||||||
MitchellNetravaliSgi = ((int)100301),
|
|
||||||
LagrangianSgi = ((int)100300),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum NurbsDisplay
|
|
||||||
{
|
|
||||||
OutlinePolygon = ((int)100240),
|
|
||||||
OutlinePatch = ((int)100241),
|
|
||||||
Fill = ((int)QuadricDrawStyle.Fill),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum NurbsCallback
|
|
||||||
{
|
|
||||||
NurbsColorData = ((int)100173),
|
|
||||||
NurbsVertexData = ((int)100171),
|
|
||||||
NurbsNormal = ((int)100166),
|
|
||||||
NurbsError = ((int)100103),
|
|
||||||
NurbsTextureCoordExt = ((int)100168),
|
|
||||||
Error = ((int)100103),
|
|
||||||
NurbsEndDataExt = ((int)100175),
|
|
||||||
NurbsEnd = ((int)100169),
|
|
||||||
NurbsTextureCoord = ((int)100168),
|
|
||||||
NurbsEndExt = ((int)100169),
|
|
||||||
NurbsNormalDataExt = ((int)100172),
|
|
||||||
NurbsColor = ((int)100167),
|
|
||||||
NurbsColorExt = ((int)100167),
|
|
||||||
NurbsVertexExt = ((int)100165),
|
|
||||||
NurbsBeginExt = ((int)100164),
|
|
||||||
NurbsTextureCoordData = ((int)100174),
|
|
||||||
NurbsBeginData = ((int)100170),
|
|
||||||
NurbsColorDataExt = ((int)100173),
|
|
||||||
NurbsBeginDataExt = ((int)100170),
|
|
||||||
NurbsVertex = ((int)100165),
|
|
||||||
NurbsTextureCoordDataExt = ((int)100174),
|
|
||||||
NurbsNormalExt = ((int)100166),
|
|
||||||
NurbsVertexDataExt = ((int)100171),
|
|
||||||
NurbsBegin = ((int)100164),
|
|
||||||
NurbsEndData = ((int)100175),
|
|
||||||
NurbsNormalData = ((int)100172),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum NurbsError
|
|
||||||
{
|
|
||||||
NurbsError37 = ((int)100287),
|
|
||||||
NurbsError16 = ((int)100266),
|
|
||||||
NurbsError26 = ((int)100276),
|
|
||||||
NurbsError36 = ((int)100286),
|
|
||||||
NurbsError19 = ((int)100269),
|
|
||||||
NurbsError29 = ((int)100279),
|
|
||||||
NurbsError8 = ((int)100258),
|
|
||||||
NurbsError12 = ((int)100262),
|
|
||||||
NurbsError9 = ((int)100259),
|
|
||||||
NurbsError1 = ((int)100251),
|
|
||||||
NurbsError18 = ((int)100268),
|
|
||||||
NurbsError28 = ((int)100278),
|
|
||||||
NurbsError4 = ((int)100254),
|
|
||||||
NurbsError5 = ((int)100255),
|
|
||||||
NurbsError6 = ((int)100256),
|
|
||||||
NurbsError7 = ((int)100257),
|
|
||||||
NurbsError3 = ((int)100253),
|
|
||||||
NurbsError22 = ((int)100272),
|
|
||||||
NurbsError32 = ((int)100282),
|
|
||||||
NurbsError2 = ((int)100252),
|
|
||||||
NurbsError11 = ((int)100261),
|
|
||||||
NurbsError21 = ((int)100271),
|
|
||||||
NurbsError31 = ((int)100281),
|
|
||||||
NurbsError10 = ((int)100260),
|
|
||||||
NurbsError20 = ((int)100270),
|
|
||||||
NurbsError30 = ((int)100280),
|
|
||||||
NurbsError15 = ((int)100265),
|
|
||||||
NurbsError25 = ((int)100275),
|
|
||||||
NurbsError35 = ((int)100285),
|
|
||||||
NurbsError14 = ((int)100264),
|
|
||||||
NurbsError24 = ((int)100274),
|
|
||||||
NurbsError34 = ((int)100284),
|
|
||||||
NurbsError13 = ((int)100263),
|
|
||||||
NurbsError23 = ((int)100273),
|
|
||||||
NurbsError33 = ((int)100283),
|
|
||||||
NurbsError17 = ((int)100267),
|
|
||||||
NurbsError27 = ((int)100277),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum NurbsProperty
|
|
||||||
{
|
|
||||||
DisplayMode = ((int)100204),
|
|
||||||
ParametricTolerance = ((int)100202),
|
|
||||||
NurbsRenderer = ((int)100162),
|
|
||||||
NurbsTessellator = ((int)100161),
|
|
||||||
NurbsTessellatorExt = ((int)100161),
|
|
||||||
NurbsModeExt = ((int)100160),
|
|
||||||
UStep = ((int)100206),
|
|
||||||
SamplingMethod = ((int)100205),
|
|
||||||
AutoLoadMatrix = ((int)100200),
|
|
||||||
VStep = ((int)100207),
|
|
||||||
Culling = ((int)100201),
|
|
||||||
NurbsRendererExt = ((int)100162),
|
|
||||||
NurbsMode = ((int)100160),
|
|
||||||
SamplingTolerance = ((int)100203),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum NurbsSampling
|
|
||||||
{
|
|
||||||
ObjectParametricError = ((int)100208),
|
|
||||||
ObjectPathLength = ((int)100209),
|
|
||||||
PathLength = ((int)100215),
|
|
||||||
DomainDistance = ((int)100217),
|
|
||||||
ObjectPathLengthExt = ((int)100209),
|
|
||||||
ObjectParametricErrorExt = ((int)100208),
|
|
||||||
ParametricError = ((int)100216),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum NurbsTrim
|
|
||||||
{
|
|
||||||
Map1Trim3 = ((int)100211),
|
|
||||||
Map1Trim2 = ((int)100210),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum QuadricDrawStyle
|
|
||||||
{
|
|
||||||
Line = ((int)100011),
|
|
||||||
Silhouette = ((int)100013),
|
|
||||||
Point = ((int)100010),
|
|
||||||
Fill = ((int)100012),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum QuadricCallback
|
|
||||||
{
|
|
||||||
Error = ((int)NurbsCallback.Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum QuadricNormal
|
|
||||||
{
|
|
||||||
None = ((int)100002),
|
|
||||||
Flat = ((int)100001),
|
|
||||||
Smooth = ((int)100000),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum QuadricOrientation
|
|
||||||
{
|
|
||||||
Outside = ((int)100020),
|
|
||||||
Inside = ((int)100021),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum TessCallback
|
|
||||||
{
|
|
||||||
TessEdgeFlagData = ((int)100110),
|
|
||||||
Begin = ((int)100100),
|
|
||||||
TessError = ((int)100103),
|
|
||||||
EdgeFlag = ((int)100104),
|
|
||||||
End = ((int)100102),
|
|
||||||
TessCombine = ((int)100105),
|
|
||||||
Error = ((int)100103),
|
|
||||||
TessEndData = ((int)100108),
|
|
||||||
TessBeginData = ((int)100106),
|
|
||||||
TessErrorData = ((int)100109),
|
|
||||||
Vertex = ((int)100101),
|
|
||||||
TessVertexData = ((int)100107),
|
|
||||||
TessVertex = ((int)100101),
|
|
||||||
TessEdgeFlag = ((int)100104),
|
|
||||||
TessEnd = ((int)100102),
|
|
||||||
TessBegin = ((int)100100),
|
|
||||||
TessCombineData = ((int)100111),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum TessContour
|
|
||||||
{
|
|
||||||
Exterior = ((int)100123),
|
|
||||||
Ccw = ((int)100121),
|
|
||||||
Interior = ((int)100122),
|
|
||||||
Unknown = ((int)100124),
|
|
||||||
Cw = ((int)100120),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum TessParameter
|
|
||||||
{
|
|
||||||
TessWindingRule = ((int)100140),
|
|
||||||
TessBoundaryOnly = ((int)100141),
|
|
||||||
TessTolerance = ((int)100142),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum TessError
|
|
||||||
{
|
|
||||||
TessMissingBeginPolygon = ((int)100151),
|
|
||||||
TessMissingEndPolygon = ((int)100153),
|
|
||||||
TessError1 = ((int)100151),
|
|
||||||
TessMissingBeginContour = ((int)100152),
|
|
||||||
TessCoordTooLarge = ((int)100155),
|
|
||||||
TessError7 = ((int)100157),
|
|
||||||
TessError2 = ((int)100152),
|
|
||||||
TessError4 = ((int)100154),
|
|
||||||
TessNeedCombineCallback = ((int)100156),
|
|
||||||
TessError3 = ((int)100153),
|
|
||||||
TessError6 = ((int)100156),
|
|
||||||
TessError5 = ((int)100155),
|
|
||||||
TessError8 = ((int)100158),
|
|
||||||
TessMissingEndContour = ((int)100154),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum TessWinding
|
|
||||||
{
|
|
||||||
TessWindingNonzero = ((int)100131),
|
|
||||||
TessWindingOdd = ((int)100130),
|
|
||||||
TessWindingPositive = ((int)100132),
|
|
||||||
TessWindingAbsGeqTwo = ((int)100134),
|
|
||||||
TessWindingNegative = ((int)100133),
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum AllGlu
|
|
||||||
{
|
|
||||||
None = ((int)100002),
|
|
||||||
TessWindingRule = ((int)100140),
|
|
||||||
TessWindingPositive = ((int)100132),
|
|
||||||
ObjectPathLength = ((int)100209),
|
|
||||||
NurbsTextureCoordExt = ((int)100168),
|
|
||||||
Vertex = ((int)100101),
|
|
||||||
TessCombine = ((int)100105),
|
|
||||||
AutoLoadMatrix = ((int)100200),
|
|
||||||
TessBoundaryOnly = ((int)100141),
|
|
||||||
NurbsEndExt = ((int)100169),
|
|
||||||
NurbsError17 = ((int)100267),
|
|
||||||
NurbsError27 = ((int)100277),
|
|
||||||
NurbsError37 = ((int)100287),
|
|
||||||
Interior = ((int)100122),
|
|
||||||
TessWindingOdd = ((int)100130),
|
|
||||||
InvalidValue = ((int)100901),
|
|
||||||
ParametricError = ((int)100216),
|
|
||||||
TessError8 = ((int)100158),
|
|
||||||
NurbsError14 = ((int)100264),
|
|
||||||
NurbsError24 = ((int)100274),
|
|
||||||
NurbsError34 = ((int)100284),
|
|
||||||
NurbsTextureCoordDataExt = ((int)100174),
|
|
||||||
TessMissingBeginContour = ((int)100152),
|
|
||||||
Silhouette = ((int)100013),
|
|
||||||
TessError7 = ((int)100157),
|
|
||||||
NurbsNormalDataExt = ((int)100172),
|
|
||||||
NurbsError21 = ((int)100271),
|
|
||||||
NurbsError31 = ((int)100281),
|
|
||||||
PathLength = ((int)100215),
|
|
||||||
OutlinePolygon = ((int)100240),
|
|
||||||
TessVertex = ((int)100101),
|
|
||||||
TessWindingAbsGeqTwo = ((int)100134),
|
|
||||||
Extensions = ((int)100801),
|
|
||||||
TessEdgeFlagData = ((int)100110),
|
|
||||||
EdgeFlag = ((int)100104),
|
|
||||||
TessError1 = ((int)100151),
|
|
||||||
Line = ((int)100011),
|
|
||||||
NurbsBeginExt = ((int)100164),
|
|
||||||
Point = ((int)100010),
|
|
||||||
Begin = ((int)100100),
|
|
||||||
Inside = ((int)100021),
|
|
||||||
Flat = ((int)100001),
|
|
||||||
TessBegin = ((int)100100),
|
|
||||||
NurbsNormal = ((int)100166),
|
|
||||||
NurbsColorData = ((int)100173),
|
|
||||||
NurbsBeginDataExt = ((int)100170),
|
|
||||||
NurbsRenderer = ((int)100162),
|
|
||||||
NurbsBeginData = ((int)100170),
|
|
||||||
Outside = ((int)100020),
|
|
||||||
DisplayMode = ((int)100204),
|
|
||||||
NurbsError15 = ((int)100265),
|
|
||||||
NurbsError25 = ((int)100275),
|
|
||||||
NurbsError35 = ((int)100285),
|
|
||||||
NurbsVertexExt = ((int)100165),
|
|
||||||
TessError5 = ((int)100155),
|
|
||||||
Unknown = ((int)100124),
|
|
||||||
NurbsEndDataExt = ((int)100175),
|
|
||||||
NurbsError12 = ((int)100262),
|
|
||||||
NurbsError22 = ((int)100272),
|
|
||||||
NurbsError32 = ((int)100282),
|
|
||||||
ObjectParametricErrorExt = ((int)100208),
|
|
||||||
NurbsRendererExt = ((int)100162),
|
|
||||||
TessError3 = ((int)100153),
|
|
||||||
Fill = ((int)100012),
|
|
||||||
TessError = ((int)100103),
|
|
||||||
ObjectPathLengthExt = ((int)100209),
|
|
||||||
TessWindingNegative = ((int)100133),
|
|
||||||
NurbsTessellator = ((int)100161),
|
|
||||||
NurbsColor = ((int)100167),
|
|
||||||
NurbsModeExt = ((int)100160),
|
|
||||||
SamplingTolerance = ((int)100203),
|
|
||||||
NurbsColorDataExt = ((int)100173),
|
|
||||||
Exterior = ((int)100123),
|
|
||||||
Ccw = ((int)100121),
|
|
||||||
Cw = ((int)100120),
|
|
||||||
NurbsNormalExt = ((int)100166),
|
|
||||||
NurbsError18 = ((int)100268),
|
|
||||||
NurbsError28 = ((int)100278),
|
|
||||||
LagrangianSgi = ((int)100300),
|
|
||||||
TessEnd = ((int)100102),
|
|
||||||
NurbsTessellatorExt = ((int)100161),
|
|
||||||
NurbsEnd = ((int)100169),
|
|
||||||
TessWindingNonzero = ((int)100131),
|
|
||||||
OutOfMemory = ((int)100902),
|
|
||||||
TessBeginData = ((int)100106),
|
|
||||||
Error = ((int)100103),
|
|
||||||
ObjectParametricError = ((int)100208),
|
|
||||||
NurbsBegin = ((int)100164),
|
|
||||||
TessCombineData = ((int)100111),
|
|
||||||
TessMissingEndPolygon = ((int)100153),
|
|
||||||
NurbsTextureCoord = ((int)100168),
|
|
||||||
Smooth = ((int)100000),
|
|
||||||
TessMissingBeginPolygon = ((int)100151),
|
|
||||||
NurbsEndData = ((int)100175),
|
|
||||||
NurbsVertexData = ((int)100171),
|
|
||||||
TessEndData = ((int)100108),
|
|
||||||
NurbsError11 = ((int)100261),
|
|
||||||
NurbsVertex = ((int)100165),
|
|
||||||
NurbsError30 = ((int)100280),
|
|
||||||
Version11 = ((int)1),
|
|
||||||
TessError6 = ((int)100156),
|
|
||||||
Version13 = ((int)1),
|
|
||||||
Version12 = ((int)1),
|
|
||||||
TessErrorData = ((int)100109),
|
|
||||||
NurbsError36 = ((int)100286),
|
|
||||||
End = ((int)100102),
|
|
||||||
SamplingMethod = ((int)100205),
|
|
||||||
TessNeedCombineCallback = ((int)100156),
|
|
||||||
UStep = ((int)100206),
|
|
||||||
DomainDistance = ((int)100217),
|
|
||||||
TessEdgeFlag = ((int)100104),
|
|
||||||
NurbsColorExt = ((int)100167),
|
|
||||||
NurbsError19 = ((int)100269),
|
|
||||||
NurbsError29 = ((int)100279),
|
|
||||||
InvalidOperation = ((int)100904),
|
|
||||||
TessCoordTooLarge = ((int)100155),
|
|
||||||
TessVertexData = ((int)100107),
|
|
||||||
NurbsMode = ((int)100160),
|
|
||||||
ParametricTolerance = ((int)100202),
|
|
||||||
NurbsError2 = ((int)100252),
|
|
||||||
VStep = ((int)100207),
|
|
||||||
TessMissingEndContour = ((int)100154),
|
|
||||||
Map1Trim2 = ((int)100210),
|
|
||||||
Map1Trim3 = ((int)100211),
|
|
||||||
Culling = ((int)100201),
|
|
||||||
NurbsError16 = ((int)100266),
|
|
||||||
NurbsError26 = ((int)100276),
|
|
||||||
NurbsVertexDataExt = ((int)100171),
|
|
||||||
NurbsNormalData = ((int)100172),
|
|
||||||
TessError2 = ((int)100152),
|
|
||||||
NurbsError13 = ((int)100263),
|
|
||||||
NurbsError23 = ((int)100273),
|
|
||||||
NurbsError33 = ((int)100283),
|
|
||||||
NurbsError8 = ((int)100258),
|
|
||||||
NurbsError9 = ((int)100259),
|
|
||||||
TessError4 = ((int)100154),
|
|
||||||
NurbsError10 = ((int)100260),
|
|
||||||
NurbsError20 = ((int)100270),
|
|
||||||
OutlinePatch = ((int)100241),
|
|
||||||
NurbsError = ((int)100103),
|
|
||||||
NurbsTextureCoordData = ((int)100174),
|
|
||||||
NurbsError1 = ((int)100251),
|
|
||||||
InvalidEnum = ((int)100900),
|
|
||||||
NurbsError3 = ((int)100253),
|
|
||||||
NurbsError4 = ((int)100254),
|
|
||||||
NurbsError5 = ((int)100255),
|
|
||||||
NurbsError6 = ((int)100256),
|
|
||||||
NurbsError7 = ((int)100257),
|
|
||||||
MitchellNetravaliSgi = ((int)100301),
|
|
||||||
Version = ((int)100800),
|
|
||||||
TessTolerance = ((int)100142),
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,446 +0,0 @@
|
||||||
#region --- License ---
|
|
||||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
||||||
* Contributions by Andy Gill.
|
|
||||||
* See license.txt for license info
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Reflection.Emit;
|
|
||||||
|
|
||||||
using OpenTK.Platform;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Provides access to the OpenGL Utilities library.
|
|
||||||
/// Methods i this library are considered deprecated and should be avoided.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("Use OpenTK math functions instead.")]
|
|
||||||
public static partial class Glu
|
|
||||||
{
|
|
||||||
private const string Library = "glu32.dll";
|
|
||||||
|
|
||||||
private static Dictionary<string, bool> AvailableExtensions = new Dictionary<string, bool>();
|
|
||||||
private static bool rebuildExtensionList = true;
|
|
||||||
|
|
||||||
private static Type importsClass = typeof(Imports);
|
|
||||||
|
|
||||||
static Glu()
|
|
||||||
{
|
|
||||||
// Glu doesn't have any extensions, so this is safe to call once and be done with it.
|
|
||||||
LoadAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
#region private static Delegate LoadDelegate(string name, Type signature)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a System.Delegate that can be used to call a GLU function, core or extension.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The name of the GLU function (eg. "gluBuild2DMipmaps")</param>
|
|
||||||
/// <param name="signature">The signature of the GLU function.</param>
|
|
||||||
/// <returns>
|
|
||||||
/// A System.Delegate that can be used to call this GLU function, or null if the specified
|
|
||||||
/// function name did not correspond to an GLU function.
|
|
||||||
/// </returns>
|
|
||||||
private static Delegate LoadDelegate(string name, Type signature)
|
|
||||||
{
|
|
||||||
MethodInfo m = importsClass.GetMethod(name.Substring(3), BindingFlags.Static | BindingFlags.NonPublic);
|
|
||||||
return
|
|
||||||
GL.GetExtensionDelegate(name, signature) ??
|
|
||||||
(m != null ? Delegate.CreateDelegate(signature, m) : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public static void LoadAll()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Loads all GLU functions (core and extensions).
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// <para>
|
|
||||||
/// Call this function manually whenever you need to update GLU entry points.
|
|
||||||
/// This need will never arise under normal usage patterns.
|
|
||||||
/// </para>
|
|
||||||
/// </remarks>
|
|
||||||
public static void LoadAll()
|
|
||||||
{
|
|
||||||
int supported = 0;
|
|
||||||
Type extensions_class = typeof(Glu).GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
|
|
||||||
if (extensions_class == null)
|
|
||||||
throw new InvalidOperationException("The specified type does not have any loadable extensions.");
|
|
||||||
|
|
||||||
FieldInfo[] delegates = extensions_class.GetFields(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
|
|
||||||
if (delegates == null)
|
|
||||||
throw new InvalidOperationException("The specified type does not have any loadable extensions.");
|
|
||||||
|
|
||||||
foreach (FieldInfo f in delegates)
|
|
||||||
{
|
|
||||||
Delegate d = LoadDelegate(f.Name, f.FieldType);
|
|
||||||
if (d != null)
|
|
||||||
++supported;
|
|
||||||
|
|
||||||
f.SetValue(null, d);
|
|
||||||
}
|
|
||||||
|
|
||||||
rebuildExtensionList = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public static bool Load(string function)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tries to reload the given GLU function (core or extension).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="function">The name of the GLU function.</param>
|
|
||||||
/// <returns>True if the function was found and reloaded, false otherwise.</returns>
|
|
||||||
/// <remarks>
|
|
||||||
/// <para>
|
|
||||||
/// While the automatic initialisation will load all GLU entry points, in some cases
|
|
||||||
/// the initialization can take place before a render context has been established.
|
|
||||||
/// In this case, use this function to load the entry points for the GLU functions
|
|
||||||
/// you will need, or use LoadAll() to load all available entry points.
|
|
||||||
/// </para>
|
|
||||||
/// <para>
|
|
||||||
/// This function returns true if the given GLU function is supported, false otherwise.
|
|
||||||
/// </para>
|
|
||||||
/// <para>
|
|
||||||
/// To query for supported extensions use the IsExtensionSupported() function instead.
|
|
||||||
/// </para>
|
|
||||||
/// </remarks>
|
|
||||||
public static bool Load(string function)
|
|
||||||
{
|
|
||||||
// Glu does not contain any extensions - this method does nothing.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public static bool SupportsExtension(string name)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Determines whether the specified GLU extension is available in
|
|
||||||
/// the current GLU context.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The string for the GLU extension.</param>
|
|
||||||
/// <returns>True if the specified extension is available, false otherwise.</returns>
|
|
||||||
public static bool SupportsExtension(string name)
|
|
||||||
{
|
|
||||||
if (rebuildExtensionList)
|
|
||||||
{
|
|
||||||
BuildExtensionList();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search the cache for the string. Note that the cache substitutes
|
|
||||||
// strings "1.0" to "2.1" with "GL_VERSION_1_0" to "GL_VERSION_2_1"
|
|
||||||
if (AvailableExtensions.ContainsKey(name))
|
|
||||||
{
|
|
||||||
return AvailableExtensions[name];
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region private static void BuildExtensionList()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Builds a cache of the supported extensions to speed up searches.
|
|
||||||
/// </summary>
|
|
||||||
private static void BuildExtensionList()
|
|
||||||
{
|
|
||||||
// Assumes there is an opengl context current.
|
|
||||||
|
|
||||||
AvailableExtensions.Clear();
|
|
||||||
|
|
||||||
string version_string = Glu.GetString(GluStringName.Version);
|
|
||||||
if (String.IsNullOrEmpty(version_string))
|
|
||||||
{
|
|
||||||
throw new ApplicationException("Failed to build extension list. Is there an opengl context current?");
|
|
||||||
}
|
|
||||||
|
|
||||||
string version = version_string.Trim(' ');
|
|
||||||
if (version.StartsWith("1.0"))
|
|
||||||
{
|
|
||||||
AvailableExtensions.Add("VERSION_1_0", true);
|
|
||||||
}
|
|
||||||
else if (version.StartsWith("1.1"))
|
|
||||||
{
|
|
||||||
AvailableExtensions.Add("VERSION_1_0", true);
|
|
||||||
AvailableExtensions.Add("VERSION_1_1", true);
|
|
||||||
}
|
|
||||||
else if (version.StartsWith("1.2"))
|
|
||||||
{
|
|
||||||
AvailableExtensions.Add("VERSION_1_0", true);
|
|
||||||
AvailableExtensions.Add("VERSION_1_1", true);
|
|
||||||
AvailableExtensions.Add("VERSION_1_2", true);
|
|
||||||
}
|
|
||||||
else if (version.StartsWith("1.3"))
|
|
||||||
{
|
|
||||||
AvailableExtensions.Add("VERSION_1_0", true);
|
|
||||||
AvailableExtensions.Add("VERSION_1_1", true);
|
|
||||||
AvailableExtensions.Add("VERSION_1_2", true);
|
|
||||||
AvailableExtensions.Add("VERSION_1_3", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
string extension_string = Glu.GetString(GluStringName.Extensions);
|
|
||||||
if (String.IsNullOrEmpty(extension_string))
|
|
||||||
{ // no extensions are available
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
string[] extensions = extension_string.Split(' ');
|
|
||||||
foreach (string ext in extensions)
|
|
||||||
{
|
|
||||||
AvailableExtensions.Add(ext, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
rebuildExtensionList = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Overloads
|
|
||||||
|
|
||||||
public static void LookAt(Vector3 eye, Vector3 center, Vector3 up)
|
|
||||||
{
|
|
||||||
Delegates.gluLookAt((double)eye.X, (double)eye.Y, (double)eye.Z, (double)center.X, (double)center.Y, (double)center.Z, (double)up.X, (double)up.Y, (double)up.Z);
|
|
||||||
}
|
|
||||||
|
|
||||||
// One token Project overload, I picked this one because it's CLS compliant, and it
|
|
||||||
// makes reasonably clear which args are inputs and which are outputs.
|
|
||||||
public static Int32 Project(Vector3 obj, double[] model, double[] proj, Int32[] view, out Vector3 win)
|
|
||||||
{
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
double winX, winY, winZ;
|
|
||||||
double* winX_ptr = &winX;
|
|
||||||
double* winY_ptr = &winY;
|
|
||||||
double* winZ_ptr = &winZ;
|
|
||||||
fixed (double* model_ptr = model)
|
|
||||||
fixed (double* proj_ptr = proj)
|
|
||||||
fixed (Int32* view_ptr = view)
|
|
||||||
{
|
|
||||||
Int32 retval = Delegates.gluProject((double)obj.X, (double)obj.Y, (double)obj.Z, (double*)model_ptr, (double*)proj_ptr, (Int32*)view_ptr, (double*)winX_ptr, (double*)winY_ptr, (double*)winZ_ptr);
|
|
||||||
win = new Vector3((float)*winX_ptr, (float)*winY_ptr, (float)*winZ_ptr);
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void TessNormal(IntPtr tess, Vector3 normal)
|
|
||||||
{
|
|
||||||
Delegates.gluTessNormal(tess, (double)normal.X, (double)normal.Y, (double)normal.Z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Int32 UnProject(Vector3 win, double[] model, double[] proj, Int32[] view, out Vector3 obj)
|
|
||||||
{
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
double objX, objY, objZ;
|
|
||||||
double* objX_ptr = &objX;
|
|
||||||
double* objY_ptr = &objY;
|
|
||||||
double* objZ_ptr = &objZ;
|
|
||||||
fixed (double* model_ptr = model)
|
|
||||||
fixed (double* proj_ptr = proj)
|
|
||||||
fixed (Int32* view_ptr = view)
|
|
||||||
{
|
|
||||||
Int32 retval = Delegates.gluUnProject((double)win.X, (double)win.Y, (double)win.Z, (double*)model_ptr, (double*)proj_ptr, (Int32*)view_ptr, (double*)objX_ptr, (double*)objY_ptr, (double*)objZ_ptr);
|
|
||||||
obj = new Vector3((float)*objX_ptr, (float)*objY_ptr, (float)*objZ_ptr);
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Int32 UnProject4(Vector4 win, double[] model, double[] proj, Int32[] view, double near, double far, out Vector4 obj)
|
|
||||||
{
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
double objX, objY, objZ, objW;
|
|
||||||
double* objX_ptr = &objX;
|
|
||||||
double* objY_ptr = &objY;
|
|
||||||
double* objZ_ptr = &objZ;
|
|
||||||
double* objW_ptr = &objW;
|
|
||||||
fixed (double* model_ptr = model)
|
|
||||||
fixed (double* proj_ptr = proj)
|
|
||||||
fixed (Int32* view_ptr = view)
|
|
||||||
{
|
|
||||||
Int32 retval = Delegates.gluUnProject4((double)win.X, (double)win.Y, (double)win.Z, (double)win.W, (double*)model_ptr, (double*)proj_ptr, (Int32*)view_ptr, (double)near, (double)far, (double*)objX_ptr, (double*)objY_ptr, (double*)objZ_ptr, (double*)objW_ptr);
|
|
||||||
obj = new Vector4((float)*objX_ptr, (float)*objY_ptr, (float)*objZ_ptr, (float)*objW_ptr);
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string ErrorString(ErrorCode error)
|
|
||||||
{
|
|
||||||
return ErrorString((GluErrorCode)error);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void TessWindingRuleProperty(IntPtr tess, TessWinding property)
|
|
||||||
{
|
|
||||||
Glu.TessProperty(tess, TessParameter.TessWindingRule, (double)property);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#if false
|
|
||||||
|
|
||||||
//public delegate object
|
|
||||||
|
|
||||||
public delegate void FastVoidInvokeHandler(object target, object[] paramters);
|
|
||||||
public delegate object FastInvokeHandler(object target, object[] paramters);
|
|
||||||
public static class FastInvoker
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Use this one instead of MethodInfo.Invoke, this way it is 50 times quicker.
|
|
||||||
///
|
|
||||||
/// <example>
|
|
||||||
/// string Filter = "FirstName = 'Ton'"
|
|
||||||
/// MethodInfo mi = typeof(Person).GetMethod("GetAll");
|
|
||||||
/// snoei.net.Reflection.FastInvoker.FastInvokeHandler fi = snoei.net.Reflection.FastInvoker.GetMethodInvoker( mi );
|
|
||||||
// return fi.Invoke( Person, new object[]{Filter} );
|
|
||||||
/// //Calls Person.GetAll(string Filter);
|
|
||||||
/// </example>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="methodInfo"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static Delegate GetMethodInvoker(MethodInfo methodInfo)
|
|
||||||
{
|
|
||||||
DynamicMethod dynamicMethod = new DynamicMethod(string.Empty, methodInfo.ReturnType, new Type[] { typeof(object), typeof(object[]) }, methodInfo.DeclaringType.Module);
|
|
||||||
ILGenerator il = dynamicMethod.GetILGenerator();
|
|
||||||
ParameterInfo[] ps = methodInfo.GetParameters();
|
|
||||||
Type[] paramTypes = new Type[ps.Length];
|
|
||||||
|
|
||||||
for (int i = 0; i < paramTypes.Length; i++)
|
|
||||||
{
|
|
||||||
if (ps[i].ParameterType.IsByRef)
|
|
||||||
paramTypes[i] = ps[i].ParameterType.GetElementType();
|
|
||||||
else
|
|
||||||
paramTypes[i] = ps[i].ParameterType;
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalBuilder[] locals = new LocalBuilder[paramTypes.Length];
|
|
||||||
|
|
||||||
for (int i = 0; i < paramTypes.Length; i++)
|
|
||||||
locals[i] = il.DeclareLocal(paramTypes[i], true);
|
|
||||||
|
|
||||||
for (int i = 0; i < paramTypes.Length; i++)
|
|
||||||
{
|
|
||||||
il.Emit(OpCodes.Ldarg_1);
|
|
||||||
EmitFastInt(il, i);
|
|
||||||
il.Emit(OpCodes.Ldelem_Ref);
|
|
||||||
EmitCastToReference(il, paramTypes[i]);
|
|
||||||
il.Emit(OpCodes.Stloc, locals[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!methodInfo.IsStatic)
|
|
||||||
il.Emit(OpCodes.Ldarg_0);
|
|
||||||
|
|
||||||
for (int i = 0; i < paramTypes.Length; i++)
|
|
||||||
{
|
|
||||||
if (ps[i].ParameterType.IsByRef)
|
|
||||||
il.Emit(OpCodes.Ldloca_S, locals[i]);
|
|
||||||
else
|
|
||||||
il.Emit(OpCodes.Ldloc, locals[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (methodInfo.IsStatic)
|
|
||||||
il.EmitCall(OpCodes.Call, methodInfo, null);
|
|
||||||
else
|
|
||||||
il.EmitCall(OpCodes.Callvirt, methodInfo, null);
|
|
||||||
|
|
||||||
if (methodInfo.ReturnType == typeof(void))
|
|
||||||
il.Emit(OpCodes.Ldnull);
|
|
||||||
else
|
|
||||||
EmitBoxIfNeeded(il, methodInfo.ReturnType);
|
|
||||||
|
|
||||||
for (int i = 0; i < paramTypes.Length; i++)
|
|
||||||
{
|
|
||||||
if (ps[i].ParameterType.IsByRef)
|
|
||||||
{
|
|
||||||
il.Emit(OpCodes.Ldarg_1);
|
|
||||||
EmitFastInt(il, i);
|
|
||||||
il.Emit(OpCodes.Ldloc, locals[i]);
|
|
||||||
if (locals[i].LocalType.IsValueType)
|
|
||||||
il.Emit(OpCodes.Box, locals[i].LocalType);
|
|
||||||
il.Emit(OpCodes.Stelem_Ref);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
il.Emit(OpCodes.Ret);
|
|
||||||
|
|
||||||
if (methodInfo.ReturnType == typeof(void))
|
|
||||||
return dynamicMethod.CreateDelegate(typeof(FastVoidInvokeHandler));
|
|
||||||
else
|
|
||||||
return dynamicMethod.CreateDelegate(typeof(FastInvokeHandler));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void EmitCastToReference(ILGenerator il, System.Type type)
|
|
||||||
{
|
|
||||||
if (type.IsValueType)
|
|
||||||
il.Emit(OpCodes.Unbox_Any, type);
|
|
||||||
else
|
|
||||||
il.Emit(OpCodes.Castclass, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void EmitBoxIfNeeded(ILGenerator il, System.Type type)
|
|
||||||
{
|
|
||||||
if (type.IsValueType)
|
|
||||||
il.Emit(OpCodes.Box, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void EmitFastInt(ILGenerator il, int value)
|
|
||||||
{
|
|
||||||
switch (value)
|
|
||||||
{
|
|
||||||
case -1:
|
|
||||||
il.Emit(OpCodes.Ldc_I4_M1);
|
|
||||||
return;
|
|
||||||
case 0:
|
|
||||||
il.Emit(OpCodes.Ldc_I4_0);
|
|
||||||
return;
|
|
||||||
case 1:
|
|
||||||
il.Emit(OpCodes.Ldc_I4_1);
|
|
||||||
return;
|
|
||||||
case 2:
|
|
||||||
il.Emit(OpCodes.Ldc_I4_2);
|
|
||||||
return;
|
|
||||||
case 3:
|
|
||||||
il.Emit(OpCodes.Ldc_I4_3);
|
|
||||||
return;
|
|
||||||
case 4:
|
|
||||||
il.Emit(OpCodes.Ldc_I4_4);
|
|
||||||
return;
|
|
||||||
case 5:
|
|
||||||
il.Emit(OpCodes.Ldc_I4_5);
|
|
||||||
return;
|
|
||||||
case 6:
|
|
||||||
il.Emit(OpCodes.Ldc_I4_6);
|
|
||||||
return;
|
|
||||||
case 7:
|
|
||||||
il.Emit(OpCodes.Ldc_I4_7);
|
|
||||||
return;
|
|
||||||
case 8:
|
|
||||||
il.Emit(OpCodes.Ldc_I4_8);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value > -129 && value < 128)
|
|
||||||
il.Emit(OpCodes.Ldc_I4_S, (SByte)value);
|
|
||||||
else
|
|
||||||
il.Emit(OpCodes.Ldc_I4, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents exceptions related to IGraphicsResources.
|
|
||||||
/// </summary>
|
|
||||||
public class GraphicsResourceException : Exception
|
|
||||||
{
|
|
||||||
/// <summary>Constructs a new GraphicsResourceException.</summary>
|
|
||||||
public GraphicsResourceException() : base() { }
|
|
||||||
/// <summary>Constructs a new string with the specified error message.</summary>
|
|
||||||
public GraphicsResourceException(string message) : base(message) { }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Defines a common interface to all OpenGL resources.
|
|
||||||
/// </summary>
|
|
||||||
interface IGraphicsResource : IDisposable
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the GraphicsContext that owns this resource.
|
|
||||||
/// </summary>
|
|
||||||
IGraphicsContext Context { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the Id of this IGraphicsResource.
|
|
||||||
/// </summary>
|
|
||||||
int Id { get; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,159 +0,0 @@
|
||||||
#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.Drawing;
|
|
||||||
using OpenTK.Graphics.Text;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Defines the interface for a TextPrinter.
|
|
||||||
/// </summary>
|
|
||||||
public interface ITextPrinter : IDisposable
|
|
||||||
{
|
|
||||||
#region Print
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prints text using the specified color and layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to print.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
|
||||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
|
||||||
void Print(string text, Font font, Color color);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prints text using the specified color and layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to print.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
|
||||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
void Print(string text, Font font, Color color, RectangleF rect);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prints text using the specified color and layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to print.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
|
||||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
|
|
||||||
void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prints text using the specified color and layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to print.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
|
||||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
|
|
||||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to print text.</param>
|
|
||||||
void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prints text using the specified color and layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to print.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
|
||||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
|
|
||||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to print text.</param>
|
|
||||||
/// <param name="direction">The OpenTK.Graphics.TextDirection that will be used to print text.</param>
|
|
||||||
void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction);
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Measure
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Measures text using the specified layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to measure.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
|
||||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
|
||||||
TextExtents Measure(string text, Font font);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Measures text using the specified layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to measure.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
|
||||||
TextExtents Measure(string text, Font font, RectangleF rect);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Measures text using the specified layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to measure.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
|
|
||||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
|
||||||
TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Measures text using the specified layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to measure.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
|
|
||||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to measure text.</param>
|
|
||||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
|
||||||
TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Measures text using the specified layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to measure.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
|
|
||||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to measure text.</param>
|
|
||||||
/// <param name="direction">The OpenTK.Graphics.TextDirection that will be used to measure text.</param>
|
|
||||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
|
||||||
TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction);
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Begin
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets up a resolution-dependent orthographic projection.
|
|
||||||
/// </summary>
|
|
||||||
void Begin();
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region End
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Restores the projection and modelview matrices to their previous state.
|
|
||||||
/// </summary>
|
|
||||||
void End();
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Obsolete
|
|
||||||
|
|
||||||
[Obsolete("Use TextPrinter.Print instead")]
|
|
||||||
void Draw(TextHandle handle);
|
|
||||||
|
|
||||||
[Obsolete("Use TextPrinter.Print instead")]
|
|
||||||
void Draw(string text, TextureFont font);
|
|
||||||
|
|
||||||
[Obsolete("Use TextPrinter.Print instead")]
|
|
||||||
void Prepare(string text, TextureFont font, out TextHandle handle);
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Graphics.OpenGL;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
[Obsolete]
|
|
||||||
class RgbaTexture2D : Texture2D
|
|
||||||
{
|
|
||||||
public RgbaTexture2D(int width, int height)
|
|
||||||
: base(width, height)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected override PixelInternalFormat InternalFormat
|
|
||||||
{
|
|
||||||
get { return PixelInternalFormat.Rgba; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
[Obsolete]
|
|
||||||
struct CachedGlyphInfo
|
|
||||||
{
|
|
||||||
public readonly Texture2D Texture;
|
|
||||||
public readonly RectangleF RectangleNormalized;
|
|
||||||
public Rectangle Rectangle
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return new Rectangle(
|
|
||||||
(int)(RectangleNormalized.X * Texture.Width),
|
|
||||||
(int)(RectangleNormalized.Y * Texture.Height),
|
|
||||||
(int)(RectangleNormalized.Width * Texture.Width),
|
|
||||||
(int)(RectangleNormalized.Height * Texture.Height));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rect denotes the absolute position of the glyph in the texture [0, Texture.Width], [0, Texture.Height].
|
|
||||||
public CachedGlyphInfo(Texture2D texture, Rectangle rect)
|
|
||||||
{
|
|
||||||
Texture = texture;
|
|
||||||
RectangleNormalized = new RectangleF(
|
|
||||||
rect.X / (float)texture.Width,
|
|
||||||
rect.Y / (float)texture.Height,
|
|
||||||
rect.Width / (float)texture.Width,
|
|
||||||
rect.Height / (float)texture.Height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,65 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Drawing;
|
|
||||||
using OpenTK.Graphics.OpenGL;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
[Obsolete]
|
|
||||||
sealed class GL11TextOutputProvider : GL1TextOutputProvider
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
TextQuality quality;
|
|
||||||
GlyphCache cache;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constuctors
|
|
||||||
|
|
||||||
public GL11TextOutputProvider(TextQuality quality)
|
|
||||||
{
|
|
||||||
if (quality == TextQuality.High || quality == TextQuality.Default)
|
|
||||||
this.quality = TextQuality.Medium;
|
|
||||||
else
|
|
||||||
this.quality = quality;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Protected Members
|
|
||||||
|
|
||||||
protected override void SetBlendFunction()
|
|
||||||
{
|
|
||||||
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // For grayscale
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void SetColor(Color color)
|
|
||||||
{
|
|
||||||
GL.Color3(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override TextQuality TextQuality
|
|
||||||
{
|
|
||||||
get { return quality; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override GlyphCache Cache
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (cache == null)
|
|
||||||
{
|
|
||||||
if (GL.GetString(StringName.Renderer).Contains("ProSavage/Twister"))
|
|
||||||
cache = new GlyphCache<RgbaTexture2D>();
|
|
||||||
else
|
|
||||||
cache = new GlyphCache<AlphaTexture2D>();
|
|
||||||
}
|
|
||||||
return cache;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Drawing;
|
|
||||||
|
|
||||||
using OpenTK.Graphics.OpenGL;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
[Obsolete]
|
|
||||||
sealed class GL12TextOutputProvider : GL1TextOutputProvider
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
TextQuality quality;
|
|
||||||
GlyphCache cache;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constuctors
|
|
||||||
|
|
||||||
public GL12TextOutputProvider(TextQuality quality)
|
|
||||||
{
|
|
||||||
this.quality = quality;
|
|
||||||
|
|
||||||
cache = new GlyphCache<RgbaTexture2D>();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
protected override void SetBlendFunction()
|
|
||||||
{
|
|
||||||
GL.BlendFunc(BlendingFactorSrc.ConstantColorExt, BlendingFactorDest.OneMinusSrcColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void SetColor(Color color)
|
|
||||||
{
|
|
||||||
GL.Color3(Color.White);
|
|
||||||
GL.BlendColor(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override TextQuality TextQuality
|
|
||||||
{
|
|
||||||
get { return quality; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override GlyphCache Cache
|
|
||||||
{
|
|
||||||
get { return cache; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,340 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
|
|
||||||
using OpenTK.Graphics.OpenGL;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
[Obsolete]
|
|
||||||
abstract class GL1TextOutputProvider : ITextOutputProvider
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
// Triangle lists, sorted by texture.
|
|
||||||
Dictionary<Texture2D, List<Vector2>> active_lists = new Dictionary<Texture2D, List<Vector2>>();
|
|
||||||
Queue<List<Vector2>> inactive_lists = new Queue<List<Vector2>>();
|
|
||||||
|
|
||||||
#pragma warning disable 0649
|
|
||||||
struct Viewport { public int X, Y, Width, Height; }
|
|
||||||
#pragma warning restore 0649
|
|
||||||
|
|
||||||
// Used to save the current state in Begin() and restore it in End()
|
|
||||||
Stack<Matrix4> projection_stack = new Stack<Matrix4>();
|
|
||||||
Stack<Matrix4> modelview_stack = new Stack<Matrix4>();
|
|
||||||
Stack<Matrix4> texture_stack = new Stack<Matrix4>();
|
|
||||||
Stack<Viewport> viewport_stack = new Stack<Viewport>();
|
|
||||||
|
|
||||||
// Used as temporary storage when saving / restoring the current state.
|
|
||||||
Viewport viewport = new Viewport();
|
|
||||||
Matrix4 matrix = new Matrix4();
|
|
||||||
|
|
||||||
// TextBlock - display list cache.
|
|
||||||
// Todo: we need a cache eviction strategy.
|
|
||||||
const int block_cache_capacity = 32;
|
|
||||||
readonly Dictionary<int, int> block_cache = new Dictionary<int, int>(block_cache_capacity);
|
|
||||||
|
|
||||||
bool disposed;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
public GL1TextOutputProvider()
|
|
||||||
{
|
|
||||||
inactive_lists.Enqueue(new List<Vector2>());
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region ITextOutputProvider Members
|
|
||||||
|
|
||||||
#region Print
|
|
||||||
|
|
||||||
public void Print(ref TextBlock block, Color color, IGlyphRasterizer rasterizer)
|
|
||||||
{
|
|
||||||
GL.PushAttrib(AttribMask.CurrentBit | AttribMask.TextureBit | AttribMask.EnableBit | AttribMask.ColorBufferBit | AttribMask.DepthBufferBit);
|
|
||||||
|
|
||||||
GL.Enable(EnableCap.Texture2D);
|
|
||||||
GL.Enable(EnableCap.Blend);
|
|
||||||
SetBlendFunction();
|
|
||||||
|
|
||||||
GL.Disable(EnableCap.DepthTest);
|
|
||||||
|
|
||||||
GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)All.Modulate);
|
|
||||||
GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvColor, new Color4(0, 0, 0, 0));
|
|
||||||
|
|
||||||
GL.Disable(EnableCap.TextureGenQ);
|
|
||||||
GL.Disable(EnableCap.TextureGenR);
|
|
||||||
GL.Disable(EnableCap.TextureGenS);
|
|
||||||
GL.Disable(EnableCap.TextureGenT);
|
|
||||||
|
|
||||||
RectangleF position;
|
|
||||||
|
|
||||||
SetColor(color);
|
|
||||||
|
|
||||||
int block_hash = block.GetHashCode();
|
|
||||||
if (block_cache.ContainsKey(block_hash))
|
|
||||||
{
|
|
||||||
GL.CallList(block_cache[block_hash]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
using (TextExtents extents = rasterizer.MeasureText(ref block))
|
|
||||||
{
|
|
||||||
// Build layout
|
|
||||||
int current = 0;
|
|
||||||
foreach (Glyph glyph in block)
|
|
||||||
{
|
|
||||||
// Do not render whitespace characters or characters outside the clip rectangle.
|
|
||||||
if (glyph.IsWhiteSpace || extents[current].Width == 0 || extents[current].Height == 0)
|
|
||||||
{
|
|
||||||
current++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if (!Cache.Contains(glyph))
|
|
||||||
Cache.Add(glyph, rasterizer, TextQuality);
|
|
||||||
|
|
||||||
CachedGlyphInfo info = Cache[glyph];
|
|
||||||
position = extents[current++];
|
|
||||||
|
|
||||||
// Use the real glyph width instead of the measured one (we want to achieve pixel perfect output).
|
|
||||||
position.Size = info.Rectangle.Size;
|
|
||||||
|
|
||||||
if (!active_lists.ContainsKey(info.Texture))
|
|
||||||
{
|
|
||||||
if (inactive_lists.Count > 0)
|
|
||||||
{
|
|
||||||
List<Vector2> list = inactive_lists.Dequeue();
|
|
||||||
list.Clear();
|
|
||||||
active_lists.Add(info.Texture, list);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
active_lists.Add(info.Texture, new List<Vector2>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
// Interleaved array: Vertex, TexCoord, Vertex, ...
|
|
||||||
List<Vector2> current_list = active_lists[info.Texture];
|
|
||||||
current_list.Add(new Vector2(info.RectangleNormalized.Left, info.RectangleNormalized.Top));
|
|
||||||
current_list.Add(new Vector2(position.Left, position.Top));
|
|
||||||
current_list.Add(new Vector2(info.RectangleNormalized.Left, info.RectangleNormalized.Bottom));
|
|
||||||
current_list.Add(new Vector2(position.Left, position.Bottom));
|
|
||||||
current_list.Add(new Vector2(info.RectangleNormalized.Right, info.RectangleNormalized.Bottom));
|
|
||||||
current_list.Add(new Vector2(position.Right, position.Bottom));
|
|
||||||
|
|
||||||
current_list.Add(new Vector2(info.RectangleNormalized.Right, info.RectangleNormalized.Bottom));
|
|
||||||
current_list.Add(new Vector2(position.Right, position.Bottom));
|
|
||||||
current_list.Add(new Vector2(info.RectangleNormalized.Right, info.RectangleNormalized.Top));
|
|
||||||
current_list.Add(new Vector2(position.Right, position.Top));
|
|
||||||
current_list.Add(new Vector2(info.RectangleNormalized.Left, info.RectangleNormalized.Top));
|
|
||||||
current_list.Add(new Vector2(position.Left, position.Top));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render
|
|
||||||
int display_list = 0;
|
|
||||||
if ((block.Options & TextPrinterOptions.NoCache) == 0)
|
|
||||||
{
|
|
||||||
display_list = GL.GenLists(1);
|
|
||||||
// Mesa Indirect gerates an InvalidOperation error right after
|
|
||||||
// GL.EndList() when using ListMode.CompileAndExecute.
|
|
||||||
// Using ListMode.Compile as a workaround.
|
|
||||||
GL.NewList(display_list, ListMode.Compile);
|
|
||||||
}
|
|
||||||
foreach (Texture2D key in active_lists.Keys)
|
|
||||||
{
|
|
||||||
List<Vector2> list = active_lists[key];
|
|
||||||
|
|
||||||
key.Bind();
|
|
||||||
|
|
||||||
GL.Begin(BeginMode.Triangles);
|
|
||||||
|
|
||||||
for (int i = 0; i < list.Count; i += 2)
|
|
||||||
{
|
|
||||||
GL.TexCoord2(list[i]);
|
|
||||||
GL.Vertex2(list[i + 1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
GL.End();
|
|
||||||
}
|
|
||||||
if ((block.Options & TextPrinterOptions.NoCache) == 0)
|
|
||||||
{
|
|
||||||
GL.EndList();
|
|
||||||
block_cache.Add(block_hash, display_list);
|
|
||||||
GL.CallList(display_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean layout
|
|
||||||
foreach (List<Vector2> list in active_lists.Values)
|
|
||||||
{
|
|
||||||
//list.Clear();
|
|
||||||
inactive_lists.Enqueue(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
active_lists.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
GL.PopAttrib();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Clear
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
Cache.Clear();
|
|
||||||
foreach (int display_list in block_cache.Keys)
|
|
||||||
GL.DeleteLists(display_list, 1);
|
|
||||||
block_cache.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Begin
|
|
||||||
|
|
||||||
public void Begin()
|
|
||||||
{
|
|
||||||
if (disposed)
|
|
||||||
throw new ObjectDisposedException(this.GetType().ToString());
|
|
||||||
|
|
||||||
GraphicsContext.Assert();
|
|
||||||
|
|
||||||
// Save the state of everything we are going to modify:
|
|
||||||
// the current matrix mode, viewport state and the projection, modelview and texture matrices.
|
|
||||||
// All these will be restored in the TextPrinter.End() method.
|
|
||||||
int current_matrix;
|
|
||||||
GL.GetInteger(GetPName.MatrixMode, out current_matrix);
|
|
||||||
|
|
||||||
GL.GetInteger(GetPName.Viewport, out viewport.X);
|
|
||||||
viewport_stack.Push(viewport);
|
|
||||||
|
|
||||||
GL.GetFloat(GetPName.ProjectionMatrix, out matrix.Row0.X);
|
|
||||||
projection_stack.Push(matrix);
|
|
||||||
GL.GetFloat(GetPName.ModelviewMatrix, out matrix.Row0.X);
|
|
||||||
modelview_stack.Push(matrix);
|
|
||||||
GL.GetFloat(GetPName.TextureMatrix, out matrix.Row0.X);
|
|
||||||
texture_stack.Push(matrix);
|
|
||||||
|
|
||||||
// Prepare to draw text. We want pixel perfect precision, so we setup a 2D mode,
|
|
||||||
// with size equal to the window (in pixels).
|
|
||||||
// While we could also render text in 3D mode, it would be very hard to get
|
|
||||||
// pixel-perfect precision.
|
|
||||||
GL.MatrixMode(MatrixMode.Projection);
|
|
||||||
GL.LoadIdentity();
|
|
||||||
GL.Ortho(viewport.X, viewport.Width, viewport.Height, viewport.Y, -1.0, 1.0);
|
|
||||||
|
|
||||||
GL.MatrixMode(MatrixMode.Modelview);
|
|
||||||
GL.LoadIdentity();
|
|
||||||
|
|
||||||
GL.MatrixMode(MatrixMode.Texture);
|
|
||||||
GL.LoadIdentity();
|
|
||||||
|
|
||||||
GL.MatrixMode((MatrixMode)current_matrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region End
|
|
||||||
|
|
||||||
public void End()
|
|
||||||
{
|
|
||||||
if (disposed)
|
|
||||||
throw new ObjectDisposedException(this.GetType().ToString());
|
|
||||||
|
|
||||||
GraphicsContext.Assert();
|
|
||||||
|
|
||||||
int current_matrix;
|
|
||||||
GL.GetInteger(GetPName.MatrixMode, out current_matrix);
|
|
||||||
|
|
||||||
viewport = viewport_stack.Pop();
|
|
||||||
GL.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height);
|
|
||||||
|
|
||||||
GL.MatrixMode(MatrixMode.Texture);
|
|
||||||
matrix = texture_stack.Pop();
|
|
||||||
GL.LoadMatrix(ref matrix);
|
|
||||||
|
|
||||||
GL.MatrixMode(MatrixMode.Modelview);
|
|
||||||
matrix = modelview_stack.Pop();
|
|
||||||
GL.LoadMatrix(ref matrix);
|
|
||||||
|
|
||||||
GL.MatrixMode(MatrixMode.Projection);
|
|
||||||
matrix = projection_stack.Pop();
|
|
||||||
GL.LoadMatrix(ref matrix);
|
|
||||||
|
|
||||||
GL.MatrixMode((MatrixMode)current_matrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Protected Members
|
|
||||||
|
|
||||||
protected abstract void SetBlendFunction();
|
|
||||||
|
|
||||||
protected abstract void SetColor(Color color);
|
|
||||||
|
|
||||||
protected abstract TextQuality TextQuality { get; }
|
|
||||||
|
|
||||||
protected abstract GlyphCache Cache { get; }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Static Members
|
|
||||||
|
|
||||||
public static GL1TextOutputProvider Create(TextQuality quality)
|
|
||||||
{
|
|
||||||
if (!GL.SupportsExtension("Version12") || !GL.SupportsFunction("BlendColor") || quality == TextQuality.Low || quality == TextQuality.Medium)
|
|
||||||
return new GL11TextOutputProvider(quality);
|
|
||||||
else
|
|
||||||
return new GL12TextOutputProvider(quality);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
if (!disposed)
|
|
||||||
{
|
|
||||||
Cache.Dispose();
|
|
||||||
disposed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,501 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
using System.Drawing.Imaging;
|
|
||||||
using System.Drawing.Text;
|
|
||||||
using OpenTK.Platform;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
sealed class GdiPlusGlyphRasterizer : IGlyphRasterizer
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
// Note: as an optimization, we store the TextBlock hashcode instead of the TextBlock itself.
|
|
||||||
Dictionary<int, TextExtents> block_cache = new Dictionary<int, TextExtents>();
|
|
||||||
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(new Bitmap(1, 1));
|
|
||||||
|
|
||||||
IntPtr[] regions = new IntPtr[GdiPlus.MaxMeasurableCharacterRanges];
|
|
||||||
CharacterRange[] characterRanges = new CharacterRange[GdiPlus.MaxMeasurableCharacterRanges];
|
|
||||||
|
|
||||||
Bitmap glyph_surface;
|
|
||||||
System.Drawing.Graphics glyph_renderer;
|
|
||||||
|
|
||||||
readonly List<RectangleF> measured_glyphs = new List<RectangleF>(256);
|
|
||||||
|
|
||||||
readonly ObjectPool<PoolableTextExtents> text_extents_pool = new ObjectPool<PoolableTextExtents>();
|
|
||||||
|
|
||||||
// Check the constructor, too, for additional flags.
|
|
||||||
// Used for measuring text. Can set the leftToRight, rightToLeft, vertical and measure trailing spaces flags.
|
|
||||||
readonly StringFormat measure_string_format = new StringFormat(StringFormat.GenericDefault);
|
|
||||||
readonly StringFormat measure_string_format_tight = new StringFormat(StringFormat.GenericTypographic);
|
|
||||||
// Used for loading glyphs. Only use leftToRight!
|
|
||||||
readonly StringFormat load_glyph_string_format = new StringFormat(StringFormat.GenericDefault);
|
|
||||||
readonly StringFormat load_glyph_string_format_tight = new StringFormat(StringFormat.GenericTypographic);
|
|
||||||
|
|
||||||
static readonly char[] newline_characters = new char[] { '\n', '\r' };
|
|
||||||
|
|
||||||
static readonly SizeF MaximumGraphicsClipSize;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
static GdiPlusGlyphRasterizer()
|
|
||||||
{
|
|
||||||
using (Bitmap bmp = new Bitmap(1, 1))
|
|
||||||
using (System.Drawing.Graphics gfx = System.Drawing.Graphics.FromImage(bmp))
|
|
||||||
{
|
|
||||||
MaximumGraphicsClipSize = gfx.ClipBounds.Size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public GdiPlusGlyphRasterizer()
|
|
||||||
{
|
|
||||||
measure_string_format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoClip;
|
|
||||||
measure_string_format_tight.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IGlyphRasterizer Members
|
|
||||||
|
|
||||||
#region Rasterize
|
|
||||||
|
|
||||||
public Bitmap Rasterize(Glyph glyph)
|
|
||||||
{
|
|
||||||
return Rasterize(glyph, TextQuality.Default);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Bitmap Rasterize(Glyph glyph, TextQuality quality)
|
|
||||||
{
|
|
||||||
EnsureSurfaceSize(ref glyph_surface, ref glyph_renderer, glyph.Font);
|
|
||||||
SetTextRenderingOptions(glyph_renderer, glyph.Font, quality);
|
|
||||||
|
|
||||||
RectangleF r2 = new RectangleF();
|
|
||||||
|
|
||||||
glyph_renderer.Clear(Color.Transparent);
|
|
||||||
|
|
||||||
glyph_renderer.DrawString(glyph.Character.ToString(), glyph.Font, Brushes.White, Point.Empty, //new Point(glyph_surface.Width, 0),
|
|
||||||
glyph.Font.Style == FontStyle.Italic ? load_glyph_string_format : load_glyph_string_format_tight);
|
|
||||||
|
|
||||||
r2 = FindEdges(glyph_surface, true);
|
|
||||||
|
|
||||||
//if ((default_string_format.FormatFlags & StringFormatFlags.DirectionRightToLeft) != 0)
|
|
||||||
//{
|
|
||||||
// glyph_renderer.DrawString(glyph.Character.ToString(), glyph.Font, Brushes.White, Point.Empty, //new Point(glyph_surface.Width, 0),
|
|
||||||
// load_glyph_string_format);//glyph.Font.Style == FontStyle.Italic ? load_glyph_string_format : default_string_format);
|
|
||||||
|
|
||||||
// r2 = FindEdges(glyph_surface, true);
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
// glyph_renderer.DrawString(glyph.Character.ToString(), glyph.Font, Brushes.White, Point.Empty,
|
|
||||||
// load_glyph_string_format_tight); //glyph.Font.Style == FontStyle.Italic ? load_glyph_string_format : default_string_format);
|
|
||||||
|
|
||||||
// r2 = FindEdges(glyph_surface, false);
|
|
||||||
//}
|
|
||||||
|
|
||||||
return glyph_surface.Clone(r2, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region MeasureText
|
|
||||||
|
|
||||||
public TextExtents MeasureText(ref TextBlock block)
|
|
||||||
{
|
|
||||||
return MeasureText(ref block, TextQuality.Default);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextExtents MeasureText(ref TextBlock block, TextQuality quality)
|
|
||||||
{
|
|
||||||
// First, check if we have cached this text block. Do not use block_cache.TryGetValue, to avoid thrashing
|
|
||||||
// the user's TextBlockExtents struct.
|
|
||||||
int hashcode = block.GetHashCode();
|
|
||||||
if (block_cache.ContainsKey(hashcode))
|
|
||||||
return block_cache[hashcode];
|
|
||||||
|
|
||||||
// If this block is not cached, we have to measure it and (potentially) place it in the cache.
|
|
||||||
TextExtents extents = MeasureTextExtents(ref block, quality);
|
|
||||||
|
|
||||||
if ((block.Options & TextPrinterOptions.NoCache) == 0)
|
|
||||||
block_cache.Add(hashcode, extents);
|
|
||||||
|
|
||||||
return extents;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Clear
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
block_cache.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Private Members
|
|
||||||
|
|
||||||
#region EnsureSurfaceSize
|
|
||||||
|
|
||||||
void EnsureSurfaceSize(ref Bitmap bmp, ref System.Drawing.Graphics gfx, Font font)
|
|
||||||
{
|
|
||||||
if (bmp == null || bmp.Width < 2 * font.Size || bmp.Height < 2 * font.Size)
|
|
||||||
{
|
|
||||||
if (bmp != null)
|
|
||||||
bmp.Dispose();
|
|
||||||
if (gfx != null)
|
|
||||||
gfx.Dispose();
|
|
||||||
|
|
||||||
bmp = new Bitmap((int)(2 * font.Size), (int)(2 * font.Size));
|
|
||||||
gfx = System.Drawing.Graphics.FromImage(bmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region SetRenderingOptions
|
|
||||||
|
|
||||||
// Modify rendering settings (antialiasing, grid fitting) to improve appearance.
|
|
||||||
void SetTextRenderingOptions(System.Drawing.Graphics gfx, Font font, TextQuality quality)
|
|
||||||
{
|
|
||||||
switch (quality)
|
|
||||||
{
|
|
||||||
case TextQuality.Default:
|
|
||||||
gfx.TextRenderingHint = TextRenderingHint.SystemDefault;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TextQuality.High:
|
|
||||||
gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TextQuality.Medium:
|
|
||||||
if (font.Size <= 18.0f)
|
|
||||||
gfx.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
|
||||||
else
|
|
||||||
gfx.TextRenderingHint = TextRenderingHint.AntiAlias;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TextQuality.Low:
|
|
||||||
if (font.Size <= 18.0f)
|
|
||||||
gfx.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
|
|
||||||
else
|
|
||||||
gfx.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region MeasureTextExtents
|
|
||||||
|
|
||||||
TextExtents MeasureTextExtents(ref TextBlock block, TextQuality quality)
|
|
||||||
{
|
|
||||||
// Todo: Parse layout options:
|
|
||||||
StringFormat format = block.Font.Italic ? measure_string_format : measure_string_format_tight;
|
|
||||||
//StringFormat format = measure_string_format_tight;
|
|
||||||
|
|
||||||
if (block.Direction == TextDirection.Vertical)
|
|
||||||
format.FormatFlags |= StringFormatFlags.DirectionVertical;
|
|
||||||
else
|
|
||||||
format.FormatFlags &= ~StringFormatFlags.DirectionVertical;
|
|
||||||
|
|
||||||
if (block.Direction == TextDirection.RightToLeft)
|
|
||||||
format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
|
|
||||||
else
|
|
||||||
format.FormatFlags &= ~StringFormatFlags.DirectionRightToLeft;
|
|
||||||
|
|
||||||
if (block.Alignment == TextAlignment.Near)
|
|
||||||
format.Alignment = StringAlignment.Near;
|
|
||||||
else if (block.Alignment == TextAlignment.Center)
|
|
||||||
format.Alignment = StringAlignment.Center;
|
|
||||||
else
|
|
||||||
format.Alignment = StringAlignment.Far;
|
|
||||||
|
|
||||||
TextExtents extents = text_extents_pool.Acquire();
|
|
||||||
|
|
||||||
RectangleF rect = block.Bounds;
|
|
||||||
// Work around Mono/GDI+ bug, which causes incorrect
|
|
||||||
// text wraping when block.Bounds == SizeF.Empty.
|
|
||||||
if (block.Bounds.Size == SizeF.Empty)
|
|
||||||
rect.Size = MaximumGraphicsClipSize;
|
|
||||||
|
|
||||||
SetTextRenderingOptions(graphics, block.Font, quality);
|
|
||||||
|
|
||||||
IntPtr native_graphics = GdiPlus.GetNativeGraphics(graphics);
|
|
||||||
IntPtr native_font = GdiPlus.GetNativeFont(block.Font);
|
|
||||||
IntPtr native_string_format = GdiPlus.GetNativeStringFormat(format);
|
|
||||||
|
|
||||||
float max_width = 0, max_height = 0;
|
|
||||||
|
|
||||||
// It seems that the mere presence of \n and \r characters
|
|
||||||
// is enough for Mono to botch the layout (even if these
|
|
||||||
// characters are not processed.) We'll need to find a
|
|
||||||
// different way to perform layout on Mono, probably
|
|
||||||
// through Pango.
|
|
||||||
// Todo: This workaround allocates memory.
|
|
||||||
//if (Configuration.RunningOnMono)
|
|
||||||
{
|
|
||||||
string[] lines = block.Text.Replace("\r", String.Empty).Split('\n');
|
|
||||||
foreach (string s in lines)
|
|
||||||
{
|
|
||||||
float width, height;
|
|
||||||
|
|
||||||
extents.AddRange(MeasureGlyphExtents(
|
|
||||||
ref block, s,
|
|
||||||
native_graphics, native_font, native_string_format,
|
|
||||||
ref rect, out width, out height));
|
|
||||||
|
|
||||||
if ((block.Direction & TextDirection.Vertical) == 0)
|
|
||||||
rect.Y += block.Font.Height;
|
|
||||||
else
|
|
||||||
rect.X += block.Font.Height;
|
|
||||||
|
|
||||||
if (width > max_width)
|
|
||||||
max_width = width;
|
|
||||||
if (height > max_height)
|
|
||||||
max_height = height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extents.Count > 0)
|
|
||||||
extents.BoundingBox = new RectangleF(extents[0].X, extents[0].Y, max_width, max_height);
|
|
||||||
else
|
|
||||||
extents.BoundingBox = RectangleF.Empty;
|
|
||||||
|
|
||||||
return extents;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region MeasureGlyphExtents
|
|
||||||
|
|
||||||
// Gets the bounds of each character in a line of text.
|
|
||||||
// Each line is processed in blocks of 32 characters (GdiPlus.MaxMeasurableCharacterRanges).
|
|
||||||
IEnumerable<RectangleF> MeasureGlyphExtents(
|
|
||||||
ref TextBlock block, string text,
|
|
||||||
IntPtr native_graphics, IntPtr native_font, IntPtr native_string_format,
|
|
||||||
ref RectangleF layoutRect, out float max_width, out float max_height)
|
|
||||||
{
|
|
||||||
measured_glyphs.Clear();
|
|
||||||
max_width = layoutRect.Left;
|
|
||||||
max_height = layoutRect.Top;
|
|
||||||
float last_line_width = 0, last_line_height = 0;
|
|
||||||
|
|
||||||
int current = 0;
|
|
||||||
while (current < text.Length)
|
|
||||||
{
|
|
||||||
int num_characters = (text.Length - current) > GdiPlus.MaxMeasurableCharacterRanges ?
|
|
||||||
GdiPlus.MaxMeasurableCharacterRanges :
|
|
||||||
text.Length - current;
|
|
||||||
int status = 0;
|
|
||||||
|
|
||||||
// Prepare the character ranges and region structs for the measurement.
|
|
||||||
for (int i = 0; i < num_characters; i++)
|
|
||||||
{
|
|
||||||
if (text[current + i] == '\n' || text[current + i] == '\r')
|
|
||||||
throw new NotSupportedException();
|
|
||||||
|
|
||||||
characterRanges[i] = new CharacterRange(current + i, 1);
|
|
||||||
|
|
||||||
IntPtr region;
|
|
||||||
status = GdiPlus.CreateRegion(out region);
|
|
||||||
regions[i] = region;
|
|
||||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
|
||||||
}
|
|
||||||
|
|
||||||
status = GdiPlus.SetStringFormatMeasurableCharacterRanges(native_string_format, num_characters, characterRanges);
|
|
||||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
|
||||||
|
|
||||||
status = GdiPlus.MeasureCharacterRanges(native_graphics, text, text.Length,
|
|
||||||
native_font, ref layoutRect, native_string_format, num_characters, regions);
|
|
||||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
|
||||||
|
|
||||||
// Read back the results of the measurement.
|
|
||||||
for (int i = 0; i < num_characters; i++)
|
|
||||||
{
|
|
||||||
RectangleF rect = new RectangleF();
|
|
||||||
|
|
||||||
GdiPlus.GetRegionBounds(regions[i], native_graphics, ref rect);
|
|
||||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
|
||||||
GdiPlus.DeleteRegion(regions[i]);
|
|
||||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
|
||||||
|
|
||||||
if (rect.Bottom > max_height)
|
|
||||||
max_height = rect.Bottom;
|
|
||||||
if (rect.Right > max_width)
|
|
||||||
max_width = rect.Right;
|
|
||||||
|
|
||||||
if (rect.X > last_line_width)
|
|
||||||
last_line_width = rect.X;
|
|
||||||
if (rect.Y > last_line_height)
|
|
||||||
last_line_height = rect.Y;
|
|
||||||
|
|
||||||
measured_glyphs.Add(rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
current += num_characters;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure the current height is updated, if the the current line has wrapped due to word-wraping.
|
|
||||||
// Otherwise, the next line will overlap with the current one.
|
|
||||||
if (measured_glyphs.Count > 1)
|
|
||||||
{
|
|
||||||
if ((block.Direction & TextDirection.Vertical) == 0)
|
|
||||||
{
|
|
||||||
if (layoutRect.Y < last_line_height)
|
|
||||||
layoutRect.Y = last_line_height;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (layoutRect.X < last_line_width)
|
|
||||||
layoutRect.X = last_line_width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mono's GDI+ implementation suffers from an issue where the specified layoutRect is not taken into
|
|
||||||
// account. We will try to improve the situation by moving text to the correct location on this
|
|
||||||
// error condition. This will not help word wrapping, but it is better than nothing.
|
|
||||||
// Todo: Mono 2.8 is supposed to ship with a Pango-based GDI+ text renderer, which should not
|
|
||||||
// suffer from this bug. Verify that this is the case and remove the hack.
|
|
||||||
if (Configuration.RunningOnMono && (layoutRect.X != 0 || layoutRect.Y != 0) && measured_glyphs.Count > 0)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < measured_glyphs.Count; i++)
|
|
||||||
{
|
|
||||||
RectangleF rect = measured_glyphs[i];
|
|
||||||
rect.X += layoutRect.X;
|
|
||||||
rect.Y += layoutRect.Y;
|
|
||||||
measured_glyphs[i] = rect;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return measured_glyphs;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region FindEdges
|
|
||||||
|
|
||||||
#pragma warning disable 0649
|
|
||||||
|
|
||||||
struct Pixel { public byte B, G, R, A; }
|
|
||||||
|
|
||||||
#pragma warning restore 0649
|
|
||||||
|
|
||||||
// Note: The bool parameter is not used at this point.
|
|
||||||
// We might need it if we ever load true rightToLeft glyphs.
|
|
||||||
Rectangle FindEdges(Bitmap bmp, bool rightToLeft)
|
|
||||||
{
|
|
||||||
BitmapData data = bmp.LockBits(
|
|
||||||
new Rectangle(0, 0, bmp.Width, bmp.Height),
|
|
||||||
ImageLockMode.ReadOnly,
|
|
||||||
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
|
||||||
|
|
||||||
//Rectangle rect = rightToLeft ?
|
|
||||||
// Rectangle.FromLTRB(FindLeftEdge(bmp, data.Scan0), 0, bmp.Width - 1, FindBottomEdge(bmp, data.Scan0)) :
|
|
||||||
// Rectangle.FromLTRB(0, 0, FindRightEdge(bmp, data.Scan0), FindBottomEdge(bmp, data.Scan0));
|
|
||||||
|
|
||||||
Rectangle rect =
|
|
||||||
Rectangle.FromLTRB(0, 0, FindRightEdge(bmp, data.Scan0), FindBottomEdge(bmp, data.Scan0));
|
|
||||||
//Rectangle.FromLTRB(FindLeftEdge(bmp, data.Scan0), 0, FindRightEdge(bmp, data.Scan0), FindBottomEdge(bmp, data.Scan0));
|
|
||||||
|
|
||||||
bmp.UnlockBits(data);
|
|
||||||
|
|
||||||
return rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Find[Left|Right|Top|Bottom]Edge
|
|
||||||
|
|
||||||
// Iterates through the bmp, and returns the first row or line that contains a non-transparent pixels.
|
|
||||||
|
|
||||||
int FindLeftEdge(Bitmap bmp, IntPtr ptr)
|
|
||||||
{
|
|
||||||
for (int x = 0; x < bmp.Width; x++)
|
|
||||||
for (int y = 0; y < bmp.Height; y++)
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
if (((Pixel*)(ptr) + y * bmp.Width + x)->A != 0)
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
return bmp.Width - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FindRightEdge(Bitmap bmp, IntPtr ptr)
|
|
||||||
{
|
|
||||||
for (int x = bmp.Width - 1; x >= 0; x--)
|
|
||||||
for (int y = 0; y < bmp.Height; y++)
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
if (((Pixel*)(ptr) + y * bmp.Width + x)->A != 0)
|
|
||||||
return x + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FindTopEdge(Bitmap bmp, IntPtr ptr)
|
|
||||||
{
|
|
||||||
for (int y = 0; y < bmp.Height; y++)
|
|
||||||
for (int x = 0; x < bmp.Width; x++)
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
if (((Pixel*)(ptr) + y * bmp.Width + x)->A != 0)
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
return bmp.Height - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FindBottomEdge(Bitmap bmp, IntPtr ptr)
|
|
||||||
{
|
|
||||||
for (int y = bmp.Height - 1; y >= 0; y--)
|
|
||||||
for (int x = 0; x < bmp.Width; x++)
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
if (((Pixel*)(ptr) + y * bmp.Width + x)->A != 0)
|
|
||||||
return y + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,153 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
struct Glyph : IEquatable<Glyph>
|
|
||||||
{
|
|
||||||
char character;
|
|
||||||
Font font;
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new Glyph that represents the given character and Font.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="c">The character to represent.</param>
|
|
||||||
/// <param name="font">The Font of the character.</param>
|
|
||||||
public Glyph(char c, Font font)
|
|
||||||
{
|
|
||||||
if (font == null)
|
|
||||||
throw new ArgumentNullException("font");
|
|
||||||
character = c;
|
|
||||||
this.font = font;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Methods
|
|
||||||
|
|
||||||
#region public char Character
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the character represented by this Glyph.
|
|
||||||
/// </summary>
|
|
||||||
public char Character
|
|
||||||
{
|
|
||||||
get { return character; }
|
|
||||||
private set { character = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public Font Font
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the Font of this Glyph.
|
|
||||||
/// </summary>
|
|
||||||
public Font Font
|
|
||||||
{
|
|
||||||
get { return font; }
|
|
||||||
private set
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
throw new ArgumentNullException("Font", "Glyph font cannot be null");
|
|
||||||
|
|
||||||
font = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public bool IsWhiteSpace
|
|
||||||
|
|
||||||
public bool IsWhiteSpace
|
|
||||||
{
|
|
||||||
get { return Char.IsWhiteSpace(Character); }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override bool Equals(object obj)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks whether the given object is equal (memberwise) to the current Glyph.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="obj">The obj to check.</param>
|
|
||||||
/// <returns>True, if the object is identical to the current Glyph.</returns>
|
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
|
||||||
if (obj is Glyph)
|
|
||||||
return this.Equals((Glyph)obj);
|
|
||||||
return base.Equals(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override string ToString()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Describes this Glyph object.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Returns a System.String describing this Glyph.</returns>
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return String.Format("'{0}', {1} {2}, {3} {4}", Character, Font.Name, font.Style, font.Size, font.Unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override int GetHashCode()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculates the hashcode for this Glyph.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>A System.Int32 containing a hashcode that uniquely identifies this Glyph.</returns>
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return character.GetHashCode() ^ font.GetHashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IEquatable<Glyph> Members
|
|
||||||
|
|
||||||
public bool Equals(Glyph other)
|
|
||||||
{
|
|
||||||
return Character == other.Character && Font == other.Font;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,156 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
[Obsolete]
|
|
||||||
abstract class GlyphCache : IGlyphCache
|
|
||||||
{
|
|
||||||
#region IGlyphCache Members
|
|
||||||
|
|
||||||
public abstract void Add(Glyph glyph, IGlyphRasterizer rasterizer, TextQuality quality);
|
|
||||||
|
|
||||||
public abstract bool Contains(Glyph glyph);
|
|
||||||
|
|
||||||
public abstract CachedGlyphInfo this[Glyph glyph] { get; }
|
|
||||||
|
|
||||||
public abstract void Clear();
|
|
||||||
|
|
||||||
public abstract void Dispose();
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
[Obsolete]
|
|
||||||
sealed class GlyphCache<T> : GlyphCache where T : Texture2D
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
List<GlyphSheet<T>> sheets = new List<GlyphSheet<T>>();
|
|
||||||
|
|
||||||
Dictionary<Glyph, CachedGlyphInfo> cached_glyphs = new Dictionary<Glyph, CachedGlyphInfo>();
|
|
||||||
|
|
||||||
bool disposed;
|
|
||||||
|
|
||||||
const int SheetWidth = 512, SheetHeight = 512;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
public GlyphCache()
|
|
||||||
{
|
|
||||||
sheets.Add(new GlyphSheet<T>(SheetWidth, SheetHeight));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IGlyphCache Members
|
|
||||||
|
|
||||||
public override void Add(Glyph glyph, IGlyphRasterizer rasterizer, TextQuality quality)
|
|
||||||
{
|
|
||||||
if (rasterizer == null)
|
|
||||||
throw new ArgumentNullException("rasterizer");
|
|
||||||
|
|
||||||
bool inserted = false;
|
|
||||||
|
|
||||||
using (Bitmap bmp = rasterizer.Rasterize(glyph, quality))
|
|
||||||
{
|
|
||||||
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
|
|
||||||
foreach (GlyphSheet<T> sheet in sheets)
|
|
||||||
{
|
|
||||||
inserted = InsertGlyph(glyph, bmp, rect, sheet);
|
|
||||||
if (inserted)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!inserted)
|
|
||||||
{
|
|
||||||
GlyphSheet<T> sheet = new GlyphSheet<T>(SheetWidth, SheetHeight);
|
|
||||||
sheets.Add(sheet);
|
|
||||||
InsertGlyph(glyph, bmp, rect, sheet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool Contains(Glyph glyph)
|
|
||||||
{
|
|
||||||
return cached_glyphs.ContainsKey(glyph);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override CachedGlyphInfo this[Glyph glyph]
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return cached_glyphs[glyph];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public override void Clear()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < sheets.Count; i++)
|
|
||||||
sheets[i].Dispose();
|
|
||||||
|
|
||||||
sheets.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Private Members
|
|
||||||
|
|
||||||
// Asks the packer for an empty space and writes the glyph there.
|
|
||||||
bool InsertGlyph(Glyph glyph, Bitmap bmp, Rectangle source, GlyphSheet<T> sheet)
|
|
||||||
{
|
|
||||||
Rectangle target = new Rectangle();
|
|
||||||
if (!sheet.Packer.TryAdd(source, out target))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
sheet.Texture.WriteRegion(source, target, 0, bmp);
|
|
||||||
cached_glyphs.Add(glyph, new CachedGlyphInfo(sheet.Texture, target));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
public override void Dispose()
|
|
||||||
{
|
|
||||||
if (!disposed)
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
disposed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,107 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
class GlyphEnumerator : IEnumerator<Glyph>
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
string text;
|
|
||||||
Font font;
|
|
||||||
|
|
||||||
IEnumerator<char> implementation;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
public GlyphEnumerator(string text, Font font)
|
|
||||||
{
|
|
||||||
if (text == null)
|
|
||||||
throw new ArgumentNullException("text");
|
|
||||||
|
|
||||||
if (font == null)
|
|
||||||
throw new ArgumentNullException("font");
|
|
||||||
|
|
||||||
this.text = text;
|
|
||||||
this.font = font;
|
|
||||||
|
|
||||||
implementation = text.GetEnumerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IEnumerator<Glyph> Members
|
|
||||||
|
|
||||||
public Glyph Current
|
|
||||||
{
|
|
||||||
get { return new Glyph(implementation.Current, font); }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
implementation.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IEnumerator Members
|
|
||||||
|
|
||||||
object System.Collections.IEnumerator.Current
|
|
||||||
{
|
|
||||||
get { return new Glyph(implementation.Current, font); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool MoveNext()
|
|
||||||
{
|
|
||||||
bool status;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
status = implementation.MoveNext();
|
|
||||||
} while (status && (implementation.Current == '\n' || implementation.Current == '\r'));
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
implementation.Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,270 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
class GlyphPacker
|
|
||||||
{
|
|
||||||
Node root;
|
|
||||||
|
|
||||||
#region --- Constructors ---
|
|
||||||
|
|
||||||
public GlyphPacker(int width, int height)
|
|
||||||
{
|
|
||||||
if (width <= 0)
|
|
||||||
throw new ArgumentOutOfRangeException("width", width, "Must be greater than zero.");
|
|
||||||
if (height <= 0)
|
|
||||||
throw new ArgumentOutOfRangeException("height", height, "Must be greater than zero.");
|
|
||||||
|
|
||||||
root = new Node();
|
|
||||||
root.Rectangle = new Rectangle(0, 0, width, width);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- Public Methods ---
|
|
||||||
|
|
||||||
#region public bool TryAdd(Rectangle boundingBox)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds boundingBox to the GlyphPacker.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="boundingBox">The bounding box of the item to pack.</param>
|
|
||||||
/// <param name="packedRectangle">The System.Drawing.Rectangle that contains the position of the packed item.</param>
|
|
||||||
/// <returns>True, if the item was successfully packed; false if the item is too big for this packer..</returns>
|
|
||||||
/// <exception cref="InvalidOperationException">Occurs if the item is larger than the available TexturePacker area</exception>
|
|
||||||
/// <exception cref="TexturePackerFullException">Occurs if the item cannot fit in the remaining packer space.</exception>
|
|
||||||
public bool TryAdd(Rectangle boundingBox, out Rectangle packedRectangle)
|
|
||||||
{
|
|
||||||
if (!root.Rectangle.Contains(boundingBox))
|
|
||||||
{
|
|
||||||
packedRectangle = new Rectangle();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increase size so that the glyphs do not touch each other (to avoid rendering artifacts).
|
|
||||||
boundingBox.Width += 2;
|
|
||||||
boundingBox.Height += 2;
|
|
||||||
|
|
||||||
Node node = root.Insert(boundingBox);
|
|
||||||
|
|
||||||
// Tree is full and insertion failed:
|
|
||||||
if (node == null)
|
|
||||||
{
|
|
||||||
packedRectangle = new Rectangle();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
packedRectangle = new Rectangle(node.Rectangle.X, node.Rectangle.Y, node.Rectangle.Width - 2, node.Rectangle.Height - 2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public Rectangle TryAdd(RectangleF boundingBox)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds boundingBox to the GlyphPacker.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="boundingBox">The bounding box of the item to pack.</param>
|
|
||||||
/// <param name="packedRectangle">The System.Drawing.RectangleF that contains the position of the packed item.</param>
|
|
||||||
/// <returns>True, if the item was successfully packed; false if the item is too big for this packer..</returns>
|
|
||||||
/// <exception cref="InvalidOperationException">Occurs if the item is larger than the available TexturePacker area</exception>
|
|
||||||
/// <exception cref="TexturePackerFullException">Occurs if the item cannot fit in the remaining packer space.</exception>
|
|
||||||
public bool TryAdd(RectangleF boundingBox, out RectangleF packedRectangle)
|
|
||||||
{
|
|
||||||
Rectangle bbox = new Rectangle(
|
|
||||||
(int)boundingBox.X, (int)boundingBox.Y,
|
|
||||||
(int)(boundingBox.Width + 0.5f), (int)(boundingBox.Height + 0.5f));
|
|
||||||
|
|
||||||
return TryAdd(bbox, out packedRectangle);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public Rectangle Add(Rectangle boundingBox)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds boundingBox to the GlyphPacker.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="boundingBox">The bounding box of the item to pack.</param>
|
|
||||||
/// <returns>A System.Drawing.Rectangle containing the coordinates of the packed item.</returns>
|
|
||||||
/// <exception cref="InvalidOperationException">Occurs if the item is larger than the available TexturePacker area</exception>
|
|
||||||
/// <exception cref="TexturePackerFullException">Occurs if the item cannot fit in the remaining packer space.</exception>
|
|
||||||
public Rectangle Add(Rectangle boundingBox)
|
|
||||||
{
|
|
||||||
if (!TryAdd(boundingBox, out boundingBox))
|
|
||||||
throw new TexturePackerFullException();
|
|
||||||
|
|
||||||
return boundingBox;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public Rectangle Add(RectangleF boundingBox)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Rounds boundingBox to the largest integer and adds the resulting Rectangle to the GlyphPacker.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="boundingBox">The bounding box of the item to pack.</param>
|
|
||||||
/// <returns>A System.Drawing.Rectangle containing the coordinates of the packed item.</returns>
|
|
||||||
/// <exception cref="InvalidOperationException">Occurs if the item is larger than the available TexturePacker area</exception>
|
|
||||||
/// <exception cref="ArgumentException">Occurs if the item already exists in the TexturePacker.</exception>
|
|
||||||
public Rectangle Add(RectangleF boundingBox)
|
|
||||||
{
|
|
||||||
Rectangle bbox = new Rectangle(
|
|
||||||
(int)boundingBox.X, (int)boundingBox.Y,
|
|
||||||
(int)(boundingBox.Width + 0.5f), (int)(boundingBox.Height + 0.5f));
|
|
||||||
|
|
||||||
return Add(bbox);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public void Clear()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Discards all packed items.
|
|
||||||
/// </summary>
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
root.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Node
|
|
||||||
|
|
||||||
class Node
|
|
||||||
{
|
|
||||||
public Node()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Node left, right;
|
|
||||||
Rectangle rect;
|
|
||||||
bool occupied;
|
|
||||||
|
|
||||||
public Rectangle Rectangle { get { return rect; } set { rect = value; } }
|
|
||||||
public Node Left { get { return left; } set { left = value; } }
|
|
||||||
public Node Right { get { return right; } set { right = value; } }
|
|
||||||
|
|
||||||
#region --- Constructor ---
|
|
||||||
|
|
||||||
public bool Leaf
|
|
||||||
{
|
|
||||||
get { return left == null && right == null; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Node Insert(Rectangle bbox)
|
|
||||||
|
|
||||||
public Node Insert( Rectangle bbox)
|
|
||||||
{
|
|
||||||
if (!this.Leaf)
|
|
||||||
{
|
|
||||||
// Recurse towards left child, and if that fails, towards the right.
|
|
||||||
Node new_node = left.Insert(bbox);
|
|
||||||
return new_node ?? right.Insert(bbox);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// We have recursed to a leaf.
|
|
||||||
|
|
||||||
// If it is not empty go back.
|
|
||||||
if (occupied)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
// If this leaf is too small go back.
|
|
||||||
if (rect.Width < bbox.Width || rect.Height < bbox.Height)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
// If this leaf is the right size, insert here.
|
|
||||||
if (rect.Width == bbox.Width && rect.Height == bbox.Height)
|
|
||||||
{
|
|
||||||
occupied = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This leaf is too large, split it up. We'll decide which way to split
|
|
||||||
// by checking the width and height difference between this rectangle and
|
|
||||||
// out item's bounding box. If the width difference is larger, we'll split
|
|
||||||
// horizontaly, else verticaly.
|
|
||||||
left = new Node();
|
|
||||||
right = new Node();
|
|
||||||
|
|
||||||
int dw = this.rect.Width - bbox.Width + 1;
|
|
||||||
int dh = this.rect.Height - bbox.Height + 1;
|
|
||||||
|
|
||||||
if (dw > dh)
|
|
||||||
{
|
|
||||||
left.rect = new Rectangle(rect.Left, rect.Top, bbox.Width, rect.Height);
|
|
||||||
right.rect = new Rectangle(rect.Left + bbox.Width, rect.Top, rect.Width - bbox.Width, rect.Height);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
left.rect = new Rectangle(rect.Left, rect.Top, rect.Width, bbox.Height);
|
|
||||||
right.rect = new Rectangle(rect.Left, rect.Top + bbox.Height, rect.Width, rect.Height - bbox.Height);
|
|
||||||
}
|
|
||||||
|
|
||||||
return left.Insert(bbox);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public void Clear()
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
if (left != null)
|
|
||||||
left.Clear();
|
|
||||||
if (right != null)
|
|
||||||
right.Clear();
|
|
||||||
|
|
||||||
left = right = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
class TexturePackerFullException : Exception
|
|
||||||
{
|
|
||||||
public TexturePackerFullException() : base("There is not enough space to add this item. Consider calling the Clear() method.") { }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,86 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
[Obsolete]
|
|
||||||
class GlyphSheet<T> : IDisposable where T : Texture2D
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
readonly T texture;
|
|
||||||
readonly GlyphPacker packer;
|
|
||||||
|
|
||||||
bool disposed;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
public GlyphSheet(int width, int height)
|
|
||||||
{
|
|
||||||
texture = (T)typeof(T).GetConstructor(new Type[] { typeof(int), typeof(int) }).Invoke(new object[] { width, height });
|
|
||||||
//texture.MagnificationFilter = TextureMagFilter.Nearest;
|
|
||||||
//texture.MinificationFilter = TextureMinFilter.Nearest;
|
|
||||||
packer = new GlyphPacker(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Members
|
|
||||||
|
|
||||||
public T Texture
|
|
||||||
{
|
|
||||||
get { return texture; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public GlyphPacker Packer
|
|
||||||
{
|
|
||||||
get { return packer; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
if (!disposed)
|
|
||||||
{
|
|
||||||
texture.Dispose();
|
|
||||||
disposed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
[Obsolete]
|
|
||||||
interface IGlyphCache : IDisposable
|
|
||||||
{
|
|
||||||
void Add(Glyph glyph, IGlyphRasterizer rasterizer, TextQuality quality);
|
|
||||||
bool Contains(Glyph glyph);
|
|
||||||
CachedGlyphInfo this[Glyph glyph] { get; }
|
|
||||||
void Clear();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
|
|
||||||
using OpenTK.Graphics.Text;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
interface IGlyphRasterizer
|
|
||||||
{
|
|
||||||
Bitmap Rasterize(Glyph glyph);
|
|
||||||
Bitmap Rasterize(Glyph glyph, TextQuality quality);
|
|
||||||
TextExtents MeasureText(ref TextBlock block);
|
|
||||||
TextExtents MeasureText(ref TextBlock block, TextQuality quality);
|
|
||||||
void Clear();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
interface ITextOutputProvider : IDisposable
|
|
||||||
{
|
|
||||||
void Print(ref TextBlock block, Color color, IGlyphRasterizer rasterizer);
|
|
||||||
void Clear();
|
|
||||||
void Begin();
|
|
||||||
void End();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
class PoolableTextExtents : TextExtents, IPoolable<PoolableTextExtents>
|
|
||||||
{
|
|
||||||
ObjectPool<PoolableTextExtents> owner;
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
public PoolableTextExtents()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IPoolable<PoolableTextExtents> Members
|
|
||||||
|
|
||||||
ObjectPool<PoolableTextExtents> IPoolable<PoolableTextExtents>.Owner
|
|
||||||
{
|
|
||||||
get { return owner; }
|
|
||||||
set { owner = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IPoolable Members
|
|
||||||
|
|
||||||
void IPoolable.OnAcquire()
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void IPoolable.OnRelease()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,124 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
|
||||||
{
|
|
||||||
// Uniquely identifies a block of text. This structure can be used to identify text blocks for caching.
|
|
||||||
struct TextBlock : IEquatable<TextBlock>, IEnumerable<Glyph>
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
public readonly string Text;
|
|
||||||
|
|
||||||
public readonly Font Font;
|
|
||||||
|
|
||||||
public readonly RectangleF Bounds;
|
|
||||||
|
|
||||||
public readonly TextPrinterOptions Options;
|
|
||||||
|
|
||||||
public readonly TextAlignment Alignment;
|
|
||||||
|
|
||||||
public readonly TextDirection Direction;
|
|
||||||
|
|
||||||
public readonly int UsageCount;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
public TextBlock(string text, Font font, RectangleF bounds, TextPrinterOptions options, TextAlignment alignment, TextDirection direction)
|
|
||||||
{
|
|
||||||
Text = text;
|
|
||||||
Font = font;
|
|
||||||
Bounds = bounds;
|
|
||||||
Options = options;
|
|
||||||
Alignment = alignment;
|
|
||||||
Direction = direction;
|
|
||||||
UsageCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Members
|
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
|
||||||
if (!(obj is TextBlock))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return Equals((TextBlock)obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return Text.GetHashCode() ^ Font.GetHashCode() ^ Bounds.GetHashCode() ^ Options.GetHashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Glyph this[int i]
|
|
||||||
{
|
|
||||||
get { return new Glyph(Text[i], Font); }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IEquatable<TextBlock> Members
|
|
||||||
|
|
||||||
public bool Equals(TextBlock other)
|
|
||||||
{
|
|
||||||
return
|
|
||||||
Text == other.Text &&
|
|
||||||
Font == other.Font &&
|
|
||||||
Bounds == other.Bounds &&
|
|
||||||
Options == other.Options;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IEnumerable<Glyph> Members
|
|
||||||
|
|
||||||
public IEnumerator<Glyph> GetEnumerator()
|
|
||||||
{
|
|
||||||
return new GlyphEnumerator(Text, Font);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IEnumerable Members
|
|
||||||
|
|
||||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
|
||||||
{
|
|
||||||
return new GlyphEnumerator(Text, Font);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Graphics.Text
|
|
||||||
{
|
|
||||||
class TextBlockComparer : IComparer<TextBlock>
|
|
||||||
{
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
public TextBlockComparer() { }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IComparer<TextBlock> Members
|
|
||||||
|
|
||||||
public int Compare(TextBlock x, TextBlock y)
|
|
||||||
{
|
|
||||||
return x.UsageCount.CompareTo(y.UsageCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Defines available alignments for text.
|
|
||||||
/// </summary>
|
|
||||||
public enum TextAlignment
|
|
||||||
{
|
|
||||||
/// <summary>The text is aligned to the near side (left for left-to-right text and right for right-to-left text).</summary>
|
|
||||||
Near = 0,
|
|
||||||
/// <summary>The text is aligned to the center.</summary>
|
|
||||||
Center,
|
|
||||||
/// <summary>The text is aligned to the far side (right for left-to-right text and left for right-to-left text).</summary>
|
|
||||||
Far
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Defines available directions for text layout.
|
|
||||||
/// </summary>
|
|
||||||
public enum TextDirection
|
|
||||||
{
|
|
||||||
/// <summary>The text is layed out from left to right.</summary>
|
|
||||||
LeftToRight,
|
|
||||||
/// <summary>The text is layed out from right to left.</summary>
|
|
||||||
RightToLeft,
|
|
||||||
/// <summary>The text is layed out vertically.</summary>
|
|
||||||
Vertical
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,136 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Holds the results of a text measurement.
|
|
||||||
/// </summary>
|
|
||||||
public class TextExtents : IDisposable
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
protected RectangleF text_extents;
|
|
||||||
protected List<RectangleF> glyph_extents = new List<RectangleF>();
|
|
||||||
|
|
||||||
public static readonly TextExtents Empty = new TextExtents();
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
internal TextExtents()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Members
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the bounding box of the measured text.
|
|
||||||
/// </summary>
|
|
||||||
public RectangleF BoundingBox
|
|
||||||
{
|
|
||||||
get { return text_extents; }
|
|
||||||
internal set { text_extents = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the extents of each glyph in the measured text.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="i">The index of the glyph.</param>
|
|
||||||
/// <returns>The extents of the specified glyph.</returns>
|
|
||||||
public RectangleF this[int i]
|
|
||||||
{
|
|
||||||
get { return glyph_extents[i]; }
|
|
||||||
internal set { glyph_extents[i] = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the extents of each glyph in the measured text.
|
|
||||||
/// </summary>
|
|
||||||
public IEnumerable<RectangleF> GlyphExtents
|
|
||||||
{
|
|
||||||
get { return (IEnumerable<RectangleF>)glyph_extents; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the number of the measured glyphs.
|
|
||||||
/// </summary>
|
|
||||||
public int Count
|
|
||||||
{
|
|
||||||
get { return glyph_extents.Count; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Internal Members
|
|
||||||
|
|
||||||
internal void Add(RectangleF glyphExtent)
|
|
||||||
{
|
|
||||||
glyph_extents.Add(glyphExtent);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void AddRange(IEnumerable<RectangleF> glyphExtents)
|
|
||||||
{
|
|
||||||
glyph_extents.AddRange(glyphExtents);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void Clear()
|
|
||||||
{
|
|
||||||
BoundingBox = RectangleF.Empty;
|
|
||||||
glyph_extents.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal TextExtents Clone()
|
|
||||||
{
|
|
||||||
TextExtents extents = new TextExtents();
|
|
||||||
extents.glyph_extents.AddRange(GlyphExtents);
|
|
||||||
extents.BoundingBox = BoundingBox;
|
|
||||||
return extents;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Frees the resources consumed by this TextExtents instance.
|
|
||||||
/// </summary>
|
|
||||||
public virtual void Dispose()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,339 +0,0 @@
|
||||||
#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 details.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
using OpenTK.Graphics;
|
|
||||||
using OpenTK.Graphics.Text;
|
|
||||||
using OpenTK.Platform;
|
|
||||||
|
|
||||||
namespace OpenTK.Fonts { }
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Provides methods to perform layout and print hardware accelerated text.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete]
|
|
||||||
public sealed class TextPrinter : ITextPrinter
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
IGlyphRasterizer glyph_rasterizer;
|
|
||||||
ITextOutputProvider text_output;
|
|
||||||
TextQuality text_quality;
|
|
||||||
|
|
||||||
bool disposed;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new TextPrinter instance.
|
|
||||||
/// </summary>
|
|
||||||
public TextPrinter()
|
|
||||||
: this(null, null, TextQuality.Default) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new TextPrinter instance with the specified TextQuality level.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="quality">The desired TextQuality of this TextPrinter.</param>
|
|
||||||
public TextPrinter(TextQuality quality)
|
|
||||||
: this(null, null, quality) { }
|
|
||||||
|
|
||||||
TextPrinter(IGlyphRasterizer rasterizer, ITextOutputProvider output, TextQuality quality)
|
|
||||||
{
|
|
||||||
glyph_rasterizer = rasterizer;
|
|
||||||
text_output = output;
|
|
||||||
text_quality = quality;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region ITextPrinter Members
|
|
||||||
|
|
||||||
#region Print
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prints text using the specified color and layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to print.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
|
||||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
|
||||||
public void Print(string text, Font font, Color color)
|
|
||||||
{
|
|
||||||
Print(text, font, color, RectangleF.Empty, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prints text using the specified color and layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to print.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
|
||||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
public void Print(string text, Font font, Color color, RectangleF rect)
|
|
||||||
{
|
|
||||||
Print(text, font, color, rect, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prints text using the specified color and layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to print.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
|
||||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
|
|
||||||
public void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options)
|
|
||||||
{
|
|
||||||
Print(text, font, color, rect, options, TextAlignment.Near, TextDirection.LeftToRight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prints text using the specified color and layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to print.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
|
||||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
|
|
||||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to print text.</param>
|
|
||||||
public void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment)
|
|
||||||
{
|
|
||||||
Print(text, font, color, rect, options, alignment, TextDirection.LeftToRight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prints text using the specified color and layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to print.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
|
||||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
|
|
||||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to print text.</param>
|
|
||||||
/// <param name="direction">The OpenTK.Graphics.TextDirection that will be used to print text.</param>
|
|
||||||
public void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction)
|
|
||||||
{
|
|
||||||
if (disposed)
|
|
||||||
throw new ObjectDisposedException(this.GetType().ToString());
|
|
||||||
|
|
||||||
if (!ValidateParameters(text, font, rect))
|
|
||||||
return;
|
|
||||||
|
|
||||||
TextBlock block = new TextBlock(text, font, rect, options, alignment, direction);
|
|
||||||
TextOutput.Print(ref block, color, Rasterizer);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Measure
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Measures text using the specified layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to measure.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
|
||||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
|
||||||
public TextExtents Measure(string text, Font font)
|
|
||||||
{
|
|
||||||
return Measure(text, font, RectangleF.Empty, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Measures text using the specified layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to measure.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
|
||||||
public TextExtents Measure(string text, Font font, RectangleF rect)
|
|
||||||
{
|
|
||||||
return Measure(text, font, rect, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Measures text using the specified layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to measure.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
|
|
||||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
|
||||||
public TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options)
|
|
||||||
{
|
|
||||||
return Measure(text, font, rect, options, TextAlignment.Near, TextDirection.LeftToRight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Measures text using the specified layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to measure.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
|
|
||||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to measure text.</param>
|
|
||||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
|
||||||
public TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment)
|
|
||||||
{
|
|
||||||
return Measure(text, font, rect, options, alignment, TextDirection.LeftToRight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Measures text using the specified layout options.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The System.String to measure.</param>
|
|
||||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
|
||||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
|
||||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
|
|
||||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to measure text.</param>
|
|
||||||
/// <param name="direction">The OpenTK.Graphics.TextDirection that will be used to measure text.</param>
|
|
||||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
|
||||||
public TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction)
|
|
||||||
{
|
|
||||||
if (disposed)
|
|
||||||
throw new ObjectDisposedException(this.GetType().ToString());
|
|
||||||
|
|
||||||
if (!ValidateParameters(text, font, rect))
|
|
||||||
return TextExtents.Empty;
|
|
||||||
|
|
||||||
TextBlock block = new TextBlock(text, font, rect, options, alignment, direction);
|
|
||||||
return Rasterizer.MeasureText(ref block);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Clear
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
if (disposed)
|
|
||||||
throw new ObjectDisposedException(this.GetType().ToString());
|
|
||||||
|
|
||||||
TextOutput.Clear();
|
|
||||||
Rasterizer.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Begin
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets up a resolution-dependent orthographic projection.
|
|
||||||
/// </summary>
|
|
||||||
public void Begin()
|
|
||||||
{
|
|
||||||
TextOutput.Begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Begin
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Restores the projection and modelview matrices to their previous state.
|
|
||||||
/// </summary>
|
|
||||||
public void End()
|
|
||||||
{
|
|
||||||
TextOutput.End();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Obsolete
|
|
||||||
|
|
||||||
[Obsolete("Use TextPrinter.Print instead")]
|
|
||||||
public void Draw(TextHandle handle)
|
|
||||||
{
|
|
||||||
Print(handle.Text, handle.GdiPFont, Color.White);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Obsolete("Use TextPrinter.Print instead")]
|
|
||||||
public void Draw(string text, TextureFont font)
|
|
||||||
{
|
|
||||||
Print(text, font.font, Color.White);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Obsolete("Use TextPrinter.Print instead")]
|
|
||||||
public void Prepare(string text, TextureFont font, out TextHandle handle)
|
|
||||||
{
|
|
||||||
handle = new TextHandle(text, font.font);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Private Members
|
|
||||||
|
|
||||||
IGlyphRasterizer Rasterizer
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (glyph_rasterizer == null)
|
|
||||||
glyph_rasterizer = new GdiPlusGlyphRasterizer();
|
|
||||||
|
|
||||||
return glyph_rasterizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ITextOutputProvider TextOutput
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (text_output == null)
|
|
||||||
text_output = GL1TextOutputProvider.Create(text_quality);
|
|
||||||
|
|
||||||
return text_output;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Static Members
|
|
||||||
|
|
||||||
static bool ValidateParameters(string text, Font font, RectangleF rect)
|
|
||||||
{
|
|
||||||
if (String.IsNullOrEmpty(text))
|
|
||||||
return false;
|
|
||||||
if (font == null)
|
|
||||||
throw new ArgumentNullException("font");
|
|
||||||
if (rect.Width < 0 || rect.Height < 0)
|
|
||||||
throw new ArgumentOutOfRangeException("rect");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Frees the resources consumed by this TextPrinter object.
|
|
||||||
/// </summary>
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
if (!disposed)
|
|
||||||
{
|
|
||||||
TextOutput.Dispose();
|
|
||||||
disposed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Defines available options for the TextPrinter.
|
|
||||||
/// </summary>
|
|
||||||
[Flags]
|
|
||||||
public enum TextPrinterOptions
|
|
||||||
{
|
|
||||||
/// <summary>The TextPrinter will use default printing options.</summary>
|
|
||||||
Default = 0x0000,
|
|
||||||
/// <summary>The TextPrinter will not cache text blocks as they are measured or printed.</summary>
|
|
||||||
NoCache = 0x0001,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Defines available quality levels for text printing.
|
|
||||||
/// </summary>
|
|
||||||
public enum TextQuality
|
|
||||||
{
|
|
||||||
/// <summary>Use the default quality, as specified by the operating system.</summary>
|
|
||||||
Default = 0,
|
|
||||||
/// <summary>Use fast, low quality text (typically non-antialiased) .</summary>
|
|
||||||
Low,
|
|
||||||
/// <summary>Use medium quality text (typically grayscale antialiased).</summary>
|
|
||||||
Medium,
|
|
||||||
/// <summary>Use slow, high quality text (typically subpixel antialiased).</summary>
|
|
||||||
High
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,321 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
using System.Drawing.Imaging;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
[Obsolete]
|
|
||||||
abstract class Texture2D : IGraphicsResource, IEquatable<Texture2D>
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
IGraphicsContext context;
|
|
||||||
int id;
|
|
||||||
int width, height;
|
|
||||||
bool disposed;
|
|
||||||
|
|
||||||
TextureMagFilter mag_filter = TextureMagFilter.Linear;
|
|
||||||
TextureMinFilter min_filter = TextureMinFilter.Linear;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
public Texture2D(int width, int height)
|
|
||||||
{
|
|
||||||
if (width <= 0)
|
|
||||||
throw new ArgumentOutOfRangeException("width");
|
|
||||||
|
|
||||||
if (height <= 0)
|
|
||||||
throw new ArgumentOutOfRangeException("height");
|
|
||||||
|
|
||||||
Width = width;
|
|
||||||
Height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Members
|
|
||||||
|
|
||||||
#region public int Width
|
|
||||||
|
|
||||||
/// <summary>Gets the width of the texture.</summary>
|
|
||||||
public int Width { get { return width; } private set { width = value; } }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public int Height
|
|
||||||
|
|
||||||
/// <summary>Gets the height of the texture.</summary>
|
|
||||||
public int Height { get { return height; } private set { height = value; } }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region MagnificationFilter
|
|
||||||
|
|
||||||
public TextureMagFilter MagnificationFilter
|
|
||||||
{
|
|
||||||
get { return mag_filter; }
|
|
||||||
set { mag_filter = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region MinificationFilter
|
|
||||||
|
|
||||||
public TextureMinFilter MinificationFilter
|
|
||||||
{
|
|
||||||
get { return min_filter; }
|
|
||||||
set { min_filter = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Bind
|
|
||||||
|
|
||||||
public void Bind()
|
|
||||||
{
|
|
||||||
GL.BindTexture(TextureTarget.Texture2D, (this as IGraphicsResource).Id);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region WriteRegion
|
|
||||||
|
|
||||||
public void WriteRegion(Rectangle source, Rectangle target, int mipLevel, Bitmap bitmap)
|
|
||||||
{
|
|
||||||
if (bitmap == null)
|
|
||||||
throw new ArgumentNullException("data");
|
|
||||||
|
|
||||||
GraphicsUnit unit = GraphicsUnit.Pixel;
|
|
||||||
if (!bitmap.GetBounds(ref unit).Contains(source))
|
|
||||||
throw new InvalidOperationException("The source Rectangle is larger than the Bitmap.");
|
|
||||||
|
|
||||||
if (mipLevel < 0)
|
|
||||||
throw new ArgumentOutOfRangeException("mipLevel");
|
|
||||||
|
|
||||||
Bind();
|
|
||||||
|
|
||||||
BitmapData data = null;
|
|
||||||
|
|
||||||
GL.PushClientAttrib(ClientAttribMask.ClientPixelStoreBit);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
data = bitmap.LockBits(source, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
|
||||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
|
|
||||||
GL.PixelStore(PixelStoreParameter.UnpackRowLength, bitmap.Width);
|
|
||||||
GL.TexSubImage2D(TextureTarget.Texture2D, mipLevel,
|
|
||||||
target.Left, target.Top,
|
|
||||||
target.Width, target.Height,
|
|
||||||
OpenTK.Graphics.PixelFormat.Bgra,
|
|
||||||
PixelType.UnsignedByte, data.Scan0);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
GL.PopClientAttrib();
|
|
||||||
if (data != null)
|
|
||||||
bitmap.UnlockBits(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region ReadRegion
|
|
||||||
|
|
||||||
public TextureRegion2D ReadRegion(Rectangle rect, int mipLevel)
|
|
||||||
{
|
|
||||||
if (mipLevel < 0)
|
|
||||||
throw new ArgumentOutOfRangeException("miplevel");
|
|
||||||
|
|
||||||
TextureRegion2D<int> region = new TextureRegion2D<int>(rect);
|
|
||||||
|
|
||||||
GL.GetTexImage(TextureTarget.Texture2D, mipLevel, OpenTK.Graphics.PixelFormat.Bgra, PixelType.UnsignedByte, region.Data);
|
|
||||||
|
|
||||||
return region;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Equals
|
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
|
||||||
if (obj is Texture2D)
|
|
||||||
return this.Equals((Texture2D)obj);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override int GetHashCode()
|
|
||||||
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return (this as IGraphicsResource).Id;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public overrid string ToString()
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return String.Format("Texture2D #{0} ({1}x{2}, {3})",
|
|
||||||
(this as IGraphicsResource).Id.ToString(),
|
|
||||||
Width.ToString(),
|
|
||||||
Height.ToString(),
|
|
||||||
InternalFormat.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Protected Members
|
|
||||||
|
|
||||||
#region InternalFormat
|
|
||||||
|
|
||||||
protected abstract PixelInternalFormat InternalFormat { get; }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Private Members
|
|
||||||
|
|
||||||
int CreateTexture(int width, int height)
|
|
||||||
{
|
|
||||||
int id = GL.GenTexture();
|
|
||||||
if (id == 0)
|
|
||||||
throw new GraphicsResourceException(String.Format("Texture creation failed, (Error: {0})", GL.GetError()));
|
|
||||||
|
|
||||||
SetDefaultTextureParameters(id);
|
|
||||||
|
|
||||||
GL.TexImage2D(TextureTarget.Texture2D, 0, InternalFormat, Width, Height, 0,
|
|
||||||
OpenTK.Graphics.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
|
|
||||||
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetDefaultTextureParameters(int id)
|
|
||||||
{
|
|
||||||
// Ensure the texture is allocated.
|
|
||||||
GL.BindTexture(TextureTarget.Texture2D, id);
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear);
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);
|
|
||||||
if (GL.SupportsExtension("Version12"))
|
|
||||||
{
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.ClampToEdge);
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.ClampToEdge);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.Clamp);
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.Clamp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IGraphicsResource Members
|
|
||||||
|
|
||||||
#region IGraphicsResource.Context
|
|
||||||
|
|
||||||
IGraphicsContext IGraphicsResource.Context { get { return context; } }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IGraphicsResource.Id
|
|
||||||
|
|
||||||
int IGraphicsResource.Id
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (id == 0)
|
|
||||||
{
|
|
||||||
GraphicsContext.Assert();
|
|
||||||
context = GraphicsContext.CurrentContext;
|
|
||||||
|
|
||||||
id = CreateTexture(Width, Height);
|
|
||||||
}
|
|
||||||
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IEquatable<Texture2D> Members
|
|
||||||
|
|
||||||
public bool Equals(Texture2D other)
|
|
||||||
{
|
|
||||||
return (this as IGraphicsResource).Id == (other as IGraphicsResource).Id;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Dispose(bool manual)
|
|
||||||
{
|
|
||||||
if (!disposed)
|
|
||||||
{
|
|
||||||
if (manual)
|
|
||||||
{
|
|
||||||
GL.DeleteTexture(id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.Print("[Warning] {0} leaked.", this);
|
|
||||||
}
|
|
||||||
disposed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~Texture2D()
|
|
||||||
{
|
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,79 +0,0 @@
|
||||||
#region License
|
|
||||||
//
|
|
||||||
// The Open Toolkit Library License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
|
||||||
//
|
|
||||||
// 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.Drawing;
|
|
||||||
|
|
||||||
namespace OpenTK.Graphics
|
|
||||||
{
|
|
||||||
abstract class TextureRegion2D
|
|
||||||
{
|
|
||||||
Rectangle rectangle;
|
|
||||||
|
|
||||||
public Rectangle Rectangle { get { return rectangle; } protected set { rectangle = value; } }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Holds part or the whole of a 2d OpenGL texture.
|
|
||||||
/// </summary>
|
|
||||||
class TextureRegion2D<T> : TextureRegion2D where T : struct
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
T[,] data;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
internal TextureRegion2D(Rectangle rect)
|
|
||||||
{
|
|
||||||
data = new T[rect.Width, rect.Height];
|
|
||||||
Rectangle = rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Members
|
|
||||||
|
|
||||||
public T this[int x, int y]
|
|
||||||
{
|
|
||||||
get { return data[x, y]; }
|
|
||||||
set { data[x, y] = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Internal Members
|
|
||||||
|
|
||||||
internal T[,] Data { get { return data; } }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
#region --- License ---
|
|
||||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
||||||
* See license.txt for license info
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OpenTK
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents an item that can be packed with the TexturePacker.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The type of the packable item.</typeparam>
|
|
||||||
interface IPackable<T> : IEquatable<T>
|
|
||||||
{
|
|
||||||
int Width { get; }
|
|
||||||
int Height { get; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OpenTK
|
|
||||||
{
|
|
||||||
interface IPoolable : IDisposable
|
|
||||||
{
|
|
||||||
void OnAcquire();
|
|
||||||
void OnRelease();
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IPoolable<T> : IPoolable where T : IPoolable<T>, new()
|
|
||||||
{
|
|
||||||
ObjectPool<T> Owner { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,262 +0,0 @@
|
||||||
#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.Math
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a bezier curve with as many points as you want.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
[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)Functions.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)Functions.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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,164 +0,0 @@
|
||||||
#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.Math
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a cubic bezier curve with two anchor and two control points.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
[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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,152 +0,0 @@
|
||||||
#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.Math
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a quadric bezier curve with two anchor and one control point.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
[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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,97 +0,0 @@
|
||||||
#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.Math
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Defines a 2d box (rectangle).
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
[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 = topLeft.X;
|
|
||||||
Bottom = topLeft.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); } }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return String.Format("({0},{1})-({2},{3})", Left, Top, Right, Bottom);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,327 +0,0 @@
|
||||||
#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.Math
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Contains mathematical functions for the OpenTK.Math toolkit.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
public static class Functions
|
|
||||||
{
|
|
||||||
#region public static long NextPowerOfTwo(long n)
|
|
||||||
|
|
||||||
/// <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)));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public static int NextPowerOfTwo(int n)
|
|
||||||
|
|
||||||
/// <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)));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public static int NextPowerOfTwo(int n)
|
|
||||||
|
|
||||||
/// <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)));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
#region public static int NextPowerOfTwo(int n)
|
|
||||||
|
|
||||||
/// <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
|
|
||||||
|
|
||||||
/// <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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static readonly float PIF = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930382f;
|
|
||||||
public static readonly float RTODF = 180.0f / PIF;
|
|
||||||
public static readonly float DTORF = PIF / 180.0f;
|
|
||||||
|
|
||||||
public static readonly double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930382d;
|
|
||||||
public static readonly double RTOD = 180.0d / PIF;
|
|
||||||
public static readonly double DTOR = PIF / 180.0d;
|
|
||||||
|
|
||||||
public static void Swap(ref double a, ref double b)
|
|
||||||
{
|
|
||||||
double temp = a;
|
|
||||||
a = b;
|
|
||||||
b = temp;
|
|
||||||
}
|
|
||||||
public static void Swap(ref float a, ref float b)
|
|
||||||
{
|
|
||||||
float temp = a;
|
|
||||||
a = b;
|
|
||||||
b = temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#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
|
|
||||||
}
|
|
|
@ -1,589 +0,0 @@
|
||||||
#region --- License ---
|
|
||||||
/*
|
|
||||||
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
|
||||||
the Software without restriction, including without limitation the rights to
|
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
||||||
of the Software, and to permit persons to whom the Software is furnished to do
|
|
||||||
so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
The conversion functions are derived from OpenEXR's implementation and are
|
|
||||||
governed by the following license:
|
|
||||||
|
|
||||||
Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
|
|
||||||
Digital Ltd. LLC
|
|
||||||
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are
|
|
||||||
met:
|
|
||||||
* Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
* Neither the name of Industrial Light & Magic nor the names of
|
|
||||||
its contributors may be used to endorse or promote products derived
|
|
||||||
from this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
#endregion --- License ---
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
namespace OpenTK.Math
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The name Half is derived from half-precision floating-point number.
|
|
||||||
/// It occupies only 16 bits, which are split into 1 Sign bit, 5 Exponent bits and 10 Mantissa bits.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// Quote from ARB_half_float_pixel specification:
|
|
||||||
/// Any representable 16-bit floating-point value is legal as input to a GL command that accepts 16-bit floating-point data. The
|
|
||||||
/// result of providing a value that is not a floating-point number (such as infinity or NaN) to such a command is unspecified,
|
|
||||||
/// but must not lead to GL interruption or termination. Providing a denormalized number or negative zero to GL must yield
|
|
||||||
/// predictable results.
|
|
||||||
/// </remarks>
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
[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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,829 +0,0 @@
|
||||||
#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.Math
|
|
||||||
{
|
|
||||||
// Todo: Remove this warning when the code goes public.
|
|
||||||
#pragma warning disable 3019
|
|
||||||
#if false
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
[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
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,969 +0,0 @@
|
||||||
#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.Math
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a 4x4 Matrix with double-precision components.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
[Serializable]
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct Matrix4d : IEquatable<Matrix4d>
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Top row of the matrix
|
|
||||||
/// </summary>
|
|
||||||
public Vector4d Row0;
|
|
||||||
/// <summary>
|
|
||||||
/// 2nd row of the matrix
|
|
||||||
/// </summary>
|
|
||||||
public Vector4d Row1;
|
|
||||||
/// <summary>
|
|
||||||
/// 3rd row of the matrix
|
|
||||||
/// </summary>
|
|
||||||
public Vector4d Row2;
|
|
||||||
/// <summary>
|
|
||||||
/// Bottom row of the matrix
|
|
||||||
/// </summary>
|
|
||||||
public Vector4d Row3;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The identity matrix
|
|
||||||
/// </summary>
|
|
||||||
public static Matrix4d Identity = new Matrix4d(Vector4d .UnitX, Vector4d .UnitY, Vector4d .UnitZ, Vector4d .UnitW);
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new instance.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="row0">Top row of the matrix</param>
|
|
||||||
/// <param name="row1">Second row of the matrix</param>
|
|
||||||
/// <param name="row2">Third row of the matrix</param>
|
|
||||||
/// <param name="row3">Bottom row of the matrix</param>
|
|
||||||
public Matrix4d(Vector4d row0, Vector4d row1, Vector4d row2, Vector4d row3)
|
|
||||||
{
|
|
||||||
Row0 = row0;
|
|
||||||
Row1 = row1;
|
|
||||||
Row2 = row2;
|
|
||||||
Row3 = row3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new instance.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="m00">First item of the first row.</param>
|
|
||||||
/// <param name="m01">Second item of the first row.</param>
|
|
||||||
/// <param name="m02">Third item of the first row.</param>
|
|
||||||
/// <param name="m03">Fourth item of the first row.</param>
|
|
||||||
/// <param name="m10">First item of the second row.</param>
|
|
||||||
/// <param name="m11">Second item of the second row.</param>
|
|
||||||
/// <param name="m12">Third item of the second row.</param>
|
|
||||||
/// <param name="m13">Fourth item of the second row.</param>
|
|
||||||
/// <param name="m20">First item of the third row.</param>
|
|
||||||
/// <param name="m21">Second item of the third row.</param>
|
|
||||||
/// <param name="m22">Third item of the third row.</param>
|
|
||||||
/// <param name="m23">First item of the third row.</param>
|
|
||||||
/// <param name="m30">Fourth item of the fourth row.</param>
|
|
||||||
/// <param name="m31">Second item of the fourth row.</param>
|
|
||||||
/// <param name="m32">Third item of the fourth row.</param>
|
|
||||||
/// <param name="m33">Fourth item of the fourth row.</param>
|
|
||||||
public Matrix4d(
|
|
||||||
float m00, float m01, float m02, float m03,
|
|
||||||
float m10, float m11, float m12, float m13,
|
|
||||||
float m20, float m21, float m22, float m23,
|
|
||||||
float m30, float m31, float m32, float m33)
|
|
||||||
{
|
|
||||||
Row0 = new Vector4d(m00, m01, m02, m03);
|
|
||||||
Row1 = new Vector4d(m10, m11, m12, m13);
|
|
||||||
Row2 = new Vector4d(m20, m21, m22, m23);
|
|
||||||
Row3 = new Vector4d(m30, m31, m32, m33);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Members
|
|
||||||
|
|
||||||
#region Properties
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The determinant of this matrix
|
|
||||||
/// </summary>
|
|
||||||
public double Determinant
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return
|
|
||||||
Row0.X * Row1.Y * Row2.Z * Row3.W - Row0.X * Row1.Y * Row2.W * Row3.Z + Row0.X * Row1.Z * Row2.W * Row3.Y - Row0.X * Row1.Z * Row2.Y * Row3.W
|
|
||||||
+ Row0.X * Row1.W * Row2.Y * Row3.Z - Row0.X * Row1.W * Row2.Z * Row3.Y - Row0.Y * Row1.Z * Row2.W * Row3.X + Row0.Y * Row1.Z * Row2.X * Row3.W
|
|
||||||
- Row0.Y * Row1.W * Row2.X * Row3.Z + Row0.Y * Row1.W * Row2.Z * Row3.X - Row0.Y * Row1.X * Row2.Z * Row3.W + Row0.Y * Row1.X * Row2.W * Row3.Z
|
|
||||||
+ Row0.Z * Row1.W * Row2.X * Row3.Y - Row0.Z * Row1.W * Row2.Y * Row3.X + Row0.Z * Row1.X * Row2.Y * Row3.W - Row0.Z * Row1.X * Row2.W * Row3.Y
|
|
||||||
+ Row0.Z * Row1.Y * Row2.W * Row3.X - Row0.Z * Row1.Y * Row2.X * Row3.W - Row0.W * Row1.X * Row2.Y * Row3.Z + Row0.W * Row1.X * Row2.Z * Row3.Y
|
|
||||||
- Row0.W * Row1.Y * Row2.Z * Row3.X + Row0.W * Row1.Y * Row2.X * Row3.Z - Row0.W * Row1.Z * Row2.X * Row3.Y + Row0.W * Row1.Z * Row2.Y * Row3.X;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The first column of this matrix
|
|
||||||
/// </summary>
|
|
||||||
public Vector4d Column0
|
|
||||||
{
|
|
||||||
get { return new Vector4d (Row0.X, Row1.X, Row2.X, Row3.X); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The second column of this matrix
|
|
||||||
/// </summary>
|
|
||||||
public Vector4d Column1
|
|
||||||
{
|
|
||||||
get { return new Vector4d (Row0.Y, Row1.Y, Row2.Y, Row3.Y); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The third column of this matrix
|
|
||||||
/// </summary>
|
|
||||||
public Vector4d Column2
|
|
||||||
{
|
|
||||||
get { return new Vector4d (Row0.Z, Row1.Z, Row2.Z, Row3.Z); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The fourth column of this matrix
|
|
||||||
/// </summary>
|
|
||||||
public Vector4d Column3
|
|
||||||
{
|
|
||||||
get { return new Vector4d (Row0.W, Row1.W, Row2.W, Row3.W); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public double this[int i, int j]
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (i < 0 || i > 3)
|
|
||||||
throw new ArgumentOutOfRangeException("i");
|
|
||||||
|
|
||||||
if (j < 0 || j > 3)
|
|
||||||
throw new ArgumentOutOfRangeException("j");
|
|
||||||
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
fixed (Matrix4d* ptr = &this)
|
|
||||||
return *((double*)ptr + i + j * 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (i < 0 || i > 3)
|
|
||||||
throw new ArgumentOutOfRangeException("i");
|
|
||||||
|
|
||||||
if (j < 0 || j > 3)
|
|
||||||
throw new ArgumentOutOfRangeException("j");
|
|
||||||
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
fixed (Matrix4d* ptr = &this)
|
|
||||||
*((double*)ptr + i + j * 4) = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 1, column 1 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M11 { get { return Row0.X; } set { Row0.X = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 1, column 2 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M12 { get { return Row0.Y; } set { Row0.Y = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 1, column 3 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M13 { get { return Row0.Z; } set { Row0.Z = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 1, column 4 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M14 { get { return Row0.W; } set { Row0.W = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 2, column 1 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M21 { get { return Row1.X; } set { Row1.X = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 2, column 2 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M22 { get { return Row1.Y; } set { Row1.Y = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 2, column 3 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M23 { get { return Row1.Z; } set { Row1.Z = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 2, column 4 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M24 { get { return Row1.W; } set { Row1.W = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 3, column 1 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M31 { get { return Row2.X; } set { Row2.X = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 3, column 2 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M32 { get { return Row2.Y; } set { Row2.Y = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 3, column 3 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M33 { get { return Row2.Z; } set { Row2.Z = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 3, column 4 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M34 { get { return Row2.W; } set { Row2.W = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 4, column 1 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M41 { get { return Row3.X; } set { Row3.X = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 4, column 3 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M42 { get { return Row3.Y; } set { Row3.Y = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 4, column 3 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M43 { get { return Row3.Z; } set { Row3.Z = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the value at row 4, column 4 of this instance.
|
|
||||||
/// </summary>
|
|
||||||
public double M44 { get { return Row3.W; } set { Row3.W = value; } }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Instance
|
|
||||||
|
|
||||||
#region public void Invert()
|
|
||||||
|
|
||||||
public void Invert()
|
|
||||||
{
|
|
||||||
this = Matrix4d.Invert(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public void Transpose()
|
|
||||||
|
|
||||||
public void Transpose()
|
|
||||||
{
|
|
||||||
this = Matrix4d.Transpose(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Static
|
|
||||||
|
|
||||||
#region CreateTranslation
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a translation matrix.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">X translation.</param>
|
|
||||||
/// <param name="y">Y translation.</param>
|
|
||||||
/// <param name="z">Z translation.</param>
|
|
||||||
/// <param name="result">The resulting Matrix4d instance.</param>
|
|
||||||
public static void CreateTranslation(double x, double y, double z, out Matrix4d result)
|
|
||||||
{
|
|
||||||
result = Identity;
|
|
||||||
result.Row3 = new Vector4d(x, y, z, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a translation matrix.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vector">The translation vector.</param>
|
|
||||||
/// <param name="result">The resulting Matrix4d instance.</param>
|
|
||||||
public static void CreateTranslation(ref Vector3d vector, out Matrix4d result)
|
|
||||||
{
|
|
||||||
result = Identity;
|
|
||||||
result.Row3 = new Vector4d(vector.X, vector.Y, vector.Z, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a translation matrix.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">X translation.</param>
|
|
||||||
/// <param name="y">Y translation.</param>
|
|
||||||
/// <param name="z">Z translation.</param>
|
|
||||||
/// <returns>The resulting Matrix4d instance.</returns>
|
|
||||||
public static Matrix4d CreateTranslation(double x, double y, double z)
|
|
||||||
{
|
|
||||||
Matrix4d result;
|
|
||||||
CreateTranslation(x, y, z, out result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a translation matrix.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vector">The translation vector.</param>
|
|
||||||
/// <returns>The resulting Matrix4d instance.</returns>
|
|
||||||
public static Matrix4d CreateTranslation(Vector3d vector)
|
|
||||||
{
|
|
||||||
Matrix4d result;
|
|
||||||
CreateTranslation(vector.X, vector.Y, vector.Z, out result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region CreateOrthographic
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an orthographic projection matrix.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="width">The width of the projection volume.</param>
|
|
||||||
/// <param name="height">The height of the projection volume.</param>
|
|
||||||
/// <param name="zNear">The near edge of the projection volume.</param>
|
|
||||||
/// <param name="zFar">The far edge of the projection volume.</param>
|
|
||||||
/// <param name="result">The resulting Matrix4d instance.</param>
|
|
||||||
public static void CreateOrthographic(double width, double height, double zNear, double zFar, out Matrix4d result)
|
|
||||||
{
|
|
||||||
CreateOrthographicOffCenter(-width / 2, width / 2, -height / 2, height / 2, zNear, zFar, out result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an orthographic projection matrix.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="width">The width of the projection volume.</param>
|
|
||||||
/// <param name="height">The height of the projection volume.</param>
|
|
||||||
/// <param name="zNear">The near edge of the projection volume.</param>
|
|
||||||
/// <param name="zFar">The far edge of the projection volume.</param>
|
|
||||||
/// <rereturns>The resulting Matrix4d instance.</rereturns>
|
|
||||||
public static Matrix4d CreateOrthographic(double width, double height, double zNear, double zFar)
|
|
||||||
{
|
|
||||||
Matrix4d result;
|
|
||||||
CreateOrthographicOffCenter(-width / 2, width / 2, -height / 2, height / 2, zNear, zFar, out result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region CreateOrthographicOffCenter
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an orthographic projection matrix.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">The left edge of the projection volume.</param>
|
|
||||||
/// <param name="right">The right edge of the projection volume.</param>
|
|
||||||
/// <param name="bottom">The bottom edge of the projection volume.</param>
|
|
||||||
/// <param name="top">The top edge of the projection volume.</param>
|
|
||||||
/// <param name="zNear">The near edge of the projection volume.</param>
|
|
||||||
/// <param name="zFar">The far edge of the projection volume.</param>
|
|
||||||
/// <param name="result">The resulting Matrix4d instance.</param>
|
|
||||||
public static void CreateOrthographicOffCenter(double left, double right, double bottom, double top, double zNear, double zFar, out Matrix4d result)
|
|
||||||
{
|
|
||||||
result = new Matrix4d();
|
|
||||||
|
|
||||||
double invRL = 1 / (right - left);
|
|
||||||
double invTB = 1 / (top - bottom);
|
|
||||||
double invFN = 1 / (zFar - zNear);
|
|
||||||
|
|
||||||
result.M11 = 2 * invRL;
|
|
||||||
result.M22 = 2 * invTB;
|
|
||||||
result.M33 = -2 * invFN;
|
|
||||||
|
|
||||||
result.M41 = -(right + left) * invRL;
|
|
||||||
result.M42 = -(top + bottom) * invTB;
|
|
||||||
result.M43 = -(zFar + zNear) * invFN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an orthographic projection matrix.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">The left edge of the projection volume.</param>
|
|
||||||
/// <param name="right">The right edge of the projection volume.</param>
|
|
||||||
/// <param name="bottom">The bottom edge of the projection volume.</param>
|
|
||||||
/// <param name="top">The top edge of the projection volume.</param>
|
|
||||||
/// <param name="zNear">The near edge of the projection volume.</param>
|
|
||||||
/// <param name="zFar">The far edge of the projection volume.</param>
|
|
||||||
/// <returns>The resulting Matrix4d instance.</returns>
|
|
||||||
public static Matrix4d CreateOrthographicOffCenter(double left, double right, double bottom, double top, double zNear, double zFar)
|
|
||||||
{
|
|
||||||
Matrix4d result;
|
|
||||||
CreateOrthographicOffCenter(left, right, bottom, top, zNear, zFar, out result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Obsolete Functions
|
|
||||||
|
|
||||||
#region Translation Functions
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Build a translation matrix with the given translation
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="trans">The vector to translate along</param>
|
|
||||||
/// <returns>A Translation matrix</returns>
|
|
||||||
[Obsolete("Use CreateTranslation instead.")]
|
|
||||||
public static Matrix4d Translation(Vector3d trans)
|
|
||||||
{
|
|
||||||
return Translation(trans.X, trans.Y, trans.Z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Build a translation matrix with the given translation
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">X translation</param>
|
|
||||||
/// <param name="y">Y translation</param>
|
|
||||||
/// <param name="z">Z translation</param>
|
|
||||||
/// <returns>A Translation matrix</returns>
|
|
||||||
[Obsolete("Use CreateTranslation instead.")]
|
|
||||||
public static Matrix4d Translation(double x, double y, double z)
|
|
||||||
{
|
|
||||||
Matrix4d result = Identity;
|
|
||||||
result.Row3 = new Vector4d(x, y, z, 1.0f);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Scale Functions
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Build a scaling matrix
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="scale">Single scale factor for x,y and z axes</param>
|
|
||||||
/// <returns>A scaling matrix</returns>
|
|
||||||
public static Matrix4d Scale(double scale)
|
|
||||||
{
|
|
||||||
return Scale(scale, scale, scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Build a scaling matrix
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="scale">Scale factors for x,y and z axes</param>
|
|
||||||
/// <returns>A scaling matrix</returns>
|
|
||||||
public static Matrix4d Scale(Vector3d scale)
|
|
||||||
{
|
|
||||||
return Scale(scale.X, scale.Y, scale.Z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Build a scaling matrix
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">Scale factor for x-axis</param>
|
|
||||||
/// <param name="y">Scale factor for y-axis</param>
|
|
||||||
/// <param name="z">Scale factor for z-axis</param>
|
|
||||||
/// <returns>A scaling matrix</returns>
|
|
||||||
public static Matrix4d Scale(double x, double y, double z)
|
|
||||||
{
|
|
||||||
Matrix4d result;
|
|
||||||
result.Row0 = Vector4d .UnitX * x;
|
|
||||||
result.Row1 = Vector4d .UnitY * y;
|
|
||||||
result.Row2 = Vector4d .UnitZ * z;
|
|
||||||
result.Row3 = Vector4d .UnitW;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Rotation Functions
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Build a rotation matrix that rotates about the x-axis
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="angle">angle in radians to rotate counter-clockwise around the x-axis</param>
|
|
||||||
/// <returns>A rotation matrix</returns>
|
|
||||||
public static Matrix4d RotateX(double angle)
|
|
||||||
{
|
|
||||||
double cos = (double)System.Math.Cos(angle);
|
|
||||||
double sin = (double)System.Math.Sin(angle);
|
|
||||||
|
|
||||||
Matrix4d result;
|
|
||||||
result.Row0 = Vector4d .UnitX;
|
|
||||||
result.Row1 = new Vector4d (0.0f, cos, sin, 0.0f);
|
|
||||||
result.Row2 = new Vector4d (0.0f, -sin, cos, 0.0f);
|
|
||||||
result.Row3 = Vector4d .UnitW;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Build a rotation matrix that rotates about the y-axis
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="angle">angle in radians to rotate counter-clockwise around the y-axis</param>
|
|
||||||
/// <returns>A rotation matrix</returns>
|
|
||||||
public static Matrix4d RotateY(double angle)
|
|
||||||
{
|
|
||||||
double cos = (double)System.Math.Cos(angle);
|
|
||||||
double sin = (double)System.Math.Sin(angle);
|
|
||||||
|
|
||||||
Matrix4d result;
|
|
||||||
result.Row0 = new Vector4d (cos, 0.0f, -sin, 0.0f);
|
|
||||||
result.Row1 = Vector4d .UnitY;
|
|
||||||
result.Row2 = new Vector4d (sin, 0.0f, cos, 0.0f);
|
|
||||||
result.Row3 = Vector4d .UnitW;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Build a rotation matrix that rotates about the z-axis
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="angle">angle in radians to rotate counter-clockwise around the z-axis</param>
|
|
||||||
/// <returns>A rotation matrix</returns>
|
|
||||||
public static Matrix4d RotateZ(double angle)
|
|
||||||
{
|
|
||||||
double cos = (double)System.Math.Cos(angle);
|
|
||||||
double sin = (double)System.Math.Sin(angle);
|
|
||||||
|
|
||||||
Matrix4d result;
|
|
||||||
result.Row0 = new Vector4d (cos, sin, 0.0f, 0.0f);
|
|
||||||
result.Row1 = new Vector4d (-sin, cos, 0.0f, 0.0f);
|
|
||||||
result.Row2 = Vector4d .UnitZ;
|
|
||||||
result.Row3 = Vector4d .UnitW;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Build a rotation matrix to rotate about the given axis
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="axis">the axis to rotate about</param>
|
|
||||||
/// <param name="angle">angle in radians to rotate counter-clockwise (looking in the direction of the given axis)</param>
|
|
||||||
/// <returns>A rotation matrix</returns>
|
|
||||||
public static Matrix4d Rotate(Vector3d axis, double angle)
|
|
||||||
{
|
|
||||||
double cos = (double)System.Math.Cos(-angle);
|
|
||||||
double sin = (double)System.Math.Sin(-angle);
|
|
||||||
double t = 1.0f - cos;
|
|
||||||
|
|
||||||
axis.Normalize();
|
|
||||||
|
|
||||||
Matrix4d result;
|
|
||||||
result.Row0 = new Vector4d (t * axis.X * axis.X + cos, t * axis.X * axis.Y - sin * axis.Z, t * axis.X * axis.Z + sin * axis.Y, 0.0f);
|
|
||||||
result.Row1 = new Vector4d (t * axis.X * axis.Y + sin * axis.Z, t * axis.Y * axis.Y + cos, t * axis.Y * axis.Z - sin * axis.X, 0.0f);
|
|
||||||
result.Row2 = new Vector4d (t * axis.X * axis.Z - sin * axis.Y, t * axis.Y * axis.Z + sin * axis.X, t * axis.Z * axis.Z + cos, 0.0f);
|
|
||||||
result.Row3 = Vector4d .UnitW;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Build a rotation matrix from a quaternion
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="q">the quaternion</param>
|
|
||||||
/// <returns>A rotation matrix</returns>
|
|
||||||
public static Matrix4d Rotate(Quaterniond q)
|
|
||||||
{
|
|
||||||
Vector3d axis;
|
|
||||||
double angle;
|
|
||||||
q.ToAxisAngle(out axis, out angle);
|
|
||||||
return Rotate(axis, angle);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Camera Helper Functions
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Build a world space to camera space matrix
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="eye">Eye (camera) position in world space</param>
|
|
||||||
/// <param name="target">Target position in world space</param>
|
|
||||||
/// <param name="up">Up vector in world space (should not be parallel to the camera direction, that is target - eye)</param>
|
|
||||||
/// <returns>A Matrix that transforms world space to camera space</returns>
|
|
||||||
public static Matrix4d LookAt(Vector3d eye, Vector3d target, Vector3d up)
|
|
||||||
{
|
|
||||||
Vector3d z = Vector3d.Normalize(eye - target);
|
|
||||||
Vector3d x = Vector3d.Normalize(Vector3d.Cross(up, z));
|
|
||||||
Vector3d y = Vector3d.Normalize(Vector3d.Cross(z, x));
|
|
||||||
|
|
||||||
Matrix4d rot = new Matrix4d(new Vector4d (x.X, y.X, z.X, 0.0f),
|
|
||||||
new Vector4d (x.Y, y.Y, z.Y, 0.0f),
|
|
||||||
new Vector4d (x.Z, y.Z, z.Z, 0.0f),
|
|
||||||
Vector4d .UnitW);
|
|
||||||
|
|
||||||
Matrix4d trans = Matrix4d.CreateTranslation(-eye);
|
|
||||||
|
|
||||||
return trans * rot;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Build a world space to camera space matrix
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="eyeX">Eye (camera) position in world space</param>
|
|
||||||
/// <param name="eyeY">Eye (camera) position in world space</param>
|
|
||||||
/// <param name="eyeZ">Eye (camera) position in world space</param>
|
|
||||||
/// <param name="targetX">Target position in world space</param>
|
|
||||||
/// <param name="targetY">Target position in world space</param>
|
|
||||||
/// <param name="targetZ">Target position in world space</param>
|
|
||||||
/// <param name="upX">Up vector in world space (should not be parallel to the camera direction, that is target - eye)</param>
|
|
||||||
/// <param name="upY">Up vector in world space (should not be parallel to the camera direction, that is target - eye)</param>
|
|
||||||
/// <param name="upZ">Up vector in world space (should not be parallel to the camera direction, that is target - eye)</param>
|
|
||||||
/// <returns>A Matrix4 that transforms world space to camera space</returns>
|
|
||||||
public static Matrix4d LookAt(double eyeX, double eyeY, double eyeZ, double targetX, double targetY, double targetZ, double upX, double upY, double upZ)
|
|
||||||
{
|
|
||||||
return LookAt(new Vector3d(eyeX, eyeY, eyeZ), new Vector3d(targetX, targetY, targetZ), new Vector3d(upX, upY, upZ));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Build a projection matrix
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">Left edge of the view frustum</param>
|
|
||||||
/// <param name="right">Right edge of the view frustum</param>
|
|
||||||
/// <param name="bottom">Bottom edge of the view frustum</param>
|
|
||||||
/// <param name="top">Top edge of the view frustum</param>
|
|
||||||
/// <param name="near">Distance to the near clip plane</param>
|
|
||||||
/// <param name="far">Distance to the far clip plane</param>
|
|
||||||
/// <returns>A projection matrix that transforms camera space to raster space</returns>
|
|
||||||
public static Matrix4d Frustum(double left, double right, double bottom, double top, double near, double far)
|
|
||||||
{
|
|
||||||
double invRL = 1.0f / (right - left);
|
|
||||||
double invTB = 1.0f / (top - bottom);
|
|
||||||
double invFN = 1.0f / (far - near);
|
|
||||||
return new Matrix4d(new Vector4d (2.0f * near * invRL, 0.0f, 0.0f, 0.0f),
|
|
||||||
new Vector4d (0.0f, 2.0f * near * invTB, 0.0f, 0.0f),
|
|
||||||
new Vector4d ((right + left) * invRL, (top + bottom) * invTB, -(far + near) * invFN, -1.0f),
|
|
||||||
new Vector4d (0.0f, 0.0f, -2.0f * far * near * invFN, 0.0f));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Build a projection matrix
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="fovy">Angle of the field of view in the y direction (in radians)</param>
|
|
||||||
/// <param name="aspect">Aspect ratio of the view (width / height)</param>
|
|
||||||
/// <param name="near">Distance to the near clip plane</param>
|
|
||||||
/// <param name="far">Distance to the far clip plane</param>
|
|
||||||
/// <returns>A projection matrix that transforms camera space to raster space</returns>
|
|
||||||
public static Matrix4d Perspective(double fovy, double aspect, double near, double far)
|
|
||||||
{
|
|
||||||
double yMax = near * (double)System.Math.Tan(0.5f * fovy);
|
|
||||||
double yMin = -yMax;
|
|
||||||
double xMin = yMin * aspect;
|
|
||||||
double xMax = yMax * aspect;
|
|
||||||
|
|
||||||
return Frustum(xMin, xMax, yMin, yMax, near, far);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Multiply Functions
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Multiplies two instances.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">The left operand of the multiplication.</param>
|
|
||||||
/// <param name="right">The right operand of the multiplication.</param>
|
|
||||||
/// <returns>A new instance that is the result of the multiplication</returns>
|
|
||||||
public static Matrix4d Mult(Matrix4d left, Matrix4d right)
|
|
||||||
{
|
|
||||||
Matrix4d result;
|
|
||||||
Mult(ref left, ref right, out result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Multiplies two instances.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">The left operand of the multiplication.</param>
|
|
||||||
/// <param name="right">The right operand of the multiplication.</param>
|
|
||||||
/// <param name="result">A new instance that is the result of the multiplication</param>
|
|
||||||
public static void Mult(ref Matrix4d left, ref Matrix4d right, out Matrix4d result)
|
|
||||||
{
|
|
||||||
result = new Matrix4d();
|
|
||||||
result.M11 = left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31 + left.M14 * right.M41;
|
|
||||||
result.M12 = left.M11 * right.M12 + left.M12 * right.M22 + left.M13 * right.M32 + left.M14 * right.M42;
|
|
||||||
result.M13 = left.M11 * right.M13 + left.M12 * right.M23 + left.M13 * right.M33 + left.M14 * right.M43;
|
|
||||||
result.M14 = left.M11 * right.M14 + left.M12 * right.M24 + left.M13 * right.M34 + left.M14 * right.M44;
|
|
||||||
result.M21 = left.M21 * right.M11 + left.M22 * right.M21 + left.M23 * right.M31 + left.M24 * right.M41;
|
|
||||||
result.M22 = left.M21 * right.M12 + left.M22 * right.M22 + left.M23 * right.M32 + left.M24 * right.M42;
|
|
||||||
result.M23 = left.M21 * right.M13 + left.M22 * right.M23 + left.M23 * right.M33 + left.M24 * right.M43;
|
|
||||||
result.M24 = left.M21 * right.M14 + left.M22 * right.M24 + left.M23 * right.M34 + left.M24 * right.M44;
|
|
||||||
result.M31 = left.M31 * right.M11 + left.M32 * right.M21 + left.M33 * right.M31 + left.M34 * right.M41;
|
|
||||||
result.M32 = left.M31 * right.M12 + left.M32 * right.M22 + left.M33 * right.M32 + left.M34 * right.M42;
|
|
||||||
result.M33 = left.M31 * right.M13 + left.M32 * right.M23 + left.M33 * right.M33 + left.M34 * right.M43;
|
|
||||||
result.M34 = left.M31 * right.M14 + left.M32 * right.M24 + left.M33 * right.M34 + left.M34 * right.M44;
|
|
||||||
result.M41 = left.M41 * right.M11 + left.M42 * right.M21 + left.M43 * right.M31 + left.M44 * right.M41;
|
|
||||||
result.M42 = left.M41 * right.M12 + left.M42 * right.M22 + left.M43 * right.M32 + left.M44 * right.M42;
|
|
||||||
result.M43 = left.M41 * right.M13 + left.M42 * right.M23 + left.M43 * right.M33 + left.M44 * right.M43;
|
|
||||||
result.M44 = left.M41 * right.M14 + left.M42 * right.M24 + left.M43 * right.M34 + left.M44 * right.M44;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Invert Functions
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the inverse of the given matrix
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mat">The matrix to invert</param>
|
|
||||||
/// <returns>The inverse of the given matrix if it has one, or the input if it is singular</returns>
|
|
||||||
/// <exception cref="InvalidOperationException">Thrown if the Matrix4d is singular.</exception>
|
|
||||||
public static Matrix4d Invert(Matrix4d mat)
|
|
||||||
{
|
|
||||||
int[] colIdx = { 0, 0, 0, 0 };
|
|
||||||
int[] rowIdx = { 0, 0, 0, 0 };
|
|
||||||
int[] pivotIdx = { -1, -1, -1, -1 };
|
|
||||||
|
|
||||||
// convert the matrix to an array for easy looping
|
|
||||||
double[,] inverse = {{mat.Row0.X, mat.Row0.Y, mat.Row0.Z, mat.Row0.W},
|
|
||||||
{mat.Row1.X, mat.Row1.Y, mat.Row1.Z, mat.Row1.W},
|
|
||||||
{mat.Row2.X, mat.Row2.Y, mat.Row2.Z, mat.Row2.W},
|
|
||||||
{mat.Row3.X, mat.Row3.Y, mat.Row3.Z, mat.Row3.W} };
|
|
||||||
int icol = 0;
|
|
||||||
int irow = 0;
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
// Find the largest pivot value
|
|
||||||
double maxPivot = 0.0f;
|
|
||||||
for (int j = 0; j < 4; j++)
|
|
||||||
{
|
|
||||||
if (pivotIdx[j] != 0)
|
|
||||||
{
|
|
||||||
for (int k = 0; k < 4; ++k)
|
|
||||||
{
|
|
||||||
if (pivotIdx[k] == -1)
|
|
||||||
{
|
|
||||||
double absVal = System.Math.Abs(inverse[j, k]);
|
|
||||||
if (absVal > maxPivot)
|
|
||||||
{
|
|
||||||
maxPivot = absVal;
|
|
||||||
irow = j;
|
|
||||||
icol = k;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (pivotIdx[k] > 0)
|
|
||||||
{
|
|
||||||
return mat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
++(pivotIdx[icol]);
|
|
||||||
|
|
||||||
// Swap rows over so pivot is on diagonal
|
|
||||||
if (irow != icol)
|
|
||||||
{
|
|
||||||
for (int k = 0; k < 4; ++k)
|
|
||||||
{
|
|
||||||
double f = inverse[irow, k];
|
|
||||||
inverse[irow, k] = inverse[icol, k];
|
|
||||||
inverse[icol, k] = f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rowIdx[i] = irow;
|
|
||||||
colIdx[i] = icol;
|
|
||||||
|
|
||||||
double pivot = inverse[icol, icol];
|
|
||||||
// check for singular matrix
|
|
||||||
if (pivot == 0.0f)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Matrix is singular and cannot be inverted.");
|
|
||||||
//return mat;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scale row so it has a unit diagonal
|
|
||||||
double oneOverPivot = 1.0f / pivot;
|
|
||||||
inverse[icol, icol] = 1.0f;
|
|
||||||
for (int k = 0; k < 4; ++k)
|
|
||||||
inverse[icol, k] *= oneOverPivot;
|
|
||||||
|
|
||||||
// Do elimination of non-diagonal elements
|
|
||||||
for (int j = 0; j < 4; ++j)
|
|
||||||
{
|
|
||||||
// check this isn't on the diagonal
|
|
||||||
if (icol != j)
|
|
||||||
{
|
|
||||||
double f = inverse[j, icol];
|
|
||||||
inverse[j, icol] = 0.0f;
|
|
||||||
for (int k = 0; k < 4; ++k)
|
|
||||||
inverse[j, k] -= inverse[icol, k] * f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int j = 3; j >= 0; --j)
|
|
||||||
{
|
|
||||||
int ir = rowIdx[j];
|
|
||||||
int ic = colIdx[j];
|
|
||||||
for (int k = 0; k < 4; ++k)
|
|
||||||
{
|
|
||||||
double f = inverse[k, ir];
|
|
||||||
inverse[k, ir] = inverse[k, ic];
|
|
||||||
inverse[k, ic] = f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mat.Row0 = new Vector4d (inverse[0, 0], inverse[0, 1], inverse[0, 2], inverse[0, 3]);
|
|
||||||
mat.Row1 = new Vector4d (inverse[1, 0], inverse[1, 1], inverse[1, 2], inverse[1, 3]);
|
|
||||||
mat.Row2 = new Vector4d (inverse[2, 0], inverse[2, 1], inverse[2, 2], inverse[2, 3]);
|
|
||||||
mat.Row3 = new Vector4d (inverse[3, 0], inverse[3, 1], inverse[3, 2], inverse[3, 3]);
|
|
||||||
return mat;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Transpose
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the transpose of the given matrix
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mat">The matrix to transpose</param>
|
|
||||||
/// <returns>The transpose of the given matrix</returns>
|
|
||||||
public static Matrix4d Transpose(Matrix4d mat)
|
|
||||||
{
|
|
||||||
return new Matrix4d(mat.Column0, mat.Column1, mat.Column2, mat.Column3);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the transpose of the given matrix
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mat">The matrix to transpose</param>
|
|
||||||
/// <param name="result">The result of the calculation</param>
|
|
||||||
public static void Transpose(ref Matrix4d mat, out Matrix4d result)
|
|
||||||
{
|
|
||||||
result.Row0 = mat.Column0;
|
|
||||||
result.Row1 = mat.Column1;
|
|
||||||
result.Row2 = mat.Column2;
|
|
||||||
result.Row3 = mat.Column3;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Operators
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Matrix multiplication
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">left-hand operand</param>
|
|
||||||
/// <param name="right">right-hand operand</param>
|
|
||||||
/// <returns>A new Matrix44 which holds the result of the multiplication</returns>
|
|
||||||
public static Matrix4d operator *(Matrix4d left, Matrix4d right)
|
|
||||||
{
|
|
||||||
return Matrix4d.Mult(left, right);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool operator ==(Matrix4d left, Matrix4d right)
|
|
||||||
{
|
|
||||||
return left.Equals(right);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool operator !=(Matrix4d left, Matrix4d right)
|
|
||||||
{
|
|
||||||
return !left.Equals(right);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Overrides
|
|
||||||
|
|
||||||
#region public override string ToString()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a System.String that represents the current Matrix44.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return String.Format("{0}\n{1}\n{2}\n{3}", Row0, Row1, Row2, Row3);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override int GetHashCode()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the hashcode for this instance.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode() ^ Row3.GetHashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override bool Equals(object obj)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Indicates whether this instance and a specified object are equal.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="obj">The object to compare to.</param>
|
|
||||||
/// <returns>True if the instances are equal; false otherwise.</returns>
|
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
|
||||||
if (!(obj is Matrix4d))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return this.Equals((Matrix4d)obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IEquatable<Matrix4d> Members
|
|
||||||
|
|
||||||
/// <summary>Indicates whether the current matrix is equal to another matrix.</summary>
|
|
||||||
/// <param name="other">An matrix to compare with this matrix.</param>
|
|
||||||
/// <returns>true if the current matrix is equal to the matrix parameter; otherwise, false.</returns>
|
|
||||||
public bool Equals(Matrix4d other)
|
|
||||||
{
|
|
||||||
return
|
|
||||||
Row0 == other.Row0 &&
|
|
||||||
Row1 == other.Row1 &&
|
|
||||||
Row2 == other.Row2 &&
|
|
||||||
Row3 == other.Row3;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,587 +0,0 @@
|
||||||
#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;
|
|
||||||
|
|
||||||
namespace OpenTK.Math
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a Quaternion.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
[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 (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
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
public static Quaternion operator +(Quaternion left, Quaternion right)
|
|
||||||
{
|
|
||||||
left.Xyz += right.Xyz;
|
|
||||||
left.W += right.W;
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Quaternion operator -(Quaternion left, Quaternion right)
|
|
||||||
{
|
|
||||||
left.Xyz -= right.Xyz;
|
|
||||||
left.W -= right.W;
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Quaternion operator *(Quaternion left, Quaternion right)
|
|
||||||
{
|
|
||||||
float w = left.W * right.W - Vector3.Dot(left.Xyz, right.Xyz);
|
|
||||||
left.Xyz = right.W * left.Xyz + left.W * right.Xyz + Vector3.Cross(left.Xyz, right.Xyz);
|
|
||||||
left.W = w;
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool operator ==(Quaternion left, Quaternion right)
|
|
||||||
{
|
|
||||||
return left.Equals(right);
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,915 +0,0 @@
|
||||||
#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.Math
|
|
||||||
{
|
|
||||||
/// <summary>Represents a 2D vector using two single-precision floating-point numbers.</summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// The Vector2 structure is suitable for interoperation with unmanaged code requiring two consecutive floats.
|
|
||||||
/// </remarks>
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
[Serializable]
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct Vector2 : IEquatable<Vector2>
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The X component of the Vector2.
|
|
||||||
/// </summary>
|
|
||||||
public float X;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The Y component of the Vector2.
|
|
||||||
/// </summary>
|
|
||||||
public float Y;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new Vector2.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">The x coordinate of the net Vector2.</param>
|
|
||||||
/// <param name="y">The y coordinate of the net Vector2.</param>
|
|
||||||
public Vector2(float x, float y)
|
|
||||||
{
|
|
||||||
X = x;
|
|
||||||
Y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new Vector2 from the given Vector2.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="v">The Vector2 to copy components from.</param>
|
|
||||||
[Obsolete]
|
|
||||||
public Vector2(Vector2 v)
|
|
||||||
{
|
|
||||||
X = v.X;
|
|
||||||
Y = v.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new Vector2 from the given Vector3.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="v">The Vector3 to copy components from. Z is discarded.</param>
|
|
||||||
[Obsolete]
|
|
||||||
public Vector2(Vector3 v)
|
|
||||||
{
|
|
||||||
X = v.X;
|
|
||||||
Y = v.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new Vector2 from the given Vector4.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="v">The Vector4 to copy components from. Z and W are discarded.</param>
|
|
||||||
[Obsolete]
|
|
||||||
public Vector2(Vector4 v)
|
|
||||||
{
|
|
||||||
X = v.X;
|
|
||||||
Y = v.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Members
|
|
||||||
|
|
||||||
#region Instance
|
|
||||||
|
|
||||||
#region public void Add()
|
|
||||||
|
|
||||||
/// <summary>Add the Vector passed as parameter to this instance.</summary>
|
|
||||||
/// <param name="right">Right operand. This parameter is only read from.</param>
|
|
||||||
public void Add( Vector2 right )
|
|
||||||
{
|
|
||||||
this.X += right.X;
|
|
||||||
this.Y += right.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Add the Vector passed as parameter to this instance.</summary>
|
|
||||||
/// <param name="right">Right operand. This parameter is only read from.</param>
|
|
||||||
[CLSCompliant(false)]
|
|
||||||
public void Add( ref Vector2 right )
|
|
||||||
{
|
|
||||||
this.X += right.X;
|
|
||||||
this.Y += right.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Add()
|
|
||||||
|
|
||||||
#region public void Sub()
|
|
||||||
|
|
||||||
/// <summary>Subtract the Vector passed as parameter from this instance.</summary>
|
|
||||||
/// <param name="right">Right operand. This parameter is only read from.</param>
|
|
||||||
public void Sub( Vector2 right )
|
|
||||||
{
|
|
||||||
this.X -= right.X;
|
|
||||||
this.Y -= right.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Subtract the Vector passed as parameter from this instance.</summary>
|
|
||||||
/// <param name="right">Right operand. This parameter is only read from.</param>
|
|
||||||
[CLSCompliant(false)]
|
|
||||||
public void Sub( ref Vector2 right )
|
|
||||||
{
|
|
||||||
this.X -= right.X;
|
|
||||||
this.Y -= right.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Sub()
|
|
||||||
|
|
||||||
#region public void Mult()
|
|
||||||
|
|
||||||
/// <summary>Multiply this instance by a scalar.</summary>
|
|
||||||
/// <param name="f">Scalar operand.</param>
|
|
||||||
public void Mult( float f )
|
|
||||||
{
|
|
||||||
this.X *= f;
|
|
||||||
this.Y *= f;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Mult()
|
|
||||||
|
|
||||||
#region public void Div()
|
|
||||||
|
|
||||||
/// <summary>Divide this instance by a scalar.</summary>
|
|
||||||
/// <param name="f">Scalar operand.</param>
|
|
||||||
public void Div( float f )
|
|
||||||
{
|
|
||||||
float mult = 1.0f / f;
|
|
||||||
this.X *= mult;
|
|
||||||
this.Y *= mult;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Div()
|
|
||||||
|
|
||||||
#region public float Length
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the length (magnitude) of the vector.
|
|
||||||
/// </summary>
|
|
||||||
/// <see cref="LengthFast"/>
|
|
||||||
/// <seealso cref="LengthSquared"/>
|
|
||||||
public float Length
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return (float)System.Math.Sqrt(X * X + Y * Y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public float LengthFast
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets an approximation of the vector length (magnitude).
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// This property uses an approximation of the square root function to calculate vector magnitude, with
|
|
||||||
/// an upper error bound of 0.001.
|
|
||||||
/// </remarks>
|
|
||||||
/// <see cref="Length"/>
|
|
||||||
/// <seealso cref="LengthSquared"/>
|
|
||||||
public float LengthFast
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return 1.0f / MathHelper.InverseSqrtFast(X * X + Y * Y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public float LengthSquared
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the square of the vector length (magnitude).
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// This property avoids the costly square root operation required by the Length property. This makes it more suitable
|
|
||||||
/// for comparisons.
|
|
||||||
/// </remarks>
|
|
||||||
/// <see cref="Length"/>
|
|
||||||
/// <seealso cref="LengthFast"/>
|
|
||||||
public float LengthSquared
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return X * X + Y * Y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public Vector2 PerpendicularRight
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the perpendicular vector on the right side of this vector.
|
|
||||||
/// </summary>
|
|
||||||
public Vector2 PerpendicularRight
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return new Vector2(Y, -X);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public Vector2 PerpendicularLeft
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the perpendicular vector on the left side of this vector.
|
|
||||||
/// </summary>
|
|
||||||
public Vector2 PerpendicularLeft
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return new Vector2(-Y, X);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public void Normalize()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scales the Vector2 to unit length.
|
|
||||||
/// </summary>
|
|
||||||
public void Normalize()
|
|
||||||
{
|
|
||||||
float scale = 1.0f / this.Length;
|
|
||||||
X *= scale;
|
|
||||||
Y *= scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public void NormalizeFast()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scales the Vector2 to approximately unit length.
|
|
||||||
/// </summary>
|
|
||||||
public void NormalizeFast()
|
|
||||||
{
|
|
||||||
float scale = Functions.InverseSqrtFast(X * X + Y * Y);
|
|
||||||
X *= scale;
|
|
||||||
Y *= scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public void Scale()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scales the current Vector2 by the given amounts.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sx">The scale of the X component.</param>
|
|
||||||
/// <param name="sy">The scale of the Y component.</param>
|
|
||||||
public void Scale(float sx, float sy)
|
|
||||||
{
|
|
||||||
this.X = X * sx;
|
|
||||||
this.Y = Y * sy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Scales this instance by the given parameter.</summary>
|
|
||||||
/// <param name="scale">The scaling of the individual components.</param>
|
|
||||||
public void Scale( Vector2 scale )
|
|
||||||
{
|
|
||||||
this.X *= scale.X;
|
|
||||||
this.Y *= scale.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Scales this instance by the given parameter.</summary>
|
|
||||||
/// <param name="scale">The scaling of the individual components.</param>
|
|
||||||
[CLSCompliant(false)]
|
|
||||||
public void Scale( ref Vector2 scale )
|
|
||||||
{
|
|
||||||
this.X *= scale.X;
|
|
||||||
this.Y *= scale.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Scale()
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Static
|
|
||||||
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines a unit-length Vector2 that points towards the X-axis.
|
|
||||||
/// </summary>
|
|
||||||
public static readonly Vector2 UnitX = new Vector2(1, 0);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines a unit-length Vector2 that points towards the Y-axis.
|
|
||||||
/// </summary>
|
|
||||||
public static readonly Vector2 UnitY = new Vector2(0, 1);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines a zero-length Vector2.
|
|
||||||
/// </summary>
|
|
||||||
public static readonly Vector2 Zero = new Vector2(0, 0);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines an instance with all components set to 1.
|
|
||||||
/// </summary>
|
|
||||||
public static readonly Vector2 One = new Vector2(1, 1);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines the size of the Vector2 struct in bytes.
|
|
||||||
/// </summary>
|
|
||||||
public static readonly int SizeInBytes = Marshal.SizeOf(new Vector2());
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Add
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add the specified instances
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <returns>Result of addition</returns>
|
|
||||||
public static Vector2 Add(Vector2 a, Vector2 b)
|
|
||||||
{
|
|
||||||
a.X += b.X;
|
|
||||||
a.Y += b.Y;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add two Vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <param name="result">Result of addition</param>
|
|
||||||
public static void Add(ref Vector2 a, ref Vector2 b, out Vector2 result)
|
|
||||||
{
|
|
||||||
result.X = a.X + b.X;
|
|
||||||
result.Y = a.Y + b.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Sub
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Subtract one Vector from another
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <returns>Result of subtraction</returns>
|
|
||||||
public static Vector2 Sub(Vector2 a, Vector2 b)
|
|
||||||
{
|
|
||||||
a.X -= b.X;
|
|
||||||
a.Y -= b.Y;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Subtract one Vector from another
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <param name="result">Result of subtraction</param>
|
|
||||||
public static void Sub(ref Vector2 a, ref Vector2 b, out Vector2 result)
|
|
||||||
{
|
|
||||||
result.X = a.X - b.X;
|
|
||||||
result.Y = a.Y - b.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Mult
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Multiply a vector and a scalar
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">Vector operand</param>
|
|
||||||
/// <param name="f">Scalar operand</param>
|
|
||||||
/// <returns>Result of the multiplication</returns>
|
|
||||||
public static Vector2 Mult(Vector2 a, float f)
|
|
||||||
{
|
|
||||||
a.X *= f;
|
|
||||||
a.Y *= f;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Multiply a vector and a scalar
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">Vector operand</param>
|
|
||||||
/// <param name="f">Scalar operand</param>
|
|
||||||
/// <param name="result">Result of the multiplication</param>
|
|
||||||
public static void Mult(ref Vector2 a, float f, out Vector2 result)
|
|
||||||
{
|
|
||||||
result.X = a.X * f;
|
|
||||||
result.Y = a.Y * f;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Div
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Divide a vector by a scalar
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">Vector operand</param>
|
|
||||||
/// <param name="f">Scalar operand</param>
|
|
||||||
/// <returns>Result of the division</returns>
|
|
||||||
public static Vector2 Div(Vector2 a, float f)
|
|
||||||
{
|
|
||||||
float mult = 1.0f / f;
|
|
||||||
a.X *= mult;
|
|
||||||
a.Y *= mult;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Divide a vector by a scalar
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">Vector operand</param>
|
|
||||||
/// <param name="f">Scalar operand</param>
|
|
||||||
/// <param name="result">Result of the division</param>
|
|
||||||
public static void Div(ref Vector2 a, float f, out Vector2 result)
|
|
||||||
{
|
|
||||||
float mult = 1.0f / f;
|
|
||||||
result.X = a.X * mult;
|
|
||||||
result.Y = a.Y * mult;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region ComponentMin
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the component-wise minimum of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <returns>The component-wise minimum</returns>
|
|
||||||
public static Vector2 ComponentMin(Vector2 a, Vector2 b)
|
|
||||||
{
|
|
||||||
a.X = a.X < b.X ? a.X : b.X;
|
|
||||||
a.Y = a.Y < b.Y ? a.Y : b.Y;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the component-wise minimum of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <param name="result">The component-wise minimum</param>
|
|
||||||
public static void ComponentMin(ref Vector2 a, ref Vector2 b, out Vector2 result)
|
|
||||||
{
|
|
||||||
result.X = a.X < b.X ? a.X : b.X;
|
|
||||||
result.Y = a.Y < b.Y ? a.Y : b.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region ComponentMax
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the component-wise maximum of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <returns>The component-wise maximum</returns>
|
|
||||||
public static Vector2 ComponentMax(Vector2 a, Vector2 b)
|
|
||||||
{
|
|
||||||
a.X = a.X > b.X ? a.X : b.X;
|
|
||||||
a.Y = a.Y > b.Y ? a.Y : b.Y;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the component-wise maximum of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <param name="result">The component-wise maximum</param>
|
|
||||||
public static void ComponentMax(ref Vector2 a, ref Vector2 b, out Vector2 result)
|
|
||||||
{
|
|
||||||
result.X = a.X > b.X ? a.X : b.X;
|
|
||||||
result.Y = a.Y > b.Y ? a.Y : b.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Min
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the Vector3 with the minimum magnitude
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">Left operand</param>
|
|
||||||
/// <param name="right">Right operand</param>
|
|
||||||
/// <returns>The minimum Vector3</returns>
|
|
||||||
public static Vector2 Min(Vector2 left, Vector2 right)
|
|
||||||
{
|
|
||||||
return left.LengthSquared < right.LengthSquared ? left : right;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Max
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the Vector3 with the minimum magnitude
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">Left operand</param>
|
|
||||||
/// <param name="right">Right operand</param>
|
|
||||||
/// <returns>The minimum Vector3</returns>
|
|
||||||
public static Vector2 Max(Vector2 left, Vector2 right)
|
|
||||||
{
|
|
||||||
return left.LengthSquared >= right.LengthSquared ? left : right;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Clamp
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clamp a vector to the given minimum and maximum vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">Input vector</param>
|
|
||||||
/// <param name="min">Minimum vector</param>
|
|
||||||
/// <param name="max">Maximum vector</param>
|
|
||||||
/// <returns>The clamped vector</returns>
|
|
||||||
public static Vector2 Clamp(Vector2 vec, Vector2 min, Vector2 max)
|
|
||||||
{
|
|
||||||
vec.X = vec.X < min.X ? min.X : vec.X > max.X ? max.X : vec.X;
|
|
||||||
vec.Y = vec.Y < min.Y ? min.Y : vec.Y > max.Y ? max.Y : vec.Y;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clamp a vector to the given minimum and maximum vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">Input vector</param>
|
|
||||||
/// <param name="min">Minimum vector</param>
|
|
||||||
/// <param name="max">Maximum vector</param>
|
|
||||||
/// <param name="result">The clamped vector</param>
|
|
||||||
public static void Clamp(ref Vector2 vec, ref Vector2 min, ref Vector2 max, out Vector2 result)
|
|
||||||
{
|
|
||||||
result.X = vec.X < min.X ? min.X : vec.X > max.X ? max.X : vec.X;
|
|
||||||
result.Y = vec.Y < min.Y ? min.Y : vec.Y > max.Y ? max.Y : vec.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Normalize
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scale a vector to unit length
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The input vector</param>
|
|
||||||
/// <returns>The normalized vector</returns>
|
|
||||||
public static Vector2 Normalize(Vector2 vec)
|
|
||||||
{
|
|
||||||
float scale = 1.0f / vec.Length;
|
|
||||||
vec.X *= scale;
|
|
||||||
vec.Y *= scale;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scale a vector to unit length
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The input vector</param>
|
|
||||||
/// <param name="result">The normalized vector</param>
|
|
||||||
public static void Normalize(ref Vector2 vec, out Vector2 result)
|
|
||||||
{
|
|
||||||
float scale = 1.0f / vec.Length;
|
|
||||||
result.X = vec.X * scale;
|
|
||||||
result.Y = vec.Y * scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region NormalizeFast
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scale a vector to approximately unit length
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The input vector</param>
|
|
||||||
/// <returns>The normalized vector</returns>
|
|
||||||
public static Vector2 NormalizeFast(Vector2 vec)
|
|
||||||
{
|
|
||||||
float scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);
|
|
||||||
vec.X *= scale;
|
|
||||||
vec.Y *= scale;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scale a vector to approximately unit length
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The input vector</param>
|
|
||||||
/// <param name="result">The normalized vector</param>
|
|
||||||
public static void NormalizeFast(ref Vector2 vec, out Vector2 result)
|
|
||||||
{
|
|
||||||
float scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);
|
|
||||||
result.X = vec.X * scale;
|
|
||||||
result.Y = vec.Y * scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Dot
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the dot (scalar) product of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">First operand</param>
|
|
||||||
/// <param name="right">Second operand</param>
|
|
||||||
/// <returns>The dot product of the two inputs</returns>
|
|
||||||
public static float Dot(Vector2 left, Vector2 right)
|
|
||||||
{
|
|
||||||
return left.X * right.X + left.Y * right.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the dot (scalar) product of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">First operand</param>
|
|
||||||
/// <param name="right">Second operand</param>
|
|
||||||
/// <param name="result">The dot product of the two inputs</param>
|
|
||||||
public static void Dot( ref Vector2 left, ref Vector2 right, out float result )
|
|
||||||
{
|
|
||||||
result = left.X * right.X + left.Y * right.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Lerp
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a new Vector that is the linear blend of the 2 given Vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First input vector</param>
|
|
||||||
/// <param name="b">Second input vector</param>
|
|
||||||
/// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
|
|
||||||
/// <returns>a when blend=0, b when blend=1, and a linear combination otherwise</returns>
|
|
||||||
public static Vector2 Lerp(Vector2 a, Vector2 b, float blend)
|
|
||||||
{
|
|
||||||
a.X = blend * (b.X - a.X) + a.X;
|
|
||||||
a.Y = blend * (b.Y - a.Y) + a.Y;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a new Vector that is the linear blend of the 2 given Vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First input vector</param>
|
|
||||||
/// <param name="b">Second input vector</param>
|
|
||||||
/// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
|
|
||||||
/// <param name="result">a when blend=0, b when blend=1, and a linear combination otherwise</param>
|
|
||||||
public static void Lerp( ref Vector2 a, ref Vector2 b, float blend, out Vector2 result )
|
|
||||||
{
|
|
||||||
result.X = blend * ( b.X - a.X ) + a.X;
|
|
||||||
result.Y = blend * ( b.Y - a.Y ) + a.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Barycentric
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Interpolate 3 Vectors using Barycentric coordinates
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First input Vector</param>
|
|
||||||
/// <param name="b">Second input Vector</param>
|
|
||||||
/// <param name="c">Third input Vector</param>
|
|
||||||
/// <param name="u">First Barycentric Coordinate</param>
|
|
||||||
/// <param name="v">Second Barycentric Coordinate</param>
|
|
||||||
/// <returns>a when u=v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise</returns>
|
|
||||||
public static Vector2 BaryCentric(Vector2 a, Vector2 b, Vector2 c, float u, float v)
|
|
||||||
{
|
|
||||||
return a + u * (b - a) + v * (c - a);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Interpolate 3 Vectors using Barycentric coordinates</summary>
|
|
||||||
/// <param name="a">First input Vector.</param>
|
|
||||||
/// <param name="b">Second input Vector.</param>
|
|
||||||
/// <param name="c">Third input Vector.</param>
|
|
||||||
/// <param name="u">First Barycentric Coordinate.</param>
|
|
||||||
/// <param name="v">Second Barycentric Coordinate.</param>
|
|
||||||
/// <param name="result">Output Vector. a when u=v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise</param>
|
|
||||||
public static void BaryCentric( ref Vector2 a, ref Vector2 b, ref Vector2 c, float u, float v, out Vector2 result )
|
|
||||||
{
|
|
||||||
result = a; // copy
|
|
||||||
|
|
||||||
Vector2 temp = b; // copy
|
|
||||||
temp.Sub( ref a );
|
|
||||||
temp.Mult( u );
|
|
||||||
result.Add( ref temp );
|
|
||||||
|
|
||||||
temp = c; // copy
|
|
||||||
temp.Sub( ref a );
|
|
||||||
temp.Mult( v );
|
|
||||||
result.Add( ref temp );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Operators
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds the specified instances.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">Left operand.</param>
|
|
||||||
/// <param name="right">Right operand.</param>
|
|
||||||
/// <returns>Result of addition.</returns>
|
|
||||||
public static Vector2 operator +(Vector2 left, Vector2 right)
|
|
||||||
{
|
|
||||||
left.X += right.X;
|
|
||||||
left.Y += right.Y;
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Subtracts the specified instances.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">Left operand.</param>
|
|
||||||
/// <param name="right">Right operand.</param>
|
|
||||||
/// <returns>Result of subtraction.</returns>
|
|
||||||
public static Vector2 operator -(Vector2 left, Vector2 right)
|
|
||||||
{
|
|
||||||
left.X -= right.X;
|
|
||||||
left.Y -= right.Y;
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Negates the specified instance.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">Operand.</param>
|
|
||||||
/// <returns>Result of negation.</returns>
|
|
||||||
public static Vector2 operator -(Vector2 vec)
|
|
||||||
{
|
|
||||||
vec.X = -vec.X;
|
|
||||||
vec.Y = -vec.Y;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Multiplies the specified instance by a scalar.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">Left operand.</param>
|
|
||||||
/// <param name="scale">Right operand.</param>
|
|
||||||
/// <returns>Result of multiplication.</returns>
|
|
||||||
public static Vector2 operator *(Vector2 vec, float scale)
|
|
||||||
{
|
|
||||||
vec.X *= scale;
|
|
||||||
vec.Y *= scale;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Multiplies the specified instance by a scalar.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="scale">Left operand.</param>
|
|
||||||
/// <param name="vec">Right operand.</param>
|
|
||||||
/// <returns>Result of multiplication.</returns>
|
|
||||||
public static Vector2 operator *(float scale, Vector2 vec)
|
|
||||||
{
|
|
||||||
vec.X *= scale;
|
|
||||||
vec.Y *= scale;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Divides the specified instance by a scalar.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">Left operand</param>
|
|
||||||
/// <param name="scale">Right operand</param>
|
|
||||||
/// <returns>Result of the division.</returns>
|
|
||||||
public static Vector2 operator /(Vector2 vec, float scale)
|
|
||||||
{
|
|
||||||
float mult = 1.0f / scale;
|
|
||||||
vec.X *= mult;
|
|
||||||
vec.Y *= mult;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Compares the specified instances for equality.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">Left operand.</param>
|
|
||||||
/// <param name="right">Right operand.</param>
|
|
||||||
/// <returns>True if both instances are equal; false otherwise.</returns>
|
|
||||||
public static bool operator ==(Vector2 left, Vector2 right)
|
|
||||||
{
|
|
||||||
return left.Equals(right);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Compares the specified instances for inequality.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">Left operand.</param>
|
|
||||||
/// <param name="right">Right operand.</param>
|
|
||||||
/// <returns>True if both instances are not equal; false otherwise.</returns>
|
|
||||||
public static bool operator !=(Vector2 left, Vector2 right)
|
|
||||||
{
|
|
||||||
return !left.Equals(right);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Overrides
|
|
||||||
|
|
||||||
#region public override string ToString()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a System.String that represents the current Vector2.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return String.Format("({0}, {1})", X, Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override int GetHashCode()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the hashcode for this instance.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return X.GetHashCode() ^ Y.GetHashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override bool Equals(object obj)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Indicates whether this instance and a specified object are equal.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="obj">The object to compare to.</param>
|
|
||||||
/// <returns>True if the instances are equal; false otherwise.</returns>
|
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
|
||||||
if (!(obj is Vector2))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return this.Equals((Vector2)obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IEquatable<Vector2> Members
|
|
||||||
|
|
||||||
/// <summary>Indicates whether the current vector is equal to another vector.</summary>
|
|
||||||
/// <param name="other">A vector to compare with this vector.</param>
|
|
||||||
/// <returns>true if the current vector is equal to the vector parameter; otherwise, false.</returns>
|
|
||||||
public bool Equals(Vector2 other)
|
|
||||||
{
|
|
||||||
return
|
|
||||||
X == other.X &&
|
|
||||||
Y == other.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,818 +0,0 @@
|
||||||
#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.Math
|
|
||||||
{
|
|
||||||
/// <summary>Represents a 2D vector using two double-precision floating-point numbers.</summary>
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
[Serializable]
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct Vector2d : IEquatable<Vector2d>
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
/// <summary>The X coordinate of this instance.</summary>
|
|
||||||
public double X;
|
|
||||||
|
|
||||||
/// <summary>The Y coordinate of this instance.</summary>
|
|
||||||
public double Y;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines a unit-length Vector2d that points towards the X-axis.
|
|
||||||
/// </summary>
|
|
||||||
public static Vector2d UnitX = new Vector2d(1, 0);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines a unit-length Vector2d that points towards the Y-axis.
|
|
||||||
/// </summary>
|
|
||||||
public static Vector2d UnitY = new Vector2d(0, 1);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines a zero-length Vector2d.
|
|
||||||
/// </summary>
|
|
||||||
public static Vector2d Zero = new Vector2d(0, 0);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines an instance with all components set to 1.
|
|
||||||
/// </summary>
|
|
||||||
public static readonly Vector2d One = new Vector2d(1, 1);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines the size of the Vector2d struct in bytes.
|
|
||||||
/// </summary>
|
|
||||||
public static readonly int SizeInBytes = Marshal.SizeOf(new Vector2d());
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
/// <summary>Constructs left vector with the given coordinates.</summary>
|
|
||||||
/// <param name="x">The X coordinate.</param>
|
|
||||||
/// <param name="y">The Y coordinate.</param>
|
|
||||||
public Vector2d(double x, double y)
|
|
||||||
{
|
|
||||||
this.X = x;
|
|
||||||
this.Y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Members
|
|
||||||
|
|
||||||
#region Instance
|
|
||||||
|
|
||||||
#region public void Add()
|
|
||||||
|
|
||||||
/// <summary>Add the Vector passed as parameter to this instance.</summary>
|
|
||||||
/// <param name="right">Right operand. This parameter is only read from.</param>
|
|
||||||
public void Add(Vector2d right)
|
|
||||||
{
|
|
||||||
this.X += right.X;
|
|
||||||
this.Y += right.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Add the Vector passed as parameter to this instance.</summary>
|
|
||||||
/// <param name="right">Right operand. This parameter is only read from.</param>
|
|
||||||
[CLSCompliant(false)]
|
|
||||||
public void Add(ref Vector2d right)
|
|
||||||
{
|
|
||||||
this.X += right.X;
|
|
||||||
this.Y += right.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Add()
|
|
||||||
|
|
||||||
#region public void Sub()
|
|
||||||
|
|
||||||
/// <summary>Subtract the Vector passed as parameter from this instance.</summary>
|
|
||||||
/// <param name="right">Right operand. This parameter is only read from.</param>
|
|
||||||
public void Sub(Vector2d right)
|
|
||||||
{
|
|
||||||
this.X -= right.X;
|
|
||||||
this.Y -= right.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Subtract the Vector passed as parameter from this instance.</summary>
|
|
||||||
/// <param name="right">Right operand. This parameter is only read from.</param>
|
|
||||||
[CLSCompliant(false)]
|
|
||||||
public void Sub(ref Vector2d right)
|
|
||||||
{
|
|
||||||
this.X -= right.X;
|
|
||||||
this.Y -= right.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Sub()
|
|
||||||
|
|
||||||
#region public void Mult()
|
|
||||||
|
|
||||||
/// <summary>Multiply this instance by a scalar.</summary>
|
|
||||||
/// <param name="f">Scalar operand.</param>
|
|
||||||
public void Mult(double f)
|
|
||||||
{
|
|
||||||
this.X *= f;
|
|
||||||
this.Y *= f;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Mult()
|
|
||||||
|
|
||||||
#region public void Div()
|
|
||||||
|
|
||||||
/// <summary>Divide this instance by a scalar.</summary>
|
|
||||||
/// <param name="f">Scalar operand.</param>
|
|
||||||
public void Div(double f)
|
|
||||||
{
|
|
||||||
double mult = 1.0 / f;
|
|
||||||
this.X *= mult;
|
|
||||||
this.Y *= mult;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Div()
|
|
||||||
|
|
||||||
#region public double Length
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the length (magnitude) of the vector.
|
|
||||||
/// </summary>
|
|
||||||
/// <seealso cref="LengthSquared"/>
|
|
||||||
public double Length
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return (float)System.Math.Sqrt(X * X + Y * Y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public double LengthSquared
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the square of the vector length (magnitude).
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// This property avoids the costly square root operation required by the Length property. This makes it more suitable
|
|
||||||
/// for comparisons.
|
|
||||||
/// </remarks>
|
|
||||||
/// <see cref="Length"/>
|
|
||||||
public double LengthSquared
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return X * X + Y * Y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public Vector2d PerpendicularRight
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the perpendicular vector on the right side of this vector.
|
|
||||||
/// </summary>
|
|
||||||
public Vector2d PerpendicularRight
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return new Vector2d(Y, -X);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public Vector2d PerpendicularLeft
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the perpendicular vector on the left side of this vector.
|
|
||||||
/// </summary>
|
|
||||||
public Vector2d PerpendicularLeft
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return new Vector2d(-Y, X);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public void Normalize()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scales the Vector2 to unit length.
|
|
||||||
/// </summary>
|
|
||||||
public void Normalize()
|
|
||||||
{
|
|
||||||
double scale = 1.0f / Length;
|
|
||||||
X *= scale;
|
|
||||||
Y *= scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public void Scale()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scales the current Vector2 by the given amounts.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sx">The scale of the X component.</param>
|
|
||||||
/// <param name="sy">The scale of the Y component.</param>
|
|
||||||
public void Scale(double sx, double sy)
|
|
||||||
{
|
|
||||||
X *= sx;
|
|
||||||
Y *= sy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Scales this instance by the given parameter.</summary>
|
|
||||||
/// <param name="scale">The scaling of the individual components.</param>
|
|
||||||
public void Scale(Vector2d scale)
|
|
||||||
{
|
|
||||||
this.X *= scale.X;
|
|
||||||
this.Y *= scale.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Scales this instance by the given parameter.</summary>
|
|
||||||
/// <param name="scale">The scaling of the individual components.</param>
|
|
||||||
[CLSCompliant(false)]
|
|
||||||
public void Scale(ref Vector2d scale)
|
|
||||||
{
|
|
||||||
this.X *= scale.X;
|
|
||||||
this.Y *= scale.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Scale()
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Static
|
|
||||||
|
|
||||||
#region Add
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add two Vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <returns>Result of addition</returns>
|
|
||||||
public static Vector2d Add(Vector2d a, Vector2d b)
|
|
||||||
{
|
|
||||||
a.X += b.X;
|
|
||||||
a.Y += b.Y;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add two Vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <param name="result">Result of addition</param>
|
|
||||||
public static void Add(ref Vector2d a, ref Vector2d b, out Vector2d result)
|
|
||||||
{
|
|
||||||
result.X = a.X + b.X;
|
|
||||||
result.Y = a.Y + b.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Sub
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Subtract one Vector from another
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <returns>Result of subtraction</returns>
|
|
||||||
public static Vector2d Sub(Vector2d a, Vector2d b)
|
|
||||||
{
|
|
||||||
a.X -= b.X;
|
|
||||||
a.Y -= b.Y;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Subtract one Vector from another
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <param name="result">Result of subtraction</param>
|
|
||||||
public static void Sub(ref Vector2d a, ref Vector2d b, out Vector2d result)
|
|
||||||
{
|
|
||||||
result.X = a.X - b.X;
|
|
||||||
result.Y = a.Y - b.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Mult
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Multiply a vector and a scalar
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">Vector operand</param>
|
|
||||||
/// <param name="d">Scalar operand</param>
|
|
||||||
/// <returns>Result of the multiplication</returns>
|
|
||||||
public static Vector2d Mult(Vector2d a, double d)
|
|
||||||
{
|
|
||||||
a.X *= d;
|
|
||||||
a.Y *= d;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Multiply a vector and a scalar
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">Vector operand</param>
|
|
||||||
/// <param name="d">Scalar operand</param>
|
|
||||||
/// <param name="result">Result of the multiplication</param>
|
|
||||||
public static void Mult(ref Vector2d a, double d, out Vector2d result)
|
|
||||||
{
|
|
||||||
result.X = a.X * d;
|
|
||||||
result.Y = a.Y * d;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Div
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Divide a vector by a scalar
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">Vector operand</param>
|
|
||||||
/// <param name="d">Scalar operand</param>
|
|
||||||
/// <returns>Result of the division</returns>
|
|
||||||
public static Vector2d Div(Vector2d a, double d)
|
|
||||||
{
|
|
||||||
double mult = 1.0 / d;
|
|
||||||
a.X *= mult;
|
|
||||||
a.Y *= mult;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Divide a vector by a scalar
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">Vector operand</param>
|
|
||||||
/// <param name="d">Scalar operand</param>
|
|
||||||
/// <param name="result">Result of the division</param>
|
|
||||||
public static void Div(ref Vector2d a, double d, out Vector2d result)
|
|
||||||
{
|
|
||||||
double mult = 1.0 / d;
|
|
||||||
result.X = a.X * mult;
|
|
||||||
result.Y = a.Y * mult;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Min
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the component-wise minimum of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <returns>The component-wise minimum</returns>
|
|
||||||
public static Vector2d Min(Vector2d a, Vector2d b)
|
|
||||||
{
|
|
||||||
a.X = a.X < b.X ? a.X : b.X;
|
|
||||||
a.Y = a.Y < b.Y ? a.Y : b.Y;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the component-wise minimum of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <param name="result">The component-wise minimum</param>
|
|
||||||
public static void Min(ref Vector2d a, ref Vector2d b, out Vector2d result)
|
|
||||||
{
|
|
||||||
result.X = a.X < b.X ? a.X : b.X;
|
|
||||||
result.Y = a.Y < b.Y ? a.Y : b.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Max
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the component-wise maximum of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <returns>The component-wise maximum</returns>
|
|
||||||
public static Vector2d Max(Vector2d a, Vector2d b)
|
|
||||||
{
|
|
||||||
a.X = a.X > b.X ? a.X : b.X;
|
|
||||||
a.Y = a.Y > b.Y ? a.Y : b.Y;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the component-wise maximum of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <param name="result">The component-wise maximum</param>
|
|
||||||
public static void Max(ref Vector2d a, ref Vector2d b, out Vector2d result)
|
|
||||||
{
|
|
||||||
result.X = a.X > b.X ? a.X : b.X;
|
|
||||||
result.Y = a.Y > b.Y ? a.Y : b.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Clamp
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clamp a vector to the given minimum and maximum vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">Input vector</param>
|
|
||||||
/// <param name="min">Minimum vector</param>
|
|
||||||
/// <param name="max">Maximum vector</param>
|
|
||||||
/// <returns>The clamped vector</returns>
|
|
||||||
public static Vector2d Clamp(Vector2d vec, Vector2d min, Vector2d max)
|
|
||||||
{
|
|
||||||
vec.X = vec.X < min.X ? min.X : vec.X > max.X ? max.X : vec.X;
|
|
||||||
vec.Y = vec.Y < min.Y ? min.Y : vec.Y > max.Y ? max.Y : vec.Y;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clamp a vector to the given minimum and maximum vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">Input vector</param>
|
|
||||||
/// <param name="min">Minimum vector</param>
|
|
||||||
/// <param name="max">Maximum vector</param>
|
|
||||||
/// <param name="result">The clamped vector</param>
|
|
||||||
public static void Clamp(ref Vector2d vec, ref Vector2d min, ref Vector2d max, out Vector2d result)
|
|
||||||
{
|
|
||||||
result.X = vec.X < min.X ? min.X : vec.X > max.X ? max.X : vec.X;
|
|
||||||
result.Y = vec.Y < min.Y ? min.Y : vec.Y > max.Y ? max.Y : vec.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Normalize
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scale a vector to unit length
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The input vector</param>
|
|
||||||
/// <returns>The normalized vector</returns>
|
|
||||||
public static Vector2d Normalize(Vector2d vec)
|
|
||||||
{
|
|
||||||
double scale = 1.0f / vec.Length;
|
|
||||||
vec.X *= scale;
|
|
||||||
vec.Y *= scale;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scale a vector to unit length
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The input vector</param>
|
|
||||||
/// <param name="result">The normalized vector</param>
|
|
||||||
public static void Normalize(ref Vector2d vec, out Vector2d result)
|
|
||||||
{
|
|
||||||
double scale = 1.0f / vec.Length;
|
|
||||||
result.X = vec.X * scale;
|
|
||||||
result.Y = vec.Y * scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region NormalizeFast
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scale a vector to approximately unit length
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The input vector</param>
|
|
||||||
/// <returns>The normalized vector</returns>
|
|
||||||
public static Vector2d NormalizeFast(Vector2d vec)
|
|
||||||
{
|
|
||||||
double scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);
|
|
||||||
vec.X *= scale;
|
|
||||||
vec.Y *= scale;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scale a vector to approximately unit length
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The input vector</param>
|
|
||||||
/// <param name="result">The normalized vector</param>
|
|
||||||
public static void NormalizeFast(ref Vector2d vec, out Vector2d result)
|
|
||||||
{
|
|
||||||
double scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);
|
|
||||||
result.X = vec.X * scale;
|
|
||||||
result.Y = vec.Y * scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Dot
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the dot (scalar) product of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">First operand</param>
|
|
||||||
/// <param name="right">Second operand</param>
|
|
||||||
/// <returns>The dot product of the two inputs</returns>
|
|
||||||
public static double Dot(Vector2d left, Vector2d right)
|
|
||||||
{
|
|
||||||
return left.X * right.X + left.Y * right.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the dot (scalar) product of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">First operand</param>
|
|
||||||
/// <param name="right">Second operand</param>
|
|
||||||
/// <param name="result">The dot product of the two inputs</param>
|
|
||||||
public static void Dot(ref Vector2d left, ref Vector2d right, out double result)
|
|
||||||
{
|
|
||||||
result = left.X * right.X + left.Y * right.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Lerp
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a new Vector that is the linear blend of the 2 given Vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First input vector</param>
|
|
||||||
/// <param name="b">Second input vector</param>
|
|
||||||
/// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
|
|
||||||
/// <returns>a when blend=0, b when blend=1, and a linear combination otherwise</returns>
|
|
||||||
public static Vector2d Lerp(Vector2d a, Vector2d b, double blend)
|
|
||||||
{
|
|
||||||
a.X = blend * (b.X - a.X) + a.X;
|
|
||||||
a.Y = blend * (b.Y - a.Y) + a.Y;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a new Vector that is the linear blend of the 2 given Vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First input vector</param>
|
|
||||||
/// <param name="b">Second input vector</param>
|
|
||||||
/// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
|
|
||||||
/// <param name="result">a when blend=0, b when blend=1, and a linear combination otherwise</param>
|
|
||||||
public static void Lerp(ref Vector2d a, ref Vector2d b, double blend, out Vector2d result)
|
|
||||||
{
|
|
||||||
result.X = blend * (b.X - a.X) + a.X;
|
|
||||||
result.Y = blend * (b.Y - a.Y) + a.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Barycentric
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Interpolate 3 Vectors using Barycentric coordinates
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First input Vector</param>
|
|
||||||
/// <param name="b">Second input Vector</param>
|
|
||||||
/// <param name="c">Third input Vector</param>
|
|
||||||
/// <param name="u">First Barycentric Coordinate</param>
|
|
||||||
/// <param name="v">Second Barycentric Coordinate</param>
|
|
||||||
/// <returns>a when u=v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise</returns>
|
|
||||||
public static Vector2d BaryCentric(Vector2d a, Vector2d b, Vector2d c, double u, double v)
|
|
||||||
{
|
|
||||||
return a + u * (b - a) + v * (c - a);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Interpolate 3 Vectors using Barycentric coordinates</summary>
|
|
||||||
/// <param name="a">First input Vector.</param>
|
|
||||||
/// <param name="b">Second input Vector.</param>
|
|
||||||
/// <param name="c">Third input Vector.</param>
|
|
||||||
/// <param name="u">First Barycentric Coordinate.</param>
|
|
||||||
/// <param name="v">Second Barycentric Coordinate.</param>
|
|
||||||
/// <param name="result">Output Vector. a when u=v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise</param>
|
|
||||||
public static void BaryCentric(ref Vector2d a, ref Vector2d b, ref Vector2d c, float u, float v, out Vector2d result)
|
|
||||||
{
|
|
||||||
result = a; // copy
|
|
||||||
|
|
||||||
Vector2d temp = b; // copy
|
|
||||||
temp.Sub(ref a);
|
|
||||||
temp.Mult(u);
|
|
||||||
result.Add(ref temp);
|
|
||||||
|
|
||||||
temp = c; // copy
|
|
||||||
temp.Sub(ref a);
|
|
||||||
temp.Mult(v);
|
|
||||||
result.Add(ref temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Operators
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds 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 Vector2d operator +(Vector2d left, Vector2d right)
|
|
||||||
{
|
|
||||||
left.X += right.X;
|
|
||||||
left.Y += right.Y;
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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 Vector2d operator -(Vector2d left, Vector2d right)
|
|
||||||
{
|
|
||||||
left.X -= right.X;
|
|
||||||
left.Y -= right.Y;
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Negates an instance.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The instance.</param>
|
|
||||||
/// <returns>The result of the operation.</returns>
|
|
||||||
public static Vector2d operator -(Vector2d vec)
|
|
||||||
{
|
|
||||||
vec.X = -vec.X;
|
|
||||||
vec.Y = -vec.Y;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Multiplies an instance by a scalar.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The instance.</param>
|
|
||||||
/// <param name="f">The scalar.</param>
|
|
||||||
/// <returns>The result of the operation.</returns>
|
|
||||||
public static Vector2d operator *(Vector2d vec, double f)
|
|
||||||
{
|
|
||||||
vec.X *= f;
|
|
||||||
vec.Y *= f;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Multiply an instance by a scalar.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="f">The scalar.</param>
|
|
||||||
/// <param name="vec">The instance.</param>
|
|
||||||
/// <returns>The result of the operation.</returns>
|
|
||||||
public static Vector2d operator *(double f, Vector2d vec)
|
|
||||||
{
|
|
||||||
vec.X *= f;
|
|
||||||
vec.Y *= f;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Divides an instance by a scalar.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The instance.</param>
|
|
||||||
/// <param name="f">The scalar.</param>
|
|
||||||
/// <returns>The result of the operation.</returns>
|
|
||||||
public static Vector2d operator /(Vector2d vec, double f)
|
|
||||||
{
|
|
||||||
double mult = 1.0f / f;
|
|
||||||
vec.X *= mult;
|
|
||||||
vec.Y *= mult;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Compares two instances for equality.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">The left instance.</param>
|
|
||||||
/// <param name="right">The right instance.</param>
|
|
||||||
/// <returns>True, if both instances are equal; false otherwise.</returns>
|
|
||||||
public static bool operator ==(Vector2d left, Vector2d right)
|
|
||||||
{
|
|
||||||
return left.Equals(right);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Compares two instances for ienquality.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">The left instance.</param>
|
|
||||||
/// <param name="right">The right instance.</param>
|
|
||||||
/// <returns>True, if the instances are not equal; false otherwise.</returns>
|
|
||||||
public static bool operator !=(Vector2d left, Vector2d right)
|
|
||||||
{
|
|
||||||
return !left.Equals(right);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Converts OpenTK.Vector2 to OpenTK.Vector2d.</summary>
|
|
||||||
/// <param name="v2">The Vector2 to convert.</param>
|
|
||||||
/// <returns>The resulting Vector2d.</returns>
|
|
||||||
public static explicit operator Vector2d(Vector2 v2)
|
|
||||||
{
|
|
||||||
return new Vector2d(v2.X, v2.Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Converts OpenTK.Vector2d to OpenTK.Vector2.</summary>
|
|
||||||
/// <param name="v2d">The Vector2d to convert.</param>
|
|
||||||
/// <returns>The resulting Vector2.</returns>
|
|
||||||
public static explicit operator Vector2(Vector2d v2d)
|
|
||||||
{
|
|
||||||
return new Vector2((float)v2d.X, (float)v2d.Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Overrides
|
|
||||||
|
|
||||||
#region public override string ToString()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a System.String that represents the current instance.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return String.Format("({0}, {1})", X, Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override int GetHashCode()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the hashcode for this instance.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return X.GetHashCode() ^ Y.GetHashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override bool Equals(object obj)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Indicates whether this instance and a specified object are equal.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="obj">The object to compare to.</param>
|
|
||||||
/// <returns>True if the instances are equal; false otherwise.</returns>
|
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
|
||||||
if (!(obj is Vector2d))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return this.Equals((Vector2d)obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IEquatable<Vector2d> Members
|
|
||||||
|
|
||||||
/// <summary>Indicates whether the current vector is equal to another vector.</summary>
|
|
||||||
/// <param name="other">A vector to compare with this vector.</param>
|
|
||||||
/// <returns>true if the current vector is equal to the vector parameter; otherwise, false.</returns>
|
|
||||||
public bool Equals(Vector2d other)
|
|
||||||
{
|
|
||||||
return
|
|
||||||
X == other.X &&
|
|
||||||
Y == other.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,337 +0,0 @@
|
||||||
#region --- License ---
|
|
||||||
/*
|
|
||||||
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
|
||||||
the Software without restriction, including without limitation the rights to
|
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
||||||
of the Software, and to permit persons to whom the Software is furnished to do
|
|
||||||
so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
namespace OpenTK.Math
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>2-component Vector of the Half type. Occupies 4 Byte total.</summary>
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
[Serializable, StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct Vector2h : ISerializable, IEquatable<Vector2h>
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
/// <summary>The X component of the Half2.</summary>
|
|
||||||
public Half X;
|
|
||||||
|
|
||||||
/// <summary>The Y component of the Half2.</summary>
|
|
||||||
public Half Y;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The new Half2 instance will avoid conversion and copy directly from the Half parameters.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">An Half instance of a 16-bit half-precision floating-point number.</param>
|
|
||||||
/// <param name="y">An Half instance of a 16-bit half-precision floating-point number.</param>
|
|
||||||
public Vector2h(Half x, Half y)
|
|
||||||
{
|
|
||||||
X = x;
|
|
||||||
Y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The new Half2 instance will convert the 2 parameters into 16-bit half-precision floating-point.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="y">32-bit single-precision floating-point number.</param>
|
|
||||||
public Vector2h(Single x, Single y)
|
|
||||||
{
|
|
||||||
X = new Half(x);
|
|
||||||
Y = new Half(y);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The new Half2 instance will convert the 2 parameters into 16-bit half-precision floating-point.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="y">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
|
|
||||||
public Vector2h(Single x, Single y, bool throwOnError)
|
|
||||||
{
|
|
||||||
X = new Half(x, throwOnError);
|
|
||||||
Y = new Half(y, throwOnError);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The new Half2 instance will convert the Vector2 into 16-bit half-precision floating-point.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="v">OpenTK.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
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,382 +0,0 @@
|
||||||
#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;
|
|
||||||
|
|
||||||
namespace OpenTK.Math
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 3-component Vector of the Half type. Occupies 6 Byte total.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
[Serializable, StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct Vector3h : ISerializable, IEquatable<Vector3h>
|
|
||||||
{
|
|
||||||
#region Public Fields
|
|
||||||
|
|
||||||
/// <summary>The X component of the Half3.</summary>
|
|
||||||
public Half X;
|
|
||||||
|
|
||||||
/// <summary>The Y component of the Half3.</summary>
|
|
||||||
public Half Y;
|
|
||||||
|
|
||||||
/// <summary>The Z component of the Half3.</summary>
|
|
||||||
public Half Z;
|
|
||||||
|
|
||||||
#endregion Public Fields
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The new Half3 instance will avoid conversion and copy directly from the Half parameters.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">An Half instance of a 16-bit half-precision floating-point number.</param>
|
|
||||||
/// <param name="y">An Half instance of a 16-bit half-precision floating-point number.</param>
|
|
||||||
/// <param name="z">An Half instance of a 16-bit half-precision floating-point number.</param>
|
|
||||||
public Vector3h(Half x, Half y, Half z)
|
|
||||||
{
|
|
||||||
this.X = x;
|
|
||||||
this.Y = y;
|
|
||||||
this.Z = z;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The new Half3 instance will convert the 3 parameters into 16-bit half-precision floating-point.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="y">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="z">32-bit single-precision floating-point number.</param>
|
|
||||||
public Vector3h(Single x, Single y, Single z)
|
|
||||||
{
|
|
||||||
X = new Half(x);
|
|
||||||
Y = new Half(y);
|
|
||||||
Z = new Half(z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The new Half3 instance will convert the 3 parameters into 16-bit half-precision floating-point.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="y">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="z">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
|
|
||||||
public Vector3h(Single x, Single y, Single z, bool throwOnError)
|
|
||||||
{
|
|
||||||
X = new Half(x, throwOnError);
|
|
||||||
Y = new Half(y, throwOnError);
|
|
||||||
Z = new Half(z, throwOnError);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The new Half3 instance will convert the Vector3 into 16-bit half-precision floating-point.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="v">OpenTK.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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,998 +0,0 @@
|
||||||
#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.Xml.Serialization;
|
|
||||||
|
|
||||||
namespace OpenTK.Math
|
|
||||||
{
|
|
||||||
/// <summary>Represents a 4D vector using four single-precision floating-point numbers.</summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// The Vector4 structure is suitable for interoperation with unmanaged code requiring four consecutive floats.
|
|
||||||
/// </remarks>
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
[Serializable]
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct Vector4 : IEquatable<Vector4>
|
|
||||||
{
|
|
||||||
#region Fields
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The X component of the Vector4.
|
|
||||||
/// </summary>
|
|
||||||
public float X;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The Y component of the Vector4.
|
|
||||||
/// </summary>
|
|
||||||
public float Y;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The Z component of the Vector4.
|
|
||||||
/// </summary>
|
|
||||||
public float Z;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The W component of the Vector4.
|
|
||||||
/// </summary>
|
|
||||||
public float W;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines a unit-length Vector4 that points towards the X-axis.
|
|
||||||
/// </summary>
|
|
||||||
public static Vector4 UnitX = new Vector4(1, 0, 0, 0);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines a unit-length Vector4 that points towards the Y-axis.
|
|
||||||
/// </summary>
|
|
||||||
public static Vector4 UnitY = new Vector4(0, 1, 0, 0);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines a unit-length Vector4 that points towards the Z-axis.
|
|
||||||
/// </summary>
|
|
||||||
public static Vector4 UnitZ = new Vector4(0, 0, 1, 0);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines a unit-length Vector4 that points towards the W-axis.
|
|
||||||
/// </summary>
|
|
||||||
public static Vector4 UnitW = new Vector4(0, 0, 0, 1);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines a zero-length Vector4.
|
|
||||||
/// </summary>
|
|
||||||
public static Vector4 Zero = new Vector4(0, 0, 0, 0);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines an instance with all components set to 1.
|
|
||||||
/// </summary>
|
|
||||||
public static readonly Vector4 One = new Vector4(1, 1, 1, 1);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines the size of the Vector4 struct in bytes.
|
|
||||||
/// </summary>
|
|
||||||
public static readonly int SizeInBytes = Marshal.SizeOf(new Vector4());
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new Vector4.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">The x component of the Vector4.</param>
|
|
||||||
/// <param name="y">The y component of the Vector4.</param>
|
|
||||||
/// <param name="z">The z component of the Vector4.</param>
|
|
||||||
/// <param name="w">The w component of the Vector4.</param>
|
|
||||||
public Vector4(float x, float y, float z, float w)
|
|
||||||
{
|
|
||||||
X = x;
|
|
||||||
Y = y;
|
|
||||||
Z = z;
|
|
||||||
W = w;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new Vector4 from the given Vector2.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="v">The Vector2 to copy components from.</param>
|
|
||||||
public Vector4(Vector2 v)
|
|
||||||
{
|
|
||||||
X = v.X;
|
|
||||||
Y = v.Y;
|
|
||||||
Z = 0.0f;
|
|
||||||
W = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new Vector4 from the given Vector3.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="v">The Vector3 to copy components from.</param>
|
|
||||||
public Vector4(Vector3 v)
|
|
||||||
{
|
|
||||||
X = v.X;
|
|
||||||
Y = v.Y;
|
|
||||||
Z = v.Z;
|
|
||||||
W = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new Vector4 from the specified Vector3 and w component.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="v">The Vector3 to copy components from.</param>
|
|
||||||
/// <param name="w">The w component of the new Vector4.</param>
|
|
||||||
public Vector4(Vector3 v, float w)
|
|
||||||
{
|
|
||||||
X = v.X;
|
|
||||||
Y = v.Y;
|
|
||||||
Z = v.Z;
|
|
||||||
W = w;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructs a new Vector4 from the given Vector4.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="v">The Vector4 to copy components from.</param>
|
|
||||||
public Vector4(Vector4 v)
|
|
||||||
{
|
|
||||||
X = v.X;
|
|
||||||
Y = v.Y;
|
|
||||||
Z = v.Z;
|
|
||||||
W = v.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Members
|
|
||||||
|
|
||||||
#region Instance
|
|
||||||
|
|
||||||
#region public void Add()
|
|
||||||
|
|
||||||
/// <summary>Add the Vector passed as parameter to this instance.</summary>
|
|
||||||
/// <param name="right">Right operand. This parameter is only read from.</param>
|
|
||||||
public void Add( Vector4 right )
|
|
||||||
{
|
|
||||||
this.X += right.X;
|
|
||||||
this.Y += right.Y;
|
|
||||||
this.Z += right.Z;
|
|
||||||
this.W += right.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Add the Vector passed as parameter to this instance.</summary>
|
|
||||||
/// <param name="right">Right operand. This parameter is only read from.</param>
|
|
||||||
[CLSCompliant(false)]
|
|
||||||
public void Add( ref Vector4 right )
|
|
||||||
{
|
|
||||||
this.X += right.X;
|
|
||||||
this.Y += right.Y;
|
|
||||||
this.Z += right.Z;
|
|
||||||
this.W += right.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Add()
|
|
||||||
|
|
||||||
#region public void Sub()
|
|
||||||
|
|
||||||
/// <summary>Subtract the Vector passed as parameter from this instance.</summary>
|
|
||||||
/// <param name="right">Right operand. This parameter is only read from.</param>
|
|
||||||
public void Sub( Vector4 right )
|
|
||||||
{
|
|
||||||
this.X -= right.X;
|
|
||||||
this.Y -= right.Y;
|
|
||||||
this.Z -= right.Z;
|
|
||||||
this.W -= right.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Subtract the Vector passed as parameter from this instance.</summary>
|
|
||||||
/// <param name="right">Right operand. This parameter is only read from.</param>
|
|
||||||
[CLSCompliant(false)]
|
|
||||||
public void Sub( ref Vector4 right )
|
|
||||||
{
|
|
||||||
this.X -= right.X;
|
|
||||||
this.Y -= right.Y;
|
|
||||||
this.Z -= right.Z;
|
|
||||||
this.W -= right.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Sub()
|
|
||||||
|
|
||||||
#region public void Mult()
|
|
||||||
|
|
||||||
/// <summary>Multiply this instance by a scalar.</summary>
|
|
||||||
/// <param name="f">Scalar operand.</param>
|
|
||||||
public void Mult( float f )
|
|
||||||
{
|
|
||||||
this.X *= f;
|
|
||||||
this.Y *= f;
|
|
||||||
this.Z *= f;
|
|
||||||
this.W *= f;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Mult()
|
|
||||||
|
|
||||||
#region public void Div()
|
|
||||||
|
|
||||||
/// <summary>Divide this instance by a scalar.</summary>
|
|
||||||
/// <param name="f">Scalar operand.</param>
|
|
||||||
public void Div( float f )
|
|
||||||
{
|
|
||||||
float mult = 1.0f / f;
|
|
||||||
this.X *= mult;
|
|
||||||
this.Y *= mult;
|
|
||||||
this.Z *= mult;
|
|
||||||
this.W *= mult;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Div()
|
|
||||||
|
|
||||||
#region public float Length
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the length (magnitude) of the vector.
|
|
||||||
/// </summary>
|
|
||||||
/// <see cref="LengthFast"/>
|
|
||||||
/// <seealso cref="LengthSquared"/>
|
|
||||||
public float Length
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return (float)System.Math.Sqrt(X * X + Y * Y + Z * Z + W * W);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public float LengthFast
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets an approximation of the vector length (magnitude).
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// This property uses an approximation of the square root function to calculate vector magnitude, with
|
|
||||||
/// an upper error bound of 0.001.
|
|
||||||
/// </remarks>
|
|
||||||
/// <see cref="Length"/>
|
|
||||||
/// <seealso cref="LengthSquared"/>
|
|
||||||
public float LengthFast
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return 1.0f / MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z + W * W);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public float LengthSquared
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the square of the vector length (magnitude).
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// This property avoids the costly square root operation required by the Length property. This makes it more suitable
|
|
||||||
/// for comparisons.
|
|
||||||
/// </remarks>
|
|
||||||
/// <see cref="Length"/>
|
|
||||||
/// <seealso cref="LengthFast"/>
|
|
||||||
public float LengthSquared
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return X * X + Y * Y + Z * Z + W * W;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public void Normalize()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scales the Vector4 to unit length.
|
|
||||||
/// </summary>
|
|
||||||
public void Normalize()
|
|
||||||
{
|
|
||||||
float scale = 1.0f / this.Length;
|
|
||||||
X *= scale;
|
|
||||||
Y *= scale;
|
|
||||||
Z *= scale;
|
|
||||||
W *= scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public void NormalizeFast()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scales the Vector4 to approximately unit length.
|
|
||||||
/// </summary>
|
|
||||||
public void NormalizeFast()
|
|
||||||
{
|
|
||||||
float scale = Functions.InverseSqrtFast(X * X + Y * Y + Z * Z + W * W);
|
|
||||||
X *= scale;
|
|
||||||
Y *= scale;
|
|
||||||
Z *= scale;
|
|
||||||
W *= scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public void Scale()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scales the current Vector4 by the given amounts.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sx">The scale of the X component.</param>
|
|
||||||
/// <param name="sy">The scale of the Y component.</param>
|
|
||||||
/// <param name="sz">The scale of the Z component.</param>
|
|
||||||
/// <param name="sw">The scale of the Z component.</param>
|
|
||||||
public void Scale( float sx, float sy, float sz, float sw )
|
|
||||||
{
|
|
||||||
this.X = X * sx;
|
|
||||||
this.Y = Y * sy;
|
|
||||||
this.Z = Z * sz;
|
|
||||||
this.W = W * sw;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Scales this instance by the given parameter.</summary>
|
|
||||||
/// <param name="scale">The scaling of the individual components.</param>
|
|
||||||
public void Scale( Vector4 scale )
|
|
||||||
{
|
|
||||||
this.X *= scale.X;
|
|
||||||
this.Y *= scale.Y;
|
|
||||||
this.Z *= scale.Z;
|
|
||||||
this.W *= scale.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Scales this instance by the given parameter.</summary>
|
|
||||||
/// <param name="scale">The scaling of the individual components.</param>
|
|
||||||
[CLSCompliant(false)]
|
|
||||||
public void Scale( ref Vector4 scale )
|
|
||||||
{
|
|
||||||
this.X *= scale.X;
|
|
||||||
this.Y *= scale.Y;
|
|
||||||
this.Z *= scale.Z;
|
|
||||||
this.W *= scale.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion public void Scale()
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Static
|
|
||||||
|
|
||||||
#region Add
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add two Vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <returns>Result of addition</returns>
|
|
||||||
public static Vector4 Add(Vector4 a, Vector4 b)
|
|
||||||
{
|
|
||||||
a.X += b.X;
|
|
||||||
a.Y += b.Y;
|
|
||||||
a.Z += b.Z;
|
|
||||||
a.W += b.W;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add two Vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <param name="result">Result of addition</param>
|
|
||||||
public static void Add(ref Vector4 a, ref Vector4 b, out Vector4 result)
|
|
||||||
{
|
|
||||||
result.X = a.X + b.X;
|
|
||||||
result.Y = a.Y + b.Y;
|
|
||||||
result.Z = a.Z + b.Z;
|
|
||||||
result.W = a.W + b.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Sub
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Subtract one Vector from another
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <returns>Result of subtraction</returns>
|
|
||||||
public static Vector4 Sub(Vector4 a, Vector4 b)
|
|
||||||
{
|
|
||||||
a.X -= b.X;
|
|
||||||
a.Y -= b.Y;
|
|
||||||
a.Z -= b.Z;
|
|
||||||
a.W -= b.W;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Subtract one Vector from another
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <param name="result">Result of subtraction</param>
|
|
||||||
public static void Sub(ref Vector4 a, ref Vector4 b, out Vector4 result)
|
|
||||||
{
|
|
||||||
result.X = a.X - b.X;
|
|
||||||
result.Y = a.Y - b.Y;
|
|
||||||
result.Z = a.Z - b.Z;
|
|
||||||
result.W = a.W - b.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Mult
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Multiply a vector and a scalar
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">Vector operand</param>
|
|
||||||
/// <param name="f">Scalar operand</param>
|
|
||||||
/// <returns>Result of the multiplication</returns>
|
|
||||||
public static Vector4 Mult(Vector4 a, float f)
|
|
||||||
{
|
|
||||||
a.X *= f;
|
|
||||||
a.Y *= f;
|
|
||||||
a.Z *= f;
|
|
||||||
a.W *= f;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Multiply a vector and a scalar
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">Vector operand</param>
|
|
||||||
/// <param name="f">Scalar operand</param>
|
|
||||||
/// <param name="result">Result of the multiplication</param>
|
|
||||||
public static void Mult(ref Vector4 a, float f, out Vector4 result)
|
|
||||||
{
|
|
||||||
result.X = a.X * f;
|
|
||||||
result.Y = a.Y * f;
|
|
||||||
result.Z = a.Z * f;
|
|
||||||
result.W = a.W * f;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Div
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Divide a vector by a scalar
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">Vector operand</param>
|
|
||||||
/// <param name="f">Scalar operand</param>
|
|
||||||
/// <returns>Result of the division</returns>
|
|
||||||
public static Vector4 Div(Vector4 a, float f)
|
|
||||||
{
|
|
||||||
float mult = 1.0f / f;
|
|
||||||
a.X *= mult;
|
|
||||||
a.Y *= mult;
|
|
||||||
a.Z *= mult;
|
|
||||||
a.W *= mult;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Divide a vector by a scalar
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">Vector operand</param>
|
|
||||||
/// <param name="f">Scalar operand</param>
|
|
||||||
/// <param name="result">Result of the division</param>
|
|
||||||
public static void Div(ref Vector4 a, float f, out Vector4 result)
|
|
||||||
{
|
|
||||||
float mult = 1.0f / f;
|
|
||||||
result.X = a.X * mult;
|
|
||||||
result.Y = a.Y * mult;
|
|
||||||
result.Z = a.Z * mult;
|
|
||||||
result.W = a.W * mult;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Min
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the component-wise minimum of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <returns>The component-wise minimum</returns>
|
|
||||||
public static Vector4 Min(Vector4 a, Vector4 b)
|
|
||||||
{
|
|
||||||
a.X = a.X < b.X ? a.X : b.X;
|
|
||||||
a.Y = a.Y < b.Y ? a.Y : b.Y;
|
|
||||||
a.Z = a.Z < b.Z ? a.Z : b.Z;
|
|
||||||
a.W = a.W < b.W ? a.W : b.W;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the component-wise minimum of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <param name="result">The component-wise minimum</param>
|
|
||||||
public static void Min(ref Vector4 a, ref Vector4 b, out Vector4 result)
|
|
||||||
{
|
|
||||||
result.X = a.X < b.X ? a.X : b.X;
|
|
||||||
result.Y = a.Y < b.Y ? a.Y : b.Y;
|
|
||||||
result.Z = a.Z < b.Z ? a.Z : b.Z;
|
|
||||||
result.W = a.W < b.W ? a.W : b.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Max
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the component-wise maximum of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <returns>The component-wise maximum</returns>
|
|
||||||
public static Vector4 Max(Vector4 a, Vector4 b)
|
|
||||||
{
|
|
||||||
a.X = a.X > b.X ? a.X : b.X;
|
|
||||||
a.Y = a.Y > b.Y ? a.Y : b.Y;
|
|
||||||
a.Z = a.Z > b.Z ? a.Z : b.Z;
|
|
||||||
a.W = a.W > b.W ? a.W : b.W;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the component-wise maximum of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First operand</param>
|
|
||||||
/// <param name="b">Second operand</param>
|
|
||||||
/// <param name="result">The component-wise maximum</param>
|
|
||||||
public static void Max(ref Vector4 a, ref Vector4 b, out Vector4 result)
|
|
||||||
{
|
|
||||||
result.X = a.X > b.X ? a.X : b.X;
|
|
||||||
result.Y = a.Y > b.Y ? a.Y : b.Y;
|
|
||||||
result.Z = a.Z > b.Z ? a.Z : b.Z;
|
|
||||||
result.W = a.W > b.W ? a.W : b.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Clamp
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clamp a vector to the given minimum and maximum vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">Input vector</param>
|
|
||||||
/// <param name="min">Minimum vector</param>
|
|
||||||
/// <param name="max">Maximum vector</param>
|
|
||||||
/// <returns>The clamped vector</returns>
|
|
||||||
public static Vector4 Clamp(Vector4 vec, Vector4 min, Vector4 max)
|
|
||||||
{
|
|
||||||
vec.X = vec.X < min.X ? min.X : vec.X > max.X ? max.X : vec.X;
|
|
||||||
vec.Y = vec.Y < min.Y ? min.Y : vec.Y > max.Y ? max.Y : vec.Y;
|
|
||||||
vec.Z = vec.X < min.Z ? min.Z : vec.Z > max.Z ? max.Z : vec.Z;
|
|
||||||
vec.W = vec.Y < min.W ? min.W : vec.W > max.W ? max.W : vec.W;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clamp a vector to the given minimum and maximum vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">Input vector</param>
|
|
||||||
/// <param name="min">Minimum vector</param>
|
|
||||||
/// <param name="max">Maximum vector</param>
|
|
||||||
/// <param name="result">The clamped vector</param>
|
|
||||||
public static void Clamp(ref Vector4 vec, ref Vector4 min, ref Vector4 max, out Vector4 result)
|
|
||||||
{
|
|
||||||
result.X = vec.X < min.X ? min.X : vec.X > max.X ? max.X : vec.X;
|
|
||||||
result.Y = vec.Y < min.Y ? min.Y : vec.Y > max.Y ? max.Y : vec.Y;
|
|
||||||
result.Z = vec.X < min.Z ? min.Z : vec.Z > max.Z ? max.Z : vec.Z;
|
|
||||||
result.W = vec.Y < min.W ? min.W : vec.W > max.W ? max.W : vec.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Normalize
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scale a vector to unit length
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The input vector</param>
|
|
||||||
/// <returns>The normalized vector</returns>
|
|
||||||
public static Vector4 Normalize(Vector4 vec)
|
|
||||||
{
|
|
||||||
float scale = 1.0f / vec.Length;
|
|
||||||
vec.X *= scale;
|
|
||||||
vec.Y *= scale;
|
|
||||||
vec.Z *= scale;
|
|
||||||
vec.W *= scale;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scale a vector to unit length
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The input vector</param>
|
|
||||||
/// <param name="result">The normalized vector</param>
|
|
||||||
public static void Normalize(ref Vector4 vec, out Vector4 result)
|
|
||||||
{
|
|
||||||
float scale = 1.0f / vec.Length;
|
|
||||||
result.X = vec.X * scale;
|
|
||||||
result.Y = vec.Y * scale;
|
|
||||||
result.Z = vec.Z * scale;
|
|
||||||
result.W = vec.W * scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region NormalizeFast
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scale a vector to approximately unit length
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The input vector</param>
|
|
||||||
/// <returns>The normalized vector</returns>
|
|
||||||
public static Vector4 NormalizeFast(Vector4 vec)
|
|
||||||
{
|
|
||||||
float scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z + vec.W * vec.W);
|
|
||||||
vec.X *= scale;
|
|
||||||
vec.Y *= scale;
|
|
||||||
vec.Z *= scale;
|
|
||||||
vec.W *= scale;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Scale a vector to approximately unit length
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">The input vector</param>
|
|
||||||
/// <param name="result">The normalized vector</param>
|
|
||||||
public static void NormalizeFast(ref Vector4 vec, out Vector4 result)
|
|
||||||
{
|
|
||||||
float scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z + vec.W * vec.W);
|
|
||||||
result.X = vec.X * scale;
|
|
||||||
result.Y = vec.Y * scale;
|
|
||||||
result.Z = vec.Z * scale;
|
|
||||||
result.W = vec.W * scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Dot
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the dot product of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">First operand</param>
|
|
||||||
/// <param name="right">Second operand</param>
|
|
||||||
/// <returns>The dot product of the two inputs</returns>
|
|
||||||
public static float Dot(Vector4 left, Vector4 right)
|
|
||||||
{
|
|
||||||
return left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the dot product of two vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="left">First operand</param>
|
|
||||||
/// <param name="right">Second operand</param>
|
|
||||||
/// <param name="result">The dot product of the two inputs</param>
|
|
||||||
public static void Dot( ref Vector4 left, ref Vector4 right, out float result )
|
|
||||||
{
|
|
||||||
result = left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Lerp
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a new Vector that is the linear blend of the 2 given Vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First input vector</param>
|
|
||||||
/// <param name="b">Second input vector</param>
|
|
||||||
/// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
|
|
||||||
/// <returns>a when blend=0, b when blend=1, and a linear combination otherwise</returns>
|
|
||||||
public static Vector4 Lerp(Vector4 a, Vector4 b, float blend)
|
|
||||||
{
|
|
||||||
a.X = blend * (b.X - a.X) + a.X;
|
|
||||||
a.Y = blend * (b.Y - a.Y) + a.Y;
|
|
||||||
a.Z = blend * (b.Z - a.Z) + a.Z;
|
|
||||||
a.W = blend * (b.W - a.W) + a.W;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a new Vector that is the linear blend of the 2 given Vectors
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First input vector</param>
|
|
||||||
/// <param name="b">Second input vector</param>
|
|
||||||
/// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
|
|
||||||
/// <param name="result">a when blend=0, b when blend=1, and a linear combination otherwise</param>
|
|
||||||
public static void Lerp( ref Vector4 a, ref Vector4 b, float blend, out Vector4 result )
|
|
||||||
{
|
|
||||||
result.X = blend * ( b.X - a.X ) + a.X;
|
|
||||||
result.Y = blend * ( b.Y - a.Y ) + a.Y;
|
|
||||||
result.Z = blend * ( b.Z - a.Z ) + a.Z;
|
|
||||||
result.W = blend * ( b.W - a.W ) + a.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Barycentric
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Interpolate 3 Vectors using Barycentric coordinates
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First input Vector</param>
|
|
||||||
/// <param name="b">Second input Vector</param>
|
|
||||||
/// <param name="c">Third input Vector</param>
|
|
||||||
/// <param name="u">First Barycentric Coordinate</param>
|
|
||||||
/// <param name="v">Second Barycentric Coordinate</param>
|
|
||||||
/// <returns>a when u=v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise</returns>
|
|
||||||
public static Vector4 BaryCentric(Vector4 a, Vector4 b, Vector4 c, float u, float v)
|
|
||||||
{
|
|
||||||
return a + u * (b - a) + v * (c - a);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Interpolate 3 Vectors using Barycentric coordinates</summary>
|
|
||||||
/// <param name="a">First input Vector.</param>
|
|
||||||
/// <param name="b">Second input Vector.</param>
|
|
||||||
/// <param name="c">Third input Vector.</param>
|
|
||||||
/// <param name="u">First Barycentric Coordinate.</param>
|
|
||||||
/// <param name="v">Second Barycentric Coordinate.</param>
|
|
||||||
/// <param name="result">Output Vector. a when u=v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise</param>
|
|
||||||
public static void BaryCentric( ref Vector4 a, ref Vector4 b, ref Vector4 c, float u, float v, out Vector4 result )
|
|
||||||
{
|
|
||||||
result = a; // copy
|
|
||||||
|
|
||||||
Vector4 temp = b; // copy
|
|
||||||
temp.Sub( ref a );
|
|
||||||
temp.Mult( u );
|
|
||||||
result.Add( ref temp );
|
|
||||||
|
|
||||||
temp = c; // copy
|
|
||||||
temp.Sub( ref a );
|
|
||||||
temp.Mult( v );
|
|
||||||
result.Add( ref temp );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Transform
|
|
||||||
|
|
||||||
/// <summary>Transform a Vector by the given Matrix</summary>
|
|
||||||
/// <param name="vec">The vector to transform</param>
|
|
||||||
/// <param name="mat">The desired transformation</param>
|
|
||||||
/// <returns>The transformed vector</returns>
|
|
||||||
public static Vector4 Transform(Vector4 vec, Matrix4 mat)
|
|
||||||
{
|
|
||||||
Vector4 result;
|
|
||||||
result.X = Vector4.Dot(vec, mat.Column0);
|
|
||||||
result.Y = Vector4.Dot(vec, mat.Column1);
|
|
||||||
result.Z = Vector4.Dot(vec, mat.Column2);
|
|
||||||
result.W = Vector4.Dot(vec, mat.Column3);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Transform a Vector by the given Matrix</summary>
|
|
||||||
/// <param name="vec">The vector to transform</param>
|
|
||||||
/// <param name="mat">The desired transformation</param>
|
|
||||||
/// <param name="result">The transformed vector</param>
|
|
||||||
public static void Transform( ref Vector4 vec, ref Matrix4 mat, out Vector4 result )
|
|
||||||
{
|
|
||||||
result.X = vec.X * mat.Row0.X +
|
|
||||||
vec.Y * mat.Row1.X +
|
|
||||||
vec.Z * mat.Row2.X +
|
|
||||||
vec.W * mat.Row3.X;
|
|
||||||
|
|
||||||
result.Y = vec.X * mat.Row0.Y +
|
|
||||||
vec.Y * mat.Row1.Y +
|
|
||||||
vec.Z * mat.Row2.Y +
|
|
||||||
vec.W * mat.Row3.Y;
|
|
||||||
|
|
||||||
result.Z = vec.X * mat.Row0.Z +
|
|
||||||
vec.Y * mat.Row1.Z +
|
|
||||||
vec.Z * mat.Row2.Z +
|
|
||||||
vec.W * mat.Row3.Z;
|
|
||||||
|
|
||||||
result.W = vec.X * mat.Row0.W +
|
|
||||||
vec.Y * mat.Row1.W +
|
|
||||||
vec.Z * mat.Row2.W +
|
|
||||||
vec.W * mat.Row3.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Swizzle
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets an OpenTK.Vector2 with the X and Y components of this instance.
|
|
||||||
/// </summary>
|
|
||||||
[XmlIgnore]
|
|
||||||
public Vector2 Xy { get { return new Vector2(X, Y); } set { X = value.X; Y = value.Y; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets an OpenTK.Vector3 with the X, Y and Z components of this instance.
|
|
||||||
/// </summary>
|
|
||||||
[XmlIgnore]
|
|
||||||
public Vector3 Xyz { get { return new Vector3(X, Y, Z); } set { X = value.X; Y = value.Y; Z = value.Z; } }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Operators
|
|
||||||
|
|
||||||
public static Vector4 operator +(Vector4 left, Vector4 right)
|
|
||||||
{
|
|
||||||
left.X += right.X;
|
|
||||||
left.Y += right.Y;
|
|
||||||
left.Z += right.Z;
|
|
||||||
left.W += right.W;
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector4 operator -(Vector4 left, Vector4 right)
|
|
||||||
{
|
|
||||||
left.X -= right.X;
|
|
||||||
left.Y -= right.Y;
|
|
||||||
left.Z -= right.Z;
|
|
||||||
left.W -= right.W;
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector4 operator -(Vector4 vec)
|
|
||||||
{
|
|
||||||
vec.X = -vec.X;
|
|
||||||
vec.Y = -vec.Y;
|
|
||||||
vec.Z = -vec.Z;
|
|
||||||
vec.W = -vec.W;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector4 operator *(Vector4 vec, float f)
|
|
||||||
{
|
|
||||||
vec.X *= f;
|
|
||||||
vec.Y *= f;
|
|
||||||
vec.Z *= f;
|
|
||||||
vec.W *= f;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector4 operator *(float f, Vector4 vec)
|
|
||||||
{
|
|
||||||
vec.X *= f;
|
|
||||||
vec.Y *= f;
|
|
||||||
vec.Z *= f;
|
|
||||||
vec.W *= f;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector4 operator /(Vector4 vec, float f)
|
|
||||||
{
|
|
||||||
float mult = 1.0f / f;
|
|
||||||
vec.X *= mult;
|
|
||||||
vec.Y *= mult;
|
|
||||||
vec.Z *= mult;
|
|
||||||
vec.W *= mult;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool operator ==(Vector4 left, Vector4 right)
|
|
||||||
{
|
|
||||||
return left.Equals(right);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool operator !=(Vector4 left, Vector4 right)
|
|
||||||
{
|
|
||||||
return !left.Equals(right);
|
|
||||||
}
|
|
||||||
|
|
||||||
[CLSCompliant(false)]
|
|
||||||
unsafe public static explicit operator float*(Vector4 v)
|
|
||||||
{
|
|
||||||
return &v.X;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static explicit operator IntPtr(Vector4 v)
|
|
||||||
{
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
return (IntPtr)(&v.X);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Overrides
|
|
||||||
|
|
||||||
#region public override string ToString()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a System.String that represents the current Vector4.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return String.Format("({0}, {1}, {2}, {3})", X, Y, Z, W);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override int GetHashCode()
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the hashcode for this instance.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode() ^ W.GetHashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public override bool Equals(object obj)
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Indicates whether this instance and a specified object are equal.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="obj">The object to compare to.</param>
|
|
||||||
/// <returns>True if the instances are equal; false otherwise.</returns>
|
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
|
||||||
if (!(obj is Vector4))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return this.Equals((Vector4)obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IEquatable<Vector4> Members
|
|
||||||
|
|
||||||
/// <summary>Indicates whether the current vector is equal to another vector.</summary>
|
|
||||||
/// <param name="other">A vector to compare with this vector.</param>
|
|
||||||
/// <returns>true if the current vector is equal to the vector parameter; otherwise, false.</returns>
|
|
||||||
public bool Equals(Vector4 other)
|
|
||||||
{
|
|
||||||
return
|
|
||||||
X == other.X &&
|
|
||||||
Y == other.Y &&
|
|
||||||
Z == other.Z &&
|
|
||||||
W == other.W;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,415 +0,0 @@
|
||||||
#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;
|
|
||||||
|
|
||||||
namespace OpenTK.Math
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 4-component Vector of the Half type. Occupies 8 Byte total.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("OpenTK.Math functions have been moved to the root OpenTK namespace (reason: XNA compatibility")]
|
|
||||||
[Serializable, StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct Vector4h : ISerializable, IEquatable<Vector4h>
|
|
||||||
{
|
|
||||||
#region Public Fields
|
|
||||||
|
|
||||||
/// <summary>The X component of the Half4.</summary>
|
|
||||||
public Half X;
|
|
||||||
|
|
||||||
/// <summary>The Y component of the Half4.</summary>
|
|
||||||
public Half Y;
|
|
||||||
|
|
||||||
/// <summary>The Z component of the Half4.</summary>
|
|
||||||
public Half Z;
|
|
||||||
|
|
||||||
/// <summary>The W component of the Half4.</summary>
|
|
||||||
public Half W;
|
|
||||||
|
|
||||||
#endregion Public Fields
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The new Half4 instance will avoid conversion and copy directly from the Half parameters.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">An Half instance of a 16-bit half-precision floating-point number.</param>
|
|
||||||
/// <param name="y">An Half instance of a 16-bit half-precision floating-point number.</param>
|
|
||||||
/// <param name="z">An Half instance of a 16-bit half-precision floating-point number.</param>
|
|
||||||
/// <param name="w">An Half instance of a 16-bit half-precision floating-point number.</param>
|
|
||||||
public Vector4h(Half x, Half y, Half z, Half w)
|
|
||||||
{
|
|
||||||
this.X = x;
|
|
||||||
this.Y = y;
|
|
||||||
this.Z = z;
|
|
||||||
this.W = w;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The new Half4 instance will convert the 4 parameters into 16-bit half-precision floating-point.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="y">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="z">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="w">32-bit single-precision floating-point number.</param>
|
|
||||||
public Vector4h(Single x, Single y, Single z, Single w)
|
|
||||||
{
|
|
||||||
X = new Half(x);
|
|
||||||
Y = new Half(y);
|
|
||||||
Z = new Half(z);
|
|
||||||
W = new Half(w);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The new Half4 instance will convert the 4 parameters into 16-bit half-precision floating-point.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="y">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="z">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="w">32-bit single-precision floating-point number.</param>
|
|
||||||
/// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param>
|
|
||||||
public Vector4h(Single x, Single y, Single z, Single w, bool throwOnError)
|
|
||||||
{
|
|
||||||
X = new Half(x, throwOnError);
|
|
||||||
Y = new Half(y, throwOnError);
|
|
||||||
Z = new Half(z, throwOnError);
|
|
||||||
W = new Half(w, throwOnError);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The new Half4 instance will convert the Vector4 into 16-bit half-precision floating-point.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="v">OpenTK.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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OpenTK
|
|
||||||
{
|
|
||||||
class ObjectPool<T> where T : IPoolable<T>, new()
|
|
||||||
{
|
|
||||||
Queue<T> pool = new Queue<T>();
|
|
||||||
|
|
||||||
public ObjectPool()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public T Acquire()
|
|
||||||
{
|
|
||||||
T item;
|
|
||||||
|
|
||||||
if (pool.Count > 0)
|
|
||||||
{
|
|
||||||
item = pool.Dequeue();
|
|
||||||
item.OnAcquire();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
item = new T();
|
|
||||||
item.Owner = this;
|
|
||||||
item.OnAcquire();
|
|
||||||
}
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Release(T item)
|
|
||||||
{
|
|
||||||
if (item == null)
|
|
||||||
throw new ArgumentNullException("item");
|
|
||||||
|
|
||||||
item.OnRelease();
|
|
||||||
pool.Enqueue(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,518 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
|
||||||
<PropertyGroup>
|
|
||||||
<ProjectType>Local</ProjectType>
|
|
||||||
<ProductVersion>8.0.50727</ProductVersion>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
<ProjectGuid>{62C0DB35-0000-0000-0000-000000000000}</ProjectGuid>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<AssemblyKeyContainerName>
|
|
||||||
</AssemblyKeyContainerName>
|
|
||||||
<AssemblyName>OpenTK.Compatibility</AssemblyName>
|
|
||||||
<DefaultClientScript>JScript</DefaultClientScript>
|
|
||||||
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
|
|
||||||
<DefaultTargetSchema>IE50</DefaultTargetSchema>
|
|
||||||
<DelaySign>false</DelaySign>
|
|
||||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AppDesignerFolder>
|
|
||||||
</AppDesignerFolder>
|
|
||||||
<RootNamespace>OpenTK.Compatibility</RootNamespace>
|
|
||||||
<StartArguments>
|
|
||||||
</StartArguments>
|
|
||||||
<FileUpgradeFlags>
|
|
||||||
</FileUpgradeFlags>
|
|
||||||
<OldToolsVersion>2.0</OldToolsVersion>
|
|
||||||
<UpgradeBackupLocation />
|
|
||||||
<PublishUrl>publish\</PublishUrl>
|
|
||||||
<Install>true</Install>
|
|
||||||
<InstallFrom>Disk</InstallFrom>
|
|
||||||
<UpdateEnabled>false</UpdateEnabled>
|
|
||||||
<UpdateMode>Foreground</UpdateMode>
|
|
||||||
<UpdateInterval>7</UpdateInterval>
|
|
||||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
|
||||||
<UpdatePeriodically>false</UpdatePeriodically>
|
|
||||||
<UpdateRequired>false</UpdateRequired>
|
|
||||||
<MapFileExtensions>true</MapFileExtensions>
|
|
||||||
<ApplicationRevision>0</ApplicationRevision>
|
|
||||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
|
||||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
|
||||||
<UseApplicationTrust>false</UseApplicationTrust>
|
|
||||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
|
||||||
<BaseAddress>285212672</BaseAddress>
|
|
||||||
<ConfigurationOverrideFile>
|
|
||||||
</ConfigurationOverrideFile>
|
|
||||||
<DefineConstants>DEBUG;TRACE;</DefineConstants>
|
|
||||||
<DebugSymbols>True</DebugSymbols>
|
|
||||||
<FileAlignment>4096</FileAlignment>
|
|
||||||
<Optimize>False</Optimize>
|
|
||||||
<OutputPath>..\..\Binaries\OpenTK\Debug\</OutputPath>
|
|
||||||
<RegisterForComInterop>False</RegisterForComInterop>
|
|
||||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<NoWarn>0219, 0414, 0612, 0618, 1591, 3005, 3006</NoWarn>
|
|
||||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
|
||||||
<BaseAddress>285212672</BaseAddress>
|
|
||||||
<ConfigurationOverrideFile>
|
|
||||||
</ConfigurationOverrideFile>
|
|
||||||
<DefineConstants>TRACE;</DefineConstants>
|
|
||||||
<FileAlignment>4096</FileAlignment>
|
|
||||||
<Optimize>True</Optimize>
|
|
||||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
|
||||||
<RegisterForComInterop>False</RegisterForComInterop>
|
|
||||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<NoWarn>0219, 0414, 0612, 0618, 1591, 3005, 3006</NoWarn>
|
|
||||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Documentation|AnyCPU'">
|
|
||||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
|
||||||
<DebugType>none</DebugType>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<NoWarn>0219, 0414, 0612, 0618, 1591, 3005, 3006</NoWarn>
|
|
||||||
<Optimize>True</Optimize>
|
|
||||||
<DefineConstants>TRACE;</DefineConstants>
|
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Nsis|AnyCPU'">
|
|
||||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
|
||||||
<BaseAddress>285212672</BaseAddress>
|
|
||||||
<ConfigurationOverrideFile>
|
|
||||||
</ConfigurationOverrideFile>
|
|
||||||
<DefineConstants>TRACE;</DefineConstants>
|
|
||||||
<FileAlignment>4096</FileAlignment>
|
|
||||||
<Optimize>True</Optimize>
|
|
||||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
|
||||||
<RegisterForComInterop>False</RegisterForComInterop>
|
|
||||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<NoWarn>0219, 0414, 0612, 0618, 1591, 3005, 3006</NoWarn>
|
|
||||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
|
||||||
<DebugType>none</DebugType>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup>
|
|
||||||
<SignAssembly>True</SignAssembly>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup>
|
|
||||||
<AssemblyOriginatorKeyFile>..\..\OpenTK.snk</AssemblyOriginatorKeyFile>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="System">
|
|
||||||
<Name>System</Name>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Data">
|
|
||||||
<Name>System.Data</Name>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Drawing">
|
|
||||||
<Name>System.Drawing</Name>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Windows.Forms">
|
|
||||||
<Name>System.Windows.Forms</Name>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Xml">
|
|
||||||
<Name>System.Xml</Name>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\OpenTK\OpenTK.csproj">
|
|
||||||
<Name>OpenTK</Name>
|
|
||||||
<Project>{A37A7E14-0000-0000-0000-000000000000}</Project>
|
|
||||||
<Private>False</Private>
|
|
||||||
</ProjectReference>
|
|
||||||
<ProjectReference Include="..\GLControl\OpenTK.GLControl.csproj">
|
|
||||||
<Name>OpenTK.GLControl</Name>
|
|
||||||
<Project>{A625BE88-0000-0000-0000-000000000000}</Project>
|
|
||||||
<Private>False</Private>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="..\GlobalAssemblyInfo.cs">
|
|
||||||
<Link>Properties\GlobalAssemblyInfo.cs</Link>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="IPackable.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="IPoolable.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="TexturePacker.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="ObjectPool.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Platform\IGdiPlusInternals.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Platform\GdiPlus.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Platform\Windows\WinGdiPlusInternals.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Platform\X11\X11GdiPlusInternals.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Fonts\DisplayListTextPrinter.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Fonts\DisplayListTextHandle.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Fonts\IPrinterImplementation.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Fonts\VboTextPrinter.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Fonts\TextureFont.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Fonts\Glyph.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Fonts\TextHandle.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Fonts\IFont.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Texture2D.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\AlphaTexture2D.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\TextPrinterOptions.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\TextPrinter.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\TextAlignment.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\TextDirection.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\GraphicsResourceException.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\TextureRegion2D.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\ITextPrinter.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\TextExtents.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\TextQuality.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\RgbaTexture2D.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\IGraphicsResource.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\GL\GLDelegates.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\GL\GLHelper.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\GL\GLEnums.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\GL\GLCore.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\GL\GL.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\GL\ErrorHelper.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\GL11TextOutputProvider.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\GL12TextOutputProvider.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\TextBlockComparer.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\GL1TextOutputProvider.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\IGlyphCache.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\GlyphCache.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\GlyphPacker.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\GdiPlusGlyphRasterizer.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\IGlyphRasterizer.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\Glyph.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\GlyphEnumerator.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\ITextOutputProvider.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\GlyphSheet.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\CachedGlyphInfo.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\TextBlock.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Text\PoolableTextExtents.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Glu\Glu.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Glu\GluHelper.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Glu\GluCore.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Glu\GluEnums.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Graphics\Glu\GluDelegates.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Quaternion.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Matrix3d.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Vector4.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\BezierCurve.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Vector3.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Functions.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Matrix4d.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Vector2d.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Vector2h.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Vector3h.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Box2.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Matrix4.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Half.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Vector4d.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Vector2.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\BezierCurveQuadric.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Quaterniond.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Vector4h.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\Vector3d.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Math\BezierCurveCubic.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Tao\Platform\Windows\SimpleOpenGlControl.cs">
|
|
||||||
<SubType>UserControl</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Tao\OpenAl\Alut.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Tao\OpenAl\Al.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Tao\OpenAl\ALDelegates.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Tao\OpenAl\Alc.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Tao\OpenGl\GLDelegates.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Tao\OpenGl\Gl.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Tao\OpenGl\GLEnums.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Tao\OpenGl\GLCore.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Tao\OpenGl\Glu.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Tao\OpenGl\GlHelper.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\WaveReader.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\Sound.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\SoundFormat.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\AudioReaderException.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\AudioReader.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\SoundData.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\OpenAL\Alut\Alut.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\OpenAL\Alut\AlutEnums.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\OpenAL\Alc\AlcEnums.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\OpenAL\Alc\Alc.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\OpenAL\AL\EffectsExtensionPresets.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\OpenAL\AL\EffectsExtensionEnums.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\OpenAL\AL\XRamExtension.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\OpenAL\AL\EffectsExtension.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\OpenAL\AL\AL.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Audio\OpenAL\AL\ALEnums.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<EmbeddedResource Include="Properties\Resources.resx">
|
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
|
||||||
<SubType>Designer</SubType>
|
|
||||||
</EmbeddedResource>
|
|
||||||
<Compile Include="Properties\Resources.Designer.cs">
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
|
||||||
<DesignTime>True</DesignTime>
|
|
||||||
</Compile>
|
|
||||||
<EmbeddedResource Include="Tao\Platform\Windows\SimpleOpenGlControl.resx">
|
|
||||||
<DependentUpon>SimpleOpenGlControl.cs</DependentUpon>
|
|
||||||
</EmbeddedResource>
|
|
||||||
<Compile Include="Tao\Platform\Windows\SimpleOpenGlControl.Designer.cs">
|
|
||||||
<DependentUpon>SimpleOpenGlControl.cs</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
<None Include="..\..\OpenTK.snk">
|
|
||||||
<Link>OpenTK.snk</Link>
|
|
||||||
</None>
|
|
||||||
<None Include="OpenTK.Compatibility.dll.config">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
|
||||||
<PropertyGroup>
|
|
||||||
<PreBuildEvent>
|
|
||||||
</PreBuildEvent>
|
|
||||||
<PostBuildEvent>
|
|
||||||
</PostBuildEvent>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMinimal|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>..\..\Binaries\OpenTK\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE;</DefineConstants>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
|
||||||
<NoWarn>0219, 0414, 0612, 0618, 1591, 3005, 3006</NoWarn>
|
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
|
||||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
|
||||||
<BaseAddress>285212672</BaseAddress>
|
|
||||||
<ConfigurationOverrideFile>
|
|
||||||
</ConfigurationOverrideFile>
|
|
||||||
<RegisterForComInterop>False</RegisterForComInterop>
|
|
||||||
<FileAlignment>4096</FileAlignment>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseMinimal|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE;</DefineConstants>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
|
||||||
<NoWarn>0219, 0414, 0612, 0618, 1591, 3005, 3006</NoWarn>
|
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
|
||||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
|
||||||
<BaseAddress>285212672</BaseAddress>
|
|
||||||
<ConfigurationOverrideFile>
|
|
||||||
</ConfigurationOverrideFile>
|
|
||||||
<RegisterForComInterop>False</RegisterForComInterop>
|
|
||||||
<FileAlignment>4096</FileAlignment>
|
|
||||||
</PropertyGroup>
|
|
||||||
</Project>
|
|
|
@ -1,11 +0,0 @@
|
||||||
<configuration>
|
|
||||||
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1"/>
|
|
||||||
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1"/>
|
|
||||||
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1"/>
|
|
||||||
<dllmap os="linux" dll="alut.dll" target="libalut.so.0"/>
|
|
||||||
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so"/>
|
|
||||||
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
|
||||||
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
|
||||||
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
|
||||||
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
|
||||||
</configuration>
|
|
|
@ -1,129 +0,0 @@
|
||||||
#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 details.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace OpenTK.Platform
|
|
||||||
{
|
|
||||||
internal static class GdiPlus
|
|
||||||
{
|
|
||||||
static IGdiPlusInternals internals;
|
|
||||||
|
|
||||||
const string gdi_plus_library = "gdiplus.dll";
|
|
||||||
|
|
||||||
#region --- Constructors ---
|
|
||||||
|
|
||||||
static GdiPlus()
|
|
||||||
{
|
|
||||||
if (Configuration.RunningOnWindows && !Configuration.RunningOnMono)
|
|
||||||
internals = new Windows.WinGdiPlusInternals();
|
|
||||||
else
|
|
||||||
internals = new X11.X11GdiPlusInternals(); // This class is Mono-specific and works on all platforms.
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region --- Public Methods ---
|
|
||||||
|
|
||||||
public static IntPtr GetNativeGraphics(System.Drawing.Graphics graphics)
|
|
||||||
{
|
|
||||||
return internals.GetNativeGraphics(graphics);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IntPtr GetNativeFont(Font font)
|
|
||||||
{
|
|
||||||
return internals.GetNativeFont(font);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IntPtr GetNativeStringFormat(StringFormat format)
|
|
||||||
{
|
|
||||||
return internals.GetNativeStringFormat(format);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int MaxMeasurableCharacterRanges
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return 32; // This is a GDI+ limitation. TODO: Can we query this somehow?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[DllImport(gdi_plus_library, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true, EntryPoint = "GdipSetStringFormatMeasurableCharacterRanges")]
|
|
||||||
public static extern int SetStringFormatMeasurableCharacterRanges(HandleRef format, int rangeCount, [In, Out] CharacterRange[] range);
|
|
||||||
|
|
||||||
[DllImport(gdi_plus_library, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true, EntryPoint = "GdipSetStringFormatMeasurableCharacterRanges")]
|
|
||||||
public static extern int SetStringFormatMeasurableCharacterRanges(IntPtr format, int rangeCount, [In, Out] CharacterRange[] range);
|
|
||||||
|
|
||||||
[DllImport(gdi_plus_library, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true, EntryPoint = "GdipGetStringFormatMeasurableCharacterRangeCount")]
|
|
||||||
public static extern int GetStringFormatMeasurableCharacterRangeCount(HandleRef format, out int count);
|
|
||||||
|
|
||||||
[DllImport(gdi_plus_library, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true, EntryPoint = "GdipMeasureCharacterRanges")]
|
|
||||||
public static extern int MeasureCharacterRanges(HandleRef graphics, string textString, int length, HandleRef font, ref RectangleF layoutRect, HandleRef stringFormat, int characterCount, [In, Out] IntPtr[] region);
|
|
||||||
|
|
||||||
[DllImport(gdi_plus_library, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true, EntryPoint = "GdipMeasureCharacterRanges")]
|
|
||||||
public static extern int MeasureCharacterRanges(IntPtr graphics, string textString, int length, IntPtr font, ref RectangleF layoutRect, IntPtr stringFormat, int characterCount, [In, Out] IntPtr[] region);
|
|
||||||
|
|
||||||
[DllImport(gdi_plus_library, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true, EntryPoint = "GdipGetRegionBounds")]
|
|
||||||
public static extern int GetRegionBounds(IntPtr region, HandleRef graphics, ref RectangleF gprectf);
|
|
||||||
|
|
||||||
[DllImport(gdi_plus_library, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true, EntryPoint = "GdipGetRegionBounds")]
|
|
||||||
public static extern int GetRegionBounds(IntPtr region, IntPtr graphics, ref RectangleF gprectf);
|
|
||||||
|
|
||||||
[DllImport(gdi_plus_library, EntryPoint = "GdipCreateRegion", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
|
|
||||||
public static extern int CreateRegion(out IntPtr region);
|
|
||||||
|
|
||||||
[DllImport(gdi_plus_library, EntryPoint = "GdipDeleteRegion", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
|
|
||||||
public static extern int DeleteRegion(IntPtr region);
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#if false
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
internal struct GPRECTF
|
|
||||||
{
|
|
||||||
internal float X;
|
|
||||||
internal float Y;
|
|
||||||
internal float Width;
|
|
||||||
internal float Height;
|
|
||||||
internal GPRECTF(float x, float y, float width, float height)
|
|
||||||
{
|
|
||||||
this.X = x;
|
|
||||||
this.Y = y;
|
|
||||||
this.Width = width;
|
|
||||||
this.Height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal GPRECTF(RectangleF rect)
|
|
||||||
{
|
|
||||||
this.X = rect.X;
|
|
||||||
this.Y = rect.Y;
|
|
||||||
this.Width = rect.Width;
|
|
||||||
this.Height = rect.Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal SizeF SizeF
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return new SizeF(this.Width, this.Height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal RectangleF ToRectangleF()
|
|
||||||
{
|
|
||||||
return new RectangleF(this.X, this.Y, this.Width, this.Height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
#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.Platform
|
|
||||||
{
|
|
||||||
// Provides methods to access internal GdiPlus fields. This is necessary for
|
|
||||||
// managed <-> native GdiPlus interoperability.
|
|
||||||
// Note that the fields are named differently between .Net and Mono.
|
|
||||||
// GdiPlus is considered deprecated by Microsoft - it is highly unlikely that
|
|
||||||
// future framework upgrades will break this code, but it is something to
|
|
||||||
// keep in mind.
|
|
||||||
interface IGdiPlusInternals
|
|
||||||
{
|
|
||||||
IntPtr GetNativeGraphics(System.Drawing.Graphics graphics);
|
|
||||||
|
|
||||||
IntPtr GetNativeFont(System.Drawing.Font font);
|
|
||||||
|
|
||||||
IntPtr GetNativeStringFormat(System.Drawing.StringFormat format);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
#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;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace OpenTK.Platform.Windows
|
|
||||||
{
|
|
||||||
class WinGdiPlusInternals : IGdiPlusInternals
|
|
||||||
{
|
|
||||||
static readonly PropertyInfo native_graphics_property, native_font_property;
|
|
||||||
static readonly FieldInfo native_string_format_field;
|
|
||||||
|
|
||||||
static WinGdiPlusInternals()
|
|
||||||
{
|
|
||||||
native_graphics_property =
|
|
||||||
typeof(System.Drawing.Graphics).GetProperty("NativeGraphics", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
||||||
|
|
||||||
native_font_property =
|
|
||||||
typeof(System.Drawing.Font).GetProperty("NativeFont", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
||||||
|
|
||||||
native_string_format_field =
|
|
||||||
typeof(System.Drawing.StringFormat).GetField("nativeFormat", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region --- IGdiPlusInternals Members ---
|
|
||||||
|
|
||||||
public IntPtr GetNativeGraphics(System.Drawing.Graphics graphics)
|
|
||||||
{
|
|
||||||
return (IntPtr)native_graphics_property.GetValue(graphics, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IntPtr GetNativeFont(Font font)
|
|
||||||
{
|
|
||||||
return (IntPtr)native_font_property.GetValue(font, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IntPtr GetNativeStringFormat(StringFormat format)
|
|
||||||
{
|
|
||||||
return (IntPtr)native_string_format_field.GetValue(format);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
#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;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace OpenTK.Platform.X11
|
|
||||||
{
|
|
||||||
// Note: This class is Mono-specific, not X11-specific!
|
|
||||||
// It works on all platforms (windows, linux, macos) as long as we are running on Mono.
|
|
||||||
class X11GdiPlusInternals : IGdiPlusInternals
|
|
||||||
{
|
|
||||||
static readonly PropertyInfo native_graphics_property, native_font_property, native_string_format_property;
|
|
||||||
|
|
||||||
static X11GdiPlusInternals()
|
|
||||||
{
|
|
||||||
native_graphics_property =
|
|
||||||
typeof(System.Drawing.Graphics).GetProperty("NativeObject", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
||||||
|
|
||||||
native_font_property =
|
|
||||||
typeof(System.Drawing.Font).GetProperty("NativeObject", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
||||||
|
|
||||||
native_string_format_property =
|
|
||||||
typeof(System.Drawing.StringFormat).GetProperty("NativeObject", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region --- IGdiPlusInternals Members ---
|
|
||||||
|
|
||||||
public IntPtr GetNativeGraphics(System.Drawing.Graphics graphics)
|
|
||||||
{
|
|
||||||
return (IntPtr)native_graphics_property.GetValue(graphics, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IntPtr GetNativeFont(Font font)
|
|
||||||
{
|
|
||||||
return (IntPtr)native_font_property.GetValue(font, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IntPtr GetNativeStringFormat(StringFormat format)
|
|
||||||
{
|
|
||||||
return (IntPtr)native_string_format_property.GetValue(format, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
|
||||||
// set of attributes. Change these attribute values to modify the information
|
|
||||||
// associated with an assembly.
|
|
||||||
[assembly: AssemblyTitle("OpenTK.Compatibility")]
|
|
||||||
[assembly: AssemblyDescription("Provides compatibility with previous versions of OpenTK and the Tao framework.")]
|
|
||||||
|
|
||||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|
||||||
[assembly: Guid("7c495044-4b1a-4bff-aee9-ff9dbf85433f")]
|
|
||||||
|
|
||||||
[assembly: System.CLSCompliant(true)]
|
|
||||||
[assembly: System.Security.AllowPartiallyTrustedCallers]
|
|
||||||
#if NET40
|
|
||||||
[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]
|
|
||||||
#endif
|
|
|
@ -1,70 +0,0 @@
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// <auto-generated>
|
|
||||||
// This code was generated by a tool.
|
|
||||||
// Runtime Version:2.0.50727.4927
|
|
||||||
//
|
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
|
||||||
// the code is regenerated.
|
|
||||||
// </auto-generated>
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace OpenTK.Compatibility.Properties {
|
|
||||||
using System;
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
|
||||||
/// </summary>
|
|
||||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
|
||||||
// class via a tool like ResGen or Visual Studio.
|
|
||||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
|
||||||
// with the /str option, or rebuild your VS project.
|
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
|
||||||
internal class Resources {
|
|
||||||
|
|
||||||
private static global::System.Resources.ResourceManager resourceMan;
|
|
||||||
|
|
||||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
|
||||||
|
|
||||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
||||||
internal Resources() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the cached ResourceManager instance used by this class.
|
|
||||||
/// </summary>
|
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
|
||||||
get {
|
|
||||||
if (object.ReferenceEquals(resourceMan, null)) {
|
|
||||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OpenTK.Compatibility.Properties.Resources", typeof(Resources).Assembly);
|
|
||||||
resourceMan = temp;
|
|
||||||
}
|
|
||||||
return resourceMan;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Overrides the current thread's CurrentUICulture property for all
|
|
||||||
/// resource lookups using this strongly typed resource class.
|
|
||||||
/// </summary>
|
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
internal static global::System.Globalization.CultureInfo Culture {
|
|
||||||
get {
|
|
||||||
return resourceCulture;
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
resourceCulture = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static System.Drawing.Bitmap TaoButton {
|
|
||||||
get {
|
|
||||||
object obj = ResourceManager.GetObject("TaoButton", resourceCulture);
|
|
||||||
return ((System.Drawing.Bitmap)(obj));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,124 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:choice maxOccurs="unbounded">
|
|
||||||
<xsd:element name="metadata">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="assembly">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:attribute name="alias" type="xsd:string" />
|
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="data">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="resheader">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:choice>
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:schema>
|
|
||||||
<resheader name="resmimetype">
|
|
||||||
<value>text/microsoft-resx</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="version">
|
|
||||||
<value>2.0</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="reader">
|
|
||||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="writer">
|
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
|
||||||
<data name="TaoButton" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
|
||||||
<value>../Resources/TaoButton.jpg;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
|
||||||
</data>
|
|
||||||
</root>
|
|
Binary file not shown.
Before Width: | Height: | Size: 13 KiB |
|
@ -1,248 +0,0 @@
|
||||||
#region License
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
Copyright ©2003-2006 Tao Framework Team
|
|
||||||
http://www.taoframework.com
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
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 License
|
|
||||||
|
|
||||||
namespace Tao.OpenAl
|
|
||||||
{
|
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
[Obsolete]
|
|
||||||
internal static class Delegates
|
|
||||||
{
|
|
||||||
static Delegates()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a System.Delegate that can be used to call a dynamically exported OpenAL function.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The function string for the OpenAL function</param>
|
|
||||||
/// <param name="signature">The signature of the OpenAL function.</param>
|
|
||||||
/// <returns>
|
|
||||||
/// A System.Delegate that can be used to call this OpenAL function or null
|
|
||||||
/// if the function is not available in the current OpenAL context.
|
|
||||||
/// </returns>
|
|
||||||
public static Delegate GetDelegateForExtensionMethod(string name, Type signature)
|
|
||||||
{
|
|
||||||
IntPtr address = Al.alGetProcAddress(name);
|
|
||||||
if (address == IntPtr.Zero)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Marshal.GetDelegateForFunctionPointer(address, signature);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region X-RAM
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void EAXSetBufferModeDelegate(int n, [Out] int* buffers, int value);
|
|
||||||
internal static EAXSetBufferModeDelegate EAXSetBufferMode = (EAXSetBufferModeDelegate)GetDelegateForExtensionMethod("EAXSetBufferMode", typeof(EAXSetBufferModeDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate int EAXGetBufferModeDelegate(int buffer, [Out] int* reserved);
|
|
||||||
internal static EAXGetBufferModeDelegate EAXGetBufferMode = (EAXGetBufferModeDelegate)GetDelegateForExtensionMethod("EAXGetBufferMode", typeof(EAXGetBufferModeDelegate));
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region EFX_EXT
|
|
||||||
#region alEffect
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGenEffectsDelegate(int size, [Out] int* effects);
|
|
||||||
internal static alGenEffectsDelegate alGenEffects = (alGenEffectsDelegate)GetDelegateForExtensionMethod("alGenEffects", typeof(alGenEffectsDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alDeleteEffectsDelegate(int size, int* effects);
|
|
||||||
internal static alDeleteEffectsDelegate alDeleteEffects = (alDeleteEffectsDelegate)GetDelegateForExtensionMethod("alDeleteEffects", typeof(alDeleteEffectsDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate bool alIsEffectDelegate(int effect);
|
|
||||||
internal static alIsEffectDelegate alIsEffect = (alIsEffectDelegate)GetDelegateForExtensionMethod("alIsEffect", typeof(alIsEffectDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void alEffectiDelegate(int effect, int param, int value);
|
|
||||||
internal static alEffectiDelegate alEffecti = (alEffectiDelegate)GetDelegateForExtensionMethod("alEffecti", typeof(alEffectiDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alEffectivDelegate(int effect, int param, int* value);
|
|
||||||
internal static alEffectivDelegate alEffectiv = (alEffectivDelegate)GetDelegateForExtensionMethod("alEffectiv", typeof(alEffectivDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void alEffectfDelegate(int effect, int param, float value);
|
|
||||||
internal static alEffectfDelegate alEffectf = (alEffectfDelegate)GetDelegateForExtensionMethod("alEffectf", typeof(alEffectfDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alEffectfvDelegate(int effect, int param, float* value);
|
|
||||||
internal static alEffectfvDelegate alEffectfv = (alEffectfvDelegate)GetDelegateForExtensionMethod("alEffectfv", typeof(alEffectfvDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGetEffectiDelegate(int effect, int param, [Out] int* value);
|
|
||||||
internal static alGetEffectiDelegate alGetEffecti = (alGetEffectiDelegate)GetDelegateForExtensionMethod("alGetEffecti", typeof(alGetEffectiDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGetEffectivDelegate(int effect, int param, [Out] int* value);
|
|
||||||
internal static alGetEffectivDelegate alGetEffectiv = (alGetEffectivDelegate)GetDelegateForExtensionMethod("alGetEffectiv", typeof(alGetEffectivDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGetEffectfDelegate(int effect, int param, [Out] float* value);
|
|
||||||
internal static alGetEffectfDelegate alGetEffectf = (alGetEffectfDelegate)GetDelegateForExtensionMethod("alGetEffectf", typeof(alGetEffectfDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGetEffectfvDelegate(int effect, int param, [Out] float* value);
|
|
||||||
internal static alGetEffectfvDelegate alGetEffectfv = (alGetEffectfvDelegate)GetDelegateForExtensionMethod("alGetEffectfv", typeof(alGetEffectfvDelegate));
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region alFilter
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGenFiltersDelegate(int size, [Out] int* Filters);
|
|
||||||
internal static alGenFiltersDelegate alGenFilters = (alGenFiltersDelegate)GetDelegateForExtensionMethod("alGenFilters", typeof(alGenFiltersDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alDeleteFiltersDelegate(int size, int* Filters);
|
|
||||||
internal static alDeleteFiltersDelegate alDeleteFilters = (alDeleteFiltersDelegate)GetDelegateForExtensionMethod("alDeleteFilters", typeof(alDeleteFiltersDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate bool alIsFilterDelegate(int Filter);
|
|
||||||
internal static alIsFilterDelegate alIsFilter = (alIsFilterDelegate)GetDelegateForExtensionMethod("alIsFilter", typeof(alIsFilterDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void alFilteriDelegate(int Filter, int param, int value);
|
|
||||||
internal static alFilteriDelegate alFilteri = (alFilteriDelegate)GetDelegateForExtensionMethod("alFilteri", typeof(alFilteriDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alFilterivDelegate(int Filter, int param, int* value);
|
|
||||||
internal static alFilterivDelegate alFilteriv = (alFilterivDelegate)GetDelegateForExtensionMethod("alFilteriv", typeof(alFilterivDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void alFilterfDelegate(int Filter, int param, float value);
|
|
||||||
internal static alFilterfDelegate alFilterf = (alFilterfDelegate)GetDelegateForExtensionMethod("alFilterf", typeof(alFilterfDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alFilterfvDelegate(int Filter, int param, float* value);
|
|
||||||
internal static alFilterfvDelegate alFilterfv = (alFilterfvDelegate)GetDelegateForExtensionMethod("alFilterfv", typeof(alFilterfvDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGetFilteriDelegate(int Filter, int param, [Out] int* value);
|
|
||||||
internal static alGetFilteriDelegate alGetFilteri = (alGetFilteriDelegate)GetDelegateForExtensionMethod("alGetFilteri", typeof(alGetFilteriDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGetFilterivDelegate(int Filter, int param, [Out] int* value);
|
|
||||||
internal static alGetFilterivDelegate alGetFilteriv = (alGetFilterivDelegate)GetDelegateForExtensionMethod("alGetFilteriv", typeof(alGetFilterivDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGetFilterfDelegate(int Filter, int param, [Out] float* value);
|
|
||||||
internal static alGetFilterfDelegate alGetFilterf = (alGetFilterfDelegate)GetDelegateForExtensionMethod("alGetFilterf", typeof(alGetFilterfDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGetFilterfvDelegate(int Filter, int param, [Out] float* value);
|
|
||||||
internal static alGetFilterfvDelegate alGetFilterfv = (alGetFilterfvDelegate)GetDelegateForExtensionMethod("alGetFilterfv", typeof(alGetFilterfvDelegate));
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region alFilter
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGenAuxiliaryEffectSlotsDelegate(int size, [Out] int* AuxiliaryEffectSlots);
|
|
||||||
internal static alGenAuxiliaryEffectSlotsDelegate alGenAuxiliaryEffectSlots = (alGenAuxiliaryEffectSlotsDelegate)GetDelegateForExtensionMethod("alGenAuxiliaryEffectSlots", typeof(alGenAuxiliaryEffectSlotsDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alDeleteAuxiliaryEffectSlotsDelegate(int size, int* AuxiliaryEffectSlots);
|
|
||||||
internal static alDeleteAuxiliaryEffectSlotsDelegate alDeleteAuxiliaryEffectSlots = (alDeleteAuxiliaryEffectSlotsDelegate)GetDelegateForExtensionMethod("alDeleteAuxiliaryEffectSlots", typeof(alDeleteAuxiliaryEffectSlotsDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate bool alIsAuxiliaryEffectSlotDelegate(int AuxiliaryEffectSlot);
|
|
||||||
internal static alIsAuxiliaryEffectSlotDelegate alIsAuxiliaryEffectSlot = (alIsAuxiliaryEffectSlotDelegate)GetDelegateForExtensionMethod("alIsAuxiliaryEffectSlot", typeof(alIsAuxiliaryEffectSlotDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void alAuxiliaryEffectSlotiDelegate(int AuxiliaryEffectSlot, int param, int value);
|
|
||||||
internal static alAuxiliaryEffectSlotiDelegate alAuxiliaryEffectSloti = (alAuxiliaryEffectSlotiDelegate)GetDelegateForExtensionMethod("alAuxiliaryEffectSloti", typeof(alAuxiliaryEffectSlotiDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alAuxiliaryEffectSlotivDelegate(int AuxiliaryEffectSlot, int param, int* value);
|
|
||||||
internal static alAuxiliaryEffectSlotivDelegate alAuxiliaryEffectSlotiv = (alAuxiliaryEffectSlotivDelegate)GetDelegateForExtensionMethod("alAuxiliaryEffectSlotiv", typeof(alAuxiliaryEffectSlotivDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal delegate void alAuxiliaryEffectSlotfDelegate(int AuxiliaryEffectSlot, int param, float value);
|
|
||||||
internal static alAuxiliaryEffectSlotfDelegate alAuxiliaryEffectSlotf = (alAuxiliaryEffectSlotfDelegate)GetDelegateForExtensionMethod("alAuxiliaryEffectSlotf", typeof(alAuxiliaryEffectSlotfDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alAuxiliaryEffectSlotfvDelegate(int AuxiliaryEffectSlot, int param, float* value);
|
|
||||||
internal static alAuxiliaryEffectSlotfvDelegate alAuxiliaryEffectSlotfv = (alAuxiliaryEffectSlotfvDelegate)GetDelegateForExtensionMethod("alAuxiliaryEffectSlotfv", typeof(alAuxiliaryEffectSlotfvDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGetAuxiliaryEffectSlotiDelegate(int AuxiliaryEffectSlot, int param, [Out] int* value);
|
|
||||||
internal static alGetAuxiliaryEffectSlotiDelegate alGetAuxiliaryEffectSloti = (alGetAuxiliaryEffectSlotiDelegate)GetDelegateForExtensionMethod("alGetAuxiliaryEffectSloti", typeof(alGetAuxiliaryEffectSlotiDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGetAuxiliaryEffectSlotivDelegate(int AuxiliaryEffectSlot, int param, [Out] int* value);
|
|
||||||
internal static alGetAuxiliaryEffectSlotivDelegate alGetAuxiliaryEffectSlotiv = (alGetAuxiliaryEffectSlotivDelegate)GetDelegateForExtensionMethod("alGetAuxiliaryEffectSlotiv", typeof(alGetAuxiliaryEffectSlotivDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGetAuxiliaryEffectSlotfDelegate(int AuxiliaryEffectSlot, int param, [Out] float* value);
|
|
||||||
internal static alGetAuxiliaryEffectSlotfDelegate alGetAuxiliaryEffectSlotf = (alGetAuxiliaryEffectSlotfDelegate)GetDelegateForExtensionMethod("alGetAuxiliaryEffectSlotf", typeof(alGetAuxiliaryEffectSlotfDelegate));
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
|
||||||
internal unsafe delegate void alGetAuxiliaryEffectSlotfvDelegate(int AuxiliaryEffectSlot, int param, [Out] float* value);
|
|
||||||
internal static alGetAuxiliaryEffectSlotfvDelegate alGetAuxiliaryEffectSlotfv = (alGetAuxiliaryEffectSlotfvDelegate)GetDelegateForExtensionMethod("alGetAuxiliaryEffectSlotfv", typeof(alGetAuxiliaryEffectSlotfvDelegate));
|
|
||||||
#endregion
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue