Skip to content

Commit

Permalink
refactor: support netstandard2.1 vector3
Browse files Browse the repository at this point in the history
  • Loading branch information
ikpil committed Oct 28, 2023
1 parent 0924b82 commit ca019c1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 48 deletions.
36 changes: 0 additions & 36 deletions src/DotRecast.Core/Numerics/RcVec3f.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,6 @@ public RcVec3f(float f)
Z = f;
}

public float this[int index]
{
get => GetElement(index);
set => SetElement(index, value);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float GetElement(int index)
{
switch (index)
{
case 0: return X;
case 1: return Y;
case 2: return Z;
default: throw new IndexOutOfRangeException($"{index}");
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetElement(int index, float value)
{
switch (index)
{
case 0:
X = value;
break;
case 1:
Y = value;
break;
case 2:
Z = value;
break;

default: throw new IndexOutOfRangeException($"{index}-{value}");
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly float Length()
Expand Down
3 changes: 1 addition & 2 deletions src/DotRecast.Core/Numerics/RcVecUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace DotRecast.Core.Numerics
public static class RcVecUtils
{
public const float EPSILON = 1e-6f;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RcVec3f Create(float[] values)
{
Expand Down Expand Up @@ -42,7 +42,6 @@ public static float Get(this RcVec3f v, int i)
}
}


[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RcVec3f Scale(this RcVec3f v, float scale)
{
Expand Down
19 changes: 9 additions & 10 deletions src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public RecastDebugDraw(GL gl) : base(gl)
{
}

public void DebugDrawTriMeshSlope(float[] verts, int[] tris, float[] normals, float walkableSlopeAngle,
float texScale)
public void DebugDrawTriMeshSlope(float[] verts, int[] tris, float[] normals, float walkableSlopeAngle, float texScale)
{
float walkableThr = MathF.Cos(walkableSlopeAngle / 180.0f * MathF.PI);

Expand Down Expand Up @@ -70,25 +69,25 @@ public void DebugDrawTriMeshSlope(float[] verts, int[] tris, float[] normals, fl
RcVec3f vc = new RcVec3f(verts[tris[i + 2] * 3], verts[tris[i + 2] * 3 + 1], verts[tris[i + 2] * 3 + 2]);

int ax = 0, ay = 0;
if (MathF.Abs(norm.Y) > MathF.Abs(norm[ax]))
if (MathF.Abs(norm.Y) > MathF.Abs(norm.Get(ax)))
{
ax = 1;
}

if (MathF.Abs(norm.Z) > MathF.Abs(norm[ax]))
if (MathF.Abs(norm.Z) > MathF.Abs(norm.Get(ax)))
{
ax = 2;
}

ax = (1 << ax) & 3; // +1 mod 3
ay = (1 << ax) & 3; // +1 mod 3

uva.X = va[ax] * texScale;
uva.Y = va[ay] * texScale;
uvb.X = vb[ax] * texScale;
uvb.Y = vb[ay] * texScale;
uvc.X = vc[ax] * texScale;
uvc.Y = vc[ay] * texScale;
uva.X = va.Get(ax) * texScale;
uva.Y = va.Get(ay) * texScale;
uvb.X = vb.Get(ax) * texScale;
uvb.Y = vb.Get(ay) * texScale;
uvc.X = vc.Get(ax) * texScale;
uvc.Y = vc.Get(ay) * texScale;

Vertex(va, color, uva);
Vertex(vb, color, uvb);
Expand Down

0 comments on commit ca019c1

Please sign in to comment.