Beispiel #1
0
/**

polygon to polygon calculation
*/
int lw_dist3d_poly_poly(LWPOLY *poly1, LWPOLY *poly2, DISTPTS3D *dl)
{		
	PLANE3D plane;		
	LWDEBUG(2, "lw_dist3d_poly_poly is called");
	if (dl->mode == DIST_MAX)
	{
		return lw_dist3d_ptarray_ptarray(poly1->rings[0], poly2->rings[0], dl);
	}
	
	if(!define_plane(poly2->rings[0], &plane))
		return LW_FALSE;
	
	/*What we do here is to compare the bondary of one polygon with the other polygon 
	and then take the second boudary comparing with the first polygon*/
	dl->twisted=1;
	if(!lw_dist3d_ptarray_poly(poly1->rings[0], poly2,&plane, dl))
		return LW_FALSE;
	if(dl->distance==0.0) /*Just check if the answer already is given*/
		return LW_TRUE;
	
	if(!define_plane(poly1->rings[0], &plane))
		return LW_FALSE;
	dl->twisted=-1; /*because we swithc the order of geometries we swithch "twisted" to -1 which will give the right order of points in shortest line.*/
	return lw_dist3d_ptarray_poly(poly2->rings[0], poly1,&plane, dl);
}
Beispiel #2
0
/**

line to polygon calculation
*/
int lw_dist3d_line_poly(LWLINE *line, LWPOLY *poly, DISTPTS3D *dl)
{
	PLANE3D plane;	
	LWDEBUG(2, "lw_dist3d_line_poly is called");	
		
	if (dl->mode == DIST_MAX)
	{
		return lw_dist3d_ptarray_ptarray(line->points, poly->rings[0], dl);
	}
	
	if(!define_plane(poly->rings[0], &plane))
		return LW_FALSE;
	
	return lw_dist3d_ptarray_poly(line->points, poly,&plane, dl);
}
Beispiel #3
0
/**

Computes point to polygon distance
For mindistance that means:
1)find the plane of the polygon 
2)projecting the point to the plane of the polygon 
3)finding if that projected point is inside the polygon, if so the distance is measured to that projected point
4) if not in polygon above, check the distance against the boundary of the polygon
for max distance it is always point against boundary

*/
int
lw_dist3d_point_poly(LWPOINT *point, LWPOLY *poly, DISTPTS3D *dl)
{
	POINT3DZ p, projp;/*projp is "point projected on plane"*/
	PLANE3D plane;
	LWDEBUG(2, "lw_dist3d_point_poly is called");
	getPoint3dz_p(point->point, 0, &p);
	
	/*If we are lookig for max distance, longestline or dfullywithin*/
	if (dl->mode == DIST_MAX)
	{
		LWDEBUG(3, "looking for maxdistance");
		return lw_dist3d_pt_ptarray(&p, poly->rings[0], dl);
	}
	
	/*Find the plane of the polygon, the "holes" have to be on the same plane. so we only care about the boudary*/
	if(!define_plane(poly->rings[0], &plane))
		return LW_FALSE;
	
	/*get our point projected on the plane of the polygon*/
	project_point_on_plane(&p, &plane, &projp);
	
	return lw_dist3d_pt_poly(&p, poly,&plane, &projp, dl);
}
// Drawing function for the plane
void draw_plane(float z) {
	glPushMatrix();
	glPopMatrix();
	int plane = define_plane(z);
	glCallList(plane);
}
void
read_terrain (void)
{
	FILE *inf;
	char buf[1000];
	int idx;
	char *tokstate, *tok;
	double vals[12], B_minus_A[3], C_minus_A[3], normal[3];

	if ((inf = fopen ("simpleground2.raw", "r")) == NULL) {
		fprintf (stderr, "can't open simpleground2.raw\n");
		exit (1);
	}

	terrain_list = glGenLists (1);
	
	glNewList (terrain_list, GL_COMPILE);

	glPushMatrix ();

	glEnable (GL_TEXTURE_2D);

	glColor3f (1, 1, 0);

	while (fgets (buf, sizeof buf, inf) != NULL) {
		idx = 0;
		tokstate = buf;
		while (idx < 9 && (tok = strtok (tokstate, " ")) != NULL) {
			tokstate = NULL;
			vals[idx++] = atof (tok);
		}

		arrayvsub (B_minus_A, vals + 3, vals);
		arrayvsub (C_minus_A, vals + 6, vals);
		arrayvcross (normal, B_minus_A, C_minus_A);

		if (idx == 9) {
			define_plane (vals[0], vals[1], vals[2],
				      vals[3], vals[4], vals[5],
				      vals[6], vals[7], vals[8],
				      normal[0], normal[1], normal[2]);

			glBindTexture (GL_TEXTURE_2D, texName[0]);
			glBegin (GL_TRIANGLES);
			glTexCoord2f (1, 0);
			glVertex3dv (vals);
			glTexCoord2f (1, 1);
			glVertex3dv (vals + 3);
			glTexCoord2f (0, 1);
			glVertex3dv (vals + 6);
			
			glNormal3dv (normal);
			
			glEnd ();
		} else {
			printf ("Model has non-triangles, exiting\n");
			exit (1);
		}
	}

	fclose (inf);
	
	glDisable (GL_TEXTURE_2D);
	
	glPopMatrix ();
	
	glEndList ();
}