Esempio n. 1
0
void MyTorus::draw(int p_num, int t_num){
    calPoint(p_num,t_num);

    if(wire)
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    else{
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        if(flat)
            glShadeModel(GL_FLAT);
        if(smooth || smoothExact)
            glShadeModel(GL_SMOOTH);
    }
    glBegin(GL_QUADS);

    glColor3f(1,0,0);
    colorChoose();
    if(wire)
        wireFrame();
    else{
        if(flat)
            flatShading();
        /*if(smooth)
            smoothShading();*/
        if(smoothExact)
            smoothExactShading();
     }

    glEnd();
}
Esempio n. 2
0
// Build the full landscape using the previously set flags.
void BoidsLand::build( CFrameWnd *win, LPDIRECT3DRM d,
					  LPDIRECT3DRMFRAME s, D3DRMRENDERQUALITY solidStyle )
{
	window = win;
	d3drm = d;  // Store two pointers to the D3D interfaces inside the object.
	scene = s;  // This helps to keep future calls to the object concise.

	// Abort the build if nothing to do.
	if ( solidOn == false && wireframeOn == false )
	{
		return;
	}

	// Calculate the uniform sizes of all the landscape patches.
	xSpacing = X_LIMIT * 2 / LAND_X_SIZE;
	ySpacing = LAND_HEIGHT;
	zSpacing = Z_LIMIT * 2 / LAND_Z_SIZE;


	// Create the main landscape root frame.
	d3drm -> CreateFrame( scene, &landFrame );
	landFrame -> SetPosition( scene, D3DVALUE( 0.0 ),
										D3DVALUE( 0.0 ), D3DVALUE( 0.0 ) );

	// Create the landscape mesh.
	d3drm -> CreateMesh( &landMesh );


	// Used for producing each patch of land.
	D3DRMVERTEX patchVertices[ 6 ];
	unsigned vertOrder[] = { 0, 1, 2, 3, 4, 5 };


	// Generate the surface for the landMesh.
	for ( int row = 0; row < LAND_Z_SIZE; row++ )
	{
		for ( int col = 0; col < LAND_X_SIZE; col++ )
		{
			// Create the solid representation if required.
			if ( solidOn )
			{
				landMesh -> AddGroup( 6, 2, 3, vertOrder,
										&patchGroups[ 0 ][ row ][ col ] );
			}

			// Create the wireframe overlay if required.
			if ( wireframeOn )
			{
				landMesh -> AddGroup( 6, 2, 3, vertOrder,
										&patchGroups[ 1 ][ row ][ col ] );
			}


			// Call the auxillary function to position the land patch.
			positionPatch( patchVertices, row, col );


			// Apply flat shading to the patch of land.
			if ( solidOn )
			{
				flatShading( row, col, patchVertices );
			}


			// Complete the production of the patch of -
			// - land for solid representation.
			if ( solidOn )
			{
				landMesh -> SetVertices( patchGroups[ 0 ][ row ][ col ],
													0, 6, patchVertices );
				landMesh -> SetGroupQuality(
							patchGroups[ 0 ][ row ][ col ], solidStyle );


				// Set the landscape's colours.
				// Colour the central tower brown.
				if ( row == 4 && col == 4 )
				{
					// Brown.
					landMesh -> SetGroupColor(
								patchGroups[ 0 ][ row ][ col ], RGB_BROWN );
				}
				else  // Colour the land.
				{
					if  ( solidColour == LSC_CHECKERED )
					{
						// Colour the land checkered style.
						if ( row % 2 == 0 )
						{
							if ( col % 2 == 0 )
							{
								// Black.
								landMesh -> SetGroupColor(
									patchGroups[ 0 ][ row ][ col ], RGB_BLACK );
							}
							else
							{
								// White.
								landMesh -> SetGroupColor(
									patchGroups[ 0 ][ row ][ col ], RGB_WHITE );
							}
						}
						else
						{
							if ( col % 2 == 0 )
							{
								// White.
								landMesh -> SetGroupColor(
									patchGroups[ 0 ][ row ][ col ], RGB_WHITE );
							}
							else
							{
								// Black.
								landMesh -> SetGroupColor(
									patchGroups[ 0 ][ row ][ col ], RGB_BLACK );
							}
						}
					}

					if  ( solidColour == LSC_GREEN )
					{
						// Colour the land green.
						landMesh -> SetGroupColor(
							patchGroups[ 0 ][ row ][ col ], RGB_LAND_GREEN );
					}
				}
			}


			if ( wireframeOn )
			{
				// Complete the production of the patch of land.
				landMesh -> SetVertices( patchGroups[ 1 ][ row ][ col ],
														0, 6, patchVertices );
				landMesh -> SetGroupQuality( patchGroups[ 1 ][ row ][ col ],
													D3DRMRENDER_WIREFRAME );
				// Set the wireframe landscape colour.
				if ( solidOn )
				{
					// Black.
					landMesh -> SetGroupColor(
								patchGroups[ 1 ][ row ][ col ], RGB_BLACK );
				}
				else
				{
					// If there is no solid land, colour -
					// - the wireframe black for clarity.
					// Black.
					landMesh -> SetGroupColor(
								patchGroups[ 1 ][ row ][ col ], RGB_BLACK );
				}

			}

			// If the patch of land was a tower, add the sides of the tower.
			if ( row == 4 && col == 4 )
			{
				buildTowerSides( row, col );
			}
		}
	}


	// Add the land to the land frame.
	landFrame -> AddVisual(	landMesh );

	// Apply gouraud shading to the landscape if selected.
	if ( solidStyle == D3DRMRENDER_GOURAUD && solidOn )
	{
		gouraudShading( );
	}

	exists = true;  // Set the flag.
}