swordlegend / recastnavigation

Automatically exported from code.google.com/p/recastnavigation
zlib License
0 stars 0 forks source link

Generalized DebugDraw Interface #7

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Simple generalized immediate mode debug draw interface for Recast/Detour
debug draw functions.

Original issue reported on code.google.com by memono...@gmail.com on 26 Aug 2009 at 12:13

GoogleCodeExporter commented 9 years ago
fwiw, I did this in my local copy:

It requires the draw functions to put things in the structs, which may be seen 
as
extra work(versus passing float * and such like some of the existing recast
functions), but it makes it easier on the implementation side of the render 
interface
to batch things up by just having big arrays of Triangles, Lines, Points, etc.

class RenderInterface
{
public:
    struct Color
    {
        unsigned char r,g,b,a;
        Color(unsigned char _r = 0,unsigned char _g = 0,unsigned char _b = 0,unsigned char
_a = 255)
            : r(_r), g(_g), b(_b), a(_a)
        {
        }
    };
    struct Point
    {
        float x,y,z;
        Point() {}
        Point(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
    };
    struct Triangle
    {
        Point vert[3];
    };
    struct Line
    {
        Point vert[2];
    };

    virtual void DrawTriangles(const Triangle *tris, int numTris, const Color& col) = 0;
    virtual void DrawLines(const Line *lines, int numLines, const Color& col) = 0;
    virtual void DrawPoints(const Point *points, int numPoints, const Color& col) = 0;
    virtual void DrawLineWidth(float width) = 0;
    virtual void DrawPointSize(float width) = 0;

    virtual ~RenderInterface() {}
};

Original comment by jswig...@gmail.com on 27 Aug 2009 at 2:09

GoogleCodeExporter commented 9 years ago
I don't think that's such a good idea, actually.
An abstract class: yes.
Renderinterface: no.
I found it very easy to convert the existing debug renderer to Ogre, thanks to 
it
being in immediate mode.
This code:

    glBegin(GL_TRIANGLES);
    for (int i = 0; i < ntris*3; i += 3)
    {
        float a = (2+normals[i+0]+normals[i+1])/4;
        if (flags && !flags[i/3])
            glColor3f(a,a*0.3f,a*0.1f);
        else
            glColor3f(a,a,a);
        glVertex3fv(&verts[tris[i]*3]);
        glVertex3fv(&verts[tris[i+1]*3]);
        glVertex3fv(&verts[tris[i+2]*3]);
    }
    glEnd();

Is extremely easy to port to this:

    manualObject->begin(triangle_material, RenderOperation::OT_TRIANGLE_LIST);
    for (int i = 0; i < ntris*3; i += 3)
    {
        float a = (2+normals[i+0]+normals[i+1])/4;
        if (flags && !flags[i/3])
            manualObject->colour(a,a*0.3f,a*0.1f);
        else
            manualObject->colour(a,a,a);
        manualObject->position(&verts[tris[i]*3]);
        manualObject->position(&verts[tris[i+1]*3]);
        manualObject->position(&verts[tris[i+2]*3]);
    }
    manualObject->end();

So, just an abstract class, with the same interface as the existing - please. :)

Original comment by jacmoe...@gmail.com on 12 Sep 2009 at 1:54

GoogleCodeExporter commented 9 years ago
Yea, I have since changed the 'render interface' to mimic opengl calls, and also
added caching support so that opengl can create a display list for performance, 
and
potentiallly other implementations can do similar caching.

Original comment by jswig...@gmail.com on 16 Sep 2009 at 7:36

GoogleCodeExporter commented 9 years ago
I added simple debug draw interface:

// Abstrace debug draw interface.
struct rcDebugDraw
{
    // Begin drawing primitives.
    // Params:
    //  prim - (in) primitive type to draw, one of rcDebugDrawPrimitives.
    //  nverts - (in) number of vertices to be submitted.
    //  size - (in) size of a primitive, applies to point size and line width only.
    virtual void begin(rcDebugDrawPrimitives prim, int nverts, float size = 1.0f) = 0;

    // Submit a vertex
    // Params:
    //  pos - (in) position of the verts.
    //  color - (in) color of the verts.
    virtual void vertex(const float* pos, unsigned int color) = 0;

    // Submit a vertex
    // Params:
    //  x,y,z - (in) position of the verts.
    //  color - (in) color of the verts.
    virtual void vertex(const float x, const float y, const float z, unsigned int color)
= 0;

    // End drawing primitives.
    virtual void end() = 0;
};

That second vertex method was just for making things a bit easier for myself.
Currently only Recast debug draw uses this. I will see how to combine the 
debugdraw
facilities of the two projects.

Original comment by memono...@gmail.com on 15 Nov 2009 at 3:41

GoogleCodeExporter commented 9 years ago
Is there a reason to pass the number of verts to the begin method? It may be 
simple
to provide that in recast, but as I update the detour interface to use the same 
debug
draw interface it becomes clear that without doing additional passes to count
vertices before a 2nd pass performs the draw call, it's a pain to have to pass 
the
vertices to begin, and since it doesn't appear to be used, IMO it should be 
removed.
Thoughts?

Original comment by jswig...@gmail.com on 6 Dec 2009 at 12:55

GoogleCodeExporter commented 9 years ago
One project I work on requires to pass a number of verts when creating a temp 
vertex
buffer. On a hindsight, I think that vertex number is not necessary. I'll 
remove it,
and I think I'll move the debug draw functions out to a separate folder where 
they
can share more code.

Original comment by memono...@gmail.com on 6 Dec 2009 at 8:24

GoogleCodeExporter commented 9 years ago
excellent

Original comment by jswig...@gmail.com on 6 Dec 2009 at 5:16

GoogleCodeExporter commented 9 years ago
Changed now in version R85.

I moved all the debug draw code out of the Recast and Debug folders, they now 
lie in
DebugUtils folder and share the same debugdraw interface. I also removed the 
vertex
count from the begin() method.

There is also method to dump meshes as .obj files. I hope to add a way to save 
every
intermediate state data one day.

Let me know if there are ay problems with the new stuff.

Original comment by memono...@gmail.com on 9 Dec 2009 at 3:50

GoogleCodeExporter commented 9 years ago

Original comment by memono...@gmail.com on 9 Dec 2009 at 3:50