THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/11/2009 at 08:32, xxxxxxxx wrote:
This is generally known as camera(or view)-dependent backface culling.
First thing you need is to calculate the normal vector for the polygon (there is a function to do this: CalcFaceNormal()). Then get the camera's location. In general, something like this:
// Polygon and Vertex array pointers
CPolygon* padr = pobj->GetPolygonW();
Vector* vadr = pobj->GetPointW();
if (!(padr && vadr)) return FALSE;
// Camera (global-space) location
BaseDraw* bd = doc->GetActiveBaseDraw();
BaseObject* cam = bd->GetSceneCamera(doc);
if (!cam) cam = bd->GetEditorCamera();
Vector E = cam->GetMg().off;
// incidentals
Matrix mg = pobj->GetMg();
LONG pcnt = pobj->GetPolygonCount();
CPolygon* p;
Vector N, V;
Real dir;
for (LONG i = 0L; i != pcnt; ++i)
{
// Some polygon
p = padr[i];
// Normal vector of polygon
N = CalcFaceNormal(vadr, p)*mg;
V = vadr[p->a]*mg;
// Determination of polygon facing wrt camera
dir = N*(E-V);
if (dir <= 0.0f) // backfacing: cull polygon
}
If you need to consider only what is in the direction of the camera view, you will need to build a direction vector and a bit more calculation.