mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-23 11:05:40 +00:00
Merge remote-tracking branch 'andy/master'
This commit is contained in:
commit
c7e04c6097
139
.gitignore
vendored
Normal file
139
.gitignore
vendored
Normal file
|
@ -0,0 +1,139 @@
|
|||
# Ignores specific to OpenTK.
|
||||
Binaries/
|
||||
OpenTK.userprefs
|
||||
Source/GlobalAssemblyInfo.cs
|
||||
Version.txt
|
||||
Source/OpenTK/OpenTK.xml
|
||||
|
||||
# OpenTK Resource files that seem like they should be ignored:
|
||||
Source/Compatibility/Properties/Resources.resources
|
||||
Source/Compatibility/Tao/Platform/Windows/SimpleOpenGlControl.resources
|
||||
Source/Examples/ExampleBrowser.resources
|
||||
Source/Examples/OpenAL/1.1/Parrot.resources
|
||||
Source/Examples/OpenTK/Fonts/FontRenderingBasic.resources
|
||||
Source/Examples/OpenTK/GLControl/DerivedGLControl.resources
|
||||
Source/Examples/OpenTK/GLControl/GLControlGameLoop.resources
|
||||
Source/Examples/OpenTK/GLControl/GLControlSimple.resources
|
||||
Source/Examples/OpenTK/GLControl/MultipleGLControls.resources
|
||||
Source/Examples/OpenTK/Test/Extensions.resources
|
||||
Source/Examples/OpenTK/Test/InputLogger.resources
|
||||
Source/Examples/Properties/Resources.resources
|
||||
Source/OpenTK/Properties/Resources.resources
|
||||
|
||||
|
||||
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
|
||||
# mstest test results
|
||||
TestResults
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# Mac folder attribute metadata file
|
||||
.DS_Store
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.sln.docstates
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
x64/
|
||||
*_i.c
|
||||
*_p.c
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*
|
||||
|
||||
# Mindbench SASS cache
|
||||
.sass-cache/
|
||||
|
||||
# NCrunch
|
||||
*.ncrunch*
|
||||
.*crunch*.local.xml
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish
|
||||
|
||||
# Publish Web Output
|
||||
*.Publish.xml
|
||||
|
||||
# NuGet Packages Directory
|
||||
packages
|
||||
|
||||
# Windows Azure Build Output
|
||||
csx
|
||||
*.build.csdef
|
||||
|
||||
# Windows Store app package directory
|
||||
AppPackages/
|
||||
|
||||
# Others
|
||||
sql
|
||||
TestResults
|
||||
[Tt]est[Rr]esult*
|
||||
*.Cache
|
||||
ClientBin
|
||||
[Ss]tyle[Cc]op.*
|
||||
~$*
|
||||
*.dbmdl
|
||||
Generated_Code #added for RIA/Silverlight projects
|
||||
|
||||
# Backup & report files from converting an old project file to a newer
|
||||
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
|
||||
# SQL Server files
|
||||
App_Data/*.mdf
|
||||
App_Data/*.ldf
|
|
@ -22,7 +22,36 @@
|
|||
<HtmlPath>$(OutputPath)\html</HtmlPath>
|
||||
<ProjectGuid>{650C6F3D-33B5-4216-9536-956AB42C0624}</ProjectGuid>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile />
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>10.0.0</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AssemblyName>Build.Docs</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Documentation|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>Source</OutputPath>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>Source</OutputPath>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>Source</OutputPath>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Nsis|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>Source</OutputPath>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Doxyfile" />
|
||||
|
|
|
@ -17,7 +17,32 @@
|
|||
<PropertyGroup>
|
||||
<ProjectGuid>{ADC34399-7613-44D2-90B2-19250F06FE7A}</ProjectGuid>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile />
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>10.0.0</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AssemblyName>Build.Installer.Nsis</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Documentation|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Nsis|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="opentk.nsi" />
|
||||
|
@ -25,9 +50,9 @@
|
|||
<Target Name="Build">
|
||||
<Exec Command="makensis opentk.nsi" />
|
||||
<ReadLinesFromFile File="../../Version.txt">
|
||||
<Output TaskParameter="Lines" ItemName="Version"/>
|
||||
<Output TaskParameter="Lines" ItemName="Version" />
|
||||
</ReadLinesFromFile>
|
||||
<Copy SourceFiles=".\opentk.exe" DestinationFiles="@(Version->'../../opentk-%(Identity).exe')" />
|
||||
<Copy SourceFiles=".\opentk.exe" DestinationFiles="@(Version->'../../opentk-%(Identity).exe')" />
|
||||
</Target>
|
||||
<Target Name="Clean">
|
||||
<CreateItem Include=".\opentk.exe;..\..\opentk-*.exe">
|
||||
|
|
|
@ -15,39 +15,53 @@
|
|||
<PropertyGroup>
|
||||
<ProjectGuid>{ADC34399-7613-44D2-90B2-19250F06FE7B}</ProjectGuid>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile />
|
||||
<InputPath>..\..\</InputPath>
|
||||
<OutputPath>.\opentk\</OutputPath>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>10.0.0</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AssemblyName>Build.Installer.Zip</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Documentation|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>opentk\</OutputPath>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>opentk\</OutputPath>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>opentk\</OutputPath>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Nsis|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>opentk\</OutputPath>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<Target Name="Build">
|
||||
<CallTarget Targets="CleanTreeCopy" />
|
||||
<!-- Make a clean copy of the source tree -->
|
||||
<CreateItem
|
||||
Include="$(InputPath)**\*.*"
|
||||
Exclude="$(InputPath)**\.svn\**\*.*;
|
||||
$(InputPath)**\obj\**\*.*;
|
||||
$(InputPath)Installers\Zip\opentk\**\*.*;
|
||||
$(InputPath)Documentation\Source\**\*.*;
|
||||
$(InputPath)Automation\**\*.*;
|
||||
$(InputPath)Old\**\*.*;
|
||||
$(InputPath)**\OpenTK*.xml;
|
||||
$(InputPath)**\*.suo;
|
||||
$(InputPath)**\*.pidb;
|
||||
$(InputPath)**\*.userprefs;
|
||||
$(InputPath)**\opentk*.zip;
|
||||
$(InputPath)**\opentk*.exe;
|
||||
$(InputPath)**\vshost*.exe;
|
||||
">
|
||||
<Output TaskParameter="Include" ItemName="FileList" />
|
||||
<CreateItem Include="$(InputPath)**\*.*" Exclude="$(InputPath)**\.svn\**\*.*;
 $(InputPath)**\obj\**\*.*;
 $(InputPath)Installers\Zip\opentk\**\*.*;
 $(InputPath)Documentation\Source\**\*.*;
 $(InputPath)Automation\**\*.*;
 $(InputPath)Old\**\*.*;
 $(InputPath)**\OpenTK*.xml;
 $(InputPath)**\*.suo;
 $(InputPath)**\*.pidb;
 $(InputPath)**\*.userprefs;
 $(InputPath)**\opentk*.zip;
 $(InputPath)**\opentk*.exe;
 $(InputPath)**\vshost*.exe;
 ">
|
||||
<Output TaskParameter="Include" ItemName="FileList" />
|
||||
</CreateItem>
|
||||
<Copy SourceFiles="@(FileList)" DestinationFiles="@(FileList->'$(OutputPath)%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
<Copy SourceFiles="@(FileList)" DestinationFiles="@(FileList->'$(OutputPath)%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
<!-- Zip the copy of the source tree -->
|
||||
<Exec Command="7z a -tzip opentk.zip $(OutputPath)" />
|
||||
<!-- Copy the zip file to the root directory and add a date stamp -->
|
||||
<ReadLinesFromFile File="../../Version.txt">
|
||||
<Output TaskParameter="Lines" ItemName="Version"/>
|
||||
<Output TaskParameter="Lines" ItemName="Version" />
|
||||
</ReadLinesFromFile>
|
||||
<Copy SourceFiles=".\opentk.zip" DestinationFiles="@(Version->'..\..\opentk-%(Identity).zip')" />
|
||||
<Copy SourceFiles=".\opentk.zip" DestinationFiles="@(Version->'..\..\opentk-%(Identity).zip')" />
|
||||
</Target>
|
||||
<Target Name="Clean">
|
||||
<CreateItem Include=".\opentk.zip;..\..\opentk-*.zip">
|
||||
|
|
76
OpenTK.sln
76
OpenTK.sln
|
@ -1,3 +1,4 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTK", "Source\OpenTK\OpenTK.csproj", "{A37A7E14-0000-0000-0000-000000000000}"
|
||||
|
@ -66,20 +67,38 @@ Global
|
|||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A37A7E14-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A37A7E14-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A37A7E14-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
|
||||
{A37A7E14-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU
|
||||
{A37A7E14-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU
|
||||
{A37A7E14-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A37A7E14-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{31D19132-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{31D19132-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
|
||||
{31D19132-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU
|
||||
{31D19132-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU
|
||||
{31D19132-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{31D19132-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5FDFF4B6-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5FDFF4B6-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
|
||||
{5FDFF4B6-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU
|
||||
{5FDFF4B6-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU
|
||||
{5FDFF4B6-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5FDFF4B6-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|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}.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
|
||||
{650C6F3D-33B5-4216-9536-956AB42C0624}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{650C6F3D-33B5-4216-9536-956AB42C0624}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
|
||||
{650C6F3D-33B5-4216-9536-956AB42C0624}.Documentation|Any CPU.Build.0 = Documentation|Any CPU
|
||||
{650C6F3D-33B5-4216-9536-956AB42C0624}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU
|
||||
{650C6F3D-33B5-4216-9536-956AB42C0624}.Nsis|Any CPU.Build.0 = Nsis|Any CPU
|
||||
{650C6F3D-33B5-4216-9536-956AB42C0624}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Documentation|Any CPU.Build.0 = Documentation|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Nsis|Any CPU.Build.0 = Nsis|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Release|Any CPU.Build.0 = Release|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}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
|
||||
|
@ -87,6 +106,13 @@ Global
|
|||
{868E37B3-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU
|
||||
{868E37B3-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{868E37B3-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A37A7E14-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A37A7E14-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A37A7E14-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
|
||||
{A37A7E14-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU
|
||||
{A37A7E14-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU
|
||||
{A37A7E14-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A37A7E14-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A625BE88-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A625BE88-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A625BE88-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
|
||||
|
@ -99,44 +125,16 @@ Global
|
|||
{ADC34399-7613-44D2-90B2-19250F06FE7A}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU
|
||||
{ADC34399-7613-44D2-90B2-19250F06FE7A}.Nsis|Any CPU.Build.0 = Nsis|Any CPU
|
||||
{ADC34399-7613-44D2-90B2-19250F06FE7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{650C6F3D-33B5-4216-9536-956AB42C0624}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{650C6F3D-33B5-4216-9536-956AB42C0624}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
|
||||
{650C6F3D-33B5-4216-9536-956AB42C0624}.Documentation|Any CPU.Build.0 = Documentation|Any CPU
|
||||
{650C6F3D-33B5-4216-9536-956AB42C0624}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU
|
||||
{650C6F3D-33B5-4216-9536-956AB42C0624}.Nsis|Any CPU.Build.0 = Nsis|Any CPU
|
||||
{650C6F3D-33B5-4216-9536-956AB42C0624}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{31D19132-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{31D19132-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{31D19132-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
|
||||
{31D19132-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU
|
||||
{31D19132-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU
|
||||
{31D19132-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{31D19132-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5FDFF4B6-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5FDFF4B6-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5FDFF4B6-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
|
||||
{5FDFF4B6-0000-0000-0000-000000000000}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU
|
||||
{5FDFF4B6-0000-0000-0000-000000000000}.Nsis|Any CPU.Build.0 = Nsis|Any CPU
|
||||
{5FDFF4B6-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5FDFF4B6-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Documentation|Any CPU.Build.0 = Documentation|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Nsis|Any CPU.Build.0 = Nsis|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{75DC22B1-113F-4A66-96B9-2FF8208C10E8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{ADC34399-7613-44D2-90B2-19250F06FE7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ADC34399-7613-44D2-90B2-19250F06FE7B}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU
|
||||
{ADC34399-7613-44D2-90B2-19250F06FE7B}.Nsis|Any CPU.ActiveCfg = Nsis|Any CPU
|
||||
{ADC34399-7613-44D2-90B2-19250F06FE7B}.Nsis|Any CPU.Build.0 = Nsis|Any CPU
|
||||
{ADC34399-7613-44D2-90B2-19250F06FE7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = Source\Examples\OpenTK.Examples.csproj
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
20
README.md
Normal file
20
README.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
OpenTK
|
||||
======
|
||||
|
||||
The Open Toolkit is an advanced, low-level C# library that wraps OpenGL, OpenCL and OpenAL. The OpenTK home is http://www.opentk.com/
|
||||
|
||||
This is an unofficial fork for community changes that we hope will someday make it into the official repository. Unfortunately, the only official maintainer of OpenTK has been missing since early 2012.
|
||||
|
||||
This fork was created from the latest official SVN repository. It contains numerous fixes by the original maintainer that are not found in the last release (2010-10-06). This fork is based on AndyKorth's OpenTK fork with lots of fixes from all over the community.
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
The best source of documentation is the [OpenTK Manual](http://www.opentk.com/doc)
|
||||
|
||||
Need Help?
|
||||
==========
|
||||
|
||||
Head over to the [OpenTK forums](http://www.opentk.com/forum). It's the best way to reach the community.
|
||||
|
||||
OpenTK Version: 1.1.1160.61462 (build 2013-03-07), also available via nuget (OpenTK and OpenTKWithOpenAL) and used in the DeltaEngine.
|
|
@ -25,7 +25,6 @@
|
|||
</FileUpgradeFlags>
|
||||
<OldToolsVersion>2.0</OldToolsVersion>
|
||||
<UpgradeBackupLocation />
|
||||
<TargetFrameworkProfile />
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
|
@ -49,9 +48,9 @@
|
|||
<DefineConstants>DEBUG;TRACE;</DefineConstants>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugSymbols>True</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>false</Optimize>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Debug\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -67,7 +66,7 @@
|
|||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -83,7 +82,7 @@
|
|||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -95,11 +94,11 @@
|
|||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<DebugType>none</DebugType>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<SignAssembly>True</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>..\..\OpenTK.snk</AssemblyOriginatorKeyFile>
|
||||
|
@ -107,15 +106,12 @@
|
|||
<ItemGroup>
|
||||
<Reference Include="System">
|
||||
<Name>System</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Core">
|
||||
<Name>System.Core</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml">
|
||||
<Name>System.Xml</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -1040,7 +1036,6 @@
|
|||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
|
@ -51,7 +50,7 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugSymbols>True</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -1,168 +1,191 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2010 the Open Toolkit library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Build.UpdateVersion
|
||||
{
|
||||
class Program
|
||||
{
|
||||
const string Major = "1";
|
||||
const string Minor = "1";
|
||||
|
||||
static string RootDirectory;
|
||||
static string SourceDirectory;
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
string wdir = Environment.CurrentDirectory;
|
||||
if (Directory.GetParent(wdir).Name == "Source")
|
||||
{
|
||||
// Running through msbuild inside Source/Build.UpdateVersion/
|
||||
RootDirectory = "../..";
|
||||
SourceDirectory = "..";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Running manually inside Binaries/OpenTK/[Debug|Release]/
|
||||
RootDirectory = "../../..";
|
||||
SourceDirectory = "../../../Source";
|
||||
}
|
||||
|
||||
DateTime now = DateTime.UtcNow;
|
||||
GenerateVersionInfo(now, Path.Combine(RootDirectory, "Version.txt"));
|
||||
GenerateAssemblyInfo(now, Path.Combine(SourceDirectory, "GlobalAssemblyInfo.cs"));
|
||||
}
|
||||
|
||||
static void GenerateVersionInfo(DateTime now, string file)
|
||||
{
|
||||
string version = null;
|
||||
|
||||
if (System.IO.File.Exists(file))
|
||||
{
|
||||
string[] lines = System.IO.File.ReadAllLines(file);
|
||||
if (lines.Length > 0 && !String.IsNullOrEmpty(lines[0]))
|
||||
{
|
||||
version = lines[0];
|
||||
}
|
||||
}
|
||||
|
||||
// If the file does not exist, create it.
|
||||
if (version == null)
|
||||
{
|
||||
version = now.ToString("u").Split(' ')[0];
|
||||
System.IO.File.WriteAllLines(file, new string[] { version });
|
||||
}
|
||||
}
|
||||
|
||||
static void GenerateAssemblyInfo(DateTime now, string file)
|
||||
{
|
||||
// Build number is defined as the number of days since 1/1/2010.
|
||||
// Revision number is defined as the fraction of the current day, expressed in seconds.
|
||||
double timespan = now.Subtract(new DateTime(2010, 1, 1)).TotalDays;
|
||||
string build = ((int)timespan).ToString();
|
||||
|
||||
string revision = RetrieveSvnRevision() ?? RetrieveBzrRevision() ?? RetrieveSeconds(timespan);
|
||||
revision = revision.Trim();
|
||||
|
||||
File.WriteAllLines(file, new string[]
|
||||
{
|
||||
"// This file is auto-generated through Source/Build.Tasks/GenerateAssemblyInfo.cs.",
|
||||
"// Do not edit by hand!",
|
||||
"",
|
||||
"using System;",
|
||||
"using System.Reflection;",
|
||||
"using System.Resources;",
|
||||
"using System.Runtime.CompilerServices;",
|
||||
"using System.Runtime.InteropServices;",
|
||||
"",
|
||||
"[assembly: AssemblyCompany(\"The Open Toolkit Library\")]",
|
||||
"[assembly: AssemblyProduct(\"The Open Toolkit Library\")]",
|
||||
"[assembly: AssemblyCopyright(\"Copyright © 2006 - 2010 the Open Toolkit Library\")]",
|
||||
"[assembly: AssemblyTrademark(\"OpenTK\")]",
|
||||
String.Format("[assembly: AssemblyVersion(\"{0}.{1}.0.0\")]", Major, Minor),
|
||||
String.Format("[assembly: AssemblyFileVersion(\"{0}.{1}.{2}.{3}\")]", Major, Minor, build, revision),
|
||||
});
|
||||
}
|
||||
|
||||
static string RetrieveSeconds(double timespan)
|
||||
{
|
||||
string revision = ((int)((timespan - (int)timespan) * UInt16.MaxValue)).ToString();
|
||||
return revision;
|
||||
}
|
||||
|
||||
static string RetrieveSvnRevision()
|
||||
{
|
||||
try
|
||||
{
|
||||
string output = RunProcess("svn", "info", RootDirectory);
|
||||
|
||||
const string RevisionText = "Revision: ";
|
||||
int index = output.IndexOf(RevisionText);
|
||||
if (index > -1)
|
||||
return output.Substring(index + RevisionText.Length, 5)
|
||||
.Replace('\r', ' ').Replace('\n', ' ').Trim();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Print("Failed to retrieve svn revision. Error: {0}", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static string RetrieveBzrRevision()
|
||||
{
|
||||
try
|
||||
{
|
||||
string output = RunProcess("bzr", "revno", RootDirectory);
|
||||
return output != null && !output.StartsWith("bzr") ? output : null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Print("Failed to retrieve svn revision. Error: {0}", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static string RunProcess(string cmd, string args, string wdir)
|
||||
{
|
||||
ProcessStartInfo info = new ProcessStartInfo(cmd, args);
|
||||
info.WorkingDirectory = wdir;
|
||||
info.RedirectStandardOutput = true;
|
||||
info.RedirectStandardError = true;
|
||||
info.UseShellExecute = false;
|
||||
Process p = new Process();
|
||||
p.StartInfo = info;
|
||||
p.Start();
|
||||
p.WaitForExit();
|
||||
string output = p.StandardOutput.ReadToEnd();
|
||||
return output;
|
||||
}
|
||||
}
|
||||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2010 the Open Toolkit library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Build.UpdateVersion
|
||||
{
|
||||
class Program
|
||||
{
|
||||
const string Major = "1";
|
||||
const string Minor = "1";
|
||||
|
||||
static string RootDirectory;
|
||||
static string SourceDirectory;
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
string wdir = Environment.CurrentDirectory;
|
||||
if (Directory.GetParent(wdir).Name == "Source")
|
||||
{
|
||||
// Running through msbuild inside Source/Build.UpdateVersion/
|
||||
RootDirectory = "../..";
|
||||
SourceDirectory = "..";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Running manually inside Binaries/OpenTK/[Debug|Release]/
|
||||
RootDirectory = "../../..";
|
||||
SourceDirectory = "../../../Source";
|
||||
}
|
||||
|
||||
DateTime now = DateTime.UtcNow;
|
||||
GenerateVersionInfo(now, Path.Combine(RootDirectory, "Version.txt"));
|
||||
GenerateAssemblyInfo(now, Path.Combine(SourceDirectory, "GlobalAssemblyInfo.cs"));
|
||||
}
|
||||
|
||||
static void GenerateVersionInfo(DateTime now, string file)
|
||||
{
|
||||
string version = null;
|
||||
|
||||
if (System.IO.File.Exists(file))
|
||||
{
|
||||
string[] lines = System.IO.File.ReadAllLines(file);
|
||||
if (lines.Length > 0 && !String.IsNullOrEmpty(lines[0]))
|
||||
{
|
||||
version = lines[0];
|
||||
}
|
||||
}
|
||||
|
||||
// If the file does not exist, create it.
|
||||
if (version == null)
|
||||
{
|
||||
version = now.ToString("u").Split(' ')[0];
|
||||
System.IO.File.WriteAllLines(file, new string[] { version });
|
||||
}
|
||||
}
|
||||
|
||||
static void GenerateAssemblyInfo(DateTime now, string file)
|
||||
{
|
||||
// Build number is defined as the number of days since 1/1/2010.
|
||||
// Revision number is defined as the fraction of the current day, expressed in seconds.
|
||||
double timespan = now.Subtract(new DateTime(2010, 1, 1)).TotalDays;
|
||||
string build = ((int)timespan).ToString();
|
||||
|
||||
string revision = RetrieveGitRevision() ?? RetrieveSvnRevision() ?? RetrieveBzrRevision() ?? RetrieveSeconds(timespan);
|
||||
revision = revision.Trim();
|
||||
|
||||
Console.WriteLine("Build timestamp was: " + build);
|
||||
Console.WriteLine("Revision detected was: " + revision);
|
||||
|
||||
File.WriteAllLines(file, new string[]
|
||||
{
|
||||
"// This file is auto-generated through Source/Build.Tasks/GenerateAssemblyInfo.cs.",
|
||||
"// Do not edit by hand!",
|
||||
"",
|
||||
"using System;",
|
||||
"using System.Reflection;",
|
||||
"using System.Resources;",
|
||||
"using System.Runtime.CompilerServices;",
|
||||
"using System.Runtime.InteropServices;",
|
||||
"",
|
||||
"[assembly: AssemblyCompany(\"The Open Toolkit Library\")]",
|
||||
"[assembly: AssemblyProduct(\"The Open Toolkit Library\")]",
|
||||
"[assembly: AssemblyCopyright(\"Copyright © 2006 - 2010 the Open Toolkit Library\")]",
|
||||
"[assembly: AssemblyTrademark(\"OpenTK\")]",
|
||||
String.Format("[assembly: AssemblyVersion(\"{0}.{1}.0.0\")]", Major, Minor),
|
||||
String.Format("[assembly: AssemblyFileVersion(\"{0}.{1}.{2}.{3}\")]", Major, Minor, build, revision),
|
||||
});
|
||||
}
|
||||
|
||||
static string RetrieveSeconds(double timespan)
|
||||
{
|
||||
string revision = ((int)((timespan - (int)timespan) * UInt16.MaxValue)).ToString();
|
||||
return revision;
|
||||
}
|
||||
|
||||
static string RetrieveGitRevision()
|
||||
{
|
||||
try
|
||||
{
|
||||
string output = RunProcess("git", "log -1", RootDirectory);
|
||||
|
||||
const string RevisionText = "commit ";
|
||||
int index = output.IndexOf(RevisionText);
|
||||
int endIndex = output.IndexOf("\n"); // since it's the first line...
|
||||
if (index > -1)
|
||||
return output.Substring(index + RevisionText.Length, endIndex - index - RevisionText.Length).Trim();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Print("Failed to retrieve git revision. Error: {0}", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
static string RetrieveSvnRevision()
|
||||
{
|
||||
try
|
||||
{
|
||||
string output = RunProcess("svn", "info", RootDirectory);
|
||||
|
||||
const string RevisionText = "Revision: ";
|
||||
int index = output.IndexOf(RevisionText);
|
||||
if (index > -1)
|
||||
return output.Substring(index + RevisionText.Length, 5)
|
||||
.Replace('\r', ' ').Replace('\n', ' ').Trim();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Print("Failed to retrieve svn revision. Error: {0}", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static string RetrieveBzrRevision()
|
||||
{
|
||||
try
|
||||
{
|
||||
string output = RunProcess("bzr", "revno", RootDirectory);
|
||||
return output != null && !output.StartsWith("bzr") ? output : null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Print("Failed to retrieve svn revision. Error: {0}", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static string RunProcess(string cmd, string args, string wdir)
|
||||
{
|
||||
ProcessStartInfo info = new ProcessStartInfo(cmd, args);
|
||||
info.WorkingDirectory = wdir;
|
||||
info.RedirectStandardOutput = true;
|
||||
info.RedirectStandardError = true;
|
||||
info.UseShellExecute = false;
|
||||
Process p = new Process();
|
||||
p.StartInfo = info;
|
||||
p.Start();
|
||||
p.WaitForExit();
|
||||
string output = p.StandardOutput.ReadToEnd();
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -42,16 +42,16 @@
|
|||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>DEBUG;TRACE;</DefineConstants>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugSymbols>True</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>false</Optimize>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Debug\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -61,7 +61,7 @@
|
|||
<DebugType>full</DebugType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
|
@ -69,7 +69,7 @@
|
|||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -83,11 +83,11 @@
|
|||
<DebugType>none</DebugType>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoWarn>0219, 0414, 0612, 0618, 1591, 3005, 3006</NoWarn>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Nsis|AnyCPU'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
|
@ -95,7 +95,7 @@
|
|||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -105,7 +105,7 @@
|
|||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<SignAssembly>True</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>..\..\OpenTK.snk</AssemblyOriginatorKeyFile>
|
||||
|
@ -113,23 +113,18 @@
|
|||
<ItemGroup>
|
||||
<Reference Include="System">
|
||||
<Name>System</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Data">
|
||||
<Name>System.Data</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing">
|
||||
<Name>System.Drawing</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows.Forms">
|
||||
<Name>System.Windows.Forms</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml">
|
||||
<Name>System.Xml</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -47,9 +47,9 @@
|
|||
<DefineConstants>DEBUG;TRACE;</DefineConstants>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugSymbols>True</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>false</Optimize>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Debug\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -65,7 +65,7 @@
|
|||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -77,7 +77,7 @@
|
|||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<DebugType>none</DebugType>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Nsis|AnyCPU'">
|
||||
|
@ -88,7 +88,7 @@
|
|||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -97,7 +97,7 @@
|
|||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<SignAssembly>True</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>..\..\OpenTK.snk</AssemblyOriginatorKeyFile>
|
||||
|
@ -105,19 +105,15 @@
|
|||
<ItemGroup>
|
||||
<Reference Include="System">
|
||||
<Name>System</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Core">
|
||||
<Name>System.Core</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml">
|
||||
<Name>System.Xml</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<Name>System.Xml.Linq</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -166,7 +162,6 @@
|
|||
<None Include="Readme.txt">
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
|
|
|
@ -1,57 +1,57 @@
|
|||
// Copyright (c) 2008 the OpenTK Team. See license.txt for legal bla
|
||||
|
||||
// Material uniforms
|
||||
uniform sampler2D Material_DiffuseAndHeight;
|
||||
uniform sampler2D Material_NormalAndGloss;
|
||||
uniform vec3 Material_ScaleBiasShininess; // x=Scale, y=Bias, z=Shininess
|
||||
|
||||
// Light uniforms
|
||||
uniform vec3 Light_DiffuseColor;
|
||||
uniform vec3 Light_SpecularColor;
|
||||
|
||||
// from VS
|
||||
varying vec3 VaryingLightVector;
|
||||
varying vec3 VaryingEyeVector;
|
||||
|
||||
vec3 normal;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lightVector = normalize( VaryingLightVector );
|
||||
vec3 eyeVector = normalize( VaryingEyeVector );
|
||||
|
||||
// first, find the parallax displacement by reading only the height map
|
||||
float parallaxOffset = texture2D( Material_DiffuseAndHeight, gl_TexCoord[0].st ).a *
|
||||
Material_ScaleBiasShininess.x - Material_ScaleBiasShininess.y;
|
||||
vec2 newTexCoords = gl_TexCoord[0].st + ( parallaxOffset * eyeVector.xy ); // displace texcoords according to viewer
|
||||
|
||||
// knowing the displacement, read RGB, Normal and Gloss
|
||||
vec3 diffuseColor = texture2D( Material_DiffuseAndHeight, newTexCoords.st ).rgb;
|
||||
vec4 temp = texture2D( Material_NormalAndGloss, newTexCoords.st );
|
||||
|
||||
// build a usable normal vector
|
||||
normal.xy = temp.ag * 2.0 - 1.0; // swizzle alpha and green to x/y and scale to [-1..+1]
|
||||
normal.z = sqrt( 1.0 - normal.x*normal.x - normal.y*normal.y ); // z = sqrt(1-x²-y²)
|
||||
|
||||
// move other properties to be better readable
|
||||
float gloss = temp.r;
|
||||
|
||||
// float alpha = temp.b;
|
||||
// if ( alpha < 0.2 ) // optimization: should move this test before reading RGB texture
|
||||
// discard;
|
||||
|
||||
// tweaked phong lighting
|
||||
float lambert = max( dot( lightVector, normal ), 0.0 );
|
||||
|
||||
gl_FragColor = vec4( Light_DiffuseColor * diffuseColor, 1.0 ) *
|
||||
lambert;
|
||||
|
||||
if ( lambert > 0.0 )
|
||||
{
|
||||
float specular = pow(
|
||||
clamp( dot( reflect( -lightVector, normal ), eyeVector ), 0.0, 1.0 ),
|
||||
Material_ScaleBiasShininess.z );
|
||||
|
||||
gl_FragColor += vec4( Light_SpecularColor * diffuseColor, 1.0 ) * ( specular * gloss );
|
||||
}
|
||||
// Copyright (c) 2008 the OpenTK Team. See license.txt for legal bla
|
||||
|
||||
// Material uniforms
|
||||
uniform sampler2D Material_DiffuseAndHeight;
|
||||
uniform sampler2D Material_NormalAndGloss;
|
||||
uniform vec3 Material_ScaleBiasShininess; // x=Scale, y=Bias, z=Shininess
|
||||
|
||||
// Light uniforms
|
||||
uniform vec3 Light_DiffuseColor;
|
||||
uniform vec3 Light_SpecularColor;
|
||||
|
||||
// from VS
|
||||
varying vec3 VaryingLightVector;
|
||||
varying vec3 VaryingEyeVector;
|
||||
|
||||
vec3 normal;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lightVector = normalize( VaryingLightVector );
|
||||
vec3 eyeVector = normalize( VaryingEyeVector );
|
||||
|
||||
// first, find the parallax displacement by reading only the height map
|
||||
float parallaxOffset = texture2D( Material_DiffuseAndHeight, gl_TexCoord[0].st ).a *
|
||||
Material_ScaleBiasShininess.x - Material_ScaleBiasShininess.y;
|
||||
vec2 newTexCoords = gl_TexCoord[0].st + ( parallaxOffset * eyeVector.xy ); // displace texcoords according to viewer
|
||||
|
||||
// knowing the displacement, read RGB, Normal and Gloss
|
||||
vec3 diffuseColor = texture2D( Material_DiffuseAndHeight, newTexCoords.st ).rgb;
|
||||
vec4 temp = texture2D( Material_NormalAndGloss, newTexCoords.st );
|
||||
|
||||
// build a usable normal vector
|
||||
normal.xy = temp.ag * 2.0 - 1.0; // swizzle alpha and green to x/y and scale to [-1..+1]
|
||||
normal.z = sqrt( 1.0 - normal.x*normal.x - normal.y*normal.y ); // z = sqrt(1-x^2-y^2)
|
||||
|
||||
// move other properties to be better readable
|
||||
float gloss = temp.r;
|
||||
|
||||
// float alpha = temp.b;
|
||||
// if ( alpha < 0.2 ) // optimization: should move this test before reading RGB texture
|
||||
// discard;
|
||||
|
||||
// tweaked phong lighting
|
||||
float lambert = max( dot( lightVector, normal ), 0.0 );
|
||||
|
||||
gl_FragColor = vec4( Light_DiffuseColor * diffuseColor, 1.0 ) *
|
||||
lambert;
|
||||
|
||||
if ( lambert > 0.0 )
|
||||
{
|
||||
float specular = pow(
|
||||
clamp( dot( reflect( -lightVector, normal ), eyeVector ), 0.0, 1.0 ),
|
||||
Material_ScaleBiasShininess.z );
|
||||
|
||||
gl_FragColor += vec4( Light_SpecularColor * diffuseColor, 1.0 ) * ( specular * gloss );
|
||||
}
|
||||
}
|
|
@ -41,10 +41,19 @@ namespace Examples
|
|||
public static void Main()
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
// This seems to be useful enough to leave in for a while.
|
||||
TextWriterTraceListener console = new TextWriterTraceListener(System.Console.Out);
|
||||
Trace.Listeners.Add (console);
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
// The ExampleBrowser works pretty poorly on some platforms, so you may want to start examples directly.
|
||||
// for example: Examples.Tutorial.T12_GLSL_Parallax.Main ();
|
||||
// Examples.Tutorial.T10_GLSL_Cube.Main ();
|
||||
Examples.Tests.BasicMouseInput.Main ();
|
||||
|
||||
using (Form browser = new ExampleBrowser())
|
||||
{
|
||||
try
|
||||
|
|
|
@ -44,16 +44,16 @@
|
|||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>DEBUG;TRACE;</DefineConstants>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugSymbols>True</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>false</Optimize>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Debug\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -62,7 +62,7 @@
|
|||
<DebugType>full</DebugType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
|
@ -70,7 +70,7 @@
|
|||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -82,11 +82,11 @@
|
|||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<DebugType>none</DebugType>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Nsis|AnyCPU'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
|
@ -94,7 +94,7 @@
|
|||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -103,7 +103,7 @@
|
|||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<SignAssembly>True</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>..\..\OpenTK.snk</AssemblyOriginatorKeyFile>
|
||||
|
@ -111,23 +111,18 @@
|
|||
<ItemGroup>
|
||||
<Reference Include="System">
|
||||
<Name>System</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Data">
|
||||
<Name>System.Data</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing">
|
||||
<Name>System.Drawing</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows.Forms">
|
||||
<Name>System.Windows.Forms</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml">
|
||||
<Name>System.Xml</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -560,6 +555,10 @@
|
|||
<None Include="..\OpenTK\OpenTK.dll.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Compile Include="OpenTK\Test\BasicMouseInput.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="OpenTK\Test\MatrixTest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
|
|
89
Source/Examples/OpenTK/Test/BasicMouseInput.cs
Normal file
89
Source/Examples/OpenTK/Test/BasicMouseInput.cs
Normal file
|
@ -0,0 +1,89 @@
|
|||
// This code was written for the OpenTK library and has been released
|
||||
// to the Public Domain by Andy Korth
|
||||
// It is provided "as is" without express or implied warranty of any kind.
|
||||
|
||||
#region --- Using Directives ---
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using OpenTK.Input;
|
||||
|
||||
#endregion --- Using Directives ---
|
||||
|
||||
namespace Examples.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Demonstrates basic recommended mouse input, and to see if it actually works
|
||||
/// </summary>
|
||||
[Example("Basic Mouse Input", ExampleCategory.OpenTK,"Basic Mouse Input")]
|
||||
public class BasicMouseInput : GameWindow
|
||||
{
|
||||
|
||||
public BasicMouseInput()
|
||||
: base(800, 600)
|
||||
{ }
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
|
||||
this.Mouse.ButtonUp += (object sender, MouseButtonEventArgs buttonEvent) => {
|
||||
Console.WriteLine("Mouse button up: " + buttonEvent.Button + " at: " + buttonEvent.Position);
|
||||
};
|
||||
|
||||
GL.ClearColor(Color.MidnightBlue);
|
||||
GL.Enable(EnableCap.DepthTest);
|
||||
}
|
||||
|
||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
base.OnUpdateFrame(e);
|
||||
|
||||
// Here's the big test!
|
||||
if(OpenTK.Input.Mouse.GetState()[MouseButton.Left]){
|
||||
Console.WriteLine("The left mouse button is down!");
|
||||
}
|
||||
|
||||
|
||||
// While we are here, test keyboard.
|
||||
if(OpenTK.Input.Keyboard.GetState()[Key.A]){
|
||||
Console.WriteLine("The A key is down!");
|
||||
}
|
||||
|
||||
if (Keyboard[OpenTK.Input.Key.Escape])
|
||||
this.Exit();
|
||||
|
||||
if (Keyboard[OpenTK.Input.Key.F11])
|
||||
if (WindowState != WindowState.Fullscreen)
|
||||
WindowState = WindowState.Fullscreen;
|
||||
else
|
||||
WindowState = WindowState.Normal;
|
||||
}
|
||||
|
||||
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
using (BasicMouseInput example = new BasicMouseInput())
|
||||
{
|
||||
// Get the title and category of this example using reflection.
|
||||
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
|
||||
example.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
|
||||
|
||||
example.Run(30.0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
34
Source/Examples/OpenTK/Test/MatrixTest.cs
Normal file
34
Source/Examples/OpenTK/Test/MatrixTest.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
// This code was written for the OpenTK library and has been released
|
||||
// to the Public Domain.
|
||||
// It is provided "as is" without express or implied warranty of any kind.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using OpenTK;
|
||||
|
||||
namespace Examples.Tests
|
||||
{
|
||||
[Example("Matrix math test", ExampleCategory.OpenTK, "Test", Visible = false)]
|
||||
public class MatrixTest
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
float x = 1.0f;
|
||||
float y = 1.0f;
|
||||
float z = 1.0f;
|
||||
|
||||
Matrix4 createdTranslation = Matrix4.CreateTranslation(new Vector3(2, 3, -1));
|
||||
|
||||
Matrix4 translation = new Matrix4(new Vector4(1, 0, 0, 2), new Vector4(0, 1, 0, 3), new Vector4(0, 0, 1, -1), new Vector4(0, 0, 0, 1));
|
||||
Vector4 point = new Vector4(x, y, z, 1);
|
||||
|
||||
Vector4 result = Vector4.Transform(point, translation);
|
||||
|
||||
Trace.WriteLine("Result should be: (3, 4, 0, 1) : " + result);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -42,15 +42,15 @@
|
|||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>DEBUG;TRACE;</DefineConstants>
|
||||
<DocumentationFile>OpenTK.GLControl.xml</DocumentationFile>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugSymbols>True</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>false</Optimize>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Debug\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -59,14 +59,14 @@
|
|||
<DebugType>full</DebugType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
<DocumentationFile>OpenTK.GLControl.xml</DocumentationFile>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -78,18 +78,18 @@
|
|||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<DebugType>none</DebugType>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Nsis|AnyCPU'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
<DocumentationFile>OpenTK.GLControl.xml</DocumentationFile>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -98,7 +98,7 @@
|
|||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<SignAssembly>True</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>..\..\OpenTK.snk</AssemblyOriginatorKeyFile>
|
||||
|
@ -106,23 +106,18 @@
|
|||
<ItemGroup>
|
||||
<Reference Include="System">
|
||||
<Name>System</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Data">
|
||||
<Name>System.Data</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing">
|
||||
<Name>System.Drawing</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows.Forms">
|
||||
<Name>System.Windows.Forms</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml">
|
||||
<Name>System.Xml</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -34,6 +34,7 @@ namespace OpenTK.Graphics.ES10
|
|||
#pragma warning disable 1591
|
||||
#pragma warning disable 1572
|
||||
#pragma warning disable 1573
|
||||
#pragma warning disable 3006
|
||||
|
||||
partial class GL
|
||||
{
|
||||
|
|
|
@ -34,6 +34,7 @@ namespace OpenTK.Graphics.ES11
|
|||
#pragma warning disable 1591
|
||||
#pragma warning disable 1572
|
||||
#pragma warning disable 1573
|
||||
#pragma warning disable 3006
|
||||
|
||||
partial class GL
|
||||
{
|
||||
|
|
|
@ -34,6 +34,7 @@ namespace OpenTK.Graphics.ES20
|
|||
#pragma warning disable 1591
|
||||
#pragma warning disable 1572
|
||||
#pragma warning disable 1573
|
||||
#pragma warning disable 3006
|
||||
|
||||
partial class GL
|
||||
{
|
||||
|
|
|
@ -137,6 +137,28 @@ namespace OpenTK.Graphics.ES20
|
|||
GL.Uniform4(location, quaternion.X, quaternion.Y, quaternion.Z, quaternion.W);
|
||||
}
|
||||
|
||||
public static void UniformMatrix2(int location, bool transpose, ref Matrix2 matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (float* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix2(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix3(int location, bool transpose, ref Matrix3 matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (float* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix3(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix4(int location, bool transpose, ref Matrix4 matrix)
|
||||
{
|
||||
unsafe
|
||||
|
|
|
@ -34,6 +34,7 @@ namespace OpenTK.Graphics.OpenGL
|
|||
#pragma warning disable 1591
|
||||
#pragma warning disable 1572
|
||||
#pragma warning disable 1573
|
||||
#pragma warning disable 3006
|
||||
|
||||
partial class GL
|
||||
{
|
||||
|
|
|
@ -300,17 +300,6 @@ namespace OpenTK.Graphics.OpenGL
|
|||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix4(int location, bool transpose, ref Matrix4 matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (float* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix4(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Normal3(Vector3d normal)
|
||||
{
|
||||
GL.Normal3(normal.X, normal.Y, normal.Z);
|
||||
|
@ -420,6 +409,8 @@ namespace OpenTK.Graphics.OpenGL
|
|||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Uniform
|
||||
|
||||
[CLSCompliant(false)]
|
||||
|
@ -465,7 +456,203 @@ namespace OpenTK.Graphics.OpenGL
|
|||
GL.Uniform4(location, quaternion.X, quaternion.Y, quaternion.Z, quaternion.W);
|
||||
}
|
||||
|
||||
#endregion
|
||||
public static void UniformMatrix2(int location, bool transpose, ref Matrix2 matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (float* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix2(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix2(int location, bool transpose, ref Matrix2d matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (double* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix2(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix2x3(int location, bool transpose, ref Matrix2x3 matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (float* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix2x3(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix2x3(int location, bool transpose, ref Matrix2x3d matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (double* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix2x3(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix2x4(int location, bool transpose, ref Matrix2x4 matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (float* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix2x4(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix2x4(int location, bool transpose, ref Matrix2x4d matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (double* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix2x4(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix3x2(int location, bool transpose, ref Matrix3x2 matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (float* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix3x2(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix3x2(int location, bool transpose, ref Matrix3x2d matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (double* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix3x2(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix3(int location, bool transpose, ref Matrix3 matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (float* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix3(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix3(int location, bool transpose, ref Matrix3d matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (double* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix3(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix3x4(int location, bool transpose, ref Matrix3x4 matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (float* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix3x4(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix3x4(int location, bool transpose, ref Matrix3x4d matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (double* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix3x4(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix4x2(int location, bool transpose, ref Matrix4x2 matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (float* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix4x2(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix4x2(int location, bool transpose, ref Matrix4x2d matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (double* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix4x2(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix4x3(int location, bool transpose, ref Matrix4x3 matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (float* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix4x3(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix4x3(int location, bool transpose, ref Matrix4x3d matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (double* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix4x3(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix4(int location, bool transpose, ref Matrix4 matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (float* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix4(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UniformMatrix4(int location, bool transpose, ref Matrix4d matrix)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (double* matrix_ptr = &matrix.Row0.X)
|
||||
{
|
||||
GL.UniformMatrix4(location, 1, transpose, matrix_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
56
Source/OpenTK/Input/GamePadAxis.cs
Normal file
56
Source/OpenTK/Input/GamePadAxis.cs
Normal file
|
@ -0,0 +1,56 @@
|
|||
//
|
||||
// GamePadAxis.cs
|
||||
//
|
||||
// Author:
|
||||
// robert <${AuthorEmail}>
|
||||
//
|
||||
// Copyright (c) 2012 robert
|
||||
//
|
||||
// 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.
|
||||
using System;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
public enum GamePadAxis
|
||||
{
|
||||
/// <summary>The first axis of the gamepad.</summary>
|
||||
Axis0 = 0,
|
||||
/// <summary>The second axis of the gamepad.</summary>
|
||||
Axis1,
|
||||
/// <summary>The third axis of the gamepad.</summary>
|
||||
Axis2,
|
||||
/// <summary>The fourth axis of the gamepad.</summary>
|
||||
Axis3,
|
||||
/// <summary>The fifth axis of the gamepad.</summary>
|
||||
Axis4,
|
||||
/// <summary>The sixth axis of the gamepad.</summary>
|
||||
Axis5,
|
||||
/// <summary>The seventh axis of the gamepad.</summary>
|
||||
Axis6,
|
||||
/// <summary>The eighth axis of the gamepad.</summary>
|
||||
Axis7,
|
||||
/// <summary>The ninth axis of the gamepad.</summary>
|
||||
Axis8,
|
||||
/// <summary>The tenth axis of the gamepad.</summary>
|
||||
Axis9,
|
||||
/// <summary>The last axis of the gamepad.</summary>
|
||||
LastAxis
|
||||
}
|
||||
}
|
||||
|
68
Source/OpenTK/Input/GamePadButton.cs
Normal file
68
Source/OpenTK/Input/GamePadButton.cs
Normal file
|
@ -0,0 +1,68 @@
|
|||
//
|
||||
// GamePadButton.cs
|
||||
//
|
||||
// Author:
|
||||
// robert <${AuthorEmail}>
|
||||
//
|
||||
// Copyright (c) 2012 robert
|
||||
//
|
||||
// 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.
|
||||
using System;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
public enum GamePadButton
|
||||
{
|
||||
/// <summary>The first button of the gamepad.</summary>
|
||||
Button0 = 0,
|
||||
/// <summary>The second button of the gamepad.</summary>
|
||||
Button1,
|
||||
/// <summary>The third button of the gamepad.</summary>
|
||||
Button2,
|
||||
/// <summary>The fourth button of the gamepad.</summary>
|
||||
Button3,
|
||||
/// <summary>The fifth button of the gamepad.</summary>
|
||||
Button4,
|
||||
/// <summary>The sixth button of the gamepad.</summary>
|
||||
Button5,
|
||||
/// <summary>The seventh button of the gamepad.</summary>
|
||||
Button6,
|
||||
/// <summary>The eighth button of the gamepad.</summary>
|
||||
Button7,
|
||||
/// <summary>The ninth button of the gamepad.</summary>
|
||||
Button8,
|
||||
/// <summary>The tenth button of the gamepad.</summary>
|
||||
Button9,
|
||||
/// <summary>The eleventh button of the gamepad.</summary>
|
||||
Button10,
|
||||
/// <summary>The twelfth button of the gamepad.</summary>
|
||||
Button11,
|
||||
/// <summary>The thirteenth button of the gamepad.</summary>
|
||||
Button12,
|
||||
/// <summary>The fourteenth button of the gamepad.</summary>
|
||||
Button13,
|
||||
/// <summary>The fifteenth button of the gamepad.</summary>
|
||||
Button14,
|
||||
/// <summary>The sixteenth button of the gamepad.</summary>
|
||||
Button15,
|
||||
/// <summary>The last button of the gamepad.</summary>
|
||||
LastButton
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,8 @@ namespace OpenTK.Input
|
|||
/// <summary>
|
||||
/// Encapsulates the state of a GamePad device.
|
||||
/// </summary>
|
||||
public struct GamePadState
|
||||
public struct GamePadState /*: IEquatable<GamePadState>*/
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,5 +6,26 @@ namespace OpenTK.Input
|
|||
{
|
||||
interface IGamePadDriver
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves the combined <see cref="OpenTK.Input.GamePadState"/> for all gamepad devices.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="OpenTK.Input.GamePadState"/> structure containing the combined state for all gamepad devices.</returns>
|
||||
GamePadState GetState();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the <see cref="OpenTK.Input.GamePadState"/> for the specified gamepad device.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the keyboard device.</param>
|
||||
/// <returns>A <see cref="OpenTK.Input.GamePadState"/> structure containing the state of the gamepad device.</returns>
|
||||
GamePadState GetState(int index);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the device name for the gamepad device.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the gamepad device.</param>
|
||||
/// <returns>A <see cref="System.String"/> with the name of the specified device or <see cref="System.String.Empty"/>.</returns>
|
||||
/// <remarks>
|
||||
/// <para>If no device exists at the specified index, the return value is <see cref="System.String.Empty"/>.</para></remarks>
|
||||
string GetDeviceName(int index);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace OpenTK.Input
|
|||
{
|
||||
//private IKeyboard keyboard;
|
||||
private bool[] keys = new bool[Enum.GetValues(typeof(Key)).Length];
|
||||
private bool[] scancodes = new bool[256];
|
||||
private string description;
|
||||
private int numKeys, numFKeys, numLeds;
|
||||
private IntPtr devID;
|
||||
|
@ -44,24 +45,16 @@ namespace OpenTK.Input
|
|||
public bool this[Key key]
|
||||
{
|
||||
get { return keys[(int)key]; }
|
||||
internal set
|
||||
{
|
||||
if (keys[(int)key] != value || KeyRepeat)
|
||||
{
|
||||
keys[(int)key] = value;
|
||||
}
|
||||
|
||||
if (value && KeyDown != null)
|
||||
{
|
||||
args.Key = key;
|
||||
KeyDown(this, args);
|
||||
}
|
||||
else if (!value && KeyUp != null)
|
||||
{
|
||||
args.Key = key;
|
||||
KeyUp(this, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets a value indicating the status of the specified Key.
|
||||
/// </summary>
|
||||
/// <param name="scancode">The scancode to check.</param>
|
||||
/// <returns>True if the scancode is pressed, false otherwise.</returns>
|
||||
public bool this[uint scancode]
|
||||
{
|
||||
get { return scancodes[scancode]; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -197,12 +190,34 @@ namespace OpenTK.Input
|
|||
internal void ClearKeys()
|
||||
{
|
||||
for (int i = 0; i < keys.Length; i++)
|
||||
if (this[(Key)i]) // Make sure KeyUp events are *not* raised for keys that are up, even if key repeat is on.
|
||||
this[(Key)i] = false;
|
||||
keys[i] = false;
|
||||
for (uint i = 0; i < scancodes.Length; i++)
|
||||
scancodes[i] = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
internal void SetKey(Key key, uint scancode, bool state)
|
||||
{
|
||||
if (keys[(int)key] != state || KeyRepeat)
|
||||
{
|
||||
keys[(int)key] = scancodes[scancode] = state;
|
||||
|
||||
if (state && KeyDown != null)
|
||||
{
|
||||
args.Key = key;
|
||||
args.ScanCode = scancode;
|
||||
KeyDown(this, args);
|
||||
}
|
||||
else if (!state && KeyUp != null)
|
||||
{
|
||||
args.Key = key;
|
||||
args.ScanCode = scancode;
|
||||
KeyUp(this, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,83 +1,95 @@
|
|||
#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.Input
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the event data for <see cref="KeyboardDevice"/> events.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Do not cache instances of this type outside their event handler.
|
||||
/// If necessary, you can clone a KeyboardEventArgs instance using the
|
||||
/// <see cref="KeyboardKeyEventArgs(KeyboardKeyEventArgs)"/> constructor.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public class KeyboardKeyEventArgs : EventArgs
|
||||
{
|
||||
#region Fields
|
||||
|
||||
Key key;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new KeyboardEventArgs instance.
|
||||
/// </summary>
|
||||
public KeyboardKeyEventArgs() { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new KeyboardEventArgs instance.
|
||||
/// </summary>
|
||||
/// <param name="args">An existing KeyboardEventArgs instance to clone.</param>
|
||||
public KeyboardKeyEventArgs(KeyboardKeyEventArgs args)
|
||||
{
|
||||
Key = args.Key;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Key"/> that generated this event.
|
||||
/// </summary>
|
||||
public Key Key
|
||||
{
|
||||
get { return key; }
|
||||
internal set { key = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#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.Input
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the event data for <see cref="KeyboardDevice"/> events.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Do not cache instances of this type outside their event handler.
|
||||
/// If necessary, you can clone a KeyboardEventArgs instance using the
|
||||
/// <see cref="KeyboardKeyEventArgs(KeyboardKeyEventArgs)"/> constructor.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public class KeyboardKeyEventArgs : EventArgs
|
||||
{
|
||||
#region Fields
|
||||
|
||||
Key key;
|
||||
uint scancode;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new KeyboardEventArgs instance.
|
||||
/// </summary>
|
||||
public KeyboardKeyEventArgs() { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new KeyboardEventArgs instance.
|
||||
/// </summary>
|
||||
/// <param name="args">An existing KeyboardEventArgs instance to clone.</param>
|
||||
public KeyboardKeyEventArgs(KeyboardKeyEventArgs args)
|
||||
{
|
||||
Key = args.Key;
|
||||
ScanCode = args.ScanCode;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Key"/> that generated this event.
|
||||
/// </summary>
|
||||
public Key Key
|
||||
{
|
||||
get { return key; }
|
||||
internal set { key = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scancode which generated this event.
|
||||
/// </summary>
|
||||
public uint ScanCode
|
||||
{
|
||||
get { return scancode; }
|
||||
internal set { scancode = value; }
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,9 @@ namespace OpenTK.Input
|
|||
const int NumInts = ((int)Key.LastKey + IntSize - 1) / IntSize;
|
||||
// The following line triggers bogus CS0214 in gmcs 2.0.1, sigh...
|
||||
unsafe fixed int Keys[NumInts];
|
||||
|
||||
const int CodesSize = 256;
|
||||
unsafe fixed int Codes[CodesSize];
|
||||
bool is_connected;
|
||||
|
||||
#endregion
|
||||
|
@ -58,13 +61,17 @@ namespace OpenTK.Input
|
|||
public bool this[Key key]
|
||||
{
|
||||
get { return IsKeyDown(key); }
|
||||
internal set
|
||||
{
|
||||
if (value)
|
||||
EnableBit((int)key);
|
||||
else
|
||||
DisableBit((int)key);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="System.Boolean"/> indicating whether the specified
|
||||
/// <see cref="OpenTK.Input.Key"/> is pressed.
|
||||
/// </summary>
|
||||
/// <param name="key">The <see cref="OpenTK.Input.Key"/> to check.</param>
|
||||
/// <returns>True if key is pressed; false otherwise.</returns>
|
||||
public bool this[short code]
|
||||
{
|
||||
get { return IsKeyDown(code); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -76,6 +83,15 @@ namespace OpenTK.Input
|
|||
return ReadBit((int)key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="System.Boolean"/> indicating whether this scan code is down.
|
||||
/// </summary>
|
||||
/// <param name="code">The scan code to check.</param>
|
||||
public bool IsKeyDown(short code)
|
||||
{
|
||||
return ReadBit(code,true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="System.Boolean"/> indicating whether this key is up.
|
||||
/// </summary>
|
||||
|
@ -85,6 +101,15 @@ namespace OpenTK.Input
|
|||
return !ReadBit((int)key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="System.Boolean"/> indicating whether this scan code is down.
|
||||
/// </summary>
|
||||
/// <param name="code">The scan code to check.</param>
|
||||
public bool IsKeyUp(short code)
|
||||
{
|
||||
return !ReadBit(code,true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="System.Boolean"/> indicating whether this keyboard
|
||||
/// is connected.
|
||||
|
@ -187,48 +212,62 @@ namespace OpenTK.Input
|
|||
|
||||
#region Internal Members
|
||||
|
||||
internal bool ReadBit(int offset)
|
||||
internal void SetKeyState(Key key, byte code, bool down)
|
||||
{
|
||||
ValidateOffset(offset);
|
||||
|
||||
int int_offset = offset / 32;
|
||||
int bit_offset = offset % 32;
|
||||
unsafe
|
||||
if (down)
|
||||
{
|
||||
fixed (int* k = Keys)
|
||||
{
|
||||
return (*(k + int_offset) & (1 << bit_offset)) != 0u;
|
||||
}
|
||||
EnableBit((int)key);
|
||||
EnableBit(code,true);
|
||||
}
|
||||
else
|
||||
{
|
||||
DisableBit((int)key);
|
||||
DisableBit(code, true);
|
||||
}
|
||||
}
|
||||
|
||||
internal void EnableBit(int offset)
|
||||
internal bool ReadBit(int offset, bool ScanCode = false)
|
||||
{
|
||||
ValidateOffset(offset);
|
||||
ValidateOffset(offset, ScanCode);
|
||||
|
||||
int int_offset = offset / 32;
|
||||
int bit_offset = offset % 32;
|
||||
unsafe
|
||||
{
|
||||
fixed (int* k = Keys)
|
||||
{
|
||||
*(k + int_offset) |= 1 << bit_offset;
|
||||
}
|
||||
if (ScanCode)
|
||||
fixed (int* c = Codes) { return (*(c + int_offset) & (1 << bit_offset)) != 0u; }
|
||||
else
|
||||
fixed (int* k = Keys) { return (*(k + int_offset) & (1 << bit_offset)) != 0u; }
|
||||
}
|
||||
}
|
||||
|
||||
internal void DisableBit(int offset)
|
||||
internal void EnableBit(int offset, bool ScanCode = false)
|
||||
{
|
||||
ValidateOffset(offset);
|
||||
ValidateOffset(offset, ScanCode);
|
||||
|
||||
int int_offset = offset / 32;
|
||||
int bit_offset = offset % 32;
|
||||
unsafe
|
||||
{
|
||||
fixed (int* k = Keys)
|
||||
{
|
||||
*(k + int_offset) &= ~(1 << bit_offset);
|
||||
}
|
||||
if (ScanCode)
|
||||
fixed (int* c = Codes) { *(c + int_offset) |= 1 << bit_offset; }
|
||||
else
|
||||
fixed (int* k = Keys) { *(k + int_offset) |= 1 << bit_offset; }
|
||||
}
|
||||
}
|
||||
|
||||
internal void DisableBit(int offset, bool ScanCode = false)
|
||||
{
|
||||
ValidateOffset(offset, ScanCode);
|
||||
|
||||
int int_offset = offset / 32;
|
||||
int bit_offset = offset % 32;
|
||||
unsafe
|
||||
{
|
||||
if (ScanCode)
|
||||
fixed (int* c = Codes) { *(c + int_offset) &= ~(1 << bit_offset); }
|
||||
else
|
||||
fixed (int* k = Keys) { *(k + int_offset) &= ~(1 << bit_offset); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,6 +281,12 @@ namespace OpenTK.Input
|
|||
for (int i = 0; i < NumInts; i++)
|
||||
*(k1 + i) |= *(k2 + i);
|
||||
}
|
||||
int* c2 = other.Codes;
|
||||
fixed (int* c1 = Codes)
|
||||
{
|
||||
for (int i = 0; i < CodesSize; i++)
|
||||
*(c1 + i) |= *(c2 + i);
|
||||
}
|
||||
}
|
||||
IsConnected |= other.IsConnected;
|
||||
}
|
||||
|
@ -250,9 +295,9 @@ namespace OpenTK.Input
|
|||
|
||||
#region Private Members
|
||||
|
||||
static void ValidateOffset(int offset)
|
||||
static void ValidateOffset(int offset, bool ScanCode)
|
||||
{
|
||||
if (offset < 0 || offset >= NumInts * IntSize)
|
||||
if (offset < 0 || offset >= (ScanCode ? 256 : NumInts * IntSize))
|
||||
throw new ArgumentOutOfRangeException("offset");
|
||||
}
|
||||
|
||||
|
|
764
Source/OpenTK/Math/Matrix2.cs
Normal file
764
Source/OpenTK/Math/Matrix2.cs
Normal file
|
@ -0,0 +1,764 @@
|
|||
#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
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a 2x2 matrix
|
||||
/// </summary>
|
||||
public struct Matrix2 : IEquatable<Matrix2>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Top row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Row0;
|
||||
|
||||
/// <summary>
|
||||
/// Bottom row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Row1;
|
||||
|
||||
/// <summary>
|
||||
/// The identity matrix.
|
||||
/// </summary>
|
||||
public static readonly Matrix2 Identity = new Matrix2(Vector2.UnitX, Vector2.UnitY);
|
||||
|
||||
/// <summary>
|
||||
/// The zero matrix.
|
||||
/// </summary>
|
||||
public static readonly Matrix2 Zero = new Matrix2(Vector2.Zero, Vector2.Zero);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance.
|
||||
/// </summary>
|
||||
/// <param name="row0">Top row of the matrix.</param>
|
||||
/// <param name="row1">Bottom row of the matrix.</param>
|
||||
public Matrix2(Vector2 row0, Vector2 row1)
|
||||
{
|
||||
Row0 = row0;
|
||||
Row1 = row1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance
|
||||
/// </summary>
|
||||
/// <param name="m00">First item of the first row of the matrix.</param>
|
||||
/// <param name="m01">Second item of the first row of the matrix.</param>
|
||||
/// <param name="m10">First item of the second row of the matrix.</param>
|
||||
/// <param name="m11">Second item of the second row of the matrix.</param>
|
||||
public Matrix2(
|
||||
float m00, float m01,
|
||||
float m10, float m11)
|
||||
{
|
||||
Row0 = new Vector2(m00, m01);
|
||||
Row1 = new Vector2(m10, m11);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the determinant of this matrix.
|
||||
/// </summary>
|
||||
public float Determinant
|
||||
{
|
||||
get
|
||||
{
|
||||
float m11 = Row0.X, m12 = Row0.Y,
|
||||
m21 = Row1.X, m22 = Row1.Y;
|
||||
|
||||
return m11 * m22 - m12 * m21;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the first column of this matrix.
|
||||
/// </summary>
|
||||
public Vector2 Column0
|
||||
{
|
||||
get { return new Vector2(Row0.X, Row1.X); }
|
||||
set { Row0.X = value.X; Row1.X = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the second column of this matrix.
|
||||
/// </summary>
|
||||
public Vector2 Column1
|
||||
{
|
||||
get { return new Vector2(Row0.Y, Row1.Y); }
|
||||
set { Row0.Y = value.X; Row1.Y = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 1, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float 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 float M12 { get { return Row0.Y; } set { Row0.Y = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 2, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float 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 float M22 { get { return Row1.Y; } set { Row1.Y = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the values along the main diagonal of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Diagonal
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2(Row0.X, Row1.Y);
|
||||
}
|
||||
set
|
||||
{
|
||||
Row0.X = value.X;
|
||||
Row1.Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trace of the matrix, the sum of the values along the diagonal.
|
||||
/// </summary>
|
||||
public float Trace { get { return Row0.X + Row1.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexers
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at a specified row and column.
|
||||
/// </summary>
|
||||
public float this[int rowIndex, int columnIndex]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowIndex == 0) return Row0[columnIndex];
|
||||
else if (rowIndex == 1) return Row1[columnIndex];
|
||||
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowIndex == 0) Row0[columnIndex] = value;
|
||||
else if (rowIndex == 1) Row1[columnIndex] = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Instance
|
||||
|
||||
#region public void Transpose()
|
||||
|
||||
/// <summary>
|
||||
/// Converts this instance to it's transpose.
|
||||
/// </summary>
|
||||
public void Transpose()
|
||||
{
|
||||
this = Matrix2.Transpose(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void Invert()
|
||||
|
||||
/// <summary>
|
||||
/// Converts this instance into its inverse.
|
||||
/// </summary>
|
||||
public void Invert()
|
||||
{
|
||||
this = Matrix2.Invert(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static
|
||||
|
||||
#region CreateRotation
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix2 instance.</param>
|
||||
public static void CreateRotation(float angle, out Matrix2 result)
|
||||
{
|
||||
float cos = (float)System.Math.Cos(angle);
|
||||
float sin = (float)System.Math.Sin(angle);
|
||||
|
||||
result.Row0.X = cos;
|
||||
result.Row0.Y = sin;
|
||||
result.Row1.X = -sin;
|
||||
result.Row1.Y = cos;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix2 instance.</returns>
|
||||
public static Matrix2 CreateRotation(float angle)
|
||||
{
|
||||
Matrix2 result;
|
||||
CreateRotation(angle, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateScale
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x, y, and z axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(float scale, out Matrix2 result)
|
||||
{
|
||||
result.Row0.X = scale;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2 CreateScale(float scale)
|
||||
{
|
||||
Matrix2 result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(Vector2 scale, out Matrix2 result)
|
||||
{
|
||||
result.Row0.X = scale.X;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2 CreateScale(Vector2 scale)
|
||||
{
|
||||
Matrix2 result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(float x, float y, out Matrix2 result)
|
||||
{
|
||||
result.Row0.X = x;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2 CreateScale(float x, float y)
|
||||
{
|
||||
Matrix2 result;
|
||||
CreateScale(x, y, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Multiply Functions
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix2 left, float right, out Matrix2 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X * right;
|
||||
result.Row0.Y = left.Row0.Y * right;
|
||||
result.Row1.X = left.Row1.X * right;
|
||||
result.Row1.Y = left.Row1.Y * right;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix2 Mult(Matrix2 left, float right)
|
||||
{
|
||||
Matrix2 result;
|
||||
Mult(ref left, 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 Matrix2 left, ref Matrix2 right, out Matrix2 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
}
|
||||
|
||||
/// <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 Matrix2 Mult(Matrix2 left, Matrix2 right)
|
||||
{
|
||||
Matrix2 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 Matrix2 left, ref Matrix2x3 right, out Matrix2x3 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row0.Z = (lM11 * rM13) + (lM12 * rM23);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row1.Z = (lM21 * rM13) + (lM22 * rM23);
|
||||
}
|
||||
|
||||
/// <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 Matrix2x3 Mult(Matrix2 left, Matrix2x3 right)
|
||||
{
|
||||
Matrix2x3 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 Matrix2 left, ref Matrix2x4 right, out Matrix2x4 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z, rM14 = right.Row0.W,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z, rM24 = right.Row1.W;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row0.Z = (lM11 * rM13) + (lM12 * rM23);
|
||||
result.Row0.W = (lM11 * rM14) + (lM12 * rM24);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row1.Z = (lM21 * rM13) + (lM22 * rM23);
|
||||
result.Row1.W = (lM21 * rM14) + (lM22 * rM24);
|
||||
}
|
||||
|
||||
/// <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 Matrix2x4 Mult(Matrix2 left, Matrix2x4 right)
|
||||
{
|
||||
Matrix2x4 result;
|
||||
Mult(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Add
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <param name="result">A new instance that is the result of the addition.</param>
|
||||
public static void Add(ref Matrix2 left, ref Matrix2 right, out Matrix2 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X + right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y + right.Row0.Y;
|
||||
result.Row1.X = left.Row1.X + right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y + right.Row1.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <returns>A new instance that is the result of the addition.</returns>
|
||||
public static Matrix2 Add(Matrix2 left, Matrix2 right)
|
||||
{
|
||||
Matrix2 result;
|
||||
Add(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subtract
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <param name="result">A new instance that is the result of the subtraction.</param>
|
||||
public static void Subtract(ref Matrix2 left, ref Matrix2 right, out Matrix2 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X - right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y - right.Row0.Y;
|
||||
result.Row1.X = left.Row1.X - right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y - right.Row1.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <returns>A new instance that is the result of the subtraction.</returns>
|
||||
public static Matrix2 Subtract(Matrix2 left, Matrix2 right)
|
||||
{
|
||||
Matrix2 result;
|
||||
Subtract(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Invert Functions
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the inverse of the given matrix
|
||||
/// </summary>
|
||||
/// <param name="mat">The matrix to invert</param>
|
||||
/// <param name="result">The inverse of the given matrix if it has one, or the input if it is singular</param>
|
||||
/// <exception cref="InvalidOperationException">Thrown if the Matrix2 is singular.</exception>
|
||||
public static void Invert(ref Matrix2 mat, out Matrix2 result)
|
||||
{
|
||||
float det = mat.Determinant;
|
||||
|
||||
if (det == 0)
|
||||
throw new InvalidOperationException("Matrix is singular and cannot be inverted.");
|
||||
|
||||
float invDet = 1f / det;
|
||||
|
||||
result.Row0.X = mat.Row1.Y * invDet;
|
||||
result.Row0.Y = -mat.Row0.Y * invDet;
|
||||
result.Row1.X = -mat.Row1.X * invDet;
|
||||
result.Row1.Y = mat.Row0.X * invDet;
|
||||
}
|
||||
|
||||
/// <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 Matrix2 is singular.</exception>
|
||||
public static Matrix2 Invert(Matrix2 mat)
|
||||
{
|
||||
Matrix2 result;
|
||||
Invert(ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Transpose
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the transpose of the given matrix.
|
||||
/// </summary>
|
||||
/// <param name="mat">The matrix to transpose.</param>
|
||||
/// <param name="result">The transpose of the given matrix.</param>
|
||||
public static void Transpose(ref Matrix2 mat, out Matrix2 result)
|
||||
{
|
||||
result.Row0.X = mat.Row0.X;
|
||||
result.Row0.Y = mat.Row1.X;
|
||||
result.Row1.X = mat.Row0.Y;
|
||||
result.Row1.Y = mat.Row1.Y;
|
||||
}
|
||||
|
||||
/// <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 Matrix2 Transpose(Matrix2 mat)
|
||||
{
|
||||
Matrix2 result;
|
||||
Transpose(ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2 which holds the result of the multiplication</returns>
|
||||
public static Matrix2 operator *(float left, Matrix2 right)
|
||||
{
|
||||
return Mult(right, left);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2 which holds the result of the multiplication</returns>
|
||||
public static Matrix2 operator *(Matrix2 left, float right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2 which holds the result of the multiplication</returns>
|
||||
public static Matrix2 operator *(Matrix2 left, Matrix2 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x3 which holds the result of the multiplication</returns>
|
||||
public static Matrix2x3 operator *(Matrix2 left, Matrix2x3 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x4 which holds the result of the multiplication</returns>
|
||||
public static Matrix2x4 operator *(Matrix2 left, Matrix2x4 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix addition
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2 which holds the result of the addition</returns>
|
||||
public static Matrix2 operator +(Matrix2 left, Matrix2 right)
|
||||
{
|
||||
return Add(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix subtraction
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2 which holds the result of the subtraction</returns>
|
||||
public static Matrix2 operator -(Matrix2 left, Matrix2 right)
|
||||
{
|
||||
return Subtract(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left equals right; false otherwise.</returns>
|
||||
public static bool operator ==(Matrix2 left, Matrix2 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left does not equal right; false otherwise.</returns>
|
||||
public static bool operator !=(Matrix2 left, Matrix2 right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Matrix4.
|
||||
/// </summary>
|
||||
/// <returns>The string representation of the matrix.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0}\n{1}", Row0, Row1);
|
||||
}
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
#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 Matrix2))
|
||||
return false;
|
||||
|
||||
return this.Equals((Matrix2)obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<Matrix2> 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(Matrix2 other)
|
||||
{
|
||||
return
|
||||
Row0 == other.Row0 &&
|
||||
Row1 == other.Row1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
764
Source/OpenTK/Math/Matrix2d.cs
Normal file
764
Source/OpenTK/Math/Matrix2d.cs
Normal file
|
@ -0,0 +1,764 @@
|
|||
#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
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a 2x2 matrix
|
||||
/// </summary>
|
||||
public struct Matrix2d : IEquatable<Matrix2d>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Top row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Row0;
|
||||
|
||||
/// <summary>
|
||||
/// Bottom row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Row1;
|
||||
|
||||
/// <summary>
|
||||
/// The identity matrix.
|
||||
/// </summary>
|
||||
public static readonly Matrix2d Identity = new Matrix2d(Vector2d.UnitX, Vector2d.UnitY);
|
||||
|
||||
/// <summary>
|
||||
/// The zero matrix.
|
||||
/// </summary>
|
||||
public static readonly Matrix2d Zero = new Matrix2d(Vector2d.Zero, Vector2d.Zero);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance.
|
||||
/// </summary>
|
||||
/// <param name="row0">Top row of the matrix.</param>
|
||||
/// <param name="row1">Bottom row of the matrix.</param>
|
||||
public Matrix2d(Vector2d row0, Vector2d row1)
|
||||
{
|
||||
Row0 = row0;
|
||||
Row1 = row1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance
|
||||
/// </summary>
|
||||
/// <param name="m00">First item of the first row of the matrix.</param>
|
||||
/// <param name="m01">Second item of the first row of the matrix.</param>
|
||||
/// <param name="m10">First item of the second row of the matrix.</param>
|
||||
/// <param name="m11">Second item of the second row of the matrix.</param>
|
||||
public Matrix2d(
|
||||
double m00, double m01,
|
||||
double m10, double m11)
|
||||
{
|
||||
Row0 = new Vector2d(m00, m01);
|
||||
Row1 = new Vector2d(m10, m11);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the determinant of this matrix.
|
||||
/// </summary>
|
||||
public double Determinant
|
||||
{
|
||||
get
|
||||
{
|
||||
double m11 = Row0.X, m12 = Row0.Y,
|
||||
m21 = Row1.X, m22 = Row1.Y;
|
||||
|
||||
return m11 * m22 - m12 * m21;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the first column of this matrix.
|
||||
/// </summary>
|
||||
public Vector2d Column0
|
||||
{
|
||||
get { return new Vector2d(Row0.X, Row1.X); }
|
||||
set { Row0.X = value.X; Row1.X = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the second column of this matrix.
|
||||
/// </summary>
|
||||
public Vector2d Column1
|
||||
{
|
||||
get { return new Vector2d(Row0.Y, Row1.Y); }
|
||||
set { Row0.Y = value.X; Row1.Y = value.Y; }
|
||||
}
|
||||
|
||||
/// <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 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 values along the main diagonal of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Diagonal
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2d(Row0.X, Row1.Y);
|
||||
}
|
||||
set
|
||||
{
|
||||
Row0.X = value.X;
|
||||
Row1.Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trace of the matrix, the sum of the values along the diagonal.
|
||||
/// </summary>
|
||||
public double Trace { get { return Row0.X + Row1.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexers
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at a specified row and column.
|
||||
/// </summary>
|
||||
public double this[int rowIndex, int columnIndex]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowIndex == 0) return Row0[columnIndex];
|
||||
else if (rowIndex == 1) return Row1[columnIndex];
|
||||
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowIndex == 0) Row0[columnIndex] = value;
|
||||
else if (rowIndex == 1) Row1[columnIndex] = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Instance
|
||||
|
||||
#region public void Transpose()
|
||||
|
||||
/// <summary>
|
||||
/// Converts this instance to it's transpose.
|
||||
/// </summary>
|
||||
public void Transpose()
|
||||
{
|
||||
this = Matrix2d.Transpose(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void Invert()
|
||||
|
||||
/// <summary>
|
||||
/// Converts this instance into its inverse.
|
||||
/// </summary>
|
||||
public void Invert()
|
||||
{
|
||||
this = Matrix2d.Invert(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static
|
||||
|
||||
#region CreateRotation
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix2d instance.</param>
|
||||
public static void CreateRotation(double angle, out Matrix2d result)
|
||||
{
|
||||
double cos = (double)System.Math.Cos(angle);
|
||||
double sin = (double)System.Math.Sin(angle);
|
||||
|
||||
result.Row0.X = cos;
|
||||
result.Row0.Y = sin;
|
||||
result.Row1.X = -sin;
|
||||
result.Row1.Y = cos;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix2d instance.</returns>
|
||||
public static Matrix2d CreateRotation(double angle)
|
||||
{
|
||||
Matrix2d result;
|
||||
CreateRotation(angle, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateScale
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x, y, and z axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(double scale, out Matrix2d result)
|
||||
{
|
||||
result.Row0.X = scale;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2d CreateScale(double scale)
|
||||
{
|
||||
Matrix2d result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(Vector2d scale, out Matrix2d result)
|
||||
{
|
||||
result.Row0.X = scale.X;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2d CreateScale(Vector2d scale)
|
||||
{
|
||||
Matrix2d result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(double x, double y, out Matrix2d result)
|
||||
{
|
||||
result.Row0.X = x;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2d CreateScale(double x, double y)
|
||||
{
|
||||
Matrix2d result;
|
||||
CreateScale(x, y, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Multiply Functions
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix2d left, double right, out Matrix2d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X * right;
|
||||
result.Row0.Y = left.Row0.Y * right;
|
||||
result.Row1.X = left.Row1.X * right;
|
||||
result.Row1.Y = left.Row1.Y * right;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix2d Mult(Matrix2d left, double right)
|
||||
{
|
||||
Matrix2d result;
|
||||
Mult(ref left, 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 Matrix2d left, ref Matrix2d right, out Matrix2d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
}
|
||||
|
||||
/// <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 Matrix2d Mult(Matrix2d left, Matrix2d right)
|
||||
{
|
||||
Matrix2d 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 Matrix2d left, ref Matrix2x3d right, out Matrix2x3d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row0.Z = (lM11 * rM13) + (lM12 * rM23);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row1.Z = (lM21 * rM13) + (lM22 * rM23);
|
||||
}
|
||||
|
||||
/// <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 Matrix2x3d Mult(Matrix2d left, Matrix2x3d right)
|
||||
{
|
||||
Matrix2x3d 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 Matrix2d left, ref Matrix2x4d right, out Matrix2x4d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z, rM14 = right.Row0.W,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z, rM24 = right.Row1.W;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row0.Z = (lM11 * rM13) + (lM12 * rM23);
|
||||
result.Row0.W = (lM11 * rM14) + (lM12 * rM24);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row1.Z = (lM21 * rM13) + (lM22 * rM23);
|
||||
result.Row1.W = (lM21 * rM14) + (lM22 * rM24);
|
||||
}
|
||||
|
||||
/// <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 Matrix2x4d Mult(Matrix2d left, Matrix2x4d right)
|
||||
{
|
||||
Matrix2x4d result;
|
||||
Mult(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Add
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <param name="result">A new instance that is the result of the addition.</param>
|
||||
public static void Add(ref Matrix2d left, ref Matrix2d right, out Matrix2d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X + right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y + right.Row0.Y;
|
||||
result.Row1.X = left.Row1.X + right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y + right.Row1.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <returns>A new instance that is the result of the addition.</returns>
|
||||
public static Matrix2d Add(Matrix2d left, Matrix2d right)
|
||||
{
|
||||
Matrix2d result;
|
||||
Add(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subtract
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <param name="result">A new instance that is the result of the subtraction.</param>
|
||||
public static void Subtract(ref Matrix2d left, ref Matrix2d right, out Matrix2d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X - right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y - right.Row0.Y;
|
||||
result.Row1.X = left.Row1.X - right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y - right.Row1.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <returns>A new instance that is the result of the subtraction.</returns>
|
||||
public static Matrix2d Subtract(Matrix2d left, Matrix2d right)
|
||||
{
|
||||
Matrix2d result;
|
||||
Subtract(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Invert Functions
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the inverse of the given matrix
|
||||
/// </summary>
|
||||
/// <param name="mat">The matrix to invert</param>
|
||||
/// <param name="result">The inverse of the given matrix if it has one, or the input if it is singular</param>
|
||||
/// <exception cref="InvalidOperationException">Thrown if the Matrix2d is singular.</exception>
|
||||
public static void Invert(ref Matrix2d mat, out Matrix2d result)
|
||||
{
|
||||
double det = mat.Determinant;
|
||||
|
||||
if (det == 0)
|
||||
throw new InvalidOperationException("Matrix is singular and cannot be inverted.");
|
||||
|
||||
double invDet = 1f / det;
|
||||
|
||||
result.Row0.X = mat.Row1.Y * invDet;
|
||||
result.Row0.Y = -mat.Row0.Y * invDet;
|
||||
result.Row1.X = -mat.Row1.X * invDet;
|
||||
result.Row1.Y = mat.Row0.X * invDet;
|
||||
}
|
||||
|
||||
/// <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 Matrix2d is singular.</exception>
|
||||
public static Matrix2d Invert(Matrix2d mat)
|
||||
{
|
||||
Matrix2d result;
|
||||
Invert(ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Transpose
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the transpose of the given matrix.
|
||||
/// </summary>
|
||||
/// <param name="mat">The matrix to transpose.</param>
|
||||
/// <param name="result">The transpose of the given matrix.</param>
|
||||
public static void Transpose(ref Matrix2d mat, out Matrix2d result)
|
||||
{
|
||||
result.Row0.X = mat.Row0.X;
|
||||
result.Row0.Y = mat.Row1.X;
|
||||
result.Row1.X = mat.Row0.Y;
|
||||
result.Row1.Y = mat.Row1.Y;
|
||||
}
|
||||
|
||||
/// <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 Matrix2d Transpose(Matrix2d mat)
|
||||
{
|
||||
Matrix2d result;
|
||||
Transpose(ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2d which holds the result of the multiplication</returns>
|
||||
public static Matrix2d operator *(double left, Matrix2d right)
|
||||
{
|
||||
return Mult(right, left);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2d which holds the result of the multiplication</returns>
|
||||
public static Matrix2d operator *(Matrix2d left, double right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2d which holds the result of the multiplication</returns>
|
||||
public static Matrix2d operator *(Matrix2d left, Matrix2d right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x3d which holds the result of the multiplication</returns>
|
||||
public static Matrix2x3d operator *(Matrix2d left, Matrix2x3d right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x4d which holds the result of the multiplication</returns>
|
||||
public static Matrix2x4d operator *(Matrix2d left, Matrix2x4d right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix addition
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2d which holds the result of the addition</returns>
|
||||
public static Matrix2d operator +(Matrix2d left, Matrix2d right)
|
||||
{
|
||||
return Add(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix subtraction
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2d which holds the result of the subtraction</returns>
|
||||
public static Matrix2d operator -(Matrix2d left, Matrix2d right)
|
||||
{
|
||||
return Subtract(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left equals right; false otherwise.</returns>
|
||||
public static bool operator ==(Matrix2d left, Matrix2d right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left does not equal right; false otherwise.</returns>
|
||||
public static bool operator !=(Matrix2d left, Matrix2d right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Matrix4.
|
||||
/// </summary>
|
||||
/// <returns>The string representation of the matrix.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0}\n{1}", Row0, Row1);
|
||||
}
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
#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 Matrix2d))
|
||||
return false;
|
||||
|
||||
return this.Equals((Matrix2d)obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<Matrix2d> 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(Matrix2d other)
|
||||
{
|
||||
return
|
||||
Row0 == other.Row0 &&
|
||||
Row1 == other.Row1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
724
Source/OpenTK/Math/Matrix2x3.cs
Normal file
724
Source/OpenTK/Math/Matrix2x3.cs
Normal file
|
@ -0,0 +1,724 @@
|
|||
#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.Collections.Generic;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a 2x3 matrix.
|
||||
/// </summary>
|
||||
public struct Matrix2x3 : IEquatable<Matrix2x3>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Top row of the matrix.
|
||||
/// </summary>
|
||||
public Vector3 Row0;
|
||||
|
||||
/// <summary>
|
||||
/// Bottom row of the matrix.
|
||||
/// </summary>
|
||||
public Vector3 Row1;
|
||||
|
||||
/// <summary>
|
||||
/// The zero matrix.
|
||||
/// </summary>
|
||||
public static readonly Matrix2x3 Zero = new Matrix2x3(Vector3.Zero, Vector3.Zero);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance.
|
||||
/// </summary>
|
||||
/// <param name="row0">Top row of the matrix.</param>
|
||||
/// <param name="row1">Bottom row of the matrix.</param>
|
||||
public Matrix2x3(Vector3 row0, Vector3 row1)
|
||||
{
|
||||
Row0 = row0;
|
||||
Row1 = row1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance
|
||||
/// </summary>
|
||||
/// <param name="m00">First item of the first row of the matrix.</param>
|
||||
/// <param name="m01">Second item of the first row of the matrix.</param>
|
||||
/// <param name="m02">Third item of the first row of the matrix.</param>
|
||||
/// <param name="m10">First item of the second row of the matrix.</param>
|
||||
/// <param name="m11">Second item of the second row of the matrix.</param>
|
||||
/// <param name="m12">Third item of the second row of the matrix.</param>
|
||||
public Matrix2x3(
|
||||
float m00, float m01, float m02,
|
||||
float m10, float m11, float m12)
|
||||
{
|
||||
Row0 = new Vector3(m00, m01, m02);
|
||||
Row1 = new Vector3(m10, m11, m12);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the first column of this matrix.
|
||||
/// </summary>
|
||||
public Vector2 Column0
|
||||
{
|
||||
get { return new Vector2(Row0.X, Row1.X); }
|
||||
set { Row0.X = value.X; Row1.X = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the second column of this matrix.
|
||||
/// </summary>
|
||||
public Vector2 Column1
|
||||
{
|
||||
get { return new Vector2(Row0.Y, Row1.Y); }
|
||||
set { Row0.Y = value.X; Row1.Y = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the third column of this matrix.
|
||||
/// </summary>
|
||||
public Vector2 Column2
|
||||
{
|
||||
get { return new Vector2(Row0.Z, Row1.Z); }
|
||||
set { Row0.Z = value.X; Row1.Z = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 1, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float 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 float 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 float M13 { get { return Row0.Z; } set { Row0.Z = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 2, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float 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 float 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 float M23 { get { return Row1.Z; } set { Row1.Z = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the values along the main diagonal of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Diagonal
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2(Row0.X, Row1.Y);
|
||||
}
|
||||
set
|
||||
{
|
||||
Row0.X = value.X;
|
||||
Row1.Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trace of the matrix, the sum of the values along the diagonal.
|
||||
/// </summary>
|
||||
public float Trace { get { return Row0.X + Row1.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexers
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at a specified row and column.
|
||||
/// </summary>
|
||||
public float this[int rowIndex, int columnIndex]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowIndex == 0) return Row0[columnIndex];
|
||||
else if (rowIndex == 1) return Row1[columnIndex];
|
||||
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowIndex == 0) Row0[columnIndex] = value;
|
||||
else if (rowIndex == 1) Row1[columnIndex] = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Instance
|
||||
#endregion
|
||||
|
||||
#region Static
|
||||
|
||||
#region CreateRotation
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix2x3 instance.</param>
|
||||
public static void CreateRotation(float angle, out Matrix2x3 result)
|
||||
{
|
||||
float cos = (float)System.Math.Cos(angle);
|
||||
float sin = (float)System.Math.Sin(angle);
|
||||
|
||||
result.Row0.X = cos;
|
||||
result.Row0.Y = sin;
|
||||
result.Row0.Z = 0;
|
||||
result.Row1.X = -sin;
|
||||
result.Row1.Y = cos;
|
||||
result.Row1.Z = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix2x3 instance.</returns>
|
||||
public static Matrix2x3 CreateRotation(float angle)
|
||||
{
|
||||
Matrix2x3 result;
|
||||
CreateRotation(angle, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateScale
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x, y, and z axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(float scale, out Matrix2x3 result)
|
||||
{
|
||||
result.Row0.X = scale;
|
||||
result.Row0.Y = 0;
|
||||
result.Row0.Z = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale;
|
||||
result.Row1.Z = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2x3 CreateScale(float scale)
|
||||
{
|
||||
Matrix2x3 result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(Vector2 scale, out Matrix2x3 result)
|
||||
{
|
||||
result.Row0.X = scale.X;
|
||||
result.Row0.Y = 0;
|
||||
result.Row0.Z = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale.Y;
|
||||
result.Row1.Z = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2x3 CreateScale(Vector2 scale)
|
||||
{
|
||||
Matrix2x3 result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(float x, float y, out Matrix2x3 result)
|
||||
{
|
||||
result.Row0.X = x;
|
||||
result.Row0.Y = 0;
|
||||
result.Row0.Z = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = y;
|
||||
result.Row1.Z = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2x3 CreateScale(float x, float y)
|
||||
{
|
||||
Matrix2x3 result;
|
||||
CreateScale(x, y, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Multiply Functions
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix2x3 left, float right, out Matrix2x3 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X * right;
|
||||
result.Row0.Y = left.Row0.Y * right;
|
||||
result.Row0.Z = left.Row0.Z * right;
|
||||
result.Row1.X = left.Row1.X * right;
|
||||
result.Row1.Y = left.Row1.Y * right;
|
||||
result.Row1.Z = left.Row1.Z * right;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix2x3 Mult(Matrix2x3 left, float right)
|
||||
{
|
||||
Matrix2x3 result;
|
||||
Mult(ref left, 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 Matrix2x3 left, ref Matrix3x2 right, out Matrix2 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y,
|
||||
rM31 = right.Row2.X, rM32 = right.Row2.Y;
|
||||
|
||||
result.Row0.X = ((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31);
|
||||
result.Row0.Y = ((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32);
|
||||
result.Row1.X = ((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31);
|
||||
result.Row1.Y = ((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32);
|
||||
}
|
||||
|
||||
/// <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 Matrix2 Mult(Matrix2x3 left, Matrix3x2 right)
|
||||
{
|
||||
Matrix2 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 Matrix2x3 left, ref Matrix3 right, out Matrix2x3 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z,
|
||||
rM31 = right.Row2.X, rm32 = right.Row2.Y, rM33 = right.Row2.Z;
|
||||
|
||||
result.Row0.X = ((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31);
|
||||
result.Row0.Y = ((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rm32);
|
||||
result.Row0.Z = ((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33);
|
||||
result.Row1.X = ((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31);
|
||||
result.Row1.Y = ((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rm32);
|
||||
result.Row1.Z = ((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33);
|
||||
}
|
||||
|
||||
/// <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 Matrix2x3 Mult(Matrix2x3 left, Matrix3 right)
|
||||
{
|
||||
Matrix2x3 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 Matrix2x3 left, ref Matrix3x4 right, out Matrix2x4 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z, rM14 = right.Row0.W,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z, rM24 = right.Row1.W,
|
||||
rM31 = right.Row2.X, rm32 = right.Row2.Y, rM33 = right.Row2.Z, rM34 = right.Row2.W;
|
||||
|
||||
result.Row0.X = ((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31);
|
||||
result.Row0.Y = ((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rm32);
|
||||
result.Row0.Z = ((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33);
|
||||
result.Row0.W = ((lM11 * rM14) + (lM12 * rM24)) + (lM13 * rM34);
|
||||
result.Row1.X = ((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31);
|
||||
result.Row1.Y = ((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rm32);
|
||||
result.Row1.Z = ((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33);
|
||||
result.Row1.W = ((lM21 * rM14) + (lM22 * rM24)) + (lM23 * rM34);
|
||||
}
|
||||
|
||||
/// <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 Matrix2x4 Mult(Matrix2x3 left, Matrix3x4 right)
|
||||
{
|
||||
Matrix2x4 result;
|
||||
Mult(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Add
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <param name="result">A new instance that is the result of the addition.</param>
|
||||
public static void Add(ref Matrix2x3 left, ref Matrix2x3 right, out Matrix2x3 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X + right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y + right.Row0.Y;
|
||||
result.Row0.Z = left.Row0.Z + right.Row0.Z;
|
||||
result.Row1.X = left.Row1.X + right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y + right.Row1.Y;
|
||||
result.Row1.Z = left.Row1.Z + right.Row1.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <returns>A new instance that is the result of the addition.</returns>
|
||||
public static Matrix2x3 Add(Matrix2x3 left, Matrix2x3 right)
|
||||
{
|
||||
Matrix2x3 result;
|
||||
Add(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subtract
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <param name="result">A new instance that is the result of the subtraction.</param>
|
||||
public static void Subtract(ref Matrix2x3 left, ref Matrix2x3 right, out Matrix2x3 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X - right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y - right.Row0.Y;
|
||||
result.Row0.Z = left.Row0.Z - right.Row0.Z;
|
||||
result.Row1.X = left.Row1.X - right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y - right.Row1.Y;
|
||||
result.Row1.Z = left.Row1.Z - right.Row1.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <returns>A new instance that is the result of the subtraction.</returns>
|
||||
public static Matrix2x3 Subtract(Matrix2x3 left, Matrix2x3 right)
|
||||
{
|
||||
Matrix2x3 result;
|
||||
Subtract(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Transpose
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the transpose of the given matrix.
|
||||
/// </summary>
|
||||
/// <param name="mat">The matrix to transpose.</param>
|
||||
/// <param name="result">The transpose of the given matrix.</param>
|
||||
public static void Transpose(ref Matrix2x3 mat, out Matrix3x2 result)
|
||||
{
|
||||
result.Row0.X = mat.Row0.X;
|
||||
result.Row0.Y = mat.Row1.X;
|
||||
result.Row1.X = mat.Row0.Y;
|
||||
result.Row1.Y = mat.Row1.Y;
|
||||
result.Row2.X = mat.Row0.Z;
|
||||
result.Row2.Y = mat.Row1.Z;
|
||||
}
|
||||
|
||||
/// <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 Matrix3x2 Transpose(Matrix2x3 mat)
|
||||
{
|
||||
Matrix3x2 result;
|
||||
Transpose(ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x3 which holds the result of the multiplication</returns>
|
||||
public static Matrix2x3 operator *(float left, Matrix2x3 right)
|
||||
{
|
||||
return Mult(right, left);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x3 which holds the result of the multiplication</returns>
|
||||
public static Matrix2x3 operator *(Matrix2x3 left, float right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2 which holds the result of the multiplication</returns>
|
||||
public static Matrix2 operator *(Matrix2x3 left, Matrix3x2 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x3 which holds the result of the multiplication</returns>
|
||||
public static Matrix2x3 operator *(Matrix2x3 left, Matrix3 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x4 which holds the result of the multiplication</returns>
|
||||
public static Matrix2x4 operator *(Matrix2x3 left, Matrix3x4 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix addition
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x3 which holds the result of the addition</returns>
|
||||
public static Matrix2x3 operator +(Matrix2x3 left, Matrix2x3 right)
|
||||
{
|
||||
return Add(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix subtraction
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x3 which holds the result of the subtraction</returns>
|
||||
public static Matrix2x3 operator -(Matrix2x3 left, Matrix2x3 right)
|
||||
{
|
||||
return Subtract(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left equals right; false otherwise.</returns>
|
||||
public static bool operator ==(Matrix2x3 left, Matrix2x3 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left does not equal right; false otherwise.</returns>
|
||||
public static bool operator !=(Matrix2x3 left, Matrix2x3 right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Matrix2x3.
|
||||
/// </summary>
|
||||
/// <returns>The string representation of the matrix.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0}\n{1}", Row0, Row1);
|
||||
}
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
#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 tresult.</param>
|
||||
/// <returns>True if the instances are equal; false otherwise.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Matrix2x3))
|
||||
return false;
|
||||
|
||||
return this.Equals((Matrix2x3)obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<Matrix2x3> 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(Matrix2x3 other)
|
||||
{
|
||||
return
|
||||
Row0 == other.Row0 &&
|
||||
Row1 == other.Row1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
724
Source/OpenTK/Math/Matrix2x3d.cs
Normal file
724
Source/OpenTK/Math/Matrix2x3d.cs
Normal file
|
@ -0,0 +1,724 @@
|
|||
#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.Collections.Generic;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a 2x3 matrix.
|
||||
/// </summary>
|
||||
public struct Matrix2x3d : IEquatable<Matrix2x3d>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Top row of the matrix.
|
||||
/// </summary>
|
||||
public Vector3d Row0;
|
||||
|
||||
/// <summary>
|
||||
/// Bottom row of the matrix.
|
||||
/// </summary>
|
||||
public Vector3d Row1;
|
||||
|
||||
/// <summary>
|
||||
/// The zero matrix.
|
||||
/// </summary>
|
||||
public static readonly Matrix2x3d Zero = new Matrix2x3d(Vector3d.Zero, Vector3d.Zero);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance.
|
||||
/// </summary>
|
||||
/// <param name="row0">Top row of the matrix.</param>
|
||||
/// <param name="row1">Bottom row of the matrix.</param>
|
||||
public Matrix2x3d(Vector3d row0, Vector3d row1)
|
||||
{
|
||||
Row0 = row0;
|
||||
Row1 = row1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance
|
||||
/// </summary>
|
||||
/// <param name="m00">First item of the first row of the matrix.</param>
|
||||
/// <param name="m01">Second item of the first row of the matrix.</param>
|
||||
/// <param name="m02">Third item of the first row of the matrix.</param>
|
||||
/// <param name="m10">First item of the second row of the matrix.</param>
|
||||
/// <param name="m11">Second item of the second row of the matrix.</param>
|
||||
/// <param name="m12">Third item of the second row of the matrix.</param>
|
||||
public Matrix2x3d(
|
||||
double m00, double m01, double m02,
|
||||
double m10, double m11, double m12)
|
||||
{
|
||||
Row0 = new Vector3d(m00, m01, m02);
|
||||
Row1 = new Vector3d(m10, m11, m12);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the first column of this matrix.
|
||||
/// </summary>
|
||||
public Vector2d Column0
|
||||
{
|
||||
get { return new Vector2d(Row0.X, Row1.X); }
|
||||
set { Row0.X = value.X; Row1.X = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the second column of this matrix.
|
||||
/// </summary>
|
||||
public Vector2d Column1
|
||||
{
|
||||
get { return new Vector2d(Row0.Y, Row1.Y); }
|
||||
set { Row0.Y = value.X; Row1.Y = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the third column of this matrix.
|
||||
/// </summary>
|
||||
public Vector2d Column2
|
||||
{
|
||||
get { return new Vector2d(Row0.Z, Row1.Z); }
|
||||
set { Row0.Z = value.X; Row1.Z = value.Y; }
|
||||
}
|
||||
|
||||
/// <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 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 values along the main diagonal of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Diagonal
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2d(Row0.X, Row1.Y);
|
||||
}
|
||||
set
|
||||
{
|
||||
Row0.X = value.X;
|
||||
Row1.Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trace of the matrix, the sum of the values along the diagonal.
|
||||
/// </summary>
|
||||
public double Trace { get { return Row0.X + Row1.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexers
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at a specified row and column.
|
||||
/// </summary>
|
||||
public double this[int rowIndex, int columnIndex]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowIndex == 0) return Row0[columnIndex];
|
||||
else if (rowIndex == 1) return Row1[columnIndex];
|
||||
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowIndex == 0) Row0[columnIndex] = value;
|
||||
else if (rowIndex == 1) Row1[columnIndex] = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Instance
|
||||
#endregion
|
||||
|
||||
#region Static
|
||||
|
||||
#region CreateRotation
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix2x3d instance.</param>
|
||||
public static void CreateRotation(double angle, out Matrix2x3d result)
|
||||
{
|
||||
double cos = System.Math.Cos(angle);
|
||||
double sin = System.Math.Sin(angle);
|
||||
|
||||
result.Row0.X = cos;
|
||||
result.Row0.Y = sin;
|
||||
result.Row0.Z = 0;
|
||||
result.Row1.X = -sin;
|
||||
result.Row1.Y = cos;
|
||||
result.Row1.Z = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix2x3d instance.</returns>
|
||||
public static Matrix2x3d CreateRotation(double angle)
|
||||
{
|
||||
Matrix2x3d result;
|
||||
CreateRotation(angle, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateScale
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x, y, and z axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(double scale, out Matrix2x3d result)
|
||||
{
|
||||
result.Row0.X = scale;
|
||||
result.Row0.Y = 0;
|
||||
result.Row0.Z = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale;
|
||||
result.Row1.Z = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2x3d CreateScale(double scale)
|
||||
{
|
||||
Matrix2x3d result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(Vector2d scale, out Matrix2x3d result)
|
||||
{
|
||||
result.Row0.X = scale.X;
|
||||
result.Row0.Y = 0;
|
||||
result.Row0.Z = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale.Y;
|
||||
result.Row1.Z = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2x3d CreateScale(Vector2d scale)
|
||||
{
|
||||
Matrix2x3d result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(double x, double y, out Matrix2x3d result)
|
||||
{
|
||||
result.Row0.X = x;
|
||||
result.Row0.Y = 0;
|
||||
result.Row0.Z = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = y;
|
||||
result.Row1.Z = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2x3d CreateScale(double x, double y)
|
||||
{
|
||||
Matrix2x3d result;
|
||||
CreateScale(x, y, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Multiply Functions
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix2x3d left, double right, out Matrix2x3d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X * right;
|
||||
result.Row0.Y = left.Row0.Y * right;
|
||||
result.Row0.Z = left.Row0.Z * right;
|
||||
result.Row1.X = left.Row1.X * right;
|
||||
result.Row1.Y = left.Row1.Y * right;
|
||||
result.Row1.Z = left.Row1.Z * right;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix2x3d Mult(Matrix2x3d left, double right)
|
||||
{
|
||||
Matrix2x3d result;
|
||||
Mult(ref left, 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 Matrix2x3d left, ref Matrix3x2 right, out Matrix2d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y,
|
||||
rM31 = right.Row2.X, rM32 = right.Row2.Y;
|
||||
|
||||
result.Row0.X = ((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31);
|
||||
result.Row0.Y = ((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32);
|
||||
result.Row1.X = ((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31);
|
||||
result.Row1.Y = ((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32);
|
||||
}
|
||||
|
||||
/// <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 Matrix2d Mult(Matrix2x3d left, Matrix3x2 right)
|
||||
{
|
||||
Matrix2d 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 Matrix2x3d left, ref Matrix3 right, out Matrix2x3d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z,
|
||||
rM31 = right.Row2.X, rm32 = right.Row2.Y, rM33 = right.Row2.Z;
|
||||
|
||||
result.Row0.X = ((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31);
|
||||
result.Row0.Y = ((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rm32);
|
||||
result.Row0.Z = ((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33);
|
||||
result.Row1.X = ((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31);
|
||||
result.Row1.Y = ((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rm32);
|
||||
result.Row1.Z = ((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33);
|
||||
}
|
||||
|
||||
/// <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 Matrix2x3d Mult(Matrix2x3d left, Matrix3 right)
|
||||
{
|
||||
Matrix2x3d 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 Matrix2x3d left, ref Matrix3x4 right, out Matrix2x4d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z, rM14 = right.Row0.W,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z, rM24 = right.Row1.W,
|
||||
rM31 = right.Row2.X, rm32 = right.Row2.Y, rM33 = right.Row2.Z, rM34 = right.Row2.W;
|
||||
|
||||
result.Row0.X = ((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31);
|
||||
result.Row0.Y = ((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rm32);
|
||||
result.Row0.Z = ((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33);
|
||||
result.Row0.W = ((lM11 * rM14) + (lM12 * rM24)) + (lM13 * rM34);
|
||||
result.Row1.X = ((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31);
|
||||
result.Row1.Y = ((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rm32);
|
||||
result.Row1.Z = ((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33);
|
||||
result.Row1.W = ((lM21 * rM14) + (lM22 * rM24)) + (lM23 * rM34);
|
||||
}
|
||||
|
||||
/// <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 Matrix2x4d Mult(Matrix2x3d left, Matrix3x4 right)
|
||||
{
|
||||
Matrix2x4d result;
|
||||
Mult(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Add
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <param name="result">A new instance that is the result of the addition.</param>
|
||||
public static void Add(ref Matrix2x3d left, ref Matrix2x3d right, out Matrix2x3d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X + right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y + right.Row0.Y;
|
||||
result.Row0.Z = left.Row0.Z + right.Row0.Z;
|
||||
result.Row1.X = left.Row1.X + right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y + right.Row1.Y;
|
||||
result.Row1.Z = left.Row1.Z + right.Row1.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <returns>A new instance that is the result of the addition.</returns>
|
||||
public static Matrix2x3d Add(Matrix2x3d left, Matrix2x3d right)
|
||||
{
|
||||
Matrix2x3d result;
|
||||
Add(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subtract
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <param name="result">A new instance that is the result of the subtraction.</param>
|
||||
public static void Subtract(ref Matrix2x3d left, ref Matrix2x3d right, out Matrix2x3d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X - right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y - right.Row0.Y;
|
||||
result.Row0.Z = left.Row0.Z - right.Row0.Z;
|
||||
result.Row1.X = left.Row1.X - right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y - right.Row1.Y;
|
||||
result.Row1.Z = left.Row1.Z - right.Row1.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <returns>A new instance that is the result of the subtraction.</returns>
|
||||
public static Matrix2x3d Subtract(Matrix2x3d left, Matrix2x3d right)
|
||||
{
|
||||
Matrix2x3d result;
|
||||
Subtract(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Transpose
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the transpose of the given matrix.
|
||||
/// </summary>
|
||||
/// <param name="mat">The matrix to transpose.</param>
|
||||
/// <param name="result">The transpose of the given matrix.</param>
|
||||
public static void Transpose(ref Matrix2x3d mat, out Matrix3x2d result)
|
||||
{
|
||||
result.Row0.X = mat.Row0.X;
|
||||
result.Row0.Y = mat.Row1.X;
|
||||
result.Row1.X = mat.Row0.Y;
|
||||
result.Row1.Y = mat.Row1.Y;
|
||||
result.Row2.X = mat.Row0.Z;
|
||||
result.Row2.Y = mat.Row1.Z;
|
||||
}
|
||||
|
||||
/// <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 Matrix3x2d Transpose(Matrix2x3d mat)
|
||||
{
|
||||
Matrix3x2d result;
|
||||
Transpose(ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x3d which holds the result of the multiplication</returns>
|
||||
public static Matrix2x3d operator *(double left, Matrix2x3d right)
|
||||
{
|
||||
return Mult(right, left);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x3d which holds the result of the multiplication</returns>
|
||||
public static Matrix2x3d operator *(Matrix2x3d left, double right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2d which holds the result of the multiplication</returns>
|
||||
public static Matrix2d operator *(Matrix2x3d left, Matrix3x2 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x3d which holds the result of the multiplication</returns>
|
||||
public static Matrix2x3d operator *(Matrix2x3d left, Matrix3 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x4d which holds the result of the multiplication</returns>
|
||||
public static Matrix2x4d operator *(Matrix2x3d left, Matrix3x4 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix addition
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x3d which holds the result of the addition</returns>
|
||||
public static Matrix2x3d operator +(Matrix2x3d left, Matrix2x3d right)
|
||||
{
|
||||
return Add(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix subtraction
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x3d which holds the result of the subtraction</returns>
|
||||
public static Matrix2x3d operator -(Matrix2x3d left, Matrix2x3d right)
|
||||
{
|
||||
return Subtract(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left equals right; false otherwise.</returns>
|
||||
public static bool operator ==(Matrix2x3d left, Matrix2x3d right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left does not equal right; false otherwise.</returns>
|
||||
public static bool operator !=(Matrix2x3d left, Matrix2x3d right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Matrix2x3d.
|
||||
/// </summary>
|
||||
/// <returns>The string representation of the matrix.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0}\n{1}", Row0, Row1);
|
||||
}
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
#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 tresult.</param>
|
||||
/// <returns>True if the instances are equal; false otherwise.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Matrix2x3d))
|
||||
return false;
|
||||
|
||||
return this.Equals((Matrix2x3d)obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<Matrix2x3d> 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(Matrix2x3d other)
|
||||
{
|
||||
return
|
||||
Row0 == other.Row0 &&
|
||||
Row1 == other.Row1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
761
Source/OpenTK/Math/Matrix2x4.cs
Normal file
761
Source/OpenTK/Math/Matrix2x4.cs
Normal file
|
@ -0,0 +1,761 @@
|
|||
#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
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a 2x4 matrix.
|
||||
/// </summary>
|
||||
public struct Matrix2x4 : IEquatable<Matrix2x4>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Top row of the matrix.
|
||||
/// </summary>
|
||||
public Vector4 Row0;
|
||||
|
||||
/// <summary>
|
||||
/// Bottom row of the matrix.
|
||||
/// </summary>
|
||||
public Vector4 Row1;
|
||||
|
||||
/// <summary>
|
||||
/// The zero matrix.
|
||||
/// </summary>
|
||||
public static readonly Matrix2x4 Zero = new Matrix2x4(Vector4.Zero, Vector4.Zero);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance.
|
||||
/// </summary>
|
||||
/// <param name="row0">Top row of the matrix.</param>
|
||||
/// <param name="row1">Bottom row of the matrix.</param>
|
||||
public Matrix2x4(Vector4 row0, Vector4 row1)
|
||||
{
|
||||
Row0 = row0;
|
||||
Row1 = row1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance
|
||||
/// </summary>
|
||||
/// <param name="m00">First item of the first row of the matrix.</param>
|
||||
/// <param name="m01">Second item of the first row of the matrix.</param>
|
||||
/// <param name="m02">Third item of the first row of the matrix.</param>
|
||||
/// <param name="m03">Fourth item of the first row of the matrix.</param>
|
||||
/// <param name="m10">First item of the second row of the matrix.</param>
|
||||
/// <param name="m11">Second item of the second row of the matrix.</param>
|
||||
/// <param name="m12">Third item of the second row of the matrix.</param>
|
||||
/// <param name="m13">Fourth item of the second row of the matrix.</param>
|
||||
public Matrix2x4(
|
||||
float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13)
|
||||
{
|
||||
Row0 = new Vector4(m00, m01, m02, m03);
|
||||
Row1 = new Vector4(m10, m11, m12, m13);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the first column of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Column0
|
||||
{
|
||||
get { return new Vector2(Row0.X, Row1.X); }
|
||||
set { Row0.X = value.X; Row1.X = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the second column of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Column1
|
||||
{
|
||||
get { return new Vector2(Row0.Y, Row1.Y); }
|
||||
set { Row0.Y = value.X; Row1.Y = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the third column of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Column2
|
||||
{
|
||||
get { return new Vector2(Row0.Z, Row1.Z); }
|
||||
set { Row0.Z = value.X; Row1.Z = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the fourth column of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Column3
|
||||
{
|
||||
get { return new Vector2(Row0.W, Row1.W); }
|
||||
set { Row0.W = value.X; Row1.W = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 1, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float 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 float 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 float 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 float 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 float 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 float 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 float 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 float M24 { get { return Row1.W; } set { Row1.W = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the values along the main diagonal of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Diagonal
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2(Row0.X, Row1.Y);
|
||||
}
|
||||
set
|
||||
{
|
||||
Row0.X = value.X;
|
||||
Row1.Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trace of the matrix, the sum of the values along the diagonal.
|
||||
/// </summary>
|
||||
public float Trace { get { return Row0.X + Row1.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexers
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at a specified row and column.
|
||||
/// </summary>
|
||||
public float this[int rowIndex, int columnIndex]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowIndex == 0) return Row0[columnIndex];
|
||||
else if (rowIndex == 1) return Row1[columnIndex];
|
||||
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowIndex == 0) Row0[columnIndex] = value;
|
||||
else if (rowIndex == 1) Row1[columnIndex] = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static
|
||||
|
||||
#region CreateRotation
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix2x4 instance.</param>
|
||||
public static void CreateRotation(float angle, out Matrix2x4 result)
|
||||
{
|
||||
float cos = (float)System.Math.Cos(angle);
|
||||
float sin = (float)System.Math.Sin(angle);
|
||||
|
||||
result.Row0.X = cos;
|
||||
result.Row0.Y = sin;
|
||||
result.Row0.Z = 0;
|
||||
result.Row0.W = 0;
|
||||
result.Row1.X = -sin;
|
||||
result.Row1.Y = cos;
|
||||
result.Row1.Z = 0;
|
||||
result.Row1.W = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix2x3 instance.</returns>
|
||||
public static Matrix2x4 CreateRotation(float angle)
|
||||
{
|
||||
Matrix2x4 result;
|
||||
CreateRotation(angle, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateScale
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x, y, and z axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(float scale, out Matrix2x4 result)
|
||||
{
|
||||
result.Row0.X = scale;
|
||||
result.Row0.Y = 0;
|
||||
result.Row0.Z = 0;
|
||||
result.Row0.W = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale;
|
||||
result.Row1.Z = 0;
|
||||
result.Row1.W = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2x4 CreateScale(float scale)
|
||||
{
|
||||
Matrix2x4 result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(Vector2 scale, out Matrix2x4 result)
|
||||
{
|
||||
result.Row0.X = scale.X;
|
||||
result.Row0.Y = 0;
|
||||
result.Row0.Z = 0;
|
||||
result.Row0.W = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale.Y;
|
||||
result.Row1.Z = 0;
|
||||
result.Row1.W = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2x4 CreateScale(Vector2 scale)
|
||||
{
|
||||
Matrix2x4 result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(float x, float y, out Matrix2x4 result)
|
||||
{
|
||||
result.Row0.X = x;
|
||||
result.Row0.Y = 0;
|
||||
result.Row0.Z = 0;
|
||||
result.Row0.W = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = y;
|
||||
result.Row1.Z = 0;
|
||||
result.Row1.W = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2x4 CreateScale(float x, float y)
|
||||
{
|
||||
Matrix2x4 result;
|
||||
CreateScale(x, y, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Multiply Functions
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix2x4 left, float right, out Matrix2x4 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X * right;
|
||||
result.Row0.Y = left.Row0.Y * right;
|
||||
result.Row0.Z = left.Row0.Z * right;
|
||||
result.Row0.W = left.Row0.W * right;
|
||||
result.Row1.X = left.Row1.X * right;
|
||||
result.Row1.Y = left.Row1.Y * right;
|
||||
result.Row1.Z = left.Row1.Z * right;
|
||||
result.Row1.W = left.Row1.W * right;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix2x4 Mult(Matrix2x4 left, float right)
|
||||
{
|
||||
Matrix2x4 result;
|
||||
Mult(ref left, 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 Matrix2x4 left, ref Matrix4x2 right, out Matrix2 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z, lM14 = left.Row0.W,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z, lM24 = left.Row1.W,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y,
|
||||
rM31 = right.Row2.X, rM32 = right.Row2.Y,
|
||||
rM41 = right.Row3.X, rM42 = right.Row3.Y;
|
||||
|
||||
result.Row0.X = (((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31)) + (lM14 * rM41);
|
||||
result.Row0.Y = (((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32)) + (lM14 * rM42);
|
||||
result.Row1.X = (((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31)) + (lM24 * rM41);
|
||||
result.Row1.Y = (((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32)) + (lM24 * rM42);
|
||||
}
|
||||
|
||||
/// <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 Matrix2 Mult(Matrix2x4 left, Matrix4x2 right)
|
||||
{
|
||||
Matrix2 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 Matrix2x4 left, ref Matrix4x3 right, out Matrix2x3 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z, lM14 = left.Row0.W,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z, lM24 = left.Row1.W,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z,
|
||||
rM31 = right.Row2.X, rM32 = right.Row2.Y, rM33 = right.Row2.Z,
|
||||
rM41 = right.Row3.X, rM42 = right.Row3.Y, rM43 = right.Row3.Z;
|
||||
|
||||
result.Row0.X = (((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31)) + (lM14 * rM41);
|
||||
result.Row0.Y = (((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32)) + (lM14 * rM42);
|
||||
result.Row0.Z = (((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33)) + (lM14 * rM43);
|
||||
result.Row1.X = (((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31)) + (lM24 * rM41);
|
||||
result.Row1.Y = (((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32)) + (lM24 * rM42);
|
||||
result.Row1.Z = (((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33)) + (lM24 * rM43);
|
||||
}
|
||||
|
||||
/// <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 Matrix2x3 Mult(Matrix2x4 left, Matrix4x3 right)
|
||||
{
|
||||
Matrix2x3 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 Matrix2x4 left, ref Matrix4 right, out Matrix2x4 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z, lM14 = left.Row0.W,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z, lM24 = left.Row1.W,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z, rM14 = right.Row0.W,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z, rM24 = right.Row1.W,
|
||||
rM31 = right.Row2.X, rM32 = right.Row2.Y, rM33 = right.Row2.Z, rM34 = right.Row2.W,
|
||||
rM41 = right.Row3.X, rM42 = right.Row3.Y, rM43 = right.Row3.Z, rM44 = right.Row3.W;
|
||||
|
||||
result.Row0.X = (((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31)) + (lM14 * rM41);
|
||||
result.Row0.Y = (((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32)) + (lM14 * rM42);
|
||||
result.Row0.Z = (((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33)) + (lM14 * rM43);
|
||||
result.Row0.W = (((lM11 * rM14) + (lM12 * rM24)) + (lM13 * rM34)) + (lM14 * rM44);
|
||||
result.Row1.X = (((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31)) + (lM24 * rM41);
|
||||
result.Row1.Y = (((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32)) + (lM24 * rM42);
|
||||
result.Row1.Z = (((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33)) + (lM24 * rM43);
|
||||
result.Row1.W = (((lM21 * rM14) + (lM22 * rM24)) + (lM23 * rM34)) + (lM24 * rM44);
|
||||
}
|
||||
|
||||
/// <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 Matrix2x4 Mult(Matrix2x4 left, Matrix4 right)
|
||||
{
|
||||
Matrix2x4 result;
|
||||
Mult(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Add
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <param name="result">A new instance that is the result of the addition.</param>
|
||||
public static void Add(ref Matrix2x4 left, ref Matrix2x4 right, out Matrix2x4 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X + right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y + right.Row0.Y;
|
||||
result.Row0.Z = left.Row0.Z + right.Row0.Z;
|
||||
result.Row0.W = left.Row0.W + right.Row0.W;
|
||||
result.Row1.X = left.Row1.X + right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y + right.Row1.Y;
|
||||
result.Row1.Z = left.Row1.Z + right.Row1.Z;
|
||||
result.Row1.W = left.Row1.W + right.Row1.W;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <returns>A new instance that is the result of the addition.</returns>
|
||||
public static Matrix2x4 Add(Matrix2x4 left, Matrix2x4 right)
|
||||
{
|
||||
Matrix2x4 result;
|
||||
Add(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subtract
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <param name="result">A new instance that is the result of the subtraction.</param>
|
||||
public static void Subtract(ref Matrix2x4 left, ref Matrix2x4 right, out Matrix2x4 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X - right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y - right.Row0.Y;
|
||||
result.Row0.Z = left.Row0.Z - right.Row0.Z;
|
||||
result.Row0.W = left.Row0.W - right.Row0.W;
|
||||
result.Row1.X = left.Row1.X - right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y - right.Row1.Y;
|
||||
result.Row1.Z = left.Row1.Z - right.Row1.Z;
|
||||
result.Row1.W = left.Row1.W - right.Row1.W;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <returns>A new instance that is the result of the subtraction.</returns>
|
||||
public static Matrix2x4 Subtract(Matrix2x4 left, Matrix2x4 right)
|
||||
{
|
||||
Matrix2x4 result;
|
||||
Subtract(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Transpose
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the transpose of the given matrix.
|
||||
/// </summary>
|
||||
/// <param name="mat">The matrix to transpose.</param>
|
||||
/// <param name="result">The transpose of the given matrix.</param>
|
||||
public static void Transpose(ref Matrix2x4 mat, out Matrix4x2 result)
|
||||
{
|
||||
result.Row0.X = mat.Row0.X;
|
||||
result.Row0.Y = mat.Row1.X;
|
||||
result.Row1.X = mat.Row0.Y;
|
||||
result.Row1.Y = mat.Row1.Y;
|
||||
result.Row2.X = mat.Row0.Z;
|
||||
result.Row2.Y = mat.Row1.Z;
|
||||
result.Row3.X = mat.Row0.W;
|
||||
result.Row3.Y = mat.Row1.W;
|
||||
}
|
||||
|
||||
/// <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 Matrix4x2 Transpose(Matrix2x4 mat)
|
||||
{
|
||||
Matrix4x2 result;
|
||||
Transpose(ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x4 which holds the result of the multiplication</returns>
|
||||
public static Matrix2x4 operator *(float left, Matrix2x4 right)
|
||||
{
|
||||
return Mult(right, left);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x4 which holds the result of the multiplication</returns>
|
||||
public static Matrix2x4 operator *(Matrix2x4 left, float right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2 which holds the result of the multiplication</returns>
|
||||
public static Matrix2 operator *(Matrix2x4 left, Matrix4x2 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x3 which holds the result of the multiplication</returns>
|
||||
public static Matrix2x3 operator *(Matrix2x4 left, Matrix4x3 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x4 which holds the result of the multiplication</returns>
|
||||
public static Matrix2x4 operator *(Matrix2x4 left, Matrix4 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix addition
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2 which holds the result of the addition</returns>
|
||||
public static Matrix2x4 operator +(Matrix2x4 left, Matrix2x4 right)
|
||||
{
|
||||
return Add(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix subtraction
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x4 which holds the result of the subtraction</returns>
|
||||
public static Matrix2x4 operator -(Matrix2x4 left, Matrix2x4 right)
|
||||
{
|
||||
return Subtract(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left equals right; false otherwise.</returns>
|
||||
public static bool operator ==(Matrix2x4 left, Matrix2x4 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left does not equal right; false otherwise.</returns>
|
||||
public static bool operator !=(Matrix2x4 left, Matrix2x4 right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Matrix4.
|
||||
/// </summary>
|
||||
/// <returns>The string representation of the matrix.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0}\n{1}", Row0, Row1);
|
||||
}
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
#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 Matrix2x4))
|
||||
return false;
|
||||
|
||||
return this.Equals((Matrix2x4)obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<Matrix2x4> 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(Matrix2x4 other)
|
||||
{
|
||||
return
|
||||
Row0 == other.Row0 &&
|
||||
Row1 == other.Row1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
761
Source/OpenTK/Math/Matrix2x4d.cs
Normal file
761
Source/OpenTK/Math/Matrix2x4d.cs
Normal file
|
@ -0,0 +1,761 @@
|
|||
#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
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a 2x4 matrix.
|
||||
/// </summary>
|
||||
public struct Matrix2x4d : IEquatable<Matrix2x4d>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Top row of the matrix.
|
||||
/// </summary>
|
||||
public Vector4d Row0;
|
||||
|
||||
/// <summary>
|
||||
/// Bottom row of the matrix.
|
||||
/// </summary>
|
||||
public Vector4d Row1;
|
||||
|
||||
/// <summary>
|
||||
/// The zero matrix.
|
||||
/// </summary>
|
||||
public static readonly Matrix2x4d Zero = new Matrix2x4d(Vector4d.Zero, Vector4d.Zero);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance.
|
||||
/// </summary>
|
||||
/// <param name="row0">Top row of the matrix.</param>
|
||||
/// <param name="row1">Bottom row of the matrix.</param>
|
||||
public Matrix2x4d(Vector4d row0, Vector4d row1)
|
||||
{
|
||||
Row0 = row0;
|
||||
Row1 = row1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance
|
||||
/// </summary>
|
||||
/// <param name="m00">First item of the first row of the matrix.</param>
|
||||
/// <param name="m01">Second item of the first row of the matrix.</param>
|
||||
/// <param name="m02">Third item of the first row of the matrix.</param>
|
||||
/// <param name="m03">Fourth item of the first row of the matrix.</param>
|
||||
/// <param name="m10">First item of the second row of the matrix.</param>
|
||||
/// <param name="m11">Second item of the second row of the matrix.</param>
|
||||
/// <param name="m12">Third item of the second row of the matrix.</param>
|
||||
/// <param name="m13">Fourth item of the second row of the matrix.</param>
|
||||
public Matrix2x4d(
|
||||
double m00, double m01, double m02, double m03,
|
||||
double m10, double m11, double m12, double m13)
|
||||
{
|
||||
Row0 = new Vector4d(m00, m01, m02, m03);
|
||||
Row1 = new Vector4d(m10, m11, m12, m13);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the first column of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Column0
|
||||
{
|
||||
get { return new Vector2d(Row0.X, Row1.X); }
|
||||
set { Row0.X = value.X; Row1.X = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the second column of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Column1
|
||||
{
|
||||
get { return new Vector2d(Row0.Y, Row1.Y); }
|
||||
set { Row0.Y = value.X; Row1.Y = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the third column of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Column2
|
||||
{
|
||||
get { return new Vector2d(Row0.Z, Row1.Z); }
|
||||
set { Row0.Z = value.X; Row1.Z = value.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the fourth column of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Column3
|
||||
{
|
||||
get { return new Vector2d(Row0.W, Row1.W); }
|
||||
set { Row0.W = value.X; Row1.W = value.Y; }
|
||||
}
|
||||
|
||||
/// <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 values along the main diagonal of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Diagonal
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2d(Row0.X, Row1.Y);
|
||||
}
|
||||
set
|
||||
{
|
||||
Row0.X = value.X;
|
||||
Row1.Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trace of the matrix, the sum of the values along the diagonal.
|
||||
/// </summary>
|
||||
public double Trace { get { return Row0.X + Row1.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexers
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at a specified row and column.
|
||||
/// </summary>
|
||||
public double this[int rowIndex, int columnIndex]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowIndex == 0) return Row0[columnIndex];
|
||||
else if (rowIndex == 1) return Row1[columnIndex];
|
||||
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowIndex == 0) Row0[columnIndex] = value;
|
||||
else if (rowIndex == 1) Row1[columnIndex] = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static
|
||||
|
||||
#region CreateRotation
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix2x4d instance.</param>
|
||||
public static void CreateRotation(double angle, out Matrix2x4d result)
|
||||
{
|
||||
double cos = System.Math.Cos(angle);
|
||||
double sin = System.Math.Sin(angle);
|
||||
|
||||
result.Row0.X = cos;
|
||||
result.Row0.Y = sin;
|
||||
result.Row0.Z = 0;
|
||||
result.Row0.W = 0;
|
||||
result.Row1.X = -sin;
|
||||
result.Row1.Y = cos;
|
||||
result.Row1.Z = 0;
|
||||
result.Row1.W = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix2x3d instance.</returns>
|
||||
public static Matrix2x4d CreateRotation(double angle)
|
||||
{
|
||||
Matrix2x4d result;
|
||||
CreateRotation(angle, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateScale
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x, y, and z axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(double scale, out Matrix2x4d result)
|
||||
{
|
||||
result.Row0.X = scale;
|
||||
result.Row0.Y = 0;
|
||||
result.Row0.Z = 0;
|
||||
result.Row0.W = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale;
|
||||
result.Row1.Z = 0;
|
||||
result.Row1.W = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2x4d CreateScale(double scale)
|
||||
{
|
||||
Matrix2x4d result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(Vector2d scale, out Matrix2x4d result)
|
||||
{
|
||||
result.Row0.X = scale.X;
|
||||
result.Row0.Y = 0;
|
||||
result.Row0.Z = 0;
|
||||
result.Row0.W = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale.Y;
|
||||
result.Row1.Z = 0;
|
||||
result.Row1.W = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2x4d CreateScale(Vector2d scale)
|
||||
{
|
||||
Matrix2x4d result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(double x, double y, out Matrix2x4d result)
|
||||
{
|
||||
result.Row0.X = x;
|
||||
result.Row0.Y = 0;
|
||||
result.Row0.Z = 0;
|
||||
result.Row0.W = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = y;
|
||||
result.Row1.Z = 0;
|
||||
result.Row1.W = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix2x4d CreateScale(double x, double y)
|
||||
{
|
||||
Matrix2x4d result;
|
||||
CreateScale(x, y, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Multiply Functions
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix2x4d left, double right, out Matrix2x4d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X * right;
|
||||
result.Row0.Y = left.Row0.Y * right;
|
||||
result.Row0.Z = left.Row0.Z * right;
|
||||
result.Row0.W = left.Row0.W * right;
|
||||
result.Row1.X = left.Row1.X * right;
|
||||
result.Row1.Y = left.Row1.Y * right;
|
||||
result.Row1.Z = left.Row1.Z * right;
|
||||
result.Row1.W = left.Row1.W * right;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix2x4d Mult(Matrix2x4d left, double right)
|
||||
{
|
||||
Matrix2x4d result;
|
||||
Mult(ref left, 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 Matrix2x4d left, ref Matrix4x2 right, out Matrix2d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z, lM14 = left.Row0.W,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z, lM24 = left.Row1.W,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y,
|
||||
rM31 = right.Row2.X, rM32 = right.Row2.Y,
|
||||
rM41 = right.Row3.X, rM42 = right.Row3.Y;
|
||||
|
||||
result.Row0.X = (((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31)) + (lM14 * rM41);
|
||||
result.Row0.Y = (((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32)) + (lM14 * rM42);
|
||||
result.Row1.X = (((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31)) + (lM24 * rM41);
|
||||
result.Row1.Y = (((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32)) + (lM24 * rM42);
|
||||
}
|
||||
|
||||
/// <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 Matrix2d Mult(Matrix2x4d left, Matrix4x2 right)
|
||||
{
|
||||
Matrix2d 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 Matrix2x4d left, ref Matrix4x3 right, out Matrix2x3d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z, lM14 = left.Row0.W,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z, lM24 = left.Row1.W,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z,
|
||||
rM31 = right.Row2.X, rM32 = right.Row2.Y, rM33 = right.Row2.Z,
|
||||
rM41 = right.Row3.X, rM42 = right.Row3.Y, rM43 = right.Row3.Z;
|
||||
|
||||
result.Row0.X = (((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31)) + (lM14 * rM41);
|
||||
result.Row0.Y = (((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32)) + (lM14 * rM42);
|
||||
result.Row0.Z = (((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33)) + (lM14 * rM43);
|
||||
result.Row1.X = (((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31)) + (lM24 * rM41);
|
||||
result.Row1.Y = (((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32)) + (lM24 * rM42);
|
||||
result.Row1.Z = (((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33)) + (lM24 * rM43);
|
||||
}
|
||||
|
||||
/// <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 Matrix2x3d Mult(Matrix2x4d left, Matrix4x3 right)
|
||||
{
|
||||
Matrix2x3d 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 Matrix2x4d left, ref Matrix4 right, out Matrix2x4d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z, lM14 = left.Row0.W,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z, lM24 = left.Row1.W,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z, rM14 = right.Row0.W,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z, rM24 = right.Row1.W,
|
||||
rM31 = right.Row2.X, rM32 = right.Row2.Y, rM33 = right.Row2.Z, rM34 = right.Row2.W,
|
||||
rM41 = right.Row3.X, rM42 = right.Row3.Y, rM43 = right.Row3.Z, rM44 = right.Row3.W;
|
||||
|
||||
result.Row0.X = (((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31)) + (lM14 * rM41);
|
||||
result.Row0.Y = (((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32)) + (lM14 * rM42);
|
||||
result.Row0.Z = (((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33)) + (lM14 * rM43);
|
||||
result.Row0.W = (((lM11 * rM14) + (lM12 * rM24)) + (lM13 * rM34)) + (lM14 * rM44);
|
||||
result.Row1.X = (((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31)) + (lM24 * rM41);
|
||||
result.Row1.Y = (((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32)) + (lM24 * rM42);
|
||||
result.Row1.Z = (((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33)) + (lM24 * rM43);
|
||||
result.Row1.W = (((lM21 * rM14) + (lM22 * rM24)) + (lM23 * rM34)) + (lM24 * rM44);
|
||||
}
|
||||
|
||||
/// <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 Matrix2x4d Mult(Matrix2x4d left, Matrix4 right)
|
||||
{
|
||||
Matrix2x4d result;
|
||||
Mult(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Add
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <param name="result">A new instance that is the result of the addition.</param>
|
||||
public static void Add(ref Matrix2x4d left, ref Matrix2x4d right, out Matrix2x4d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X + right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y + right.Row0.Y;
|
||||
result.Row0.Z = left.Row0.Z + right.Row0.Z;
|
||||
result.Row0.W = left.Row0.W + right.Row0.W;
|
||||
result.Row1.X = left.Row1.X + right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y + right.Row1.Y;
|
||||
result.Row1.Z = left.Row1.Z + right.Row1.Z;
|
||||
result.Row1.W = left.Row1.W + right.Row1.W;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <returns>A new instance that is the result of the addition.</returns>
|
||||
public static Matrix2x4d Add(Matrix2x4d left, Matrix2x4d right)
|
||||
{
|
||||
Matrix2x4d result;
|
||||
Add(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subtract
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <param name="result">A new instance that is the result of the subtraction.</param>
|
||||
public static void Subtract(ref Matrix2x4d left, ref Matrix2x4d right, out Matrix2x4d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X - right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y - right.Row0.Y;
|
||||
result.Row0.Z = left.Row0.Z - right.Row0.Z;
|
||||
result.Row0.W = left.Row0.W - right.Row0.W;
|
||||
result.Row1.X = left.Row1.X - right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y - right.Row1.Y;
|
||||
result.Row1.Z = left.Row1.Z - right.Row1.Z;
|
||||
result.Row1.W = left.Row1.W - right.Row1.W;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <returns>A new instance that is the result of the subtraction.</returns>
|
||||
public static Matrix2x4d Subtract(Matrix2x4d left, Matrix2x4d right)
|
||||
{
|
||||
Matrix2x4d result;
|
||||
Subtract(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Transpose
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the transpose of the given matrix.
|
||||
/// </summary>
|
||||
/// <param name="mat">The matrix to transpose.</param>
|
||||
/// <param name="result">The transpose of the given matrix.</param>
|
||||
public static void Transpose(ref Matrix2x4d mat, out Matrix4x2d result)
|
||||
{
|
||||
result.Row0.X = mat.Row0.X;
|
||||
result.Row0.Y = mat.Row1.X;
|
||||
result.Row1.X = mat.Row0.Y;
|
||||
result.Row1.Y = mat.Row1.Y;
|
||||
result.Row2.X = mat.Row0.Z;
|
||||
result.Row2.Y = mat.Row1.Z;
|
||||
result.Row3.X = mat.Row0.W;
|
||||
result.Row3.Y = mat.Row1.W;
|
||||
}
|
||||
|
||||
/// <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 Matrix4x2d Transpose(Matrix2x4d mat)
|
||||
{
|
||||
Matrix4x2d result;
|
||||
Transpose(ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x4d which holds the result of the multiplication</returns>
|
||||
public static Matrix2x4d operator *(double left, Matrix2x4d right)
|
||||
{
|
||||
return Mult(right, left);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x4d which holds the result of the multiplication</returns>
|
||||
public static Matrix2x4d operator *(Matrix2x4d left, double right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2d which holds the result of the multiplication</returns>
|
||||
public static Matrix2d operator *(Matrix2x4d left, Matrix4x2 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x3d which holds the result of the multiplication</returns>
|
||||
public static Matrix2x3d operator *(Matrix2x4d left, Matrix4x3 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x4d which holds the result of the multiplication</returns>
|
||||
public static Matrix2x4d operator *(Matrix2x4d left, Matrix4 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix addition
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2d which holds the result of the addition</returns>
|
||||
public static Matrix2x4d operator +(Matrix2x4d left, Matrix2x4d right)
|
||||
{
|
||||
return Add(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix subtraction
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2x4d which holds the result of the subtraction</returns>
|
||||
public static Matrix2x4d operator -(Matrix2x4d left, Matrix2x4d right)
|
||||
{
|
||||
return Subtract(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left equals right; false otherwise.</returns>
|
||||
public static bool operator ==(Matrix2x4d left, Matrix2x4d right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left does not equal right; false otherwise.</returns>
|
||||
public static bool operator !=(Matrix2x4d left, Matrix2x4d right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Matrix4.
|
||||
/// </summary>
|
||||
/// <returns>The string representation of the matrix.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0}\n{1}", Row0, Row1);
|
||||
}
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
#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 Matrix2x4d))
|
||||
return false;
|
||||
|
||||
return this.Equals((Matrix2x4d)obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<Matrix2x4d> 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(Matrix2x4d other)
|
||||
{
|
||||
return
|
||||
Row0 == other.Row0 &&
|
||||
Row1 == other.Row1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
974
Source/OpenTK/Math/Matrix3.cs
Normal file
974
Source/OpenTK/Math/Matrix3.cs
Normal file
|
@ -0,0 +1,974 @@
|
|||
#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
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a 3x3 matrix containing 3D rotation and scale.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Matrix3 : IEquatable<Matrix3>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// First row of the matrix.
|
||||
/// </summary>
|
||||
public Vector3 Row0;
|
||||
|
||||
/// <summary>
|
||||
/// Second row of the matrix.
|
||||
/// </summary>
|
||||
public Vector3 Row1;
|
||||
|
||||
/// <summary>
|
||||
/// Third row of the matrix.
|
||||
/// </summary>
|
||||
public Vector3 Row2;
|
||||
|
||||
/// <summary>
|
||||
/// The identity matrix.
|
||||
/// </summary>
|
||||
public static readonly Matrix3 Identity = new Matrix3(Vector3.UnitX, Vector3.UnitY, Vector3.UnitZ);
|
||||
|
||||
/// <summary>
|
||||
/// The zero matrix.
|
||||
/// </summary>
|
||||
public static readonly Matrix3 Zero = new Matrix3(Vector3.Zero, Vector3.Zero, Vector3.Zero);
|
||||
|
||||
#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">Bottom row of the matrix</param>
|
||||
public Matrix3(Vector3 row0, Vector3 row1, Vector3 row2)
|
||||
{
|
||||
Row0 = row0;
|
||||
Row1 = row1;
|
||||
Row2 = row2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance.
|
||||
/// </summary>
|
||||
/// <param name="m00">First item of the first row of the matrix.</param>
|
||||
/// <param name="m01">Second item of the first row of the matrix.</param>
|
||||
/// <param name="m02">Third item of the first row of the matrix.</param>
|
||||
/// <param name="m10">First item of the second row of the matrix.</param>
|
||||
/// <param name="m11">Second item of the second row of the matrix.</param>
|
||||
/// <param name="m12">Third item of the second row of the matrix.</param>
|
||||
/// <param name="m20">First item of the third row of the matrix.</param>
|
||||
/// <param name="m21">Second item of the third row of the matrix.</param>
|
||||
/// <param name="m22">Third item of the third row of the matrix.</param>
|
||||
public Matrix3(
|
||||
float m00, float m01, float m02,
|
||||
float m10, float m11, float m12,
|
||||
float m20, float m21, float m22)
|
||||
{
|
||||
Row0 = new Vector3(m00, m01, m02);
|
||||
Row1 = new Vector3(m10, m11, m12);
|
||||
Row2 = new Vector3(m20, m21, m22);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance.
|
||||
/// </summary>
|
||||
/// <param name="matrix">A Matrix4 to take the upper-left 3x3 from.</param>
|
||||
public Matrix3(Matrix4 matrix)
|
||||
{
|
||||
Row0 = matrix.Row0.Xyz;
|
||||
Row1 = matrix.Row1.Xyz;
|
||||
Row2 = matrix.Row2.Xyz;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the determinant of this matrix.
|
||||
/// </summary>
|
||||
public float Determinant
|
||||
{
|
||||
get
|
||||
{
|
||||
float m11 = Row0.X, m12 = Row0.Y, m13 = Row0.Z,
|
||||
m21 = Row1.X, m22 = Row1.Y, m23 = Row1.Z,
|
||||
m31 = Row2.X, m32 = Row2.Y, m33 = Row2.Z;
|
||||
|
||||
return m11 * m22 * m33 + m12 * m23 * m31 + m13 * m21 * m32
|
||||
- m13 * m22 * m31 - m11 * m23 * m32 - m12 * m21 * m33;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the first column of this matrix.
|
||||
/// </summary>
|
||||
public Vector3 Column0
|
||||
{
|
||||
get { return new Vector3(Row0.X, Row1.X, Row2.X); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the second column of this matrix.
|
||||
/// </summary>
|
||||
public Vector3 Column1
|
||||
{
|
||||
get { return new Vector3(Row0.Y, Row1.Y, Row2.Y); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the third column of this matrix.
|
||||
/// </summary>
|
||||
public Vector3 Column2
|
||||
{
|
||||
get { return new Vector3(Row0.Z, Row1.Z, Row2.Z); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 1, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float 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 float 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 float M13 { get { return Row0.Z; } set { Row0.Z = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 2, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float 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 float 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 float M23 { get { return Row1.Z; } set { Row1.Z = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 3, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float 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 float 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 float M33 { get { return Row2.Z; } set { Row2.Z = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the values along the main diagonal of the matrix.
|
||||
/// </summary>
|
||||
public Vector3 Diagonal
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector3(Row0.X, Row1.Y, Row2.Z);
|
||||
}
|
||||
set
|
||||
{
|
||||
Row0.X = value.X;
|
||||
Row1.Y = value.Y;
|
||||
Row2.Z = value.Z;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trace of the matrix, the sum of the values along the diagonal.
|
||||
/// </summary>
|
||||
public float Trace { get { return Row0.X + Row1.Y + Row2.Z; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexers
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at a specified row and column.
|
||||
/// </summary>
|
||||
public float this[int rowIndex, int columnIndex]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowIndex == 0) return Row0[columnIndex];
|
||||
else if (rowIndex == 1) return Row1[columnIndex];
|
||||
else if (rowIndex == 2) return Row2[columnIndex];
|
||||
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowIndex == 0) Row0[columnIndex] = value;
|
||||
else if (rowIndex == 1) Row1[columnIndex] = value;
|
||||
else if (rowIndex == 2) Row2[columnIndex] = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Instance
|
||||
|
||||
#region public void Invert()
|
||||
|
||||
/// <summary>
|
||||
/// Converts this instance into its inverse.
|
||||
/// </summary>
|
||||
public void Invert()
|
||||
{
|
||||
this = Matrix3.Invert(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void Transpose()
|
||||
|
||||
/// <summary>
|
||||
/// Converts this instance into its transpose.
|
||||
/// </summary>
|
||||
public void Transpose()
|
||||
{
|
||||
this = Matrix3.Transpose(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Returns a normalised copy of this instance.
|
||||
/// </summary>
|
||||
public Matrix3 Normalized()
|
||||
{
|
||||
Matrix3 m = this;
|
||||
m.Normalize();
|
||||
return m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Divides each element in the Matrix by the <see cref="Determinant"/>.
|
||||
/// </summary>
|
||||
public void Normalize()
|
||||
{
|
||||
var determinant = this.Determinant;
|
||||
Row0 /= determinant;
|
||||
Row1 /= determinant;
|
||||
Row2 /= determinant;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an inverted copy of this instance.
|
||||
/// </summary>
|
||||
public Matrix3 Inverted()
|
||||
{
|
||||
Matrix3 m = this;
|
||||
if (m.Determinant != 0)
|
||||
m.Invert();
|
||||
return m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of this Matrix3 without scale.
|
||||
/// </summary>
|
||||
public Matrix3 ClearScale()
|
||||
{
|
||||
Matrix3 m = this;
|
||||
m.Row0 = m.Row0.Normalized();
|
||||
m.Row1 = m.Row1.Normalized();
|
||||
m.Row2 = m.Row2.Normalized();
|
||||
return m;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a copy of this Matrix3 without rotation.
|
||||
/// </summary>
|
||||
public Matrix3 ClearRotation()
|
||||
{
|
||||
Matrix3 m = this;
|
||||
m.Row0 = new Vector3(m.Row0.Length, 0, 0);
|
||||
m.Row1 = new Vector3(0, m.Row1.Length, 0);
|
||||
m.Row2 = new Vector3(0, 0, m.Row2.Length);
|
||||
return m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the scale component of this instance.
|
||||
/// </summary>
|
||||
public Vector3 ExtractScale() { return new Vector3(Row0.Length, Row1.Length, Row2.Length); }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the rotation component of this instance. Quite slow.
|
||||
/// </summary>
|
||||
/// <param name="row_normalise">Whether the method should row-normalise (i.e. remove scale from) the Matrix. Pass false if you know it's already normalised.</param>
|
||||
public Quaternion ExtractRotation(bool row_normalise = true)
|
||||
{
|
||||
var row0 = Row0;
|
||||
var row1 = Row1;
|
||||
var row2 = Row2;
|
||||
|
||||
if (row_normalise)
|
||||
{
|
||||
row0 = row0.Normalized();
|
||||
row1 = row1.Normalized();
|
||||
row2 = row2.Normalized();
|
||||
}
|
||||
|
||||
// code below adapted from Blender
|
||||
|
||||
Quaternion q = new Quaternion();
|
||||
double trace = 0.25 * (row0[0] + row1[1] + row2[2] + 1.0);
|
||||
|
||||
if (trace > 0)
|
||||
{
|
||||
double sq = Math.Sqrt(trace);
|
||||
|
||||
q.W = (float)sq;
|
||||
sq = 1.0 / (4.0 * sq);
|
||||
q.X = (float)((row1[2] - row2[1]) * sq);
|
||||
q.Y = (float)((row2[0] - row0[2]) * sq);
|
||||
q.Z = (float)((row0[1] - row1[0]) * sq);
|
||||
}
|
||||
else if (row0[0] > row1[1] && row0[0] > row2[2])
|
||||
{
|
||||
double sq = 2.0 * Math.Sqrt(1.0 + row0[0] - row1[1] - row2[2]);
|
||||
|
||||
q.X = (float)(0.25 * sq);
|
||||
sq = 1.0 / sq;
|
||||
q.W = (float)((row2[1] - row1[2]) * sq);
|
||||
q.Y = (float)((row1[0] + row0[1]) * sq);
|
||||
q.Z = (float)((row2[0] + row0[2]) * sq);
|
||||
}
|
||||
else if (row1[1] > row2[2])
|
||||
{
|
||||
double sq = 2.0 * Math.Sqrt(1.0 + row1[1] - row0[0] - row2[2]);
|
||||
|
||||
q.Y = (float)(0.25 * sq);
|
||||
sq = 1.0 / sq;
|
||||
q.W = (float)((row2[0] - row0[2]) * sq);
|
||||
q.X = (float)((row1[0] + row0[1]) * sq);
|
||||
q.Z = (float)((row2[1] + row1[2]) * sq);
|
||||
}
|
||||
else
|
||||
{
|
||||
double sq = 2.0 * Math.Sqrt(1.0 + row2[2] - row0[0] - row1[1]);
|
||||
|
||||
q.Z = (float)(0.25 * sq);
|
||||
sq = 1.0 / sq;
|
||||
q.W = (float)((row1[0] - row0[1]) * sq);
|
||||
q.X = (float)((row2[0] + row0[2]) * sq);
|
||||
q.Y = (float)((row2[1] + row1[2]) * sq);
|
||||
}
|
||||
|
||||
q.Normalize();
|
||||
return q;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static
|
||||
|
||||
#region CreateFromAxisAngle
|
||||
|
||||
/// <summary>
|
||||
/// Build a rotation matrix from the specified axis/angle rotation.
|
||||
/// </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>
|
||||
/// <param name="result">A matrix instance.</param>
|
||||
public static void CreateFromAxisAngle(Vector3 axis, float angle, out Matrix3 result)
|
||||
{
|
||||
//normalize and create a local copy of the vector.
|
||||
axis.Normalize();
|
||||
float axisX = axis.X, axisY = axis.Y, axisZ = axis.Z;
|
||||
|
||||
//calculate angles
|
||||
float cos = (float)System.Math.Cos(-angle);
|
||||
float sin = (float)System.Math.Sin(-angle);
|
||||
float t = 1.0f - cos;
|
||||
|
||||
//do the conversion math once
|
||||
float tXX = t * axisX * axisX,
|
||||
tXY = t * axisX * axisY,
|
||||
tXZ = t * axisX * axisZ,
|
||||
tYY = t * axisY * axisY,
|
||||
tYZ = t * axisY * axisZ,
|
||||
tZZ = t * axisZ * axisZ;
|
||||
|
||||
float sinX = sin * axisX,
|
||||
sinY = sin * axisY,
|
||||
sinZ = sin * axisZ;
|
||||
|
||||
result.Row0.X = tXX + cos;
|
||||
result.Row0.Y = tXY - sinZ;
|
||||
result.Row0.Z = tXZ + sinY;
|
||||
result.Row1.X = tXY + sinZ;
|
||||
result.Row1.Y = tYY + cos;
|
||||
result.Row1.Z = tYZ - sinX;
|
||||
result.Row2.X = tXZ - sinY;
|
||||
result.Row2.Y = tYZ + sinX;
|
||||
result.Row2.Z = tZZ + cos;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build a rotation matrix from the specified axis/angle rotation.
|
||||
/// </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 matrix instance.</returns>
|
||||
public static Matrix3 CreateFromAxisAngle(Vector3 axis, float angle)
|
||||
{
|
||||
Matrix3 result;
|
||||
CreateFromAxisAngle(axis, angle, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateFromQuaternion
|
||||
|
||||
/// <summary>
|
||||
/// Build a rotation matrix from the specified quaternion.
|
||||
/// </summary>
|
||||
/// <param name="q">Quaternion to translate.</param>
|
||||
/// <param name="result">Matrix result.</param>
|
||||
public static void CreateFromQuaternion(ref Quaternion q, out Matrix3 result)
|
||||
{
|
||||
Vector3 axis;
|
||||
float angle;
|
||||
q.ToAxisAngle(out axis, out angle);
|
||||
CreateFromAxisAngle(axis, angle, out result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build a rotation matrix from the specified quaternion.
|
||||
/// </summary>
|
||||
/// <param name="q">Quaternion to translate.</param>
|
||||
/// <returns>A matrix instance.</returns>
|
||||
public static Matrix3 CreateFromQuaternion(Quaternion q)
|
||||
{
|
||||
Matrix3 result;
|
||||
CreateFromQuaternion(ref q, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateRotation[XYZ]
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix for a rotation around the x-axis.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix3 instance.</param>
|
||||
public static void CreateRotationX(float angle, out Matrix3 result)
|
||||
{
|
||||
float cos = (float)System.Math.Cos(angle);
|
||||
float sin = (float)System.Math.Sin(angle);
|
||||
|
||||
result = Identity;
|
||||
result.Row1.Y = cos;
|
||||
result.Row1.Z = sin;
|
||||
result.Row2.Y = -sin;
|
||||
result.Row2.Z = cos;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix for a rotation around the x-axis.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix3 instance.</returns>
|
||||
public static Matrix3 CreateRotationX(float angle)
|
||||
{
|
||||
Matrix3 result;
|
||||
CreateRotationX(angle, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix for a rotation around the y-axis.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix3 instance.</param>
|
||||
public static void CreateRotationY(float angle, out Matrix3 result)
|
||||
{
|
||||
float cos = (float)System.Math.Cos(angle);
|
||||
float sin = (float)System.Math.Sin(angle);
|
||||
|
||||
result = Identity;
|
||||
result.Row0.X = cos;
|
||||
result.Row0.Z = -sin;
|
||||
result.Row2.X = sin;
|
||||
result.Row2.Z = cos;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix for a rotation around the y-axis.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix3 instance.</returns>
|
||||
public static Matrix3 CreateRotationY(float angle)
|
||||
{
|
||||
Matrix3 result;
|
||||
CreateRotationY(angle, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix for a rotation around the z-axis.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix3 instance.</param>
|
||||
public static void CreateRotationZ(float angle, out Matrix3 result)
|
||||
{
|
||||
float cos = (float)System.Math.Cos(angle);
|
||||
float sin = (float)System.Math.Sin(angle);
|
||||
|
||||
result = Identity;
|
||||
result.Row0.X = cos;
|
||||
result.Row0.Y = sin;
|
||||
result.Row1.X = -sin;
|
||||
result.Row1.Y = cos;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix for a rotation around the z-axis.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix3 instance.</returns>
|
||||
public static Matrix3 CreateRotationZ(float angle)
|
||||
{
|
||||
Matrix3 result;
|
||||
CreateRotationZ(angle, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateScale
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x, y, and z axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix3 CreateScale(float scale)
|
||||
{
|
||||
Matrix3 result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x, y, and z axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix3 CreateScale(Vector3 scale)
|
||||
{
|
||||
Matrix3 result;
|
||||
CreateScale(ref scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <param name="z">Scale factor for the z axis.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix3 CreateScale(float x, float y, float z)
|
||||
{
|
||||
Matrix3 result;
|
||||
CreateScale(x, y, z, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x, y, and z axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(float scale, out Matrix3 result)
|
||||
{
|
||||
result = Identity;
|
||||
result.Row0.X = scale;
|
||||
result.Row1.Y = scale;
|
||||
result.Row2.Z = scale;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x, y, and z axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(ref Vector3 scale, out Matrix3 result)
|
||||
{
|
||||
result = Identity;
|
||||
result.Row0.X = scale.X;
|
||||
result.Row1.Y = scale.Y;
|
||||
result.Row2.Z = scale.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <param name="z">Scale factor for the z axis.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(float x, float y, float z, out Matrix3 result)
|
||||
{
|
||||
result = Identity;
|
||||
result.Row0.X = x;
|
||||
result.Row1.Y = y;
|
||||
result.Row2.Z = z;
|
||||
}
|
||||
|
||||
#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 Matrix3 Mult(Matrix3 left, Matrix3 right)
|
||||
{
|
||||
Matrix3 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 Matrix3 left, ref Matrix3 right, out Matrix3 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y, lM33 = left.Row2.Z,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z,
|
||||
rM31 = right.Row2.X, rM32 = right.Row2.Y, rM33 = right.Row2.Z;
|
||||
|
||||
result.Row0.X = ((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31);
|
||||
result.Row0.Y = ((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32);
|
||||
result.Row0.Z = ((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33);
|
||||
result.Row1.X = ((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31);
|
||||
result.Row1.Y = ((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32);
|
||||
result.Row1.Z = ((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33);
|
||||
result.Row2.X = ((lM31 * rM11) + (lM32 * rM21)) + (lM33 * rM31);
|
||||
result.Row2.Y = ((lM31 * rM12) + (lM32 * rM22)) + (lM33 * rM32);
|
||||
result.Row2.Z = ((lM31 * rM13) + (lM32 * rM23)) + (lM33 * rM33);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Invert Functions
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the inverse of the given matrix
|
||||
/// </summary>
|
||||
/// <param name="mat">The matrix to invert</param>
|
||||
/// <param name="result">The inverse of the given matrix if it has one, or the input if it is singular</param>
|
||||
/// <exception cref="InvalidOperationException">Thrown if the Matrix3 is singular.</exception>
|
||||
public static void Invert(ref Matrix3 mat, out Matrix3 result)
|
||||
{
|
||||
int[] colIdx = { 0, 0, 0 };
|
||||
int[] rowIdx = { 0, 0, 0 };
|
||||
int[] pivotIdx = { -1, -1, -1 };
|
||||
|
||||
float[,] inverse = {{mat.Row0.X, mat.Row0.Y, mat.Row0.Z},
|
||||
{mat.Row1.X, mat.Row1.Y, mat.Row1.Z},
|
||||
{mat.Row2.X, mat.Row2.Y, mat.Row2.Z}};
|
||||
|
||||
int icol = 0;
|
||||
int irow = 0;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
float maxPivot = 0.0f;
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
if (pivotIdx[j] != 0)
|
||||
{
|
||||
for (int k = 0; k < 3; ++k)
|
||||
{
|
||||
if (pivotIdx[k] == -1)
|
||||
{
|
||||
float absVal = System.Math.Abs(inverse[j, k]);
|
||||
if (absVal > maxPivot)
|
||||
{
|
||||
maxPivot = absVal;
|
||||
irow = j;
|
||||
icol = k;
|
||||
}
|
||||
}
|
||||
else if (pivotIdx[k] > 0)
|
||||
{
|
||||
result = mat;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
++(pivotIdx[icol]);
|
||||
|
||||
if (irow != icol)
|
||||
{
|
||||
for (int k = 0; k < 3; ++k)
|
||||
{
|
||||
float f = inverse[irow, k];
|
||||
inverse[irow, k] = inverse[icol, k];
|
||||
inverse[icol, k] = f;
|
||||
}
|
||||
}
|
||||
|
||||
rowIdx[i] = irow;
|
||||
colIdx[i] = icol;
|
||||
|
||||
float pivot = inverse[icol, icol];
|
||||
|
||||
if (pivot == 0.0f)
|
||||
{
|
||||
throw new InvalidOperationException("Matrix is singular and cannot be inverted.");
|
||||
}
|
||||
|
||||
float oneOverPivot = 1.0f / pivot;
|
||||
inverse[icol, icol] = 1.0f;
|
||||
for (int k = 0; k < 3; ++k)
|
||||
inverse[icol, k] *= oneOverPivot;
|
||||
|
||||
for (int j = 0; j < 3; ++j)
|
||||
{
|
||||
if (icol != j)
|
||||
{
|
||||
float f = inverse[j, icol];
|
||||
inverse[j, icol] = 0.0f;
|
||||
for (int k = 0; k < 3; ++k)
|
||||
inverse[j, k] -= inverse[icol, k] * f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 2; j >= 0; --j)
|
||||
{
|
||||
int ir = rowIdx[j];
|
||||
int ic = colIdx[j];
|
||||
for (int k = 0; k < 3; ++k)
|
||||
{
|
||||
float f = inverse[k, ir];
|
||||
inverse[k, ir] = inverse[k, ic];
|
||||
inverse[k, ic] = f;
|
||||
}
|
||||
}
|
||||
|
||||
result.Row0.X = inverse[0, 0];
|
||||
result.Row0.Y = inverse[0, 1];
|
||||
result.Row0.Z = inverse[0, 2];
|
||||
result.Row1.X = inverse[1, 0];
|
||||
result.Row1.Y = inverse[1, 1];
|
||||
result.Row1.Z = inverse[1, 2];
|
||||
result.Row2.X = inverse[2, 0];
|
||||
result.Row2.Y = inverse[2, 1];
|
||||
result.Row2.Z = inverse[2, 2];
|
||||
}
|
||||
|
||||
/// <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 Matrix4 is singular.</exception>
|
||||
public static Matrix3 Invert(Matrix3 mat)
|
||||
{
|
||||
Matrix3 result;
|
||||
Invert(ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#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 Matrix3 Transpose(Matrix3 mat)
|
||||
{
|
||||
return new Matrix3(mat.Column0, mat.Column1, mat.Column2);
|
||||
}
|
||||
|
||||
/// <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 Matrix3 mat, out Matrix3 result)
|
||||
{
|
||||
result.Row0.X = mat.Row0.X;
|
||||
result.Row0.Y = mat.Row1.X;
|
||||
result.Row0.Z = mat.Row2.X;
|
||||
result.Row1.X = mat.Row0.Y;
|
||||
result.Row1.Y = mat.Row1.Y;
|
||||
result.Row1.Z = mat.Row2.Y;
|
||||
result.Row2.X = mat.Row0.Z;
|
||||
result.Row2.Y = mat.Row1.Z;
|
||||
result.Row2.Z = mat.Row2.Z;
|
||||
}
|
||||
|
||||
#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 Matrix3d which holds the result of the multiplication</returns>
|
||||
public static Matrix3 operator *(Matrix3 left, Matrix3 right)
|
||||
{
|
||||
return Matrix3.Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left equals right; false otherwise.</returns>
|
||||
public static bool operator ==(Matrix3 left, Matrix3 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left does not equal right; false otherwise.</returns>
|
||||
public static bool operator !=(Matrix3 left, Matrix3 right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Matrix3d.
|
||||
/// </summary>
|
||||
/// <returns>The string representation of the matrix.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0}\n{1}\n{2}", Row0, Row1, Row2);
|
||||
}
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
#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 Matrix3))
|
||||
return false;
|
||||
|
||||
return this.Equals((Matrix3)obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<Matrix3> Members
|
||||
|
||||
/// <summary>Indicates whether the current matrix is equal to another matrix.</summary>
|
||||
/// <param name="other">A 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(Matrix3 other)
|
||||
{
|
||||
return
|
||||
Row0 == other.Row0 &&
|
||||
Row1 == other.Row1 &&
|
||||
Row2 == other.Row2;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
736
Source/OpenTK/Math/Matrix3x2.cs
Normal file
736
Source/OpenTK/Math/Matrix3x2.cs
Normal file
|
@ -0,0 +1,736 @@
|
|||
#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
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a 3x2 matrix.
|
||||
/// </summary>
|
||||
public struct Matrix3x2 : IEquatable<Matrix3x2>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Top row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Row0;
|
||||
|
||||
/// <summary>
|
||||
/// Second row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Row1;
|
||||
|
||||
/// <summary>
|
||||
/// Bottom row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Row2;
|
||||
|
||||
/// <summary>
|
||||
/// The zero matrix.
|
||||
/// </summary>
|
||||
public static readonly Matrix3x2 Zero = new Matrix3x2(Vector2.Zero, Vector2.Zero, Vector2.Zero);
|
||||
|
||||
#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">Bottom row of the matrix.</param>
|
||||
public Matrix3x2(Vector2 row0, Vector2 row1, Vector2 row2)
|
||||
{
|
||||
Row0 = row0;
|
||||
Row1 = row1;
|
||||
Row2 = row2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance
|
||||
/// </summary>
|
||||
/// <param name="m00">First item of the first row of the matrix.</param>
|
||||
/// <param name="m01">Second item of the first row of the matrix.</param>
|
||||
/// <param name="m10">First item of the second row of the matrix.</param>
|
||||
/// <param name="m11">Second item of the second row of the matrix.</param>
|
||||
/// <param name="m20">First item of the third row of the matrix.</param>
|
||||
/// <param name="m21">Second item of the third row of the matrix.</param>
|
||||
public Matrix3x2(
|
||||
float m00, float m01,
|
||||
float m10, float m11,
|
||||
float m20, float m21)
|
||||
{
|
||||
Row0 = new Vector2(m00, m01);
|
||||
Row1 = new Vector2(m10, m11);
|
||||
Row2 = new Vector2(m20, m21);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the first column of this matrix.
|
||||
/// </summary>
|
||||
public Vector3 Column0
|
||||
{
|
||||
get { return new Vector3(Row0.X, Row1.X, Row2.X); }
|
||||
set { Row0.X = value.X; Row1.X = value.Y; Row2.X = value.Z; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the second column of this matrix.
|
||||
/// </summary>
|
||||
public Vector3 Column1
|
||||
{
|
||||
get { return new Vector3(Row0.Y, Row1.Y, Row2.Y); }
|
||||
set { Row0.Y = value.X; Row1.Y = value.Y; Row2.Y = value.Z; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 1, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float 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 float M12 { get { return Row0.Y; } set { Row0.Y = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 2, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float 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 float M22 { get { return Row1.Y; } set { Row1.Y = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 3, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float 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 float M32 { get { return Row2.Y; } set { Row2.Y = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the values along the main diagonal of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Diagonal
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2(Row0.X, Row1.Y);
|
||||
}
|
||||
set
|
||||
{
|
||||
Row0.X = value.X;
|
||||
Row1.Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trace of the matrix, the sum of the values along the diagonal.
|
||||
/// </summary>
|
||||
public float Trace { get { return Row0.X + Row1.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexers
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at a specified row and column.
|
||||
/// </summary>
|
||||
public float this[int rowIndex, int columnIndex]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowIndex == 0) return Row0[columnIndex];
|
||||
else if (rowIndex == 1) return Row1[columnIndex];
|
||||
else if (rowIndex == 2) return Row2[columnIndex];
|
||||
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowIndex == 0) Row0[columnIndex] = value;
|
||||
else if (rowIndex == 1) Row1[columnIndex] = value;
|
||||
else if (rowIndex == 2) Row2[columnIndex] = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Instance
|
||||
#endregion
|
||||
|
||||
#region Static
|
||||
|
||||
#region CreateRotation
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix3x2 instance.</param>
|
||||
public static void CreateRotation(float angle, out Matrix3x2 result)
|
||||
{
|
||||
float cos = (float)System.Math.Cos(angle);
|
||||
float sin = (float)System.Math.Sin(angle);
|
||||
|
||||
result.Row0.X = cos;
|
||||
result.Row0.Y = sin;
|
||||
result.Row1.X = -sin;
|
||||
result.Row1.Y = cos;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix3x2 instance.</returns>
|
||||
public static Matrix3x2 CreateRotation(float angle)
|
||||
{
|
||||
Matrix3x2 result;
|
||||
CreateRotation(angle, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateScale
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x, y, and z axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(float scale, out Matrix3x2 result)
|
||||
{
|
||||
result.Row0.X = scale;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix3x2 CreateScale(float scale)
|
||||
{
|
||||
Matrix3x2 result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(Vector2 scale, out Matrix3x2 result)
|
||||
{
|
||||
result.Row0.X = scale.X;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale.Y;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix3x2 CreateScale(Vector2 scale)
|
||||
{
|
||||
Matrix3x2 result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(float x, float y, out Matrix3x2 result)
|
||||
{
|
||||
result.Row0.X = x;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = y;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix3x2 CreateScale(float x, float y)
|
||||
{
|
||||
Matrix3x2 result;
|
||||
CreateScale(x, y, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Multiply Functions
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix3x2 left, float right, out Matrix3x2 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X * right;
|
||||
result.Row0.Y = left.Row0.Y * right;
|
||||
result.Row1.X = left.Row1.X * right;
|
||||
result.Row1.Y = left.Row1.Y * right;
|
||||
result.Row2.X = left.Row2.X * right;
|
||||
result.Row2.Y = left.Row2.Y * right;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix3x2 Mult(Matrix3x2 left, float right)
|
||||
{
|
||||
Matrix3x2 result;
|
||||
Mult(ref left, 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 Matrix3x2 left, ref Matrix2 right, out Matrix3x2 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row2.X = (lM31 * rM11) + (lM32 * rM21);
|
||||
result.Row2.Y = (lM31 * rM12) + (lM32 * rM22);
|
||||
}
|
||||
|
||||
/// <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 Matrix3x2 Mult(Matrix3x2 left, Matrix2 right)
|
||||
{
|
||||
Matrix3x2 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 Matrix3x2 left, ref Matrix2x3 right, out Matrix3 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row0.Z = (lM11 * rM13) + (lM12 * rM23);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row1.Z = (lM21 * rM13) + (lM22 * rM23);
|
||||
result.Row2.X = (lM31 * rM11) + (lM32 * rM21);
|
||||
result.Row2.Y = (lM31 * rM12) + (lM32 * rM22);
|
||||
result.Row2.Z = (lM31 * rM13) + (lM32 * rM23);
|
||||
}
|
||||
|
||||
/// <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 Matrix3 Mult(Matrix3x2 left, Matrix2x3 right)
|
||||
{
|
||||
Matrix3 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 Matrix3x2 left, ref Matrix2x4 right, out Matrix3x4 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z, rM14 = right.Row0.W,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z, rM24 = right.Row1.W;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row0.Z = (lM11 * rM13) + (lM12 * rM23);
|
||||
result.Row0.W = (lM11 * rM14) + (lM12 * rM24);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row1.Z = (lM21 * rM13) + (lM22 * rM23);
|
||||
result.Row1.W = (lM21 * rM14) + (lM22 * rM24);
|
||||
result.Row2.X = (lM31 * rM11) + (lM32 * rM21);
|
||||
result.Row2.Y = (lM31 * rM12) + (lM32 * rM22);
|
||||
result.Row2.Z = (lM31 * rM13) + (lM32 * rM23);
|
||||
result.Row2.W = (lM31 * rM14) + (lM32 * rM24);
|
||||
}
|
||||
|
||||
/// <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 Matrix3x4 Mult(Matrix3x2 left, Matrix2x4 right)
|
||||
{
|
||||
Matrix3x4 result;
|
||||
Mult(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Add
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <param name="result">A new instance that is the result of the addition.</param>
|
||||
public static void Add(ref Matrix3x2 left, ref Matrix3x2 right, out Matrix3x2 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X + right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y + right.Row0.Y;
|
||||
result.Row1.X = left.Row1.X + right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y + right.Row1.Y;
|
||||
result.Row2.X = left.Row2.X + right.Row2.X;
|
||||
result.Row2.Y = left.Row2.Y + right.Row2.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <returns>A new instance that is the result of the addition.</returns>
|
||||
public static Matrix3x2 Add(Matrix3x2 left, Matrix3x2 right)
|
||||
{
|
||||
Matrix3x2 result;
|
||||
Add(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subtract
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <param name="result">A new instance that is the result of the subtraction.</param>
|
||||
public static void Subtract(ref Matrix3x2 left, ref Matrix3x2 right, out Matrix3x2 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X - right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y - right.Row0.Y;
|
||||
result.Row1.X = left.Row1.X - right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y - right.Row1.Y;
|
||||
result.Row2.X = left.Row2.X - right.Row2.X;
|
||||
result.Row2.Y = left.Row2.Y - right.Row2.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <returns>A new instance that is the result of the subtraction.</returns>
|
||||
public static Matrix3x2 Subtract(Matrix3x2 left, Matrix3x2 right)
|
||||
{
|
||||
Matrix3x2 result;
|
||||
Subtract(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Transpose
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the transpose of the given matrix.
|
||||
/// </summary>
|
||||
/// <param name="mat">The matrix to transpose.</param>
|
||||
/// <param name="result">The transpose of the given matrix.</param>
|
||||
public static void Transpose(ref Matrix3x2 mat, out Matrix2x3 result)
|
||||
{
|
||||
result.Row0.X = mat.Row0.X;
|
||||
result.Row0.Y = mat.Row1.X;
|
||||
result.Row0.Z = mat.Row2.X;
|
||||
result.Row1.X = mat.Row0.Y;
|
||||
result.Row1.Y = mat.Row1.Y;
|
||||
result.Row1.Z = mat.Row2.Y;
|
||||
}
|
||||
|
||||
/// <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 Matrix2x3 Transpose(Matrix3x2 mat)
|
||||
{
|
||||
Matrix2x3 result;
|
||||
Transpose(ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix3x2 which holds the result of the multiplication</returns>
|
||||
public static Matrix3x2 operator *(float left, Matrix3x2 right)
|
||||
{
|
||||
return Mult(right, left);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix3x2 which holds the result of the multiplication</returns>
|
||||
public static Matrix3x2 operator *(Matrix3x2 left, float right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix3x2 which holds the result of the multiplication</returns>
|
||||
public static Matrix3x2 operator *(Matrix3x2 left, Matrix2 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix3 which holds the result of the multiplication</returns>
|
||||
public static Matrix3 operator *(Matrix3x2 left, Matrix2x3 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix3x4 which holds the result of the multiplication</returns>
|
||||
public static Matrix3x4 operator *(Matrix3x2 left, Matrix2x4 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix addition
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix3x2 which holds the result of the addition</returns>
|
||||
public static Matrix3x2 operator +(Matrix3x2 left, Matrix3x2 right)
|
||||
{
|
||||
return Add(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix subtraction
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix3x2 which holds the result of the subtraction</returns>
|
||||
public static Matrix3x2 operator -(Matrix3x2 left, Matrix3x2 right)
|
||||
{
|
||||
return Subtract(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left equals right; false otherwise.</returns>
|
||||
public static bool operator ==(Matrix3x2 left, Matrix3x2 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left does not equal right; false otherwise.</returns>
|
||||
public static bool operator !=(Matrix3x2 left, Matrix3x2 right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Matrix3d.
|
||||
/// </summary>
|
||||
/// <returns>The string representation of the matrix.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0}\n{1}\n{2}", Row0, Row1, Row2);
|
||||
}
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
#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 Matrix3x2))
|
||||
return false;
|
||||
|
||||
return this.Equals((Matrix3x2)obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<Matrix3x2> 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(Matrix3x2 other)
|
||||
{
|
||||
return
|
||||
Row0 == other.Row0 &&
|
||||
Row1 == other.Row1 &&
|
||||
Row2 == other.Row2;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
736
Source/OpenTK/Math/Matrix3x2d.cs
Normal file
736
Source/OpenTK/Math/Matrix3x2d.cs
Normal file
|
@ -0,0 +1,736 @@
|
|||
#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
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a 3x2 matrix.
|
||||
/// </summary>
|
||||
public struct Matrix3x2d : IEquatable<Matrix3x2d>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Top row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Row0;
|
||||
|
||||
/// <summary>
|
||||
/// Second row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Row1;
|
||||
|
||||
/// <summary>
|
||||
/// Bottom row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Row2;
|
||||
|
||||
/// <summary>
|
||||
/// The zero matrix.
|
||||
/// </summary>
|
||||
public static readonly Matrix3x2d Zero = new Matrix3x2d(Vector2d.Zero, Vector2d.Zero, Vector2d.Zero);
|
||||
|
||||
#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">Bottom row of the matrix.</param>
|
||||
public Matrix3x2d(Vector2d row0, Vector2d row1, Vector2d row2)
|
||||
{
|
||||
Row0 = row0;
|
||||
Row1 = row1;
|
||||
Row2 = row2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance
|
||||
/// </summary>
|
||||
/// <param name="m00">First item of the first row of the matrix.</param>
|
||||
/// <param name="m01">Second item of the first row of the matrix.</param>
|
||||
/// <param name="m10">First item of the second row of the matrix.</param>
|
||||
/// <param name="m11">Second item of the second row of the matrix.</param>
|
||||
/// <param name="m20">First item of the third row of the matrix.</param>
|
||||
/// <param name="m21">Second item of the third row of the matrix.</param>
|
||||
public Matrix3x2d(
|
||||
double m00, double m01,
|
||||
double m10, double m11,
|
||||
double m20, double m21)
|
||||
{
|
||||
Row0 = new Vector2d(m00, m01);
|
||||
Row1 = new Vector2d(m10, m11);
|
||||
Row2 = new Vector2d(m20, m21);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the first column of this matrix.
|
||||
/// </summary>
|
||||
public Vector3d Column0
|
||||
{
|
||||
get { return new Vector3d(Row0.X, Row1.X, Row2.X); }
|
||||
set { Row0.X = value.X; Row1.X = value.Y; Row2.X = value.Z; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the second column of this matrix.
|
||||
/// </summary>
|
||||
public Vector3d Column1
|
||||
{
|
||||
get { return new Vector3d(Row0.Y, Row1.Y, Row2.Y); }
|
||||
set { Row0.Y = value.X; Row1.Y = value.Y; Row2.Y = value.Z; }
|
||||
}
|
||||
|
||||
/// <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 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 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 values along the main diagonal of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Diagonal
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2d(Row0.X, Row1.Y);
|
||||
}
|
||||
set
|
||||
{
|
||||
Row0.X = value.X;
|
||||
Row1.Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trace of the matrix, the sum of the values along the diagonal.
|
||||
/// </summary>
|
||||
public double Trace { get { return Row0.X + Row1.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexers
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at a specified row and column.
|
||||
/// </summary>
|
||||
public double this[int rowIndex, int columnIndex]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowIndex == 0) return Row0[columnIndex];
|
||||
else if (rowIndex == 1) return Row1[columnIndex];
|
||||
else if (rowIndex == 2) return Row2[columnIndex];
|
||||
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowIndex == 0) Row0[columnIndex] = value;
|
||||
else if (rowIndex == 1) Row1[columnIndex] = value;
|
||||
else if (rowIndex == 2) Row2[columnIndex] = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Instance
|
||||
#endregion
|
||||
|
||||
#region Static
|
||||
|
||||
#region CreateRotation
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix3x2d instance.</param>
|
||||
public static void CreateRotation(double angle, out Matrix3x2d result)
|
||||
{
|
||||
double cos = System.Math.Cos(angle);
|
||||
double sin = System.Math.Sin(angle);
|
||||
|
||||
result.Row0.X = cos;
|
||||
result.Row0.Y = sin;
|
||||
result.Row1.X = -sin;
|
||||
result.Row1.Y = cos;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix3x2d instance.</returns>
|
||||
public static Matrix3x2d CreateRotation(double angle)
|
||||
{
|
||||
Matrix3x2d result;
|
||||
CreateRotation(angle, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateScale
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x, y, and z axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(double scale, out Matrix3x2d result)
|
||||
{
|
||||
result.Row0.X = scale;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix3x2d CreateScale(double scale)
|
||||
{
|
||||
Matrix3x2d result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(Vector2d scale, out Matrix3x2d result)
|
||||
{
|
||||
result.Row0.X = scale.X;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale.Y;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix3x2d CreateScale(Vector2d scale)
|
||||
{
|
||||
Matrix3x2d result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(double x, double y, out Matrix3x2d result)
|
||||
{
|
||||
result.Row0.X = x;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = y;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix3x2d CreateScale(double x, double y)
|
||||
{
|
||||
Matrix3x2d result;
|
||||
CreateScale(x, y, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Multiply Functions
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix3x2d left, double right, out Matrix3x2d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X * right;
|
||||
result.Row0.Y = left.Row0.Y * right;
|
||||
result.Row1.X = left.Row1.X * right;
|
||||
result.Row1.Y = left.Row1.Y * right;
|
||||
result.Row2.X = left.Row2.X * right;
|
||||
result.Row2.Y = left.Row2.Y * right;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix3x2d Mult(Matrix3x2d left, double right)
|
||||
{
|
||||
Matrix3x2d result;
|
||||
Mult(ref left, 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 Matrix3x2d left, ref Matrix2d right, out Matrix3x2d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row2.X = (lM31 * rM11) + (lM32 * rM21);
|
||||
result.Row2.Y = (lM31 * rM12) + (lM32 * rM22);
|
||||
}
|
||||
|
||||
/// <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 Matrix3x2d Mult(Matrix3x2d left, Matrix2d right)
|
||||
{
|
||||
Matrix3x2d 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 Matrix3x2d left, ref Matrix2x3d right, out Matrix3d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row0.Z = (lM11 * rM13) + (lM12 * rM23);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row1.Z = (lM21 * rM13) + (lM22 * rM23);
|
||||
result.Row2.X = (lM31 * rM11) + (lM32 * rM21);
|
||||
result.Row2.Y = (lM31 * rM12) + (lM32 * rM22);
|
||||
result.Row2.Z = (lM31 * rM13) + (lM32 * rM23);
|
||||
}
|
||||
|
||||
/// <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 Matrix3d Mult(Matrix3x2d left, Matrix2x3d right)
|
||||
{
|
||||
Matrix3d 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 Matrix3x2d left, ref Matrix2x4d right, out Matrix3x4d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z, rM14 = right.Row0.W,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z, rM24 = right.Row1.W;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row0.Z = (lM11 * rM13) + (lM12 * rM23);
|
||||
result.Row0.W = (lM11 * rM14) + (lM12 * rM24);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row1.Z = (lM21 * rM13) + (lM22 * rM23);
|
||||
result.Row1.W = (lM21 * rM14) + (lM22 * rM24);
|
||||
result.Row2.X = (lM31 * rM11) + (lM32 * rM21);
|
||||
result.Row2.Y = (lM31 * rM12) + (lM32 * rM22);
|
||||
result.Row2.Z = (lM31 * rM13) + (lM32 * rM23);
|
||||
result.Row2.W = (lM31 * rM14) + (lM32 * rM24);
|
||||
}
|
||||
|
||||
/// <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 Matrix3x4d Mult(Matrix3x2d left, Matrix2x4d right)
|
||||
{
|
||||
Matrix3x4d result;
|
||||
Mult(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Add
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <param name="result">A new instance that is the result of the addition.</param>
|
||||
public static void Add(ref Matrix3x2d left, ref Matrix3x2d right, out Matrix3x2d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X + right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y + right.Row0.Y;
|
||||
result.Row1.X = left.Row1.X + right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y + right.Row1.Y;
|
||||
result.Row2.X = left.Row2.X + right.Row2.X;
|
||||
result.Row2.Y = left.Row2.Y + right.Row2.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <returns>A new instance that is the result of the addition.</returns>
|
||||
public static Matrix3x2d Add(Matrix3x2d left, Matrix3x2d right)
|
||||
{
|
||||
Matrix3x2d result;
|
||||
Add(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subtract
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <param name="result">A new instance that is the result of the subtraction.</param>
|
||||
public static void Subtract(ref Matrix3x2d left, ref Matrix3x2d right, out Matrix3x2d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X - right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y - right.Row0.Y;
|
||||
result.Row1.X = left.Row1.X - right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y - right.Row1.Y;
|
||||
result.Row2.X = left.Row2.X - right.Row2.X;
|
||||
result.Row2.Y = left.Row2.Y - right.Row2.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <returns>A new instance that is the result of the subtraction.</returns>
|
||||
public static Matrix3x2d Subtract(Matrix3x2d left, Matrix3x2d right)
|
||||
{
|
||||
Matrix3x2d result;
|
||||
Subtract(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Transpose
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the transpose of the given matrix.
|
||||
/// </summary>
|
||||
/// <param name="mat">The matrix to transpose.</param>
|
||||
/// <param name="result">The transpose of the given matrix.</param>
|
||||
public static void Transpose(ref Matrix3x2d mat, out Matrix2x3d result)
|
||||
{
|
||||
result.Row0.X = mat.Row0.X;
|
||||
result.Row0.Y = mat.Row1.X;
|
||||
result.Row0.Z = mat.Row2.X;
|
||||
result.Row1.X = mat.Row0.Y;
|
||||
result.Row1.Y = mat.Row1.Y;
|
||||
result.Row1.Z = mat.Row2.Y;
|
||||
}
|
||||
|
||||
/// <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 Matrix2x3d Transpose(Matrix3x2d mat)
|
||||
{
|
||||
Matrix2x3d result;
|
||||
Transpose(ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix3x2d which holds the result of the multiplication</returns>
|
||||
public static Matrix3x2d operator *(double left, Matrix3x2d right)
|
||||
{
|
||||
return Mult(right, left);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix3x2d which holds the result of the multiplication</returns>
|
||||
public static Matrix3x2d operator *(Matrix3x2d left, double right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix3x2d which holds the result of the multiplication</returns>
|
||||
public static Matrix3x2d operator *(Matrix3x2d left, Matrix2d right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix3d which holds the result of the multiplication</returns>
|
||||
public static Matrix3d operator *(Matrix3x2d left, Matrix2x3d right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix3x4 which holds the result of the multiplication</returns>
|
||||
public static Matrix3x4d operator *(Matrix3x2d left, Matrix2x4d right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix addition
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix3x2d which holds the result of the addition</returns>
|
||||
public static Matrix3x2d operator +(Matrix3x2d left, Matrix3x2d right)
|
||||
{
|
||||
return Add(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix subtraction
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix3x2d which holds the result of the subtraction</returns>
|
||||
public static Matrix3x2d operator -(Matrix3x2d left, Matrix3x2d right)
|
||||
{
|
||||
return Subtract(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left equals right; false otherwise.</returns>
|
||||
public static bool operator ==(Matrix3x2d left, Matrix3x2d right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left does not equal right; false otherwise.</returns>
|
||||
public static bool operator !=(Matrix3x2d left, Matrix3x2d right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Matrix3d.
|
||||
/// </summary>
|
||||
/// <returns>The string representation of the matrix.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0}\n{1}\n{2}", Row0, Row1, Row2);
|
||||
}
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
#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 Matrix3x2d))
|
||||
return false;
|
||||
|
||||
return this.Equals((Matrix3x2d)obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<Matrix3x2d> 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(Matrix3x2d other)
|
||||
{
|
||||
return
|
||||
Row0 == other.Row0 &&
|
||||
Row1 == other.Row1 &&
|
||||
Row2 == other.Row2;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
1000
Source/OpenTK/Math/Matrix3x4.cs
Normal file
1000
Source/OpenTK/Math/Matrix3x4.cs
Normal file
File diff suppressed because it is too large
Load diff
1000
Source/OpenTK/Math/Matrix3x4d.cs
Normal file
1000
Source/OpenTK/Math/Matrix3x4d.cs
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -28,8 +28,9 @@ using System.Runtime.InteropServices;
|
|||
namespace OpenTK
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a 4x4 Matrix with double-precision components.
|
||||
/// Represents a 4x4 matrix containing 3D rotation, scale, transform, and projection with double-precision components.
|
||||
/// </summary>
|
||||
/// <seealso cref="Matrix4"/>
|
||||
[Serializable]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Matrix4d : IEquatable<Matrix4d>
|
||||
|
@ -137,6 +138,7 @@ namespace OpenTK
|
|||
public Vector4d Column0
|
||||
{
|
||||
get { return new Vector4d (Row0.X, Row1.X, Row2.X, Row3.X); }
|
||||
set { Row0.X = value.X; Row1.X = value.Y; Row2.X = value.Z; Row3.X = value.W; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -145,6 +147,7 @@ namespace OpenTK
|
|||
public Vector4d Column1
|
||||
{
|
||||
get { return new Vector4d (Row0.Y, Row1.Y, Row2.Y, Row3.Y); }
|
||||
set { Row0.Y = value.X; Row1.Y = value.Y; Row2.Y = value.Z; Row3.Y = value.W; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -153,6 +156,7 @@ namespace OpenTK
|
|||
public Vector4d Column2
|
||||
{
|
||||
get { return new Vector4d (Row0.Z, Row1.Z, Row2.Z, Row3.Z); }
|
||||
set { Row0.Z = value.X; Row1.Z = value.Y; Row2.Z = value.Z; Row3.Z = value.W; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -161,6 +165,7 @@ namespace OpenTK
|
|||
public Vector4d Column3
|
||||
{
|
||||
get { return new Vector4d (Row0.W, Row1.W, Row2.W, Row3.W); }
|
||||
set { Row0.W = value.X; Row1.W = value.Y; Row2.W = value.Z; Row3.W = value.W; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -243,6 +248,56 @@ namespace OpenTK
|
|||
/// </summary>
|
||||
public double M44 { get { return Row3.W; } set { Row3.W = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the values along the main diagonal of the matrix.
|
||||
/// </summary>
|
||||
public Vector4d Diagonal
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector4d(Row0.X, Row1.Y, Row2.Z, Row3.W);
|
||||
}
|
||||
set
|
||||
{
|
||||
Row0.X = value.X;
|
||||
Row1.Y = value.Y;
|
||||
Row2.Z = value.Z;
|
||||
Row3.W = value.W;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trace of the matrix, the sum of the values along the diagonal.
|
||||
/// </summary>
|
||||
public double Trace { get { return Row0.X + Row1.Y + Row2.Z + Row3.W; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexers
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at a specified row and column.
|
||||
/// </summary>
|
||||
public double this[int rowIndex, int columnIndex]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowIndex == 0) return Row0[columnIndex];
|
||||
else if (rowIndex == 1) return Row1[columnIndex];
|
||||
else if (rowIndex == 2) return Row2[columnIndex];
|
||||
else if (rowIndex == 3) return Row3[columnIndex];
|
||||
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowIndex == 0) Row0[columnIndex] = value;
|
||||
else if (rowIndex == 1) Row1[columnIndex] = value;
|
||||
else if (rowIndex == 2) Row2[columnIndex] = value;
|
||||
else if (rowIndex == 3) Row3[columnIndex] = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Instance
|
||||
|
@ -271,6 +326,166 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Returns a normalised copy of this instance.
|
||||
/// </summary>
|
||||
public Matrix4d Normalized()
|
||||
{
|
||||
Matrix4d m = this;
|
||||
m.Normalize();
|
||||
return m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Divides each element in the Matrix by the <see cref="Determinant"/>.
|
||||
/// </summary>
|
||||
public void Normalize()
|
||||
{
|
||||
var determinant = this.Determinant;
|
||||
Row0 /= determinant;
|
||||
Row1 /= determinant;
|
||||
Row2 /= determinant;
|
||||
Row3 /= determinant;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an inverted copy of this instance.
|
||||
/// </summary>
|
||||
public Matrix4d Inverted()
|
||||
{
|
||||
Matrix4d m = this;
|
||||
if (m.Determinant != 0)
|
||||
m.Invert();
|
||||
return m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of this Matrix4d without translation.
|
||||
/// </summary>
|
||||
public Matrix4d ClearTranslation()
|
||||
{
|
||||
Matrix4d m = this;
|
||||
m.Row3.Xyz = Vector3d.Zero;
|
||||
return m;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a copy of this Matrix4d without scale.
|
||||
/// </summary>
|
||||
public Matrix4d ClearScale()
|
||||
{
|
||||
Matrix4d m = this;
|
||||
m.Row0.Xyz = m.Row0.Xyz.Normalized();
|
||||
m.Row1.Xyz = m.Row1.Xyz.Normalized();
|
||||
m.Row2.Xyz = m.Row2.Xyz.Normalized();
|
||||
return m;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a copy of this Matrix4d without rotation.
|
||||
/// </summary>
|
||||
public Matrix4d ClearRotation()
|
||||
{
|
||||
Matrix4d m = this;
|
||||
m.Row0.Xyz = new Vector3d(m.Row0.Xyz.Length, 0, 0);
|
||||
m.Row1.Xyz = new Vector3d(0, m.Row1.Xyz.Length, 0);
|
||||
m.Row2.Xyz = new Vector3d(0, 0, m.Row2.Xyz.Length);
|
||||
return m;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a copy of this Matrix4d without projection.
|
||||
/// </summary>
|
||||
public Matrix4d ClearProjection()
|
||||
{
|
||||
Matrix4d m = this;
|
||||
m.Column3 = Vector4d.Zero;
|
||||
return m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the translation component of this instance.
|
||||
/// </summary>
|
||||
public Vector3d ExtractTranslation() { return Row3.Xyz; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the scale component of this instance.
|
||||
/// </summary>
|
||||
public Vector3d ExtractScale() { return new Vector3d(Row0.Xyz.Length, Row1.Xyz.Length, Row2.Xyz.Length); }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the rotation component of this instance. Quite slow.
|
||||
/// </summary>
|
||||
/// <param name="row_normalise">Whether the method should row-normalise (i.e. remove scale from) the Matrix. Pass false if you know it's already normalised.</param>
|
||||
public Quaterniond ExtractRotation(bool row_normalise = true)
|
||||
{
|
||||
var row0 = Row0.Xyz;
|
||||
var row1 = Row1.Xyz;
|
||||
var row2 = Row2.Xyz;
|
||||
|
||||
if (row_normalise)
|
||||
{
|
||||
row0 = row0.Normalized();
|
||||
row1 = row1.Normalized();
|
||||
row2 = row2.Normalized();
|
||||
}
|
||||
|
||||
// code below adapted from Blender
|
||||
|
||||
Quaterniond q = new Quaterniond();
|
||||
double trace = 0.25 * (row0[0] + row1[1] + row2[2] + 1.0);
|
||||
|
||||
if (trace > 0)
|
||||
{
|
||||
double sq = Math.Sqrt(trace);
|
||||
|
||||
q.W = sq;
|
||||
sq = 1.0 / (4.0 * sq);
|
||||
q.X = (row1[2] - row2[1]) * sq;
|
||||
q.Y = (row2[0] - row0[2]) * sq;
|
||||
q.Z = (row0[1] - row1[0]) * sq;
|
||||
}
|
||||
else if (row0[0] > row1[1] && row0[0] > row2[2])
|
||||
{
|
||||
double sq = 2.0 * Math.Sqrt(1.0 + row0[0] - row1[1] - row2[2]);
|
||||
|
||||
q.X = 0.25 * sq;
|
||||
sq = 1.0 / sq;
|
||||
q.W = (row2[1] - row1[2]) * sq;
|
||||
q.Y = (row1[0] + row0[1]) * sq;
|
||||
q.Z = (row2[0] + row0[2]) * sq;
|
||||
}
|
||||
else if (row1[1] > row2[2])
|
||||
{
|
||||
double sq = 2.0 * Math.Sqrt(1.0 + row1[1] - row0[0] - row2[2]);
|
||||
|
||||
q.Y = 0.25 * sq;
|
||||
sq = 1.0 / sq;
|
||||
q.W = (row2[0] - row0[2]) * sq;
|
||||
q.X = (row1[0] + row0[1]) * sq;
|
||||
q.Z = (row2[1] + row1[2]) * sq;
|
||||
}
|
||||
else
|
||||
{
|
||||
double sq = 2.0 * Math.Sqrt(1.0 + row2[2] - row0[0] - row1[1]);
|
||||
|
||||
q.Z = 0.25 * sq;
|
||||
sq = 1.0 / sq;
|
||||
q.W = (row1[0] - row0[1]) * sq;
|
||||
q.X = (row2[0] + row0[2]) * sq;
|
||||
q.Y = (row2[1] + row1[2]) * sq;
|
||||
}
|
||||
|
||||
q.Normalize();
|
||||
return q;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the projection component of this instance.
|
||||
/// </summary>
|
||||
public Vector4d ExtractProjection()
|
||||
{
|
||||
return Column3;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static
|
||||
|
@ -318,7 +533,7 @@ namespace OpenTK
|
|||
/// Builds a rotation matrix for a rotation around the x-axis.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix4 instance.</param>
|
||||
/// <param name="result">The resulting Matrix4d instance.</param>
|
||||
public static void CreateRotationX(double angle, out Matrix4d result)
|
||||
{
|
||||
double cos = System.Math.Cos(angle);
|
||||
|
@ -334,7 +549,7 @@ namespace OpenTK
|
|||
/// Builds a rotation matrix for a rotation around the x-axis.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix4 instance.</returns>
|
||||
/// <returns>The resulting Matrix4d instance.</returns>
|
||||
public static Matrix4d CreateRotationX(double angle)
|
||||
{
|
||||
Matrix4d result;
|
||||
|
@ -346,7 +561,7 @@ namespace OpenTK
|
|||
/// Builds a rotation matrix for a rotation around the y-axis.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix4 instance.</param>
|
||||
/// <param name="result">The resulting Matrix4d instance.</param>
|
||||
public static void CreateRotationY(double angle, out Matrix4d result)
|
||||
{
|
||||
double cos = System.Math.Cos(angle);
|
||||
|
@ -362,7 +577,7 @@ namespace OpenTK
|
|||
/// Builds a rotation matrix for a rotation around the y-axis.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix4 instance.</returns>
|
||||
/// <returns>The resulting Matrix4d instance.</returns>
|
||||
public static Matrix4d CreateRotationY(double angle)
|
||||
{
|
||||
Matrix4d result;
|
||||
|
@ -374,7 +589,7 @@ namespace OpenTK
|
|||
/// Builds a rotation matrix for a rotation around the z-axis.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix4 instance.</param>
|
||||
/// <param name="result">The resulting Matrix4d instance.</param>
|
||||
public static void CreateRotationZ(double angle, out Matrix4d result)
|
||||
{
|
||||
double cos = System.Math.Cos(angle);
|
||||
|
@ -390,7 +605,7 @@ namespace OpenTK
|
|||
/// Builds a rotation matrix for a rotation around the z-axis.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix4 instance.</returns>
|
||||
/// <returns>The resulting Matrix4d instance.</returns>
|
||||
public static Matrix4d CreateRotationZ(double angle)
|
||||
{
|
||||
Matrix4d result;
|
||||
|
@ -670,6 +885,80 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region CreateFromQuaternion
|
||||
/// <summary>
|
||||
/// Build a rotation matrix from the specified quaternion.
|
||||
/// </summary>
|
||||
/// <param name="q">Quaternion to translate.</param>
|
||||
/// <param name="m">Matrix result.</param>
|
||||
public static void CreateFromQuaternion(ref Quaternion q,ref Matrix4 m)
|
||||
{
|
||||
m = Matrix4.Identity;
|
||||
|
||||
float X = q.X;
|
||||
float Y = q.Y;
|
||||
float Z = q.Z;
|
||||
float W = q.W;
|
||||
|
||||
float xx = X * X;
|
||||
float xy = X * Y;
|
||||
float xz = X * Z;
|
||||
float xw = X * W;
|
||||
float yy = Y * Y;
|
||||
float yz = Y * Z;
|
||||
float yw = Y * W;
|
||||
float zz = Z * Z;
|
||||
float zw = Z * W;
|
||||
|
||||
m.M11 = 1 - 2 * (yy + zz);
|
||||
m.M21 = 2 * (xy - zw);
|
||||
m.M31 = 2 * (xz + yw);
|
||||
m.M12 = 2 * (xy + zw);
|
||||
m.M22 = 1 - 2 * (xx + zz);
|
||||
m.M32 = 2 * (yz - xw);
|
||||
m.M13 = 2 * (xz - yw);
|
||||
m.M23 = 2 * (yz + xw);
|
||||
m.M33 = 1 - 2 * (xx + yy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build a rotation matrix from the specified quaternion.
|
||||
/// </summary>
|
||||
/// <param name="q">Quaternion to translate.</param>
|
||||
/// <returns>A matrix instance.</returns>
|
||||
public static Matrix4 CreateFromQuaternion(ref Quaternion q)
|
||||
{
|
||||
Matrix4 result = Matrix4.Identity;
|
||||
|
||||
float X = q.X;
|
||||
float Y = q.Y;
|
||||
float Z = q.Z;
|
||||
float W = q.W;
|
||||
|
||||
float xx = X * X;
|
||||
float xy = X * Y;
|
||||
float xz = X * Z;
|
||||
float xw = X * W;
|
||||
float yy = Y * Y;
|
||||
float yz = Y * Z;
|
||||
float yw = Y * W;
|
||||
float zz = Z * Z;
|
||||
float zw = Z * W;
|
||||
|
||||
result.M11 = 1 - 2 * (yy + zz);
|
||||
result.M21 = 2 * (xy - zw);
|
||||
result.M31 = 2 * (xz + yw);
|
||||
result.M12 = 2 * (xy + zw);
|
||||
result.M22 = 1 - 2 * (xx + zz);
|
||||
result.M32 = 2 * (yz - xw);
|
||||
result.M13 = 2 * (xz - yw);
|
||||
result.M23 = 2 * (yz + xw);
|
||||
result.M33 = 1 - 2 * (xx + yy);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Obsolete Functions
|
||||
|
||||
#region Translation Functions
|
||||
|
@ -922,6 +1211,68 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region Add Functions
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <returns>A new instance that is the result of the addition.</returns>
|
||||
public static Matrix4d Add(Matrix4d left, Matrix4d right)
|
||||
{
|
||||
Matrix4d result;
|
||||
Add(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <param name="result">A new instance that is the result of the addition.</param>
|
||||
public static void Add(ref Matrix4d left, ref Matrix4d right, out Matrix4d result)
|
||||
{
|
||||
result.Row0 = left.Row0 + right.Row0;
|
||||
result.Row1 = left.Row1 + right.Row1;
|
||||
result.Row2 = left.Row2 + right.Row2;
|
||||
result.Row3 = left.Row3 + right.Row3;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subtract Functions
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts one instance from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subraction.</param>
|
||||
/// <param name="right">The right operand of the subraction.</param>
|
||||
/// <returns>A new instance that is the result of the subraction.</returns>
|
||||
public static Matrix4d Subtract(Matrix4d left, Matrix4d right)
|
||||
{
|
||||
Matrix4d result;
|
||||
Subtract(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts one instance from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subraction.</param>
|
||||
/// <param name="right">The right operand of the subraction.</param>
|
||||
/// <param name="result">A new instance that is the result of the subraction.</param>
|
||||
public static void Subtract(ref Matrix4d left, ref Matrix4d right, out Matrix4d result)
|
||||
{
|
||||
result.Row0 = left.Row0 - right.Row0;
|
||||
result.Row1 = left.Row1 - right.Row1;
|
||||
result.Row2 = left.Row2 - right.Row2;
|
||||
result.Row3 = left.Row3 - right.Row3;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Multiply Functions
|
||||
|
||||
/// <summary>
|
||||
|
@ -972,6 +1323,33 @@ namespace OpenTK
|
|||
result.Row3.W = (((lM41 * rM14) + (lM42 * rM24)) + (lM43 * rM34)) + (lM44 * rM44);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies an instance by a scalar.
|
||||
/// </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, double right)
|
||||
{
|
||||
Matrix4d result;
|
||||
Mult(ref left, right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies an instance by a scalar.
|
||||
/// </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, double right, out Matrix4d result)
|
||||
{
|
||||
result.Row0 = left.Row0 * right;
|
||||
result.Row1 = left.Row1 * right;
|
||||
result.Row2 = left.Row2 * right;
|
||||
result.Row3 = left.Row3 * right;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Invert Functions
|
||||
|
@ -1125,12 +1503,45 @@ namespace OpenTK
|
|||
/// </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>
|
||||
/// <returns>A new Matrix4d which holds the result of the multiplication</returns>
|
||||
public static Matrix4d operator *(Matrix4d left, Matrix4d right)
|
||||
{
|
||||
return Matrix4d.Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix-scalar multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4d which holds the result of the multiplication</returns>
|
||||
public static Matrix4d operator *(Matrix4d left, float right)
|
||||
{
|
||||
return Matrix4d.Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix addition
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4d which holds the result of the addition</returns>
|
||||
public static Matrix4d operator +(Matrix4d left, Matrix4d right)
|
||||
{
|
||||
return Matrix4d.Add(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix subtraction
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4d which holds the result of the subtraction</returns>
|
||||
public static Matrix4d operator -(Matrix4d left, Matrix4d right)
|
||||
{
|
||||
return Matrix4d.Subtract(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for equality.
|
||||
/// </summary>
|
||||
|
@ -1207,7 +1618,7 @@ namespace OpenTK
|
|||
#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>
|
||||
/// <param name="other">A 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)
|
||||
{
|
||||
|
|
786
Source/OpenTK/Math/Matrix4x2.cs
Normal file
786
Source/OpenTK/Math/Matrix4x2.cs
Normal file
|
@ -0,0 +1,786 @@
|
|||
#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
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a 4x2 matrix.
|
||||
/// </summary>
|
||||
public struct Matrix4x2 : IEquatable<Matrix4x2>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Top row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Row0;
|
||||
|
||||
/// <summary>
|
||||
/// Second row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Row1;
|
||||
|
||||
/// <summary>
|
||||
/// Third row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Row2;
|
||||
|
||||
/// <summary>
|
||||
/// Bottom row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Row3;
|
||||
|
||||
/// <summary>
|
||||
/// The zero matrix.
|
||||
/// </summary>
|
||||
public static readonly Matrix4x2 Zero = new Matrix4x2(Vector2.Zero, Vector2.Zero, Vector2.Zero, Vector2.Zero);
|
||||
|
||||
#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 Matrix4x2(Vector2 row0, Vector2 row1, Vector2 row2, Vector2 row3)
|
||||
{
|
||||
Row0 = row0;
|
||||
Row1 = row1;
|
||||
Row2 = row2;
|
||||
Row3 = row3;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance
|
||||
/// </summary>
|
||||
/// <param name="m00">First item of the first row of the matrix.</param>
|
||||
/// <param name="m01">Second item of the first row of the matrix.</param>
|
||||
/// <param name="m10">First item of the second row of the matrix.</param>
|
||||
/// <param name="m11">Second item of the second row of the matrix.</param>
|
||||
/// <param name="m20">First item of the third row of the matrix.</param>
|
||||
/// <param name="m21">Second item of the third row of the matrix.</param>
|
||||
/// <param name="m30">First item of the fourth row of the matrix.</param>
|
||||
/// <param name="m31">Second item of the fourth row of the matrix.</param>
|
||||
public Matrix4x2(
|
||||
float m00, float m01,
|
||||
float m10, float m11,
|
||||
float m20, float m21,
|
||||
float m30, float m31)
|
||||
{
|
||||
Row0 = new Vector2(m00, m01);
|
||||
Row1 = new Vector2(m10, m11);
|
||||
Row2 = new Vector2(m20, m21);
|
||||
Row3 = new Vector2(m30, m31);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the first column of this matrix.
|
||||
/// </summary>
|
||||
public Vector4 Column0
|
||||
{
|
||||
get { return new Vector4(Row0.X, Row1.X, Row2.X, Row3.X); }
|
||||
set { Row0.X = value.X; Row1.X = value.Y; Row2.X = value.Z; Row3.X = value.W; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the second column of this matrix.
|
||||
/// </summary>
|
||||
public Vector4 Column1
|
||||
{
|
||||
get { return new Vector4(Row0.Y, Row1.Y, Row2.Y, Row3.X); }
|
||||
set { Row0.Y = value.X; Row1.Y = value.Y; Row2.Y = value.Z; Row3.Y = value.W; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 1, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float 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 float M12 { get { return Row0.Y; } set { Row0.Y = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 2, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float 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 float M22 { get { return Row1.Y; } set { Row1.Y = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 3, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float 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 float M32 { get { return Row2.Y; } set { Row2.Y = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 4, column 1 of this instance.
|
||||
/// </summary>
|
||||
public float M41 { get { return Row3.X; } set { Row3.X = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at row 4, column 2 of this instance.
|
||||
/// </summary>
|
||||
public float M42 { get { return Row3.Y; } set { Row3.Y = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the values along the main diagonal of the matrix.
|
||||
/// </summary>
|
||||
public Vector2 Diagonal
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2(Row0.X, Row1.Y);
|
||||
}
|
||||
set
|
||||
{
|
||||
Row0.X = value.X;
|
||||
Row1.Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trace of the matrix, the sum of the values along the diagonal.
|
||||
/// </summary>
|
||||
public float Trace { get { return Row0.X + Row1.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexers
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at a specified row and column.
|
||||
/// </summary>
|
||||
public float this[int rowIndex, int columnIndex]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowIndex == 0) return Row0[columnIndex];
|
||||
else if (rowIndex == 1) return Row1[columnIndex];
|
||||
else if (rowIndex == 2) return Row2[columnIndex];
|
||||
else if (rowIndex == 3) return Row3[columnIndex];
|
||||
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowIndex == 0) Row0[columnIndex] = value;
|
||||
else if (rowIndex == 1) Row1[columnIndex] = value;
|
||||
else if (rowIndex == 2) Row2[columnIndex] = value;
|
||||
else if (rowIndex == 3) Row3[columnIndex] = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static
|
||||
|
||||
#region CreateRotation
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix3x2 instance.</param>
|
||||
public static void CreateRotation(float angle, out Matrix4x2 result)
|
||||
{
|
||||
float cos = (float)System.Math.Cos(angle);
|
||||
float sin = (float)System.Math.Sin(angle);
|
||||
|
||||
result.Row0.X = cos;
|
||||
result.Row0.Y = sin;
|
||||
result.Row1.X = -sin;
|
||||
result.Row1.Y = cos;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
result.Row3.X = 0;
|
||||
result.Row3.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix3x2 instance.</returns>
|
||||
public static Matrix4x2 CreateRotation(float angle)
|
||||
{
|
||||
Matrix4x2 result;
|
||||
CreateRotation(angle, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateScale
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x, y, and z axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(float scale, out Matrix4x2 result)
|
||||
{
|
||||
result.Row0.X = scale;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
result.Row3.X = 0;
|
||||
result.Row3.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix4x2 CreateScale(float scale)
|
||||
{
|
||||
Matrix4x2 result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(Vector2 scale, out Matrix4x2 result)
|
||||
{
|
||||
result.Row0.X = scale.X;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale.Y;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
result.Row3.X = 0;
|
||||
result.Row3.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix4x2 CreateScale(Vector2 scale)
|
||||
{
|
||||
Matrix4x2 result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(float x, float y, out Matrix4x2 result)
|
||||
{
|
||||
result.Row0.X = x;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = y;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
result.Row3.X = 0;
|
||||
result.Row3.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix4x2 CreateScale(float x, float y)
|
||||
{
|
||||
Matrix4x2 result;
|
||||
CreateScale(x, y, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Multiply Functions
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix4x2 left, float right, out Matrix4x2 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X * right;
|
||||
result.Row0.Y = left.Row0.Y * right;
|
||||
result.Row1.X = left.Row1.X * right;
|
||||
result.Row1.Y = left.Row1.Y * right;
|
||||
result.Row2.X = left.Row2.X * right;
|
||||
result.Row2.Y = left.Row2.Y * right;
|
||||
result.Row3.X = left.Row3.X * right;
|
||||
result.Row3.Y = left.Row3.Y * right;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix4x2 Mult(Matrix4x2 left, float right)
|
||||
{
|
||||
Matrix4x2 result;
|
||||
Mult(ref left, 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 Matrix4x2 left, ref Matrix2 right, out Matrix4x2 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y,
|
||||
lM41 = left.Row3.X, lM42 = left.Row3.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row2.X = (lM31 * rM11) + (lM32 * rM21);
|
||||
result.Row2.Y = (lM31 * rM12) + (lM32 * rM22);
|
||||
result.Row3.X = (lM41 * rM11) + (lM42 * rM21);
|
||||
result.Row3.Y = (lM41 * rM12) + (lM42 * rM22);
|
||||
}
|
||||
|
||||
/// <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 Matrix4x2 Mult(Matrix4x2 left, Matrix2 right)
|
||||
{
|
||||
Matrix4x2 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 Matrix4x2 left, ref Matrix2x3 right, out Matrix4x3 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y,
|
||||
lM41 = left.Row3.X, lM42 = left.Row3.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row0.Z = (lM11 * rM13) + (lM12 * rM23);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row1.Z = (lM21 * rM13) + (lM22 * rM23);
|
||||
result.Row2.X = (lM31 * rM11) + (lM32 * rM21);
|
||||
result.Row2.Y = (lM31 * rM12) + (lM32 * rM22);
|
||||
result.Row2.Z = (lM31 * rM13) + (lM32 * rM23);
|
||||
result.Row3.X = (lM41 * rM11) + (lM42 * rM21);
|
||||
result.Row3.Y = (lM41 * rM12) + (lM42 * rM22);
|
||||
result.Row3.Z = (lM41 * rM13) + (lM42 * rM23);
|
||||
}
|
||||
|
||||
/// <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 Matrix4x3 Mult(Matrix4x2 left, Matrix2x3 right)
|
||||
{
|
||||
Matrix4x3 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 Matrix4x2 left, ref Matrix2x4 right, out Matrix4 result)
|
||||
{
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y,
|
||||
lM41 = left.Row3.X, lM42 = left.Row3.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z, rM14 = right.Row0.W,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z, rM24 = right.Row1.W;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row0.Z = (lM11 * rM13) + (lM12 * rM23);
|
||||
result.Row0.W = (lM11 * rM14) + (lM12 * rM24);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row1.Z = (lM21 * rM13) + (lM22 * rM23);
|
||||
result.Row1.W = (lM21 * rM14) + (lM22 * rM24);
|
||||
result.Row2.X = (lM31 * rM11) + (lM32 * rM21);
|
||||
result.Row2.Y = (lM31 * rM12) + (lM32 * rM22);
|
||||
result.Row2.Z = (lM31 * rM13) + (lM32 * rM23);
|
||||
result.Row2.W = (lM31 * rM14) + (lM32 * rM24);
|
||||
result.Row3.X = (lM41 * rM11) + (lM42 * rM21);
|
||||
result.Row3.Y = (lM41 * rM12) + (lM42 * rM22);
|
||||
result.Row3.Z = (lM41 * rM13) + (lM42 * rM23);
|
||||
result.Row3.W = (lM41 * rM14) + (lM42 * rM24);
|
||||
}
|
||||
|
||||
/// <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 Matrix4 Mult(Matrix4x2 left, Matrix2x4 right)
|
||||
{
|
||||
Matrix4 result;
|
||||
Mult(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Add
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <param name="result">A new instance that is the result of the addition.</param>
|
||||
public static void Add(ref Matrix4x2 left, ref Matrix4x2 right, out Matrix4x2 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X + right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y + right.Row0.Y;
|
||||
result.Row1.X = left.Row1.X + right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y + right.Row1.Y;
|
||||
result.Row2.X = left.Row2.X + right.Row2.X;
|
||||
result.Row2.Y = left.Row2.Y + right.Row2.Y;
|
||||
result.Row3.X = left.Row3.X + right.Row3.X;
|
||||
result.Row3.Y = left.Row3.Y + right.Row3.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <returns>A new instance that is the result of the addition.</returns>
|
||||
public static Matrix4x2 Add(Matrix4x2 left, Matrix4x2 right)
|
||||
{
|
||||
Matrix4x2 result;
|
||||
Add(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subtract
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <param name="result">A new instance that is the result of the subtraction.</param>
|
||||
public static void Subtract(ref Matrix4x2 left, ref Matrix4x2 right, out Matrix4x2 result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X - right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y - right.Row0.Y;
|
||||
result.Row1.X = left.Row1.X - right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y - right.Row1.Y;
|
||||
result.Row2.X = left.Row2.X - right.Row2.X;
|
||||
result.Row2.Y = left.Row2.Y - right.Row2.Y;
|
||||
result.Row3.X = left.Row3.X - right.Row3.X;
|
||||
result.Row3.Y = left.Row3.Y - right.Row3.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <returns>A new instance that is the result of the subtraction.</returns>
|
||||
public static Matrix4x2 Subtract(Matrix4x2 left, Matrix4x2 right)
|
||||
{
|
||||
Matrix4x2 result;
|
||||
Subtract(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Transpose
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the transpose of the given matrix.
|
||||
/// </summary>
|
||||
/// <param name="mat">The matrix to transpose.</param>
|
||||
/// <param name="result">The transpose of the given matrix.</param>
|
||||
public static void Transpose(ref Matrix4x2 mat, out Matrix2x4 result)
|
||||
{
|
||||
result.Row0.X = mat.Row0.X;
|
||||
result.Row0.Y = mat.Row1.X;
|
||||
result.Row0.Z = mat.Row2.X;
|
||||
result.Row0.W = mat.Row3.X;
|
||||
result.Row1.X = mat.Row0.Y;
|
||||
result.Row1.Y = mat.Row1.Y;
|
||||
result.Row1.Z = mat.Row2.Y;
|
||||
result.Row1.W = mat.Row3.Y;
|
||||
}
|
||||
|
||||
/// <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 Matrix2x4 Transpose(Matrix4x2 mat)
|
||||
{
|
||||
Matrix2x4 result;
|
||||
Transpose(ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4x2 which holds the result of the multiplication</returns>
|
||||
public static Matrix4x2 operator *(float left, Matrix4x2 right)
|
||||
{
|
||||
return Mult(right, left);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4x2 which holds the result of the multiplication</returns>
|
||||
public static Matrix4x2 operator *(Matrix4x2 left, float right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2 which holds the result of the multiplication</returns>
|
||||
public static Matrix4x2 operator *(Matrix4x2 left, Matrix2 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4x3 which holds the result of the multiplication</returns>
|
||||
public static Matrix4x3 operator *(Matrix4x2 left, Matrix2x3 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4 which holds the result of the multiplication</returns>
|
||||
public static Matrix4 operator *(Matrix4x2 left, Matrix2x4 right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix addition
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4x2 which holds the result of the addition</returns>
|
||||
public static Matrix4x2 operator +(Matrix4x2 left, Matrix4x2 right)
|
||||
{
|
||||
return Add(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix subtraction
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4x2 which holds the result of the subtraction</returns>
|
||||
public static Matrix4x2 operator -(Matrix4x2 left, Matrix4x2 right)
|
||||
{
|
||||
return Subtract(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left equals right; false otherwise.</returns>
|
||||
public static bool operator ==(Matrix4x2 left, Matrix4x2 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left does not equal right; false otherwise.</returns>
|
||||
public static bool operator !=(Matrix4x2 left, Matrix4x2 right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Matrix3d.
|
||||
/// </summary>
|
||||
/// <returns>The string representation of the matrix.</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 Matrix4x2))
|
||||
return false;
|
||||
|
||||
return this.Equals((Matrix4x2)obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<Matrix4x2> 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(Matrix4x2 other)
|
||||
{
|
||||
return
|
||||
Row0 == other.Row0 &&
|
||||
Row1 == other.Row1 &&
|
||||
Row2 == other.Row2 &&
|
||||
Row3 == other.Row3;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
786
Source/OpenTK/Math/Matrix4x2d.cs
Normal file
786
Source/OpenTK/Math/Matrix4x2d.cs
Normal file
|
@ -0,0 +1,786 @@
|
|||
#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
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a 4x2 matrix.
|
||||
/// </summary>
|
||||
public struct Matrix4x2d : IEquatable<Matrix4x2d>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Top row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Row0;
|
||||
|
||||
/// <summary>
|
||||
/// Second row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Row1;
|
||||
|
||||
/// <summary>
|
||||
/// Third row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Row2;
|
||||
|
||||
/// <summary>
|
||||
/// Bottom row of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Row3;
|
||||
|
||||
/// <summary>
|
||||
/// The zero matrix.
|
||||
/// </summary>
|
||||
public static readonly Matrix4x2d Zero = new Matrix4x2d(Vector2d.Zero, Vector2d.Zero, Vector2d.Zero, Vector2d.Zero);
|
||||
|
||||
#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 Matrix4x2d(Vector2d row0, Vector2d row1, Vector2d row2, Vector2d row3)
|
||||
{
|
||||
Row0 = row0;
|
||||
Row1 = row1;
|
||||
Row2 = row2;
|
||||
Row3 = row3;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance
|
||||
/// </summary>
|
||||
/// <param name="m00">First item of the first row of the matrix.</param>
|
||||
/// <param name="m01">Second item of the first row of the matrix.</param>
|
||||
/// <param name="m10">First item of the second row of the matrix.</param>
|
||||
/// <param name="m11">Second item of the second row of the matrix.</param>
|
||||
/// <param name="m20">First item of the third row of the matrix.</param>
|
||||
/// <param name="m21">Second item of the third row of the matrix.</param>
|
||||
/// <param name="m30">First item of the fourth row of the matrix.</param>
|
||||
/// <param name="m31">Second item of the fourth row of the matrix.</param>
|
||||
public Matrix4x2d(
|
||||
double m00, double m01,
|
||||
double m10, double m11,
|
||||
double m20, double m21,
|
||||
double m30, double m31)
|
||||
{
|
||||
Row0 = new Vector2d(m00, m01);
|
||||
Row1 = new Vector2d(m10, m11);
|
||||
Row2 = new Vector2d(m20, m21);
|
||||
Row3 = new Vector2d(m30, m31);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the first column of this matrix.
|
||||
/// </summary>
|
||||
public Vector4d Column0
|
||||
{
|
||||
get { return new Vector4d(Row0.X, Row1.X, Row2.X, Row3.X); }
|
||||
set { Row0.X = value.X; Row1.X = value.Y; Row2.X = value.Z; Row3.X = value.W; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the second column of this matrix.
|
||||
/// </summary>
|
||||
public Vector4d Column1
|
||||
{
|
||||
get { return new Vector4d(Row0.Y, Row1.Y, Row2.Y, Row3.X); }
|
||||
set { Row0.Y = value.X; Row1.Y = value.Y; Row2.Y = value.Z; Row3.Y = value.W; }
|
||||
}
|
||||
|
||||
/// <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 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 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 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 2 of this instance.
|
||||
/// </summary>
|
||||
public double M42 { get { return Row3.Y; } set { Row3.Y = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the values along the main diagonal of the matrix.
|
||||
/// </summary>
|
||||
public Vector2d Diagonal
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2d(Row0.X, Row1.Y);
|
||||
}
|
||||
set
|
||||
{
|
||||
Row0.X = value.X;
|
||||
Row1.Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trace of the matrix, the sum of the values along the diagonal.
|
||||
/// </summary>
|
||||
public double Trace { get { return Row0.X + Row1.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexers
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at a specified row and column.
|
||||
/// </summary>
|
||||
public double this[int rowIndex, int columnIndex]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowIndex == 0) return Row0[columnIndex];
|
||||
else if (rowIndex == 1) return Row1[columnIndex];
|
||||
else if (rowIndex == 2) return Row2[columnIndex];
|
||||
else if (rowIndex == 3) return Row3[columnIndex];
|
||||
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowIndex == 0) Row0[columnIndex] = value;
|
||||
else if (rowIndex == 1) Row1[columnIndex] = value;
|
||||
else if (rowIndex == 2) Row2[columnIndex] = value;
|
||||
else if (rowIndex == 3) Row3[columnIndex] = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static
|
||||
|
||||
#region CreateRotation
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <param name="result">The resulting Matrix3x2 instance.</param>
|
||||
public static void CreateRotation(double angle, out Matrix4x2d result)
|
||||
{
|
||||
double cos = (double)System.Math.Cos(angle);
|
||||
double sin = (double)System.Math.Sin(angle);
|
||||
|
||||
result.Row0.X = cos;
|
||||
result.Row0.Y = sin;
|
||||
result.Row1.X = -sin;
|
||||
result.Row1.Y = cos;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
result.Row3.X = 0;
|
||||
result.Row3.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a rotation matrix.
|
||||
/// </summary>
|
||||
/// <param name="angle">The counter-clockwise angle in radians.</param>
|
||||
/// <returns>The resulting Matrix3x2 instance.</returns>
|
||||
public static Matrix4x2d CreateRotation(double angle)
|
||||
{
|
||||
Matrix4x2d result;
|
||||
CreateRotation(angle, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateScale
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x, y, and z axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(double scale, out Matrix4x2d result)
|
||||
{
|
||||
result.Row0.X = scale;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
result.Row3.X = 0;
|
||||
result.Row3.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Single scale factor for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix4x2d CreateScale(double scale)
|
||||
{
|
||||
Matrix4x2d result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(Vector2d scale, out Matrix4x2d result)
|
||||
{
|
||||
result.Row0.X = scale.X;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = scale.Y;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
result.Row3.X = 0;
|
||||
result.Row3.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale factors for the x and y axes.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix4x2d CreateScale(Vector2d scale)
|
||||
{
|
||||
Matrix4x2d result;
|
||||
CreateScale(scale, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <param name="result">A scale matrix.</param>
|
||||
public static void CreateScale(double x, double y, out Matrix4x2d result)
|
||||
{
|
||||
result.Row0.X = x;
|
||||
result.Row0.Y = 0;
|
||||
result.Row1.X = 0;
|
||||
result.Row1.Y = y;
|
||||
result.Row2.X = 0;
|
||||
result.Row2.Y = 0;
|
||||
result.Row3.X = 0;
|
||||
result.Row3.Y = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix.
|
||||
/// </summary>
|
||||
/// <param name="x">Scale factor for the x axis.</param>
|
||||
/// <param name="y">Scale factor for the y axis.</param>
|
||||
/// <returns>A scale matrix.</returns>
|
||||
public static Matrix4x2d CreateScale(double x, double y)
|
||||
{
|
||||
Matrix4x2d result;
|
||||
CreateScale(x, y, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Multiply Functions
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix4x2d left, double right, out Matrix4x2d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X * right;
|
||||
result.Row0.Y = left.Row0.Y * right;
|
||||
result.Row1.X = left.Row1.X * right;
|
||||
result.Row1.Y = left.Row1.Y * right;
|
||||
result.Row2.X = left.Row2.X * right;
|
||||
result.Row2.Y = left.Row2.Y * right;
|
||||
result.Row3.X = left.Row3.X * right;
|
||||
result.Row3.Y = left.Row3.Y * right;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies and instance by a scalar.
|
||||
/// </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 Matrix4x2d Mult(Matrix4x2d left, double right)
|
||||
{
|
||||
Matrix4x2d result;
|
||||
Mult(ref left, 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 Matrix4x2d left, ref Matrix2d right, out Matrix4x2d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y,
|
||||
lM41 = left.Row3.X, lM42 = left.Row3.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row2.X = (lM31 * rM11) + (lM32 * rM21);
|
||||
result.Row2.Y = (lM31 * rM12) + (lM32 * rM22);
|
||||
result.Row3.X = (lM41 * rM11) + (lM42 * rM21);
|
||||
result.Row3.Y = (lM41 * rM12) + (lM42 * rM22);
|
||||
}
|
||||
|
||||
/// <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 Matrix4x2d Mult(Matrix4x2d left, Matrix2d right)
|
||||
{
|
||||
Matrix4x2d 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 Matrix4x2d left, ref Matrix2x3d right, out Matrix4x3d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y,
|
||||
lM41 = left.Row3.X, lM42 = left.Row3.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row0.Z = (lM11 * rM13) + (lM12 * rM23);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row1.Z = (lM21 * rM13) + (lM22 * rM23);
|
||||
result.Row2.X = (lM31 * rM11) + (lM32 * rM21);
|
||||
result.Row2.Y = (lM31 * rM12) + (lM32 * rM22);
|
||||
result.Row2.Z = (lM31 * rM13) + (lM32 * rM23);
|
||||
result.Row3.X = (lM41 * rM11) + (lM42 * rM21);
|
||||
result.Row3.Y = (lM41 * rM12) + (lM42 * rM22);
|
||||
result.Row3.Z = (lM41 * rM13) + (lM42 * rM23);
|
||||
}
|
||||
|
||||
/// <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 Matrix4x3d Mult(Matrix4x2d left, Matrix2x3d right)
|
||||
{
|
||||
Matrix4x3d 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 Matrix4x2d left, ref Matrix2x4d right, out Matrix4d result)
|
||||
{
|
||||
double lM11 = left.Row0.X, lM12 = left.Row0.Y,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y,
|
||||
lM41 = left.Row3.X, lM42 = left.Row3.Y,
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z, rM14 = right.Row0.W,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z, rM24 = right.Row1.W;
|
||||
|
||||
result.Row0.X = (lM11 * rM11) + (lM12 * rM21);
|
||||
result.Row0.Y = (lM11 * rM12) + (lM12 * rM22);
|
||||
result.Row0.Z = (lM11 * rM13) + (lM12 * rM23);
|
||||
result.Row0.W = (lM11 * rM14) + (lM12 * rM24);
|
||||
result.Row1.X = (lM21 * rM11) + (lM22 * rM21);
|
||||
result.Row1.Y = (lM21 * rM12) + (lM22 * rM22);
|
||||
result.Row1.Z = (lM21 * rM13) + (lM22 * rM23);
|
||||
result.Row1.W = (lM21 * rM14) + (lM22 * rM24);
|
||||
result.Row2.X = (lM31 * rM11) + (lM32 * rM21);
|
||||
result.Row2.Y = (lM31 * rM12) + (lM32 * rM22);
|
||||
result.Row2.Z = (lM31 * rM13) + (lM32 * rM23);
|
||||
result.Row2.W = (lM31 * rM14) + (lM32 * rM24);
|
||||
result.Row3.X = (lM41 * rM11) + (lM42 * rM21);
|
||||
result.Row3.Y = (lM41 * rM12) + (lM42 * rM22);
|
||||
result.Row3.Z = (lM41 * rM13) + (lM42 * rM23);
|
||||
result.Row3.W = (lM41 * rM14) + (lM42 * rM24);
|
||||
}
|
||||
|
||||
/// <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(Matrix4x2d left, Matrix2x4d right)
|
||||
{
|
||||
Matrix4d result;
|
||||
Mult(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Add
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <param name="result">A new instance that is the result of the addition.</param>
|
||||
public static void Add(ref Matrix4x2d left, ref Matrix4x2d right, out Matrix4x2d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X + right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y + right.Row0.Y;
|
||||
result.Row1.X = left.Row1.X + right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y + right.Row1.Y;
|
||||
result.Row2.X = left.Row2.X + right.Row2.X;
|
||||
result.Row2.Y = left.Row2.Y + right.Row2.Y;
|
||||
result.Row3.X = left.Row3.X + right.Row3.X;
|
||||
result.Row3.Y = left.Row3.Y + right.Row3.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the addition.</param>
|
||||
/// <param name="right">The right operand of the addition.</param>
|
||||
/// <returns>A new instance that is the result of the addition.</returns>
|
||||
public static Matrix4x2d Add(Matrix4x2d left, Matrix4x2d right)
|
||||
{
|
||||
Matrix4x2d result;
|
||||
Add(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subtract
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <param name="result">A new instance that is the result of the subtraction.</param>
|
||||
public static void Subtract(ref Matrix4x2d left, ref Matrix4x2d right, out Matrix4x2d result)
|
||||
{
|
||||
result.Row0.X = left.Row0.X - right.Row0.X;
|
||||
result.Row0.Y = left.Row0.Y - right.Row0.Y;
|
||||
result.Row1.X = left.Row1.X - right.Row1.X;
|
||||
result.Row1.Y = left.Row1.Y - right.Row1.Y;
|
||||
result.Row2.X = left.Row2.X - right.Row2.X;
|
||||
result.Row2.Y = left.Row2.Y - right.Row2.Y;
|
||||
result.Row3.X = left.Row3.X - right.Row3.X;
|
||||
result.Row3.Y = left.Row3.Y - right.Row3.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two instances.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand of the subtraction.</param>
|
||||
/// <param name="right">The right operand of the subtraction.</param>
|
||||
/// <returns>A new instance that is the result of the subtraction.</returns>
|
||||
public static Matrix4x2d Subtract(Matrix4x2d left, Matrix4x2d right)
|
||||
{
|
||||
Matrix4x2d result;
|
||||
Subtract(ref left, ref right, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Transpose
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the transpose of the given matrix.
|
||||
/// </summary>
|
||||
/// <param name="mat">The matrix to transpose.</param>
|
||||
/// <param name="result">The transpose of the given matrix.</param>
|
||||
public static void Transpose(ref Matrix4x2d mat, out Matrix2x4d result)
|
||||
{
|
||||
result.Row0.X = mat.Row0.X;
|
||||
result.Row0.Y = mat.Row1.X;
|
||||
result.Row0.Z = mat.Row2.X;
|
||||
result.Row0.W = mat.Row3.X;
|
||||
result.Row1.X = mat.Row0.Y;
|
||||
result.Row1.Y = mat.Row1.Y;
|
||||
result.Row1.Z = mat.Row2.Y;
|
||||
result.Row1.W = mat.Row3.Y;
|
||||
}
|
||||
|
||||
/// <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 Matrix2x4d Transpose(Matrix4x2d mat)
|
||||
{
|
||||
Matrix2x4d result;
|
||||
Transpose(ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4x2d which holds the result of the multiplication</returns>
|
||||
public static Matrix4x2d operator *(double left, Matrix4x2d right)
|
||||
{
|
||||
return Mult(right, left);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication.
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4x2d which holds the result of the multiplication</returns>
|
||||
public static Matrix4x2d operator *(Matrix4x2d left, double right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix2d which holds the result of the multiplication</returns>
|
||||
public static Matrix4x2d operator *(Matrix4x2d left, Matrix2d right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4x3d which holds the result of the multiplication</returns>
|
||||
public static Matrix4x3d operator *(Matrix4x2d left, Matrix2x3d right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix multiplication
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4d which holds the result of the multiplication</returns>
|
||||
public static Matrix4d operator *(Matrix4x2d left, Matrix2x4d right)
|
||||
{
|
||||
return Mult(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix addition
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4x2d which holds the result of the addition</returns>
|
||||
public static Matrix4x2d operator +(Matrix4x2d left, Matrix4x2d right)
|
||||
{
|
||||
return Add(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix subtraction
|
||||
/// </summary>
|
||||
/// <param name="left">left-hand operand</param>
|
||||
/// <param name="right">right-hand operand</param>
|
||||
/// <returns>A new Matrix4x2d which holds the result of the subtraction</returns>
|
||||
public static Matrix4x2d operator -(Matrix4x2d left, Matrix4x2d right)
|
||||
{
|
||||
return Subtract(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left equals right; false otherwise.</returns>
|
||||
public static bool operator ==(Matrix4x2d left, Matrix4x2d right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">The first instance.</param>
|
||||
/// <param name="right">The second instance.</param>
|
||||
/// <returns>True, if left does not equal right; false otherwise.</returns>
|
||||
public static bool operator !=(Matrix4x2d left, Matrix4x2d right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Matrix3d.
|
||||
/// </summary>
|
||||
/// <returns>The string representation of the matrix.</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 Matrix4x2d))
|
||||
return false;
|
||||
|
||||
return this.Equals((Matrix4x2d)obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<Matrix4x2d> 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(Matrix4x2d other)
|
||||
{
|
||||
return
|
||||
Row0 == other.Row0 &&
|
||||
Row1 == other.Row1 &&
|
||||
Row2 == other.Row2 &&
|
||||
Row3 == other.Row3;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
1007
Source/OpenTK/Math/Matrix4x3.cs
Normal file
1007
Source/OpenTK/Math/Matrix4x3.cs
Normal file
File diff suppressed because it is too large
Load diff
1007
Source/OpenTK/Math/Matrix4x3d.cs
Normal file
1007
Source/OpenTK/Math/Matrix4x3d.cs
Normal file
File diff suppressed because it is too large
Load diff
|
@ -189,6 +189,34 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the Quaternion scaled to unit length.
|
||||
/// </summary>
|
||||
public Quaternion Normalized()
|
||||
{
|
||||
Quaternion q = this;
|
||||
q.Normalize();
|
||||
return q;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reverses the rotation angle of this Quaterniond.
|
||||
/// </summary>
|
||||
public void Invert()
|
||||
{
|
||||
W = -W;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of this Quaterniond with its rotation angle reversed.
|
||||
/// </summary>
|
||||
public Quaternion Inverted()
|
||||
{
|
||||
var q = this;
|
||||
q.Invert();
|
||||
return q;
|
||||
}
|
||||
|
||||
#region public void Normalize()
|
||||
|
||||
/// <summary>
|
||||
|
@ -206,7 +234,7 @@ namespace OpenTK
|
|||
#region public void Conjugate()
|
||||
|
||||
/// <summary>
|
||||
/// Convert this quaternion to its conjugate
|
||||
/// Inverts the Vector3 component of this Quaternion.
|
||||
/// </summary>
|
||||
public void Conjugate()
|
||||
{
|
||||
|
@ -224,7 +252,7 @@ namespace OpenTK
|
|||
/// <summary>
|
||||
/// Defines the identity quaternion.
|
||||
/// </summary>
|
||||
public static Quaternion Identity = new Quaternion(0, 0, 0, 1);
|
||||
public static readonly Quaternion Identity = new Quaternion(0, 0, 0, 1);
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -461,7 +489,7 @@ namespace OpenTK
|
|||
/// </summary>
|
||||
/// <param name="axis">The axis to rotate about</param>
|
||||
/// <param name="angle">The rotation angle in radians</param>
|
||||
/// <returns></returns>
|
||||
/// <returns>The equivalent quaternion</returns>
|
||||
public static Quaternion FromAxisAngle(Vector3 axis, float angle)
|
||||
{
|
||||
if (axis.LengthSquared == 0.0f)
|
||||
|
@ -479,6 +507,78 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region FromMatrix
|
||||
|
||||
/// <summary>
|
||||
/// Builds a quaternion from the given rotation matrix
|
||||
/// </summary>
|
||||
/// <param name="matrix">A rotation matrix</param>
|
||||
/// <returns>The equivalent quaternion</returns>
|
||||
public static Quaternion FromMatrix(Matrix3 matrix)
|
||||
{
|
||||
Quaternion result;
|
||||
FromMatrix(ref matrix, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a quaternion from the given rotation matrix
|
||||
/// </summary>
|
||||
/// <param name="matrix">A rotation matrix</param>
|
||||
/// <param name="result">The equivalent quaternion</param>
|
||||
public static void FromMatrix(ref Matrix3 matrix, out Quaternion result)
|
||||
{
|
||||
float trace = matrix.Trace;
|
||||
|
||||
if (trace > 0)
|
||||
{
|
||||
float s = (float)Math.Sqrt(trace + 1) * 2;
|
||||
float invS = 1f / s;
|
||||
|
||||
result.w = s * 0.25f;
|
||||
result.xyz.X = (matrix.Row2.Y - matrix.Row1.Z) * invS;
|
||||
result.xyz.Y = (matrix.Row0.Z - matrix.Row2.X) * invS;
|
||||
result.xyz.Z = (matrix.Row1.X - matrix.Row0.Y) * invS;
|
||||
}
|
||||
else
|
||||
{
|
||||
float m00 = matrix.Row0.X, m11 = matrix.Row1.Y, m22 = matrix.Row2.Z;
|
||||
|
||||
if (m00 > m11 && m00 > m22)
|
||||
{
|
||||
float s = (float)Math.Sqrt(1 + m00 - m11 - m22) * 2;
|
||||
float invS = 1f / s;
|
||||
|
||||
result.w = (matrix.Row2.Y - matrix.Row1.Z) * invS;
|
||||
result.xyz.X = s * 0.25f;
|
||||
result.xyz.Y = (matrix.Row0.Y + matrix.Row1.X) * invS;
|
||||
result.xyz.Z = (matrix.Row0.Z + matrix.Row2.X) * invS;
|
||||
}
|
||||
else if (m11 > m22)
|
||||
{
|
||||
float s = (float)Math.Sqrt(1 + m11 - m00 - m22) * 2;
|
||||
float invS = 1f / s;
|
||||
|
||||
result.w = (matrix.Row0.Z - matrix.Row2.X) * invS;
|
||||
result.xyz.X = (matrix.Row0.Y + matrix.Row1.X) * invS;
|
||||
result.xyz.Y = s * 0.25f;
|
||||
result.xyz.Z = (matrix.Row1.Z + matrix.Row2.Y) * invS;
|
||||
}
|
||||
else
|
||||
{
|
||||
float s = (float)Math.Sqrt(1 + m22 - m00 - m11) * 2;
|
||||
float invS = 1f / s;
|
||||
|
||||
result.w = (matrix.Row1.X - matrix.Row0.Y) * invS;
|
||||
result.xyz.X = (matrix.Row0.Z + matrix.Row2.X) * invS;
|
||||
result.xyz.Y = (matrix.Row1.Z + matrix.Row2.Y) * invS;
|
||||
result.xyz.Z = s * 0.25f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Slerp
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -189,6 +189,34 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the Quaterniond scaled to unit length.
|
||||
/// </summary>
|
||||
public Quaterniond Normalized()
|
||||
{
|
||||
Quaterniond q = this;
|
||||
q.Normalize();
|
||||
return q;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reverses the rotation angle of this Quaterniond.
|
||||
/// </summary>
|
||||
public void Invert()
|
||||
{
|
||||
W = -W;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of this Quaterniond with its rotation angle reversed.
|
||||
/// </summary>
|
||||
public Quaterniond Inverted()
|
||||
{
|
||||
var q = this;
|
||||
q.Invert();
|
||||
return q;
|
||||
}
|
||||
|
||||
#region public void Normalize()
|
||||
|
||||
/// <summary>
|
||||
|
@ -206,7 +234,7 @@ namespace OpenTK
|
|||
#region public void Conjugate()
|
||||
|
||||
/// <summary>
|
||||
/// Convert this Quaterniond to its conjugate
|
||||
/// Inverts the Vector3d component of this Quaterniond.
|
||||
/// </summary>
|
||||
public void Conjugate()
|
||||
{
|
||||
|
@ -479,6 +507,78 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region FromMatrix
|
||||
|
||||
/// <summary>
|
||||
/// Builds a quaternion from the given rotation matrix
|
||||
/// </summary>
|
||||
/// <param name="matrix">A rotation matrix</param>
|
||||
/// <returns>The equivalent quaternion</returns>
|
||||
public static Quaterniond FromMatrix(Matrix3d matrix)
|
||||
{
|
||||
Quaterniond result;
|
||||
FromMatrix(ref matrix, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a quaternion from the given rotation matrix
|
||||
/// </summary>
|
||||
/// <param name="matrix">A rotation matrix</param>
|
||||
/// <param name="result">The equivalent quaternion</param>
|
||||
public static void FromMatrix(ref Matrix3d matrix, out Quaterniond result)
|
||||
{
|
||||
double trace = matrix.Trace;
|
||||
|
||||
if (trace > 0)
|
||||
{
|
||||
double s = Math.Sqrt(trace + 1) * 2;
|
||||
double invS = 1.0 / s;
|
||||
|
||||
result.w = s * 0.25;
|
||||
result.xyz.X = (matrix.Row2.Y - matrix.Row1.Z) * invS;
|
||||
result.xyz.Y = (matrix.Row0.Z - matrix.Row2.X) * invS;
|
||||
result.xyz.Z = (matrix.Row1.X - matrix.Row0.Y) * invS;
|
||||
}
|
||||
else
|
||||
{
|
||||
double m00 = matrix.Row0.X, m11 = matrix.Row1.Y, m22 = matrix.Row2.Z;
|
||||
|
||||
if (m00 > m11 && m00 > m22)
|
||||
{
|
||||
double s = Math.Sqrt(1 + m00 - m11 - m22) * 2;
|
||||
double invS = 1.0 / s;
|
||||
|
||||
result.w = (matrix.Row2.Y - matrix.Row1.Z) * invS;
|
||||
result.xyz.X = s * 0.25;
|
||||
result.xyz.Y = (matrix.Row0.Y + matrix.Row1.X) * invS;
|
||||
result.xyz.Z = (matrix.Row0.Z + matrix.Row2.X) * invS;
|
||||
}
|
||||
else if (m11 > m22)
|
||||
{
|
||||
double s = Math.Sqrt(1 + m11 - m00 - m22) * 2;
|
||||
double invS = 1.0 / s;
|
||||
|
||||
result.w = (matrix.Row0.Z - matrix.Row2.X) * invS;
|
||||
result.xyz.X = (matrix.Row0.Y + matrix.Row1.X) * invS;
|
||||
result.xyz.Y = s * 0.25;
|
||||
result.xyz.Z = (matrix.Row1.Z + matrix.Row2.Y) * invS;
|
||||
}
|
||||
else
|
||||
{
|
||||
double s = Math.Sqrt(1 + m22 - m00 - m11) * 2;
|
||||
double invS = 1.0 / s;
|
||||
|
||||
result.w = (matrix.Row1.X - matrix.Row0.Y) * invS;
|
||||
result.xyz.X = (matrix.Row0.Z + matrix.Row2.X) * invS;
|
||||
result.xyz.Y = (matrix.Row1.Z + matrix.Row2.Y) * invS;
|
||||
result.xyz.Z = s * 0.25;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Slerp
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -24,6 +24,8 @@ SOFTWARE.
|
|||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
/// <summary>Represents a 2D vector using two single-precision floating-point numbers.</summary>
|
||||
|
@ -108,6 +110,21 @@ namespace OpenTK
|
|||
|
||||
#region Public Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at the index of the Vector.
|
||||
/// </summary>
|
||||
public float this[int index] {
|
||||
get{
|
||||
if(index == 0) return X;
|
||||
else if(index == 1) return Y;
|
||||
throw new IndexOutOfRangeException("You tried to access this vector at index: " + index);
|
||||
} set{
|
||||
if(index == 0) X = value;
|
||||
else if(index == 1) Y = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
|
||||
}
|
||||
}
|
||||
|
||||
#region Instance
|
||||
|
||||
#region public void Add()
|
||||
|
@ -272,6 +289,16 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the Vector2 scaled to unit length.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Vector2 Normalized()
|
||||
{
|
||||
Vector2 v = this;
|
||||
v.Normalize();
|
||||
return v;
|
||||
}
|
||||
#region public void Normalize()
|
||||
|
||||
/// <summary>
|
||||
|
@ -824,6 +851,32 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region PerpDot
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the perpendicular dot (scalar) product of two vectors
|
||||
/// </summary>
|
||||
/// <param name="left">First operand</param>
|
||||
/// <param name="right">Second operand</param>
|
||||
/// <returns>The perpendicular dot product of the two inputs</returns>
|
||||
public static float PerpDot(Vector2 left, Vector2 right)
|
||||
{
|
||||
return left.X * right.Y - left.Y * right.X;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the perpendicular dot (scalar) product of two vectors
|
||||
/// </summary>
|
||||
/// <param name="left">First operand</param>
|
||||
/// <param name="right">Second operand</param>
|
||||
/// <param name="result">The perpendicular dot product of the two inputs</param>
|
||||
public static void PerpDot(ref Vector2 left, ref Vector2 right, out float result)
|
||||
{
|
||||
result = left.X * right.Y - left.Y * right.X;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Lerp
|
||||
|
||||
/// <summary>
|
||||
|
@ -930,6 +983,16 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region Swizzle
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the Y and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Yx { get { return new Vector2(Y, X); } set { Y = value.X; X = value.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
|
@ -1038,13 +1101,14 @@ namespace OpenTK
|
|||
|
||||
#region public override string ToString()
|
||||
|
||||
private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Vector2.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("({0}, {1})", X, Y);
|
||||
return String.Format("({0}{2} {1})", X, Y, listSeparator);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -24,6 +24,7 @@ SOFTWARE.
|
|||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
|
@ -43,17 +44,17 @@ namespace OpenTK
|
|||
/// <summary>
|
||||
/// Defines a unit-length Vector2d that points towards the X-axis.
|
||||
/// </summary>
|
||||
public static Vector2d UnitX = new Vector2d(1, 0);
|
||||
public static readonly 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);
|
||||
public static readonly Vector2d UnitY = new Vector2d(0, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Defines a zero-length Vector2d.
|
||||
/// </summary>
|
||||
public static Vector2d Zero = new Vector2d(0, 0);
|
||||
public static readonly Vector2d Zero = new Vector2d(0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Defines an instance with all components set to 1.
|
||||
|
@ -92,6 +93,21 @@ namespace OpenTK
|
|||
|
||||
#region Public Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at the index of the Vector.
|
||||
/// </summary>
|
||||
public double this[int index] {
|
||||
get{
|
||||
if(index == 0) return X;
|
||||
else if(index == 1) return Y;
|
||||
throw new IndexOutOfRangeException("You tried to access this vector at index: " + index);
|
||||
} set{
|
||||
if(index == 0) X = value;
|
||||
else if(index == 1) Y = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
|
||||
}
|
||||
}
|
||||
|
||||
#region Instance
|
||||
|
||||
#region public void Add()
|
||||
|
@ -233,6 +249,17 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the Vector2d scaled to unit length.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Vector2d Normalized()
|
||||
{
|
||||
Vector2d v = this;
|
||||
v.Normalize();
|
||||
return v;
|
||||
}
|
||||
|
||||
#region public void Normalize()
|
||||
|
||||
/// <summary>
|
||||
|
@ -818,6 +845,16 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region Swizzle
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the Y and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Yx { get { return new Vector2d(Y, X); } set { Y = value.X; X = value.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
|
@ -942,13 +979,14 @@ namespace OpenTK
|
|||
|
||||
#region public override string ToString()
|
||||
|
||||
private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current instance.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("({0}, {1})", X, Y);
|
||||
return String.Format("({0}{2} {1})", X, Y, listSeparator);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -26,6 +26,7 @@ using System;
|
|||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
|
@ -192,6 +193,16 @@ namespace OpenTK
|
|||
|
||||
#endregion Constructors
|
||||
|
||||
#region Swizzle
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the Y and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Yx { get { return new Vector2h(Y, X); } set { Y = value.X; X = value.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Half -> Single
|
||||
|
||||
/// <summary>
|
||||
|
@ -312,10 +323,11 @@ namespace OpenTK
|
|||
|
||||
#region ToString()
|
||||
|
||||
private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
|
||||
/// <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());
|
||||
return String.Format("({0}{2} {1})", X, Y, listSeparator);
|
||||
}
|
||||
|
||||
#endregion ToString()
|
||||
|
|
|
@ -119,6 +119,24 @@ namespace OpenTK
|
|||
|
||||
#region Public Members
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at the index of the Vector.
|
||||
/// </summary>
|
||||
public float this[int index] {
|
||||
get{
|
||||
if(index == 0) return X;
|
||||
else if(index == 1) return Y;
|
||||
else if(index == 2) return Z;
|
||||
throw new IndexOutOfRangeException("You tried to access this vector at index: " + index);
|
||||
} set{
|
||||
if(index == 0) X = value;
|
||||
else if(index == 1) Y = value;
|
||||
else if(index == 2) Z = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
|
||||
}
|
||||
}
|
||||
|
||||
#region Instance
|
||||
|
||||
#region public void Add()
|
||||
|
@ -259,6 +277,16 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the Vector3 scaled to unit length.
|
||||
/// </summary>
|
||||
public Vector3 Normalized()
|
||||
{
|
||||
Vector3 v = this;
|
||||
v.Normalize();
|
||||
return v;
|
||||
}
|
||||
|
||||
#region public void Normalize()
|
||||
|
||||
/// <summary>
|
||||
|
@ -1195,12 +1223,80 @@ namespace OpenTK
|
|||
|
||||
#region Swizzle
|
||||
|
||||
#region 2-component
|
||||
|
||||
/// <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.Vector2 with the X and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Xz { get { return new Vector2(X, Z); } set { X = value.X; Z = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the Y and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Yx { get { return new Vector2(Y, X); } set { Y = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the Y and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Yz { get { return new Vector2(Y, Z); } set { Y = value.X; Z = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the Z and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Zx { get { return new Vector2(Z, X); } set { Z = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the Z and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Zy { get { return new Vector2(Z, Y); } set { Z = value.X; Y = value.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 3-component
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the X, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Xzy { get { return new Vector3(X, Z, Y); } set { X = value.X; Z = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Y, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Yxz { get { return new Vector3(Y, X, Z); } set { Y = value.X; X = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Y, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Yzx { get { return new Vector3(Y, Z, X); } set { Y = value.X; Z = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Z, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Zxy { get { return new Vector3(Z, X, Y); } set { Z = value.X; X = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Z, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Zyx { get { return new Vector3(Z, Y, X); } set { Z = value.X; Y = value.Y; X = value.Z; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
@ -1317,13 +1413,14 @@ namespace OpenTK
|
|||
|
||||
#region public override string ToString()
|
||||
|
||||
private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Vector3.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("({0}, {1}, {2})", X, Y, Z);
|
||||
return String.Format("({0}{3} {1}{3} {2})", X, Y, Z, listSeparator);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -118,6 +118,23 @@ namespace OpenTK
|
|||
|
||||
#region Public Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at the index of the Vector.
|
||||
/// </summary>
|
||||
public double this[int index] {
|
||||
get{
|
||||
if(index == 0) return X;
|
||||
else if(index == 1) return Y;
|
||||
else if(index == 2) return Z;
|
||||
throw new IndexOutOfRangeException("You tried to access this vector at index: " + index);
|
||||
} set{
|
||||
if(index == 0) X = value;
|
||||
else if(index == 1) Y = value;
|
||||
else if(index == 2) Z = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
|
||||
}
|
||||
}
|
||||
|
||||
#region Instance
|
||||
|
||||
#region public void Add()
|
||||
|
@ -258,6 +275,17 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the Vector3d scaled to unit length.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Vector3d Normalized()
|
||||
{
|
||||
Vector3d v = this;
|
||||
v.Normalize();
|
||||
return v;
|
||||
}
|
||||
|
||||
#region public void Normalize()
|
||||
|
||||
/// <summary>
|
||||
|
@ -1193,12 +1221,80 @@ namespace OpenTK
|
|||
|
||||
#region Swizzle
|
||||
|
||||
#region 2-component
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the X and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Xy { get { return new Vector2d(X, Y); } set { X = value.X; Y = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the X and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Xz { get { return new Vector2d(X, Z); } set { X = value.X; Z = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the Y and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Yx { get { return new Vector2d(Y, X); } set { Y = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the Y and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Yz { get { return new Vector2d(Y, Z); } set { Y = value.X; Z = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the Z and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Zx { get { return new Vector2d(Z, X); } set { Z = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the Z and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Zy { get { return new Vector2d(Z, Y); } set { Z = value.X; Y = value.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 3-component
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the X, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Xzy { get { return new Vector3d(X, Z, Y); } set { X = value.X; Z = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Y, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Yxz { get { return new Vector3d(Y, X, Z); } set { Y = value.X; X = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Y, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Yzx { get { return new Vector3d(Y, Z, X); } set { Y = value.X; Z = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Z, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Zxy { get { return new Vector3d(Z, X, Y); } set { Z = value.X; X = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Z, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Zyx { get { return new Vector3d(Z, Y, X); } set { Z = value.X; Y = value.Y; X = value.Z; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
@ -1331,13 +1427,14 @@ namespace OpenTK
|
|||
|
||||
#region public override string ToString()
|
||||
|
||||
private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Vector3.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("({0}, {1}, {2})", X, Y, Z);
|
||||
return String.Format("({0}{3} {1}{3} {2})", X, Y, Z, listSeparator);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -215,12 +215,80 @@ namespace OpenTK
|
|||
|
||||
#region Swizzle
|
||||
|
||||
#region 2-component
|
||||
|
||||
/// <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.Vector2h with the X and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Xz { get { return new Vector2h(X, Z); } set { X = value.X; Z = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the Y and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Yx { get { return new Vector2h(Y, X); } set { Y = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the Y and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Yz { get { return new Vector2h(Y, Z); } set { Y = value.X; Z = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the Z and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Zx { get { return new Vector2h(Z, X); } set { Z = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the Z and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Zy { get { return new Vector2h(Z, Y); } set { Z = value.X; Y = value.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 3-component
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the X, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Xzy { get { return new Vector3h(X, Z, Y); } set { X = value.X; Z = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Y, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Yxz { get { return new Vector3h(Y, X, Z); } set { Y = value.X; X = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Y, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Yzx { get { return new Vector3h(Y, Z, X); } set { Y = value.X; Z = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Z, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Zxy { get { return new Vector3h(Z, X, Y); } set { Z = value.X; X = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Z, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Zyx { get { return new Vector3h(Z, Y, X); } set { Z = value.X; Y = value.Y; X = value.Z; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Half -> Single
|
||||
|
@ -355,10 +423,11 @@ namespace OpenTK
|
|||
|
||||
#region ToString()
|
||||
|
||||
private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
|
||||
/// <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());
|
||||
return String.Format("({0}{3} {1}{3} {2})", X.ToString(), Y.ToString(), Z.ToString(), listSeparator);
|
||||
}
|
||||
|
||||
#endregion ToString()
|
||||
|
|
|
@ -60,27 +60,27 @@ namespace OpenTK
|
|||
/// <summary>
|
||||
/// Defines a unit-length Vector4 that points towards the X-axis.
|
||||
/// </summary>
|
||||
public static Vector4 UnitX = new Vector4(1, 0, 0, 0);
|
||||
public static readonly 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);
|
||||
public static readonly 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);
|
||||
public static readonly 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);
|
||||
public static readonly 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);
|
||||
public static readonly Vector4 Zero = new Vector4(0, 0, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Defines an instance with all components set to 1.
|
||||
|
@ -178,6 +178,25 @@ namespace OpenTK
|
|||
|
||||
#region Public Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at the index of the Vector.
|
||||
/// </summary>
|
||||
public float this[int index] {
|
||||
get{
|
||||
if(index == 0) return X;
|
||||
else if(index == 1) return Y;
|
||||
else if(index == 2) return Z;
|
||||
else if(index == 3) return W;
|
||||
throw new IndexOutOfRangeException("You tried to access this vector at index: " + index);
|
||||
} set{
|
||||
if(index == 0) X = value;
|
||||
else if(index == 1) Y = value;
|
||||
else if(index == 2) Z = value;
|
||||
else if(index == 3) W = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
|
||||
}
|
||||
}
|
||||
|
||||
#region Instance
|
||||
|
||||
#region public void Add()
|
||||
|
@ -324,6 +343,16 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the Vector4 scaled to unit length.
|
||||
/// </summary>
|
||||
public Vector4 Normalized()
|
||||
{
|
||||
Vector4 v = this;
|
||||
v.Normalize();
|
||||
return v;
|
||||
}
|
||||
|
||||
#region public void Normalize()
|
||||
|
||||
/// <summary>
|
||||
|
@ -991,6 +1020,8 @@ namespace OpenTK
|
|||
|
||||
#region Swizzle
|
||||
|
||||
#region 2-component
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the X and Y components of this instance.
|
||||
/// </summary>
|
||||
|
@ -998,11 +1029,387 @@ namespace OpenTK
|
|||
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.
|
||||
/// Gets or sets an OpenTK.Vector2 with the X and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Xz { get { return new Vector2(X, Z); } set { X = value.X; Z = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the X and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Xw { get { return new Vector2(X, W); } set { X = value.X; W = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the Y and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Yx { get { return new Vector2(Y, X); } set { Y = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the Y and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Yz { get { return new Vector2(Y, Z); } set { Y = value.X; Z = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the Y and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Yw { get { return new Vector2(Y, W); } set { Y = value.X; W = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the Z and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Zx { get { return new Vector2(Z, X); } set { Z = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the Z and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Zy { get { return new Vector2(Z, Y); } set { Z = value.X; Y = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector2 with the Z and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Zw { get { return new Vector2(Z, W); } set { Z = value.X; W = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the W and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Wx { get { return new Vector2(W, X); } set { W = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the W and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Wy { get { return new Vector2(W, Y); } set { W = value.X; Y = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2 with the W and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2 Wz { get { return new Vector2(W, Z); } set { W = value.X; Z = value.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 3-component
|
||||
|
||||
/// <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; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the X, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Xyw { get { return new Vector3(X, Y, W); } set { X = value.X; Y = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the X, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Xzy { get { return new Vector3(X, Z, Y); } set { X = value.X; Z = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the X, Z, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Xzw { get { return new Vector3(X, Z, W); } set { X = value.X; Z = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the X, W, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Xwy { get { return new Vector3(X, W, Y); } set { X = value.X; W = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the X, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Xwz { get { return new Vector3(X, W, Z); } set { X = value.X; W = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Y, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Yxz { get { return new Vector3(Y, X, Z); } set { Y = value.X; X = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Y, X, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Yxw { get { return new Vector3(Y, X, W); } set { Y = value.X; X = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Y, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Yzx { get { return new Vector3(Y, Z, X); } set { Y = value.X; Z = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Y, Z, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Yzw { get { return new Vector3(Y, Z, W); } set { Y = value.X; Z = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Y, W, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Ywx { get { return new Vector3(Y, W, X); } set { Y = value.X; W = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector3 with the Y, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Ywz { get { return new Vector3(Y, W, Z); } set { Y = value.X; W = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Z, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Zxy { get { return new Vector3(Z, X, Y); } set { Z = value.X; X = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Z, X, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Zxw { get { return new Vector3(Z, X, W); } set { Z = value.X; X = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Z, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Zyx { get { return new Vector3(Z, Y, X); } set { Z = value.X; Y = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Z, Y, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Zyw { get { return new Vector3(Z, Y, W); } set { Z = value.X; Y = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Z, W, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Zwx { get { return new Vector3(Z, W, X); } set { Z = value.X; W = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the Z, W, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Zwy { get { return new Vector3(Z, W, Y); } set { Z = value.X; W = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the W, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Wxy { get { return new Vector3(W, X, Y); } set { W = value.X; X = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the W, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Wxz { get { return new Vector3(W, X, Z); } set { W = value.X; X = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the W, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Wyx { get { return new Vector3(W, Y, X); } set { W = value.X; Y = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the W, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Wyz { get { return new Vector3(W, Y, Z); } set { W = value.X; Y = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the W, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Wzx { get { return new Vector3(W, Z, X); } set { W = value.X; Z = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3 with the W, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3 Wzy { get { return new Vector3(W, Z, Y); } set { W = value.X; Z = value.Y; Y = value.Z; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 4-component
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the X, Y, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Xywz { get { return new Vector4(X, Y, W, Z); } set { X = value.X; Y = value.Y; W = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the X, Z, Y, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Xzyw { get { return new Vector4(X, Z, Y, W); } set { X = value.X; Z = value.Y; Y = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the X, Z, W, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Xzwy { get { return new Vector4(X, Z, W, Y); } set { X = value.X; Z = value.Y; W = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the X, W, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Xwyz { get { return new Vector4(X, W, Y, Z); } set { X = value.X; W = value.Y; Y = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the X, W, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Xwzy { get { return new Vector4(X, W, Z, Y); } set { X = value.X; W = value.Y; Z = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the Y, X, Z, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Yxzw { get { return new Vector4(Y, X, Z, W); } set { Y = value.X; X = value.Y; Z = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the Y, X, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Yxwz { get { return new Vector4(Y, X, W, Z); } set { Y = value.X; X = value.Y; W = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector4 with the Y, Y, Z, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Yyzw { get { return new Vector4(Y, Y, Z, W); } set { X = value.X; Y = value.Y; Z = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector4 with the Y, Y, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Yywz { get { return new Vector4(Y, Y, W, Z); } set { X = value.X; Y = value.Y; W = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the Y, Z, X, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Yzxw { get { return new Vector4(Y, Z, X, W); } set { Y = value.X; Z = value.Y; X = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the Y, Z, W, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Yzwx { get { return new Vector4(Y, Z, W, X); } set { Y = value.X; Z = value.Y; W = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the Y, W, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Ywxz { get { return new Vector4(Y, W, X, Z); } set { Y = value.X; W = value.Y; X = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the Y, W, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Ywzx { get { return new Vector4(Y, W, Z, X); } set { Y = value.X; W = value.Y; Z = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the Z, X, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Zxyw { get { return new Vector4(Z, X, Y, W); } set { Z = value.X; X = value.Y; Y = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the Z, X, W, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Zxwy { get { return new Vector4(Z, X, W, Y); } set { Z = value.X; X = value.Y; W = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the Z, Y, X, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Zyxw { get { return new Vector4(Z, Y, X, W); } set { Z = value.X; Y = value.Y; X = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the Z, Y, W, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Zywx { get { return new Vector4(Z, Y, W, X); } set { Z = value.X; Y = value.Y; W = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the Z, W, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Zwxy { get { return new Vector4(Z, W, X, Y); } set { Z = value.X; W = value.Y; X = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the Z, W, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Zwyx { get { return new Vector4(Z, W, Y, X); } set { Z = value.X; W = value.Y; Y = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector4 with the Z, W, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Zwzy { get { return new Vector4(Z, W, Z, Y); } set { X = value.X; W = value.Y; Z = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the W, X, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Wxyz { get { return new Vector4(W, X, Y, Z); } set { W = value.X; X = value.Y; Y = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the W, X, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Wxzy { get { return new Vector4(W, X, Z, Y); } set { W = value.X; X = value.Y; Z = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the W, Y, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Wyxz { get { return new Vector4(W, Y, X, Z); } set { W = value.X; Y = value.Y; X = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the W, Y, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Wyzx { get { return new Vector4(W, Y, Z, X); } set { W = value.X; Y = value.Y; Z = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the W, Z, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Wzxy { get { return new Vector4(W, Z, X, Y); } set { W = value.X; Z = value.Y; X = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4 with the W, Z, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Wzyx { get { return new Vector4(W, Z, Y, X); } set { W = value.X; Z = value.Y; Y = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector4 with the W, Z, Y, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4 Wzyw { get { return new Vector4(W, Z, Y, W); } set { X = value.X; Z = value.Y; Y = value.Z; W = value.W; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
@ -1149,13 +1556,14 @@ namespace OpenTK
|
|||
|
||||
#region public override string ToString()
|
||||
|
||||
private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
|
||||
/// <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);
|
||||
return String.Format("({0}{4} {1}{4} {2}{4} {3})", X, Y, Z, W, listSeparator);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -58,27 +58,27 @@ namespace OpenTK
|
|||
/// <summary>
|
||||
/// Defines a unit-length Vector4d that points towards the X-axis.
|
||||
/// </summary>
|
||||
public static Vector4d UnitX = new Vector4d(1, 0, 0, 0);
|
||||
public static readonly Vector4d UnitX = new Vector4d(1, 0, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Defines a unit-length Vector4d that points towards the Y-axis.
|
||||
/// </summary>
|
||||
public static Vector4d UnitY = new Vector4d(0, 1, 0, 0);
|
||||
public static readonly Vector4d UnitY = new Vector4d(0, 1, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Defines a unit-length Vector4d that points towards the Z-axis.
|
||||
/// </summary>
|
||||
public static Vector4d UnitZ = new Vector4d(0, 0, 1, 0);
|
||||
public static readonly Vector4d UnitZ = new Vector4d(0, 0, 1, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Defines a unit-length Vector4d that points towards the W-axis.
|
||||
/// </summary>
|
||||
public static Vector4d UnitW = new Vector4d(0, 0, 0, 1);
|
||||
public static readonly Vector4d UnitW = new Vector4d(0, 0, 0, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Defines a zero-length Vector4d.
|
||||
/// </summary>
|
||||
public static Vector4d Zero = new Vector4d(0, 0, 0, 0);
|
||||
public static readonly Vector4d Zero = new Vector4d(0, 0, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Defines an instance with all components set to 1.
|
||||
|
@ -175,6 +175,25 @@ namespace OpenTK
|
|||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value at the index of the Vector.
|
||||
/// </summary>
|
||||
public double this[int index] {
|
||||
get{
|
||||
if(index == 0) return X;
|
||||
else if(index == 1) return Y;
|
||||
else if(index == 2) return Z;
|
||||
else if(index == 3) return W;
|
||||
throw new IndexOutOfRangeException("You tried to access this vector at index: " + index);
|
||||
} set{
|
||||
if(index == 0) X = value;
|
||||
else if(index == 1) Y = value;
|
||||
else if(index == 2) Z = value;
|
||||
else if(index == 3) W = value;
|
||||
else throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
|
||||
}
|
||||
}
|
||||
|
||||
#region Instance
|
||||
|
||||
|
@ -321,6 +340,16 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the Vector4d scaled to unit length.
|
||||
/// </summary>
|
||||
public Vector4d Normalized()
|
||||
{
|
||||
Vector4d v = this;
|
||||
v.Normalize();
|
||||
return v;
|
||||
}
|
||||
|
||||
#region public void Normalize()
|
||||
|
||||
/// <summary>
|
||||
|
@ -994,6 +1023,8 @@ namespace OpenTK
|
|||
|
||||
#region Swizzle
|
||||
|
||||
#region 2-component
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the X and Y components of this instance.
|
||||
/// </summary>
|
||||
|
@ -1001,11 +1032,387 @@ namespace OpenTK
|
|||
public Vector2d Xy { get { return new Vector2d(X, Y); } set { X = value.X; Y = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the X, Y and Z components of this instance.
|
||||
/// Gets or sets an OpenTK.Vector2d with the X and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Xz { get { return new Vector2d(X, Z); } set { X = value.X; Z = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the X and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Xw { get { return new Vector2d(X, W); } set { X = value.X; W = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the Y and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Yx { get { return new Vector2d(Y, X); } set { Y = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the Y and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Yz { get { return new Vector2d(Y, Z); } set { Y = value.X; Z = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the Y and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Yw { get { return new Vector2d(Y, W); } set { Y = value.X; W = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the Z and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Zx { get { return new Vector2d(Z, X); } set { Z = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the Z and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Zy { get { return new Vector2d(Z, Y); } set { Z = value.X; Y = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector2d with the Z and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Zw { get { return new Vector2d(Z, W); } set { Z = value.X; W = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the W and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Wx { get { return new Vector2d(W, X); } set { W = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the W and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Wy { get { return new Vector2d(W, Y); } set { W = value.X; Y = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2d with the W and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2d Wz { get { return new Vector2d(W, Z); } set { W = value.X; Z = value.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 3-component
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the X, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Xyz { get { return new Vector3d(X, Y, Z); } set { X = value.X; Y = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the X, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Xyw { get { return new Vector3d(X, Y, W); } set { X = value.X; Y = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the X, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Xzy { get { return new Vector3d(X, Z, Y); } set { X = value.X; Z = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the X, Z, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Xzw { get { return new Vector3d(X, Z, W); } set { X = value.X; Z = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the X, W, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Xwy { get { return new Vector3d(X, W, Y); } set { X = value.X; W = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the X, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Xwz { get { return new Vector3d(X, W, Z); } set { X = value.X; W = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Y, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Yxz { get { return new Vector3d(Y, X, Z); } set { Y = value.X; X = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Y, X, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Yxw { get { return new Vector3d(Y, X, W); } set { Y = value.X; X = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Y, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Yzx { get { return new Vector3d(Y, Z, X); } set { Y = value.X; Z = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Y, Z, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Yzw { get { return new Vector3d(Y, Z, W); } set { Y = value.X; Z = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Y, W, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Ywx { get { return new Vector3d(Y, W, X); } set { Y = value.X; W = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector3d with the Y, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Ywz { get { return new Vector3d(Y, W, Z); } set { Y = value.X; W = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Z, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Zxy { get { return new Vector3d(Z, X, Y); } set { Z = value.X; X = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Z, X, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Zxw { get { return new Vector3d(Z, X, W); } set { Z = value.X; X = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Z, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Zyx { get { return new Vector3d(Z, Y, X); } set { Z = value.X; Y = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Z, Y, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Zyw { get { return new Vector3d(Z, Y, W); } set { Z = value.X; Y = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Z, W, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Zwx { get { return new Vector3d(Z, W, X); } set { Z = value.X; W = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the Z, W, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Zwy { get { return new Vector3d(Z, W, Y); } set { Z = value.X; W = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the W, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Wxy { get { return new Vector3d(W, X, Y); } set { W = value.X; X = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the W, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Wxz { get { return new Vector3d(W, X, Z); } set { W = value.X; X = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the W, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Wyx { get { return new Vector3d(W, Y, X); } set { W = value.X; Y = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the W, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Wyz { get { return new Vector3d(W, Y, Z); } set { W = value.X; Y = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the W, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Wzx { get { return new Vector3d(W, Z, X); } set { W = value.X; Z = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3d with the W, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3d Wzy { get { return new Vector3d(W, Z, Y); } set { W = value.X; Z = value.Y; Y = value.Z; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 4-component
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the X, Y, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Xywz { get { return new Vector4d(X, Y, W, Z); } set { X = value.X; Y = value.Y; W = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the X, Z, Y, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Xzyw { get { return new Vector4d(X, Z, Y, W); } set { X = value.X; Z = value.Y; Y = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the X, Z, W, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Xzwy { get { return new Vector4d(X, Z, W, Y); } set { X = value.X; Z = value.Y; W = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the X, W, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Xwyz { get { return new Vector4d(X, W, Y, Z); } set { X = value.X; W = value.Y; Y = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the X, W, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Xwzy { get { return new Vector4d(X, W, Z, Y); } set { X = value.X; W = value.Y; Z = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the Y, X, Z, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Yxzw { get { return new Vector4d(Y, X, Z, W); } set { Y = value.X; X = value.Y; Z = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the Y, X, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Yxwz { get { return new Vector4d(Y, X, W, Z); } set { Y = value.X; X = value.Y; W = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector4d with the Y, Y, Z, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Yyzw { get { return new Vector4d(Y, Y, Z, W); } set { X = value.X; Y = value.Y; Z = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector4d with the Y, Y, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Yywz { get { return new Vector4d(Y, Y, W, Z); } set { X = value.X; Y = value.Y; W = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the Y, Z, X, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Yzxw { get { return new Vector4d(Y, Z, X, W); } set { Y = value.X; Z = value.Y; X = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the Y, Z, W, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Yzwx { get { return new Vector4d(Y, Z, W, X); } set { Y = value.X; Z = value.Y; W = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the Y, W, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Ywxz { get { return new Vector4d(Y, W, X, Z); } set { Y = value.X; W = value.Y; X = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the Y, W, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Ywzx { get { return new Vector4d(Y, W, Z, X); } set { Y = value.X; W = value.Y; Z = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the Z, X, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Zxyw { get { return new Vector4d(Z, X, Y, W); } set { Z = value.X; X = value.Y; Y = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the Z, X, W, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Zxwy { get { return new Vector4d(Z, X, W, Y); } set { Z = value.X; X = value.Y; W = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the Z, Y, X, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Zyxw { get { return new Vector4d(Z, Y, X, W); } set { Z = value.X; Y = value.Y; X = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the Z, Y, W, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Zywx { get { return new Vector4d(Z, Y, W, X); } set { Z = value.X; Y = value.Y; W = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the Z, W, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Zwxy { get { return new Vector4d(Z, W, X, Y); } set { Z = value.X; W = value.Y; X = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the Z, W, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Zwyx { get { return new Vector4d(Z, W, Y, X); } set { Z = value.X; W = value.Y; Y = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector4d with the Z, W, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Zwzy { get { return new Vector4d(Z, W, Z, Y); } set { X = value.X; W = value.Y; Z = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the W, X, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Wxyz { get { return new Vector4d(W, X, Y, Z); } set { W = value.X; X = value.Y; Y = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the W, X, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Wxzy { get { return new Vector4d(W, X, Z, Y); } set { W = value.X; X = value.Y; Z = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the W, Y, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Wyxz { get { return new Vector4d(W, Y, X, Z); } set { W = value.X; Y = value.Y; X = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the W, Y, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Wyzx { get { return new Vector4d(W, Y, Z, X); } set { W = value.X; Y = value.Y; Z = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the W, Z, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Wzxy { get { return new Vector4d(W, Z, X, Y); } set { W = value.X; Z = value.Y; X = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4d with the W, Z, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Wzyx { get { return new Vector4d(W, Z, Y, X); } set { W = value.X; Z = value.Y; Y = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector4d with the W, Z, Y, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4d Wzyw { get { return new Vector4d(W, Z, Y, W); } set { X = value.X; Z = value.Y; Y = value.Z; W = value.W; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
@ -1168,13 +1575,14 @@ namespace OpenTK
|
|||
|
||||
#region public override string ToString()
|
||||
|
||||
private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current Vector4d.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("({0}, {1}, {2}, {3})", X, Y, Z, W);
|
||||
return String.Format("({0}{4} {1}{4} {2}{4} {3})", X, Y, Z, W, listSeparator);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -234,6 +234,8 @@ namespace OpenTK
|
|||
|
||||
#region Swizzle
|
||||
|
||||
#region 2-component
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the X and Y components of this instance.
|
||||
/// </summary>
|
||||
|
@ -241,11 +243,387 @@ namespace OpenTK
|
|||
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.
|
||||
/// Gets or sets an OpenTK.Vector2h with the X and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Xz { get { return new Vector2h(X, Z); } set { X = value.X; Z = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the X and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Xw { get { return new Vector2h(X, W); } set { X = value.X; W = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the Y and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Yx { get { return new Vector2h(Y, X); } set { Y = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the Y and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Yz { get { return new Vector2h(Y, Z); } set { Y = value.X; Z = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the Y and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Yw { get { return new Vector2h(Y, W); } set { Y = value.X; W = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the Z and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Zx { get { return new Vector2h(Z, X); } set { Z = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the Z and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Zy { get { return new Vector2h(Z, Y); } set { Z = value.X; Y = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector2h with the Z and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Zw { get { return new Vector2h(Z, W); } set { Z = value.X; W = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the W and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Wx { get { return new Vector2h(W, X); } set { W = value.X; X = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the W and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Wy { get { return new Vector2h(W, Y); } set { W = value.X; Y = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector2h with the W and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector2h Wz { get { return new Vector2h(W, Z); } set { W = value.X; Z = value.Y; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 3-component
|
||||
|
||||
/// <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; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the X, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Xyw { get { return new Vector3h(X, Y, W); } set { X = value.X; Y = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the X, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Xzy { get { return new Vector3h(X, Z, Y); } set { X = value.X; Z = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the X, Z, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Xzw { get { return new Vector3h(X, Z, W); } set { X = value.X; Z = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the X, W, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Xwy { get { return new Vector3h(X, W, Y); } set { X = value.X; W = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the X, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Xwz { get { return new Vector3h(X, W, Z); } set { X = value.X; W = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Y, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Yxz { get { return new Vector3h(Y, X, Z); } set { Y = value.X; X = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Y, X, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Yxw { get { return new Vector3h(Y, X, W); } set { Y = value.X; X = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Y, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Yzx { get { return new Vector3h(Y, Z, X); } set { Y = value.X; Z = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Y, Z, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Yzw { get { return new Vector3h(Y, Z, W); } set { Y = value.X; Z = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Y, W, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Ywx { get { return new Vector3h(Y, W, X); } set { Y = value.X; W = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector3h with the Y, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Ywz { get { return new Vector3h(Y, W, Z); } set { Y = value.X; W = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Z, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Zxy { get { return new Vector3h(Z, X, Y); } set { Z = value.X; X = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Z, X, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Zxw { get { return new Vector3h(Z, X, W); } set { Z = value.X; X = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Z, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Zyx { get { return new Vector3h(Z, Y, X); } set { Z = value.X; Y = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Z, Y, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Zyw { get { return new Vector3h(Z, Y, W); } set { Z = value.X; Y = value.Y; W = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Z, W, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Zwx { get { return new Vector3h(Z, W, X); } set { Z = value.X; W = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the Z, W, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Zwy { get { return new Vector3h(Z, W, Y); } set { Z = value.X; W = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the W, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Wxy { get { return new Vector3h(W, X, Y); } set { W = value.X; X = value.Y; Y = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the W, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Wxz { get { return new Vector3h(W, X, Z); } set { W = value.X; X = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the W, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Wyx { get { return new Vector3h(W, Y, X); } set { W = value.X; Y = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the W, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Wyz { get { return new Vector3h(W, Y, Z); } set { W = value.X; Y = value.Y; Z = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the W, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Wzx { get { return new Vector3h(W, Z, X); } set { W = value.X; Z = value.Y; X = value.Z; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector3h with the W, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector3h Wzy { get { return new Vector3h(W, Z, Y); } set { W = value.X; Z = value.Y; Y = value.Z; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 4-component
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the X, Y, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Xywz { get { return new Vector4h(X, Y, W, Z); } set { X = value.X; Y = value.Y; W = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the X, Z, Y, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Xzyw { get { return new Vector4h(X, Z, Y, W); } set { X = value.X; Z = value.Y; Y = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the X, Z, W, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Xzwy { get { return new Vector4h(X, Z, W, Y); } set { X = value.X; Z = value.Y; W = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the X, W, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Xwyz { get { return new Vector4h(X, W, Y, Z); } set { X = value.X; W = value.Y; Y = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the X, W, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Xwzy { get { return new Vector4h(X, W, Z, Y); } set { X = value.X; W = value.Y; Z = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the Y, X, Z, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Yxzw { get { return new Vector4h(Y, X, Z, W); } set { Y = value.X; X = value.Y; Z = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the Y, X, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Yxwz { get { return new Vector4h(Y, X, W, Z); } set { Y = value.X; X = value.Y; W = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector4h with the Y, Y, Z, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Yyzw { get { return new Vector4h(Y, Y, Z, W); } set { X = value.X; Y = value.Y; Z = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector4h with the Y, Y, W, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Yywz { get { return new Vector4h(Y, Y, W, Z); } set { X = value.X; Y = value.Y; W = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the Y, Z, X, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Yzxw { get { return new Vector4h(Y, Z, X, W); } set { Y = value.X; Z = value.Y; X = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the Y, Z, W, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Yzwx { get { return new Vector4h(Y, Z, W, X); } set { Y = value.X; Z = value.Y; W = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the Y, W, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Ywxz { get { return new Vector4h(Y, W, X, Z); } set { Y = value.X; W = value.Y; X = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the Y, W, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Ywzx { get { return new Vector4h(Y, W, Z, X); } set { Y = value.X; W = value.Y; Z = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the Z, X, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Zxyw { get { return new Vector4h(Z, X, Y, W); } set { Z = value.X; X = value.Y; Y = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the Z, X, W, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Zxwy { get { return new Vector4h(Z, X, W, Y); } set { Z = value.X; X = value.Y; W = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the Z, Y, X, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Zyxw { get { return new Vector4h(Z, Y, X, W); } set { Z = value.X; Y = value.Y; X = value.Z; W = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the Z, Y, W, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Zywx { get { return new Vector4h(Z, Y, W, X); } set { Z = value.X; Y = value.Y; W = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the Z, W, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Zwxy { get { return new Vector4h(Z, W, X, Y); } set { Z = value.X; W = value.Y; X = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the Z, W, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Zwyx { get { return new Vector4h(Z, W, Y, X); } set { Z = value.X; W = value.Y; Y = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector4h with the Z, W, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Zwzy { get { return new Vector4h(Z, W, Z, Y); } set { X = value.X; W = value.Y; Z = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the W, X, Y, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Wxyz { get { return new Vector4h(W, X, Y, Z); } set { W = value.X; X = value.Y; Y = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the W, X, Z, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Wxzy { get { return new Vector4h(W, X, Z, Y); } set { W = value.X; X = value.Y; Z = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the W, Y, X, and Z components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Wyxz { get { return new Vector4h(W, Y, X, Z); } set { W = value.X; Y = value.Y; X = value.Z; Z = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the W, Y, Z, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Wyzx { get { return new Vector4h(W, Y, Z, X); } set { W = value.X; Y = value.Y; Z = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the W, Z, X, and Y components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Wzxy { get { return new Vector4h(W, Z, X, Y); } set { W = value.X; Z = value.Y; X = value.Z; Y = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an OpenTK.Vector4h with the W, Z, Y, and X components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Wzyx { get { return new Vector4h(W, Z, Y, X); } set { W = value.X; Z = value.Y; Y = value.Z; X = value.W; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Vector4h with the W, Z, Y, and W components of this instance.
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Vector4h Wzyw { get { return new Vector4h(W, Z, Y, W); } set { X = value.X; Z = value.Y; Y = value.Z; W = value.W; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Half -> Single
|
||||
|
@ -386,10 +764,11 @@ namespace OpenTK
|
|||
|
||||
#region ToString()
|
||||
|
||||
private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
|
||||
/// <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());
|
||||
return String.Format("({0}{4} {1}{4} {2}{4} {3})", X.ToString(), Y.ToString(), Z.ToString(), W.ToString(), listSeparator);
|
||||
}
|
||||
|
||||
#endregion ToString()
|
||||
|
|
|
@ -821,7 +821,7 @@ namespace OpenTK
|
|||
/// <summary>
|
||||
/// Called when a keybord key is released.
|
||||
/// </summary>
|
||||
/// <param name="e">The <see cref="OpenTK.KeyboardKeyEventArgs"/> for this event.</param>
|
||||
/// <param name="e">The <see cref="OpenTK.Input.KeyboardKeyEventArgs"/> for this event.</param>
|
||||
protected virtual void OnKeyUp(KeyboardKeyEventArgs e)
|
||||
{
|
||||
KeyUp(this, e);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?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>
|
||||
|
@ -42,32 +42,32 @@
|
|||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>DEBUG;TRACE;</DefineConstants>
|
||||
<DocumentationFile>OpenTK.xml</DocumentationFile>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugSymbols>True</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>false</Optimize>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Debug\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<DebugType>full</DebugType>
|
||||
<GenerateDocumentation>true</GenerateDocumentation>
|
||||
<GenerateDocumentation>True</GenerateDocumentation>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
<DocumentationFile>OpenTK.xml</DocumentationFile>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -79,19 +79,19 @@
|
|||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<DebugType>none</DebugType>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Nsis|AnyCPU'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
<DocumentationFile>OpenTK.xml</DocumentationFile>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
|
@ -100,7 +100,7 @@
|
|||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<SignAssembly>True</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>..\..\OpenTK.snk</AssemblyOriginatorKeyFile>
|
||||
|
@ -108,19 +108,15 @@
|
|||
<ItemGroup>
|
||||
<Reference Include="System">
|
||||
<Name>System</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Data">
|
||||
<Name>System.Data</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing">
|
||||
<Name>System.Drawing</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml">
|
||||
<Name>System.Xml</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -136,6 +132,21 @@
|
|||
<Compile Include="Input\IInputDriver2.cs" />
|
||||
<Compile Include="Input\IKeyboardDriver2.cs" />
|
||||
<Compile Include="Input\IMouseDriver2.cs" />
|
||||
<Compile Include="Math\Matrix2.cs" />
|
||||
<Compile Include="Math\Matrix2d.cs" />
|
||||
<Compile Include="Math\Matrix2x3.cs" />
|
||||
<Compile Include="Math\Matrix2x3d.cs" />
|
||||
<Compile Include="Math\Matrix2x4.cs" />
|
||||
<Compile Include="Math\Matrix2x4d.cs" />
|
||||
<Compile Include="Math\Matrix3.cs" />
|
||||
<Compile Include="Math\Matrix3x2.cs" />
|
||||
<Compile Include="Math\Matrix3x2d.cs" />
|
||||
<Compile Include="Math\Matrix3x4.cs" />
|
||||
<Compile Include="Math\Matrix3x4d.cs" />
|
||||
<Compile Include="Math\Matrix4x2.cs" />
|
||||
<Compile Include="Math\Matrix4x2d.cs" />
|
||||
<Compile Include="Math\Matrix4x3.cs" />
|
||||
<Compile Include="Math\Matrix4x3d.cs" />
|
||||
<Compile Include="Platform\DisplayDeviceBase.cs" />
|
||||
<Compile Include="Platform\Windows\WinInputBase.cs" />
|
||||
<Compile Include="WindowBorder.cs">
|
||||
|
@ -769,6 +780,8 @@
|
|||
</EmbeddedResource>
|
||||
<Compile Include="Platform\MacOS\HIDInput.cs" />
|
||||
<Compile Include="IntPtrEqualityComparer.cs" />
|
||||
<Compile Include="Input\GamePadButton.cs" />
|
||||
<Compile Include="Input\GamePadAxis.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
|
|
@ -124,6 +124,11 @@ namespace OpenTK.Platform
|
|||
return default_implementation.CreateMouseDriver();
|
||||
}
|
||||
|
||||
public OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
||||
{
|
||||
return default_implementation.CreateGamePadDriver();
|
||||
}
|
||||
|
||||
class UnsupportedPlatform : IPlatformFactory
|
||||
{
|
||||
#region Fields
|
||||
|
@ -178,7 +183,12 @@ namespace OpenTK.Platform
|
|||
{
|
||||
throw new PlatformNotSupportedException(error_string);
|
||||
}
|
||||
|
||||
|
||||
public OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
||||
{
|
||||
throw new PlatformNotSupportedException(error_string);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
|
|
@ -50,5 +50,7 @@ namespace OpenTK.Platform
|
|||
OpenTK.Input.IKeyboardDriver2 CreateKeyboardDriver();
|
||||
|
||||
OpenTK.Input.IMouseDriver2 CreateMouseDriver();
|
||||
|
||||
OpenTK.Input.IGamePadDriver CreateGamePadDriver();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -475,6 +475,9 @@ namespace OpenTK.Platform.MacOS
|
|||
// I do not know MacOS allows us to destroy a context from a separate thread,
|
||||
// like the finalizer thread. It's untested, but worst case is probably
|
||||
// an exception on application exit, which would be logged to the console.
|
||||
|
||||
// Actually, it seems to crash the mono runtime. -AMK 2013
|
||||
|
||||
Debug.Print("Destroying context");
|
||||
if (Agl.aglDestroyContext(Handle.Handle) == true)
|
||||
{
|
||||
|
|
|
@ -85,10 +85,26 @@ namespace OpenTK.Platform.MacOS.Carbon
|
|||
static void ConnectEvents()
|
||||
{
|
||||
|
||||
EventTypeSpec[] eventTypes = new EventTypeSpec[] { new EventTypeSpec(EventClass.Application, AppEventKind.AppActivated), new EventTypeSpec(EventClass.Application, AppEventKind.AppDeactivated), new EventTypeSpec(EventClass.Application, AppEventKind.AppQuit), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseDown), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseUp), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseMoved), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseDragged), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseEntered), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseExited), new EventTypeSpec(EventClass.Mouse, MouseEventKind.WheelMoved),
|
||||
EventTypeSpec[] eventTypes = new EventTypeSpec[] {
|
||||
new EventTypeSpec(EventClass.Application, AppEventKind.AppActivated),
|
||||
new EventTypeSpec(EventClass.Application, AppEventKind.AppDeactivated),
|
||||
new EventTypeSpec(EventClass.Application, AppEventKind.AppQuit),
|
||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseDown),
|
||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseUp),
|
||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseMoved),
|
||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseDragged),
|
||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseEntered),
|
||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseExited),
|
||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.WheelMoved),
|
||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.WheelScroll),
|
||||
|
||||
|
||||
new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyDown), new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyRepeat), new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyUp), new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyModifiersChanged), new EventTypeSpec(EventClass.AppleEvent, AppleEventKind.AppleEvent) };
|
||||
new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyDown),
|
||||
new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyRepeat),
|
||||
new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyUp),
|
||||
new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyModifiersChanged),
|
||||
new EventTypeSpec(EventClass.AppleEvent, AppleEventKind.AppleEvent),
|
||||
};
|
||||
|
||||
MacOSEventHandler handler = EventHandler;
|
||||
uppHandler = API.NewEventHandlerUPP(handler);
|
||||
|
|
|
@ -246,6 +246,7 @@ namespace OpenTK.Platform.MacOS.Carbon
|
|||
MouseEntered = 8,
|
||||
MouseExited = 9,
|
||||
WheelMoved = 10,
|
||||
WheelScroll = 11,
|
||||
}
|
||||
internal enum MouseButton : short
|
||||
{
|
||||
|
@ -286,8 +287,11 @@ namespace OpenTK.Platform.MacOS.Carbon
|
|||
WindowMouseLocation = 0x776d6f75, // typeHIPoint
|
||||
MouseButton = 0x6d62746e, // typeMouseButton
|
||||
ClickCount = 0x63636e74, // typeUInt32
|
||||
MouseWheelAxis = 0x6d776178, // typeMouseWheelAxis
|
||||
MouseWheelDelta = 0x6d77646c, // typeSInt32
|
||||
MouseWheelAxis = 0x6d776178, // typeMouseWheelAxis 'mwax'
|
||||
MouseWheelDelta = 0x6d77646c, // typeSInt32 'mwdl'
|
||||
MouseWheelSmoothVerticalDelta = 0x73617879, // typeSInt32 'saxy'
|
||||
MouseWheelSmoothHorizontalDelta = 0x73617878, // typeSInt32 'saxx'
|
||||
|
||||
MouseDelta = 0x6d647461, // typeHIPoint
|
||||
|
||||
// Keyboard events
|
||||
|
@ -712,6 +716,52 @@ namespace OpenTK.Platform.MacOS.Carbon
|
|||
|
||||
return (MouseButton)button;
|
||||
}
|
||||
|
||||
internal struct ScrollDelta {
|
||||
internal float deltaX;
|
||||
internal float deltaY;
|
||||
}
|
||||
|
||||
static internal ScrollDelta GetEventWheelScroll(IntPtr inEvent)
|
||||
{
|
||||
ScrollDelta scrolldelta = new ScrollDelta();
|
||||
Int32 delta;
|
||||
|
||||
unsafe
|
||||
{
|
||||
Int32* d = δ
|
||||
OSStatus result;
|
||||
|
||||
// vertical scroll Delta in pixels
|
||||
result = API.GetEventParameter(inEvent,
|
||||
EventParamName.MouseWheelSmoothVerticalDelta, EventParamType.typeSInt32,
|
||||
IntPtr.Zero, (uint)sizeof(int), IntPtr.Zero, (IntPtr)d);
|
||||
|
||||
if (result == OSStatus.EventParameterNotFound) {
|
||||
// it's okay for it to be simply missing...
|
||||
} else if (result != OSStatus.NoError) {
|
||||
throw new MacOSException(result);
|
||||
} else {
|
||||
scrolldelta.deltaY = delta / 20.0f;
|
||||
}
|
||||
|
||||
// horizontal scroll Delta in pixels
|
||||
result = API.GetEventParameter(inEvent,
|
||||
EventParamName.MouseWheelSmoothHorizontalDelta, EventParamType.typeSInt32,
|
||||
IntPtr.Zero, (uint)sizeof(int), IntPtr.Zero, (IntPtr)d);
|
||||
|
||||
if (result == OSStatus.EventParameterNotFound) {
|
||||
// it's okay for it to be simply missing...
|
||||
} else if (result != OSStatus.NoError) {
|
||||
throw new MacOSException(result);
|
||||
} else {
|
||||
scrolldelta.deltaY = delta / 20.0f;
|
||||
}
|
||||
}
|
||||
|
||||
return scrolldelta;
|
||||
}
|
||||
|
||||
static internal int GetEventMouseWheelDelta(IntPtr inEvent)
|
||||
{
|
||||
int delta;
|
||||
|
|
|
@ -31,6 +31,9 @@ using System.Text;
|
|||
|
||||
namespace OpenTK.Platform.MacOS.Carbon
|
||||
{
|
||||
//
|
||||
// http://web.archive.org/web/20100501161453/http://www.classicteck.com/rbarticles/mackeyboard.php
|
||||
|
||||
enum MacOSKeyCode
|
||||
{
|
||||
A = 0,
|
||||
|
@ -90,6 +93,13 @@ namespace OpenTK.Platform.MacOS.Carbon
|
|||
Backspace = 51,
|
||||
Return = 52,
|
||||
Esc = 53,
|
||||
|
||||
Command = 55,
|
||||
Shift = 56,
|
||||
CapsLock = 57,
|
||||
OptionAlt = 58,
|
||||
Control = 59,
|
||||
|
||||
KeyPad_Decimal = 65,
|
||||
KeyPad_Multiply = 67,
|
||||
KeyPad_Add = 69,
|
||||
|
@ -107,6 +117,7 @@ namespace OpenTK.Platform.MacOS.Carbon
|
|||
KeyPad_7 = 89,
|
||||
KeyPad_8 = 91,
|
||||
KeyPad_9 = 92,
|
||||
|
||||
F1 = 122,
|
||||
F2 = 120,
|
||||
F3 = 99,
|
||||
|
|
|
@ -368,6 +368,7 @@ namespace OpenTK.Platform.MacOS
|
|||
break;
|
||||
}
|
||||
|
||||
OpenTK.Input.Key key;
|
||||
switch (evt.KeyboardEventKind)
|
||||
{
|
||||
case KeyboardEventKind.RawKeyRepeat:
|
||||
|
@ -376,25 +377,15 @@ namespace OpenTK.Platform.MacOS
|
|||
break;
|
||||
|
||||
case KeyboardEventKind.RawKeyDown:
|
||||
{
|
||||
OpenTK.Input.Key key;
|
||||
if (Keymap.TryGetValue(code, out key))
|
||||
{
|
||||
InputDriver.Keyboard[0][key] = true;
|
||||
OnKeyPress(mKeyPressArgs);
|
||||
}
|
||||
Keymap.TryGetValue(code, out key);
|
||||
InputDriver.Keyboard[0].SetKey(key, (uint)code, true);
|
||||
OnKeyPress(mKeyPressArgs);
|
||||
return OSStatus.NoError;
|
||||
}
|
||||
|
||||
case KeyboardEventKind.RawKeyUp:
|
||||
{
|
||||
OpenTK.Input.Key key;
|
||||
if (Keymap.TryGetValue(code, out key))
|
||||
{
|
||||
InputDriver.Keyboard[0][key] = false;
|
||||
}
|
||||
Keymap.TryGetValue(code, out key);
|
||||
InputDriver.Keyboard[0].SetKey(key, (uint)code, false);
|
||||
return OSStatus.NoError;
|
||||
}
|
||||
|
||||
case KeyboardEventKind.RawKeyModifiersChanged:
|
||||
ProcessModifierKey(inEvent);
|
||||
|
@ -519,9 +510,19 @@ namespace OpenTK.Platform.MacOS
|
|||
}
|
||||
return OSStatus.NoError;
|
||||
|
||||
case MouseEventKind.WheelMoved:
|
||||
float delta = API.GetEventMouseWheelDelta(inEvent);
|
||||
InputDriver.Mouse[0].WheelPrecise += delta;
|
||||
case MouseEventKind.WheelMoved: // older, integer resolution only
|
||||
{
|
||||
// this is really an int, we use a float to avoid clipping the wheel value
|
||||
float delta = API.GetEventMouseWheelDelta (inEvent);
|
||||
InputDriver.Mouse[0].WheelPrecise += delta;
|
||||
}
|
||||
return OSStatus.NoError;
|
||||
|
||||
case MouseEventKind.WheelScroll: // newer, more precise X and Y scroll
|
||||
{
|
||||
API.ScrollDelta delta = API.GetEventWheelScroll(inEvent);
|
||||
InputDriver.Mouse[0].WheelPrecise += delta.deltaY;
|
||||
}
|
||||
return OSStatus.NoError;
|
||||
|
||||
case MouseEventKind.MouseMoved:
|
||||
|
@ -614,21 +615,21 @@ namespace OpenTK.Platform.MacOS
|
|||
Debug.Print("Modifiers Changed: {0}", modifiers);
|
||||
|
||||
Input.KeyboardDevice keyboard = InputDriver.Keyboard[0];
|
||||
|
||||
|
||||
if (keyboard[OpenTK.Input.Key.AltLeft] ^ option)
|
||||
keyboard[OpenTK.Input.Key.AltLeft] = option;
|
||||
keyboard.SetKey(OpenTK.Input.Key.AltLeft, (uint)MacOSKeyCode.OptionAlt, option);
|
||||
|
||||
if (keyboard[OpenTK.Input.Key.ShiftLeft] ^ shift)
|
||||
keyboard[OpenTK.Input.Key.ShiftLeft] = shift;
|
||||
keyboard.SetKey(OpenTK.Input.Key.ShiftLeft, (uint)MacOSKeyCode.Shift, shift);
|
||||
|
||||
if (keyboard[OpenTK.Input.Key.WinLeft] ^ command)
|
||||
keyboard[OpenTK.Input.Key.WinLeft] = command;
|
||||
keyboard.SetKey(OpenTK.Input.Key.WinLeft, (uint)MacOSKeyCode.Command, command);
|
||||
|
||||
if (keyboard[OpenTK.Input.Key.ControlLeft] ^ control)
|
||||
keyboard[OpenTK.Input.Key.ControlLeft] = control;
|
||||
keyboard.SetKey(OpenTK.Input.Key.ControlLeft, (uint)MacOSKeyCode.Control, control);
|
||||
|
||||
if (keyboard[OpenTK.Input.Key.CapsLock] ^ caps)
|
||||
keyboard[OpenTK.Input.Key.CapsLock] = caps;
|
||||
keyboard.SetKey(OpenTK.Input.Key.CapsLock, (uint)MacOSKeyCode.CapsLock, caps);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace OpenTK.Platform.MacOS
|
|||
|
||||
// Requires Mac OS X 10.5 or higher.
|
||||
// Todo: create a driver for older installations. Maybe use CGGetLastMouseDelta for that?
|
||||
class HIDInput : IInputDriver2, IMouseDriver2, IKeyboardDriver2
|
||||
class HIDInput : IInputDriver2, IMouseDriver2, IKeyboardDriver2/*, IGamePadDriver*/
|
||||
{
|
||||
#region Fields
|
||||
|
||||
|
@ -124,7 +124,7 @@ namespace OpenTK.Platform.MacOS
|
|||
{
|
||||
if (!MouseDevices.ContainsKey(device))
|
||||
{
|
||||
Debug.Print("Mouse device {0} discovered", device);
|
||||
Debug.Print("Mouse device {0:x} discovered, sender is {1:x}", device, sender);
|
||||
MouseState state = new MouseState();
|
||||
state.IsConnected = true;
|
||||
MouseIndexToDevice.Add(MouseDevices.Count, device);
|
||||
|
@ -132,7 +132,7 @@ namespace OpenTK.Platform.MacOS
|
|||
}
|
||||
else
|
||||
{
|
||||
Debug.Print("Mouse device {0} reconnected", device);
|
||||
Debug.Print("Mouse device {0:x} reconnected, sender is {1:x}", device, sender);
|
||||
MouseState state = MouseDevices[device];
|
||||
state.IsConnected = true;
|
||||
MouseDevices[device] = state;
|
||||
|
@ -144,7 +144,7 @@ namespace OpenTK.Platform.MacOS
|
|||
{
|
||||
if (!KeyboardDevices.ContainsKey(device))
|
||||
{
|
||||
Debug.Print("Keyboard device {0} discovered", device);
|
||||
Debug.Print("Keyboard device {0:x} discovered, sender is {1:x}", device, sender);
|
||||
KeyboardState state = new KeyboardState();
|
||||
state.IsConnected = true;
|
||||
KeyboardIndexToDevice.Add(KeyboardDevices.Count, device);
|
||||
|
@ -152,15 +152,18 @@ namespace OpenTK.Platform.MacOS
|
|||
}
|
||||
else
|
||||
{
|
||||
Debug.Print("Keyboard device {0} reconnected", device);
|
||||
Debug.Print("Keyboard device {0:x} reconnected, sender is {1:x}", device, sender);
|
||||
KeyboardState state = KeyboardDevices[device];
|
||||
state.IsConnected = true;
|
||||
KeyboardDevices[device] = state;
|
||||
}
|
||||
}
|
||||
|
||||
// The device is not normally available in the InputValueCallback (HandleDeviceValueReceived), so we include
|
||||
// the device identifier as the context variable, so we can identify it and figure out the device later.
|
||||
// Thanks to Jase: http://www.opentk.com/node/2800
|
||||
NativeMethods.IOHIDDeviceRegisterInputValueCallback(device,
|
||||
HandleDeviceValueReceived, IntPtr.Zero);
|
||||
HandleDeviceValueReceived, device);
|
||||
NativeMethods.IOHIDDeviceScheduleWithRunLoop(device, RunLoop, InputLoopMode);
|
||||
}
|
||||
}
|
||||
|
@ -170,7 +173,7 @@ namespace OpenTK.Platform.MacOS
|
|||
if (NativeMethods.IOHIDDeviceConformsTo(device, HIDPage.GenericDesktop, (int)HIDUsageGD.Mouse) &&
|
||||
MouseDevices.ContainsKey(device))
|
||||
{
|
||||
Debug.Print("Mouse device {0} disconnected", device);
|
||||
Debug.Print("Mouse device {0:x} disconnected, sender is {1:x}", device, sender);
|
||||
|
||||
// Keep the device in case it comes back later on
|
||||
MouseState state = MouseDevices[device];
|
||||
|
@ -181,7 +184,7 @@ namespace OpenTK.Platform.MacOS
|
|||
if (NativeMethods.IOHIDDeviceConformsTo(device, HIDPage.GenericDesktop, (int)HIDUsageGD.Keyboard) &&
|
||||
KeyboardDevices.ContainsKey(device))
|
||||
{
|
||||
Debug.Print("Keyboard device {0} disconnected", device);
|
||||
Debug.Print("Keyboard device {0:x} disconnected, sender is {1:x}", device, sender);
|
||||
|
||||
// Keep the device in case it comes back later on
|
||||
KeyboardState state = KeyboardDevices[device];
|
||||
|
@ -197,13 +200,15 @@ namespace OpenTK.Platform.MacOS
|
|||
{
|
||||
MouseState mouse;
|
||||
KeyboardState keyboard;
|
||||
if (MouseDevices.TryGetValue(sender, out mouse))
|
||||
if (MouseDevices.TryGetValue(context, out mouse))
|
||||
{
|
||||
MouseDevices[sender] = UpdateMouse(mouse, val);
|
||||
MouseDevices[context] = UpdateMouse(mouse, val);
|
||||
}
|
||||
else if (KeyboardDevices.TryGetValue(sender, out keyboard))
|
||||
else if (KeyboardDevices.TryGetValue(context, out keyboard))
|
||||
{
|
||||
KeyboardDevices[sender] = UpdateKeyboard(keyboard, val);
|
||||
KeyboardDevices[context] = UpdateKeyboard(keyboard, val);
|
||||
}else{
|
||||
//Debug.Print ("Device {0:x} not found in list of keyboards or mice", sender);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,19 +254,21 @@ namespace OpenTK.Platform.MacOS
|
|||
int v_int = NativeMethods.IOHIDValueGetIntegerValue(val).ToInt32();
|
||||
HIDPage page = NativeMethods.IOHIDElementGetUsagePage(elem);
|
||||
int usage = NativeMethods.IOHIDElementGetUsage(elem);
|
||||
|
||||
// This will supress the debug printing below. Seems like it generates a lot of -1s.
|
||||
// Couldn't find any details in USB spec or Apple docs for this behavior.
|
||||
if(usage < 0 ) return state;
|
||||
|
||||
switch (page)
|
||||
switch (page)
|
||||
{
|
||||
case HIDPage.GenericDesktop:
|
||||
case HIDPage.KeyboardOrKeypad:
|
||||
int raw = (int)usage;
|
||||
if (raw >= RawKeyMap.Length || raw < 0)
|
||||
if (usage >= RawKeyMap.Length)
|
||||
{
|
||||
Debug.Print("[Warning] Key {0} not mapped.", raw);
|
||||
Debug.Print("[Warning] Key {0} not mapped.", usage);
|
||||
return state;
|
||||
}
|
||||
Key key = RawKeyMap[raw];
|
||||
state[key] = v_int != 0;
|
||||
state.SetKeyState(RawKeyMap[usage], (byte)usage, v_int != 0);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,11 @@ namespace OpenTK.Platform.MacOS
|
|||
{
|
||||
return InputDriver.MouseDriver;
|
||||
}
|
||||
|
||||
public virtual OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
||||
{
|
||||
return InputDriver.GamePadDriver;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -118,10 +118,10 @@ namespace OpenTK.Platform.MacOS
|
|||
Add(MacOSKeyCode.Key_2, Key.Number2);
|
||||
Add(MacOSKeyCode.Key_3, Key.Number3);
|
||||
Add(MacOSKeyCode.Key_4, Key.Number4);
|
||||
Add(MacOSKeyCode.Key_5, Key.Number4);
|
||||
Add(MacOSKeyCode.Key_6, Key.Number5);
|
||||
Add(MacOSKeyCode.Key_7, Key.Number6);
|
||||
Add(MacOSKeyCode.Key_8, Key.Number7);
|
||||
Add(MacOSKeyCode.Key_5, Key.Number5);
|
||||
Add(MacOSKeyCode.Key_6, Key.Number6);
|
||||
Add(MacOSKeyCode.Key_7, Key.Number7);
|
||||
Add(MacOSKeyCode.Key_8, Key.Number8);
|
||||
Add(MacOSKeyCode.Key_9, Key.Number9);
|
||||
// Numlock
|
||||
Add(MacOSKeyCode.O, Key.O);
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace OpenTK.Platform.Windows
|
|||
// Input driver for legacy (pre XP) Windows platforms.
|
||||
// Supports a single mouse and keyboard through async input.
|
||||
// Supports multiple joysticks through WinMM.
|
||||
sealed class WMInput : IInputDriver2, IMouseDriver2, IKeyboardDriver2, IGamePadDriver
|
||||
sealed class WMInput : IInputDriver2, IMouseDriver2, IKeyboardDriver2/*, IGamePadDriver*/ //HACK uncomment and implement
|
||||
{
|
||||
#region Fields
|
||||
|
||||
|
@ -70,14 +70,12 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
void UpdateKeyboard()
|
||||
{
|
||||
for (int i = 0; i < 256; i++)
|
||||
for (byte i = 0; i < byte.MaxValue; i++)
|
||||
{
|
||||
VirtualKeys key = (VirtualKeys)i;
|
||||
bool pressed = (Functions.GetAsyncKeyState(key) >> 8) != 0;
|
||||
if (KeyMap.ContainsKey(key))
|
||||
{
|
||||
keyboard[KeyMap[key]] = pressed;
|
||||
}
|
||||
bool pressed = (Functions.GetAsyncKeyState((VirtualKeys)i) >> 8) != 0;
|
||||
Key key;
|
||||
KeyMap.TryGetValue((VirtualKeys)i,out key);
|
||||
keyboard.SetKeyState(key, i, pressed);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,7 +109,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
public IGamePadDriver GamePadDriver
|
||||
{
|
||||
get { return this; }
|
||||
get { return null; } //HACK return this when implemented.
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -83,6 +83,11 @@ namespace OpenTK.Platform.Windows
|
|||
{
|
||||
return InputDriver.MouseDriver;
|
||||
}
|
||||
|
||||
public virtual OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
||||
{
|
||||
return InputDriver.GamePadDriver;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -89,7 +89,13 @@ namespace OpenTK.Platform.Windows
|
|||
IList<KeyboardDevice> keyboards = new List<KeyboardDevice>(1);
|
||||
IList<MouseDevice> mice = new List<MouseDevice>(1);
|
||||
const long ExtendedBit = 1 << 24; // Used to distinguish left and right control, alt and enter keys.
|
||||
static readonly uint ShiftRightScanCode = Functions.MapVirtualKey(VirtualKeys.RSHIFT, 0); // Used to distinguish left and right shift keys.
|
||||
|
||||
public static readonly uint ShiftLeftScanCode = Functions.MapVirtualKey(VirtualKeys.LSHIFT, 0);
|
||||
public static readonly uint ShiftRightScanCode = Functions.MapVirtualKey(VirtualKeys.RSHIFT, 0);
|
||||
public static readonly uint ControlLeftScanCode = Functions.MapVirtualKey(VirtualKeys.LCONTROL, 0);
|
||||
public static readonly uint ControlRightScanCode = Functions.MapVirtualKey(VirtualKeys.RCONTROL, 0);
|
||||
public static readonly uint AltLeftScanCode = Functions.MapVirtualKey(VirtualKeys.LMENU, 0);
|
||||
public static readonly uint AltRightScanCode = Functions.MapVirtualKey(VirtualKeys.RMENU, 0);
|
||||
|
||||
KeyPressEventArgs key_press = new KeyPressEventArgs((char)0);
|
||||
|
||||
|
@ -369,6 +375,8 @@ namespace OpenTK.Platform.Windows
|
|||
// In this case, both keys will be reported as pressed.
|
||||
|
||||
bool extended = (lParam.ToInt64() & ExtendedBit) != 0;
|
||||
uint scancode = (uint)((lParam.ToInt64() >> 16) & 0xFF);
|
||||
Key key = Key.Unknown;
|
||||
switch ((VirtualKeys)wParam)
|
||||
{
|
||||
case VirtualKeys.SHIFT:
|
||||
|
@ -382,55 +390,50 @@ namespace OpenTK.Platform.Windows
|
|||
// Otherwise, the state of one key might be stuck to pressed.
|
||||
if (ShiftRightScanCode != 0 && pressed)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
if (((lParam.ToInt64() >> 16) & 0xFF) == ShiftRightScanCode)
|
||||
keyboard[Input.Key.ShiftRight] = pressed;
|
||||
else
|
||||
keyboard[Input.Key.ShiftLeft] = pressed;
|
||||
}
|
||||
if (scancode == ShiftRightScanCode)
|
||||
key = Input.Key.ShiftRight;
|
||||
else
|
||||
key = Input.Key.ShiftLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Windows 9x and NT4.0 or key release event.
|
||||
keyboard[Input.Key.ShiftLeft] = keyboard[Input.Key.ShiftRight] = pressed;
|
||||
keyboard.SetKey(Input.Key.ShiftLeft, ShiftLeftScanCode, pressed);
|
||||
keyboard.SetKey(Input.Key.ShiftRight, ShiftRightScanCode, pressed);
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
break;
|
||||
|
||||
case VirtualKeys.CONTROL:
|
||||
if (extended)
|
||||
keyboard[Input.Key.ControlRight] = pressed;
|
||||
key = Input.Key.ControlRight;
|
||||
else
|
||||
keyboard[Input.Key.ControlLeft] = pressed;
|
||||
return IntPtr.Zero;
|
||||
key = Input.Key.ControlLeft;
|
||||
break;
|
||||
|
||||
case VirtualKeys.MENU:
|
||||
if (extended)
|
||||
keyboard[Input.Key.AltRight] = pressed;
|
||||
key = Input.Key.AltRight;
|
||||
else
|
||||
keyboard[Input.Key.AltLeft] = pressed;
|
||||
return IntPtr.Zero;
|
||||
key = Input.Key.AltLeft;
|
||||
break;
|
||||
|
||||
case VirtualKeys.RETURN:
|
||||
if (extended)
|
||||
keyboard[Key.KeypadEnter] = pressed;
|
||||
key = Key.KeypadEnter;
|
||||
else
|
||||
keyboard[Key.Enter] = pressed;
|
||||
return IntPtr.Zero;
|
||||
key = Key.Enter;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!KeyMap.ContainsKey((VirtualKeys)wParam))
|
||||
{
|
||||
Debug.Print("Virtual key {0} ({1}) not mapped.", (VirtualKeys)wParam, (long)lParam);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
keyboard[KeyMap[(VirtualKeys)wParam]] = pressed;
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
key = KeyMap[(VirtualKeys)wParam];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
keyboard.SetKey(key, scancode, pressed);
|
||||
return IntPtr.Zero;
|
||||
|
||||
case WindowMessage.SYSCHAR:
|
||||
return IntPtr.Zero;
|
||||
|
@ -727,7 +730,11 @@ namespace OpenTK.Platform.Windows
|
|||
}
|
||||
set
|
||||
{
|
||||
ClientSize = value.Size;
|
||||
WindowStyle style = (WindowStyle)Functions.GetWindowLong(window.WindowHandle, GetWindowLongOffsets.STYLE);
|
||||
Win32Rectangle rect = Win32Rectangle.From(value);
|
||||
Functions.AdjustWindowRect(ref rect, style, false);
|
||||
Location = new Point(rect.left, rect.top);
|
||||
Size = new Size(rect.Width, rect.Height);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace OpenTK.Platform.Windows
|
|||
if ((caps.Capabilities & JoystCapsFlags.HasPov) != 0)
|
||||
num_axes += 2;
|
||||
|
||||
stick = new JoystickDevice<WinMMJoyDetails>(number, num_axes, caps.NumButtons);
|
||||
stick = new JoystickDevice<WinMMJoyDetails>(number, num_axes, caps.NumButtons);
|
||||
stick.Details = new WinMMJoyDetails(num_axes);
|
||||
|
||||
// Make sure to reverse the vertical axes, so that +1 points up and -1 points down.
|
||||
|
@ -427,5 +427,21 @@ namespace OpenTK.Platform.Windows
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//HACK implement
|
||||
public GamePadState GetState()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public GamePadState GetState(int index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetDeviceName(int index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,16 @@ namespace OpenTK.Platform.Windows
|
|||
// keyboard device by qeurying the registry.
|
||||
RegistryKey regkey = GetRegistryKey(name);
|
||||
string deviceDesc = (string)regkey.GetValue("DeviceDesc");
|
||||
|
||||
string deviceClass = (string)regkey.GetValue("Class");
|
||||
|
||||
string deviceClassGUID = (string)regkey.GetValue("ClassGUID"); // for windows 8 support via OpenTK issue 3198
|
||||
|
||||
// making a guess at backwards compatability. Not sure what older windows returns in these cases...
|
||||
if(deviceClass == null || deviceClass.Equals(string.Empty)){
|
||||
RegistryKey classGUIDKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\" + deviceClassGUID);
|
||||
deviceClass = classGUIDKey != null ? (string) classGUIDKey.GetValue("Class") : string.Empty;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(deviceDesc))
|
||||
{
|
||||
|
@ -171,31 +180,30 @@ namespace OpenTK.Platform.Windows
|
|||
switch (rin.Data.Keyboard.VKey)
|
||||
{
|
||||
case VirtualKeys.SHIFT:
|
||||
keyboard[Input.Key.ShiftLeft] = keyboard[Input.Key.ShiftRight] = pressed;
|
||||
keyboard.SetKeyState(Key.ShiftLeft, (byte)WinGLNative.ShiftLeftScanCode, pressed);
|
||||
keyboard.SetKeyState(Key.ShiftRight, (byte)WinGLNative.ShiftRightScanCode, pressed);
|
||||
processed = true;
|
||||
break;
|
||||
|
||||
case VirtualKeys.CONTROL:
|
||||
keyboard[Input.Key.ControlLeft] = keyboard[Input.Key.ControlRight] = pressed;
|
||||
keyboard.SetKeyState(Key.ControlLeft, (byte)WinGLNative.ControlLeftScanCode, pressed);
|
||||
keyboard.SetKeyState(Key.ControlRight, (byte)WinGLNative.ControlRightScanCode, pressed);
|
||||
processed = true;
|
||||
break;
|
||||
|
||||
case VirtualKeys.MENU:
|
||||
keyboard[Input.Key.AltLeft] = keyboard[Input.Key.AltRight] = pressed;
|
||||
keyboard.SetKeyState(Key.AltLeft, (byte)WinGLNative.AltLeftScanCode, pressed);
|
||||
keyboard.SetKeyState(Key.AltRight, (byte)WinGLNative.AltRightScanCode, pressed);
|
||||
processed = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!KeyMap.ContainsKey(rin.Data.Keyboard.VKey))
|
||||
{
|
||||
Debug.Print("Virtual key {0} ({1}) not mapped.",
|
||||
rin.Data.Keyboard.VKey, (int)rin.Data.Keyboard.VKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
keyboard[KeyMap[rin.Data.Keyboard.VKey]] = pressed;
|
||||
processed = true;
|
||||
}
|
||||
Key key;
|
||||
KeyMap.TryGetValue(rin.Data.Keyboard.VKey, out key);
|
||||
if (key == Key.Unknown)
|
||||
Debug.Print("Virtual key {0} ({1}) not mapped.", rin.Data.Keyboard.VKey, (int)rin.Data.Keyboard.VKey);
|
||||
keyboard.SetKeyState(key, BitConverter.GetBytes(rin.Data.Keyboard.MakeCode)[0], pressed);
|
||||
processed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,15 @@ namespace OpenTK.Platform.Windows
|
|||
// mouse device by qeurying the registry.
|
||||
RegistryKey regkey = FindRegistryKey(name);
|
||||
string deviceDesc = (string)regkey.GetValue("DeviceDesc");
|
||||
string deviceClass = (string)regkey.GetValue("Class");
|
||||
|
||||
|
||||
string deviceClass = (string)regkey.GetValue("Class") as string;
|
||||
if(deviceClass == null){
|
||||
// Added to address OpenTK issue 3198 with mouse on Windows 8
|
||||
string deviceClassGUID = (string)regkey.GetValue("ClassGUID");
|
||||
RegistryKey classGUIDKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\" + deviceClassGUID);
|
||||
deviceClass = classGUIDKey != null ? (string) classGUIDKey.GetValue("Class") : string.Empty;
|
||||
}
|
||||
deviceDesc = deviceDesc.Substring(deviceDesc.LastIndexOf(';') + 1);
|
||||
|
||||
if (!String.IsNullOrEmpty(deviceClass) && deviceClass.ToLower().Equals("mouse"))
|
||||
|
@ -158,16 +166,56 @@ namespace OpenTK.Platform.Windows
|
|||
int mouse_handle = rawids.ContainsKey(handle) ? rawids[handle] : 0;
|
||||
mouse = mice[mouse_handle];
|
||||
|
||||
if ((raw.ButtonFlags & RawInputMouseState.LEFT_BUTTON_DOWN) != 0) mouse.EnableBit((int)MouseButton.Left);
|
||||
if ((raw.ButtonFlags & RawInputMouseState.LEFT_BUTTON_UP) != 0) mouse.DisableBit((int)MouseButton.Left);
|
||||
if ((raw.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_DOWN) != 0) mouse.EnableBit((int)MouseButton.Right);
|
||||
if ((raw.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_UP) != 0) mouse.DisableBit((int)MouseButton.Right);
|
||||
if ((raw.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_DOWN) != 0) mouse.EnableBit((int)MouseButton.Middle);
|
||||
if ((raw.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_UP) != 0) mouse.DisableBit((int)MouseButton.Middle);
|
||||
if ((raw.ButtonFlags & RawInputMouseState.BUTTON_4_DOWN) != 0) mouse.EnableBit((int)MouseButton.Button1);
|
||||
if ((raw.ButtonFlags & RawInputMouseState.BUTTON_4_UP) != 0) mouse.DisableBit((int)MouseButton.Button1);
|
||||
if ((raw.ButtonFlags & RawInputMouseState.BUTTON_5_DOWN) != 0) mouse.EnableBit((int)MouseButton.Button2);
|
||||
if ((raw.ButtonFlags & RawInputMouseState.BUTTON_5_UP) != 0) mouse.DisableBit((int)MouseButton.Button2);
|
||||
// Set and release capture of the mouse to fix http://www.opentk.com/node/2133, Patch by Artfunkel
|
||||
if ((raw.ButtonFlags & RawInputMouseState.LEFT_BUTTON_DOWN) != 0){
|
||||
mouse.EnableBit((int)MouseButton.Left);
|
||||
Functions.SetCapture(Window);
|
||||
}
|
||||
if ((raw.ButtonFlags & RawInputMouseState.LEFT_BUTTON_UP) != 0)
|
||||
{
|
||||
mouse.DisableBit((int)MouseButton.Left);
|
||||
Functions.ReleaseCapture();
|
||||
}
|
||||
if ((raw.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_DOWN) != 0)
|
||||
{
|
||||
mouse.EnableBit((int)MouseButton.Right);
|
||||
Functions.SetCapture(Window);
|
||||
}
|
||||
if ((raw.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_UP) != 0)
|
||||
{
|
||||
mouse.DisableBit((int)MouseButton.Right);
|
||||
Functions.ReleaseCapture();
|
||||
}
|
||||
if ((raw.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_DOWN) != 0)
|
||||
{
|
||||
mouse.EnableBit((int)MouseButton.Middle);
|
||||
Functions.SetCapture(Window);
|
||||
}
|
||||
if ((raw.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_UP) != 0)
|
||||
{
|
||||
mouse.DisableBit((int)MouseButton.Middle);
|
||||
Functions.ReleaseCapture();
|
||||
}
|
||||
if ((raw.ButtonFlags & RawInputMouseState.BUTTON_4_DOWN) != 0)
|
||||
{
|
||||
mouse.EnableBit((int)MouseButton.Button1);
|
||||
Functions.SetCapture(Window);
|
||||
}
|
||||
if ((raw.ButtonFlags & RawInputMouseState.BUTTON_4_UP) != 0)
|
||||
{
|
||||
mouse.DisableBit((int)MouseButton.Button1);
|
||||
Functions.ReleaseCapture();
|
||||
}
|
||||
if ((raw.ButtonFlags & RawInputMouseState.BUTTON_5_DOWN) != 0)
|
||||
{
|
||||
mouse.EnableBit((int)MouseButton.Button2);
|
||||
Functions.SetCapture(Window);
|
||||
}
|
||||
if ((raw.ButtonFlags & RawInputMouseState.BUTTON_5_UP) != 0)
|
||||
{
|
||||
mouse.DisableBit((int)MouseButton.Button2);
|
||||
Functions.ReleaseCapture();
|
||||
}
|
||||
|
||||
if ((raw.ButtonFlags & RawInputMouseState.WHEEL) != 0)
|
||||
mouse.WheelPrecise += (short)raw.ButtonData / 120.0f;
|
||||
|
|
|
@ -91,6 +91,11 @@ namespace OpenTK.Platform.X11
|
|||
return new X11Mouse(); // Always supported.
|
||||
}
|
||||
|
||||
public virtual OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
||||
{
|
||||
return new X11Joystick();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -994,6 +994,8 @@ namespace OpenTK.Platform.X11
|
|||
{
|
||||
using (new XLock(window.Display))
|
||||
{
|
||||
Functions.XMoveWindow(window.Display, window.WindowHandle,
|
||||
value.X, value.Y);
|
||||
Functions.XResizeWindow(window.Display, window.WindowHandle,
|
||||
value.Width, value.Height);
|
||||
}
|
||||
|
|
|
@ -157,20 +157,22 @@ namespace OpenTK.Platform.X11
|
|||
case XEventName.KeyPress:
|
||||
case XEventName.KeyRelease:
|
||||
bool pressed = e.type == XEventName.KeyPress;
|
||||
XKey keysym = (XKey)API.LookupKeysym(ref e.KeyEvent, 0);
|
||||
XKey keysym2 = (XKey)API.LookupKeysym(ref e.KeyEvent, 1);
|
||||
Key key = Key.Unknown;
|
||||
|
||||
IntPtr keysym = API.LookupKeysym(ref e.KeyEvent, 0);
|
||||
IntPtr keysym2 = API.LookupKeysym(ref e.KeyEvent, 1);
|
||||
|
||||
if (keymap.ContainsKey((XKey)keysym))
|
||||
keyboard[keymap[(XKey)keysym]] = pressed;
|
||||
else if (keymap.ContainsKey((XKey)keysym2))
|
||||
keyboard[keymap[(XKey)keysym2]] = pressed;
|
||||
if (keymap.ContainsKey(keysym))
|
||||
key = keymap[keysym];
|
||||
else if (keymap.ContainsKey(keysym2))
|
||||
key = keymap[keysym2];
|
||||
else
|
||||
Debug.Print("KeyCode {0} (Keysym: {1}, {2}) not mapped.", e.KeyEvent.keycode, (XKey)keysym, (XKey)keysym2);
|
||||
|
||||
keyboard.SetKey(key, (uint)e.KeyEvent.keycode, pressed);
|
||||
break;
|
||||
|
||||
case XEventName.ButtonPress:
|
||||
if (e.ButtonEvent.button == 1) mouse[OpenTK.Input.MouseButton.Left] = true;
|
||||
if (e.ButtonEvent.button == 1) mouse[OpenTK.Input.MouseButton.Left] = true;
|
||||
else if (e.ButtonEvent.button == 2) mouse[OpenTK.Input.MouseButton.Middle] = true;
|
||||
else if (e.ButtonEvent.button == 3) mouse[OpenTK.Input.MouseButton.Right] = true;
|
||||
else if (e.ButtonEvent.button == 4) mouse.Wheel++;
|
||||
|
@ -190,7 +192,7 @@ namespace OpenTK.Platform.X11
|
|||
break;
|
||||
|
||||
case XEventName.ButtonRelease:
|
||||
if (e.ButtonEvent.button == 1) mouse[OpenTK.Input.MouseButton.Left] = false;
|
||||
if (e.ButtonEvent.button == 1) mouse[OpenTK.Input.MouseButton.Left] = false;
|
||||
else if (e.ButtonEvent.button == 2) mouse[OpenTK.Input.MouseButton.Middle] = false;
|
||||
else if (e.ButtonEvent.button == 3) mouse[OpenTK.Input.MouseButton.Right] = false;
|
||||
else if (e.ButtonEvent.button == 6) mouse[OpenTK.Input.MouseButton.Button1] = false;
|
||||
|
|
|
@ -29,13 +29,14 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace OpenTK.Platform.X11
|
||||
{
|
||||
struct X11JoyDetails { }
|
||||
|
||||
sealed class X11Joystick : IJoystickDriver
|
||||
sealed class X11Joystick : IJoystickDriver, IGamePadDriver
|
||||
{
|
||||
#region Fields
|
||||
|
||||
|
@ -58,8 +59,8 @@ namespace OpenTK.Platform.X11
|
|||
JoystickDevice stick = OpenJoystick(JoystickPath, number++);
|
||||
if (stick != null)
|
||||
{
|
||||
stick.Description = String.Format("USB Joystick {0} ({1} axes, {2} buttons, {3}{0})",
|
||||
number, stick.Axis.Count, stick.Button.Count, JoystickPath);
|
||||
//stick.Description = String.Format("USB Joystick {0} ({1} axes, {2} buttons, {3}{0})",
|
||||
//number, stick.Axis.Count, stick.Button.Count, JoystickPath);
|
||||
sticks.Add(stick);
|
||||
}
|
||||
}
|
||||
|
@ -70,8 +71,8 @@ namespace OpenTK.Platform.X11
|
|||
JoystickDevice stick = OpenJoystick(JoystickPathLegacy, number++);
|
||||
if (stick != null)
|
||||
{
|
||||
stick.Description = String.Format("USB Joystick {0} ({1} axes, {2} buttons, {3}{0})",
|
||||
number, stick.Axis.Count, stick.Button.Count, JoystickPathLegacy);
|
||||
//stick.Description = String.Format("USB Joystick {0} ({1} axes, {2} buttons, {3}{0})",
|
||||
//number, stick.Axis.Count, stick.Button.Count, JoystickPathLegacy);
|
||||
sticks.Add(stick);
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +89,7 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
public IList<JoystickDevice> Joysticks
|
||||
{
|
||||
get { return sticks_readonly; }
|
||||
get { Poll(); return sticks_readonly; }
|
||||
}
|
||||
|
||||
public void Poll()
|
||||
|
@ -153,6 +154,11 @@ namespace OpenTK.Platform.X11
|
|||
UnsafeNativeMethods.ioctl(fd, JoystickIoctlCode.Buttons, ref buttons);
|
||||
|
||||
stick = new JoystickDevice<X11JoyDetails>(fd, axes, buttons);
|
||||
|
||||
StringBuilder sb = new StringBuilder(128);
|
||||
UnsafeNativeMethods.ioctl(fd, JoystickIoctlCode.Name128, sb);
|
||||
stick.Description = sb.ToString();
|
||||
|
||||
Debug.Print("Found joystick on path {0}", path);
|
||||
}
|
||||
finally
|
||||
|
@ -186,7 +192,8 @@ namespace OpenTK.Platform.X11
|
|||
{
|
||||
Version = 0x80046a01,
|
||||
Axes = 0x80016a11,
|
||||
Buttons = 0x80016a12
|
||||
Buttons = 0x80016a12,
|
||||
Name128 = (2u << 30) | (0x6A << 8) | (0x13 << 0) | (128 << 16) //JSIOCGNAME(128), which is _IOC(_IO_READ, 'j', 0x13, len)
|
||||
}
|
||||
|
||||
static readonly string JoystickPath = "/dev/input/js";
|
||||
|
@ -203,6 +210,9 @@ namespace OpenTK.Platform.X11
|
|||
[DllImport("libc", SetLastError = true)]
|
||||
public static extern int ioctl(int d, JoystickIoctlCode request, ref int data);
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
public static extern int ioctl(int d, JoystickIoctlCode request, StringBuilder data);
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
public static extern int open([MarshalAs(UnmanagedType.LPStr)]string pathname, OpenFlags flags);
|
||||
|
||||
|
@ -248,5 +258,22 @@ namespace OpenTK.Platform.X11
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//HACK implement
|
||||
public GamePadState GetState()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public GamePadState GetState(int index)
|
||||
{
|
||||
Poll();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetDeviceName(int index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue