|
|
|
@ -87,27 +87,34 @@ static void Draw3D_VerticalPolygonalCylinder( const SHAPE_POLY_SET& aPolysList, |
|
|
|
coords[3].z = coords[0].z; |
|
|
|
|
|
|
|
// Draw the vertical polygonal side
|
|
|
|
for( int ii = 0; ii < aPolysList.OutlineCount(); ii++ ) |
|
|
|
for( int idx = 0; idx < aPolysList.OutlineCount(); idx++ ) |
|
|
|
{ |
|
|
|
const SHAPE_LINE_CHAIN& path = aPolysList.COutline( ii ); |
|
|
|
// Each polygon in aPolysList is a polygon with holes
|
|
|
|
const SHAPE_POLY_SET::POLYGON& curr_polywithholes = aPolysList.CPolygon( idx ); |
|
|
|
|
|
|
|
for( int jj = 0; jj < path.PointCount(); jj++ ) |
|
|
|
// Draw the outline of each simple polygon inside the polygon with holes:
|
|
|
|
for( unsigned ipoly = 0; ipoly < curr_polywithholes.size(); ipoly++ ) |
|
|
|
{ |
|
|
|
const VECTOR2I& a = path.CPoint( jj ); |
|
|
|
const VECTOR2I& b = path.CPoint( jj + 1 ); |
|
|
|
|
|
|
|
// Build the 4 vertices of each GL_QUAD
|
|
|
|
coords[0].x = a.x; |
|
|
|
coords[0].y = -a.y; |
|
|
|
coords[1].x = coords[0].x; |
|
|
|
coords[1].y = coords[0].y; // only z change
|
|
|
|
coords[2].x = b.x; |
|
|
|
coords[2].y = -b.y; |
|
|
|
coords[3].x = coords[2].x; |
|
|
|
coords[3].y = coords[2].y; // only z change
|
|
|
|
|
|
|
|
// Creates the GL_QUAD
|
|
|
|
TransfertToGLlist( coords, aBiuTo3DUnits ); |
|
|
|
const SHAPE_LINE_CHAIN& path = curr_polywithholes[ipoly]; // a simple polygon
|
|
|
|
|
|
|
|
for( int jj = 0; jj < path.PointCount(); jj++ ) |
|
|
|
{ |
|
|
|
const VECTOR2I& a = path.CPoint( jj ); |
|
|
|
const VECTOR2I& b = path.CPoint( jj + 1 ); |
|
|
|
|
|
|
|
// Build the 4 vertices of each GL_QUAD
|
|
|
|
coords[0].x = a.x; |
|
|
|
coords[0].y = -a.y; |
|
|
|
coords[1].x = coords[0].x; |
|
|
|
coords[1].y = coords[0].y; // only z change
|
|
|
|
coords[2].x = b.x; |
|
|
|
coords[2].y = -b.y; |
|
|
|
coords[3].x = coords[2].x; |
|
|
|
coords[3].y = coords[2].y; // only z change
|
|
|
|
|
|
|
|
// Creates the GL_QUAD
|
|
|
|
TransfertToGLlist( coords, aBiuTo3DUnits ); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -169,46 +176,47 @@ void Draw3D_SolidHorizontalPolyPolygons( const SHAPE_POLY_SET& aPolysList, |
|
|
|
|
|
|
|
// Set normal toward positive Z axis, for a solid object on the top side
|
|
|
|
|
|
|
|
//gluTessProperty( tess, GLU_TESS_BOUNDARY_ONLY, GL_TRUE );
|
|
|
|
//gluTessProperty( tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD );
|
|
|
|
//gluTessProperty( tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE );
|
|
|
|
gluTessProperty( tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD ); |
|
|
|
|
|
|
|
glNormal3f( 0.0, 0.0, aNormal_Z_Orientation ); |
|
|
|
|
|
|
|
// Draw solid areas contained in this list
|
|
|
|
SHAPE_POLY_SET polylist = aPolysList; // temporary copy for gluTessVertex
|
|
|
|
|
|
|
|
int startContour; |
|
|
|
|
|
|
|
for( int side = 0; side < 2; side++ ) |
|
|
|
{ |
|
|
|
startContour = 1; |
|
|
|
|
|
|
|
for ( SHAPE_POLY_SET::ITERATOR ii = polylist.Iterate(); ii; ++ii ) |
|
|
|
for ( int idx = 0; idx < polylist.OutlineCount(); ++idx ) |
|
|
|
{ |
|
|
|
if( startContour == 1 ) |
|
|
|
gluTessBeginPolygon( tess, NULL ); |
|
|
|
|
|
|
|
SHAPE_POLY_SET::POLYGON& curr_polywithholes = polylist.Polygon( idx ); // a polygon with holes
|
|
|
|
|
|
|
|
for( unsigned ipoly = 0; ipoly < curr_polywithholes.size(); ipoly++ ) |
|
|
|
{ |
|
|
|
gluTessBeginPolygon( tess, NULL ); |
|
|
|
gluTessBeginContour( tess ); |
|
|
|
startContour = 0; |
|
|
|
} |
|
|
|
SHAPE_LINE_CHAIN& curr_poly = curr_polywithholes[ipoly]; // a simple polygon
|
|
|
|
|
|
|
|
v_data[0] = ii->x * aBiuTo3DUnits; |
|
|
|
v_data[1] = -ii->y * aBiuTo3DUnits; |
|
|
|
// gluTessVertex store pointers on data, not data, so do not store
|
|
|
|
// different corners values in a temporary variable
|
|
|
|
// but send pointer on each CPolyPt value in polylist
|
|
|
|
// before calling gluDeleteTess
|
|
|
|
gluTessVertex( tess, v_data, &ii.Get() ); |
|
|
|
gluTessBeginContour( tess ); |
|
|
|
|
|
|
|
for( int ipt = 0; ipt < curr_poly.PointCount(); ipt++ ) |
|
|
|
{ |
|
|
|
v_data[0] = curr_poly.Point( ipt ).x * aBiuTo3DUnits; |
|
|
|
v_data[1] = -curr_poly.Point( ipt ).y * aBiuTo3DUnits; |
|
|
|
// gluTessVertex store pointers on data, not data, so do not store
|
|
|
|
// different corners values in a temporary variable
|
|
|
|
// but send pointer on each CPolyPt value in polylist
|
|
|
|
// before calling gluDeleteTess
|
|
|
|
gluTessVertex( tess, v_data, &curr_poly.Point( ipt ) ); |
|
|
|
} |
|
|
|
|
|
|
|
if( ii.IsEndContour() ) |
|
|
|
{ |
|
|
|
gluTessEndContour( tess ); |
|
|
|
gluTessEndPolygon( tess ); |
|
|
|
startContour = 1; |
|
|
|
} |
|
|
|
|
|
|
|
gluTessEndPolygon( tess ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if( aThickness == 0 ) |
|
|
|
break; |
|
|
|
|
|
|
|
@ -220,12 +228,6 @@ void Draw3D_SolidHorizontalPolyPolygons( const SHAPE_POLY_SET& aPolysList, |
|
|
|
glNormal3f( 0.0, 0.0, -aNormal_Z_Orientation ); |
|
|
|
} |
|
|
|
|
|
|
|
if( startContour == 0 ) |
|
|
|
{ |
|
|
|
gluTessEndContour( tess ); |
|
|
|
gluTessEndPolygon( tess ); |
|
|
|
} |
|
|
|
|
|
|
|
gluDeleteTess( tess ); |
|
|
|
|
|
|
|
if( aThickness == 0 ) |
|
|
|
@ -237,24 +239,6 @@ void Draw3D_SolidHorizontalPolyPolygons( const SHAPE_POLY_SET& aPolysList, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* draw the solid polygon found in aPolysList
|
|
|
|
* The first polygon is the main polygon, others are holes |
|
|
|
* See Draw3D_SolidHorizontalPolyPolygons for more info |
|
|
|
*/ |
|
|
|
void Draw3D_SolidHorizontalPolygonWithHoles( const SHAPE_POLY_SET& aPolysList, |
|
|
|
int aZpos, int aThickness, |
|
|
|
double aBiuTo3DUnits, bool aUseTextures, |
|
|
|
float aNormal_Z_Orientation ) |
|
|
|
{ |
|
|
|
SHAPE_POLY_SET polygon( aPolysList ); |
|
|
|
|
|
|
|
polygon.Fracture(); |
|
|
|
|
|
|
|
Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, aThickness, aBiuTo3DUnits, aUseTextures, |
|
|
|
aNormal_Z_Orientation ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* draw a cylinder (a tube) using 3D primitives.
|
|
|
|
* the cylinder axis is parallel to the Z axis |
|
|
|
* If aHeight = height of the cylinder is 0, only one ring will be drawn |
|
|
|
@ -274,6 +258,7 @@ void Draw3D_ZaxisCylinder( wxPoint aCenterPos, int aRadius, |
|
|
|
coords.resize( 4 ); |
|
|
|
|
|
|
|
SHAPE_POLY_SET inner_cornerBuffer; |
|
|
|
|
|
|
|
if( aThickness ) // build the the vertical inner polygon (hole)
|
|
|
|
TransformCircleToPolygon( inner_cornerBuffer, aCenterPos, |
|
|
|
aRadius - (aThickness / 2), slice ); |
|
|
|
@ -283,31 +268,28 @@ void Draw3D_ZaxisCylinder( wxPoint aCenterPos, int aRadius, |
|
|
|
|
|
|
|
// Draw the vertical outer side
|
|
|
|
Draw3D_VerticalPolygonalCylinder( outer_cornerBuffer, |
|
|
|
aHeight, aZpos, false, aBiuTo3DUnits ); |
|
|
|
aHeight, aZpos, false, aBiuTo3DUnits ); |
|
|
|
|
|
|
|
if( aThickness ) |
|
|
|
// Draws the vertical inner side (hole)
|
|
|
|
Draw3D_VerticalPolygonalCylinder( inner_cornerBuffer, |
|
|
|
aHeight, aZpos, true, aBiuTo3DUnits ); |
|
|
|
aHeight, aZpos, true, aBiuTo3DUnits ); |
|
|
|
} |
|
|
|
|
|
|
|
if( aThickness ) |
|
|
|
{ |
|
|
|
// draw top (front) and bottom (back) horizontal sides (rings)
|
|
|
|
outer_cornerBuffer.AddHole( inner_cornerBuffer.COutline( 0 ) ); |
|
|
|
SHAPE_POLY_SET polygon = outer_cornerBuffer; |
|
|
|
|
|
|
|
polygon.Fracture(); |
|
|
|
|
|
|
|
// draw top (front) horizontal ring
|
|
|
|
Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos + aHeight, 0, aBiuTo3DUnits, false, |
|
|
|
1.0f ); |
|
|
|
Draw3D_SolidHorizontalPolyPolygons( outer_cornerBuffer, aZpos + aHeight, |
|
|
|
0, aBiuTo3DUnits, false, 1.0f ); |
|
|
|
|
|
|
|
if( aHeight ) |
|
|
|
{ |
|
|
|
// draw bottom (back) horizontal ring
|
|
|
|
Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, 0, aBiuTo3DUnits, false, |
|
|
|
-1.0f ); |
|
|
|
Draw3D_SolidHorizontalPolyPolygons( outer_cornerBuffer, aZpos, |
|
|
|
0, aBiuTo3DUnits, false, -1.0f ); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -327,15 +309,15 @@ void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos, |
|
|
|
const int slice = SEGM_PER_CIRCLE; |
|
|
|
|
|
|
|
// Build the points to approximate oblong cylinder by segments
|
|
|
|
SHAPE_POLY_SET outer_cornerBuffer; |
|
|
|
SHAPE_POLY_SET cornerBuffer; |
|
|
|
|
|
|
|
int segm_width = (aRadius * 2) + aThickness; |
|
|
|
TransformRoundedEndsSegmentToPolygon( outer_cornerBuffer, aAxis1Pos, |
|
|
|
TransformRoundedEndsSegmentToPolygon( cornerBuffer, aAxis1Pos, |
|
|
|
aAxis2Pos, slice, segm_width ); |
|
|
|
|
|
|
|
// Draw the oblong outer cylinder
|
|
|
|
if( aHeight ) |
|
|
|
Draw3D_VerticalPolygonalCylinder( outer_cornerBuffer, aHeight, aZpos, |
|
|
|
Draw3D_VerticalPolygonalCylinder( cornerBuffer, aHeight, aZpos, |
|
|
|
false, aBiuTo3DUnits ); |
|
|
|
|
|
|
|
if( aThickness ) |
|
|
|
@ -352,19 +334,16 @@ void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos, |
|
|
|
|
|
|
|
// Build the horizontal full polygon shape
|
|
|
|
// (outer polygon shape - inner polygon shape)
|
|
|
|
outer_cornerBuffer.AddHole( inner_cornerBuffer.COutline( 0 ) ); |
|
|
|
|
|
|
|
SHAPE_POLY_SET polygon( outer_cornerBuffer ); |
|
|
|
polygon.Fracture(); |
|
|
|
cornerBuffer.AddHole( inner_cornerBuffer.COutline( 0 ) ); |
|
|
|
|
|
|
|
// draw top (front) horizontal side (ring)
|
|
|
|
Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos + aHeight, 0, aBiuTo3DUnits, false, |
|
|
|
Draw3D_SolidHorizontalPolyPolygons( cornerBuffer, aZpos + aHeight, 0, aBiuTo3DUnits, false, |
|
|
|
1.0f ); |
|
|
|
|
|
|
|
if( aHeight ) |
|
|
|
{ |
|
|
|
// draw bottom (back) horizontal side (ring)
|
|
|
|
Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, 0, aBiuTo3DUnits, false, |
|
|
|
Draw3D_SolidHorizontalPolyPolygons( cornerBuffer, aZpos, 0, aBiuTo3DUnits, false, |
|
|
|
-1.0f ); |
|
|
|
} |
|
|
|
} |
|
|
|
|