mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
NavMesh convex volume drawing somewhat working
This commit is contained in:
parent
ba97662c99
commit
8757d0a43f
@ -23,6 +23,7 @@
|
||||
#include "NavEditor/Include/ConvexVolumeTool.h"
|
||||
#include "NavEditor/Include/InputGeom.h"
|
||||
#include "NavEditor/Include/Sample.h"
|
||||
#include <naveditor/include/GameUtils.h>
|
||||
|
||||
// Quick and dirty convex hull.
|
||||
|
||||
@ -30,9 +31,9 @@
|
||||
inline bool left(const float* a, const float* b, const float* c)
|
||||
{
|
||||
const float u1 = b[0] - a[0];
|
||||
const float v1 = b[2] - a[2];
|
||||
const float v1 = b[1] - a[1];
|
||||
const float u2 = c[0] - a[0];
|
||||
const float v2 = c[2] - a[2];
|
||||
const float v2 = c[1] - a[1];
|
||||
return u1 * v2 - v1 * u2 < 0;
|
||||
}
|
||||
|
||||
@ -41,8 +42,8 @@ inline bool cmppt(const float* a, const float* b)
|
||||
{
|
||||
if (a[0] < b[0]) return true;
|
||||
if (a[0] > b[0]) return false;
|
||||
if (a[2] < b[2]) return true;
|
||||
if (a[2] > b[2]) return false;
|
||||
if (a[1] < b[1]) return true;
|
||||
if (a[1] > b[1]) return false;
|
||||
return false;
|
||||
}
|
||||
// Calculates convex hull on xz-plane of points on 'pts',
|
||||
@ -63,7 +64,7 @@ static int convexhull(const float* pts, int npts, int* out)
|
||||
out[i++] = hull;
|
||||
endpt = 0;
|
||||
for (int j = 1; j < npts; ++j)
|
||||
if (hull == endpt || left(&pts[hull*3], &pts[endpt*3], &pts[j*3]))
|
||||
if (hull == endpt || left(&pts[hull*3], &pts[j*3], &pts[endpt*3]))
|
||||
endpt = j;
|
||||
hull = endpt;
|
||||
}
|
||||
@ -79,8 +80,8 @@ static int pointInPoly(int nvert, const float* verts, const float* p)
|
||||
{
|
||||
const float* vi = &verts[i*3];
|
||||
const float* vj = &verts[j*3];
|
||||
if (((vi[2] > p[2]) != (vj[2] > p[2])) &&
|
||||
(p[0] < (vj[0]-vi[0]) * (p[2]-vi[2]) / (vj[2]-vi[2]) + vi[0]) )
|
||||
if (((vi[1] > p[1]) != (vj[1] > p[1])) &&
|
||||
(p[0] < (vj[0]-vi[0]) * (p[1]-vi[1]) / (vj[1]-vi[1]) + vi[0]) )
|
||||
c = !c;
|
||||
}
|
||||
return c;
|
||||
@ -91,8 +92,8 @@ ConvexVolumeTool::ConvexVolumeTool() :
|
||||
m_sample(0),
|
||||
m_areaType(SAMPLE_POLYAREA_GRASS),
|
||||
m_polyOffset(0.0f),
|
||||
m_boxHeight(6.0f),
|
||||
m_boxDescent(1.0f),
|
||||
m_boxHeight(200.0f),
|
||||
m_boxDescent(150.0f),
|
||||
m_npts(0),
|
||||
m_nhull(0)
|
||||
{
|
||||
@ -111,9 +112,9 @@ void ConvexVolumeTool::reset()
|
||||
|
||||
void ConvexVolumeTool::handleMenu()
|
||||
{
|
||||
imguiSlider("Shape Height", &m_boxHeight, 0.1f, 20.0f, 0.1f);
|
||||
imguiSlider("Shape Descent", &m_boxDescent, 0.1f, 20.0f, 0.1f);
|
||||
imguiSlider("Poly Offset", &m_polyOffset, 0.0f, 10.0f, 0.1f);
|
||||
imguiSlider("Shape Height", &m_boxHeight, 0.1f, 300.0f, 0.1f);
|
||||
imguiSlider("Shape Descent", &m_boxDescent, 0.1f, 300.0f, 0.1f);
|
||||
imguiSlider("Poly Offset", &m_polyOffset, 0.0f, 100.0f, 0.1f);
|
||||
|
||||
imguiSeparator();
|
||||
|
||||
@ -183,7 +184,7 @@ void ConvexVolumeTool::handleClick(const float* /*s*/, const float* p, bool shif
|
||||
|
||||
float minh = FLT_MAX, maxh = 0;
|
||||
for (int i = 0; i < m_nhull; ++i)
|
||||
minh = rcMin(minh, verts[i*3+1]);
|
||||
minh = rcMin(minh, verts[i*3+2]);
|
||||
minh -= m_boxDescent;
|
||||
maxh = minh + m_boxHeight;
|
||||
|
||||
@ -209,6 +210,10 @@ void ConvexVolumeTool::handleClick(const float* /*s*/, const float* p, bool shif
|
||||
if (m_npts < MAX_PTS)
|
||||
{
|
||||
rcVcopy(&m_pts[m_npts*3], p);
|
||||
const float* f = &m_pts[m_npts * 3];
|
||||
|
||||
printf("<%f, %f, %f>\n", f[0], f[1], f[2]);
|
||||
|
||||
m_npts++;
|
||||
// Update hull.
|
||||
if (m_npts > 1)
|
||||
@ -240,7 +245,7 @@ void ConvexVolumeTool::handleRender()
|
||||
// Find height extent of the shape.
|
||||
float minh = FLT_MAX, maxh = 0;
|
||||
for (int i = 0; i < m_npts; ++i)
|
||||
minh = rcMin(minh, m_pts[i*3+1]);
|
||||
minh = rcMin(minh, m_pts[i*3+2]);
|
||||
minh -= m_boxDescent;
|
||||
maxh = minh + m_boxHeight;
|
||||
|
||||
@ -250,7 +255,7 @@ void ConvexVolumeTool::handleRender()
|
||||
unsigned int col = duRGBA(255,255,255,255);
|
||||
if (i == m_npts-1)
|
||||
col = duRGBA(240,32,16,255);
|
||||
dd.vertex(m_pts[i*3+0],m_pts[i*3+1],m_pts[i*3+2] + 0.1f, col);
|
||||
dd.vertex(m_pts[i*3+0],m_pts[i*3+1],m_pts[i*3+2]+0.1f, col);//Needs to be flipped (y = z).
|
||||
}
|
||||
dd.end();
|
||||
|
||||
@ -259,12 +264,12 @@ void ConvexVolumeTool::handleRender()
|
||||
{
|
||||
const float* vi = &m_pts[m_hull[j]*3];
|
||||
const float* vj = &m_pts[m_hull[i]*3];
|
||||
dd.vertex(vj[0], vj[1], minh, duRGBA(255, 255, 255, 64));
|
||||
dd.vertex(vi[0], vi[1], minh, duRGBA(255, 255, 255, 64));
|
||||
dd.vertex(vj[0], vj[1], maxh, duRGBA(255, 255, 255, 64));
|
||||
dd.vertex(vi[0], vi[1], maxh, duRGBA(255, 255, 255, 64));
|
||||
dd.vertex(vj[0], vj[1], minh, duRGBA(255, 255, 255, 64));
|
||||
dd.vertex(vj[0], vj[1], maxh, duRGBA(255,255,255,64));
|
||||
dd.vertex(vj[0],vj[1],minh, duRGBA(255, 255, 255, 64));
|
||||
dd.vertex(vi[0],vi[1],minh, duRGBA(255, 255, 255, 64));
|
||||
dd.vertex(vj[0],vj[1],maxh, duRGBA(255, 255, 255, 64));
|
||||
dd.vertex(vi[0],vi[1],maxh, duRGBA(255, 255, 255, 64));
|
||||
dd.vertex(vj[0],vj[1],minh, duRGBA(255, 255, 255, 64));
|
||||
dd.vertex(vj[0],vj[1],maxh, duRGBA(255,255,255,64));
|
||||
}
|
||||
dd.end();
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "DebugUtils/Include/RecastDebugDraw.h"
|
||||
#include "Detour/Include/DetourNavMesh.h"
|
||||
#include "NavEditor/Include/Sample.h"
|
||||
#include <naveditor/include/GameUtils.h>
|
||||
|
||||
static bool intersectSegmentTriangle(const float* sp, const float* sq,
|
||||
const float* a, const float* b, const float* c,
|
||||
@ -598,17 +599,15 @@ void InputGeom::drawConvexVolumes(struct duDebugDraw* dd, bool /*hilight*/)
|
||||
const float* va = &vol->verts[k*3];
|
||||
const float* vb = &vol->verts[j*3];
|
||||
|
||||
dd->vertex(vol->verts[0],vol->hmax,vol->verts[2], col);
|
||||
dd->vertex(vb[0],vol->hmax,vb[2], col);
|
||||
dd->vertex(va[0],vol->hmax,va[2], col);
|
||||
|
||||
dd->vertex(va[0],vol->hmin,va[2], duDarkenCol(col));
|
||||
dd->vertex(va[0],vol->hmax,va[2], col);
|
||||
dd->vertex(vb[0],vol->hmax,vb[2], col);
|
||||
|
||||
dd->vertex(va[0],vol->hmin,va[2], duDarkenCol(col));
|
||||
dd->vertex(vb[0],vol->hmax,vb[2], col);
|
||||
dd->vertex(vb[0],vol->hmin,vb[2], duDarkenCol(col));
|
||||
dd->vertex(vol->verts[0],vol->verts[1],vol->hmax, col);
|
||||
dd->vertex(vb[0],vb[1],vol->hmax, col);
|
||||
dd->vertex(va[0],va[1],vol->hmax, col);
|
||||
dd->vertex(va[0],va[1],vol->hmin, duDarkenCol(col));
|
||||
dd->vertex(va[0],va[1],vol->hmax, col);
|
||||
dd->vertex(vb[0],vb[1],vol->hmax, col);
|
||||
dd->vertex(va[0],va[1],vol->hmin, duDarkenCol(col));
|
||||
dd->vertex(vb[0],vb[1],vol->hmax, col);
|
||||
dd->vertex(vb[0],vb[1],vol->hmin, duDarkenCol(col));
|
||||
}
|
||||
}
|
||||
|
||||
@ -623,12 +622,12 @@ void InputGeom::drawConvexVolumes(struct duDebugDraw* dd, bool /*hilight*/)
|
||||
{
|
||||
const float* va = &vol->verts[k*3];
|
||||
const float* vb = &vol->verts[j*3];
|
||||
dd->vertex(va[0],vol->hmin,va[2], duDarkenCol(col));
|
||||
dd->vertex(vb[0],vol->hmin,vb[2], duDarkenCol(col));
|
||||
dd->vertex(va[0],vol->hmax,va[2], col);
|
||||
dd->vertex(vb[0],vol->hmax,vb[2], col);
|
||||
dd->vertex(va[0],vol->hmin,va[2], duDarkenCol(col));
|
||||
dd->vertex(va[0],vol->hmax,va[2], col);
|
||||
dd->vertex(va[0],va[1],vol->hmin, duDarkenCol(col));
|
||||
dd->vertex(vb[0],vb[1],vol->hmin, duDarkenCol(col));
|
||||
dd->vertex(va[0],va[1],vol->hmax, col);
|
||||
dd->vertex(vb[0],vb[1],vol->hmax, col);
|
||||
dd->vertex(va[0],va[1],vol->hmin, duDarkenCol(col));
|
||||
dd->vertex(va[0],va[1],vol->hmax, col);
|
||||
}
|
||||
}
|
||||
dd->end();
|
||||
@ -641,8 +640,8 @@ void InputGeom::drawConvexVolumes(struct duDebugDraw* dd, bool /*hilight*/)
|
||||
for (int j = 0; j < vol->nverts; ++j)
|
||||
{
|
||||
dd->vertex(vol->verts[j*3+0],vol->verts[j*3+1]+0.1f,vol->verts[j*3+2], col);
|
||||
dd->vertex(vol->verts[j*3+0],vol->hmin,vol->verts[j*3+2], col);
|
||||
dd->vertex(vol->verts[j*3+0],vol->hmax,vol->verts[j*3+2], col);
|
||||
dd->vertex(vol->verts[j*3+0],vol->verts[j*3+1],vol->hmin, col);
|
||||
dd->vertex(vol->verts[j*3+0],vol->verts[j*3+1],vol->hmax, col);
|
||||
}
|
||||
}
|
||||
dd->end();
|
||||
|
@ -727,6 +727,13 @@ inline void rcVcopy(float* dest, const float* v)
|
||||
dest[2] = v[2];
|
||||
}
|
||||
|
||||
inline void rcVswap(float* dest, const float* v)
|
||||
{
|
||||
dest[0] = v[0];
|
||||
dest[2] = v[1];
|
||||
dest[1] = v[2];
|
||||
}
|
||||
|
||||
/// Returns the distance between two points.
|
||||
/// @param[in] v1 A point. [(x, y, z)]
|
||||
/// @param[in] v2 A point. [(x, y, z)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user