Thunder.UnitsNET.Vectors.Geometry.MonoGame
0.2.8
See the version list below for details.
dotnet add package Thunder.UnitsNET.Vectors.Geometry.MonoGame --version 0.2.8
NuGet\Install-Package Thunder.UnitsNET.Vectors.Geometry.MonoGame -Version 0.2.8
<PackageReference Include="Thunder.UnitsNET.Vectors.Geometry.MonoGame" Version="0.2.8" />
<PackageVersion Include="Thunder.UnitsNET.Vectors.Geometry.MonoGame" Version="0.2.8" />
<PackageReference Include="Thunder.UnitsNET.Vectors.Geometry.MonoGame" />
paket add Thunder.UnitsNET.Vectors.Geometry.MonoGame --version 0.2.8
#r "nuget: Thunder.UnitsNET.Vectors.Geometry.MonoGame, 0.2.8"
#:package Thunder.UnitsNET.Vectors.Geometry.MonoGame@0.2.8
#addin nuget:?package=Thunder.UnitsNET.Vectors.Geometry.MonoGame&version=0.2.8
#tool nuget:?package=Thunder.UnitsNET.Vectors.Geometry.MonoGame&version=0.2.8
Thunder.UnitsNET.Vectors.Geometry.MonoGame
MonoGame / XNA integration for Thunder.UnitsNET.Vectors.Geometry.
Provides extension methods to convert unit-aware 2D geometry shapes — circles, rectangles, triangles, ellipses, arcs, sectors, capsules, and polygons — to XNA/MonoGame rendering primitives. Scaling is explicit: you always supply the unit and pixels-per-unit factor, keeping physics dimensions and screen pixels cleanly separated.
Supported frameworks: net8.0, net10.0
Quick start
// dotnet add package Thunder.UnitsNET.Vectors.Geometry
// dotnet add package Thunder.UnitsNET.Vectors.Geometry.MonoGame
using Thunder.UnitsNET.Vectors.Geometry;
using Thunder.UnitsNET.Vectors.Geometry.MonoGame;
using UnitsNet;
using UnitsNet.Units;
using Microsoft.Xna.Framework;
const double ppm = 64.0; // 64 pixels per metre
// Circle: get centre + radius for a circle-draw call
var circle = new Circle2(LengthVector2.FromMeters(5, 3), Radius.FromMeters(2));
Vector2 center = circle.GetXnaCenter(LengthUnit.Meter, ppm); // (320, 192)
float radius = circle.GetXnaRadius(LengthUnit.Meter, ppm); // 128f
// Rectangle: get the four corners for a rotated-quad renderer
var rect = new Rectangle2(
LengthVector2.FromMeters(0, 0),
LengthVector2.FromMeters(4, 2),
Directional.FromDegrees(30));
Vector2[] corners = rect.GetXnaCorners(LengthUnit.Meter, ppm);
// Triangle: get vertex array
var tri = new Triangle2(
LengthVector2.FromMeters(0, 0),
LengthVector2.FromMeters(3, 0),
LengthVector2.FromMeters(1.5, 2));
Vector2[] verts = tri.GetXnaVertices(LengthUnit.Meter, ppm);
// Arc: get polyline for a line-strip renderer
var arc = new Arc2(
new Circle2(LengthVector2.FromMeters(0, 0), Radius.FromMeters(5)),
Directional.East,
Angle.FromDegrees(90));
Vector2[] arcPoints = arc.GetXnaPolyline(LengthUnit.Meter, ppm);
// Polygon
var hex = Polygon2.CreateRegular(LengthVector2.FromMeters(0, 0), Length.FromMeters(3), 6);
Vector2[] hexVerts = hex.GetXnaVertices(LengthUnit.Meter, ppm);
// Directional → XNA rotation float (radians)
float rot = Directional.North.ToXnaRotation(); // MathF.PI / 2
Conversion API
GeometryXnaExtensions
All methods follow the pattern GetXnaXxx(LengthUnit unit, double scale) with convenience
overloads that default scale = 1.0 and/or unit = LengthUnit.Meter.
Circle2
| Method | Returns | Notes |
|---|---|---|
GetXnaCenter(unit, scale) |
Vector2 |
Centre in screen pixels |
GetXnaRadius(unit, scale) |
float |
Radius in screen pixels |
Rectangle2
| Method | Returns | Notes |
|---|---|---|
GetXnaCenter(unit, scale) |
Vector2 |
Centre in screen pixels |
GetXnaCorners(unit, scale) |
Vector2[4] |
[TopLeft, TopRight, BottomLeft, BottomRight]; supports rotation |
Triangle2
| Method | Returns | Notes |
|---|---|---|
GetXnaVertices(unit, scale) |
Vector2[3] |
[A, B, C] |
Ellipse2
| Method | Returns | Notes |
|---|---|---|
GetXnaCenter(unit, scale) |
Vector2 |
Centre in screen pixels |
GetXnaRadii(unit, scale) |
(float semiMajor, float semiMinor) |
Both axes in screen pixels |
GetXnaRotation() |
float |
Rotation of major axis in radians |
Arc2
| Method | Returns | Notes |
|---|---|---|
GetXnaPolyline(unit, scale, segmentCount?) |
Vector2[] |
Line-strip from start to end of arc |
Sector2
| Method | Returns | Notes |
|---|---|---|
GetXnaPolyline(unit, scale, arcSegmentCount?) |
Vector2[] |
Closed polygon: [center, arcStart, …, arcEnd, center] |
Capsule2
| Method | Returns | Notes |
|---|---|---|
GetXnaSpineStart(unit, scale) |
Vector2 |
Centre of first semicircle |
GetXnaSpineEnd(unit, scale) |
Vector2 |
Centre of second semicircle |
GetXnaRadius(unit, scale) |
float |
Capsule radius in screen pixels |
Polygon2
| Method | Returns | Notes |
|---|---|---|
GetXnaVertices(unit, scale) |
Vector2[] |
Same count and order as Vertices |
Directional
| Method | Returns | Notes |
|---|---|---|
ToXnaRotation() |
float |
Angle in radians (East=0, North=π/2) |
Scale parameter
scale is "pixels per unit". Examples:
64.0→ 1 metre = 64 pixels (tile-based game)1.0→ 1 metre = 1 pixel (already in screen units)100.0→ 1 metre = 100 pixels
Pass your pixels-per-unit constant at the call site rather than storing it as a global.
MonoGame dependency note
MonoGame.Framework.DesktopGL is declared as PrivateAssets="all" in this package. Add your
own platform-specific MonoGame package to your game project.
Source repository
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Thunder.UnitsNET.Vectors (>= 0.2.8)
- Thunder.UnitsNET.Vectors.Geometry (>= 0.2.8)
- Thunder.UnitsNET.Vectors.MonoGame (>= 0.2.8)
- UnitsNet (>= 5.67.0)
-
net8.0
- Thunder.UnitsNET.Vectors (>= 0.2.8)
- Thunder.UnitsNET.Vectors.Geometry (>= 0.2.8)
- Thunder.UnitsNET.Vectors.MonoGame (>= 0.2.8)
- UnitsNet (>= 5.67.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.