Esempio n. 1
0
HRESULT InitialiseEnvironment( LPDIRECT3DDEVICE3 lpd3dDevice,
                               LPDIRECT3DVIEWPORT3 pvViewport, HWND hwnd )
{

	if ( !  LoadFile("resource/Human1.asc", Human->currentFrame, 100 ) )
		return E_FAIL;
	
	if (!Human->AdvanceFrame()) return E_FAIL;

	if ( !  LoadFile("resource/Human15.asc", Human->currentFrame, 100)  )
		return E_FAIL;
	
		
Human->AdvanceFrame();
	if ( !  LoadFile("resource/Human2.asc", Human->currentFrame, 100)  )
		return E_FAIL;	
if (!Human->AdvanceFrame()) return E_FAIL;
	if ( !  LoadFile("resource/Human25.asc", Human->currentFrame, 100)  )
		return E_FAIL;
Human->AdvanceFrame();	
	if ( !  LoadFile("resource/Human3.asc", Human->currentFrame, 100)  )
		return E_FAIL;
Human->AdvanceFrame();
	if ( !  LoadFile("resource/Human35.asc", Human->currentFrame, 100)  )
		return E_FAIL;
Human->AdvanceFrame();	
	if ( ! LoadFile("resource/Human4.asc", Human->currentFrame, 100)  )
		return E_FAIL;
Human->AdvanceFrame();	
	if ( ! LoadFile("resource/Human45.asc", Human->currentFrame, 100)  )
		return E_FAIL;
Human->AdvanceFrame();
	if ( ! LoadFile("resource/Human5.asc", Human->currentFrame, 100)  )
		return E_FAIL;
Human->AdvanceFrame();	
	if ( ! LoadFile("resource/Human55.asc", Human->currentFrame, 100)  )
		return E_FAIL;
Human->AdvanceFrame();
	if ( ! LoadFile("resource/Human6.asc", Human->currentFrame, 100)  )
		return E_FAIL;
Human->AdvanceFrame();	
	if ( ! LoadFile("resource/Human65.asc", Human->currentFrame, 100)  )
		return E_FAIL;
Human->AdvanceFrame();

	cout << "Files Loaded" << endl << flush;

	if (! Human->LoadTextures(Textures, lpd3dDevice, hwnd) ) return E_FAIL;

	cout << "Textures Loaded" << endl << flush;

	// Get a ptr to the ID3D object to create materials and/or lights. Note:
	// the Release() call just serves to decrease the ref count.
    
	LPDIRECT3D3 pD3D;
    if( FAILED( lpd3dDevice->GetDirect3D( &pD3D ) ) ) return E_FAIL;
    pD3D->Release();

    // Create the object material. This material will be used to draw the
	// triangle. Note: that when we use textures, the object material is
	// usually omitted or left as white.

    if( FAILED( pD3D->CreateMaterial( &g_pmtrlObjectMtrl, NULL ) ) )
        return E_FAIL;

	if( FAILED( pD3D->CreateMaterial( &g_pmtrlObjectMtrl2, NULL ) ) )
        return E_FAIL;

	// Set the object material as yellow. We're setting the ambient color here
	// since this tutorial only uses ambient lighting. For apps that use real
	// lights, the diffuse and specular values should be set. (In addition, the
	// polygons' vertices need normals for true lighting.)
    D3DMATERIAL       mtrl;
	D3DMATERIAL		mtrl2;
    D3DMATERIALHANDLE hmtrl;

	ZeroMemory( &mtrl, sizeof(D3DMATERIAL) );
    mtrl.dwSize       = sizeof(D3DMATERIAL);
    mtrl.dcvDiffuse.r = mtrl.dcvAmbient.r = 1.0f;
    mtrl.dcvDiffuse.g = mtrl.dcvAmbient.g = 1.0f;
    mtrl.dcvDiffuse.b = mtrl.dcvAmbient.b = 1.0f;
    mtrl.dcvDiffuse.a = mtrl.dcvAmbient.a = 1.0f;
    mtrl.dwRampSize   = 16L; // A default ramp size
	mtrl.power = 40.0f;
    g_pmtrlObjectMtrl->SetMaterial( &mtrl );

	ZeroMemory( &mtrl2, sizeof(D3DMATERIAL) );
    mtrl2.dwSize       = sizeof(D3DMATERIAL);
	mtrl2.dcvAmbient.r = 0.7f;
    mtrl2.dcvAmbient.g = 0.6f;
    mtrl2.dcvAmbient.b = 0.2f;
    g_pmtrlObjectMtrl2->SetMaterial( &mtrl2 );
	

	lpd3dDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, TRUE );
	lpd3dDevice->SetRenderState( D3DRENDERSTATE_TEXTUREPERSPECTIVE, TRUE );
	lpd3dDevice->SetRenderState( D3DRENDERSTATE_SUBPIXEL, TRUE );
	lpd3dDevice->SetRenderState( D3DRENDERSTATE_FILLMODE, D3DRENDERSTATE_FILLMODE );
	lpd3dDevice->SetRenderState( D3DRENDERSTATE_CULLMODE, D3DCULL_NONE );
	lpd3dDevice->SetRenderState( D3DRENDERSTATE_DITHERENABLE, FALSE );

	// Put the object material into effect. Direct3D is a state machine, and
	// calls like this set the current state. After this call, any polygons
	// rendered will be drawn using this material.
    g_pmtrlObjectMtrl->GetHandle( lpd3dDevice, &hmtrl );
    lpd3dDevice->SetLightState(  D3DLIGHTSTATE_MATERIAL, hmtrl );

	// The ambient lighting value is another state to set. Here, we are turning
	// ambient lighting on to full white.
    lpd3dDevice->SetLightState(  D3DLIGHTSTATE_AMBIENT,  0xffffffff );

//	lpd3dDevice->SetRenderState( D3DRENDERSTATE_FILLMODE, D3DFILL_WIREFRAME );
//	lpd3dDevice->SetRenderState( D3DRENDERSTATE_CULLMODE, D3DCULL_CCW );

    // Set the transform matrices. Direct3D uses three independant matrices:
	// the world matrix, the view matrix, and the projection matrix. For
	// convienence, we are first setting up an identity matrix.
    D3DMATRIX mat;
	mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
	mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
	mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
	mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
	
	// The world matrix controls the position and orientation of the polygons
	// in world space. We'll use it later to spin the triangle.
	D3DMATRIX matWorld = mat;
	matWorld._22 = 0.75f;
	matWorld._11 = 0.75f;
    lpd3dDevice->SetTransform( D3DTRANSFORMSTATE_WORLD, &matWorld );

	// The view matrix defines the position and orientation of the camera.
	// Here, we are just moving it back along the z-axis by 10 units.
	D3DMATRIX matView = mat;
	matView._43 = VIEW_DISTANCE;
//	matView._42 = -100.0f;
    lpd3dDevice->SetTransform( D3DTRANSFORMSTATE_VIEW, &matView );

	// The projection matrix defines how the 3D scene is "projected" onto the
	// 2D render target (the backbuffer surface). Refer to the docs for more
	// info about projection matrices.
	D3DMATRIX matProj = mat;
	matProj._11 =  1.0f;
	matProj._22 =  1.0f;
	matProj._34 =  1.0f;
	matProj._43 =  -1.0f;
	matProj._44 =  1.0f;
    lpd3dDevice->SetTransform( D3DTRANSFORMSTATE_PROJECTION, &matProj );

	if( FAILED( pD3D->CreateLight( &g_pLight, NULL ) ) )
        return E_FAIL;
    
    D3DLIGHT light;

	ZeroMemory( &light, sizeof(D3DLIGHT) );
    light.dwSize       = sizeof(D3DLIGHT);
    light.dltType      = D3DLIGHT_POINT;
    light.dvPosition.x = light.dvDirection.x = 0.0;
    light.dvPosition.y = light.dvDirection.y = 0.0;
    light.dvPosition.z = light.dvDirection.z = -10.0;

    light.dcvColor.r = 1.0;
    light.dcvColor.g = 1.0;
    light.dcvColor.b = 1.0;
    light.dvAttenuation0 = 1.0f;
    g_pLight->SetLight( &light );
    pvViewport->AddLight( g_pLight );

	return S_OK;
}