Beispiel #1
0
void C3d::Open(const TriFile &tfile)
{
	Cleanup();
	rotation = true;
	if( FAILED( g_pd3dDevice->CreateVertexBuffer(tfile.header.numVertices*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL)))
		return;
	CUSTOMVERTEX* pVertices;
	if( FAILED( g_pVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )
		return;
	vcount = tfile.header.numVertices;
	if(tfile.hasTangentsBinormals)
	{
		for( DWORD i=0; i<tfile.header.numVertices; i++ )
		{
			pVertices[i].position = tfile.verticestb(i)->vertexPosition;
			pVertices[i].normal   = tfile.verticestb(i)->vertexNormal;
			pVertices[i].uv   = tfile.verticestb(i)->vertexUV;
		}
	}else{
		for( DWORD i=0; i<tfile.header.numVertices; i++ )
		{
			pVertices[i].position = tfile.verticesc(i)->vertexPosition;
			pVertices[i].normal   = tfile.verticesc(i)->vertexNormal;
			pVertices[i].uv   = tfile.verticesc(i)->vertexUV;
		}
	}
	ComputeBoundingSphere(pVertices, vcount, &vCenter, &vRadius);
	g_pVB->Unlock();
	D3DVIEWPORT9 vp;
	g_pd3dDevice->GetViewport(&vp);
	vp.MinZ = -((int)vRadius/300)*55.0f;
	g_pd3dDevice->SetViewport(&vp);
	D3DXMatrixIdentity( &matWorld );
	MatrixTranslation( &matWorld, vCenter.x, -vCenter.y, -vCenter.z );
	DWORD *indices=NULL;
	
	ClearIndexes();
	ClearTextures();
	g_pTexture.resize(tfile.header.numSurfaces);
	for(unsigned int i = 0; i < tfile.header.numSurfaces; i++)
			g_pTexture[i] = NULL;
	g_pIB.resize(tfile.header.numSurfaces);
	fcount.resize(tfile.header.numSurfaces);
	for(dword i = 0; i < tfile.header.numSurfaces; i++)
	{
		g_pd3dDevice->CreateIndexBuffer(tfile.surfaces[i].numTriangles*3*4,D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_MANAGED, &g_pIB[i], NULL);
		g_pIB[i]->Lock( 0, 0, (void**)&indices, 0 );

		for(dword c = 0; c < tfile.surfaces[i].numTriangles; c++)
		{
			indices[3*c] = tfile.triangles[i][c][0];
			indices[3*c+1] = tfile.triangles[i][c][1];
			indices[3*c+2] = tfile.triangles[i][c][2];
		}
		g_pIB[i]->Unlock();

		fcount[i] = tfile.surfaces[i].numTriangles;
	}
	loaded = true;
}
Beispiel #2
0
bool
QueryProcessor::InitializeIndexes( Rectangles& r, bool useSummaries )
{
	AllDimensions::iterator		aitr;
	ClassAdIndex				*index;
	Rectangles					*rec = useSummaries ? &summaries : &r;
	
	ClearIndexes( );

	summarize = useSummaries;
	rectangles = &r;

		// summarize the rectangles
	if( useSummaries ) {
		if( !summaries.Summarize( r, reps, consts, constRepMap ) ) {
			printf( "Failed to summarize\n" );
			return( false );
		}
		summaries.Complete( true );
	}
	r.Complete( true );

	for(aitr=rec->exportedBoxes.begin();aitr!=rec->exportedBoxes.end();aitr++) {
		if( (aitr->first)[1] != ':' ) return( false );
		switch( (aitr->first)[0] ) {
			case 'n':
			case 'i':
			case 't':
				index = ClassAdNumericIndex::MakeNumericIndex( aitr->second );
				break;
					
			case 'b':
			case 'u':
				index = ClassAdBooleanIndex::MakeBooleanIndex( aitr->second );
				break;

			case 's':
				index = ClassAdStringIndex::MakeStringIndex( aitr->second );
				break;

			default:
				printf( "Error:  Unknown type prefix %c\n", (aitr->first)[0] );
				return( false );
		}
		if( !index ) {
			ClearIndexes( );
			return( false );
		}
		exported[aitr->first] = index;
	}


	for(aitr=rec->importedBoxes.begin();aitr!=rec->importedBoxes.end();aitr++) {
		if( (aitr->first)[1] != ':' ) return( false );
		switch( (aitr->first)[0] ) {
			case 'n':
			case 'i':
			case 't':
				index = ClassAdNumericIndex::MakeNumericIndex( aitr->second );
				break;
					
			case 'b':
			case 'u':
				index = ClassAdBooleanIndex::MakeBooleanIndex( aitr->second );
				break;

			case 's':
				index = ClassAdStringIndex::MakeStringIndex( aitr->second );
				break;

			default:
				printf( "Error:  Unknown type prefix %c\n", (aitr->first)[0] );
				return( false );
		}
		if( !index ) {
			ClearIndexes( );
			return( false );
		}
		imported[aitr->first] = index;
	}

	return( true );
}
Beispiel #3
0
void C3d::Cleanup()
{
	distance = 1.0f;
	SAFE_RELEASE(g_pVB);
	ClearIndexes();
}
Beispiel #4
0
QueryProcessor::~QueryProcessor( )
{
	ClearIndexes( );
}