Beispiel #1
0
static void Draw3D_FilledCylinder(double posx, double posy,
				double rayon, double height, double zpos)
/*********************************************************/
{
int ii;
double x, y;
#define NB_SEGM 12
S3D_Vertex coords[4];
double tmp = DataScale3D;

	DataScale3D = 1.0;	//les coord sont deja a l'echelle pour Set_Object_Data();
	coords[0].x = coords[1].x = posx + rayon;
	coords[0].y = coords[1].y = posy;
	coords[0].z = coords[3].z = zpos;
	coords[1].z = coords[2].z = zpos + height;

	for ( ii = 0; ii <= NB_SEGM; ii++ )
	{
		x = rayon; y = 0.0;
		RotatePoint(&x, &y, ii * (3600/NB_SEGM));
		coords[2].x = coords[3].x = posx + x;
		coords[2].y = coords[3].y = posy + y;
		Set_Object_Data(coords, 4 );
		coords[0].x = coords[2].x;
		coords[0].y = coords[2].y;
		coords[1].x = coords[3].x;
		coords[1].y = coords[3].y;
	}
 	glNormal3f( 0.0, 0.0, 1.0);	// Normal is Z axis
	DataScale3D = tmp;
}
Beispiel #2
0
int VRML_MODEL_PARSER::readGeometry( FILE* file, int* LineNum )
{
    char    line[1024], buffer[1024], * text;
    int     err    = 1;
    std::vector< double > points;
    std::vector< double > list;
    double vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;

    while( GetLine( file, line, LineNum, 512 ) )
    {
        strcpy( buffer, line );
        text = strtok( buffer, sep_chars );

        if( text == NULL )
            continue;

        if( *text == '}' )
        {
            err = 0;
            break;
        }

        if( stricmp( text, "normalPerVertex" ) == 0 )
        {
            text = strtok( NULL, " ,\t\n\r" );

            if( text && stricmp( text, "true" ) == 0 )
            {
            }
            else
            {
            }

            continue;
        }

        if( stricmp( text, "colorPerVertex" ) == 0 )
        {
            text = strtok( NULL, " ,\t\n\r" );

            if( text && stricmp( text, "true" ) == 0 )
            {
            }
            else
            {
            }
            continue;
        }

        if( stricmp( text, "normal" ) == 0 )
        {
            readCoordsList( file, line, list, LineNum );
            list.clear();
            continue;
        }

        if( stricmp( text, "normalIndex" ) == 0 )
        {
            while( GetLine( file, line, LineNum, 512 ) )
            {
                text = strtok( line, " ,\t\n\r" );

                while( text )
                {
                    if( *text == ']' )
                        break;

                    text = strtok( NULL, " ,\t\n\r" );
                }

                if( text && (*text == ']') )
                    break;
            }

            continue;
        }

        if( stricmp( text, "color" ) == 0 )
        {
            readCoordsList( file, line, list, LineNum );
            list.clear();
            continue;
        }

        if( stricmp( text, "solid" ) == 0 )
        {
            // ignore solid
            continue;
        }

        if( stricmp( text, "colorIndex" ) == 0 )
        {
            while( GetLine( file, line, LineNum, 512 ) )
            {
                text = strtok( line, " ,\t\n\r" );

                while( text )
                {
                    if( *text == ']' )
                        break;

                    text = strtok( NULL, " ,\t\n\r" );
                }

                if( text && (*text == ']') )
                    break;
            }

            continue;
        }

        if( stricmp( text, "coord" ) == 0 )
        {
            readCoordsList( file, line, points, LineNum );
        }
        else if( stricmp( text, "coordIndex" ) == 0 )
        {
            if( points.size() < 3 || points.size() % 3 != 0 )
            {
                wxLogError( wxT( "3D geometry read error <%s> at line %d." ),
                            GetChars( FROM_UTF8( text ) ), *LineNum );
                err = 1;
                break;
            }

            std::vector< int > coordIndex;
            std::vector< S3D_VERTEX > vertices;

            while( GetLine( file, line, LineNum, 512 ) )
            {
                int jj;
                text = strtok( line, " ,\t\n\r" );

                while( text )
                {
                    if( *text == ']' )
                        break;

                    jj = atoi( text );

                    if( jj < 0 )
                    {
                        for( jj = 0; jj < (int) coordIndex.size(); jj++ )
                        {
                            int kk = coordIndex[jj] * 3;

                            if( (kk < 0) || ((kk + 3) > (int)points.size()) )
                            {
                                wxLogError( wxT( "3D geometry index read error <%s> at line %d." ),
                                            GetChars( FROM_UTF8( text ) ), *LineNum );
                                err = 1;
                                break;
                            }

                            S3D_VERTEX vertex;
                            vertex.x = points[kk];
                            vertex.y = points[kk + 1];
                            vertex.z = points[kk + 2];
                            vertices.push_back( vertex );
                        }

                        GetMaster()->Set_Object_Coords( vertices );
                        Set_Object_Data( vertices, vrmlunits_to_3Dunits );
                        vertices.clear();
                        coordIndex.clear();
                    }
                    else
                    {
                        coordIndex.push_back( jj );
                    }

                    text = strtok( NULL, " ,\t\n\r" );
                }

                if( text && (*text == ']') )
                    break;
            }
        }
        else
        {
            wxLogError( wxT( "3D geometry read error <%s> at line %d." ),
                        GetChars( FROM_UTF8( text ) ), *LineNum );
            err = 1;
            break;
        }
    }

    return err;
}
int Struct3D_Master::ReadGeometry(FILE * file, int *LineNum)
/***********************************************************/
{
char line[1024], buffer[1024], *text;
int err = 1;
int nn = BUFSIZE;
double * points = NULL;
int * index = NULL;

	while ( GetLine(file, line, LineNum, 512) )
	{
		strcpy(buffer,line);
		text = strtok(buffer, " \t\n\r");
		if ( * text == '}' )
		{
			err = 0; break;
		}

		if ( stricmp (text, "normalPerVertex" ) == 0 )
		{
			text = strtok(NULL, " ,\t\n\r");
			if( stricmp (text, "TRUE") == 0 )
			{
			}
			else
			{
			}
			continue;
		}

		if ( stricmp (text, "normal" ) == 0 )
		{
			int coord_number;
			double * buf_points = ReadCoordsList(file, line, &coord_number, LineNum);
			continue;
			free(buf_points);
			continue;
		}
		if ( stricmp (text, "normalIndex" ) == 0 )
		{
			while ( GetLine(file, line, LineNum, 512) )
			{
				text = strtok(line, " ,\t\n\r");
				while ( text )
				{
					if ( *text == ']') break;
					text = strtok(NULL, " ,\t\n\r");
				}
				if ( text && (*text == ']') ) break;
			}
			continue;
		}

		if ( stricmp (text, "coord" ) == 0 )
		{
			int coord_number;
			points = ReadCoordsList(file, line, &coord_number, LineNum);
		}
		else if ( stricmp (text, "coordIndex" ) == 0 )
		{
			index = (int *) MyMalloc(nn * sizeof(int) );
			S3D_Vertex * coords =
				(S3D_Vertex *) MyMalloc(nn * sizeof(S3D_Vertex) );
			while ( GetLine(file, line, LineNum, 512) )
			{
				int coord_count = 0, jj;
				text = strtok(line, " ,\t\n\r");
				while ( text )
				{
					if ( *text == ']') break;
					jj = atoi(from_point(text));
					if ( jj < 0 )
					{
					S3D_Vertex * curr_coord = coords;
						for ( jj = 0; jj < coord_count; jj ++ )
						{
							int kk = index[jj] * 3;
							curr_coord->x = points[kk];
							curr_coord->y = points[kk+1];
							curr_coord->z = points[kk+2];
							curr_coord++;
						}
						Set_Object_Coords(coords, coord_count );
						Set_Object_Data(coords, coord_count );
						coord_count = 0;
					}
					else
					{
						index[coord_count++] = jj;
					}
					text = strtok(NULL, " ,\t\n\r");
				}
			if ( text && (*text == ']') ) break;
			}
			free(index);
			free(coords);
		}
		else
		{
			printf ("ReadGeometry error line %d <%s> \n", *LineNum, text);
			break;
		}
	}
	if ( points ) free (points);

	return err;
}