In Example 32 a polygon is created which consists out of two intersecting contours. The result is shown in 5.34. You will notice that the region which lies in both contours is not drawn. Only those regions of polygons are drawn which lie in an odd number of contours (odd winding rule).

It is also necessary to specify a plane for each polygon. The polygon vertices (which are 3D vertices) are projected onto this plane, then the resulting 2D contours get triangulated, and finally the triangles are mapped back into 3D again.

This plane is also used for deciding which sides of the triangles are the front sides, and for defining a parametrization of the plane, which can be used as 2D texture coordinates.

The plane has to be defined via three points A, B, and C. A is used as the origin of the polygon plane, B-A and C-A as the two basis vectors, and the orientation of the cross product (B-A) x (C-A) determines which side of the plane is the front side.

In Example 32 a small 2*2 2D texture is used. Since the polygon plane is defined with the three points A1, B1 and D1, the point A1 gets the texture coordinates (0, 0), B1 the coordinates (1, 0) and D1 the coordinates (0, 1). Also the attributes for texture wrapping are set, so that the texture repeats for coordinates less then 0 or greater then 1.

**Example 32:**` (`taken from:` data/examples/polygon3_1.dat (7.32))`

A1 = (0.,0.,0.); B1 = (10.,0.,0.); C1 = (10.,10.,0.); D1 = (0.,10.,0.); A2 = (6.,7.,0); B2 = (8.,7.,0); C2 = (8.,17.,0); D2 = (6.,17.,0); cont1 = ( A1,B1,C1,D1 ); cont2 = ( A2,B2,C2,D2 ); polygon1 = POLYGON3( (A1,B1,D1),(cont1,cont2) ); teximg1 = TEXIMAGE2D( ( ((1,0,0,1), (0,1,0,1)), ((0,0,1,1), (1,1,0,1)) ) ); SCENEROOT = SCENENODE( (), ( ATTRIBS( teximg1, USETEXIMG(2), USETEXWRAPX(1), USETEXWRAPY(1), USETEXMAGTONEAREST(1), USETEXMINTONEAREST(1) ) ), (polygon1) );

In Example 33 a rectangle is created with a triangle above it. The result is shown in Figure 5.35.

The polygon plane of the triangle is specified with its three vertices. The angle which is formed by these three vertices isn't rectangular, so this would normally cause a non- orthogonal texture coordinate system, i.e. a shearing. But this effect is compensated by the TRNSF3PT((0.3,0.1),(0.9,0.3),(0.5,1.0)) instruction in the TEX2TRANSFORMS group, so that after this transformation the triangle has the same coordinate sytem as the rectangle below it. The following TRNSF3PT((0,0),(4,0),(0,4)) causes a scaling by a factor 4, so that the texture is mapped four times onto the triangle.

**Example 33:**` (`taken from:` data/examples/polygon3_2.dat (7.33))`

A1 = (0,0,0); B1 = (10,0,0); C1 = (10,10,0); D1 = (0,10,0); cont1 = ( A1,B1,C1,D1 ); polygon1 = POLYGON3( (A1,B1,D1), (cont1) ); A2 = (3,1,0); B2 = (9,3,0); C2 = (5,10,0); cont2 = ( A2,B2,C2 ); polygon2 = POLYGON3( (A2,B2,C2), (cont2) ); node1 = SCENENODE( (), ( TRANSFORMS(TRNSF3PT((0,0,8),(1,0,8),(0,1,8))) ), (polygon1) ); SCENEROOT = SCENENODE( (node1), ( ATTRIBS( teximg1, USETEXIMG(2), USETEXWRAPX(1), USETEXWRAPY(1), USETEXMAGTONEAREST(1), USETEXMINTONEAREST(1) ), LOCAL_ATTR( TEX2TRANSFORMS(TRNSF3PT((0,0),(4,0),(0,4)), TRNSF3PT((0.3,0.1),(0.9,0.3),(0.5,1.0)) ) ) ), (polygon2) );

Example 34 creates the same output (see Figure 5.35) as Example 33, but this time a polygon with (vertice/ texture coordinate) pairs is used for describing the triangle. Though this makes a texture coordinate system superfluous, it is still necessary to define a polygon plane for the triangle (this is needed for the triangulation, and for defining a face normal). In the example simply the xy plane is chosen.

**Example 34:**` (`taken from:` data/examples/polygon3_3.dat (7.34))`

A1 = (0,0,0); B1 = (10,0,0); C1 = (10,10,0); D1 = (0,10,0); cont1 = ( A1,B1,C1,D1 ); polygon1 = POLYGON3( (A1,B1,D1), (cont1) ); A2 = (3,1,0); B2 = (9,3,0); C2 = (5,10,0); TA2 = (0.3,0.1,0); TB2 = (0.9,0.3,0); TC2 = (0.5,1.0,0); cont2 = ( (A2,TA2), (B2,TB2), (C2,TC2) ); polygon2 = POLYGON3T( ((0,0,0),(1,0,0),(0,1,0)), (cont2) ); node1 = SCENENODE( (), ( TRANSFORMS(TRNSF3PT((0,0,8),(1,0,8),(0,1,8))) ), (polygon1) ); SCENEROOT = SCENENODE( (node1), ( ATTRIBS( teximg1, USETEXIMG(2), USETEXWRAPX(1), USETEXWRAPY(1), USETEXMAGTONEAREST(1), USETEXMINTONEAREST(1) ), LOCAL_ATTR( TEX2TRANSFORMS(TRNSF3PT( (0,0),(4,0),(0,4))) ) ), (polygon2) );

Example 35 gives an example for 3D texturing, the result is shown in Figure 5.36.

A simple 2*2*2 texture is used. Two cubes are drawn whose vertices have the same object coordinates. On default object coordinates are used as 3D texture coordinates, so both cubes would look the same when using the default, since their object coordinates lie in the same octant of the 2*2*2 texture.

But in Example 1003 the attribute USEABSXYZTEXCS is used. This causes that the world coordinates of the objects are transformed into the local coordinate system of the scene graph node to which this attribute is attached, and the resulting coordinates are taken as 3D texture coordinates.

**Example 35:**` (`taken from:` data/examples/polygon3_7.dat (7.38))`

A1 = (0.,0.,0.); B1 = (0.4,0.,0.); C1 = (0.4,0.4,0.); D1 = (0.,0.4,0.); A2 = (0.,0.,0.4); B2 = (0.4,0.,0.4); C2 = (0.4,0.4,0.4); D2 = (0.,0.4,0.4); N1 = (0.,0.,1.); N2 = (0.,0.,1.); N3 = (0.,1.,0.); N4 = (1.,0.,0.); N5 = (0.,1.,0.); N6 = (1.,0.,0.); cont1 = ( (A1,N1), (B1,N1), (C1,N1), (D1,N1) ); polygon1 = POLYGON3N( (A1,B1,D1), (cont1) ); cont2 = ( (A2,N2), (B2,N2), (C2,N2), (D2,N2) ); polygon2 = POLYGON3N( (A2,B2,D2), (cont2) ); cont3 = ( (A1,N3), (B1,N3), (B2,N3), (A2,N3) ); polygon3 = POLYGON3N( (A1,B1,A2), (cont3) ); cont4 = ( (B1,N4), (C1,N4), (C2,N4), (B2,N4) ); polygon4 = POLYGON3N( (B1,C1,B2), (cont4) ); cont5 = ( (C1,N5), (D1,N5), (D2,N5), (C2,N5) ); polygon5 = POLYGON3N( (C1,D1,C2), (cont5) ); cont6 = ( (D1,N6), (A1,N6), (A2,N6), (D2,N6) ); polygon6 = POLYGON3N( (D1,A1,D2), (cont6) ); teximg1 = TEXIMAGE3D( ( ( ((1.0,1.0,0.0,0.5), (1.0,0.0,1.0,0.5)), ((1.0,1.0,0.0,0.5), (1.0,1.0,1.0,0.5)) ), ( ((0.0,0.0,0.0,0.5), (0.0,0.0,1.0,0.5)), ((0.0,1.0,0.0,0.5), (0.0,1.0,1.0,0.5)) ) ) ); polys = (polygon1,polygon2,polygon3,polygon4,polygon5, polygon6); cube1 = SCENENODE( (), ( TRANSFORMS( TRNSF3PT((0.6,0.6,0.6),(1.6,0.6,0.6),(0.6,1.6,0.6)) ) ), polys ); SCENEROOT = SCENENODE( (cube1), ( SETABSXYZTEXCS(), ATTRIBS( teximg1, USETEXIMG(3),USEXYZTEXCS(1),USEABSXYZTEXCS(1), USETEXMAGTONEAREST(1),USETEXMINTONEAREST(1) ) ), polys );

In Example 36 two pairs of two adjacent polygons are created. In one of the pairs the polygons are specified with (vertex, normal) pairs, so that there seems to be a smooth transition between the both polygons. Figure 36 shows the result.

**Example 36:**` (`taken from:` data/examples/polygon3_4.dat (7.35))`

A1 = (0.,0.,0.); B1 = (10.,0.,0.); C1 = (10.,10.,5.); D1 = (0.,10.,5.); N1 = (0.,-0.5,1.0); A2 = D1; B2 = C1; C2 = (10.,20.,0.); D2 = (0.,20.,0.); N2 = (0.,0.5,1.0); N3 = (0,0,1); cont1 = (A1,B1,C1,D1); polygon1 = POLYGON3( (A1,B1,D1), (cont1) ); cont2 = (A2,B2,C2,D2); polygon2 = POLYGON3( (A2,B2,D2), (cont2) ); cont3 = ( (A1,N1), (B1,N1), (C1,N3), (D1,N3) ); polygon3 = POLYGON3N( (A1,B1,D1), (cont3) ); cont4 = ( (A2,N3), (B2,N3), (C2,N2), (D2,N2) ); polygon4 = POLYGON3N( (A2,B2,D2), (cont4) ); front1 = FRONT_MATERIAL ( (0.05, 0.15, 0.075, 1.0), (0.0125, 0.0375, 0.019, 1.0), (0.0, 0.0, 0.0, 1.0), (0.2, 0.6, 0.3, 1.0), 0.5 ); back1 = BACK_MATERIAL ( (0.3, 0.15, 0.12, 1.0), (0.075, 0.0375, 0.03, 1.0), (0.0, 0.0, 0.0, 1.0), (0.8, 0.4, 0.3, 1.0), 0.5 ); node1 = SCENENODE ( (), (TRANSFORMS(TRNSF3PT((15,0,0),(16,0,0),(15,1,0)))), (polygon3,polygon4) ); SCENEROOT = SCENENODE( (node1), (ATTRIBS(front1,back1)), (polygon1,polygon2) );

Example 37 produces the same result as Example 36 (see Figure 5.37), but this time the smoothing effect is achieved by using the function CALCNORMALS. This function expects a list of POLYGON3 or POLYGON3T nodes as its parameter. It creates a copy of this list, and replaces all POLYGON3 or POLYGON3T nodes in the copy with POLYGON3N or POLYGON3TN nodes. The function result can be referenced by the child node selection operator [..] .

**Example 37:**` (`taken from:` data/examples/polygon3_5.dat (7.36))`

A1 = (0.,0.,0.); B1 = (10.,0.,0.); C1 = (10.,10.,5.); D1 = (0.,10.,5.); A2 = D1; B2 = C1; C2 = (10.,20.,0.); D2 = (0.,20.,0.); cont1 = (A1,B1,C1,D1); polygon1 = POLYGON3( (A1,B1,D1), (cont1) ); cont2 = (A2,B2,C2,D2); polygon2 = POLYGON3( (A2,B2,D2), (cont2) ); polygroup1 = (polygon1,polygon2); node1 = SCENENODE ( (), (), polygroup1 ); func1 = CALCNORMALS( (polygroup1) ); node2 = SCENENODE( (), (TRANSFORMS( TRNSF3PT((15,0,0),(16,0,0),(15,1,0)) )), [func1] ); SCENEROOT = SCENENODE( (node1,node2), (ATTRIBS(front1,back1)), () );

Example 38 does the same as Example 37, but this time with textured polygons. The result is shown in Figure 5.38.

**Example 38:**` (`taken from:` data/examples/polygon3_6.dat (7.37))`

A1 = (0.,0.,0.); B1 = (10.,0.,0.); C1 = (10.,10.,5.); D1 = (0.,10.,5.); TA1 = (0.,0.); TB1 = (1.,0.); TC1 = (1.,1.); TD1 = (0.,1.); A2 = D1; B2 = C1; C2 = (10.,20.,0.); D2 = (0.,20.,0.); cont1 = ((A1,TA1),(B1,TB1),(C1,TC1),(D1,TD1)); polygon1 = POLYGON3T( (A1,B1,D1), (cont1) ); cont2 = ((A2,TA1),(B2,TB1),(C2,TC1),(D2,TD1)); polygon2 = POLYGON3T( (A2,B2,D2), (cont2) ); polygroup1 = (polygon1,polygon2); node1 = SCENENODE ( (), (), polygroup1 ); func1 = CALCNORMALS( (polygroup1) ); node2 = SCENENODE( (), (TRANSFORMS( TRNSF3PT((15,0,0),(16,0,0),(15,1,0)) )), [func1] ); teximg1 = TEXIMAGE2D( ( ((1,0,0,1), (0,1,0,1)), ((0,0,1,1), (1,1,0,1)) ) ); SCENEROOT = SCENENODE( (node1,node2), (ATTRIBS( teximg1, USETEXIMG(2), USETEXWRAPX(1), USETEXWRAPY(1), USETEXMAGTONEAREST(1), USETEXMINTONEAREST(1)) ), () );