Esempio n. 1
0
void Tessellation(	Node& n1, Node& n2, Node& n3, Vertices& vertices, Indices& indices,
					unsigned curDepth, unsigned maxDepth )
{
	if( curDepth<maxDepth )
	{
		Node *n12 = GetOrCreateChild(n1, n2, vertices);
		Node *n23 = GetOrCreateChild(n2, n3, vertices);
		Node *n31 = GetOrCreateChild(n3, n1, vertices);
		Tessellation( n1, *n12, *n31, vertices, indices, curDepth+1, maxDepth );
		Tessellation( n2, *n23, *n12, vertices, indices, curDepth+1, maxDepth );
		Tessellation( n3, *n31, *n23, vertices, indices, curDepth+1, maxDepth );
		Tessellation( *n12, *n23, *n31, vertices, indices, curDepth+1, maxDepth );

	}
	else
	{
		indices.push_back( n1.GetIndex() );
		indices.push_back( n2.GetIndex() );
		indices.push_back( n3.GetIndex() );
	}
}
Esempio n. 2
0
void InitVertices(	unsigned recursionDepth, float edgeSize,
					Vertices &pyramidVertices,
					Indices &pyramidIndices)
{
	assert( 0 == pyramidIndices.size() );
	assert( 0 == pyramidVertices.size() );

	std::vector<Node> nodes;

	const float alpha = atanf( sqrtf(2.0f) );
	const float cosAlpha = cosf(alpha);
	const float sinAlpha = sinf(alpha);

	//top right triangle
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f, -edgeSize/ 2,
										sinAlpha,  cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f,  edgeSize/ 2,
										sinAlpha,  cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex(  0.0f,  edgeSize*sqrtf(2.0f)/2, 0.0f,
										sinAlpha,  cosAlpha,  0.0f ) );

	//top back triangle
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f,  edgeSize/ 2,
										0.0f,  cosAlpha,  sinAlpha ) );
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f,  edgeSize/ 2,
										0.0f,  cosAlpha,  sinAlpha ) );
	pyramidVertices.push_back( Vertex(  0.0f,  edgeSize*sqrtf(2.0f)/2, 0.0f,
										0.0f,  cosAlpha,  sinAlpha ) );

	//top left triangle
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f,  edgeSize/ 2,
									   -sinAlpha,  cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f, -edgeSize/ 2,
									   -sinAlpha,  cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex(  0.0f,  edgeSize*sqrtf(2.0f)/2, 0.0f,
									   -sinAlpha,  cosAlpha,  0.0f ) );

	//top fron triangle
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f, -edgeSize/ 2,
										0.0f,  cosAlpha, -sinAlpha ) );
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f, -edgeSize/ 2,
										0.0f,  cosAlpha, -sinAlpha ) );
	pyramidVertices.push_back( Vertex(  0.0f,  edgeSize*sqrtf(2.0f)/2, 0.0f,
										0.0f,  cosAlpha, -sinAlpha ) );



	//bottom right triangle
	pyramidVertices.push_back( Vertex(  0.0f, -edgeSize*sqrtf(2.0f)/2, 0.0f,
										sinAlpha, -cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f, -edgeSize/ 2,
										sinAlpha, -cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f,  edgeSize/ 2,
										sinAlpha, -cosAlpha,  0.0f ) );

	//bottom back triangle
	pyramidVertices.push_back( Vertex(  0.0f, -edgeSize*sqrtf(2.0f)/2, 0.0f,
										0.0f, -cosAlpha,  sinAlpha ) );
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f,  edgeSize/ 2,
										0.0f, -cosAlpha,  sinAlpha ) );
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f,  edgeSize/ 2,
										0.0f, -cosAlpha,  sinAlpha ) );

	//bottom left triangle
	pyramidVertices.push_back( Vertex(  0.0f, -edgeSize*sqrtf(2.0f)/2, 0.0f,
									   -sinAlpha, -cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f,  edgeSize/ 2,
									   -sinAlpha, -cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f, -edgeSize/ 2,
									   -sinAlpha, -cosAlpha,  0.0f ) );

	//bottom fron triangle
	pyramidVertices.push_back( Vertex(  0.0f, -edgeSize*sqrtf(2.0f)/2, 0.0f,
										0.0f, -cosAlpha, -sinAlpha ) );
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f, -edgeSize/ 2,
										0.0f, -cosAlpha, -sinAlpha ) );
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f, -edgeSize/ 2,
										0.0f, -cosAlpha, -sinAlpha ) );


	for( Index index=0; index<pyramidVertices.size(); ++index )
	{
		nodes.push_back( Node(NULL, NULL, index) );
	}

	for( unsigned i=0; i<nodes.size(); i+=3 )
	{
		Tessellation( nodes[i], nodes[i+1], nodes[i+2], pyramidVertices, pyramidIndices, 0, recursionDepth );
	}		
}
Esempio n. 3
0
	Tessellation getTessellation()
	{
		return Tessellation(Cmiss_graphic_get_tessellation(id));
	}