├── .gitignore ├── .travis.yml ├── AUTHORS.md ├── Build ├── CI │ ├── MonoGame │ │ └── packages.config │ ├── OpenTK │ │ └── packages.config │ ├── SharpDX │ │ └── packages.config │ └── Standalone │ │ └── packages.config ├── CoreOnly.proj ├── NuGet │ ├── .gitignore │ ├── SharpNav.MonoGame.nuspec │ ├── SharpNav.OpenTK.nuspec │ ├── SharpNav.SharpDX.nuspec │ ├── SharpNav.nuspec │ ├── clean-nuget.ps1 │ ├── clean-nuget.sh │ ├── publish-nuget.ps1 │ └── publish-nuget.sh └── build-docs.sh ├── CONTRIBUTING.md ├── Dependencies ├── Gwen.Renderer.OpenTK.dll └── Gwen.dll ├── Documentation ├── README.md ├── Release Notes │ ├── v0.9.0.md │ ├── v1.0.0-alpha.1.md │ └── v1.0.0-alpha.2.md ├── Styles │ └── SharpNav │ │ ├── css │ │ └── sharpdoc.css │ │ ├── html │ │ └── PageHeader.cshtml │ │ ├── images │ │ └── blacktocat.png │ │ ├── js │ │ └── sharpdoc.js │ │ └── style.xml ├── config.xml ├── overview.md └── release-notes.md ├── Graphics └── Logo │ ├── Full.png │ ├── FullWhite.png │ ├── Logo.ico │ ├── Logo.pdf │ ├── LogoOnly.png │ └── NuGet.png ├── LICENSE ├── README.md ├── Source ├── SharpNav.CLI │ ├── App.config │ ├── Log.cs │ ├── ObjModel.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SharpNav.CLI.csproj │ ├── SharpNav.CLI.snk │ ├── Verbosity.cs │ └── packages.config ├── SharpNav.Examples │ ├── .gitignore │ ├── AgentCylinder.cs │ ├── App.config │ ├── Camera.cs │ ├── ExampleWindow.Drawing.cs │ ├── ExampleWindow.UI.cs │ ├── ExampleWindow.cs │ ├── GwenSkin.png │ ├── GwenTextWriter.cs │ ├── ObjModel.cs │ ├── OpenTK.dll.config │ ├── Program.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ └── Resources.resx │ ├── SharpNav.Examples.csproj │ ├── example_ply.ply │ ├── nav_test.obj │ └── packages.config ├── SharpNav.GUI │ ├── App.config │ ├── ConfigurationForm.Designer.cs │ ├── ConfigurationForm.cs │ ├── ConfigurationForm.resx │ ├── ObjModel.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SharpNav.GUI.csproj │ └── SharpNav.GUI.snk ├── SharpNav.Tests │ ├── .gitignore │ ├── CellTests.cs │ ├── Collections │ │ └── Generic │ │ │ ├── BufferedQueueTests.cs │ │ │ ├── BufferedStackTests.cs │ │ │ └── PriorityQueueTests.cs │ ├── CompactHeightfieldTests.cs │ ├── CompactSpanTests.cs │ ├── ContourTests.cs │ ├── Geometry │ │ ├── ContainmentTests.cs │ │ ├── DistanceTests.cs │ │ └── IntersectionTests.cs │ ├── HeightfieldTests.cs │ ├── IO │ │ └── Json │ │ │ └── NavMeshJsonSerializerTests.cs │ ├── JsonTest.cs │ ├── MathHelperTests.cs │ ├── ObjModel.cs │ ├── OpenTK.dll.config │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── RegionTests.cs │ ├── SharpNav.Tests.csproj │ ├── SharpNav.Tests.snk │ ├── nav_test.obj │ └── packages.config ├── SharpNav.sln └── SharpNav │ ├── Area.cs │ ├── AreaGenerator.cs │ ├── Cell.cs │ ├── Collections │ ├── BVTree.cs │ └── Generic │ │ ├── BufferedQueue.cs │ │ ├── BufferedStack.cs │ │ ├── IValueWithCost.cs │ │ ├── PriorityQueue.cs │ │ └── ProximityGrid.cs │ ├── CompactCell.cs │ ├── CompactHeightfield.cs │ ├── CompactSpan.cs │ ├── CompactSpanReference.cs │ ├── Contour.cs │ ├── ContourBuildFlags.cs │ ├── ContourSet.cs │ ├── ContourVertex.cs │ ├── Crowds │ ├── Agent.cs │ ├── Crowd.cs │ ├── CrowdAgentState.cs │ ├── LocalBoundary.cs │ ├── ObstacleAvoidanceQuery.cs │ ├── PathCorridor.cs │ ├── PathQueue.cs │ ├── Status.cs │ ├── TargetState.cs │ └── UpdateFlags.cs │ ├── Direction.cs │ ├── EdgeFlags.cs │ ├── Geometry │ ├── BBox2i.cs │ ├── BBox3.cs │ ├── Containment.cs │ ├── Distance.cs │ ├── Intersection.cs │ ├── Triangle3.cs │ ├── TriangleEnumerable.cs │ ├── Vector2.cs │ ├── Vector2i.cs │ ├── Vector3.cs │ └── Vector3Extensions.cs │ ├── HeightPatch.cs │ ├── Heightfield.Rasterization.cs │ ├── Heightfield.cs │ ├── IO │ ├── Json │ │ ├── AreaConverter.cs │ │ ├── NavMeshJsonSerializer.cs │ │ ├── PolyIdConverter.cs │ │ └── Vector3Converter.cs │ ├── NavMeshConfigurationFile.cs │ └── NavMeshSerializer.cs │ ├── MathHelper.cs │ ├── NavMesh.cs │ ├── NavMeshBuilder.cs │ ├── NavMeshGenerationSettings.cs │ ├── NavMeshQuery.cs │ ├── NodeFlags.cs │ ├── NodePool.cs │ ├── OpenTK.dll.config │ ├── Pathfinding │ ├── BoundarySide.cs │ ├── FindPathOptions.cs │ ├── Link.cs │ ├── NavNode.cs │ ├── NavPoint.cs │ ├── NavPoly.cs │ ├── NavPolyId.cs │ ├── NavPolyIdManager.cs │ ├── NavQueryFilter.cs │ ├── NavTile.cs │ ├── OffMeshConnection.cs │ ├── Path.cs │ ├── PathBuildFlags.cs │ ├── PathfindingCommon.cs │ ├── RaycastHit.cs │ ├── RaycastOptions.cs │ └── StraightPathFlags.cs │ ├── PolyBounds.cs │ ├── PolyMesh.cs │ ├── PolyMeshDetail.cs │ ├── PolyVertex.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Region.cs │ ├── Settings.StyleCop │ ├── SharpNav.OpenTK.snk │ ├── SharpNav.SharpDX.snk │ ├── SharpNav.csproj │ ├── SharpNav.snk │ ├── Span.cs │ ├── SpanReference.cs │ ├── TiledNavMesh.cs │ └── packages.config └── appveyor.yml /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | [Bb]inaries/ 5 | 6 | # mstest test results 7 | TestResults 8 | 9 | # Ignore diagrams 10 | *.dgml 11 | 12 | ## Ignore Visual Studio temporary files, build results, and 13 | ## files generated by popular Visual Studio add-ons. 14 | 15 | # User-specific files 16 | *.suo 17 | *.user 18 | *.sln.docstates 19 | *.userprefs 20 | 21 | # Build results 22 | [Dd]ebug/ 23 | [Rr]elease/ 24 | x64/ 25 | *_i.c 26 | *_p.c 27 | *.ilk 28 | *.meta 29 | *.obj 30 | *.pch 31 | *.pdb 32 | *.pgc 33 | *.pgd 34 | *.rsp 35 | *.sbr 36 | *.tlb 37 | *.tli 38 | *.tlh 39 | *.tmp 40 | *.log 41 | *.vspscc 42 | *.vssscc 43 | .builds 44 | 45 | # Visual C++ cache files 46 | ipch/ 47 | *.aps 48 | *.ncb 49 | *.opensdf 50 | *.sdf 51 | 52 | # Visual Studio profiler 53 | *.psess 54 | *.vsp 55 | *.vspx 56 | 57 | # Guidance Automation Toolkit 58 | *.gpState 59 | 60 | # ReSharper is a .NET coding add-in 61 | _ReSharper* 62 | 63 | # NCrunch 64 | *.ncrunch* 65 | .*crunch*.local.xml 66 | 67 | # Installshield output folder 68 | [Ee]xpress 69 | 70 | # DocProject is a documentation generator add-in 71 | DocProject/buildhelp/ 72 | DocProject/Help/*.HxT 73 | DocProject/Help/*.HxC 74 | DocProject/Help/*.hhc 75 | DocProject/Help/*.hhk 76 | DocProject/Help/*.hhp 77 | DocProject/Help/Html2 78 | DocProject/Help/html 79 | 80 | # Click-Once directory 81 | publish 82 | 83 | # Publish Web Output 84 | *.Publish.xml 85 | 86 | # NuGet Packages Directory 87 | packages 88 | 89 | # Windows Azure Build Output 90 | csx 91 | *.build.csdef 92 | 93 | # Windows Store app package directory 94 | AppPackages/ 95 | 96 | # Others 97 | [Bb]in 98 | [Oo]bj 99 | sql 100 | TestResults 101 | [Tt]est[Rr]esult* 102 | *.Cache 103 | ClientBin 104 | [Ss]tyle[Cc]op.* 105 | ~$* 106 | *.dbmdl 107 | Generated_Code #added for RIA/Silverlight projects 108 | 109 | # Backup & report files from converting an old project file to a newer 110 | # Visual Studio version. Backup files are not needed, because we have git ;-) 111 | _UpgradeReport_Files/ 112 | Backup*/ 113 | UpgradeLog*.XML 114 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | solution: Source/SharpNav.sln 3 | sudo: false # Use container-based infrastructure 4 | 5 | notifications: 6 | slack: 7 | secure: Evj0iL40Tipu47BZfCdbkZbW/8Y7NLRZRSjvLXhKH7Yc6DfYLWeF7+Y2h8E8Zdd2/bdP+LxlHTbqjam5IBONAAIwpN4TAXNqMmalXtXDfs3/Cu+pMKSN+ECymcX3bUa/cZyvjm8P4FfUWLDHKuk+I3C41DfXzTPRBg4z+qSg4kI= 8 | 9 | env: 10 | matrix: 11 | - XBUILD_TARGET=Standalone 12 | - XBUILD_TARGET=OpenTK 13 | - XBUILD_TARGET=SharpDX 14 | - XBUILD_TARGET=MonoGame 15 | 16 | install: 17 | - travis_retry nuget restore Build/CI/$XBUILD_TARGET/packages.config -SolutionDirectory Source/ 18 | - travis_retry nuget install NUnit.Console -OutputDirectory test -ExcludeVersion 19 | script: 20 | - xbuild /t:$XBUILD_TARGET /verbosity:minimal ./Build/CoreOnly.proj 21 | - mono ./test/NUnit.ConsoleRunner/tools/nunit3-console.exe ./Binaries/Tests/$XBUILD_TARGET/SharpNav.Tests.dll --where "cat!=BrokenButUnused" 22 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | SharpNav Contributors 2 | ===================== 3 | 4 | (Sorted chronologically) 5 | 6 | - **[Robert Rouhani](https://github.com/Robmaister)** 7 | - Original author 8 | - Maintainer 9 | 10 | - **[Samuel Yuan](https://github.com/samuelyuan)** 11 | - Ported majority of Recast to C# 12 | 13 | - **[Renjie Xie](https://github.com/xrj800)** 14 | - Ported parts of Recast to C# 15 | - Added several missing test cases. 16 | 17 | See the [full list of contributors](https://github.com/Robmaister/SharpNav/graphs/contributors) 18 | -------------------------------------------------------------------------------- /Build/CI/MonoGame/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Build/CI/OpenTK/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Build/CI/SharpDX/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Build/CI/Standalone/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Build/CoreOnly.proj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Build/NuGet/.gitignore: -------------------------------------------------------------------------------- 1 | # Don't commit the NuGet files, they are generated by the build script. 2 | *.nupkg -------------------------------------------------------------------------------- /Build/NuGet/SharpNav.MonoGame.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SharpNav.MonoGame 5 | 1.0.0-alpha2 6 | Robert Rouhani 7 | Robert Rouhani 8 | https://raw.githubusercontent.com/Robmaister/SharpNav/master/Graphics/Logo/NuGet.png 9 | https://github.com/Robmaister/SharpNav/blob/master/LICENSE 10 | https://github.com/Robmaister/SharpNav 11 | false 12 | A fully-managed navigation mesh library. 13 | 14 | - JSON serialization for NavMesh 15 | - Started refactoring and cleaning up pathfinding and crowd APIs 16 | - Fixed a few crowd bugs 17 | 18 | For the full release notes, see http://sharpnav.com/docs/html/index.htm?page=release-notes-v1.0.0-alpha.2 19 | 20 | Copyright (c) 2013-2016 Robert Rouhani <robert.rouhani@gmail.com> and other contributors (see CONTRIBUTORS file). 21 | Navigation Pathfinding NavMesh Nav Mesh Crowd Agent AI Recast 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Build/NuGet/SharpNav.OpenTK.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SharpNav.OpenTK 5 | 1.0.0-alpha2 6 | Robert Rouhani 7 | Robert Rouhani 8 | https://raw.githubusercontent.com/Robmaister/SharpNav/master/Graphics/Logo/NuGet.png 9 | https://github.com/Robmaister/SharpNav/blob/master/LICENSE 10 | https://github.com/Robmaister/SharpNav 11 | false 12 | A fully-managed navigation mesh library. 13 | 14 | - JSON serialization for NavMesh 15 | - Started refactoring and cleaning up pathfinding and crowd APIs 16 | - Fixed a few crowd bugs 17 | 18 | For the full release notes, see http://sharpnav.com/docs/html/index.htm?page=release-notes-v1.0.0-alpha.2 19 | 20 | Copyright (c) 2013-2016 Robert Rouhani <robert.rouhani@gmail.com> and other contributors (see CONTRIBUTORS file). 21 | Navigation Pathfinding NavMesh Nav Mesh Crowd Agent AI Recast 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Build/NuGet/SharpNav.SharpDX.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SharpNav.SharpDX 5 | 1.0.0-alpha2 6 | Robert Rouhani 7 | Robert Rouhani 8 | https://raw.githubusercontent.com/Robmaister/SharpNav/master/Graphics/Logo/NuGet.png 9 | https://github.com/Robmaister/SharpNav/blob/master/LICENSE 10 | https://github.com/Robmaister/SharpNav 11 | false 12 | A fully-managed navigation mesh library. 13 | 14 | - JSON serialization for NavMesh 15 | - Started refactoring and cleaning up pathfinding and crowd APIs 16 | - Fixed a few crowd bugs 17 | 18 | For the full release notes, see http://sharpnav.com/docs/html/index.htm?page=release-notes-v1.0.0-alpha.2 19 | 20 | Copyright (c) 2013-2016 Robert Rouhani <robert.rouhani@gmail.com> and other contributors (see CONTRIBUTORS file). 21 | Navigation Pathfinding NavMesh Nav Mesh Crowd Agent AI Recast 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Build/NuGet/SharpNav.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SharpNav 5 | 1.0.0-alpha2 6 | Robert Rouhani 7 | Robert Rouhani 8 | https://raw.githubusercontent.com/Robmaister/SharpNav/master/Graphics/Logo/NuGet.png 9 | https://github.com/Robmaister/SharpNav/blob/master/LICENSE 10 | https://github.com/Robmaister/SharpNav 11 | false 12 | A fully-managed navigation mesh library. 13 | 14 | - JSON serialization for NavMesh 15 | - Started refactoring and cleaning up pathfinding and crowd APIs 16 | - Fixed a few crowd bugs 17 | 18 | For the full release notes, see http://sharpnav.com/docs/html/index.htm?page=release-notes-v1.0.0-alpha.2 19 | 20 | Copyright (c) 2013-2016 Robert Rouhani <robert.rouhani@gmail.com> and other contributors (see CONTRIBUTORS file). 21 | Navigation Pathfinding NavMesh Nav Mesh Crowd Agent AI Recast 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Build/NuGet/clean-nuget.ps1: -------------------------------------------------------------------------------- 1 | "" 2 | " CLEANING " 3 | "=========================================" 4 | "" 5 | 6 | Remove-Item *.nupkg 7 | 8 | "" 9 | "Done." 10 | "" 11 | -------------------------------------------------------------------------------- /Build/NuGet/clean-nuget.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "" 4 | echo " CLEANING " 5 | echo "=========================================" 6 | echo "" 7 | 8 | rm ./*.nupkg 9 | 10 | echo "" 11 | echo "Done." 12 | echo "" 13 | -------------------------------------------------------------------------------- /Build/NuGet/publish-nuget.ps1: -------------------------------------------------------------------------------- 1 | $msbuild = "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" 2 | $buildfile = "../CoreOnly.proj" 3 | $configs = "Standalone", "OpenTK", "MonoGame", "SharpDX" 4 | 5 | "" 6 | " BUILDING " 7 | "=========================================" 8 | "" 9 | foreach ($config in $configs) { 10 | $config 11 | "---------------------------" 12 | &$msbuild ($buildfile, '/m', '/nologo', '/v:m', '/clp:Summary', ('/p:configuration=' + $config)) 13 | if (!$?) { 14 | write-host "MSBuild exited with an error, aborting." -foregroundcolor "red" 15 | exit 16 | } 17 | "---------------------------" 18 | "" 19 | } 20 | "" 21 | " PACKING " 22 | "=========================================" 23 | "" 24 | foreach ($file in Get-ChildItem *.nuspec) { 25 | $file.Name.TrimEnd($file.Extension) 26 | "---------------------------" 27 | NuGet Pack $file 28 | "---------------------------" 29 | "" 30 | } 31 | "" 32 | 33 | "" 34 | " PUBLISHING " 35 | "=========================================" 36 | "" 37 | "Packages ready to publish:" 38 | $packages = Get-ChildItem *.nupkg 39 | $packages | % { write-host (" - " + $_.Name) } 40 | "" 41 | 42 | $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Publish" 43 | $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Don't Publish" 44 | $options = [System.Management.Automation.Host.ChoiceDescription[]]($no, $yes) 45 | 46 | $result = $host.ui.PromptForChoice("", "Are you sure you want to publish these packages?", $options, 0) 47 | 48 | if ($result -eq 0) { 49 | "Upload aborted, nothing published." 50 | } 51 | elseif ($result -eq 1) { 52 | foreach ($package in $packages) { 53 | NuGet Push $package 54 | } 55 | } 56 | 57 | "" 58 | "Done." 59 | "" 60 | -------------------------------------------------------------------------------- /Build/NuGet/publish-nuget.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | MSBUILD_EXE="C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" 4 | BUILD_FILE="../CoreOnly.proj" 5 | declare -a CONFIGS=("Standalone" "OpenTK" "MonoGame" "SharpDX") 6 | 7 | BUILD_TOOL="xbuild" 8 | 9 | command -v $BUILD_TOOL >/dev/null 2>&1 10 | XBUILD_EXISTS=$? 11 | 12 | if [ -f "$MSBUILD_EXE" ]; then 13 | BUILD_TOOL="$MSBUILD_EXE" 14 | elif [ $XBUILD_EXISTS -ne 0 ]; then 15 | echo "Neither MSBuild nor XBuild are available on this system. Aborting." 16 | exit 1 17 | fi 18 | 19 | echo "" 20 | echo " BUILDING " 21 | echo "=========================================" 22 | echo "" 23 | for config in "${CONFIGS[@]}" 24 | do 25 | echo "$config" 26 | echo "---------------------------" 27 | "$BUILD_TOOL" "$BUILD_FILE" "//m" "//nologo" "//v:m" "//clp:Summary" "//p:configuration=$config" 28 | if [ $? -ne 0 ]; then 29 | echo -e "\033[0;31mMSBuild exited with an error, aborting.\033[0m" 30 | exit 31 | fi 32 | echo "---------------------------" 33 | echo "" 34 | done 35 | 36 | echo "" 37 | echo " PACKING " 38 | echo "=========================================" 39 | echo "" 40 | for f in *.nuspec 41 | do 42 | echo "${f%.*}" 43 | echo "---------------------------" 44 | nuget Pack $f 45 | echo "---------------------------" 46 | echo "" 47 | done 48 | 49 | echo "" 50 | echo " PUBLISHING " 51 | echo "=========================================" 52 | echo "" 53 | echo "Packages ready to publish:" 54 | for f in *.nupkg 55 | do 56 | echo " - ${f%.*}" 57 | done 58 | echo "" 59 | 60 | read -r -p "Are you sure you want to publish these packages? [y/N] " response 61 | case $response in 62 | [yY][eE][sS]|[yY]) 63 | ;; 64 | *) 65 | echo "Aborted. Exiting..." 66 | exit 1 67 | ;; 68 | esac 69 | 70 | for f in *.nupkg 71 | do 72 | nuget Push $f 73 | done 74 | 75 | echo "" 76 | echo "Done." 77 | echo "" 78 | -------------------------------------------------------------------------------- /Build/build-docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Uses SharpDoc to generate HTML documentation for SharpNav. 4 | # Assumes that you've cloned https://github.com/xoofx/SharpDoc in the same 5 | # parent directory as SharpNav. You can change this along with a number of 6 | # other parameters with the below variables. 7 | 8 | # Will eventually reference as NuGet package, see 9 | # https://github.com/xoofx/SharpDoc/issues/21 10 | 11 | ## 12 | ## VARIABLES 13 | ## 14 | 15 | SHARPDOC_EXE="../../SharpDoc/src/SharpDoc/bin/Debug/SharpDoc.exe" 16 | 17 | SHARPNAV_DLL="../Binaries/SharpNav/Standalone/SharpNav.dll" 18 | SHARPNAV_PROJ="./CoreOnly.proj" 19 | 20 | CONFIG_XML="../Documentation/config.xml" 21 | OUTPUT_DIR="../Binaries/Documentation/" 22 | 23 | ## 24 | ## HELPER FUNCTIONS 25 | ## 26 | 27 | build_sharpnav() { 28 | if type msbuild >/dev/null 2>&1; then 29 | msbuild /t:Standalone /v:q $SHARPNAV_PROJ 30 | elif type xbuild >/dev/null 2>&1; then 31 | xbuild /t:Standalone /v:q $SHARPNAV_PROJ 32 | else 33 | echo "[ERROR] Both msbuild and xbuild are missing. Aborting." 34 | echo "[INFO] If using msys on Windows, add an alias to MSBuild.exe in your .bash_profile" 35 | exit 1 36 | fi 37 | } 38 | 39 | ## 40 | ## CLEAN 41 | ## 42 | 43 | if [ "$1" = "--clean" ]; then 44 | rm -r $OUTPUT_DIR 45 | fi 46 | 47 | ## 48 | ## BUILD 49 | ## 50 | 51 | if [ ! -e $SHARPDOC_EXE ]; then 52 | echo "[ERROR] SharpDoc is not installed or is not being referenced properly." 53 | echo "[ERROR] Please point \$SHARPDOC_EXE to the location of SharpDoc.exe." 54 | exit 1 55 | fi 56 | 57 | if [ ! -e $SHARPNAV_DLL ]; then 58 | echo "[INFO] SharpNav.dll not found, attempting to compile SharpNav." 59 | 60 | if [ -e $SHARPNAV_PROJ ]; then 61 | build_sharpnav 62 | else 63 | echo "[ERROR] The SharpNav project file cannot be found." 64 | exit 1 65 | fi 66 | 67 | if [ ! -e $SHARPNAV_DLL ]; then 68 | echo "[ERROR] SharpNav.dll cannot be found after compilation." 69 | exit 1 70 | fi 71 | fi 72 | 73 | if [ ! -e $CONFIG_XML ]; then 74 | echo "[ERROR] Missing SharpDoc configuration file." 75 | exit 1 76 | fi 77 | 78 | $SHARPDOC_EXE --config=$CONFIG_XML --output=$OUTPUT_DIR $SHARPNAV_DLL 79 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing to SharpNav 2 | ======================== 3 | 4 | In general, contributors should follow the style of the code around their 5 | contributions and keep code well-documented. 6 | 7 | Contributors are expected to follow these guidelines when contributing to 8 | SharpNav: 9 | 10 | - Your code should follow the [C# Coding Conventions][1] and [Framework 11 | Design Guidelines][2] as closely as possible except where noted here. 12 | - Code should be indented with hard tabs with a tabstop of 4. 13 | - Line length is not strictly enforced and is not currently consistent 14 | in SharpNav. Use your best judgement and wrap long statements where it 15 | makes the most sense. In most cases, lines wrap around 120 columns. 16 | - All public and internal members should be documented with [XML 17 | Documentation Comments][3]. 18 | - If adding new functionality, write associated unit tests. 19 | - Ensure that your changes compile on all configurations. When using 2d or 20 | 3d vectors, add this block just after your `using` statements to get your 21 | changes working with the engine/framework-integrated versions of SharpNav: 22 | 23 | ```csharp 24 | #if MONOGAME 25 | using Vector3 = Microsoft.Xna.Framework.Vector3; 26 | #elif OPENTK 27 | using Vector3 = OpenTK.Vector3; 28 | #elif SHARPDX 29 | using Vector3 = SharpDX.Vector3; 30 | #endif 31 | ``` 32 | 33 | - Exceptions to the Framework Design Guideline are acceptable as long as 34 | they are considered 'normal' patterns for high-performance or video game 35 | related purposes. For example, the use of large structs with static 36 | methods and `ref`/`out` parameters. This pattern is commonly used for 37 | vectors and matrices in just about every C# graphics/game framework. 38 | - By submitting a pull request, you are licensing your changes under the 39 | terms of the MIT license. A copy of the MIT license is available in the 40 | `LICENSE` file in this directory and on the [OSI website][4]. 41 | 42 | If you are unsure about anything (besides licensing), go ahead and submit the 43 | pull request and a maintainer will let you know if there's anything you should 44 | change to meet these requirements. 45 | 46 | 47 | [1]: http://msdn.microsoft.com/en-us/library/ff926074.aspx 48 | [2]: http://msdn.microsoft.com/en-us/library/ms229042.aspx 49 | [3]: http://msdn.microsoft.com/en-us/library/b2s063f7.aspx 50 | [4]: http://opensource.org/licenses/MIT 51 | -------------------------------------------------------------------------------- /Dependencies/Gwen.Renderer.OpenTK.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Dependencies/Gwen.Renderer.OpenTK.dll -------------------------------------------------------------------------------- /Dependencies/Gwen.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Dependencies/Gwen.dll -------------------------------------------------------------------------------- /Documentation/README.md: -------------------------------------------------------------------------------- 1 | SharpNav Documentation 2 | ====================== 3 | 4 | If you came here looking for docs, you should go to http://sharpnav.com/docs 5 | for the compiled web documentation. This directory contains markdown versions 6 | of the pages included in the compiled docs as well as a configuration for 7 | [SharpDoc][1], the tool used to generate the documentation. 8 | 9 | ## Building Documentation 10 | 11 | Before anything else, make sure you have built at least one version of 12 | SharpNav (preferrably in the Standalone configuration). 13 | 14 | Almost everything you need is in this directory. There is no NuGet package for 15 | SharpDoc yet, so you should clone SharpDocs and compile the solution. If you'd 16 | like to take advantage of the `build-docs` script in the `Build/` directory, 17 | make sure SharpDocs is cloned in the same directory that SharpNav is cloned 18 | in. For example, if SharpNav were located in `C:\Projects\SharpNav`, then 19 | clone SharpDoc to `C:\Projects\SharpDoc`. 20 | 21 | **Note**: This process is not limited to Windows. Mono can do everything 22 | described here. 23 | 24 | With the script, you can simply call `./build-docs.sh` and 25 | `./build-docs.sh --clean` to generate and delete documentation, respectively. 26 | The generated docs will be output to the `/Binaries/Documentation` directory 27 | by default. 28 | 29 | If you aren't using the script, you can build documentation with the following 30 | command: 31 | 32 | ``` 33 | SharpDoc.exe --config=/config.xml --output= /SharpNav.dll 34 | ``` 35 | 36 | 37 | [1]: https://github.com/xoofx/SharpDoc 38 | -------------------------------------------------------------------------------- /Documentation/Release Notes/v0.9.0.md: -------------------------------------------------------------------------------- 1 | v0.9.0 was released on October 11, 2014 and is the first publicly released 2 | versions of SharpNav. Due to packaging issues, there are two other versions 3 | available on NuGet - v0.9.1 and v0.9.2. 4 | 5 | v0.9.1 and v0.9.2 only differ from v0.9.0 in packaging on NuGet. The 6 | assemblies are still versioned as v0.9.0, though. 7 | 8 | ## Known Issues 9 | 10 | - Bug(s) that prevent proper triangulation in `PolyMeshDetail` 11 | - Excessive memory usage in rare cases 12 | - Unfinished public APIs, though the `SharpNav` namespace is mostly stable 13 | -------------------------------------------------------------------------------- /Documentation/Release Notes/v1.0.0-alpha.1.md: -------------------------------------------------------------------------------- 1 | v1.0.0-alpha.1 was released on December 31, 2014. It is the second release of 2 | SharpNav and the first pre-release of v1.0.0. It fixes several bugs from 3 | v0.9.0 and makes several changes to the public API. 4 | 5 | ## Major Changes 6 | 7 | - Removed existing but broken XNA and Unity3D builds. 8 | - Raw contour vertices are no longer stored in the `Contour` class. 9 | - SharpNav now relies on NuGet to retrieve packages. 10 | 11 | ## Minor Changes 12 | 13 | - The `RegionId` enum is now the `Region` struct. 14 | - The `AreaId` enum is now the `Area` struct. 15 | - All vector types are now in the `SharpNav.Geometry` namespace in the 16 | Standalone build. 17 | - The `ContourSet` constructor no longer takes a `CompactHeightfield` as a 18 | parameter. It is instead handled in `CompactHeightfield.BuildContourSet`. 19 | 20 | ## Bugfixes 21 | 22 | - Fixed incorrect slope calculation in `AreaIdGenerator`. 23 | - Fixed most bugs preventing proper triangulation in `PolyMeshDetail`. 24 | - Fixed thread safety issue with triangle rasterization in `Heightfield`. 25 | 26 | ## Known Issues 27 | 28 | - With enough detail, `PolyMeshDetail` will still produce incorrectly 29 | triangulated meshes. 30 | - Edge cases consuming a lot of memory likely still exist. 31 | - public APIs are still unfinished. 32 | -------------------------------------------------------------------------------- /Documentation/Release Notes/v1.0.0-alpha.2.md: -------------------------------------------------------------------------------- 1 | v1.0.0-alpha.2 was released on May 11, 2015. It is the third release of 2 | SharpNav and the second pre-release of v1.0.0. It fixes a few bugs from 3 | v1.0.0-alpha.1 and changes some of the pathfinding and crowd APIs. 4 | 5 | ## Major Changes 6 | 7 | - Added serialization/deserialization API. 8 | - Implemented a JSON serializer ([PR #36][1]). 9 | - Started CLI and GUI clients. 10 | - Introduced the `NavPoint` struct to replace the common `int` and `Vector3` 11 | pair in pathfinding code. 12 | - Updated all projects to .NET 4.5.1 13 | - Started multithreading parts of navmesh generation (Heightfield 14 | rasterization). 15 | 16 | ## Minor Changes 17 | 18 | - Added Appveyor as a second continuous integration service. 19 | - Moved all source code and `SharpNav.sln` to the `Source/` directory. 20 | - Refactored some values in `NavMeshGenerationSettings`. 21 | - Most of the functions inside `PathfinderCommon` were refactored to their 22 | proper classes. The rest of the class was moved into 23 | `SharpNav.Pathfinding` and renamed to `PathfindingCommon`. 24 | 25 | ## Bugfixes 26 | 27 | - Fixed several crowd bugs ([PR #30][2]). 28 | 29 | ## Known Issues 30 | 31 | - CLI client doesn't log a lot of useful things. 32 | - CLI client only exports JSON file format. 33 | - GUI client doesn't generate a navmesh. 34 | - GUI client doesn't have all buttons/menus functional. 35 | - Edge cases consuming a lot of memory likely still exist. 36 | - public APIs are still unfinished. 37 | 38 | 39 | [1]: https://github.com/Robmaister/SharpNav/pull/36 40 | [2]: https://github.com/Robmaister/SharpNav/pull/30 41 | -------------------------------------------------------------------------------- /Documentation/Styles/SharpNav/html/PageHeader.cshtml: -------------------------------------------------------------------------------- 1 | @* 2 | // Copyright (c) 2010-2013 SharpDoc - Alexandre Mutel 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // ------------------------------------------------------------------------------- 22 | // Override this template to modify the generated html header for all body 23 | // ------------------------------------------------------------------------------- 24 | *@ 25 | View on GitHub 26 |

@Param.Title

27 | @if (Param.SubTitle != null) 28 | { 29 |

@Param.SubTitle

30 | } 31 | -------------------------------------------------------------------------------- /Documentation/Styles/SharpNav/images/blacktocat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Documentation/Styles/SharpNav/images/blacktocat.png -------------------------------------------------------------------------------- /Documentation/Styles/SharpNav/style.xml: -------------------------------------------------------------------------------- 1 | 2 | 26 | 38 | -------------------------------------------------------------------------------- /Documentation/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | SharpNav 6 | A Pathfinding and Navigation Mesh Library for C# 7 | Copyright (c) 2013-2015 Robert Rouhani <robert.rouhani@gmail.com> and other contributors 8 | 9 | Styles/ 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Documentation/overview.md: -------------------------------------------------------------------------------- 1 | SharpNav is a navigation mesh generation and pathfinding library. It started 2 | as a port of Mikko Monomen's [Recast Navigation][1] to C#. 3 | 4 | [1]: https://github.com/memononen/recastnavigation 5 | -------------------------------------------------------------------------------- /Documentation/release-notes.md: -------------------------------------------------------------------------------- 1 | Every publicly released version of SharpNav includes a changelog and other 2 | miscellaneous information about itself. 3 | -------------------------------------------------------------------------------- /Graphics/Logo/Full.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Graphics/Logo/Full.png -------------------------------------------------------------------------------- /Graphics/Logo/FullWhite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Graphics/Logo/FullWhite.png -------------------------------------------------------------------------------- /Graphics/Logo/Logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Graphics/Logo/Logo.ico -------------------------------------------------------------------------------- /Graphics/Logo/Logo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Graphics/Logo/Logo.pdf -------------------------------------------------------------------------------- /Graphics/Logo/LogoOnly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Graphics/Logo/LogoOnly.png -------------------------------------------------------------------------------- /Graphics/Logo/NuGet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Graphics/Logo/NuGet.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 4 | 5 | SharpNav contains some altered source code from Recast Navigation, Copyright (c) 2009 Mikko Mononen memon@inside.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /Source/SharpNav.CLI/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Source/SharpNav.CLI/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SharpNav.CLI")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SharpNav.CLI")] 13 | [assembly: AssemblyCopyright("Copyright © Robert Rouhani 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("162bd195-11e9-4dc9-9702-677dfd8e5f12")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("0.1.0.0")] 36 | [assembly: AssemblyFileVersion("0.1.0.0")] 37 | 38 | [assembly: AssemblyInformationalVersion("0.1.0")] 39 | -------------------------------------------------------------------------------- /Source/SharpNav.CLI/SharpNav.CLI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {AEAACF72-6EFE-4D9F-AEEB-8EF091B817CD} 8 | Exe 9 | Properties 10 | SharpNav.CLI 11 | SharpNav.CLI.Program 12 | SharpNav 13 | ..\..\Graphics\Logo\Logo.ico 14 | v4.5.1 15 | 512 16 | false 17 | SharpNav.CLI.snk 18 | 19 | 20 | 21 | AnyCPU 22 | true 23 | full 24 | false 25 | ..\..\Binaries\Clients\CLI\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | false 30 | 31 | 32 | AnyCPU 33 | pdbonly 34 | true 35 | ..\..\Binaries\Clients\CLI\Standalone\ 36 | TRACE 37 | prompt 38 | 4 39 | false 40 | 41 | 42 | 43 | ..\packages\Mono.Options.4.4.0.0\lib\net4-client\Mono.Options.dll 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | {0e3c6e73-cce6-4148-b847-36487ffea225} 64 | SharpNav 65 | 66 | 67 | 68 | 75 | -------------------------------------------------------------------------------- /Source/SharpNav.CLI/SharpNav.CLI.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Source/SharpNav.CLI/SharpNav.CLI.snk -------------------------------------------------------------------------------- /Source/SharpNav.CLI/Verbosity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | namespace SharpNav.CLI 7 | { 8 | /// 9 | /// An enumeration of different levels of output. 10 | /// 11 | public enum VerbosityLevel 12 | { 13 | /// 14 | /// Program outputs nothing. 15 | /// 16 | Silent, 17 | 18 | /// 19 | /// Program only outputs the bare minimum. Great for automation. 20 | /// 21 | Minimal, 22 | 23 | /// 24 | /// Standard verbosity level. 25 | /// 26 | Normal, 27 | 28 | /// 29 | /// Provides more details than most users would need. 30 | /// 31 | Verbose, 32 | 33 | /// 34 | /// Outputs everything. Great for tracking down a bug. 35 | /// 36 | Debug 37 | } 38 | 39 | /// 40 | /// Helpers for the enumeration. 41 | /// 42 | public static class Verbosity 43 | { 44 | /// 45 | /// Parses a from a string. 46 | /// 47 | /// The level as a string. 48 | /// A value from the enumeration. 49 | public static VerbosityLevel Parse(string level) 50 | { 51 | switch (level.ToLowerInvariant()) 52 | { 53 | case "s": 54 | case "silent:": 55 | return VerbosityLevel.Silent; 56 | case "m": 57 | case "minimal": 58 | return VerbosityLevel.Minimal; 59 | case "n": 60 | case "normal": 61 | return VerbosityLevel.Normal; 62 | case "v": 63 | case "verbose": 64 | return VerbosityLevel.Verbose; 65 | case "d": 66 | case "debug": 67 | return VerbosityLevel.Debug; 68 | default: 69 | Console.WriteLine("[ERROR] Cannot parse verbosity level \"" + level + "\". Setting to Normal."); 70 | return VerbosityLevel.Normal; 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Source/SharpNav.CLI/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Source/SharpNav.Examples/.gitignore: -------------------------------------------------------------------------------- 1 | !*.obj -------------------------------------------------------------------------------- /Source/SharpNav.Examples/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Source/SharpNav.Examples/GwenSkin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Source/SharpNav.Examples/GwenSkin.png -------------------------------------------------------------------------------- /Source/SharpNav.Examples/ObjModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, 2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Globalization; 7 | using System.IO; 8 | 9 | using SharpNav.Geometry; 10 | 11 | #if OPENTK 12 | using OpenTK; 13 | #endif 14 | 15 | //Doesn't compile if in an unsupported configuration 16 | #if STANDALONE || OPENTK 17 | 18 | namespace SharpNav.Examples 19 | { 20 | /// 21 | /// Parses a model in .obj format. 22 | /// 23 | public class ObjModel 24 | { 25 | private static readonly char[] lineSplitChars = { ' ' }; 26 | 27 | private List tris; 28 | private List norms; 29 | 30 | /// 31 | /// Initializes a new instance of the class. 32 | /// 33 | /// The path of the .obj file to parse. 34 | public ObjModel(string path) 35 | { 36 | tris = new List(); 37 | norms = new List(); 38 | List tempVerts = new List(); 39 | List tempNorms = new List(); 40 | 41 | using (StreamReader reader = new StreamReader(path)) 42 | { 43 | string file = reader.ReadToEnd(); 44 | foreach (string l in file.Split('\n')) 45 | { 46 | //trim any extras 47 | string tl = l; 48 | int commentStart = l.IndexOf("#"); 49 | if (commentStart != -1) 50 | tl = tl.Substring(0, commentStart); 51 | tl = tl.Trim(); 52 | 53 | string[] line = tl.Split(lineSplitChars, StringSplitOptions.RemoveEmptyEntries); 54 | if (line == null || line.Length == 0) 55 | continue; 56 | 57 | switch (line[0]) 58 | { 59 | case "v": 60 | if (line.Length < 4) 61 | continue; 62 | 63 | Vector3 v; 64 | if (!TryParseVec(line, 1, 2, 3, out v)) continue; 65 | tempVerts.Add(v); 66 | break; 67 | case "vn": 68 | if (line.Length < 4) 69 | continue; 70 | 71 | Vector3 n; 72 | if (!TryParseVec(line, 1, 2, 3, out n)) continue; 73 | tempNorms.Add(n); 74 | break; 75 | case "f": 76 | if (line.Length < 4) 77 | continue; 78 | else if (line.Length == 4) 79 | { 80 | int v0, v1, v2; 81 | int n0, n1, n2; 82 | if (!int.TryParse(line[1].Split('/')[0], out v0)) continue; 83 | if (!int.TryParse(line[2].Split('/')[0], out v1)) continue; 84 | if (!int.TryParse(line[3].Split('/')[0], out v2)) continue; 85 | if (!int.TryParse(line[1].Split('/')[2], out n0)) continue; 86 | if (!int.TryParse(line[2].Split('/')[2], out n1)) continue; 87 | if (!int.TryParse(line[3].Split('/')[2], out n2)) continue; 88 | 89 | v0 -= 1; 90 | v1 -= 1; 91 | v2 -= 1; 92 | n0 -= 1; 93 | n1 -= 1; 94 | n2 -= 1; 95 | 96 | tris.Add(new Triangle3(tempVerts[v0], tempVerts[v1], tempVerts[v2])); 97 | norms.Add(tempNorms[n0]); 98 | norms.Add(tempNorms[n1]); 99 | norms.Add(tempNorms[n2]); 100 | } 101 | else 102 | { 103 | int v0, n0; 104 | if (!int.TryParse(line[1].Split('/')[0], out v0)) continue; 105 | if (!int.TryParse(line[1].Split('/')[2], out n0)) continue; 106 | 107 | v0 -= 1; 108 | n0 -= 1; 109 | 110 | for (int i = 2; i < line.Length - 1; i++) 111 | { 112 | int vi, vii; 113 | int ni, nii; 114 | if (!int.TryParse(line[i].Split('/')[0], out vi)) continue; 115 | if (!int.TryParse(line[i + 1].Split('/')[0], out vii)) continue; 116 | if (!int.TryParse(line[i].Split('/')[2], out ni)) continue; 117 | if (!int.TryParse(line[i + 1].Split('/')[2], out nii)) continue; 118 | 119 | vi -= 1; 120 | vii -= 1; 121 | ni -= 1; 122 | nii -= 1; 123 | 124 | tris.Add(new Triangle3(tempVerts[v0], tempVerts[vi], tempVerts[vii])); 125 | norms.Add(tempNorms[n0]); 126 | norms.Add(tempNorms[ni]); 127 | norms.Add(tempNorms[nii]); 128 | } 129 | } 130 | break; 131 | } 132 | } 133 | } 134 | } 135 | 136 | /// 137 | /// Gets an array of the triangles in this model. 138 | /// 139 | /// 140 | public Triangle3[] GetTriangles() 141 | { 142 | return tris.ToArray(); 143 | } 144 | 145 | /// 146 | /// Gets an array of the normals in this model. 147 | /// 148 | /// 149 | public Vector3[] GetNormals() 150 | { 151 | return norms.ToArray(); 152 | } 153 | 154 | private bool TryParseVec(string[] values, int x, int y, int z, out Vector3 v) 155 | { 156 | v = Vector3.Zero; 157 | 158 | if (!float.TryParse(values[x], NumberStyles.Any, CultureInfo.InvariantCulture, out v.X)) 159 | return false; 160 | if (!float.TryParse(values[y], NumberStyles.Any, CultureInfo.InvariantCulture, out v.Y)) 161 | return false; 162 | if (!float.TryParse(values[z], NumberStyles.Any, CultureInfo.InvariantCulture, out v.Z)) 163 | return false; 164 | 165 | return true; 166 | } 167 | } 168 | } 169 | 170 | #endif 171 | -------------------------------------------------------------------------------- /Source/SharpNav.Examples/OpenTK.dll.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Source/SharpNav.Examples/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, 2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | namespace SharpNav.Examples 7 | { 8 | class Program 9 | { 10 | [STAThread] 11 | static void Main(string[] args) 12 | { 13 | #if OPENTK || STANDALONE 14 | using (ExampleWindow ex = new ExampleWindow()) 15 | { 16 | ex.Run(); 17 | } 18 | #else 19 | Console.WriteLine("SharpNav.Examples does not support this configuration of SharpNav."); 20 | #endif 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Source/SharpNav.Examples/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System.Reflection; 5 | using System.Runtime.CompilerServices; 6 | using System.Runtime.InteropServices; 7 | 8 | // General Information about an assembly is controlled through the following 9 | // set of attributes. Change these attribute values to modify the information 10 | // associated with an assembly. 11 | [assembly: AssemblyTitle("Examples")] 12 | [assembly: AssemblyDescription("Examples for SharpNav.")] 13 | [assembly: AssemblyConfiguration("")] 14 | [assembly: AssemblyCompany("")] 15 | [assembly: AssemblyProduct("Examples")] 16 | [assembly: AssemblyCopyright("Copyright © 2013-2014 Robert Rouhani and other contributors (see CONTRIBUTORS file).")] 17 | [assembly: AssemblyTrademark("")] 18 | [assembly: AssemblyCulture("")] 19 | 20 | // Setting ComVisible to false makes the types in this assembly not visible 21 | // to COM components. If you need to access a type in this assembly from 22 | // COM, set the ComVisible attribute to true on that type. 23 | [assembly: ComVisible(false)] 24 | 25 | // The following GUID is for the ID of the typelib if this project is exposed to COM 26 | [assembly: Guid("8ae6c8b3-d43d-4faa-8243-8927e58e1385")] 27 | 28 | // Version information for an assembly consists of the following four values: 29 | // 30 | // Major Version 31 | // Minor Version 32 | // Build Number 33 | // Revision 34 | // 35 | // You can specify all the values or you can default the Build and Revision Numbers 36 | // by using the '*' as shown below: 37 | // [assembly: AssemblyVersion("1.0.*")] 38 | [assembly: AssemblyVersion("1.0.0.0")] 39 | [assembly: AssemblyFileVersion("1.0.0.0")] 40 | -------------------------------------------------------------------------------- /Source/SharpNav.Examples/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SharpNav.Examples.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SharpNav.Examples.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 65 | /// 66 | internal static System.Drawing.Icon Icon { 67 | get { 68 | object obj = ResourceManager.GetObject("Icon", resourceCulture); 69 | return ((System.Drawing.Icon)(obj)); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Source/SharpNav.Examples/example_ply.ply: -------------------------------------------------------------------------------- 1 | ply 2 | format ascii 1.0 3 | comment cube.obj created by IVREAD. 4 | comment Original data in cube.iv 5 | comment converted from OBJ by obj2ply 6 | element vertex 8 7 | property float32 x 8 | property float32 y 9 | property float32 z 10 | element face 12 11 | property list uint8 int32 vertex_indices 12 | end_header 13 | -0.5 -0.5 1 14 | 0.5 -0.5 1 15 | 0.5 0.5 1 16 | -0.5 0.5 1 17 | 0.5 -0.5 0 18 | -0.5 -0.5 0 19 | -0.5 0.5 0 20 | 0.5 0.5 0 21 | 3 2 1 0 22 | 3 3 2 0 23 | 3 6 5 4 24 | 3 7 6 4 25 | 3 3 0 5 26 | 3 6 3 5 27 | 3 7 4 1 28 | 3 2 7 1 29 | 3 1 4 5 30 | 3 0 1 5 31 | 3 7 2 3 32 | 3 6 7 3 -------------------------------------------------------------------------------- /Source/SharpNav.Examples/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Source/SharpNav.GUI/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Source/SharpNav.GUI/ObjModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Globalization; 7 | using System.IO; 8 | 9 | using SharpNav.Geometry; 10 | 11 | namespace SharpNav.GUI 12 | { 13 | /// 14 | /// Parses a model in .obj format. 15 | /// 16 | public class ObjModel 17 | { 18 | private static readonly char[] lineSplitChars = { ' ' }; 19 | 20 | private List tris; 21 | private List norms; 22 | 23 | /// 24 | /// Initializes a new instance of the class. 25 | /// 26 | /// The path of the .obj file to parse. 27 | public ObjModel(string path) 28 | { 29 | tris = new List(); 30 | norms = new List(); 31 | List tempVerts = new List(); 32 | List tempNorms = new List(); 33 | 34 | using (StreamReader reader = new StreamReader(path)) 35 | { 36 | string file = reader.ReadToEnd(); 37 | foreach (string l in file.Split('\n')) 38 | { 39 | //trim any extras 40 | string tl = l; 41 | int commentStart = l.IndexOf("#"); 42 | if (commentStart != -1) 43 | tl = tl.Substring(0, commentStart); 44 | tl = tl.Trim(); 45 | 46 | string[] line = tl.Split(lineSplitChars, StringSplitOptions.RemoveEmptyEntries); 47 | if (line == null || line.Length == 0) 48 | continue; 49 | 50 | switch (line[0]) 51 | { 52 | case "v": 53 | if (line.Length < 4) 54 | continue; 55 | 56 | Vector3 v; 57 | if (!TryParseVec(line, 1, 2, 3, out v)) continue; 58 | tempVerts.Add(v); 59 | break; 60 | case "vn": 61 | if (line.Length < 4) 62 | continue; 63 | 64 | Vector3 n; 65 | if (!TryParseVec(line, 1, 2, 3, out n)) continue; 66 | tempNorms.Add(n); 67 | break; 68 | case "f": 69 | if (line.Length < 4) 70 | continue; 71 | else if (line.Length == 4) 72 | { 73 | int v0, v1, v2; 74 | int n0, n1, n2; 75 | if (!int.TryParse(line[1].Split('/')[0], out v0)) continue; 76 | if (!int.TryParse(line[2].Split('/')[0], out v1)) continue; 77 | if (!int.TryParse(line[3].Split('/')[0], out v2)) continue; 78 | if (!int.TryParse(line[1].Split('/')[2], out n0)) continue; 79 | if (!int.TryParse(line[2].Split('/')[2], out n1)) continue; 80 | if (!int.TryParse(line[3].Split('/')[2], out n2)) continue; 81 | 82 | v0 -= 1; 83 | v1 -= 1; 84 | v2 -= 1; 85 | n0 -= 1; 86 | n1 -= 1; 87 | n2 -= 1; 88 | 89 | tris.Add(new Triangle3(tempVerts[v0], tempVerts[v1], tempVerts[v2])); 90 | norms.Add(tempNorms[n0]); 91 | norms.Add(tempNorms[n1]); 92 | norms.Add(tempNorms[n2]); 93 | } 94 | else 95 | { 96 | int v0, n0; 97 | if (!int.TryParse(line[1].Split('/')[0], out v0)) continue; 98 | if (!int.TryParse(line[1].Split('/')[2], out n0)) continue; 99 | 100 | v0 -= 1; 101 | n0 -= 1; 102 | 103 | for (int i = 2; i < line.Length - 1; i++) 104 | { 105 | int vi, vii; 106 | int ni, nii; 107 | if (!int.TryParse(line[i].Split('/')[0], out vi)) continue; 108 | if (!int.TryParse(line[i + 1].Split('/')[0], out vii)) continue; 109 | if (!int.TryParse(line[i].Split('/')[2], out ni)) continue; 110 | if (!int.TryParse(line[i + 1].Split('/')[2], out nii)) continue; 111 | 112 | vi -= 1; 113 | vii -= 1; 114 | ni -= 1; 115 | nii -= 1; 116 | 117 | tris.Add(new Triangle3(tempVerts[v0], tempVerts[vi], tempVerts[vii])); 118 | norms.Add(tempNorms[n0]); 119 | norms.Add(tempNorms[ni]); 120 | norms.Add(tempNorms[nii]); 121 | } 122 | } 123 | break; 124 | } 125 | } 126 | } 127 | } 128 | 129 | /// 130 | /// Gets an array of the triangles in this model. 131 | /// 132 | /// 133 | public Triangle3[] GetTriangles() 134 | { 135 | return tris.ToArray(); 136 | } 137 | 138 | /// 139 | /// Gets an array of the normals in this model. 140 | /// 141 | /// 142 | public Vector3[] GetNormals() 143 | { 144 | return norms.ToArray(); 145 | } 146 | 147 | private bool TryParseVec(string[] values, int x, int y, int z, out Vector3 v) 148 | { 149 | v = Vector3.Zero; 150 | 151 | if (!float.TryParse(values[x], NumberStyles.Any, CultureInfo.InvariantCulture, out v.X)) 152 | return false; 153 | if (!float.TryParse(values[y], NumberStyles.Any, CultureInfo.InvariantCulture, out v.Y)) 154 | return false; 155 | if (!float.TryParse(values[z], NumberStyles.Any, CultureInfo.InvariantCulture, out v.Z)) 156 | return false; 157 | 158 | return true; 159 | } 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /Source/SharpNav.GUI/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Windows.Forms; 6 | 7 | namespace SharpNav.GUI 8 | { 9 | class Program 10 | { 11 | [STAThread] 12 | static void Main(string[] args) 13 | { 14 | Application.EnableVisualStyles(); 15 | Application.SetCompatibleTextRenderingDefault(false); 16 | Application.Run(new ConfigurationForm()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Source/SharpNav.GUI/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SharpNav.Gui")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SharpNav.Gui")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("560205a7-8ed3-413e-9862-c5b8fae78e20")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Source/SharpNav.GUI/SharpNav.GUI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {7E95190C-3DDC-4A31-95A0-B17486519853} 8 | WinExe 9 | Properties 10 | SharpNav.GUI 11 | SharpNavGUI 12 | ..\..\Graphics\Logo\Logo.ico 13 | v4.5.1 14 | 512 15 | true 16 | SharpNav.GUI.snk 17 | 18 | 19 | 20 | AnyCPU 21 | true 22 | full 23 | false 24 | ..\..\Binaries\Clients\GUI\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | 29 | 30 | AnyCPU 31 | pdbonly 32 | true 33 | ..\..\Binaries\Clients\GUI\Standalone\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | Form 51 | 52 | 53 | ConfigurationForm.cs 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | {0e3c6e73-cce6-4148-b847-36487ffea225} 66 | SharpNav 67 | 68 | 69 | 70 | 71 | ConfigurationForm.cs 72 | 73 | 74 | 75 | 82 | -------------------------------------------------------------------------------- /Source/SharpNav.GUI/SharpNav.GUI.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Source/SharpNav.GUI/SharpNav.GUI.snk -------------------------------------------------------------------------------- /Source/SharpNav.Tests/.gitignore: -------------------------------------------------------------------------------- 1 | test-results/ -------------------------------------------------------------------------------- /Source/SharpNav.Tests/CellTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | using NUnit.Framework; 7 | 8 | using SharpNav; 9 | 10 | namespace SharpNav.Tests 11 | { 12 | [TestFixture] 13 | public class CellTests 14 | { 15 | [Test] 16 | public void AddSpan_Flipped_Success() 17 | { 18 | var cell = new Cell(40); 19 | var span = new Span(20, 10); 20 | 21 | cell.AddSpan(span); 22 | 23 | Assert.AreEqual(cell.Spans[0].Minimum, span.Maximum); 24 | Assert.AreEqual(cell.Spans[0].Maximum, span.Minimum); 25 | } 26 | 27 | [Test] 28 | public void AddSpan_First_Success() 29 | { 30 | var cell = new Cell(40); 31 | var span = new Span(10, 20); 32 | 33 | cell.AddSpan(span); 34 | 35 | Assert.AreEqual(span.Minimum, cell.Spans[0].Minimum); 36 | Assert.AreEqual(span.Maximum, cell.Spans[0].Maximum); 37 | } 38 | 39 | [Test] 40 | public void AddSpan_Below_Success() 41 | { 42 | var cell = new Cell(40); 43 | var span = new Span(10, 20); 44 | var span2 = new Span(5, 8); 45 | 46 | cell.AddSpan(span); 47 | cell.AddSpan(span2); 48 | 49 | Assert.AreEqual(span2.Minimum, cell.Spans[0].Minimum); 50 | Assert.AreEqual(span2.Maximum, cell.Spans[0].Maximum); 51 | Assert.AreEqual(span.Minimum, cell.Spans[1].Minimum); 52 | Assert.AreEqual(span.Maximum, cell.Spans[1].Maximum); 53 | } 54 | 55 | [Test] 56 | public void AddSpan_Above_Success() 57 | { 58 | var cell = new Cell(40); 59 | var span = new Span(10, 20); 60 | var span2 = new Span(21, 25); 61 | 62 | cell.AddSpan(span); 63 | cell.AddSpan(span2); 64 | 65 | Assert.AreEqual(span.Minimum, cell.Spans[0].Minimum); 66 | Assert.AreEqual(span.Maximum, cell.Spans[0].Maximum); 67 | Assert.AreEqual(span2.Minimum, cell.Spans[1].Minimum); 68 | Assert.AreEqual(span2.Maximum, cell.Spans[1].Maximum); 69 | } 70 | 71 | [Test] 72 | public void AddSpan_ContainedMerge_Success() 73 | { 74 | var cell = new Cell(40); 75 | var span = new Span(10, 20); 76 | var span2 = new Span(5, 25); 77 | 78 | cell.AddSpan(span); 79 | cell.AddSpan(span2); 80 | 81 | Assert.AreEqual(span2.Minimum, cell.Spans[0].Minimum); 82 | Assert.AreEqual(span2.Maximum, cell.Spans[0].Maximum); 83 | } 84 | 85 | [Test] 86 | public void AddSpan_BelowMerge_Success() 87 | { 88 | var cell = new Cell(40); 89 | var span = new Span(10, 20); 90 | var span2 = new Span(5, 15); 91 | 92 | cell.AddSpan(span); 93 | cell.AddSpan(span2); 94 | 95 | Assert.AreEqual(span2.Minimum, cell.Spans[0].Minimum); 96 | Assert.AreEqual(span.Maximum, cell.Spans[0].Maximum); 97 | } 98 | 99 | [Test] 100 | public void AddSpan_AboveMerge_Success() 101 | { 102 | var cell = new Cell(40); 103 | var span = new Span(10, 20); 104 | var span2 = new Span(15, 25); 105 | 106 | cell.AddSpan(span); 107 | cell.AddSpan(span2); 108 | 109 | Assert.AreEqual(span.Minimum, cell.Spans[0].Minimum); 110 | Assert.AreEqual(span2.Maximum, cell.Spans[0].Maximum); 111 | } 112 | 113 | 114 | [Test] 115 | public void Indexer_NoSpans_ReturnsNull() 116 | { 117 | var cell = new Cell(10); 118 | Assert.IsNull(cell[5]); 119 | } 120 | 121 | [Test] 122 | public void Indexer_BelowZero_Throws() 123 | { 124 | var cell = new Cell(10); 125 | Assert.Throws(() => { var s = cell[-1]; }); 126 | } 127 | 128 | [Test] 129 | public void Indexer_AboveMax_Throws() 130 | { 131 | var cell = new Cell(10); 132 | Assert.Throws(() => { var s = cell[10]; }); 133 | } 134 | 135 | [Test] 136 | public void Indexer_InSpan_Success() 137 | { 138 | var cell = new Cell(10); 139 | cell.AddSpan(new Span(2, 6)); 140 | 141 | var span = cell[4]; 142 | Assert.AreEqual(2, span.Value.Minimum); 143 | Assert.AreEqual(6, span.Value.Maximum); 144 | } 145 | 146 | [Test] 147 | public void Indexer_OutOfSpan_ReturnsNull() 148 | { 149 | var cell = new Cell(10); 150 | cell.AddSpan(new Span(2, 6)); 151 | 152 | var span = cell[1]; 153 | Assert.IsNull(span); 154 | } 155 | 156 | [Test] 157 | public void Indexer_FindSpan_Success() 158 | { 159 | var cell = new Cell(10); 160 | cell.AddSpan(new Span(2, 5)); 161 | cell.AddSpan(new Span(7, 9)); 162 | 163 | var span = cell[6]; 164 | Assert.IsNull(span); 165 | } 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/Collections/Generic/BufferedQueueTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | 9 | using NUnit.Framework; 10 | 11 | using SharpNav.Collections.Generic; 12 | 13 | namespace SharpNav.Tests.Collections.Generic 14 | { 15 | [TestFixture] 16 | [Category("BrokenButUnused")] 17 | public class BufferedQueueTests 18 | { 19 | [Test] 20 | public void Empty_Queue_Count() 21 | { 22 | var empty = new BufferedQueue(1000); 23 | //Assert.AreEqual(empty.Count, 0); 24 | } 25 | 26 | [Test] 27 | public void Enqueue_Test() 28 | { 29 | var queue = new BufferedQueue(1000); 30 | for (int c = 0; c < 100; c++) 31 | { 32 | queue.Enqueue(c); 33 | //Assert.AreEqual(queue.Count, c + 1); 34 | } 35 | } 36 | 37 | [Test] 38 | public void Dequeue_Test() 39 | { 40 | var queue = new BufferedQueue(1000); 41 | for (int c = 0; c < 100; c++) 42 | queue.Enqueue(c); 43 | 44 | for (int c = 0; c < 100; c++) 45 | { 46 | int n = queue.Dequeue(); 47 | //Assert.AreEqual(n, c); 48 | //Assert.AreEqual(queue.Count, c); 49 | } 50 | } 51 | 52 | [Test] 53 | public void Empty_Test() 54 | { 55 | var queue = new BufferedQueue(1000); 56 | for (int c = 0; c < 100; c++) 57 | queue.Enqueue(1); 58 | //Assert.AreEqual(queue.Count, 100); 59 | queue.Clear(); 60 | //Assert.AreEqual(queue.Count, 0); 61 | } 62 | 63 | [Test] 64 | public void ReadOnly_Test() 65 | { 66 | var queue = new BufferedQueue(1000); 67 | ICollection collection = queue; 68 | Assert.AreEqual(collection.IsReadOnly, false); 69 | } 70 | 71 | [Test] 72 | public void Peek_Test() 73 | { 74 | var queue = new BufferedQueue(1000); 75 | for (int c = 0; c < 100; c++) 76 | { 77 | queue.Enqueue(c); 78 | //Assert.AreEqual(queue.Peek(), c); 79 | } 80 | } 81 | 82 | // TODO: ICollection 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/Collections/Generic/BufferedStackTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | 9 | using NUnit.Framework; 10 | 11 | using SharpNav.Collections.Generic; 12 | 13 | namespace SharpNav.Tests.Collections.Generic 14 | { 15 | [TestFixture] 16 | public class BufferedStackTests 17 | { 18 | [Test] 19 | public void Empty_Stack_Count() 20 | { 21 | var empty = new BufferedStack(1000); 22 | Assert.AreEqual(empty.Count, 0); 23 | } 24 | 25 | [Test] 26 | public void Push_Test() 27 | { 28 | var stack = new BufferedStack(1000); 29 | for (int c = 0; c < 100; c++) 30 | { 31 | stack.Push(c); 32 | Assert.AreEqual(stack.Count, c + 1); 33 | } 34 | } 35 | 36 | [Test] 37 | public void Pop_Test() 38 | { 39 | var stack = new BufferedStack(1000); 40 | for (int c = 0; c < 100; c++) 41 | stack.Push(c); 42 | 43 | for (int c = 99; c >= 0; c--) 44 | { 45 | int n = stack.Pop(); 46 | Assert.AreEqual(n, c); 47 | Assert.AreEqual(stack.Count, c); 48 | } 49 | } 50 | 51 | [Test] 52 | public void Empty_Test() 53 | { 54 | var stack = new BufferedStack(1000); 55 | for (int c = 0; c < 100; c++) 56 | stack.Push(1); 57 | Assert.AreEqual(stack.Count, 100); 58 | stack.Clear(); 59 | Assert.AreEqual(stack.Count, 0); 60 | } 61 | 62 | [Test] 63 | public void ReadOnly_Test() 64 | { 65 | var stack = new BufferedStack(1000); 66 | ICollection collection = stack; 67 | Assert.AreEqual(collection.IsReadOnly, false); 68 | } 69 | 70 | [Test] 71 | public void Index_Operator_Test() 72 | { 73 | var stack = new BufferedStack(1000); 74 | for (int c = 0; c < 100; c++) 75 | { 76 | stack.Push(c); 77 | Assert.AreEqual(stack[c], c); 78 | } 79 | } 80 | 81 | [Test] 82 | public void Peek_Test() 83 | { 84 | var stack = new BufferedStack(1000); 85 | for (int c = 0; c < 100; c++) 86 | { 87 | stack.Push(c); 88 | Assert.AreEqual(stack.Peek(), c); 89 | } 90 | } 91 | 92 | 93 | // TBD: Tests for ICollection interface functions 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/Collections/Generic/PriorityQueueTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | 9 | using NUnit.Framework; 10 | 11 | using SharpNav.Collections.Generic; 12 | 13 | namespace SharpNav.Tests.Collections.Generic 14 | { 15 | [TestFixture] 16 | public class PriorityQueueTests 17 | { 18 | [Test] 19 | public void TopTest() 20 | { 21 | } 22 | 23 | [Test] 24 | public void PopTest() 25 | { 26 | } 27 | 28 | [Test] 29 | public void PushTest() 30 | { 31 | } 32 | 33 | [Test] 34 | public void ContainsTest() 35 | { 36 | } 37 | 38 | [Test] 39 | public void ModifyTest() 40 | { 41 | } 42 | 43 | [Test] 44 | public void ValidHeapTest() 45 | { 46 | } 47 | 48 | [Test] 49 | public void MiscICollectionTests() 50 | { 51 | } 52 | 53 | [Test] 54 | public void StatusAccessorTests() 55 | { 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/CompactSpanTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | using NUnit.Framework; 8 | 9 | using SharpNav; 10 | 11 | namespace SharpNav.Tests 12 | { 13 | [TestFixture] 14 | public class CompactSpanTests 15 | { 16 | [Test] 17 | public void AddCompactSpan_NoUpperLimit_Success() 18 | { 19 | CompactSpan cs = new CompactSpan(10, int.MaxValue); 20 | 21 | Assert.IsFalse(cs.HasUpperBound); 22 | Assert.AreEqual(cs.ConnectionCount, 0); 23 | } 24 | 25 | [Test] 26 | public void AddCompactSpan_SetConnection_Success() 27 | { 28 | CompactSpan cs = new CompactSpan(10, int.MaxValue); 29 | CompactSpan.SetConnection((Direction)1, 1, ref cs); 30 | 31 | Assert.AreEqual(cs.ConnectionCount, 1); 32 | } 33 | 34 | [Test] 35 | public void AddCompactSpan_GetConnection_Success() 36 | { 37 | CompactSpan cs = new CompactSpan(10, int.MaxValue); 38 | CompactSpan.SetConnection((Direction)1, 50, ref cs); 39 | 40 | Assert.AreEqual(CompactSpan.GetConnection(ref cs, (Direction)1), 50); 41 | Assert.AreEqual(cs.GetConnection((Direction)1), 50); 42 | } 43 | 44 | [Test] 45 | public void AddCompactSpan_UnsetConnection_Success() 46 | { 47 | CompactSpan cs = new CompactSpan(10, int.MaxValue); 48 | CompactSpan.SetConnection((Direction)1, 1, ref cs); 49 | CompactSpan.UnsetConnection((Direction)1, ref cs); 50 | 51 | Assert.AreEqual(cs.ConnectionCount, 0); 52 | } 53 | 54 | [Test] 55 | public void AddCompactSpan_IsConnected_Success() 56 | { 57 | CompactSpan cs = new CompactSpan(10, int.MaxValue); 58 | CompactSpan.SetConnection(Direction.East, 1, ref cs); 59 | 60 | Assert.IsTrue(cs.IsConnected(Direction.East)); 61 | Assert.IsFalse(cs.IsConnected(Direction.West)); 62 | } 63 | 64 | [Test] 65 | public void SetConnection_TooHigh_Success() 66 | { 67 | CompactSpan cs = new CompactSpan(10, int.MaxValue); 68 | Assert.Throws(() => CompactSpan.SetConnection((Direction)2, 300, ref cs)); 69 | } 70 | 71 | [Test] 72 | public void SetConnection_InvalidDirection_Success() 73 | { 74 | CompactSpan cs = new CompactSpan(10, int.MaxValue); 75 | Assert.Throws(() => CompactSpan.SetConnection((Direction)(-1), 1, ref cs)); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/ContourTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | using SharpNav.Geometry; 8 | 9 | using NUnit.Framework; 10 | 11 | #if MONOGAME 12 | using Vector3 = Microsoft.Xna.Framework.Vector3; 13 | #elif OPENTK 14 | using Vector3 = OpenTK.Vector3; 15 | #elif SHARPDX 16 | using Vector3 = SharpDX.Vector3; 17 | #endif 18 | 19 | namespace SharpNav.Tests 20 | { 21 | [TestFixture] 22 | public class ContourTests 23 | { 24 | [Test] 25 | public void ContourConstructor() 26 | { 27 | //TODO directly build contours now that ContourSet allows it. 28 | //Build a 5x5 heightfield 29 | Heightfield hf = new Heightfield(new BBox3(Vector3.Zero, Vector3.One), (float)(1.0f / 5.0f), 0.02f); 30 | for (int i = 0; i < 5 * 5; i++) 31 | { 32 | hf[i].AddSpan(new Span(10, 20, Area.Default)); 33 | hf[i].AddSpan(new Span(25, 30, Area.Default)); 34 | } 35 | CompactHeightfield chf = new CompactHeightfield(hf, 2, 1); 36 | 37 | chf.BuildDistanceField(); 38 | chf.BuildRegions(1, 1, 1); 39 | 40 | ContourSet contourSet = chf.BuildContourSet(1, 5, ContourBuildFlags.None); 41 | 42 | Assert.AreEqual(contourSet.Count, 2); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/Geometry/ContainmentTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | using NUnit.Framework; 7 | 8 | using SharpNav; 9 | using SharpNav.Geometry; 10 | 11 | #if MONOGAME 12 | using Vector3 = Microsoft.Xna.Framework.Vector3; 13 | #elif OPENTK 14 | using Vector3 = OpenTK.Vector3; 15 | #elif SHARPDX 16 | using Vector3 = SharpDX.Vector3; 17 | #endif 18 | 19 | namespace SharpNav.Tests.Geometry 20 | { 21 | [TestFixture] 22 | public class ContainmentTests 23 | { 24 | [Test] 25 | public void PointInPoly_InternalPoint_Success() 26 | { 27 | Vector3 pt = new Vector3(0.0f, 0.0f, 0.5f); 28 | 29 | Vector3[] poly = new Vector3[3]; 30 | poly[0] = new Vector3(0.0f, 0.0f, 1.0f); 31 | poly[1] = new Vector3(-1.0f, 0.0f, 0.0f); 32 | poly[2] = new Vector3(1.0f, 0.0f, 0.0f); 33 | 34 | bool isInPoly = Containment.PointInPoly(pt, poly, poly.Length); 35 | 36 | Assert.IsTrue(isInPoly); 37 | } 38 | 39 | [Test] 40 | public void PointInPoly_BoundaryPoint_Success() 41 | { 42 | Vector3 pt = new Vector3(0.0f, 0.0f, 0.0f); 43 | 44 | Vector3[] poly = new Vector3[3]; 45 | poly[0] = new Vector3(0.0f, 0.0f, 1.0f); 46 | poly[1] = new Vector3(-1.0f, 0.0f, 0.0f); 47 | poly[2] = new Vector3(1.0f, 0.0f, 0.0f); 48 | 49 | bool isInPoly = Containment.PointInPoly(pt, poly, poly.Length); 50 | 51 | Assert.IsTrue(isInPoly); 52 | } 53 | 54 | [Test] 55 | public void PointInPoly_ExternalPoint_Success() 56 | { 57 | Vector3 pt = new Vector3(-1.0f, 0.0f, -1.0f); 58 | 59 | Vector3[] poly = new Vector3[3]; 60 | poly[0] = new Vector3(0.0f, 0.0f, 1.0f); 61 | poly[1] = new Vector3(-1.0f, 0.0f, 0.0f); 62 | poly[2] = new Vector3(1.0f, 0.0f, 0.0f); 63 | 64 | bool isInPoly = Containment.PointInPoly(pt, poly, poly.Length); 65 | 66 | Assert.IsFalse(isInPoly); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/Geometry/DistanceTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | using NUnit.Framework; 7 | 8 | using SharpNav; 9 | using SharpNav.Geometry; 10 | 11 | #if MONOGAME 12 | using Vector3 = Microsoft.Xna.Framework.Vector3; 13 | #elif OPENTK 14 | using Vector3 = OpenTK.Vector3; 15 | #elif SHARPDX 16 | using Vector3 = SharpDX.Vector3; 17 | #endif 18 | 19 | namespace SharpNav.Tests.Geometry 20 | { 21 | [TestFixture] 22 | public class DistanceTests 23 | { 24 | [Test] 25 | public void PointToSegment2DSquared_NoVectors_Success() 26 | { 27 | //point is (0, 0), segment is (0, 1) to (1,0) 28 | float dist = Distance.PointToSegment2DSquared(0, 0, 0, 1, 1, 0); 29 | 30 | //safe floating value comparison 31 | Assert.AreEqual(dist + float.Epsilon, 0.5f); 32 | } 33 | 34 | [Test] 35 | public void PointToSegment2DSquared_Vectors_Success() 36 | { 37 | //the point 38 | Vector3 pt = new Vector3(0, 0, 0); 39 | 40 | //the segment 41 | Vector3 p = new Vector3(0, 0, 1); 42 | Vector3 q = new Vector3(1, 0, 0); 43 | 44 | float dist = Distance.PointToSegment2DSquared(ref pt, ref p, ref q); 45 | 46 | //safe floating value comparison 47 | Assert.AreEqual(dist + float.Epsilon, 0.5f); 48 | } 49 | 50 | [Test] 51 | public void PointToSegment2DSquared_VectorsWithParameters_Success() 52 | { 53 | //the point 54 | Vector3 pt = new Vector3(0, 0, 0); 55 | 56 | //the segment 57 | Vector3 p = new Vector3(0, 0, 1); 58 | Vector3 q = new Vector3(1, 0, 0); 59 | 60 | //the paramater t 61 | float t; 62 | 63 | float dist = Distance.PointToSegment2DSquared(ref pt, ref p, ref q, out t); 64 | 65 | //safe floating value comparison 66 | Assert.AreEqual(dist + float.Epsilon, 0.5f); 67 | Assert.AreEqual(t + float.Epsilon, 0.5f); 68 | } 69 | 70 | [Test] 71 | public void PointToTriangle_CenterPointDist_Success() 72 | { 73 | //Point 74 | Vector3 p = new Vector3(0.5f, 0.5f, 0.5f); 75 | 76 | //Triangle 77 | Vector3 a = new Vector3(0, 0, 1); 78 | Vector3 b = new Vector3(-1, 0, 0); 79 | Vector3 c = new Vector3(1, 0, 0); 80 | 81 | float dist = Distance.PointToTriangle(p, a, b, c); 82 | 83 | Assert.AreEqual(dist + float.Epsilon, 0.5f); 84 | } 85 | 86 | [Test] 87 | public void PointToTriangle_EdgePointDist_Success() 88 | { 89 | //Point 90 | Vector3 p = new Vector3(0.0f, 0.0f, 0.0f); 91 | 92 | //Triangle 93 | Vector3 a = new Vector3(0, 0, 1); 94 | Vector3 b = new Vector3(-1, 0, 0); 95 | Vector3 c = new Vector3(1, 0, 0); 96 | 97 | float dist = Distance.PointToTriangle(p, a, b, c); 98 | 99 | Assert.AreEqual(dist, 0.0f); 100 | } 101 | 102 | [Test] 103 | public void PointToTriangle_CenterPointBool_Success() 104 | { 105 | //Point 106 | Vector3 p = new Vector3(0.5f, 0.5f, 0.5f); 107 | 108 | //Triangle 109 | Vector3 a = new Vector3(0, 0, 1); 110 | Vector3 b = new Vector3(-1, 0, 0); 111 | Vector3 c = new Vector3(1, 0, 0); 112 | 113 | float height; 114 | bool isInTriangle = Distance.PointToTriangle(p, a, b, c, out height); 115 | 116 | Assert.AreEqual(height, 0.0f); 117 | Assert.IsTrue(isInTriangle); 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/Geometry/IntersectionTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | using NUnit.Framework; 7 | 8 | using SharpNav; 9 | using SharpNav.Geometry; 10 | 11 | #if MONOGAME 12 | using Vector3 = Microsoft.Xna.Framework.Vector3; 13 | #elif OPENTK 14 | using Vector3 = OpenTK.Vector3; 15 | #elif SHARPDX 16 | using Vector3 = SharpDX.Vector3; 17 | #endif 18 | 19 | namespace SharpNav.Tests.Geometry 20 | { 21 | [TestFixture] 22 | public class IntersectionTests 23 | { 24 | [Test] 25 | public void SegmentSegment2D_without_float_success() 26 | { 27 | //the Segment 1 28 | Vector3 a = new Vector3(0, 0, 0); 29 | Vector3 b = new Vector3(1, 0, 1); 30 | 31 | //the segment 2 32 | Vector3 p = new Vector3(0, 0, 1); 33 | Vector3 q = new Vector3(1, 0, 0); 34 | bool f = Intersection.SegmentSegment2D(ref a, ref b, ref p, ref q); 35 | Assert.IsTrue(f); 36 | 37 | } 38 | 39 | [Test] 40 | public void SegmentSegment2D_without_float_false() 41 | { 42 | //the Segment 1 43 | Vector3 a = new Vector3(0, 0, 0); 44 | Vector3 b = new Vector3(1, 0, 1); 45 | 46 | //the segment 2 47 | Vector3 p = new Vector3(1, 0, 0); 48 | Vector3 q = new Vector3(2, 0, 1); 49 | bool f = Intersection.SegmentSegment2D(ref a, ref b, ref p, ref q); 50 | Assert.IsFalse(f); 51 | 52 | } 53 | 54 | [Test] 55 | public void SegmentSegment2D_with_float_success() 56 | { 57 | //the Segment 1 58 | Vector3 a = new Vector3(0, 0, 0); 59 | Vector3 b = new Vector3(1, 0, 1); 60 | 61 | //the segment 2 62 | Vector3 p = new Vector3(0, 0, 1); 63 | Vector3 q = new Vector3(1, 0, 0); 64 | float m; 65 | float n; 66 | bool f = Intersection.SegmentSegment2D(ref a, ref b, ref p, ref q, out m, out n); 67 | Assert.IsTrue(f); 68 | 69 | } 70 | 71 | [Test] 72 | public void SegmentSegment2D_with_float_false() 73 | { 74 | //the Segment 1 75 | Vector3 a = new Vector3(0, 0, 0); 76 | Vector3 b = new Vector3(1, 0, 1); 77 | 78 | //the segment 2 79 | Vector3 p = new Vector3(1, 0, 0); 80 | Vector3 q = new Vector3(2, 0, 1); 81 | float m; 82 | float n; 83 | bool f = Intersection.SegmentSegment2D(ref a, ref b, ref p, ref q, out m, out n); 84 | Assert.IsFalse(f); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/HeightfieldTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | using NUnit.Framework; 7 | 8 | using SharpNav; 9 | using SharpNav.Geometry; 10 | 11 | #if MONOGAME 12 | using Vector3 = Microsoft.Xna.Framework.Vector3; 13 | #elif OPENTK 14 | using Vector3 = OpenTK.Vector3; 15 | #elif SHARPDX 16 | using Vector3 = SharpDX.Vector3; 17 | #endif 18 | 19 | namespace SharpNav.Tests 20 | { 21 | [TestFixture] 22 | public class HeightfieldTests 23 | { 24 | [Test] 25 | public void Indexer_Valid_ReturnsCell() 26 | { 27 | var hf = new Heightfield(new BBox3(Vector3.Zero, Vector3.One), 0.5f, 0.5f); 28 | 29 | Assert.IsNotNull(hf[0, 1]); 30 | } 31 | 32 | [Test] 33 | public void Indexer_NegativeX_Throws() 34 | { 35 | var hf = new Heightfield(new BBox3(Vector3.Zero, Vector3.One), 0.5f, 0.5f); 36 | 37 | Assert.Throws(() => { var c = hf[-1, 1]; }); 38 | } 39 | 40 | [Test] 41 | public void Indexer_NegativeY_Throws() 42 | { 43 | var hf = new Heightfield(new BBox3(Vector3.Zero, Vector3.One), 0.5f, 0.5f); 44 | 45 | Assert.Throws(() => { var c = hf[1, -1]; }); 46 | } 47 | 48 | [Test] 49 | public void Indexer_NegativeBoth_Throws() 50 | { 51 | var hf = new Heightfield(new BBox3(Vector3.Zero, Vector3.One), 0.5f, 0.5f); 52 | 53 | Assert.Throws(() => { var c = hf[-1, -1]; }); 54 | } 55 | 56 | [Test] 57 | public void Indexer_TooLargeX_Throws() 58 | { 59 | var hf = new Heightfield(new BBox3(Vector3.Zero, Vector3.One), 0.5f, 0.5f); 60 | 61 | Assert.Throws(() => { var c = hf[2, 0]; }); 62 | } 63 | 64 | [Test] 65 | public void Indexer_TooLargeY_Throws() 66 | { 67 | var hf = new Heightfield(new BBox3(Vector3.Zero, Vector3.One), 0.5f, 0.5f); 68 | 69 | Assert.Throws(() => { var c = hf[0, 2]; }); 70 | } 71 | 72 | [Test] 73 | public void Indexer_TooLargeBoth_Throws() 74 | { 75 | var hf = new Heightfield(new BBox3(Vector3.Zero, Vector3.One), 0.5f, 0.5f); 76 | 77 | Assert.Throws(() => { var c = hf[3, 3]; }); 78 | } 79 | 80 | [Test] 81 | public void Indexer_CellOutOfRange_Throws() 82 | { 83 | var hf = new Heightfield(new BBox3(Vector3.Zero, Vector3.One), 0.5f, 0.5f); 84 | Assert.Throws(() => { var c = hf[5]; }); 85 | } 86 | 87 | [Test] 88 | public void Filter_LowHangingWalkable_Success() 89 | { 90 | var hf = new Heightfield(new BBox3(Vector3.Zero, Vector3.One), 0.5f, 0.02f); 91 | var span = new Span(10, 15, Area.Default); 92 | var span2 = new Span(16, 20, Area.Null); 93 | 94 | hf[0].AddSpan(span); 95 | hf[0].AddSpan(span2); 96 | 97 | hf.FilterLowHangingWalkableObstacles(20); 98 | 99 | Assert.AreEqual(hf[0].Spans[0].Area, hf[0].Spans[1].Area); 100 | } 101 | 102 | [Test] 103 | public void Filter_LowHangingWalkable_Fail() 104 | { 105 | var hf = new Heightfield(new BBox3(Vector3.Zero, Vector3.One), 0.5f, 0.02f); 106 | var span = new Span(1, 2, Area.Default); 107 | var span2 = new Span(10, 20, Area.Null); 108 | 109 | hf[2].AddSpan(span); 110 | hf[2].AddSpan(span2); 111 | 112 | //walkable step cannot cover the gap (difference between span2 maximum and span 1 maximum) so fail 113 | hf.FilterLowHangingWalkableObstacles(10); 114 | Assert.AreNotEqual(hf[0, 1].Spans[0].Area, hf[0, 1].Spans[1].Area); 115 | } 116 | 117 | [Test] 118 | public void Filter_WalkableLowHeight_Success() 119 | { 120 | var hf = new Heightfield(new BBox3(Vector3.Zero, Vector3.One), 0.5f, 0.02f); 121 | var span = new Span(10, 20, Area.Default); 122 | var span2 = new Span(25, 30, Area.Default); 123 | 124 | hf[0].AddSpan(span); 125 | hf[0].AddSpan(span2); 126 | 127 | //too low to walk through. there is only a gap of 5 units to walk through, 128 | //but at least 15 units is needed 129 | hf.FilterWalkableLowHeightSpans(15); 130 | 131 | //so one span is unwalkable and the other is fine 132 | Assert.AreEqual(hf[0].Spans[0].Area, Area.Null); 133 | Assert.AreEqual(hf[0].Spans[1].Area, Area.Default); 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/IO/Json/NavMeshJsonSerializerTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System.IO; 5 | 6 | using NUnit.Framework; 7 | 8 | using SharpNav.IO.Json; 9 | 10 | namespace SharpNav.Tests 11 | { 12 | [TestFixture] 13 | class NavMeshSerializationTests 14 | { 15 | [Test] 16 | public void JsonSerializationTest() 17 | { 18 | string objPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "nav_test.obj"); 19 | string snjPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "mesh.snj"); 20 | 21 | var objModel = new ObjModel(objPath); 22 | TiledNavMesh mesh = NavMesh.Generate(objModel.GetTriangles(), NavMeshGenerationSettings.Default); 23 | new NavMeshJsonSerializer().Serialize(snjPath, mesh); 24 | 25 | TiledNavMesh deserializedMesh = new NavMeshJsonSerializer().Deserialize(snjPath); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/JsonTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | using Newtonsoft.Json; 7 | 8 | using NUnit.Framework; 9 | 10 | using SharpNav; 11 | using SharpNavTests; 12 | using SharpNav.Geometry; 13 | 14 | #if MONOGAME || XNA 15 | using Microsoft.Xna.Framework; 16 | #elif OPENTK 17 | using OpenTK; 18 | #elif SHARPDX 19 | using SharpDX; 20 | #elif UNITY3D 21 | using UnityEngine; 22 | #endif 23 | 24 | namespace SharpNavTests.Libraries 25 | { 26 | [TestFixture] 27 | class JsonTest 28 | { 29 | [Test] 30 | public void JsonNet_Test() 31 | { 32 | // Simple test to make sure that the JSON.Net library is working 33 | Triangle3 triangle = new Triangle3(new Vector3(3), new Vector3(4), new Vector3(5)); 34 | string output = JsonConvert.SerializeObject(triangle); 35 | 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/MathHelperTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | using NUnit.Framework; 7 | 8 | using SharpNav; 9 | using SharpNav.Geometry; 10 | 11 | #if MONOGAME 12 | using Vector3 = Microsoft.Xna.Framework.Vector3; 13 | #elif OPENTK 14 | using Vector3 = OpenTK.Vector3; 15 | #elif SHARPDX 16 | using Vector3 = SharpDX.Vector3; 17 | #endif 18 | 19 | using MathHelper = SharpNav.MathHelper; 20 | 21 | namespace SharpNav.Tests 22 | { 23 | [TestFixture] 24 | public class MathHelperTests 25 | { 26 | [Test] 27 | public void ClampTest_ValOutOfRange_Success() 28 | { 29 | int num = MathHelper.Clamp(3, 6, 10); 30 | Assert.AreEqual (num, 6); 31 | } 32 | 33 | [Test] 34 | public void ClampTest_ValInRange_Success() 35 | { 36 | int num = MathHelper.Clamp(7, 4, 10); 37 | Assert.AreEqual(num, 7); 38 | } 39 | 40 | [Test] 41 | public void ClampTest_ValOutOfRangeRef_Success() 42 | { 43 | int num_r = 3; 44 | MathHelper.Clamp(ref num_r, 6, 10); 45 | Assert.AreEqual(num_r, 6); 46 | } 47 | 48 | [Test] 49 | public void ClampTest_ValInRangeRef_Success() 50 | { 51 | int num_r = 7; 52 | MathHelper.Clamp(ref num_r, 6, 10); 53 | Assert.AreEqual(num_r, 7); 54 | } 55 | 56 | [Test] 57 | public void ClampTest_ValInRangeFloat_Success() 58 | { 59 | float num = MathHelper.Clamp(7.56f, 6.75f, 10.89f); 60 | Assert.AreEqual(num, 7.56f); 61 | } 62 | 63 | [Test] 64 | public void ClampTest_ValOutOfRangeFloat_Success() 65 | { 66 | float num = MathHelper.Clamp(3.89f, 6.75f, 10.89f); 67 | Assert.AreEqual(num, 6.75f); 68 | } 69 | 70 | public void ClampTest_ValInRangeFloatRef_Success() 71 | { 72 | float num_r = 7.56f; 73 | MathHelper.Clamp(ref num_r, 6.75f, 10.89f); 74 | Assert.AreEqual(num_r, 7.56f); 75 | } 76 | 77 | [Test] 78 | public void ClampTest_ValOutOfRangeFloatRef_Success() 79 | { 80 | float num_r = 3.89f; 81 | MathHelper.Clamp(ref num_r, 6.75f, 10.89f); 82 | Assert.AreEqual (num_r, 6.75f); 83 | } 84 | 85 | [Test] 86 | public void NextPowerOfTwo_PositiveIntegerInt_Sucess() 87 | { 88 | int num = MathHelper.NextPowerOfTwo(5); 89 | 90 | Assert.AreEqual(num, 8); 91 | } 92 | 93 | [Test] 94 | public void NextPowerOfTwo_PositiveIntegerUint_Sucess() 95 | { 96 | uint num = MathHelper.NextPowerOfTwo((uint)5); 97 | 98 | Assert.AreEqual(num, 8); 99 | } 100 | 101 | [Test] 102 | public void Log2_PositiveIntegerInt_Success() 103 | { 104 | int num = MathHelper.Log2(65); 105 | 106 | Assert.AreEqual(num, 6); 107 | } 108 | 109 | [Test] 110 | public void Log2_PositiveIntegerUint_Success() 111 | { 112 | uint num = MathHelper.Log2((uint)65); 113 | 114 | Assert.AreEqual(num, 6); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/OpenTK.dll.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System.Reflection; 5 | using System.Runtime.CompilerServices; 6 | using System.Runtime.InteropServices; 7 | 8 | // General Information about an assembly is controlled through the following 9 | // set of attributes. Change these attribute values to modify the information 10 | // associated with an assembly. 11 | [assembly: AssemblyTitle("SharpNavTests")] 12 | [assembly: AssemblyDescription("Unit tests for SharpNav.")] 13 | [assembly: AssemblyConfiguration("")] 14 | [assembly: AssemblyCompany("")] 15 | [assembly: AssemblyProduct("SharpNavTests")] 16 | [assembly: AssemblyCopyright("Copyright © 2013-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file).")] 17 | [assembly: AssemblyTrademark("")] 18 | [assembly: AssemblyCulture("")] 19 | 20 | // Setting ComVisible to false makes the types in this assembly not visible 21 | // to COM components. If you need to access a type in this assembly from 22 | // COM, set the ComVisible attribute to true on that type. 23 | [assembly: ComVisible(false)] 24 | 25 | // The following GUID is for the ID of the typelib if this project is exposed to COM 26 | [assembly: Guid("03a13e8d-76ad-4b78-be2e-980538084c58")] 27 | 28 | // Version information for an assembly consists of the following four values: 29 | // 30 | // Major Version 31 | // Minor Version 32 | // Build Number 33 | // Revision 34 | // 35 | // You can specify all the values or you can default the Build and Revision Numbers 36 | // by using the '*' as shown below: 37 | // [assembly: AssemblyVersion("1.0.*")] 38 | [assembly: AssemblyVersion("1.0.0.1")] 39 | [assembly: AssemblyFileVersion("1.0.0.0")] 40 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/RegionTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | using NUnit.Framework; 7 | 8 | using SharpNav; 9 | 10 | namespace SharpNav.Tests 11 | { 12 | [TestFixture] 13 | public class RegionTests 14 | { 15 | [Test] 16 | public void Region_AvoidDuplicateFloors_Success() 17 | { 18 | var reg = new Region(1); 19 | 20 | reg.AddUniqueFloorRegion(new RegionId(10)); 21 | reg.AddUniqueFloorRegion(new RegionId(10)); 22 | reg.AddUniqueFloorRegion(new RegionId(20)); 23 | 24 | Assert.AreEqual((int)reg.FloorRegions[0], 10); 25 | Assert.AreEqual((int)reg.FloorRegions[1], 20); 26 | Assert.AreEqual(reg.FloorRegions.Count, 2); 27 | } 28 | 29 | [Test] 30 | public void Region_RemoveAdjacentConnections_Success() 31 | { 32 | var reg = new Region(1); 33 | 34 | reg.Connections.Add(new RegionId(10)); 35 | reg.Connections.Add(new RegionId(20)); 36 | reg.Connections.Add(new RegionId(20)); 37 | reg.RemoveAdjacentNeighbors(); 38 | 39 | Assert.AreEqual((int)reg.Connections[1], 20); 40 | } 41 | 42 | [Test] 43 | public void Region_ConnectedBorder_Success() 44 | { 45 | var reg = new Region(1); 46 | 47 | reg.Connections.Add(new RegionId(10)); 48 | reg.Connections.Add(new RegionId(20)); 49 | reg.Connections.Add(new RegionId(30)); 50 | 51 | Assert.AreEqual(reg.IsConnectedToBorder(), false); 52 | } 53 | 54 | [Test] 55 | public void Region_ReplaceNeighbor_Success() 56 | { 57 | var reg = new Region(1); 58 | 59 | reg.Connections.Add(new RegionId(10)); 60 | reg.Connections.Add(new RegionId(20)); 61 | reg.Connections.Add(new RegionId(30)); 62 | 63 | reg.AddUniqueFloorRegion(new RegionId(10)); 64 | reg.AddUniqueFloorRegion(new RegionId(20)); 65 | reg.AddUniqueFloorRegion(new RegionId(30)); 66 | 67 | reg.ReplaceNeighbor(new RegionId(10), RegionId.Null); 68 | 69 | Assert.AreEqual((int)reg.Connections[0], 0); 70 | Assert.AreEqual((int)reg.FloorRegions[0], 0); 71 | } 72 | 73 | [Test] 74 | public void Region_MergeWithOther_Success() 75 | { 76 | var reg1 = new Region(1); 77 | var reg2 = new Region(2); 78 | 79 | reg1.Connections.Add(new RegionId(2)); 80 | reg1.AddUniqueFloorRegion(new RegionId(1)); 81 | reg1.AddUniqueFloorRegion(new RegionId(3)); 82 | 83 | Assert.True(reg1.CanMergeWith(reg2)); 84 | Assert.True(reg2.CanMergeWith(reg1)); 85 | } 86 | 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Source/SharpNav.Tests/SharpNav.Tests.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Source/SharpNav.Tests/SharpNav.Tests.snk -------------------------------------------------------------------------------- /Source/SharpNav.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Source/SharpNav/Area.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace SharpNav 8 | { 9 | /// 10 | /// An area groups together pieces of data through the navmesh generation process. 11 | /// 12 | [Serializable] 13 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 14 | public struct Area : IEquatable, IEquatable 15 | { 16 | /// 17 | /// The maximum number of areas that can be defined. 18 | /// 19 | public const int MaxValues = 256; 20 | 21 | /// 22 | /// The null area is one that is considered unwalkable. 23 | /// 24 | public static readonly Area Null = new Area(0); 25 | 26 | /// 27 | /// This is a default in the event that the user does not provide one. 28 | /// 29 | /// 30 | /// If a user only applies IDs to some parts of a , they will most likely choose low 31 | /// integer values. Choosing the maximum value makes it unlikely for the "default" area to collide with any 32 | /// user-defined areas. 33 | /// 34 | public static readonly Area Default = new Area(0xff); 35 | 36 | /// 37 | /// The identifier for an area, represented as a byte. 38 | /// 39 | public readonly byte Id; 40 | 41 | /// 42 | /// Initializes a new instance of the struct. 43 | /// 44 | /// An identifier for the area. 45 | public Area(byte id) 46 | { 47 | this.Id = id; 48 | } 49 | 50 | /// 51 | /// Gets a value indicating whether the area is considered walkable (not ). 52 | /// 53 | public bool IsWalkable 54 | { 55 | get 56 | { 57 | return Id != 0; 58 | } 59 | } 60 | 61 | /// 62 | /// Implicitly casts a byte to an Area. This is included since an Area is a very thin wrapper around a byte. 63 | /// 64 | /// The identifier for an area. 65 | /// An area with the specified identifier. 66 | public static implicit operator Area(byte value) 67 | { 68 | return new Area(value); 69 | } 70 | 71 | /// 72 | /// Compares two areas for equality. 73 | /// 74 | /// An . 75 | /// Another 76 | /// A value indicating whether the two s are equal. 77 | public static bool operator ==(Area left, Area right) 78 | { 79 | return left.Equals(right); 80 | } 81 | 82 | /// 83 | /// Compares two areas for inequality. 84 | /// 85 | /// An . 86 | /// Another 87 | /// A value indicating whether the two s are unequal. 88 | public static bool operator !=(Area left, Area right) 89 | { 90 | return !(left == right); 91 | } 92 | 93 | /// 94 | /// Compares this instance with another instance of for equality. 95 | /// 96 | /// An . 97 | /// A value indicating whether the two s are equal. 98 | public bool Equals(Area other) 99 | { 100 | return this.Id == other.Id; 101 | } 102 | 103 | /// 104 | /// Compares this instance with a byte representing another for equality. 105 | /// 106 | /// A byte. 107 | /// A value indicating whether this instance and the specified byte are equal. 108 | public bool Equals(byte other) 109 | { 110 | return this.Id == other; 111 | } 112 | 113 | /// 114 | /// Compares this instance with another object for equality. 115 | /// 116 | /// An object. 117 | /// A value indicating whether this instance and the specified object are equal. 118 | public override bool Equals(object obj) 119 | { 120 | var areaObj = obj as Area?; 121 | var byteObj = obj as byte?; 122 | 123 | if (areaObj.HasValue) 124 | return this.Equals(areaObj.Value); 125 | else if (byteObj.HasValue) 126 | return this.Equals(byteObj.Value); 127 | else 128 | return false; 129 | } 130 | 131 | /// 132 | /// Generates a hashcode unique to the of this instance. 133 | /// 134 | /// A hash code. 135 | public override int GetHashCode() 136 | { 137 | return Id.GetHashCode(); 138 | } 139 | 140 | /// 141 | /// Converts this instance to a human-readable string. 142 | /// 143 | /// A string representing this instance. 144 | public override string ToString() 145 | { 146 | if (Id == 0) 147 | return "Null/Unwalkable"; 148 | else 149 | return Id.ToString(); 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /Source/SharpNav/Collections/Generic/IValueWithCost.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | namespace SharpNav.Collections.Generic 5 | { 6 | /// 7 | /// An interface that defines a class containing a cost associated with the instance. 8 | /// Used in 9 | /// 10 | public interface IValueWithCost 11 | { 12 | /// 13 | /// Gets the cost of this instance. 14 | /// 15 | float Cost { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Source/SharpNav/CompactCell.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System.Runtime.InteropServices; 5 | 6 | namespace SharpNav 7 | { 8 | /// 9 | /// Represents a cell in a . 10 | /// 11 | [StructLayout(LayoutKind.Sequential)] 12 | public struct CompactCell 13 | { 14 | /// 15 | /// The starting index of spans in a for this cell. 16 | /// 17 | public int StartIndex; 18 | 19 | /// 20 | /// The number of spans in a for this cell. 21 | /// 22 | public int Count; 23 | 24 | /// 25 | /// Initializes a new instance of the struct. 26 | /// 27 | /// The start index. 28 | /// The count. 29 | public CompactCell(int start, int count) 30 | { 31 | StartIndex = start; 32 | Count = count; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Source/SharpNav/CompactSpanReference.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace SharpNav 8 | { 9 | /// 10 | /// A reference to a in a . 11 | /// 12 | [StructLayout(LayoutKind.Sequential)] 13 | public struct CompactSpanReference : IEquatable 14 | { 15 | /// 16 | /// A "null" reference is one with a negative index. 17 | /// 18 | public static readonly CompactSpanReference Null = new CompactSpanReference(0, 0, -1); 19 | 20 | /// 21 | /// The X coordinate of the referenced span. 22 | /// 23 | public readonly int X; 24 | 25 | /// 26 | /// The Y coordinate of the referenced span. 27 | /// 28 | public readonly int Y; 29 | 30 | /// 31 | /// The index of the referenced span in the spans array. 32 | /// 33 | public readonly int Index; 34 | 35 | /// 36 | /// Initializes a new instance of the struct. 37 | /// 38 | /// The X coordinate. 39 | /// The Y coordinate. 40 | /// The index of the span in the spans array. 41 | public CompactSpanReference(int x, int y, int i) 42 | { 43 | this.X = x; 44 | this.Y = y; 45 | this.Index = i; 46 | } 47 | 48 | /// 49 | /// Compares two instances of for equality. 50 | /// 51 | /// 52 | /// If both references have a negative , they are considered equal, as both would be considered "null". 53 | /// 54 | /// A reference. 55 | /// Another reference. 56 | /// A value indicating whether the two references are equal. 57 | public static bool operator ==(CompactSpanReference left, CompactSpanReference right) 58 | { 59 | //A negative index is considered null. 60 | //these two cases quickly compare null references. 61 | bool leftNull = left.Index < 0, rightNull = right.Index < 0; 62 | if (leftNull && rightNull) 63 | return true; 64 | else if (leftNull ^ rightNull) 65 | return false; 66 | 67 | //if the references are not null, 68 | else if (left.X == right.X && left.Y == right.Y && left.Index == right.Index) 69 | return true; 70 | 71 | return false; 72 | } 73 | 74 | /// 75 | /// Compare two instances of for inequality. 76 | /// 77 | /// 78 | /// If both references have a negative , they are considered equal, as both would be considered "null". 79 | /// 80 | /// A reference. 81 | /// Another reference. 82 | /// A value indicating whether the two references are not equal. 83 | public static bool operator !=(CompactSpanReference left, CompactSpanReference right) 84 | { 85 | return !(left == right); 86 | } 87 | 88 | /// 89 | /// Compares this instance to another instance of for equality. 90 | /// 91 | /// Another instance of . 92 | /// A value indicating whether this instance and another instance are equal. 93 | public bool Equals(CompactSpanReference other) 94 | { 95 | return this == other; 96 | } 97 | 98 | /// 99 | /// Compares this instance to another object for equality. 100 | /// 101 | /// An object. 102 | /// A value indicating whether the object is equal to this instance. 103 | public override bool Equals(object obj) 104 | { 105 | CompactSpanReference? r = obj as CompactSpanReference?; 106 | if (r.HasValue) 107 | return this == r.Value; 108 | return false; 109 | } 110 | 111 | /// 112 | /// Gets a hash code unique to this instance. 113 | /// 114 | /// A hash code. 115 | public override int GetHashCode() 116 | { 117 | //TODO should "null" references all have the same hash? 118 | int hash = 27; 119 | hash = (13 * hash) + X.GetHashCode(); 120 | hash = (13 * hash) + Y.GetHashCode(); 121 | hash = (13 * hash) + Index.GetHashCode(); 122 | 123 | return hash; 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /Source/SharpNav/ContourBuildFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, 2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | namespace SharpNav 7 | { 8 | /// 9 | /// A set of flags that control the way contours are built. 10 | /// 11 | [Flags] 12 | public enum ContourBuildFlags 13 | { 14 | /// Build normally. 15 | None = 0, 16 | 17 | /// Tessellate solid edges during contour simplification. 18 | TessellateWallEdges = 0x01, 19 | 20 | /// Tessellate edges between areas during contour simplification. 21 | TessellateAreaEdges = 0x02 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Source/SharpNav/ContourVertex.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | using SharpNav.Geometry; 8 | 9 | #if MONOGAME 10 | using Vector3 = Microsoft.Xna.Framework.Vector3; 11 | #elif OPENTK 12 | using Vector3 = OpenTK.Vector3; 13 | #elif SHARPDX 14 | using Vector3 = SharpDX.Vector3; 15 | #endif 16 | 17 | namespace SharpNav 18 | { 19 | /// 20 | /// A is a vertex that stores 3 integer coordinates and a region ID, and is used to build s. 21 | /// 22 | [StructLayout(LayoutKind.Sequential)] 23 | public struct ContourVertex 24 | { 25 | /// 26 | /// The X coordinate. 27 | /// 28 | public int X; 29 | 30 | /// 31 | /// The Y coordinate. 32 | /// 33 | public int Y; 34 | 35 | /// 36 | /// The Z coordinate. 37 | /// 38 | public int Z; 39 | 40 | /// 41 | /// The region that the vertex belongs to. 42 | /// 43 | public RegionId RegionId; 44 | 45 | /// 46 | /// Initializes a new instance of the struct. 47 | /// 48 | /// The X coordinate. 49 | /// The Y coordinate. 50 | /// The Z coordinate. 51 | /// The region ID. 52 | public ContourVertex(int x, int y, int z, RegionId region) 53 | { 54 | this.X = x; 55 | this.Y = y; 56 | this.Z = z; 57 | this.RegionId = region; 58 | } 59 | 60 | /// 61 | /// Initializes a new instance of the struct. 62 | /// 63 | /// The array of X,Y,Z coordinates. 64 | /// The Region ID. 65 | public ContourVertex(Vector3 vec, RegionId region) 66 | { 67 | this.X = (int)vec.X; 68 | this.Y = (int)vec.Y; 69 | this.Z = (int)vec.Z; 70 | this.RegionId = region; 71 | } 72 | 73 | /// 74 | /// Initializes a new instance of the struct as a copy. 75 | /// 76 | /// The original vertex. 77 | /// The index of the original vertex, which is temporarily stored in the field. 78 | public ContourVertex(ContourVertex vert, int index) 79 | { 80 | this.X = vert.X; 81 | this.Y = vert.Y; 82 | this.Z = vert.Z; 83 | this.RegionId = new RegionId(index); 84 | } 85 | 86 | /// 87 | /// Initializes a new instance of the struct as a copy. 88 | /// 89 | /// The original vertex. 90 | /// The region that the vertex belongs to. 91 | public ContourVertex(ContourVertex vert, RegionId region) 92 | { 93 | this.X = vert.X; 94 | this.Y = vert.Y; 95 | this.Z = vert.Z; 96 | this.RegionId = region; 97 | } 98 | 99 | /// 100 | /// Gets the leftness of a triangle formed from 3 contour vertices. 101 | /// 102 | /// The first vertex. 103 | /// The second vertex. 104 | /// The third vertex. 105 | /// A value indicating the leftness of the triangle. 106 | public static bool IsLeft(ref ContourVertex a, ref ContourVertex b, ref ContourVertex c) 107 | { 108 | int area; 109 | Area2D(ref a, ref b, ref c, out area); 110 | return area < 0; 111 | } 112 | 113 | /// 114 | /// Gets the 2D area of the triangle ABC. 115 | /// 116 | /// Point A of triangle ABC. 117 | /// Point B of triangle ABC. 118 | /// Point C of triangle ABC. 119 | /// The 2D area of the triangle. 120 | public static void Area2D(ref ContourVertex a, ref ContourVertex b, ref ContourVertex c, out int area) 121 | { 122 | area = (b.X - a.X) * (c.Z - a.Z) - (c.X - a.X) * (b.Z - a.Z); 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /Source/SharpNav/Crowds/CrowdAgentState.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | namespace SharpNav.Crowds 7 | { 8 | /// 9 | /// Describes the current state of a crowd agent 10 | /// 11 | [Flags] 12 | public enum AgentState 13 | { 14 | /// 15 | /// Not in any state 16 | /// 17 | Invalid, 18 | 19 | /// 20 | /// Walking on the navigation mesh 21 | /// 22 | Walking, 23 | 24 | /// 25 | /// Handling an offmesh connection 26 | /// 27 | Offmesh 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/SharpNav/Crowds/Status.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | namespace SharpNav.Crowds 5 | { 6 | /// 7 | /// The status of an asynchronous task. 8 | /// 9 | public enum Status 10 | { 11 | /* Detailed information */ 12 | 13 | /// Something is wrong with the input data 14 | InvalidData = 0x00000001, 15 | 16 | /// A parameter was invalid 17 | InvalidParam = 0x00000002, 18 | 19 | /// Result buffer was too small for the output 20 | BufferTooSmall = 0x00000004, 21 | 22 | /// Query ran out of nodes during search 23 | OutOfNodes = 0x00000008, 24 | 25 | /// Query didn't reach the end. Result is the best guess. 26 | PartialResult = 0x00000010, 27 | 28 | /// A bitmask for detailed status values 29 | DetailMask = 0x0fffffff, 30 | 31 | /* High level status */ 32 | 33 | /// Operation in progress 34 | InProgress = 0x20000000, 35 | 36 | /// Operation finished 37 | Success = 0x40000000, 38 | 39 | /// Operation failed to complete 40 | Failure = unchecked((int)0x80000000) 41 | } 42 | 43 | /// 44 | /// A static class containing extension methods related to the enum. 45 | /// 46 | public static class StatusExtensions 47 | { 48 | /// 49 | /// Converts a boolean value to a . 50 | /// 51 | /// The boolean value. 52 | /// The equivalent status. 53 | public static Status ToStatus(this bool variable) 54 | { 55 | return variable ? Status.Success : Status.Failure; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Source/SharpNav/Crowds/TargetState.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | namespace SharpNav.Crowds 5 | { 6 | /// 7 | /// This state changes depending on what the crowd agent has to do next 8 | /// 9 | public enum TargetState 10 | { 11 | /// 12 | /// Not in any state 13 | /// 14 | None, 15 | 16 | /// 17 | /// Failed to find a new path 18 | /// 19 | Failed, 20 | 21 | /// 22 | /// Target destination reached. 23 | /// 24 | Valid, 25 | 26 | /// 27 | /// Requesting a new path 28 | /// 29 | Requesting, 30 | 31 | /// 32 | /// Add this agent to the crowd manager's path queue 33 | /// 34 | WaitingForQueue, 35 | 36 | /// 37 | /// The agent is in the path queue 38 | /// 39 | WaitingForPath, 40 | 41 | /// 42 | /// Changing its velocity 43 | /// 44 | Velocity 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Source/SharpNav/Crowds/UpdateFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | namespace SharpNav.Crowds 7 | { 8 | /// 9 | /// The UpdateFlag affects the way the agent moves acorss its path. 10 | /// 11 | [Flags] 12 | public enum UpdateFlags 13 | { 14 | /// 15 | /// The agent will be making turns in its path 16 | /// 17 | AnticipateTurns = 1, 18 | 19 | /// 20 | /// Avoid obstacles on the path 21 | /// 22 | ObstacleAvoidance = 2, 23 | 24 | /// 25 | /// Separate this agent from other agents 26 | /// 27 | Separation = 4, 28 | 29 | /// 30 | /// Optimize if the agent can see the next corner 31 | /// 32 | OptimizeVis = 8, 33 | 34 | /// 35 | /// Optimize the agent's path corridor 36 | /// 37 | OptimizeTopo = 16 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Source/SharpNav/Direction.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace SharpNav 8 | { 9 | /// 10 | /// A set of cardinal directions. 11 | /// 12 | public enum Direction 13 | { 14 | /// 15 | /// The west direction. 16 | /// 17 | West = 0, 18 | 19 | /// 20 | /// The north direction. 21 | /// 22 | North = 1, 23 | 24 | /// 25 | /// The east direction. 26 | /// 27 | East = 2, 28 | 29 | /// 30 | /// The south direction. 31 | /// 32 | South = 3 33 | } 34 | 35 | /// 36 | /// A set of extension methods to make using the Direction enum a lot simpler. 37 | /// 38 | public static class DirectionExtensions 39 | { 40 | private static readonly int[] OffsetsX = { -1, 0, 1, 0 }; 41 | private static readonly int[] OffsetsY = { 0, 1, 0, -1 }; 42 | 43 | /// 44 | /// Gets an X offset. 45 | /// 46 | /// 47 | /// The directions cycle between the following, starting from 0: west, north, east, south. 48 | /// 49 | /// The direction. 50 | /// The offset for the X coordinate. 51 | public static int GetHorizontalOffset(this Direction dir) 52 | { 53 | return OffsetsX[(int)dir]; 54 | } 55 | 56 | /// 57 | /// Get a Y offset. 58 | /// 59 | /// 60 | /// The directions cycle between the following, starting from 0: west, north, east, south. 61 | /// 62 | /// The direction. 63 | /// The offset for the Y coordinate. 64 | public static int GetVerticalOffset(this Direction dir) 65 | { 66 | return OffsetsY[(int)dir]; 67 | } 68 | 69 | /// 70 | /// Gets the next cardinal direction in clockwise order. 71 | /// 72 | /// The current direction. 73 | /// The next direction. 74 | public static Direction NextClockwise(this Direction dir) 75 | { 76 | switch (dir) 77 | { 78 | case Direction.West: 79 | return Direction.North; 80 | case Direction.North: 81 | return Direction.East; 82 | case Direction.East: 83 | return Direction.South; 84 | case Direction.South: 85 | return Direction.West; 86 | default: 87 | throw new ArgumentException("dir isn't a valid Direction."); 88 | } 89 | } 90 | 91 | /// 92 | /// Gets the next cardinal direction in counter-clockwise order. 93 | /// 94 | /// The current direction. 95 | /// The next direction. 96 | public static Direction NextCounterClockwise(this Direction dir) 97 | { 98 | switch (dir) 99 | { 100 | case Direction.West: 101 | return Direction.South; 102 | case Direction.South: 103 | return Direction.East; 104 | case Direction.East: 105 | return Direction.North; 106 | case Direction.North: 107 | return Direction.West; 108 | default: 109 | throw new ArgumentException("dir isn't a valid Direction."); 110 | } 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Source/SharpNav/EdgeFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | namespace SharpNav 7 | { 8 | /// 9 | /// An enum similar to , but with the ability to store multiple directions. 10 | /// 11 | [Flags] 12 | public enum EdgeFlags : byte 13 | { 14 | /// No edges are selected. 15 | None = 0x0, 16 | 17 | /// The west edge is selected. 18 | West = 0x1, 19 | 20 | /// The north edge is selected. 21 | North = 0x2, 22 | 23 | /// The east edge is selected. 24 | East = 0x4, 25 | 26 | /// The south edge is selected. 27 | South = 0x8, 28 | 29 | /// All of the edges are selected. 30 | All = West | North | East | South 31 | } 32 | 33 | /// 34 | /// A static class with helper functions to modify instances of the enum. 35 | /// 36 | public static class EdgeFlagsHelper 37 | { 38 | /// 39 | /// Adds an edge in a specified direction to an instance of . 40 | /// 41 | /// An existing set of edges. 42 | /// The direction to add. 43 | public static void AddEdge(ref EdgeFlags edges, Direction dir) 44 | { 45 | edges |= (EdgeFlags)(1 << (int)dir); 46 | } 47 | 48 | /// 49 | /// Flips the set of edges in an instance of . 50 | /// 51 | /// An existing set of edges. 52 | public static void FlipEdges(ref EdgeFlags edges) 53 | { 54 | edges ^= EdgeFlags.All; 55 | } 56 | 57 | /// 58 | /// Determines whether an instance of includes an edge in a specified direction. 59 | /// 60 | /// A set of edges. 61 | /// The direction to check for an edge. 62 | /// A value indicating whether the set of edges contains an edge in the specified direction. 63 | public static bool IsConnected(ref EdgeFlags edges, Direction dir) 64 | { 65 | return (edges & (EdgeFlags)(1 << (int)dir)) != EdgeFlags.None; 66 | } 67 | 68 | /// 69 | /// Removes an edge from an instance of . 70 | /// 71 | /// A set of edges. 72 | /// The direction to remove. 73 | public static void RemoveEdge(ref EdgeFlags edges, Direction dir) 74 | { 75 | edges &= (EdgeFlags)(~(1 << (int)dir)); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Source/SharpNav/Geometry/BBox2i.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | namespace SharpNav.Geometry 7 | { 8 | /// 9 | /// A 2d bounding box represeted by integers. 10 | /// 11 | [Serializable] 12 | public struct BBox2i : IEquatable 13 | { 14 | /// 15 | /// The minimum of the bounding box. 16 | /// 17 | public Vector2i Min; 18 | 19 | /// 20 | /// The maximum of the bounding box. 21 | /// 22 | public Vector2i Max; 23 | 24 | /// 25 | /// Initializes a new instance of the struct. 26 | /// 27 | /// A minimum bound. 28 | /// A maximum bound. 29 | public BBox2i(Vector2i min, Vector2i max) 30 | { 31 | Min = min; 32 | Max = max; 33 | } 34 | 35 | /// 36 | /// Initializes a new instance of the struct. 37 | /// 38 | /// The minimum X bound. 39 | /// The minimum Y bound. 40 | /// The maximum X bound. 41 | /// The maximum Y bound. 42 | public BBox2i(int minX, int minY, int maxX, int maxY) 43 | { 44 | Min.X = minX; 45 | Min.Y = minY; 46 | Max.X = maxX; 47 | Max.Y = maxY; 48 | } 49 | 50 | /// 51 | /// Compares two instances of for equality. 52 | /// 53 | /// An instance of . 54 | /// Another instance of . 55 | /// A value indicating whether the two instances are equal. 56 | public static bool operator ==(BBox2i left, BBox2i right) 57 | { 58 | return left.Equals(right); 59 | } 60 | 61 | /// 62 | /// Compares two instances of for inequality. 63 | /// 64 | /// An instance of . 65 | /// Another instance of . 66 | /// A value indicating whether the two instances are unequal. 67 | public static bool operator !=(BBox2i left, BBox2i right) 68 | { 69 | return !(left == right); 70 | } 71 | 72 | /// 73 | /// Turns the instance into a human-readable string. 74 | /// 75 | /// A string representing the instance. 76 | public override string ToString() 77 | { 78 | return "{ Min: " + Min.ToString() + ", Max: " + Max.ToString() + " }"; 79 | } 80 | 81 | /// 82 | /// Gets a unique hash code for this instance. 83 | /// 84 | /// A hash code. 85 | public override int GetHashCode() 86 | { 87 | //TODO write a good hash code. 88 | return Min.GetHashCode() ^ Max.GetHashCode(); 89 | } 90 | 91 | /// 92 | /// Checks for equality between this instance and a specified object. 93 | /// 94 | /// An object. 95 | /// A value indicating whether this instance and the object are equal. 96 | public override bool Equals(object obj) 97 | { 98 | BBox2i? objV = obj as BBox2i?; 99 | if (objV != null) 100 | return this.Equals(objV); 101 | 102 | return false; 103 | } 104 | 105 | /// 106 | /// Checks for equality between this instance and a specified instance of . 107 | /// 108 | /// An instance of . 109 | /// A value indicating whether this instance and the other instance are equal. 110 | public bool Equals(BBox2i other) 111 | { 112 | return Min == other.Min && Max == other.Max; 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Source/SharpNav/Geometry/Containment.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | #if MONOGAME 5 | using Vector3 = Microsoft.Xna.Framework.Vector3; 6 | #elif OPENTK 7 | using Vector3 = OpenTK.Vector3; 8 | #elif SHARPDX 9 | using Vector3 = SharpDX.Vector3; 10 | #endif 11 | 12 | namespace SharpNav.Geometry 13 | { 14 | /// 15 | /// Contains helper methods to check for containment of points or shapes. 16 | /// 17 | internal static class Containment 18 | { 19 | /// 20 | /// Determines whether a point is inside a polygon. 21 | /// 22 | /// A point. 23 | /// A set of vertices that define a polygon. 24 | /// The number of vertices to use from verts. 25 | /// A value indicating whether the point is contained within the polygon. 26 | internal static bool PointInPoly(Vector3 pt, Vector3[] verts, int nverts) 27 | { 28 | bool c = false; 29 | 30 | for (int i = 0, j = nverts - 1; i < nverts; j = i++) 31 | { 32 | Vector3 vi = verts[i]; 33 | Vector3 vj = verts[j]; 34 | if (((vi.Z > pt.Z) != (vj.Z > pt.Z)) && 35 | (pt.X < (vj.X - vi.X) * (pt.Z - vi.Z) / (vj.Z - vi.Z) + vi.X)) 36 | { 37 | c = !c; 38 | } 39 | } 40 | 41 | return c; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Source/SharpNav/Geometry/Vector2i.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | namespace SharpNav.Geometry 7 | { 8 | /// 9 | /// A 2d vector represented by integers. 10 | /// 11 | [Serializable] 12 | public struct Vector2i : IEquatable 13 | { 14 | /// 15 | /// A vector where both X and Y are . 16 | /// 17 | public static readonly Vector2i Min = new Vector2i(int.MinValue, int.MinValue); 18 | 19 | /// 20 | /// A vector where both X and Y are . 21 | /// 22 | public static readonly Vector2i Max = new Vector2i(int.MaxValue, int.MaxValue); 23 | 24 | /// 25 | /// A vector where both X and Y are 0. 26 | /// 27 | public static readonly Vector2i Zero = new Vector2i(0, 0); 28 | 29 | /// 30 | /// The X coordinate. 31 | /// 32 | public int X; 33 | 34 | /// 35 | /// The Y coordinate. 36 | /// 37 | public int Y; 38 | 39 | /// 40 | /// Initializes a new instance of the struct with a specified coordinate. 41 | /// 42 | /// The X coordinate. 43 | /// The Y coordinate. 44 | public Vector2i(int x, int y) 45 | { 46 | X = x; 47 | Y = y; 48 | } 49 | 50 | /// 51 | /// Compares two instances of for equality. 52 | /// 53 | /// An instance of . 54 | /// Another instance of . 55 | /// A value indicating whether the two instances are equal. 56 | public static bool operator ==(Vector2i left, Vector2i right) 57 | { 58 | return left.Equals(right); 59 | } 60 | 61 | /// 62 | /// Compares two instances of for inequality. 63 | /// 64 | /// An instance of . 65 | /// Another instance of . 66 | /// A value indicating whether the two instances are unequal. 67 | public static bool operator !=(Vector2i left, Vector2i right) 68 | { 69 | return !(left == right); 70 | } 71 | 72 | /// 73 | /// Gets a unique hash code for this instance. 74 | /// 75 | /// A hash code. 76 | public override int GetHashCode() 77 | { 78 | //TODO generate a good hashcode. 79 | return base.GetHashCode(); 80 | } 81 | 82 | /// 83 | /// Turns the instance into a human-readable string. 84 | /// 85 | /// A string representing the instance. 86 | public override string ToString() 87 | { 88 | return "{ X: " + X.ToString() + ", Y: " + Y.ToString() + " }"; 89 | } 90 | 91 | /// 92 | /// Checks for equality between this instance and a specified object. 93 | /// 94 | /// An object. 95 | /// A value indicating whether this instance and the object are equal. 96 | public override bool Equals(object obj) 97 | { 98 | Vector2i? objV = obj as Vector2i?; 99 | if (objV != null) 100 | return this.Equals(objV); 101 | 102 | return false; 103 | } 104 | 105 | /// 106 | /// Checks for equality between this instance and a specified instance of . 107 | /// 108 | /// An instance of . 109 | /// A value indicating whether this instance and the other instance are equal. 110 | public bool Equals(Vector2i other) 111 | { 112 | return X == other.X && Y == other.Y; 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Source/SharpNav/IO/Json/AreaConverter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | using SharpNav; 7 | 8 | using Newtonsoft.Json; 9 | using Newtonsoft.Json.Linq; 10 | 11 | namespace SharpNav.IO.Json 12 | { 13 | public class AreaConverter : JsonConverter 14 | { 15 | public override bool CanConvert(Type objectType) 16 | { 17 | return objectType == typeof(Area); 18 | } 19 | 20 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) 21 | { 22 | if (reader.TokenType == JsonToken.Null) 23 | return null; 24 | 25 | return new Area(serializer.Deserialize(reader)); 26 | } 27 | 28 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) 29 | { 30 | var area = (value as Area?).Value; 31 | serializer.Serialize(writer, (int)area.Id); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Source/SharpNav/IO/Json/PolyIdConverter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | using SharpNav.Pathfinding; 7 | 8 | using Newtonsoft.Json; 9 | using Newtonsoft.Json.Linq; 10 | 11 | namespace SharpNav.IO.Json 12 | { 13 | class PolyIdConverter : JsonConverter 14 | { 15 | public override bool CanConvert(Type objectType) 16 | { 17 | return objectType == typeof(NavPolyId); 18 | } 19 | 20 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) 21 | { 22 | if (reader.TokenType == JsonToken.Null) 23 | return null; 24 | 25 | return new NavPolyId(serializer.Deserialize(reader)); 26 | } 27 | 28 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) 29 | { 30 | var polyId = (value as NavPolyId?).Value; 31 | serializer.Serialize(writer, (int)polyId.Id); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Source/SharpNav/IO/Json/Vector3Converter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | using SharpNav.Geometry; 7 | 8 | using Newtonsoft.Json; 9 | using Newtonsoft.Json.Linq; 10 | 11 | #if MONOGAME 12 | using Vector3 = Microsoft.Xna.Framework.Vector3; 13 | #elif OPENTK 14 | using Vector3 = OpenTK.Vector3; 15 | #elif SHARPDX 16 | using Vector3 = SharpDX.Vector3; 17 | #endif 18 | 19 | namespace SharpNav.IO.Json 20 | { 21 | public class Vector3Converter : JsonConverter 22 | { 23 | public override bool CanConvert(Type objectType) 24 | { 25 | return objectType == typeof(Vector3); 26 | } 27 | 28 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) 29 | { 30 | //with help from http://stackoverflow.com/a/21632292/1122135 31 | if (reader.TokenType == JsonToken.Null) 32 | return null; 33 | 34 | JObject jObject = JObject.Load(reader); 35 | return new Vector3(jObject["X"].ToObject(serializer), jObject["Y"].ToObject(serializer), jObject["Z"].ToObject(serializer)); 36 | } 37 | 38 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) 39 | { 40 | var vec = (value as Vector3?).Value; 41 | writer.WriteStartObject(); 42 | writer.WritePropertyName("X"); 43 | serializer.Serialize(writer, vec.X); 44 | writer.WritePropertyName("Y"); 45 | serializer.Serialize(writer, vec.Y); 46 | writer.WritePropertyName("Z"); 47 | serializer.Serialize(writer, vec.Z); 48 | writer.WriteEndObject(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Source/SharpNav/IO/NavMeshConfigurationFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | 5 | using YamlDotNet.Serialization; 6 | using YamlDotNet.Serialization.NamingConventions; 7 | 8 | using SharpNav.Geometry; 9 | 10 | #if MONOGAME 11 | using Vector3 = Microsoft.Xna.Framework.Vector3; 12 | #elif OPENTK 13 | using Vector3 = OpenTK.Vector3; 14 | #elif SHARPDX 15 | using Vector3 = SharpDX.Vector3; 16 | #endif 17 | 18 | namespace SharpNav.IO 19 | { 20 | public class NavMeshConfigurationFile 21 | { 22 | public NavMeshGenerationSettings GenerationSettings { get; set; } 23 | public string ExportPath { get; set; } 24 | public List InputMeshes { get; set; } 25 | 26 | public NavMeshConfigurationFile() 27 | { 28 | GenerationSettings = NavMeshGenerationSettings.Default; 29 | InputMeshes = new List(); 30 | } 31 | 32 | public NavMeshConfigurationFile(StreamReader input) 33 | { 34 | var deserializer = new Deserializer(namingConvention: new HyphenatedNamingConvention()); 35 | var data = deserializer.Deserialize(input); 36 | 37 | GenerationSettings = data.Config; 38 | ExportPath = data.Export; 39 | InputMeshes = data.Meshes; 40 | } 41 | 42 | public void Save(string path) 43 | { 44 | var data = new YamlData(); 45 | data.Config = GenerationSettings; 46 | data.Export = ExportPath; 47 | data.Meshes = InputMeshes; 48 | 49 | var serializer = new Serializer(SerializationOptions.None, new HyphenatedNamingConvention()); 50 | using (StreamWriter writer = new StreamWriter(path)) 51 | serializer.Serialize(writer, data); 52 | } 53 | 54 | private class YamlData 55 | { 56 | public NavMeshGenerationSettings Config { get; set; } 57 | public string Export { get; set; } 58 | public List Meshes { get; set; } 59 | } 60 | 61 | public class MeshSettings 62 | { 63 | public string Path { get; set; } 64 | public float Scale { get; set; } 65 | //TODO make this class private, public one with Vector3 instead? 66 | public float[] Position { get; set; } 67 | //TODO: rotation; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Source/SharpNav/IO/NavMeshSerializer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Reflection; 6 | using SharpNav; 7 | 8 | namespace SharpNav.IO 9 | { 10 | //TODO make an interface if it doesn't need to be extended 11 | 12 | /// 13 | /// Abstract class for nav mesh serializers 14 | /// 15 | public abstract class NavMeshSerializer 16 | { 17 | /// 18 | /// Serialize navigation mesh into external file 19 | /// 20 | /// path of file to serialize into 21 | /// mesh to serialize 22 | public abstract void Serialize(string path, TiledNavMesh mesh); 23 | 24 | /// 25 | /// Deserialize navigation mesh from external file 26 | /// 27 | /// file to deserialize from 28 | /// deserialized mesh 29 | public abstract TiledNavMesh Deserialize(string path); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Source/SharpNav/NavMesh.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | using SharpNav.Geometry; 8 | 9 | namespace SharpNav 10 | { 11 | //TODO right now this is basically an alias for TiledNavMesh. Fix this in the future. 12 | 13 | /// 14 | /// A TiledNavMesh generated from a collection of triangles and some settings 15 | /// 16 | public class NavMesh : TiledNavMesh 17 | { 18 | /// 19 | /// Initializes a new instance of the class. 20 | /// 21 | /// The NavMeshBuilder data 22 | public NavMesh(NavMeshBuilder builder) 23 | : base(builder) 24 | { 25 | } 26 | 27 | /// 28 | /// Generates a given a collection of triangles and some settings. 29 | /// 30 | /// The triangles that form the level. 31 | /// The settings to generate with. 32 | /// A . 33 | public static NavMesh Generate(IEnumerable triangles, NavMeshGenerationSettings settings) 34 | { 35 | BBox3 bounds = triangles.GetBoundingBox(settings.CellSize); 36 | var hf = new Heightfield(bounds, settings); 37 | hf.RasterizeTriangles(triangles); 38 | hf.FilterLedgeSpans(settings.VoxelAgentHeight, settings.VoxelMaxClimb); 39 | hf.FilterLowHangingWalkableObstacles(settings.VoxelMaxClimb); 40 | hf.FilterWalkableLowHeightSpans(settings.VoxelAgentHeight); 41 | 42 | var chf = new CompactHeightfield(hf, settings); 43 | chf.Erode(settings.VoxelAgentRadius); 44 | chf.BuildDistanceField(); 45 | chf.BuildRegions(2, settings.MinRegionSize, settings.MergedRegionSize); 46 | 47 | var cont = chf.BuildContourSet(settings); 48 | 49 | var polyMesh = new PolyMesh(cont, settings); 50 | 51 | var polyMeshDetail = new PolyMeshDetail(polyMesh, chf, settings); 52 | 53 | var buildData = new NavMeshBuilder(polyMesh, polyMeshDetail, new Pathfinding.OffMeshConnection[0], settings); 54 | 55 | var navMesh = new NavMesh(buildData); 56 | return navMesh; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Source/SharpNav/NavMeshGenerationSettings.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | using YamlDotNet.Serialization; 7 | 8 | namespace SharpNav 9 | { 10 | /// 11 | /// Contains all the settings necessary to convert a mesh to a navmesh. 12 | /// 13 | public class NavMeshGenerationSettings 14 | { 15 | /// 16 | /// Prevents a default instance of the class from being created. 17 | /// Use instead. 18 | /// 19 | public NavMeshGenerationSettings() 20 | { 21 | //TODO now that this is public set reasonable defaults. 22 | } 23 | 24 | /// 25 | /// Gets the "default" generation settings for a model where 1 unit represents 1 meter. 26 | /// 27 | public static NavMeshGenerationSettings Default 28 | { 29 | get 30 | { 31 | //TODO rename this property to something more descriptive. 32 | var settings = new NavMeshGenerationSettings(); 33 | 34 | settings.CellSize = 0.3f; 35 | settings.CellHeight = 0.2f; 36 | settings.MaxClimb = 0.9f; 37 | settings.AgentHeight = 2.0f; 38 | settings.AgentRadius = 0.6f; 39 | settings.MinRegionSize = 8; 40 | settings.MergedRegionSize = 20; 41 | settings.MaxEdgeLength = 12; 42 | settings.MaxEdgeError = 1.8f; 43 | settings.VertsPerPoly = 6; 44 | settings.SampleDistance = 6; 45 | settings.MaxSampleError = 1; 46 | 47 | settings.BuildBoundingVolumeTree = true; 48 | 49 | return settings; 50 | } 51 | } 52 | 53 | /// 54 | /// Gets or sets the size of a cell in the X and Z axes in world units. 55 | /// 56 | public float CellSize { get; set; } 57 | 58 | /// 59 | /// Gets or sets the height of a cell in world units. 60 | /// 61 | public float CellHeight { get; set; } 62 | 63 | /// 64 | /// Gets or sets the maximum climb height. 65 | /// 66 | public float MaxClimb { get; set; } 67 | 68 | /// 69 | /// Gets or sets the height of the agents traversing the . 70 | /// 71 | public float AgentHeight { get; set; } 72 | 73 | /// 74 | /// Gets or sets the radius of the agents traversing the . 75 | /// 76 | public float AgentRadius { get; set; } 77 | 78 | /// 79 | /// Gets or sets the minimum number of spans that can form a region. Any less than this, and they will be 80 | /// merged with another region. 81 | /// 82 | public int MinRegionSize { get; set; } 83 | 84 | /// 85 | /// Gets or sets the size of the merged regions 86 | /// 87 | public int MergedRegionSize { get; set; } 88 | 89 | /// 90 | /// Gets or sets the maximum edge length allowed 91 | /// 92 | public int MaxEdgeLength { get; set; } 93 | 94 | /// 95 | /// Gets or sets the maximum error allowed 96 | /// 97 | public float MaxEdgeError { get; set; } 98 | 99 | /// 100 | /// Gets or sets the flags that determine how the is generated. 101 | /// 102 | public ContourBuildFlags ContourFlags { get; set; } 103 | 104 | /// 105 | /// Gets or sets the number of vertices a polygon can have. 106 | /// 107 | public int VertsPerPoly { get; set; } 108 | 109 | /// 110 | /// Gets or sets the sampling distance for the PolyMeshDetail 111 | /// 112 | public int SampleDistance { get; set; } 113 | 114 | /// 115 | /// Gets or sets the maximium error allowed in sampling for the PolyMeshDetail 116 | /// 117 | public int MaxSampleError { get; set; } 118 | 119 | /// 120 | /// Gets or sets a value indicating whether a bounding volume tree is generated for the mesh. 121 | /// 122 | public bool BuildBoundingVolumeTree { get; set; } 123 | 124 | /// 125 | /// Gets the height of the agents traversing the in voxel (cell) units. 126 | /// 127 | [YamlIgnore] 128 | public int VoxelAgentHeight 129 | { 130 | get 131 | { 132 | return (int)(AgentHeight / CellHeight); 133 | } 134 | } 135 | 136 | /// 137 | /// Gets the maximum clim height in voxel (cell) units. 138 | /// 139 | [YamlIgnore] 140 | public int VoxelMaxClimb 141 | { 142 | get 143 | { 144 | return (int)(MaxClimb / CellHeight); 145 | } 146 | } 147 | 148 | /// 149 | /// Gets the radius of the agents traversing the in voxel (cell) units. 150 | /// 151 | [YamlIgnore] 152 | public int VoxelAgentRadius 153 | { 154 | get 155 | { 156 | return (int)(AgentRadius / CellHeight); 157 | } 158 | } 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /Source/SharpNav/NodeFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace SharpNav 8 | { 9 | /// 10 | /// Determine which list the node is in. 11 | /// 12 | [Flags] 13 | public enum NodeFlags 14 | { 15 | /// 16 | /// Open list contains nodes to examine. 17 | /// 18 | Open = 0x01, 19 | 20 | /// 21 | /// Closed list stores path. 22 | /// 23 | Closed = 0x02, 24 | 25 | /// 26 | /// Parent of the node is not adjacent. Found using raycast. 27 | /// 28 | ParentDetached = 0x04 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Source/SharpNav/NodePool.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | using SharpNav.Pathfinding; 8 | 9 | namespace SharpNav 10 | { 11 | /// 12 | /// Link all nodes together. Store indices in hash map. 13 | /// 14 | public class NodePool 15 | { 16 | private List nodes; 17 | private Dictionary nodeDict; 18 | private int maxNodes; 19 | 20 | /// 21 | /// Initializes a new instance of the class. 22 | /// 23 | /// The maximum number of nodes that can be stored 24 | /// The maximum number of elements in the hash table 25 | public NodePool(int maxNodes) 26 | { 27 | this.maxNodes = maxNodes; 28 | 29 | nodes = new List(maxNodes); 30 | nodeDict = new Dictionary(); 31 | } 32 | 33 | /// 34 | /// Reset all the data. 35 | /// 36 | public void Clear() 37 | { 38 | nodes.Clear(); 39 | nodeDict.Clear(); 40 | } 41 | 42 | /// 43 | /// Try to find a node. 44 | /// 45 | /// Node's id 46 | /// The node, if found. Null, if otherwise. 47 | public NavNode FindNode(NavPolyId id) 48 | { 49 | NavNode node; 50 | if (nodeDict.TryGetValue(id, out node)) 51 | { 52 | return node; 53 | } 54 | 55 | return null; 56 | } 57 | 58 | /// 59 | /// Try to find the node. If it doesn't exist, create a new node. 60 | /// 61 | /// Node's id 62 | /// The node 63 | public NavNode GetNode(NavPolyId id) 64 | { 65 | NavNode node; 66 | if (nodeDict.TryGetValue(id, out node)) 67 | { 68 | return node; 69 | } 70 | 71 | if (nodes.Count >= maxNodes) 72 | return null; 73 | 74 | NavNode newNode = new NavNode(); 75 | newNode.ParentIndex = 0; 76 | newNode.PolyCost = 0; 77 | newNode.TotalCost = 0; 78 | newNode.Id = id; 79 | newNode.Flags = 0; 80 | 81 | nodes.Add(newNode); 82 | nodeDict.Add(id, newNode); 83 | 84 | return newNode; 85 | } 86 | 87 | /// 88 | /// Gets the id of the node. 89 | /// 90 | /// The node 91 | /// The id 92 | public int GetNodeIdx(NavNode node) 93 | { 94 | if (node == null) 95 | return 0; 96 | 97 | for (int i = 0; i < nodes.Count; i++) 98 | { 99 | if (nodes[i] == node) 100 | return i + 1; 101 | } 102 | 103 | return 0; 104 | } 105 | 106 | /// 107 | /// Return a node at a certain index. If index is out-of-bounds, return null. 108 | /// 109 | /// Node index 110 | /// 111 | public NavNode GetNodeAtIdx(int idx) 112 | { 113 | if (idx <= 0 || idx > nodes.Count) 114 | return null; 115 | 116 | return nodes[idx - 1]; 117 | } 118 | 119 | /// 120 | /// Determine whether two nodes are equal 121 | /// 122 | /*private class IntNodeIdComparer : IEqualityComparer 123 | { 124 | private int hashSize; 125 | 126 | /// 127 | /// Initializes a new instance of the class. 128 | /// 129 | /// The maximum number of elements in the hash table 130 | public IntNodeIdComparer(int hashSize) 131 | { 132 | this.hashSize = hashSize; 133 | } 134 | 135 | /// 136 | /// Determines whether two objects or equal or now 137 | /// 138 | /// The first object 139 | /// The second object 140 | /// True if equal, false if not equal 141 | public bool Equals(PolyId left, int right) 142 | { 143 | return left == right; 144 | } 145 | 146 | /// 147 | /// Gets the hash code for this object 148 | /// 149 | /// The object 150 | /// The hash code 151 | public int GetHashCode(int obj) 152 | { 153 | obj += ~(obj << 15); 154 | obj ^= obj >> 10; 155 | obj += obj << 3; 156 | obj ^= obj >> 6; 157 | obj += ~(obj << 11); 158 | obj ^= obj >> 16; 159 | 160 | return obj & (hashSize - 1); 161 | } 162 | }*/ 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /Source/SharpNav/OpenTK.dll.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/BoundarySide.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using SharpNav.Geometry; 6 | 7 | #if MONOGAME 8 | using Vector3 = Microsoft.Xna.Framework.Vector3; 9 | #elif OPENTK 10 | using Vector3 = OpenTK.Vector3; 11 | #elif SHARPDX 12 | using Vector3 = SharpDX.Vector3; 13 | #endif 14 | 15 | namespace SharpNav.Pathfinding 16 | { 17 | /// 18 | /// An enumeration of the different places a point can be relative to a rectangular boundary on the XZ plane. 19 | /// 20 | public enum BoundarySide : byte 21 | { 22 | /// 23 | /// Not outside of the defined boundary. 24 | /// 25 | Internal = 0xff, 26 | 27 | /// 28 | /// Only outside of the defined bondary on the X axis, in the positive direction. 29 | /// 30 | PlusX = 0, 31 | 32 | /// 33 | /// Outside of the defined boundary on both the X and Z axes, both in the positive direction. 34 | /// 35 | PlusXPlusZ = 1, 36 | 37 | /// 38 | /// Only outside of the defined bondary on the Z axis, in the positive direction. 39 | /// 40 | PlusZ = 2, 41 | 42 | /// 43 | /// Outside of the defined boundary on both the X and Z axes, in the negative and positive directions respectively. 44 | /// 45 | MinusXPlusZ = 3, 46 | 47 | /// 48 | /// Only outside of the defined bondary on the X axis, in the negative direction. 49 | /// 50 | MinusX = 4, 51 | 52 | /// 53 | /// Outside of the defined boundary on both the X and Z axes, both in the negative direction. 54 | /// 55 | MinusXMinusZ = 5, 56 | 57 | /// 58 | /// Only outside of the defined bondary on the Z axis, in the negative direction. 59 | /// 60 | MinusZ = 6, 61 | 62 | /// 63 | /// Outside of the defined boundary on both the X and Z axes, in the positive and negative directions respectively. 64 | /// 65 | PlusXMinusZ = 7 66 | } 67 | 68 | /// 69 | /// Extension methods for the enumeration. 70 | /// 71 | public static class BoundarySideExtensions 72 | { 73 | /// 74 | /// Gets the side in the exact opposite direction as a specified side. 75 | /// 76 | /// 77 | /// The value will always return . 78 | /// 79 | /// A side. 80 | /// The opposite side. 81 | public static BoundarySide GetOpposite(this BoundarySide side) 82 | { 83 | if (side == BoundarySide.Internal) 84 | return BoundarySide.Internal; 85 | 86 | return (BoundarySide)((int)(side + 4) % 8); 87 | } 88 | 89 | /// 90 | /// Gets the boundary side of a point relative to a bounding box. 91 | /// 92 | /// A point. 93 | /// A bounding box. 94 | /// The point's position relative to the bounding box. 95 | public static BoundarySide FromPoint(Vector3 pt, BBox3 bounds) 96 | { 97 | const int PlusX = 0x1; 98 | const int PlusZ = 0x2; 99 | const int MinusX = 0x4; 100 | const int MinusZ = 0x8; 101 | 102 | int outcode = 0; 103 | outcode |= (pt.X >= bounds.Max.X) ? PlusX : 0; 104 | outcode |= (pt.Z >= bounds.Max.Z) ? PlusZ : 0; 105 | outcode |= (pt.X < bounds.Min.X) ? MinusX : 0; 106 | outcode |= (pt.Z < bounds.Min.Z) ? MinusZ : 0; 107 | 108 | switch (outcode) 109 | { 110 | case PlusX: 111 | return BoundarySide.PlusX; 112 | 113 | case PlusX | PlusZ: 114 | return BoundarySide.PlusXPlusZ; 115 | 116 | case PlusZ: 117 | return BoundarySide.PlusZ; 118 | 119 | case MinusX | PlusZ: 120 | return BoundarySide.MinusXPlusZ; 121 | 122 | case MinusX: 123 | return BoundarySide.MinusX; 124 | 125 | case MinusX | MinusZ: 126 | return BoundarySide.MinusXMinusZ; 127 | 128 | case MinusZ: 129 | return BoundarySide.MinusZ; 130 | 131 | case PlusX | MinusZ: 132 | return BoundarySide.PlusXMinusZ; 133 | 134 | default: 135 | return BoundarySide.Internal; 136 | } 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/FindPathOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | namespace SharpNav.Pathfinding 7 | { 8 | [Flags] 9 | public enum FindPathOptions 10 | { 11 | None = 0x00, 12 | AnyAngle = 0x01 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/Link.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | namespace SharpNav.Pathfinding 5 | { 6 | /// 7 | /// A link is formed between two polygons in a TiledNavMesh 8 | /// 9 | public class Link 10 | { 11 | /// 12 | /// Entity links to external entity. 13 | /// 14 | public const int External = unchecked((int)0x80000000); 15 | 16 | /// 17 | /// Doesn't link to anything. 18 | /// 19 | public const int Null = unchecked((int)0xffffffff); 20 | 21 | /// 22 | /// Gets or sets the neighbor reference (the one it's linked to) 23 | /// 24 | public NavPolyId Reference { get; set; } 25 | 26 | /// 27 | /// Gets or sets the index of polygon edge 28 | /// 29 | public int Edge { get; set; } 30 | 31 | /// 32 | /// Gets or sets the polygon side 33 | /// 34 | public BoundarySide Side { get; set; } 35 | 36 | /// 37 | /// Gets or sets the minimum Vector3 of the bounding box 38 | /// 39 | public int BMin { get; set; } 40 | 41 | /// 42 | /// Gets or sets the maximum Vector3 of the bounding box 43 | /// 44 | public int BMax { get; set; } 45 | 46 | public static bool IsExternal(int link) 47 | { 48 | return (link & Link.External) != 0; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/NavNode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | using SharpNav.Collections.Generic; 7 | using SharpNav.Geometry; 8 | using SharpNav.Pathfinding; 9 | 10 | #if MONOGAME 11 | using Vector3 = Microsoft.Xna.Framework.Vector3; 12 | #elif OPENTK 13 | using Vector3 = OpenTK.Vector3; 14 | #elif SHARPDX 15 | using Vector3 = SharpDX.Vector3; 16 | #endif 17 | 18 | namespace SharpNav 19 | { 20 | /// 21 | /// Every polygon becomes a Node, which contains a position and cost. 22 | /// 23 | public class NavNode : IValueWithCost 24 | { 25 | public const int NullIndex = ~0; 26 | 27 | public Vector3 Position; 28 | 29 | /// 30 | /// Cost from previous node/poly to current. 31 | /// 32 | public float PolyCost; 33 | 34 | /// 35 | /// Total cost up to this node 36 | /// 37 | public float TotalCost; 38 | public int ParentIndex; //index to parent node 39 | public byte State; 40 | public NodeFlags Flags = 0; //node flags 0/open/closed 41 | public NavPolyId Id; //polygon ref the node corresponds to 42 | 43 | //TODO should make more generic or move to Pathfinding namespace 44 | 45 | public float Cost 46 | { 47 | get 48 | { 49 | return TotalCost; 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/NavPoint.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | using SharpNav.Geometry; 8 | 9 | #if MONOGAME 10 | using Vector3 = Microsoft.Xna.Framework.Vector3; 11 | #elif OPENTK 12 | using Vector3 = OpenTK.Vector3; 13 | #elif SHARPDX 14 | using Vector3 = SharpDX.Vector3; 15 | #endif 16 | 17 | namespace SharpNav.Pathfinding 18 | { 19 | /// 20 | /// A point in a navigation mesh. 21 | /// 22 | [Serializable] 23 | [StructLayout(LayoutKind.Sequential)] 24 | public struct NavPoint 25 | { 26 | /// 27 | /// A null point that isn't associated with any polygon. 28 | /// 29 | public static readonly NavPoint Null = new NavPoint(NavPolyId.Null, Vector3.Zero); 30 | 31 | /// 32 | /// A reference to the polygon this point is on. 33 | /// 34 | public NavPolyId Polygon; 35 | 36 | /// 37 | /// The 3d position of the point. 38 | /// 39 | public Vector3 Position; 40 | 41 | /// 42 | /// Initializes a new instance of the struct. 43 | /// 44 | /// The polygon that the point is on. 45 | /// The 3d position of the point. 46 | public NavPoint(NavPolyId poly, Vector3 pos) 47 | { 48 | this.Polygon = poly; 49 | this.Position = pos; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/NavPoly.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace SharpNav.Pathfinding 8 | { 9 | /// 10 | /// Flags representing the type of a navmesh polygon. 11 | /// 12 | [Flags] 13 | public enum NavPolyType : byte 14 | { 15 | /// A polygon that is part of the navmesh. 16 | Ground = 0, 17 | 18 | /// An off-mesh connection consisting of two vertices. 19 | OffMeshConnection = 1 20 | } 21 | 22 | /// 23 | /// Uses the PolyMesh polygon data for pathfinding 24 | /// 25 | public class NavPoly 26 | { 27 | public NavPoly() 28 | { 29 | Links = new List(); 30 | } 31 | 32 | /// 33 | /// Gets or sets the polygon type (ground or offmesh) 34 | /// 35 | public NavPolyType PolyType { get; set; } 36 | 37 | public List Links { get; private set; } 38 | 39 | /// 40 | /// Gets or sets the indices of polygon's vertices 41 | /// 42 | public int[] Verts { get; set; } 43 | 44 | /// 45 | /// Gets or sets packed data representing neighbor polygons references and flags for each edge 46 | /// 47 | public int[] Neis { get; set; } 48 | 49 | /// 50 | /// Gets or sets a user defined polygon flags 51 | /// 52 | public object Tag { get; set; } 53 | 54 | /// 55 | /// Gets or sets the number of vertices 56 | /// 57 | public int VertCount { get; set; } 58 | 59 | /// 60 | /// Gets or sets the AreaId 61 | /// 62 | public Area Area { get; set; } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/NavPolyId.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace SharpNav.Pathfinding 8 | { 9 | [Serializable] 10 | [StructLayout(LayoutKind.Sequential)] 11 | public struct NavPolyId : IEquatable 12 | { 13 | /// 14 | /// A null ID that isn't associated with any polygon or tile. 15 | /// 16 | public static readonly NavPolyId Null = new NavPolyId(0); 17 | 18 | private int bits; 19 | 20 | public NavPolyId(int raw) 21 | { 22 | bits = raw; 23 | } 24 | 25 | public int Id { get { return bits; } } 26 | 27 | public static bool operator ==(NavPolyId left, NavPolyId right) 28 | { 29 | return left.Equals(right); 30 | } 31 | 32 | public static bool operator !=(NavPolyId left, NavPolyId right) 33 | { 34 | return !(left == right); 35 | } 36 | 37 | public bool Equals(NavPolyId other) 38 | { 39 | return bits == other.bits; 40 | } 41 | 42 | public override bool Equals(object obj) 43 | { 44 | var polyObj = obj as NavPolyId?; 45 | 46 | if (polyObj.HasValue) 47 | return this.Equals(polyObj.Value); 48 | else 49 | return false; 50 | } 51 | 52 | public override int GetHashCode() 53 | { 54 | //TODO actual hash code 55 | return base.GetHashCode(); 56 | } 57 | 58 | public string ToString(NavPolyIdManager manager) 59 | { 60 | int polyIndex, tileIndex, salt; 61 | manager.Decode(ref this, out polyIndex, out tileIndex, out salt); 62 | 63 | return "{ Poly: " + polyIndex + ", Tile: " + tileIndex + ", Salt: " + salt + "}"; 64 | } 65 | 66 | public override string ToString() 67 | { 68 | return bits.ToString(); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/NavPolyIdManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | namespace SharpNav.Pathfinding 5 | { 6 | /// 7 | /// Helps encode and decode by storing the number of 8 | /// bits the salt, tile, and poly sections of an ID. 9 | /// 10 | /// 11 | /// IDs should not be used between different instances of 12 | /// as the bits for each section may be 13 | /// diffrent, causing incorrect decoded values. 14 | /// 15 | public class NavPolyIdManager 16 | { 17 | private int polyBits; 18 | private int tileBits; 19 | private int saltBits; 20 | private int polyMask; 21 | private int tileMask; 22 | private int saltMask; 23 | private int tileOffset; 24 | private int saltOffset; 25 | 26 | public NavPolyIdManager(int polyBits, int tileBits, int saltBits) 27 | { 28 | this.polyBits = polyBits; 29 | this.tileBits = tileBits; 30 | this.saltBits = saltBits; 31 | 32 | this.polyMask = (1 << polyBits) - 1; 33 | this.tileMask = (1 << tileBits) - 1; 34 | this.saltMask = (1 << saltBits) - 1; 35 | 36 | this.tileOffset = polyBits; 37 | this.saltOffset = polyBits + tileBits; 38 | } 39 | 40 | public int PolyBits { get { return polyBits; } } 41 | public int TileBits { get { return tileBits; } } 42 | public int SaltBits { get { return saltBits; } } 43 | 44 | public NavPolyId Encode(int salt, int tileIndex, int polyIndex) 45 | { 46 | NavPolyId id; 47 | Encode(salt, tileIndex, polyIndex, out id); 48 | return id; 49 | } 50 | 51 | /// 52 | /// Derive a standard polygon reference, which compresses salt, tile index, and poly index together. 53 | /// 54 | /// The number of bits to use for the polygon value. 55 | /// The number of bits to use for the tile value. 56 | /// Salt value 57 | /// Tile index 58 | /// Poly index 59 | /// Polygon reference 60 | public void Encode(int salt, int tileIndex, int polyIndex, out NavPolyId result) 61 | { 62 | polyIndex &= polyMask; 63 | tileIndex &= tileMask; 64 | salt &= saltMask; 65 | 66 | result = new NavPolyId((salt << saltOffset) | (tileIndex << tileOffset) | polyIndex); 67 | } 68 | 69 | public void SetPolyIndex(ref NavPolyId polyBase, int newPoly, out NavPolyId result) 70 | { 71 | newPoly &= polyMask; 72 | 73 | //first clear poly then OR with new poly 74 | result = new NavPolyId((polyBase.Id & ~polyMask) | newPoly); 75 | } 76 | 77 | /// 78 | /// Decode a standard polygon reference. 79 | /// 80 | /// The number of bits to use for the polygon value. 81 | /// The number of bits to use for the tile value. 82 | /// The number of bits to use for the salt. 83 | /// Resulting poly index. 84 | /// Resulting tile index. 85 | /// Resulting salt value. 86 | public void Decode(ref NavPolyId id, out int polyIndex, out int tileIndex, out int salt) 87 | { 88 | int bits = id.Id; 89 | 90 | salt = (bits >> saltOffset) & saltMask; 91 | tileIndex = (bits >> tileOffset) & tileMask; 92 | polyIndex = bits & polyMask; 93 | } 94 | 95 | /// 96 | /// Extract a polygon's index (within its tile) from the specified polygon reference. 97 | /// 98 | /// The number of bits to use for the polygon value. 99 | /// The value's poly index. 100 | public int DecodePolyIndex(ref NavPolyId id) 101 | { 102 | return id.Id & polyMask; 103 | } 104 | 105 | /// 106 | /// Extract a tile's index from the specified polygon reference. 107 | /// 108 | /// The number of bits to use for the polygon value. 109 | /// The number of bits to use for the tile value. 110 | /// The value's tile index. 111 | public int DecodeTileIndex(ref NavPolyId id) 112 | { 113 | return (id.Id >> tileOffset) & tileMask; 114 | } 115 | 116 | /// 117 | /// Extract a tile's salt value from the specified polygon reference. 118 | /// 119 | /// The number of bits to use for the polygon value. 120 | /// The number of bits to use for the tile value. 121 | /// The number of bits to use for the salt. 122 | /// The value's salt. 123 | public int DecodeSalt(ref NavPolyId id) 124 | { 125 | return (id.Id >> saltOffset) & saltMask; 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/NavQueryFilter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | using SharpNav.Geometry; 8 | 9 | #if MONOGAME 10 | using Vector3 = Microsoft.Xna.Framework.Vector3; 11 | #elif OPENTK 12 | using Vector3 = OpenTK.Vector3; 13 | #elif SHARPDX 14 | using Vector3 = SharpDX.Vector3; 15 | #endif 16 | 17 | namespace SharpNav.Pathfinding 18 | { 19 | public class NavQueryFilter 20 | { 21 | private float[] areaCost; 22 | 23 | public NavQueryFilter() 24 | { 25 | areaCost = new float[Area.MaxValues]; 26 | for (int i = 0; i < areaCost.Length; i++) 27 | areaCost[i] = 1; 28 | } 29 | 30 | public virtual bool PassFilter(NavPolyId polyId, NavTile tile, NavPoly poly) 31 | { 32 | return true; 33 | } 34 | 35 | public virtual float GetCost(Vector3 a, Vector3 b, 36 | NavPolyId prevRef, NavTile prevTile, NavPoly prevPoly, 37 | NavPolyId curRef, NavTile curTile, NavPoly curPoly, 38 | NavPolyId nextRef, NavTile nextTile, NavPoly nextPoly) 39 | { 40 | return (a - b).Length() * areaCost[(int)curPoly.Area.Id]; 41 | } 42 | 43 | public float GetAreaCost(Area area) 44 | { 45 | return areaCost[area.Id]; 46 | } 47 | 48 | public void SetAreaCost(Area area, float value) 49 | { 50 | areaCost[area.Id] = value; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/OffMeshConnection.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | using SharpNav.Geometry; 7 | 8 | #if MONOGAME 9 | using Vector3 = Microsoft.Xna.Framework.Vector3; 10 | #elif OPENTK 11 | using Vector3 = OpenTK.Vector3; 12 | #elif SHARPDX 13 | using Vector3 = SharpDX.Vector3; 14 | #endif 15 | 16 | namespace SharpNav.Pathfinding 17 | { 18 | /// 19 | /// A set of flags that define properties about an off-mesh connection. 20 | /// 21 | [Flags] 22 | public enum OffMeshConnectionFlags : byte 23 | { 24 | /// 25 | /// No flags. 26 | /// 27 | None = 0x0, 28 | 29 | /// 30 | /// The connection is bi-directional. 31 | /// 32 | Bidirectional = 0x1 33 | } 34 | 35 | /// 36 | /// An offmesh connection links two polygons, which are not directly adjacent, but are accessibly through 37 | /// other means (jumping, climbing, etc...). 38 | /// 39 | public class OffMeshConnection 40 | { 41 | /// 42 | /// Gets or sets the first endpoint of the connection 43 | /// 44 | public Vector3 Pos0 { get; set; } 45 | 46 | /// 47 | /// Gets or sets the second endpoint of the connection 48 | /// 49 | public Vector3 Pos1 { get; set; } 50 | 51 | /// 52 | /// Gets or sets the radius 53 | /// 54 | public float Radius { get; set; } 55 | 56 | /// 57 | /// Gets or sets the polygon's index 58 | /// 59 | public int Poly { get; set; } 60 | 61 | /// 62 | /// Gets or sets the polygon flag 63 | /// 64 | public OffMeshConnectionFlags Flags { get; set; } 65 | 66 | /// 67 | /// Gets or sets the endpoint's side 68 | /// 69 | public BoundarySide Side { get; set; } 70 | 71 | /// 72 | /// Gets or sets user data for this connection. 73 | /// 74 | public object Tag { get; set; } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/Path.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace SharpNav.Pathfinding 8 | { 9 | public class Path 10 | { 11 | private List polys; 12 | private float cost; 13 | 14 | public Path() 15 | { 16 | polys = new List(); 17 | cost = 0; 18 | } 19 | 20 | public Path(Path otherPath) 21 | : this() 22 | { 23 | polys.AddRange(otherPath.polys); 24 | cost = otherPath.Cost; 25 | } 26 | 27 | public NavPolyId this[int i] 28 | { 29 | get 30 | { 31 | return polys[i]; 32 | } 33 | set 34 | { 35 | polys[i] = value; 36 | } 37 | } 38 | 39 | public int Count { get { return polys.Count; } } 40 | 41 | public float Cost { get { return cost; } } 42 | 43 | public void Clear() 44 | { 45 | polys.Clear(); 46 | cost = 0; 47 | } 48 | 49 | public void Add(NavPolyId poly) 50 | { 51 | polys.Add(poly); 52 | } 53 | 54 | public void AddRange(IEnumerable polys) 55 | { 56 | this.polys.AddRange(polys); 57 | } 58 | 59 | public void AppendPath(Path other) 60 | { 61 | polys.AddRange(other.polys); 62 | } 63 | 64 | public void AddCost(float cost) 65 | { 66 | this.cost += cost; 67 | } 68 | 69 | public void Reverse() 70 | { 71 | polys.Reverse(); 72 | } 73 | 74 | public void RemoveTrackbacks() 75 | { 76 | for (int i = 0; i < polys.Count; i++) 77 | { 78 | if (i - 1 >= 0 && i + 1 < polys.Count) 79 | { 80 | if (polys[i - 1] == polys[i + 1]) 81 | { 82 | polys.RemoveRange(i - 1, 2); 83 | i -= 2; 84 | } 85 | } 86 | } 87 | } 88 | 89 | public void FixupCorridor(List visited) 90 | { 91 | int furthestPath = -1; 92 | int furthestVisited = -1; 93 | 94 | //find furhtest common polygon 95 | bool found = false; 96 | for (int i = polys.Count - 1; i >= 0; i--) 97 | { 98 | for (int j = visited.Count - 1; j >= 0; j--) 99 | { 100 | if (polys[i] == visited[j]) 101 | { 102 | furthestPath = i; 103 | furthestVisited = j; 104 | found = true; 105 | break; 106 | } 107 | } 108 | 109 | if (found) 110 | break; 111 | } 112 | 113 | //no intersection in visited path 114 | if (furthestPath == -1 || furthestVisited == -1) 115 | return; 116 | 117 | //concatenate paths 118 | //adjust beginning of the buffer to include the visited 119 | int req = visited.Count - furthestVisited; 120 | int orig = Math.Min(furthestPath + 1, polys.Count); 121 | int size = Math.Max(0, polys.Count - orig); 122 | 123 | //remove everything before visited 124 | polys.RemoveRange(0, orig); 125 | 126 | //for (int i = 0; i < size; i++) 127 | //polys[req + i] = polys[orig + i]; 128 | 129 | //store visited 130 | for (int i = 0; i < req; i++) 131 | //polys[i] = visited[(visited.Count - 1) - i]; 132 | polys.Insert(i, visited[(visited.Count - 1) - i]); 133 | 134 | //return req + size; 135 | return; 136 | } 137 | 138 | public void RemoveAt(int index) 139 | { 140 | polys.RemoveAt(index); 141 | } 142 | 143 | public void RemoveRange(int index, int count) 144 | { 145 | polys.RemoveRange(index, count); 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/PathBuildFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | namespace SharpNav.Pathfinding 7 | { 8 | /// 9 | /// Flags for choosing how the path is built. 10 | /// 11 | [Flags] 12 | public enum PathBuildFlags 13 | { 14 | /// 15 | /// Build normally. 16 | /// 17 | None = 0x00, 18 | 19 | /// 20 | /// Adds a vertex to the path at each polygon edge crossing, but only when the areas of the two polygons are 21 | /// different. 22 | /// 23 | AreaCrossingVertices = 0x01, 24 | 25 | /// 26 | /// Adds a vertex to the path at each polygon edge crossing. 27 | /// 28 | AllCrossingVertices = 0x02 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/PathfindingCommon.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | using SharpNav.Geometry; 7 | 8 | #if MONOGAME 9 | using Vector3 = Microsoft.Xna.Framework.Vector3; 10 | #elif OPENTK 11 | using Vector3 = OpenTK.Vector3; 12 | #elif SHARPDX 13 | using Vector3 = SharpDX.Vector3; 14 | #endif 15 | 16 | namespace SharpNav.Pathfinding 17 | { 18 | /// 19 | /// Store constants, structs, methods in this single class so that other classes can access this information. 20 | /// 21 | public class PathfindingCommon 22 | { 23 | public const int VERTS_PER_POLYGON = 6; //max number of vertices 24 | 25 | /// 26 | /// Generate an accurate sample of random points in the convex polygon and pick a point. 27 | /// 28 | /// The polygon's points data 29 | /// A random float 30 | /// Another random float 31 | /// The resulting point 32 | public static void RandomPointInConvexPoly(Vector3[] pts, float s, float t, out Vector3 pt) 33 | { 34 | //Calculate triangle areas 35 | float[] areas = new float[pts.Length]; 36 | float areaSum = 0.0f; 37 | float area; 38 | for (int i = 2; i < pts.Length; i++) 39 | { 40 | Triangle3.Area2D(ref pts[0], ref pts[i - 1], ref pts[i], out area); 41 | areaSum += Math.Max(0.001f, area); 42 | areas[i] = area; 43 | } 44 | 45 | //Find sub triangle weighted by area 46 | float threshold = s * areaSum; 47 | float accumulatedArea = 0.0f; 48 | float u = 0.0f; 49 | int triangleVertex = 0; 50 | for (int i = 2; i < pts.Length; i++) 51 | { 52 | float currentArea = areas[i]; 53 | if (threshold >= accumulatedArea && threshold < (accumulatedArea + currentArea)) 54 | { 55 | u = (threshold - accumulatedArea) / currentArea; 56 | triangleVertex = i; 57 | break; 58 | } 59 | 60 | accumulatedArea += currentArea; 61 | } 62 | 63 | float v = (float)Math.Sqrt(t); 64 | 65 | float a = 1 - v; 66 | float b = (1 - u) * v; 67 | float c = u * v; 68 | Vector3 pointA = pts[0]; 69 | Vector3 pointB = pts[triangleVertex - 1]; 70 | Vector3 pointC = pts[triangleVertex]; 71 | 72 | pt = a * pointA + b * pointB + c * pointC; 73 | } 74 | 75 | /// 76 | /// Contains information about a navigation mesh 77 | /// 78 | public class NavMeshInfo 79 | { 80 | public int X; 81 | public int Y; 82 | public int Layer; 83 | public int PolyCount; 84 | public int VertCount; 85 | public int MaxLinkCount; 86 | 87 | public int DetailMeshCount; 88 | public int DetailVertCount; 89 | public int DetailTriCount; 90 | 91 | public int BvNodeCount; 92 | 93 | public int OffMeshConCount; 94 | public int OffMeshBase; //index of first polygon which is off-mesh connection 95 | 96 | public float WalkableHeight; 97 | public float WalkableRadius; 98 | public float WalkableClimb; 99 | public BBox3 Bounds; 100 | public float BvQuantFactor; 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/RaycastHit.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | using SharpNav.Geometry; 8 | 9 | #if MONOGAME 10 | using Vector3 = Microsoft.Xna.Framework.Vector3; 11 | #elif OPENTK 12 | using Vector3 = OpenTK.Vector3; 13 | #elif SHARPDX 14 | using Vector3 = SharpDX.Vector3; 15 | #endif 16 | 17 | namespace SharpNav.Pathfinding 18 | { 19 | [Serializable] 20 | [StructLayout(LayoutKind.Sequential)] 21 | public struct RaycastHit 22 | { 23 | public float T; 24 | public Vector3 Normal; 25 | public int EdgeIndex; 26 | 27 | public bool IsHit { get { return T != float.MaxValue; } } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/RaycastOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | 6 | namespace SharpNav.Pathfinding 7 | { 8 | /// 9 | /// Options for raycasting. 10 | /// 11 | [Flags] 12 | public enum RaycastOptions 13 | { 14 | None = 0, 15 | 16 | /// 17 | /// Calculate and use movement costs across the ray. 18 | /// 19 | UseCosts = 0x01, 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Source/SharpNav/Pathfinding/StraightPathFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | using SharpNav.Geometry; 8 | 9 | #if MONOGAME 10 | using Vector3 = Microsoft.Xna.Framework.Vector3; 11 | #elif OPENTK 12 | using Vector3 = OpenTK.Vector3; 13 | #elif SHARPDX 14 | using Vector3 = SharpDX.Vector3; 15 | #endif 16 | 17 | namespace SharpNav.Pathfinding 18 | { 19 | /// 20 | /// Flags returned by NavMeshQuery.FindStraightPath. 21 | /// 22 | [Flags] 23 | public enum StraightPathFlags 24 | { 25 | None = 0, 26 | 27 | /// The vertex is the start position of the path. 28 | Start = 0x01, 29 | 30 | /// The vertex is the end position of the path. 31 | End = 0x02, 32 | 33 | /// The vertex is the start of an off-mesh connection. 34 | OffMeshConnection = 0x04 35 | } 36 | 37 | public struct StraightPathVertex 38 | { 39 | public NavPoint Point; 40 | public StraightPathFlags Flags; 41 | 42 | public StraightPathVertex(NavPoint point, StraightPathFlags flags) 43 | { 44 | Point = point; 45 | Flags = flags; 46 | } 47 | } 48 | 49 | public class StraightPath 50 | { 51 | private List verts; 52 | 53 | public StraightPath() 54 | { 55 | verts = new List(); 56 | } 57 | 58 | public int Count { get { return verts.Count; } } 59 | 60 | public StraightPathVertex this[int i] 61 | { 62 | get { return verts[i]; } 63 | set { verts[i] = value; } 64 | } 65 | 66 | public void Clear() 67 | { 68 | verts.Clear(); 69 | } 70 | 71 | public bool AppendVertex(StraightPathVertex vert) 72 | { 73 | bool equalToLast = false; 74 | if (Count > 0) 75 | { 76 | //can only be done if at least one vertex in path 77 | Vector3 lastStraightPath = verts[Count - 1].Point.Position; 78 | Vector3 pos = vert.Point.Position; 79 | equalToLast = Vector3Extensions.AlmostEqual(ref lastStraightPath, ref pos); 80 | } 81 | 82 | if (equalToLast) 83 | { 84 | //the vertices are equal, update flags and polys 85 | verts[Count - 1] = vert; 86 | } 87 | else 88 | { 89 | //append new vertex 90 | verts.Add(vert); 91 | 92 | if (vert.Flags == StraightPathFlags.End) 93 | { 94 | return false; 95 | } 96 | } 97 | 98 | return true; 99 | } 100 | 101 | public void RemoveAt(int index) 102 | { 103 | verts.RemoveAt(index); 104 | } 105 | 106 | public void RemoveRange(int index, int count) 107 | { 108 | verts.RemoveRange(index, count); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /Source/SharpNav/PolyBounds.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Linq; 6 | using System.Runtime.InteropServices; 7 | 8 | namespace SharpNav 9 | { 10 | /// 11 | /// A bounding box for vertices in a . 12 | /// 13 | [StructLayout(LayoutKind.Sequential)] 14 | public struct PolyBounds : IEquatable 15 | { 16 | /// 17 | /// The lower bound of the bounding box. 18 | /// 19 | public PolyVertex Min; 20 | 21 | /// 22 | /// The upper bound of the bounding box. 23 | /// 24 | public PolyVertex Max; 25 | 26 | /// 27 | /// Initializes a new instance of the struct. 28 | /// 29 | /// The lower bound of the bounding box. 30 | /// The upper bound of the bounding box. 31 | public PolyBounds(PolyVertex min, PolyVertex max) 32 | { 33 | Min = min; 34 | Max = max; 35 | } 36 | 37 | /// 38 | /// Checks whether two boudning boxes are intersecting. 39 | /// 40 | /// The first bounding box. 41 | /// The second bounding box. 42 | /// A value indicating whether the two bounding boxes are overlapping. 43 | public static bool Overlapping(ref PolyBounds a, ref PolyBounds b) 44 | { 45 | return !(a.Min.X > b.Max.X || a.Max.X < b.Min.X 46 | || a.Min.Y > b.Max.Y || a.Max.Y < b.Min.Y 47 | || a.Min.Z > b.Max.Z || a.Max.Z < b.Min.Z); 48 | } 49 | 50 | /// 51 | /// Compares two instances for equality. 52 | /// 53 | /// A bounding box. 54 | /// Another bounding box. 55 | /// A value indicating whether the two bounding boxes are equal. 56 | public static bool operator ==(PolyBounds left, PolyBounds right) 57 | { 58 | return left.Equals(right); 59 | } 60 | 61 | /// 62 | /// Compares two instances for inequality. 63 | /// 64 | /// A bounding box. 65 | /// Another bounding box. 66 | /// A value indicating whether the two bounding boxes are not equal. 67 | public static bool operator !=(PolyBounds left, PolyBounds right) 68 | { 69 | return !(left == right); 70 | } 71 | 72 | /// 73 | /// Compares another instance with this instance for equality. 74 | /// 75 | /// A bounding box. 76 | /// A value indicating whether the bounding box is equal to this instance. 77 | public bool Equals(PolyBounds other) 78 | { 79 | return Min == other.Min && Max == other.Max; 80 | } 81 | 82 | /// 83 | /// Compares another object with this instance for equality. 84 | /// 85 | /// An object. 86 | /// A value indicating whether the object is equal to this instance. 87 | public override bool Equals(object obj) 88 | { 89 | PolyBounds? b = obj as PolyBounds?; 90 | if (b.HasValue) 91 | return this.Equals(b.Value); 92 | 93 | return false; 94 | } 95 | 96 | /// 97 | /// Calculates a hash code unique to the contents of this instance. 98 | /// 99 | /// A hash code. 100 | public override int GetHashCode() 101 | { 102 | //TODO write a better hash code 103 | return Min.GetHashCode() ^ Max.GetHashCode(); 104 | } 105 | 106 | /// 107 | /// Creates a human-readable string with the contents of this instance. 108 | /// 109 | /// A human-readable string. 110 | public override string ToString() 111 | { 112 | return "[" + Min.ToString() + ", " + Max.ToString() + "]"; 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Source/SharpNav/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Reflection; 6 | using System.Runtime.CompilerServices; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | [assembly: AssemblyTitle("SharpNav")] 13 | [assembly: AssemblyDescription("A fully-managed navigation mesh library.")] 14 | [assembly: AssemblyConfiguration("")] 15 | [assembly: AssemblyCompany("")] 16 | [assembly: AssemblyProduct("SharpNav")] 17 | [assembly: AssemblyCopyright("Copyright © 2013-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file).")] 18 | [assembly: AssemblyTrademark("")] 19 | [assembly: AssemblyCulture("")] 20 | 21 | [assembly: CLSCompliant(true)] 22 | 23 | #if MONOGAME 24 | [assembly: InternalsVisibleTo("SharpNav.Tests")] 25 | #else 26 | [assembly: InternalsVisibleTo("SharpNav.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007db4cb90a9a4ef6908e5293fffcba3c76e490fd182595f7fd6fa32801b29ed416181383f2da9dac4271ae5f3c89a66ece56668415dcc274d775b1efbe4e013e840221fb12cfd99ffaf405ad124e5d301ba55610ee4fcf25687faf3434574b397773e720fb6573eb2e935e585926e365a1d8ac2fd864cf0b9b11932d2abb4e9af")] 27 | #endif 28 | 29 | // I'm attempting to follow Semantic Versioning with the built-in C# Version class as a fallback 30 | // or alternative to NuGet's semver support. This means I need to do some special things with this 31 | // version number to make sure that comparing these versions match the same order that the semver 32 | // versions do. 33 | // 34 | // Major and Minor are the same as semver. C#'s "Build" number is semver's "Patch" number. The 35 | // "Revision" number is special. It's based on pre-releases and follow these rules: 36 | // 37 | // * Alpha versions start at 0 and increment once per released version. 38 | // * Beta versions start at 100 and increment once per released version. 39 | // * The final release of any version will have a revision number of 200. 40 | // 41 | // This way, a consumer can programmatically determine whether a release of SharpNav is an alpha or 42 | // beta pre-release, or the final released version. comparability between SemVer and C#'s Version 43 | // class is also maintained. 44 | // 45 | // SemVer Version | C# Version 46 | // ----------------|---------------- 47 | // 0.9.0 | 0.9.0.200 48 | // 1.0.0-alpha.1 | 1.0.0.0 49 | // 1.0.0-alpha.2 | 1.0.0.1 50 | // 1.0.0-beta.1 | 1.0.0.100 51 | // 1.0.0-beta.2 | 1.0.0.101 52 | // 1.0.0 | 1.0.0.200 53 | // 1.1.0 | 1.1.0.200 54 | // 1.2.0-beta.1 | 1.2.0.100 55 | // 1.2.0 | 1.2.0.200 56 | // 2.0.1 | 2.0.1.200 57 | // 58 | [assembly: AssemblyVersion("1.0.0.1")] 59 | [assembly: AssemblyFileVersion("1.0.0.0")] 60 | 61 | // There are two ways of differentiating versions of SharpNav.dll that are built with engine integrations. 62 | // The first is metadata included with the SemVer version (e.g. 1.0.0-alpha.2+monogame). The second is that 63 | // each version is signed with a separate strong name key, which provides a few extra benefits. Multiple 64 | // integrated versions of SharpNav can now be installed to the GAC without worrying about them interfering 65 | // with one another. 66 | #if MONOGAME 67 | [assembly: AssemblyInformationalVersion("1.0.0-alpha.2+monogame")] 68 | #elif OPENTK 69 | [assembly: AssemblyInformationalVersion("1.0.0-alpha.2+opentk")] 70 | #elif SHARPDX 71 | [assembly: AssemblyInformationalVersion("1.0.0-alpha.2+sharpdx")] 72 | #else 73 | [assembly: AssemblyInformationalVersion("1.0.0-alpha.2")] 74 | #endif 75 | 76 | // Setting ComVisible to false makes the types in this assembly not visible 77 | // to COM components. If you need to access a type in this assembly from 78 | // COM, set the ComVisible attribute to true on that type. 79 | [assembly: ComVisible(false)] 80 | 81 | // The following GUID is for the ID of the typelib if this project is exposed to COM 82 | [assembly: Guid("603f4e3f-26ed-4338-b400-0a1a2fe0cf10")] 83 | -------------------------------------------------------------------------------- /Source/SharpNav/Settings.StyleCop: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2000 4 | 5 | 6 | 7 | 8 | 9 | 10 | False 11 | 12 | 13 | 14 | 15 | False 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | False 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | False 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | False 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | False 56 | 57 | 58 | 59 | 60 | False 61 | 62 | 63 | 64 | 65 | False 66 | 67 | 68 | 69 | 70 | False 71 | 72 | 73 | 74 | 75 | False 76 | 77 | 78 | 79 | 80 | False 81 | 82 | 83 | 84 | 85 | False 86 | 87 | 88 | 89 | 90 | False 91 | 92 | 93 | 94 | 95 | False 96 | 97 | 98 | 99 | 100 | 101 | 102 | False 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /Source/SharpNav/SharpNav.OpenTK.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Source/SharpNav/SharpNav.OpenTK.snk -------------------------------------------------------------------------------- /Source/SharpNav/SharpNav.SharpDX.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Source/SharpNav/SharpNav.SharpDX.snk -------------------------------------------------------------------------------- /Source/SharpNav/SharpNav.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Robmaister/SharpNav/fd2b70e25a8d30a94e1a64629e42a1de8809c431/Source/SharpNav/SharpNav.snk -------------------------------------------------------------------------------- /Source/SharpNav/Span.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System.Runtime.InteropServices; 5 | 6 | namespace SharpNav 7 | { 8 | /// 9 | /// A span is a range of integers which represents a range of voxels in a . 10 | /// 11 | [StructLayout(LayoutKind.Sequential)] 12 | public struct Span 13 | { 14 | /// 15 | /// The lowest value in the span. 16 | /// 17 | public int Minimum; 18 | 19 | /// 20 | /// The highest value in the span. 21 | /// 22 | public int Maximum; 23 | 24 | /// 25 | /// The span area id 26 | /// 27 | public Area Area; 28 | 29 | /// 30 | /// Initializes a new instance of the struct. 31 | /// 32 | /// The lowest value in the span. 33 | /// The highest value in the span. 34 | public Span(int min, int max) 35 | { 36 | Minimum = min; 37 | Maximum = max; 38 | Area = Area.Null; 39 | } 40 | 41 | /// 42 | /// Initializes a new instance of the struct. 43 | /// 44 | /// The lowest value in the span. 45 | /// The highest value in the span. 46 | /// The area flags for the span. 47 | public Span(int min, int max, Area area) 48 | { 49 | Minimum = min; 50 | Maximum = max; 51 | Area = area; 52 | } 53 | 54 | /// 55 | /// Gets the height of the span. 56 | /// 57 | public int Height 58 | { 59 | get 60 | { 61 | return Maximum - Minimum; 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Source/SharpNav/SpanReference.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). 2 | // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace SharpNav 8 | { 9 | /// 10 | /// References a within a . 11 | /// 12 | [StructLayout(LayoutKind.Sequential)] 13 | public struct SpanReference 14 | { 15 | private int x; 16 | private int y; 17 | private int index; 18 | 19 | /// 20 | /// Initializes a new instance of the struct. 21 | /// 22 | /// The X coordinate of the the is contained in. 23 | /// The Y coordinate of the the is contained in. 24 | /// The index of the within the specified . 25 | public SpanReference(int x, int y, int i) 26 | { 27 | this.x = x; 28 | this.y = y; 29 | this.index = i; 30 | } 31 | 32 | /// 33 | /// Gets the X coordinate of the that contains the referenced . 34 | /// 35 | public int X 36 | { 37 | get 38 | { 39 | return x; 40 | } 41 | } 42 | 43 | /// 44 | /// Gets the Y coordinate of the that contains the referenced . 45 | /// 46 | public int Y 47 | { 48 | get 49 | { 50 | return y; 51 | } 52 | } 53 | 54 | /// 55 | /// Gets the index of the within the it is contained in. 56 | /// 57 | public int Index 58 | { 59 | get 60 | { 61 | return index; 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Source/SharpNav/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.0-alpha.2+appveyor.{build} 2 | 3 | branches: 4 | only: 5 | - master 6 | 7 | configuration: 8 | - Standalone 9 | - OpenTK 10 | - SharpDX 11 | - MonoGame 12 | 13 | before_build: 14 | - nuget restore Build/CI/%CONFIGURATION%/packages.config -SolutionDirectory Source/ 15 | 16 | build_script: 17 | - cmd: msbuild "Build/CoreOnly.proj" /t:%CONFIGURATION% /verbosity:normal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" 18 | 19 | test: 20 | categories: 21 | except: 22 | - BrokenButUnused 23 | 24 | deploy: off 25 | --------------------------------------------------------------------------------