Skip to content

Commit

Permalink
Add Vec2/3 extensions with many constants
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfranke committed Dec 25, 2020
1 parent 5501b0f commit b56354d
Show file tree
Hide file tree
Showing 6 changed files with 520 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Godot Node Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
<ItemGroup>
<Compile Include="addons\godot-next-cs\2d\Geometry2D.cs" />
<Compile Include="addons\godot-next-cs\2d\Trail2D.cs" />
<Compile Include="addons\godot-next-cs\2d\Vec2.cs" />
<Compile Include="addons\godot-next-cs\3d\Trail3D.cs" />
<Compile Include="addons\godot-next-cs\3d\Vec3.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Expand Down
107 changes: 107 additions & 0 deletions addons/godot-next-cs/2d/Vec2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using Godot;
using Vector2Array = Godot.Collections.Array<Godot.Vector2>;

/// <summary>
/// Adds more constants for Vector2.
/// </summary>
/// <remarks>
/// Also includes all of Godot's Vector2 constants.
/// </remarks>
public static partial class Vec2
{
public static readonly Vector2 Zero = new Vector2(0, 0);
public static readonly Vector2 One = new Vector2(1, 1);
public static readonly Vector2 Right = new Vector2(1, 0);
public static readonly Vector2 DownRight = new Vector2(1, 1);
public static readonly Vector2 Down = new Vector2(0, 1);
public static readonly Vector2 DownLeft = new Vector2(-1, 1);
public static readonly Vector2 Left = new Vector2(-1, 0);
public static readonly Vector2 UpLeft = new Vector2(-1, -1);
public static readonly Vector2 Up = new Vector2(0, -1);
public static readonly Vector2 UpRight = new Vector2(1, -1);

public static readonly Vector2Array DirCardinal = new Vector2Array{
Right,
Down,
Left,
Up,
};

public static readonly Vector2Array Dir = new Vector2Array{
Right,
DownRight,
Down,
DownLeft,
Left,
UpLeft,
Up,
UpRight,
};

public static readonly Vector2 RightNorm = new Vector2(1, 0);
public static readonly Vector2 DownRightNorm = new Vector2(0.7071067811865475244f, 0.7071067811865475244f);
public static readonly Vector2 DownNorm = new Vector2(0, 1);
public static readonly Vector2 DownLeftNorm = new Vector2(-0.7071067811865475244f, 0.7071067811865475244f);
public static readonly Vector2 LeftNorm = new Vector2(-1, 0);
public static readonly Vector2 UpLeftNorm = new Vector2(-0.7071067811865475244f, -0.7071067811865475244f);
public static readonly Vector2 UpNorm = new Vector2(0, -1);
public static readonly Vector2 UpRightNorm = new Vector2(0.7071067811865475244f, -0.7071067811865475244f);

public static readonly Vector2Array DirNorm = new Vector2Array{
RightNorm,
DownRightNorm,
DownNorm,
DownLeftNorm,
LeftNorm,
UpLeftNorm,
UpNorm,
UpRightNorm,
};

public static readonly Vector2 E = new Vector2(1, 0);
public static readonly Vector2 SE = new Vector2(1, 1);
public static readonly Vector2 S = new Vector2(0, 1);
public static readonly Vector2 SW = new Vector2(-1, 1);
public static readonly Vector2 W = new Vector2(-1, 0);
public static readonly Vector2 NW = new Vector2(-1, -1);
public static readonly Vector2 N = new Vector2(0, -1);
public static readonly Vector2 NE = new Vector2(1, -1);

public static readonly Vector2 ENorm = new Vector2(1, 0);
public static readonly Vector2 SENorm = new Vector2(0.7071067811865475244f, 0.7071067811865475244f);
public static readonly Vector2 SNorm = new Vector2(0, 1);
public static readonly Vector2 SWNorm = new Vector2(-0.7071067811865475244f, 0.7071067811865475244f);
public static readonly Vector2 WNorm = new Vector2(-1, 0);
public static readonly Vector2 NWNorm = new Vector2(-0.7071067811865475244f, -0.7071067811865475244f);
public static readonly Vector2 NNorm = new Vector2(0, -1);
public static readonly Vector2 NENorm = new Vector2(0.7071067811865475244f, -0.7071067811865475244f);

public static readonly Vector2 SEE = new Vector2(0.9238795325112867561f, 0.3826834323650897717f);
public static readonly Vector2 SSE = new Vector2(0.3826834323650897717f, 0.9238795325112867561f);
public static readonly Vector2 SSW = new Vector2(-0.3826834323650897717f, 0.9238795325112867561f);
public static readonly Vector2 SWW = new Vector2(-0.9238795325112867561f, 0.3826834323650897717f);
public static readonly Vector2 NWW = new Vector2(-0.9238795325112867561f, -0.3826834323650897717f);
public static readonly Vector2 NNW = new Vector2(-0.3826834323650897717f, -0.9238795325112867561f);
public static readonly Vector2 NNE = new Vector2(0.3826834323650897717f, -0.9238795325112867561f);
public static readonly Vector2 NEE = new Vector2(0.9238795325112867561f, -0.3826834323650897717f);

public static readonly Vector2Array Dir16 = new Vector2Array{
ENorm,
SEE,
SENorm,
SSE,
SNorm,
SSW,
SWNorm,
SWW,
WNorm,
NWW,
NWNorm,
NNW,
NNorm,
NNE,
NENorm,
NEE,
};

}
147 changes: 147 additions & 0 deletions addons/godot-next-cs/3d/Vec3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
using Godot;
using Vector3Array = Godot.Collections.Array<Godot.Vector3>;

/// <summary>
/// Adds more constants for Vector3.
/// </summary>
/// <remarks>
/// Also includes all of Godot's Vector3 constants.
/// </remarks>
public static partial class Vec3
{

public static readonly Vector3 Zero = new Vector3(0, 0, 0);
public static readonly Vector3 One = new Vector3(1, 1, 1);
public static readonly Vector3 Right = new Vector3(1, 0, 0);
public static readonly Vector3 BackRight = new Vector3(1, 0, 1);
public static readonly Vector3 Back = new Vector3(0, 0, 1);
public static readonly Vector3 BackLeft = new Vector3(-1, 0, 1);
public static readonly Vector3 Left = new Vector3(-1, 0, 0);
public static readonly Vector3 ForwardLeft = new Vector3(-1, 0, -1);
public static readonly Vector3 Forward = new Vector3(0, 0, -1);
public static readonly Vector3 ForwardRight = new Vector3(1, 0, -1);

public static readonly Vector3Array DirCardinal = new Vector3Array{
Right,
Back,
Left,
Forward,
};

public static readonly Vector3Array Dir = new Vector3Array{
Right,
BackRight,
Back,
BackLeft,
Left,
ForwardLeft,
Forward,
ForwardRight,
};

public static readonly Vector3 RightNorm = new Vector3(1, 0, 0);
public static readonly Vector3 BackRightNorm = new Vector3(0.7071067811865475244f, 0, 0.7071067811865475244f);
public static readonly Vector3 BackNorm = new Vector3(0, 0, 1);
public static readonly Vector3 BackLeftNorm = new Vector3(-0.7071067811865475244f, 0, 0.7071067811865475244f);
public static readonly Vector3 LeftNorm = new Vector3(-1, 0, 0);
public static readonly Vector3 ForwardLeftNorm = new Vector3(-0.7071067811865475244f, 0, -0.7071067811865475244f);
public static readonly Vector3 ForwardNorm = new Vector3(0, 0, -1);
public static readonly Vector3 ForwardRightNorm = new Vector3(0.7071067811865475244f, 0, -0.7071067811865475244f);

public static readonly Vector3Array DirNorm = new Vector3Array{
RightNorm,
BackRightNorm,
BackNorm,
BackLeftNorm,
LeftNorm,
ForwardLeftNorm,
ForwardNorm,
ForwardRightNorm,
};

public static readonly Vector3 E = new Vector3(1, 0, 0);
public static readonly Vector3 SE = new Vector3(1, 0, 1);
public static readonly Vector3 S = new Vector3(0, 0, 1);
public static readonly Vector3 SW = new Vector3(-1, 0, 1);
public static readonly Vector3 W = new Vector3(-1, 0, 0);
public static readonly Vector3 NW = new Vector3(-1, 0, -1);
public static readonly Vector3 N = new Vector3(0, 0, -1);
public static readonly Vector3 NE = new Vector3(1, 0, -1);

public static readonly Vector3 ENorm = new Vector3(1, 0, 0);
public static readonly Vector3 SENorm = new Vector3(0.7071067811865475244f, 0, 0.7071067811865475244f);
public static readonly Vector3 SNorm = new Vector3(0, 0, 1);
public static readonly Vector3 SWNorm = new Vector3(-0.7071067811865475244f, 0, 0.7071067811865475244f);
public static readonly Vector3 WNorm = new Vector3(-1, 0, 0);
public static readonly Vector3 NWNorm = new Vector3(-0.7071067811865475244f, 0, -0.7071067811865475244f);
public static readonly Vector3 NNorm = new Vector3(0, 0, -1);
public static readonly Vector3 NENorm = new Vector3(0.7071067811865475244f, 0, -0.7071067811865475244f);

public static readonly Vector3 SEE = new Vector3(0.9238795325112867561f, 0, 0.3826834323650897717f);
public static readonly Vector3 SSE = new Vector3(0.3826834323650897717f, 0, 0.9238795325112867561f);
public static readonly Vector3 SSW = new Vector3(-0.3826834323650897717f, 0, 0.9238795325112867561f);
public static readonly Vector3 SWW = new Vector3(-0.9238795325112867561f, 0, 0.3826834323650897717f);
public static readonly Vector3 NWW = new Vector3(-0.9238795325112867561f, 0, -0.3826834323650897717f);
public static readonly Vector3 NNW = new Vector3(-0.3826834323650897717f, 0, -0.9238795325112867561f);
public static readonly Vector3 NNE = new Vector3(0.3826834323650897717f, 0, -0.9238795325112867561f);
public static readonly Vector3 NEE = new Vector3(0.9238795325112867561f, 0, -0.3826834323650897717f);

public static readonly Vector3Array Dir16 = new Vector3Array{
ENorm,
SEE,
SENorm,
SSE,
SNorm,
SSW,
SWNorm,
SWW,
WNorm,
NWW,
NWNorm,
NNW,
NNorm,
NNE,
NENorm,
NEE,
};

public static readonly Vector3 Up = new Vector3(0, 1, 0);
public static readonly Vector3 UpRight = new Vector3(1, 1, 0);
public static readonly Vector3 UpBackRight = new Vector3(1, 1, 1);
public static readonly Vector3 UpBack = new Vector3(0, 1, 1);
public static readonly Vector3 UpBackLeft = new Vector3(-1, 1, 1);
public static readonly Vector3 UpLeft = new Vector3(-1, 1, 0);
public static readonly Vector3 UpForwardLeft = new Vector3(-1, 1, -1);
public static readonly Vector3 UpForward = new Vector3(0, 1, -1);
public static readonly Vector3 UpForwardRight = new Vector3(1, 1, -1);

public static readonly Vector3 Down = new Vector3(0, -1, 0);
public static readonly Vector3 DownRight = new Vector3(1, -1, 0);
public static readonly Vector3 DownBackRight = new Vector3(1, -1, 1);
public static readonly Vector3 DownBack = new Vector3(0, -1, 1);
public static readonly Vector3 DownBackLeft = new Vector3(-1, -1, 1);
public static readonly Vector3 DownLeft = new Vector3(-1, -1, 0);
public static readonly Vector3 DownForwardLeft = new Vector3(-1, -1, -1);
public static readonly Vector3 DownForward = new Vector3(0, -1, -1);
public static readonly Vector3 DownForwardRight = new Vector3(1, -1, -1);

public static readonly Vector3 UpNorm = new Vector3(0, 1, 0);
public static readonly Vector3 UpRightNorm = new Vector3(0.7071067811865475244f, 0.7071067811865475244f, 0);
public static readonly Vector3 UpBackRightNorm = new Vector3(0.5773502691896257645f, 0.5773502691896257645f, 0.5773502691896257645f);
public static readonly Vector3 UpBackNorm = new Vector3(0, 0.7071067811865475244f, 0.7071067811865475244f);
public static readonly Vector3 UpBackLeftNorm = new Vector3(-0.5773502691896257645f, 0.5773502691896257645f, 0.5773502691896257645f);
public static readonly Vector3 UpLeftNorm = new Vector3(-0.7071067811865475244f, 0.7071067811865475244f, 0);
public static readonly Vector3 UpForwardLeftNorm = new Vector3(-0.5773502691896257645f, 0.5773502691896257645f, -0.5773502691896257645f);
public static readonly Vector3 UpForwardNorm = new Vector3(0, 0.7071067811865475244f, -0.7071067811865475244f);
public static readonly Vector3 UpForwardRightNorm = new Vector3(0.5773502691896257645f, 0.5773502691896257645f, -0.5773502691896257645f);

public static readonly Vector3 DownNorm = new Vector3(0, -1, 0);
public static readonly Vector3 DownRightNorm = new Vector3(0.7071067811865475244f, -0.7071067811865475244f, 0);
public static readonly Vector3 DownBackRightNorm = new Vector3(0.5773502691896257645f, -0.5773502691896257645f, 0.5773502691896257645f);
public static readonly Vector3 DownBackNorm = new Vector3(0, -0.7071067811865475244f, 0.7071067811865475244f);
public static readonly Vector3 DownBackLeftNorm = new Vector3(-0.5773502691896257645f, -0.5773502691896257645f, 0.5773502691896257645f);
public static readonly Vector3 DownLeftNorm = new Vector3(-0.7071067811865475244f, -0.7071067811865475244f, 0);
public static readonly Vector3 DownForwardLeftNorm = new Vector3(-0.5773502691896257645f, -0.5773502691896257645f, -0.5773502691896257645f);
public static readonly Vector3 DownForwardNorm = new Vector3(0, -0.7071067811865475244f, -0.7071067811865475244f);
public static readonly Vector3 DownForwardRightNorm = new Vector3(0.5773502691896257645f, -0.5773502691896257645f, -0.5773502691896257645f);
}
103 changes: 103 additions & 0 deletions addons/godot-next/2d/vec2.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
class_name Vec2
extends Resource
# author: aaronfranke
# license: MIT
# description: Adds more constants for Vector2.
# notes:
# - Also includes all of Godot's Vector2 constants.

const ZERO = Vector2(0, 0)
const ONE = Vector2(1, 1)
const RIGHT = Vector2(1, 0)
const DOWN_RIGHT = Vector2(1, 1)
const DOWN = Vector2(0, 1)
const DOWN_LEFT = Vector2(-1, 1)
const LEFT = Vector2(-1, 0)
const UP_LEFT = Vector2(-1, -1)
const UP = Vector2(0, -1)
const UP_RIGHT = Vector2(1, -1)

const DIR_CARDINAL = [
RIGHT,
DOWN,
LEFT,
UP,
]

const DIR = [
RIGHT,
DOWN_RIGHT,
DOWN,
DOWN_LEFT,
LEFT,
UP_LEFT,
UP,
UP_RIGHT,
]

const RIGHT_NORM = Vector2(1, 0)
const DOWN_RIGHT_NORM = Vector2(0.7071067811865475244, 0.7071067811865475244)
const DOWN_NORM = Vector2(0, 1)
const DOWN_LEFT_NORM = Vector2(-0.7071067811865475244, 0.7071067811865475244)
const LEFT_NORM = Vector2(-1, 0)
const UP_LEFT_NORM = Vector2(-0.7071067811865475244, -0.7071067811865475244)
const UP_NORM = Vector2(0, -1)
const UP_RIGHT_NORM = Vector2(0.7071067811865475244, -0.7071067811865475244)

const DIR_NORM = [
RIGHT_NORM,
DOWN_RIGHT_NORM,
DOWN_NORM,
DOWN_LEFT_NORM,
LEFT_NORM,
UP_LEFT_NORM,
UP_NORM,
UP_RIGHT_NORM,
]

const E = Vector2(1, 0)
const SE = Vector2(1, 1)
const S = Vector2(0, 1)
const SW = Vector2(-1, 1)
const W = Vector2(-1, 0)
const NW = Vector2(-1, -1)
const N = Vector2(0, -1)
const NE = Vector2(1, -1)

const E_NORM = Vector2(1, 0)
const SE_NORM = Vector2(0.7071067811865475244, 0.7071067811865475244)
const S_NORM = Vector2(0, 1)
const SW_NORM = Vector2(-0.7071067811865475244, 0.7071067811865475244)
const W_NORM = Vector2(-1, 0)
const NW_NORM = Vector2(-0.7071067811865475244, -0.7071067811865475244)
const N_NORM = Vector2(0, -1)
const NE_NORM = Vector2(0.7071067811865475244, -0.7071067811865475244)

# These are always normalized, because tan(22.5 degrees) is not rational.
const SEE = Vector2(0.9238795325112867561, 0.3826834323650897717)
const SSE = Vector2(0.3826834323650897717, 0.9238795325112867561)
const SSW = Vector2(-0.3826834323650897717, 0.9238795325112867561)
const SWW = Vector2(-0.9238795325112867561, 0.3826834323650897717)
const NWW = Vector2(-0.9238795325112867561, -0.3826834323650897717)
const NNW = Vector2(-0.3826834323650897717, -0.9238795325112867561)
const NNE = Vector2(0.3826834323650897717, -0.9238795325112867561)
const NEE = Vector2(0.9238795325112867561, -0.3826834323650897717)

const DIR_16 = [
E_NORM,
SEE,
SE_NORM,
SSE,
S_NORM,
SSW,
SW_NORM,
SWW,
W_NORM,
NWW,
NW_NORM,
NNW,
N_NORM,
NNE,
NE_NORM,
NEE,
]
Loading

0 comments on commit b56354d

Please sign in to comment.