Beispiel #1
0
/***************************************************************************
 *
 *N  point_in_face
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Test whether a line (x,y through infinity) intersects a face (which
 *    itself is multiple polygon_loop or ring structures).  Returns a 0
 *    if outside, 1 if inside.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    x         <input> == (float) x coordinate of given point.
 *    y         <input> == (float) y coordinate of given point.
 *    face_id   <input> == (rspf_int32) given face.
 *    facetable <input> == (vpf_table_type) VPF face table.
 *    ringtable <input> == (vpf_table_type) VPF ring table.
 *    edgetable <input> == (vpf_table_type) VPF edge table.
 *    point_in_face <output> == (int) VPF_BOOLEAN:
 *                                            1 --> inside
 *                                            0 --> outside
 *E
 **************************************************************************/
int point_in_face( float x, float y,
		   rspf_int32 face_id,
		   vpf_table_type facetable,
		   vpf_table_type ringtable,
		   vpf_table_type edgetable )
{
   face_rec_type face_rec;
   ring_rec_type ring_rec;
   int n;

   face_rec = read_face( face_id, facetable );
   ring_rec = read_ring( face_rec.ring, ringtable );
   n = intersect_polygon_loop( x, y, face_id, ring_rec.edge, edgetable );

   while (ring_rec.face == face_id ) {
      ring_rec = read_next_ring( ringtable );

      if (feof(ringtable.fp)) {
	 break;
      }

      if (ring_rec.face == face_id) {
	 n += intersect_polygon_loop( x, y, face_id,
				      ring_rec.edge, edgetable );
      }
   }

   if (n%2 == 0)   /* Even number of intersections */
      return 0;    /*   Not inside polygon         */
   else            /* Odd number of intersections  */
      return 1;    /*    Inside polygon            */
}
Beispiel #2
0
/*************************************************************************
 *
 *N  outline_face
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *     This function outlines (without filling) the specified face from
 *     the given face table.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *     face_id   <input>==(ossim_int32) row id of the specified face.
 *     facetable <input>==(vpf_table_type) VPF facemitive table.
 *     ringtable <input>==(vpf_table_type) VPF ringmitive table.
 *     edgetable <input>==(vpf_table_type) VPF edge primitive table.
 *     outline   <input>==(color_type) outline color.
 *     inner     <input>==(int) if TRUE, draw inner rings;
 *                              if FALSE, only draw outer ring.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels   May 1991                           DOS Turbo C
 *E
 *************************************************************************/
void outline_face( ossim_int32 face_id,
		   vpf_table_type facetable,
		   vpf_table_type ringtable,
		   vpf_table_type edgetable,
		   color_type outline,
		   int inner )
{
   face_rec_type face_rec;
   ring_rec_type ring_rec;

   gpsetlinecolor(outline);
   gpsetlinestyle(SOLID_LINE);
   gpsetlinewidth(NORM_WIDTH);

   face_rec = read_face( face_id, facetable );
   ring_rec = read_ring( face_rec.ring, ringtable );
   outline_polygon_loop( face_id, ring_rec.edge, edgetable );

   if (!inner) return;

   while (ring_rec.face == face_id ) {
      ring_rec = read_next_ring( ringtable );

      if (feof(ringtable.fp)) {
	 break;
      }

      if (ring_rec.face == face_id) {

	 outline_polygon_loop( face_id, ring_rec.edge, edgetable );

      }
   }
}
void BinaryMeshFileReader::read_faces(ReaderAdapter& reader, IMeshBuilder& builder)
{
    uint32 count;
    checked_read(reader, count);

    for (uint32 i = 0; i < count; ++i)
        read_face(reader, builder);
}
void VFSPlugin_LWO::read_pols(long length)
{
	//	Read what type of polygon mesh this is
	long chunkid = ReadLong();
	length-=sizeof(long);

	//	Determine which method to use in reading the polygon data
	switch(chunkid)
	{
		case ID_FACE:	{	read_face(length);					}break;
		case ID_CURV:	{	read_curv(length);					}break;
		case ID_PTCH:	{	read_ptch(length);					}break;
		case ID_MBAL:	{	read_mbal(length);					}break;
		case ID_BONE:	{	read_bone(length);					}break;
		default:			{	read_unkn(chunkid,length);	}break;
	};
}
Beispiel #5
0
Model_error_code OBJ_load (const char* filename, char clockwise, char left_handed, Model* model)
{
    vec3* norms     = 0;
    vec3* verts     = 0;
    texCoord* texcs = 0;
    triangle* tris  = 0;
    
    FILE* file = fopen (filename, "r");
    if (file == NULL) return Model_File_Not_Found;
    
    vec3 vert;
    vec3 normal;
    texCoord texc;
    
    vector vertices;
    vector normals;
    vector texCoords;
    vector triangles;
    
    int result = vector_new (&vertices,  sizeof(vec3),     0)
               | vector_new (&normals,   sizeof(vec3),     0)
               | vector_new (&texCoords, sizeof(texCoord), 0)
               | vector_new (&triangles, sizeof(triangle), 0);
    
    if (result != 0)
    {
        safe_free (vertices.data);
        safe_free (normals.data);
        safe_free (texCoords.data);
        safe_free (triangles.data);
        return Model_Memory_Allocation_Error;
    }
    
    while (!feof(file))
    {
        switch (fgetc(file))
        {
        case 'v':
            switch (fgetc(file))
            {
            case 't':
                read_tex_coord (file, &texc);
                vector_append (&texCoords, &texc);
                break;
                
            case 'n':
                read_normal (file, &normal);
                vector_append (&normals, &normal);
                break;
                
            default:
                read_vertex (file, &vert);
                vector_append (&vertices, &vert);
                break;
            }
            break;
            
        case 'f':
            // Initialise the normals vector if it is empty.
            if (vector_size(&normals) == 0)
            {
                vec3 zero;
                zero.x = 0.0f; zero.y = 0.0f; zero.z = 0.0f;
                vector_new (&normals, sizeof(vec3), vector_size(&vertices));
                vector_initialise (&normals, &zero);
            }
            read_face (file, clockwise, &vertices, &normals, &triangles);
            break;
        
        case '#':
        {
            int x = 17;
            while (x != '\n' && x != EOF) x = fgetc(file);
            break;
        }
            
        default: break;
        }
    }
    
    fclose (file);
    
    unsigned numVertices = vector_size (&vertices);
    
    // Normalise normals.
    unsigned i;
    for (i = 0; i < numVertices; ++i)
    {
        normalise (vector_ith (&normals, i));
    }
    
    model->vertices      = (vec3*) vertices.data;
    model->normals       = (vec3*) normals.data;
    model->texCoords     = (texCoord*) texCoords.data;
    model->triangles     = (triangle*) triangles.data;
    model->skins         = 0;
    model->animations    = 0;
    model->numFrames     = 1;
    model->numVertices   = numVertices;
    model->numTriangles  = vector_size (&triangles);
    model->numTexCoords  = vector_size (&texCoords);
    model->numSkins      = 0;
    model->numAnimations = 0;
    
    return Model_Success;
}