remove new float[3]

This commit is contained in:
ikpil 2023-04-17 23:46:00 +09:00
parent 8a59cb2d6b
commit 98cdbd7d20
6 changed files with 61 additions and 57 deletions

View File

@ -0,0 +1,43 @@
using System;
namespace DotRecast.Recast.Demo.Draw;
public class ArrayBuffer<T>
{
private int _size;
private T[] _items;
public int Count => _size;
public ArrayBuffer()
{
_size = 0;
_items = Array.Empty<T>();
}
public void Add(T item)
{
if (0 >= _items.Length)
{
_items = new T[256];
}
if (_items.Length <= _size)
{
var temp = new T[(int)(_size * 1.5)];
Array.Copy(_items, 0, temp, 0, _items.Length);
_items = temp;
}
_items[_size++] = item;
}
public void Clear()
{
_size = 0;
}
public T[] AsArray()
{
return _items;
}
}

View File

@ -201,7 +201,7 @@ public class DebugDraw
getOpenGlDraw().vertex(x, y, z, color);
}
public void vertex(float[] pos, int color, float[] uv)
public void vertex(Vector3f pos, int color, Vector2f uv)
{
getOpenGlDraw().vertex(pos, color, uv);
}

View File

@ -6,45 +6,6 @@ using Silk.NET.OpenGL;
namespace DotRecast.Recast.Demo.Draw;
public class ArrayBuffer<T>
{
private int _size;
private T[] _items;
public int Count => _size;
public ArrayBuffer()
{
_size = 0;
_items = Array.Empty<T>();
}
public void Add(T item)
{
if (0 >= _items.Length)
{
_items = new T[256];
}
if (_items.Length <= _size)
{
var temp = new T[(int)(_size * 1.5)];
Array.Copy(_items, 0, temp, 0, _items.Length);
_items = temp;
}
_items[_size++] = item;
}
public void Clear()
{
_size = 0;
}
public T[] AsArray()
{
return _items;
}
}
public class ModernOpenGLDraw : OpenGLDraw
{
private GL _gl;
@ -331,7 +292,7 @@ public class ModernOpenGLDraw : OpenGLDraw
}
public void vertex(float[] pos, int color, float[] uv)
public void vertex(Vector3f pos, int color, Vector2f uv)
{
vertices.Add(new OpenGLVertex(pos, uv, color));
}

View File

@ -18,7 +18,7 @@ public interface OpenGLDraw
void vertex(float[] pos, int color);
void vertex(Vector3f pos, int color);
void vertex(float[] pos, int color, float[] uv);
void vertex(Vector3f pos, int color, Vector2f uv);
void vertex(float x, float y, float z, int color, float u, float v);

View File

@ -15,8 +15,8 @@ public struct OpenGLVertex
[FieldOffset(16)] private readonly float v;
[FieldOffset(20)] private readonly int color;
public OpenGLVertex(float[] pos, float[] uv, int color) :
this(pos[0], pos[1], pos[2], uv[0], uv[1], color)
public OpenGLVertex(Vector3f pos, Vector2f uv, int color) :
this(pos[0], pos[1], pos[2], uv.x, uv.y, color)
{
}

View File

@ -42,9 +42,9 @@ public class RecastDebugDraw : DebugDraw
{
float walkableThr = (float)Math.Cos(walkableSlopeAngle / 180.0f * Math.PI);
float[] uva = new float[2];
float[] uvb = new float[2];
float[] uvc = new float[2];
Vector2f uva = Vector2f.Zero;
Vector2f uvb = Vector2f.Zero;
Vector2f uvc = Vector2f.Zero;
texture(true);
@ -52,7 +52,7 @@ public class RecastDebugDraw : DebugDraw
begin(DebugDrawPrimitives.TRIS);
for (int i = 0; i < tris.Length; i += 3)
{
float[] norm = new float[] { normals[i], normals[i + 1], normals[i + 2] };
Vector3f norm = Vector3f.Of(normals[i], normals[i + 1], normals[i + 2]);
int color;
char a = (char)(220 * (2 + norm[0] + norm[1]) / 4);
@ -65,9 +65,9 @@ public class RecastDebugDraw : DebugDraw
color = duRGBA(a, a, a, 255);
}
float[] va = new float[] { verts[tris[i] * 3], verts[tris[i] * 3 + 1], verts[tris[i] * 3 + 2] };
float[] vb = new float[] { verts[tris[i + 1] * 3], verts[tris[i + 1] * 3 + 1], verts[tris[i + 1] * 3 + 2] };
float[] vc = new float[] { verts[tris[i + 2] * 3], verts[tris[i + 2] * 3 + 1], verts[tris[i + 2] * 3 + 2] };
Vector3f va = Vector3f.Of(verts[tris[i] * 3], verts[tris[i] * 3 + 1], verts[tris[i] * 3 + 2]);
Vector3f vb = Vector3f.Of(verts[tris[i + 1] * 3], verts[tris[i + 1] * 3 + 1], verts[tris[i + 1] * 3 + 2]);
Vector3f vc = Vector3f.Of(verts[tris[i + 2] * 3], verts[tris[i + 2] * 3 + 1], verts[tris[i + 2] * 3 + 2]);
int ax = 0, ay = 0;
if (Math.Abs(norm[1]) > Math.Abs(norm[ax]))
@ -83,12 +83,12 @@ public class RecastDebugDraw : DebugDraw
ax = (1 << ax) & 3; // +1 mod 3
ay = (1 << ax) & 3; // +1 mod 3
uva[0] = va[ax] * texScale;
uva[1] = va[ay] * texScale;
uvb[0] = vb[ax] * texScale;
uvb[1] = vb[ay] * texScale;
uvc[0] = vc[ax] * texScale;
uvc[1] = vc[ay] * texScale;
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;
vertex(va, color, uva);
vertex(vb, color, uvb);