eng_graph_draw.cc File Reference

Visitor that renders a Graph. More...

#include "base.hh"
#include "gfx.hh"
#include "eng.hh"
#include "eng_graph.hh"
#include "eng_graph_draw.hh"
#include "eng_graph_debug.hh"

Namespaces

namespace  eng

Defines

#define ENG_GRAPH_DRAW_CC   1
#define SEND_VERTEX(I)
#define SEND_COLOR_VERTEX(I)
#define SEND_NORMAL_VERTEX(I)
#define SEND_COLOR_NORMAL_VERTEX(I)
#define SEND_TEXCOORD_VERTEX(I)
#define SEND_TEXCOORD_COLOR_VERTEX(I)
#define SEND_TEXCOORD_NORMAL_VERTEX(I)
#define SEND_TEXCOORD_COLOR_NORMAL_VERTEX(I)
#define DEBUG_DRAW_NORMAL_VECTOR
#define COMPUTE_DOT_PRODUCT_RETURN_IF_NOT_FACING
#define CODE_BEGIN_POLYGON_NODE
#define CODE_BEGIN_POLYGON_NODE_TEX

Variables

static fp eng::sDrawNormalScale = WORLD( 250.0 )
static EyeVertex eng::sEyeNormal
static GFX::ePolygonMode eng::sPolygonMode = GFX::ePolygonMode_DEFAULT


Detailed Description

Visitor that renders a Graph.

Id
LastChangedDate

Author:
Jim E. Brooks http://www.palomino3d.org
Problems: --------- To properly draw translucent polygons that exist in multiple partitions, a special sub-Visitor would be needed, since the scope of node sorting is within a Partition.

Preconditions: -------------- EndDrawing() must be called by a non-polygon Visit() method that uses GFX to exit polyon-drawing mode first.

Constant normal vectors: ------------------------ A few special-case Objects have "constant normals". A reason is that they lack enough polygons for averaging normals and therefore specially pre-computed.

Object culling: --------------- This code doesn't cull Objects. Rather, the BSP code culls BSP Nodes which contain Objects. So when VisitorDraw is constructed, the Object was pre-determined to be visible.

LEGAL: COPYRIGHT (C) 2007 JIM E. BROOKS THIS SOURCE CODE IS RELEASED UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).


Define Documentation

#define CODE_BEGIN_POLYGON_NODE

Value:

\
    const PolygonNode::Vixs& vixs = node.GetVixs();                             \
    const Nix nix = node.GetNix();                                              \
    COMPUTE_DOT_PRODUCT_RETURN_IF_NOT_FACING;
Common code at start of a polygon.

#define CODE_BEGIN_POLYGON_NODE_TEX

Value:

CODE_BEGIN_POLYGON_NODE;  /* based on untextured macro */               \
    const PolygonNode_Tex::TexCoords& texCoords = node.GetTexCoords();      \

#define COMPUTE_DOT_PRODUCT_RETURN_IF_NOT_FACING

Value:

{                                                                                       \
    /* Translate normal vector from Normal Space to Local Space. */                     \
    LocalVertex localNormal( (*mLocalVertexs)[vixs[0]].x + (*mPolygonNormals)[nix].x,   \
                             (*mLocalVertexs)[vixs[0]].y + (*mPolygonNormals)[nix].y,   \
                             (*mLocalVertexs)[vixs[0]].z + (*mPolygonNormals)[nix].z ); \
                                                                                        \
    /* Transform normal vector from Local Space to Eye Space. */                        \
    /* sEyeNormal can be used for drawing normal vectors (for debug) */                 \
    sEyeNormal = mMatrixEye.RotateTranslate<EyeVertex,LocalVertex>( localNormal );      \
                                                                                        \
    /* Translate normal vector so that the first vertex of polygon is the origin. */    \
    EyeVertex eyeNormal2( sEyeNormal.x - mEyeVertexs[vixs[0]].x,                        \
                          sEyeNormal.y - mEyeVertexs[vixs[0]].y,                        \
                          sEyeNormal.z - mEyeVertexs[vixs[0]].z );                      \
                                                                                        \
    /* Compute dot product of transformed normal vector and Eye */                      \
    /* relative to the first vertex (origin of normal vector). */                       \
    /* Use extended-precision float to increase accuracy. */                            \
    /* Note: Increasing World Space too much will erode float accuracy */               \
    /* and one symptom is flashing polygons after DotProduct loses precision. */        \
    /* tweak: Instead of -mEyeVertexs[vixs[0]], reversed relational operator. */        \
    if ( DotProduct3_fpx( eyeNormal2, mEyeVertexs[vixs[0]] ) > 0.0 )                    \
        return;                                                                         \
}
Polygon culling using dot product.

The origin of the normal vector, which is the first vertex of the polygon, has been transformed into Eye Space. Therefore, the polygon's normal vector is translated from Normal Space to Local Space, then it is transformed into Eye Space.

#define DEBUG_DRAW_NORMAL_VECTOR

To debug normal vector bugs, if enabled, draw the normal vector itself.

#define ENG_GRAPH_DRAW_CC   1

#define SEND_COLOR_NORMAL_VERTEX (  ) 

Value:

{                                                               \
    GFX::Color(                 mColors[I]  );                  \
    GFX::Normal( (*mVertexNormals)[vixs[I]] );                  \
    GFX::Vertex(       mEyeVertexs[vixs[I]] );                  \
}
Macro: Send color, normal, vertex.

#define SEND_COLOR_VERTEX (  ) 

Value:

{                                                               \
    GFX::Color(           mColors[I]  );                        \
    GFX::Vertex( mEyeVertexs[vixs[I]] );                        \
}
Macro: Send color, vertex.

#define SEND_NORMAL_VERTEX (  ) 

Value:

{                                                               \
    GFX::Normal( (*mVertexNormals)[vixs[I]] );                  \
    GFX::Vertex(       mEyeVertexs[vixs[I]] );                  \
}
Macro: Send normal, vertex.

#define SEND_TEXCOORD_COLOR_NORMAL_VERTEX (  ) 

Value:

{                                                               \
    Texture::Map(             texCoords[I]  );                  \
    GFX::Color(                 mColors[I]  );                  \
    GFX::Normal( (*mVertexNormals)[vixs[I]] );                  \
    GFX::Vertex(       mEyeVertexs[vixs[I]] );                  \
}
Macro: Send texcoord, color, normal, vertex.

#define SEND_TEXCOORD_COLOR_VERTEX (  ) 

Value:

{                                                               \
    Texture::Map(       texCoords[I]  );                        \
    GFX::Color(           mColors[I]  );                        \
    GFX::Vertex( mEyeVertexs[vixs[I]] );                        \
}
Macro: Send texcoord, color, vertex.

#define SEND_TEXCOORD_NORMAL_VERTEX (  ) 

Value:

{                                                               \
    Texture::Map(             texCoords[I]  );                  \
    GFX::Normal( (*mVertexNormals)[vixs[I]] );                  \
    GFX::Vertex(       mEyeVertexs[vixs[I]] );                  \
}
Macro: Send texcoord, normal, vertex.

#define SEND_TEXCOORD_VERTEX (  ) 

Value:

{                                                               \
    Texture::Map(       texCoords[I]  );                        \
    GFX::Vertex( mEyeVertexs[vixs[I]] );                        \
}
Macro: Send texcoord, color, vertex.

#define SEND_VERTEX (  ) 

Value:

{                                                               \
    GFX::Vertex( mEyeVertexs[vixs[I]] );                        \
}
Macro: Send color, vertex.

Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:14 2007