//////////////////////////////////////
// START of File: CO1_PGON.CPP
//////////////////////////////////////

//===================================================================
//
// COPYRIGHT NOTICE:  This code is protected by Copyright!
//
// Copyright (c) 1994, 1995, 1996, 1997 by DPC Technology.
// All rights reserved. 
//
// See files "cf_copyr.h" and "cf_licen.h" for details of 
// copyright and license specifications, and contact information.
//
//===================================================================

//
// Include this source file's header file:
//
#include	<cf_api/bf_defs.h>
#include    <cf_api/co1_pgon.hpp> 
            // relative to the IDE's (global) include path: ~/cfrz

cf_3DPolygon
    ::cf_3DPolygon()
        : cf_3DPointSeries()    // Default c-tor 
            {}

// Std c-tor lets user assign display attribs
cf_3DPolygon
    ::cf_3DPolygon( cf_DispAttribs *p_attrToDrawWith )
        : cf_3DPointSeries( p_attrToDrawWith )  // Param-ed c-tor 
            {}


// Virtual d-tor:
cf_3DPolygon
    ::~cf_3DPolygon() 
        {}


void
    cf_3DPolygon
        ::drawBorder( bf_Display *p_bf_dspOutputDisplay ) 
{
    // Construct the projected polygon borders:
    cf_2DPoint *a_cf_2dpDrawArray 
                = new cf_2DPoint[ this->iNumPoints + 1 ];

    for ( int i = 0; i < this->iNumPoints; i++ )
        a_cf_2dpDrawArray[ i ] 
            = ((cf_3DPoint*) da_p_cf_3dpVertices[ i + 1 ] )->screenPoint();
    a_cf_2dpDrawArray[ this->iNumPoints ] = a_cf_2dpDrawArray[ 0 ];
                    // Connect the last point to the first point:
                            
    // Render the line:
    this->dispPushPenAttribs( p_bf_dspOutputDisplay );
    p_bf_dspOutputDisplay
            ->dsp_polyline( a_cf_2dpDrawArray, this->iNumPoints + 1 );
    this->dispPopPenAttribs( p_bf_dspOutputDisplay );
    
    // Clean up:
    delete [] a_cf_2dpDrawArray;

    return;

}


void
    cf_3DPolygon
        ::draw2D( bf_Display *p_bf_dspOutputDisplay )
{
    int i;  // Std ICV.
                        
    // Construct the projected polygon borders:
    cf_2DPoint *a_cf_2dpDrawArray 
                = new cf_2DPoint[ this->iNumPoints ];
                            
    for ( i = 0; i < this->iNumPoints; i++ )
        a_cf_2dpDrawArray[i] 
            = ( (cf_3DPoint*) da_p_cf_3dpVertices[i + 1] )->screenPoint();
                            
    // Render the polygon:
    this->dispPushPenAttribs( p_bf_dspOutputDisplay );
    this->dispPushBrushAttribs( p_bf_dspOutputDisplay );
    p_bf_dspOutputDisplay
            ->dsp_polygon( a_cf_2dpDrawArray, this->iNumPoints );
    this->dispPopBrushAttribs( p_bf_dspOutputDisplay );
    this->dispPopPenAttribs( p_bf_dspOutputDisplay );
    
    // Clean up:
    delete [] a_cf_2dpDrawArray;
    return;
}


void
    cf_3DPolygon
        ::draw3D( bf_Display *p_bf_dspOutputDisplay ) 
{
    // Construct the projected polygon borders:
    cf_2DPoint *a_cf_2dpDrawArray 
                = new cf_2DPoint[ this->iNumPoints ];
                            
    for ( int i = 0; i < this->iNumPoints; i++ )
        a_cf_2dpDrawArray[ i ] 
            = ( (cf_3DPoint*) da_p_cf_3dpVertices[i + 1] )->screenPoint();
                            
    // Render the polygon:
    this->dispPushPenAttribs( p_bf_dspOutputDisplay );
    this->dispPushBrushAttribs( p_bf_dspOutputDisplay );
    p_bf_dspOutputDisplay
            ->dsp_polygon( a_cf_2dpDrawArray, this->iNumPoints );
    this->dispPopBrushAttribs( p_bf_dspOutputDisplay );
    this->dispPopPenAttribs( p_bf_dspOutputDisplay );

    // Clean up:
    delete [] a_cf_2dpDrawArray;
    return;
}


//
// END of cf_3DPolygon implementation.
//

//////////////////////////////////////
// END of File: CO1_PGON.CPP
//////////////////////////////////////
