Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void DirectXRenderer::render(Scene* a_scene)
- {
- m_D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
- D3DCOLOR_XRGB( 100, 255, 100 ), 1.0f, 0 );
- model=new Model("test",L"filename",this->getDevice());
- Texture* texture = new Texture("Banana", L"banana.bmp", m_D3DDevice);
- // Begin the scene
- if( SUCCEEDED( m_D3DDevice->BeginScene() ) )
- {
- // Setup the world, view, and projection matrices// Set up world matrix
- D3DXMATRIXA16 matWorld;
- D3DXMatrixIdentity( &matWorld );
- D3DXMatrixRotationX( &matWorld, 130 );
- m_D3DDevice->SetTransform( D3DTS_WORLD, &matWorld );
- // Set up our view matrix. A view matrix can be defined given an eye point,
- // a point to lookat, and a direction for which way is up. Here, we set the
- // eye five units back along the z-axis and up three units, look at the
- // origin, and define "up" to be in the y-direction.
- D3DXVECTOR3 vEyePt( 0.0f, 5.0f,-20.0f );
- D3DXVECTOR3 vLookatPt( 0.0f, 5.0f, 0.0f );
- D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
- D3DXMATRIXA16 matView;
- D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
- m_D3DDevice->SetTransform( D3DTS_VIEW, &matView );
- // For the projection matrix, we set up a perspective transform (which
- // transforms geometry from 3D view space to 2D viewport space, with
- // a perspective divide making objects smaller in the distance). To build
- // a perpsective transform, we need the field of view (1/4 pi is common),
- // the aspect ratio, and the near and far clipping planes (which define at
- // what distances geometry should be no longer be rendered).
- D3DXMATRIXA16 matProj;
- D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI / 4, 1.0f, 1.0f, 100.0f );
- m_D3DDevice->SetTransform( D3DTS_PROJECTION, &matProj );
- //SetupMatrices();
- // Meshes are divided into subsets, one for each material. Render them in
- // a loop
- /*
- frames++;
- for( DWORD i = 0; i < g_dwNumMaterials; i++ )
- {
- // Set the material and texture for this subset
- g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
- g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );
- //D3DTRANSFORMSTATETYPE tst = //g_pd3dDevice->SetTransform(?, ?);
- // Draw the mesh subset
- D3DXMATRIXA16 matWorld2;
- D3DXMatrixRotationY( &matWorld2, timeGetTime() / 1000.0f );
- g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld2 );
- g_pMesh->DrawSubset( i );
- D3DXMATRIXA16 matPosition, matRotationY, matRotationX, matWorld;
- D3DXMatrixTranslation(&matPosition, 0.0f, 1.0f, 0.0f);//x,y,z
- D3DXMatrixRotationY( &matRotationY, (frames/60)*0.1f);
- D3DXMatrixRotationX( &matRotationX, frames / 500.0f );
- matWorld = matPosition*matRotationY*matRotationX;
- g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
- g_pMesh->DrawSubset( i );
- }*/
- model->showModel();
- texture->show(m_VertexBuffer);
- // End the scene
- m_D3DDevice->EndScene();
- }
- // Present the backbuffer contents to the display
- m_D3DDevice->Present( NULL, NULL, NULL, NULL );
- //this->getWindow()->update();
- delete model;
- delete texture;
- }
- Model::~Model(void)
- {
- if(NULL != m_Mesh)
- {
- m_Mesh->Release();
- m_Mesh = NULL;
- }
- //delete m_Mesh;
- if(NULL != m_Material)
- {
- //m_Material->Release();
- delete m_Material;
- }
- m_Material = NULL;
- if(NULL != m_Texture)
- {
- //(&m_Texture)->Release();
- delete m_Texture;
- }
- m_Texture = NULL;
- }
- HRESULT Model::load()
- {
- LPD3DXBUFFER materialBuffer;
- m_FileName=L"Tiger.x";
- if(FAILED(D3DXLoadMeshFromX(m_FileName, D3DXMESH_SYSTEMMEM, m_Device, NULL, &materialBuffer, NULL, &m_NumMaterials, &m_Mesh)))
- {
- return E_FAIL;
- }
- D3DXMATERIAL* d3dxMaterials=(D3DXMATERIAL*)materialBuffer->GetBufferPointer();
- m_Material=new D3DMATERIAL9[m_NumMaterials];
- if(NULL == m_Material)
- return E_OUTOFMEMORY;
- m_Texture=new LPDIRECT3DTEXTURE9[m_NumMaterials];
- if(NULL == m_Texture)
- return E_OUTOFMEMORY;
- for( DWORD i=0; i < m_NumMaterials; i++)
- {
- m_Material[i]=d3dxMaterials[i].MatD3D;
- m_Material[i].Ambient = m_Material[i].Diffuse;
- m_Texture[i]=NULL;
- if(d3dxMaterials[i].pTextureFilename != NULL && lstrlenA(d3dxMaterials[i].pTextureFilename) > 0)
- {
- if(FAILED(D3DXCreateTextureFromFileA(m_Device, d3dxMaterials[i].pTextureFilename, &m_Texture[i])))//Internal leaks caused here
- {
- const CHAR* strPrefix = "..\\";
- CHAR strTexture[MAX_PATH];
- strcpy_s( strTexture, MAX_PATH, strPrefix );
- strcat_s( strTexture, MAX_PATH, d3dxMaterials[i].pTextureFilename);
- if( FAILED( D3DXCreateTextureFromFileA( m_Device,
- strTexture,
- &m_Texture[i] ) ) )
- {
- MessageBox( NULL, L"Could not find texture map", L"Meshes.exe", MB_OK );
- }
- }
- }
- }
- materialBuffer->Release();
- return S_OK;
- }
- LPD3DXMESH Model::getMesh()
- {
- return m_Mesh;
- }
- DWORD Model::getNumMaterials()
- {
- return m_NumMaterials;
- }
- D3DMATERIAL9* Model::getMaterial()
- {
- return m_Material;
- }
- LPDIRECT3DTEXTURE9* Model::getTexture()
- {
- return m_Texture;
- }
- void Model::showModel()
- {
- for(DWORD i=0; i < m_NumMaterials; i++)
- {
- m_Device->SetMaterial(&m_Material[i]);
- m_Device->SetTexture(0,m_Texture[i]);
- m_Mesh->DrawSubset(i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement