2012-08-26 13:59:55 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file 3d_draw_basic_functions.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
|
|
|
|
|
|
|
#include <3d_viewer.h>
|
|
|
|
#include <info3d_visu.h>
|
|
|
|
#include <3d_draw_basic_functions.h>
|
2014-07-30 09:01:25 +00:00
|
|
|
#include <modelparsers.h>
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2012-08-26 18:10:28 +00:00
|
|
|
// Number of segments to approximate a circle by segments
|
2015-03-28 11:33:56 +00:00
|
|
|
#define SEGM_PER_CIRCLE 24
|
2012-08-26 13:59:55 +00:00
|
|
|
|
|
|
|
#ifndef CALLBACK
|
|
|
|
#define CALLBACK
|
|
|
|
#endif
|
|
|
|
|
2014-08-22 10:24:14 +00:00
|
|
|
// Variables used to pass a value to call back openGL functions
|
|
|
|
static float s_textureScale;
|
|
|
|
static double s_currentZpos;
|
|
|
|
static double s_biuTo3Dunits;
|
|
|
|
bool s_useTextures;
|
|
|
|
|
2012-08-26 13:59:55 +00:00
|
|
|
// CALLBACK functions for GLU_TESS
|
|
|
|
static void CALLBACK tessBeginCB( GLenum which );
|
|
|
|
static void CALLBACK tessEndCB();
|
|
|
|
static void CALLBACK tessErrorCB( GLenum errorCode );
|
|
|
|
static void CALLBACK tessCPolyPt2Vertex( const GLvoid* data );
|
2012-08-27 07:06:52 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
void TransfertToGLlist( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits );
|
2012-08-28 06:51:18 +00:00
|
|
|
|
2012-08-27 07:06:52 +00:00
|
|
|
/* Draw3D_VerticalPolygonalCylinder is a helper function.
|
|
|
|
*
|
|
|
|
* draws a "vertical cylinder" having a polygon shape
|
|
|
|
* from Z position = aZpos to aZpos + aHeight
|
|
|
|
* Used to create the vertical sides of 3D horizontal shapes with thickness.
|
2012-08-26 13:59:55 +00:00
|
|
|
*/
|
2013-05-08 18:20:58 +00:00
|
|
|
static void Draw3D_VerticalPolygonalCylinder( const CPOLYGONS_LIST& aPolysList,
|
2012-08-27 11:41:22 +00:00
|
|
|
int aHeight, int aZpos,
|
|
|
|
bool aInside, double aBiuTo3DUnits )
|
2012-08-27 07:06:52 +00:00
|
|
|
{
|
|
|
|
if( aHeight == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::vector<S3D_VERTEX> coords;
|
|
|
|
coords.resize( 4 );
|
|
|
|
|
|
|
|
// Init Z position of the 4 points of a GL_QUAD
|
2012-08-27 11:41:22 +00:00
|
|
|
if( aInside )
|
|
|
|
{
|
|
|
|
coords[0].z = aZpos;
|
|
|
|
coords[1].z = aZpos + aHeight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
coords[0].z = aZpos + aHeight;
|
|
|
|
coords[1].z = aZpos;
|
|
|
|
}
|
2012-08-27 07:06:52 +00:00
|
|
|
coords[2].z = coords[1].z;
|
|
|
|
coords[3].z = coords[0].z;
|
|
|
|
|
|
|
|
// Draw the vertical polygonal side
|
|
|
|
int startContour = 0;
|
2013-05-09 19:08:12 +00:00
|
|
|
for( unsigned ii = 0; ii < aPolysList.GetCornersCount(); ii++ )
|
2012-08-27 07:06:52 +00:00
|
|
|
{
|
|
|
|
unsigned jj = ii + 1;
|
|
|
|
|
2013-05-09 19:08:12 +00:00
|
|
|
if( aPolysList.IsEndContour( ii ) || jj >= aPolysList.GetCornersCount() )
|
2012-08-27 07:06:52 +00:00
|
|
|
{
|
|
|
|
jj = startContour;
|
|
|
|
startContour = ii + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the 4 vertices of each GL_QUAD
|
2013-05-08 18:20:58 +00:00
|
|
|
coords[0].x = aPolysList.GetX( ii );
|
|
|
|
coords[0].y = -aPolysList.GetY( ii );
|
2012-08-27 07:06:52 +00:00
|
|
|
coords[1].x = coords[0].x;
|
|
|
|
coords[1].y = coords[0].y; // only z change
|
2013-05-08 18:20:58 +00:00
|
|
|
coords[2].x = aPolysList.GetX( jj );
|
|
|
|
coords[2].y = -aPolysList.GetY( jj );
|
2012-08-27 07:06:52 +00:00
|
|
|
coords[3].x = coords[2].x;
|
|
|
|
coords[3].y = coords[2].y; // only z change
|
|
|
|
|
|
|
|
// Creates the GL_QUAD
|
2014-03-09 18:43:53 +00:00
|
|
|
TransfertToGLlist( coords, aBiuTo3DUnits );
|
2012-08-27 07:06:52 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-26 13:59:55 +00:00
|
|
|
|
|
|
|
|
2013-10-04 08:42:09 +00:00
|
|
|
void SetGLColor( EDA_COLOR_T color, double alpha )
|
2012-08-26 13:59:55 +00:00
|
|
|
{
|
2013-04-04 21:35:01 +00:00
|
|
|
const StructColors &colordata = g_ColorRefs[ColorGetBase( color )];
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2015-03-15 15:51:56 +00:00
|
|
|
float red = colordata.m_Red / 255.0;
|
|
|
|
float blue = colordata.m_Blue / 255.0;
|
|
|
|
float green = colordata.m_Green / 255.0;
|
|
|
|
glColor4f( red, green, blue, (float)alpha );
|
2012-08-26 13:59:55 +00:00
|
|
|
}
|
|
|
|
|
2014-08-20 17:53:09 +00:00
|
|
|
|
|
|
|
void SetGLColor( S3D_COLOR& aColor, float aTransparency )
|
|
|
|
{
|
|
|
|
glColor4f( aColor.m_Red, aColor.m_Green, aColor.m_Blue, aTransparency );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
void SetGLTexture( GLuint text_id, float scale )
|
|
|
|
{
|
|
|
|
glEnable( GL_TEXTURE_2D );
|
|
|
|
glBindTexture( GL_TEXTURE_2D, text_id );
|
2014-08-22 10:24:14 +00:00
|
|
|
s_textureScale = scale; // for Tess callback functions
|
2014-07-30 09:01:25 +00:00
|
|
|
}
|
|
|
|
|
2012-08-26 13:59:55 +00:00
|
|
|
|
|
|
|
/* draw all solid polygons found in aPolysList
|
|
|
|
* aZpos = z position in board internal units
|
|
|
|
* aThickness = thickness in board internal units
|
|
|
|
* If aThickness = 0, a polygon area is drawn in a XY plane at Z position = aZpos.
|
2012-08-27 07:06:52 +00:00
|
|
|
* If aThickness > 0, a solid object is drawn.
|
2012-08-26 13:59:55 +00:00
|
|
|
* The top side is located at aZpos + aThickness / 2
|
|
|
|
* The bottom side is located at aZpos - aThickness / 2
|
|
|
|
*/
|
2013-05-08 18:20:58 +00:00
|
|
|
void Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
|
2014-08-22 10:24:14 +00:00
|
|
|
int aZpos, int aThickness, double aBiuTo3DUnits,
|
2015-04-16 07:43:27 +00:00
|
|
|
bool aUseTextures,
|
|
|
|
float aNormal_Z_Orientation )
|
2012-08-26 13:59:55 +00:00
|
|
|
{
|
2014-08-22 10:24:14 +00:00
|
|
|
// for Tess callback functions:
|
|
|
|
s_biuTo3Dunits = aBiuTo3DUnits;
|
|
|
|
s_useTextures = aUseTextures;
|
|
|
|
|
2012-08-26 13:59:55 +00:00
|
|
|
GLUtesselator* tess = gluNewTess();
|
|
|
|
|
|
|
|
gluTessCallback( tess, GLU_TESS_BEGIN, ( void (CALLBACK*) () )tessBeginCB );
|
|
|
|
gluTessCallback( tess, GLU_TESS_END, ( void (CALLBACK*) () )tessEndCB );
|
|
|
|
gluTessCallback( tess, GLU_TESS_ERROR, ( void (CALLBACK*) () )tessErrorCB );
|
|
|
|
gluTessCallback( tess, GLU_TESS_VERTEX, ( void (CALLBACK*) () )tessCPolyPt2Vertex );
|
|
|
|
|
2015-04-16 07:43:27 +00:00
|
|
|
GLdouble v_data[3];
|
|
|
|
double zpos = ( aZpos + (aThickness / 2.0) ) * aBiuTo3DUnits;
|
2014-08-22 10:24:14 +00:00
|
|
|
s_currentZpos = zpos; // for Tess callback functions
|
2015-04-16 07:43:27 +00:00
|
|
|
v_data[2] = zpos;
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2014-08-21 11:59:57 +00:00
|
|
|
// Set normal toward positive Z axis, for a solid object on the top side
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2015-04-16 07:43:27 +00:00
|
|
|
//gluTessProperty( tess, GLU_TESS_BOUNDARY_ONLY, GL_TRUE );
|
|
|
|
//gluTessProperty( tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD );
|
|
|
|
|
|
|
|
glNormal3f( 0.0, 0.0, aNormal_Z_Orientation );
|
2012-08-26 13:59:55 +00:00
|
|
|
|
|
|
|
// Draw solid areas contained in this list
|
2013-05-08 18:20:58 +00:00
|
|
|
CPOLYGONS_LIST polylist = aPolysList; // temporary copy for gluTessVertex
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2014-08-02 07:46:47 +00:00
|
|
|
int startContour;
|
|
|
|
|
2012-08-26 13:59:55 +00:00
|
|
|
for( int side = 0; side < 2; side++ )
|
|
|
|
{
|
2014-08-02 07:46:47 +00:00
|
|
|
startContour = 1;
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2013-05-09 19:08:12 +00:00
|
|
|
for( unsigned ii = 0; ii < polylist.GetCornersCount(); ii++ )
|
2012-08-26 13:59:55 +00:00
|
|
|
{
|
|
|
|
if( startContour == 1 )
|
|
|
|
{
|
|
|
|
gluTessBeginPolygon( tess, NULL );
|
|
|
|
gluTessBeginContour( tess );
|
|
|
|
startContour = 0;
|
|
|
|
}
|
|
|
|
|
2013-05-08 18:20:58 +00:00
|
|
|
v_data[0] = polylist.GetX( ii ) * aBiuTo3DUnits;
|
|
|
|
v_data[1] = -polylist.GetY( ii ) * aBiuTo3DUnits;
|
2012-08-26 13:59:55 +00:00
|
|
|
// 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, &polylist[ii] );
|
|
|
|
|
2014-07-31 07:01:30 +00:00
|
|
|
|
2013-05-08 18:20:58 +00:00
|
|
|
if( polylist.IsEndContour( ii ) )
|
2012-08-26 13:59:55 +00:00
|
|
|
{
|
|
|
|
gluTessEndContour( tess );
|
|
|
|
gluTessEndPolygon( tess );
|
|
|
|
startContour = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aThickness == 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Prepare the bottom side of solid areas
|
2014-07-30 09:01:25 +00:00
|
|
|
zpos = ( aZpos - (aThickness / 2.0) ) * aBiuTo3DUnits;
|
2014-08-22 10:24:14 +00:00
|
|
|
s_currentZpos = zpos; // for Tess callback functions
|
2012-08-26 13:59:55 +00:00
|
|
|
v_data[2] = zpos;
|
2015-04-16 07:43:27 +00:00
|
|
|
|
|
|
|
glNormal3f( 0.0, 0.0, -aNormal_Z_Orientation );
|
2012-08-26 13:59:55 +00:00
|
|
|
}
|
|
|
|
|
2014-08-02 07:46:47 +00:00
|
|
|
if( startContour == 0 )
|
|
|
|
{
|
|
|
|
gluTessEndContour( tess );
|
|
|
|
gluTessEndPolygon( tess );
|
|
|
|
}
|
|
|
|
|
2012-08-26 13:59:55 +00:00
|
|
|
gluDeleteTess( tess );
|
|
|
|
|
|
|
|
if( aThickness == 0 )
|
|
|
|
return;
|
|
|
|
|
2012-08-27 07:06:52 +00:00
|
|
|
// Build the 3D data : vertical side
|
2015-04-12 17:44:46 +00:00
|
|
|
Draw3D_VerticalPolygonalCylinder( polylist, aThickness, aZpos - (aThickness / 2.0),
|
|
|
|
true, aBiuTo3DUnits );
|
2012-08-26 13:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* draw the solid polygon found in aPolysList
|
2013-04-25 07:05:33 +00:00
|
|
|
* The first polygon is the main polygon, others are holes
|
2012-08-26 13:59:55 +00:00
|
|
|
* See Draw3D_SolidHorizontalPolyPolygons for more info
|
|
|
|
*/
|
2013-05-08 18:20:58 +00:00
|
|
|
void Draw3D_SolidHorizontalPolygonWithHoles( const CPOLYGONS_LIST& aPolysList,
|
2012-08-27 11:41:22 +00:00
|
|
|
int aZpos, int aThickness,
|
2015-04-16 07:43:27 +00:00
|
|
|
double aBiuTo3DUnits, bool aUseTextures,
|
|
|
|
float aNormal_Z_Orientation )
|
2012-08-26 13:59:55 +00:00
|
|
|
{
|
2013-05-08 18:20:58 +00:00
|
|
|
CPOLYGONS_LIST polygon;
|
2012-08-26 13:59:55 +00:00
|
|
|
|
|
|
|
ConvertPolysListWithHolesToOnePolygon( aPolysList, polygon );
|
2015-04-16 07:43:27 +00:00
|
|
|
Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, aThickness, aBiuTo3DUnits, aUseTextures,
|
|
|
|
aNormal_Z_Orientation );
|
2012-08-26 13:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
* If aThickness = 0, only one cylinder will be drawn
|
|
|
|
*/
|
|
|
|
void Draw3D_ZaxisCylinder( wxPoint aCenterPos, int aRadius,
|
|
|
|
int aHeight, int aThickness,
|
|
|
|
int aZpos, double aBiuTo3DUnits )
|
|
|
|
{
|
2012-08-26 18:10:28 +00:00
|
|
|
const int slice = SEGM_PER_CIRCLE;
|
2013-05-08 18:20:58 +00:00
|
|
|
CPOLYGONS_LIST outer_cornerBuffer;
|
2012-08-26 13:59:55 +00:00
|
|
|
|
|
|
|
TransformCircleToPolygon( outer_cornerBuffer, aCenterPos,
|
2012-08-27 11:41:22 +00:00
|
|
|
aRadius + (aThickness / 2), slice );
|
2012-08-26 13:59:55 +00:00
|
|
|
|
|
|
|
std::vector<S3D_VERTEX> coords;
|
|
|
|
coords.resize( 4 );
|
|
|
|
|
2013-05-08 18:20:58 +00:00
|
|
|
CPOLYGONS_LIST inner_cornerBuffer;
|
2012-08-27 07:06:52 +00:00
|
|
|
if( aThickness ) // build the the vertical inner polygon (hole)
|
|
|
|
TransformCircleToPolygon( inner_cornerBuffer, aCenterPos,
|
|
|
|
aRadius - (aThickness / 2), slice );
|
|
|
|
|
2012-08-26 13:59:55 +00:00
|
|
|
if( aHeight )
|
|
|
|
{
|
2015-04-12 17:44:46 +00:00
|
|
|
|
2012-08-27 07:06:52 +00:00
|
|
|
// Draw the vertical outer side
|
|
|
|
Draw3D_VerticalPolygonalCylinder( outer_cornerBuffer,
|
2012-08-27 11:41:22 +00:00
|
|
|
aHeight, aZpos, false, aBiuTo3DUnits );
|
2015-03-28 11:33:56 +00:00
|
|
|
|
2012-08-27 07:06:52 +00:00
|
|
|
if( aThickness )
|
|
|
|
// Draws the vertical inner side (hole)
|
|
|
|
Draw3D_VerticalPolygonalCylinder( inner_cornerBuffer,
|
2012-08-27 11:41:22 +00:00
|
|
|
aHeight, aZpos, true, aBiuTo3DUnits );
|
2012-08-26 13:59:55 +00:00
|
|
|
}
|
|
|
|
|
2012-08-27 07:06:52 +00:00
|
|
|
if( aThickness )
|
2012-08-26 13:59:55 +00:00
|
|
|
{
|
2012-08-27 07:06:52 +00:00
|
|
|
// draw top (front) and bottom (back) horizontal sides (rings)
|
2013-05-08 18:20:58 +00:00
|
|
|
outer_cornerBuffer.Append( inner_cornerBuffer );
|
|
|
|
CPOLYGONS_LIST polygon;
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2012-08-27 07:06:52 +00:00
|
|
|
ConvertPolysListWithHolesToOnePolygon( outer_cornerBuffer, polygon );
|
|
|
|
// draw top (front) horizontal ring
|
2015-04-16 07:43:27 +00:00
|
|
|
Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos + aHeight, 0, aBiuTo3DUnits, false,
|
|
|
|
1.0f );
|
2012-08-27 07:06:52 +00:00
|
|
|
|
|
|
|
if( aHeight )
|
2012-08-26 13:59:55 +00:00
|
|
|
{
|
2012-08-27 07:06:52 +00:00
|
|
|
// draw bottom (back) horizontal ring
|
2015-04-16 07:43:27 +00:00
|
|
|
Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, 0, aBiuTo3DUnits, false,
|
|
|
|
-1.0f );
|
2012-08-26 13:59:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function Draw3D_ZaxisOblongCylinder:
|
|
|
|
* draw a segment with an oblong hole.
|
|
|
|
* Used to draw oblong holes
|
2012-08-27 07:06:52 +00:00
|
|
|
* If aHeight = height of the cylinder is 0, only one ring will be drawn
|
|
|
|
* If aThickness = 0, only one cylinder will be drawn
|
2012-08-26 13:59:55 +00:00
|
|
|
*/
|
|
|
|
void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos,
|
|
|
|
int aRadius, int aHeight, int aThickness,
|
|
|
|
int aZpos, double aBiuTo3DUnits )
|
|
|
|
{
|
2012-08-26 18:10:28 +00:00
|
|
|
const int slice = SEGM_PER_CIRCLE;
|
2012-08-26 13:59:55 +00:00
|
|
|
|
|
|
|
// Build the points to approximate oblong cylinder by segments
|
2013-05-08 18:20:58 +00:00
|
|
|
CPOLYGONS_LIST outer_cornerBuffer;
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2012-08-27 11:41:22 +00:00
|
|
|
int segm_width = (aRadius * 2) + aThickness;
|
2012-08-27 07:06:52 +00:00
|
|
|
TransformRoundedEndsSegmentToPolygon( outer_cornerBuffer, aAxis1Pos,
|
2012-08-27 11:41:22 +00:00
|
|
|
aAxis2Pos, slice, segm_width );
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2012-08-27 07:06:52 +00:00
|
|
|
// Draw the oblong outer cylinder
|
|
|
|
if( aHeight )
|
2012-08-27 11:41:22 +00:00
|
|
|
Draw3D_VerticalPolygonalCylinder( outer_cornerBuffer, aHeight, aZpos,
|
|
|
|
false, aBiuTo3DUnits );
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2012-08-27 07:06:52 +00:00
|
|
|
if( aThickness )
|
2012-08-26 13:59:55 +00:00
|
|
|
{
|
2013-05-08 18:20:58 +00:00
|
|
|
CPOLYGONS_LIST inner_cornerBuffer;
|
2012-08-27 11:41:22 +00:00
|
|
|
segm_width = aRadius * 2;
|
2012-08-27 07:06:52 +00:00
|
|
|
TransformRoundedEndsSegmentToPolygon( inner_cornerBuffer, aAxis1Pos,
|
2012-08-27 11:41:22 +00:00
|
|
|
aAxis2Pos, slice, segm_width );
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2012-08-27 07:06:52 +00:00
|
|
|
// Draw the oblong inner cylinder
|
|
|
|
if( aHeight )
|
|
|
|
Draw3D_VerticalPolygonalCylinder( inner_cornerBuffer, aHeight,
|
2012-09-11 07:33:17 +00:00
|
|
|
aZpos, true, aBiuTo3DUnits );
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2012-08-27 11:41:22 +00:00
|
|
|
// Build the horizontal full polygon shape
|
|
|
|
// (outer polygon shape - inner polygon shape)
|
2013-05-08 18:20:58 +00:00
|
|
|
outer_cornerBuffer.Append( inner_cornerBuffer );
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2013-05-08 18:20:58 +00:00
|
|
|
CPOLYGONS_LIST polygon;
|
2012-08-27 07:06:52 +00:00
|
|
|
ConvertPolysListWithHolesToOnePolygon( outer_cornerBuffer, polygon );
|
2012-08-27 11:41:22 +00:00
|
|
|
|
|
|
|
// draw top (front) horizontal side (ring)
|
2015-04-16 07:43:27 +00:00
|
|
|
Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos + aHeight, 0, aBiuTo3DUnits, false,
|
|
|
|
1.0f );
|
2012-08-27 07:06:52 +00:00
|
|
|
|
|
|
|
if( aHeight )
|
|
|
|
{
|
|
|
|
// draw bottom (back) horizontal side (ring)
|
2015-04-16 07:43:27 +00:00
|
|
|
Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, 0, aBiuTo3DUnits, false,
|
|
|
|
-1.0f );
|
2012-08-27 07:06:52 +00:00
|
|
|
}
|
2012-08-26 13:59:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* draw a thick segment using 3D primitives, in a XY plane
|
|
|
|
* wxPoint aStart, wxPoint aEnd = YX position of end in board units
|
|
|
|
* aWidth = width of segment in board units
|
|
|
|
* aThickness = thickness of segment in board units
|
|
|
|
* aZpos = z position of segment in board units
|
|
|
|
*/
|
|
|
|
void Draw3D_SolidSegment( const wxPoint& aStart, const wxPoint& aEnd,
|
|
|
|
int aWidth, int aThickness, int aZpos, double aBiuTo3DUnits )
|
|
|
|
{
|
2013-05-08 18:20:58 +00:00
|
|
|
CPOLYGONS_LIST cornerBuffer;
|
2012-08-26 18:10:28 +00:00
|
|
|
const int slice = SEGM_PER_CIRCLE;
|
2012-08-26 13:59:55 +00:00
|
|
|
|
|
|
|
TransformRoundedEndsSegmentToPolygon( cornerBuffer, aStart, aEnd, slice, aWidth );
|
|
|
|
|
2015-04-16 07:43:27 +00:00
|
|
|
Draw3D_SolidHorizontalPolyPolygons( cornerBuffer, aZpos, aThickness, aBiuTo3DUnits, false, 1.0f );
|
2012-08-26 13:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-26 18:10:28 +00:00
|
|
|
void Draw3D_ArcSegment( const wxPoint& aCenterPos, const wxPoint& aStartPoint,
|
2013-05-05 07:17:48 +00:00
|
|
|
double aArcAngle, int aWidth, int aThickness,
|
2012-08-26 18:10:28 +00:00
|
|
|
int aZpos, double aBiuTo3DUnits )
|
2012-08-26 13:59:55 +00:00
|
|
|
{
|
2012-08-26 18:10:28 +00:00
|
|
|
const int slice = SEGM_PER_CIRCLE;
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2013-05-08 18:20:58 +00:00
|
|
|
CPOLYGONS_LIST cornerBuffer;
|
2012-08-26 18:10:28 +00:00
|
|
|
TransformArcToPolygon( cornerBuffer, aCenterPos, aStartPoint, aArcAngle,
|
2013-05-01 17:32:36 +00:00
|
|
|
slice, aWidth );
|
2012-08-26 13:59:55 +00:00
|
|
|
|
2015-04-16 07:43:27 +00:00
|
|
|
Draw3D_SolidHorizontalPolyPolygons( cornerBuffer, aZpos, aThickness, aBiuTo3DUnits, false, 1.0f );
|
2012-08-26 13:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// /////////////////////////////////////////////////////////////////////////////
|
|
|
|
// GLU_TESS CALLBACKS
|
|
|
|
// /////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CALLBACK tessBeginCB( GLenum which )
|
|
|
|
{
|
|
|
|
glBegin( which );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CALLBACK tessEndCB()
|
|
|
|
{
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CALLBACK tessCPolyPt2Vertex( const GLvoid* data )
|
|
|
|
{
|
|
|
|
// cast back to double type
|
|
|
|
const CPolyPt* ptr = (const CPolyPt*) data;
|
|
|
|
|
2014-08-22 10:24:14 +00:00
|
|
|
if( s_useTextures )
|
2014-07-30 09:01:25 +00:00
|
|
|
{
|
2014-08-22 10:24:14 +00:00
|
|
|
glTexCoord2f( ptr->x * s_biuTo3Dunits * s_textureScale,
|
|
|
|
-ptr->y * s_biuTo3Dunits * s_textureScale);
|
2014-07-30 09:01:25 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 10:24:14 +00:00
|
|
|
glVertex3d( ptr->x * s_biuTo3Dunits, -ptr->y * s_biuTo3Dunits, s_currentZpos );
|
2012-08-26 13:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CALLBACK tessErrorCB( GLenum errorCode )
|
|
|
|
{
|
|
|
|
#if defined(DEBUG)
|
|
|
|
const GLubyte* errorStr;
|
|
|
|
|
|
|
|
errorStr = gluErrorString( errorCode );
|
|
|
|
|
|
|
|
// DEBUG //
|
2013-09-10 08:47:42 +00:00
|
|
|
DBG( printf( "Tess ERROR: %s\n", errorStr ); )
|
2012-08-26 13:59:55 +00:00
|
|
|
#endif
|
|
|
|
}
|