How to send D3D Device by giving reference ( DirectX/C++ Prgoramming )
H1. I'm trying to depart my codes into different .cpp and .h files to make them find, see and understand easier. Here is what I'm trying to do now: I got a Meshes.cpp wich is my main .cpp source file. In the Render function ( Render() ) I have to call a function that named SetupMatrices:
This is my "d3dGeneral.cpp" file:
// Begining of the "d3dGeneral.cpp"
#include "DXUT.h"
VOID SetupMatrices( LPDIRECT3DDEVICE9 *PDev )
{
D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj,
D3DX_PI / 4,
1.777777777777778f,
1.0f,
1000.0f );
PDev->SetTransform( D3DTS_PROJECTION, &matProj ); // The problem is here......
}
//Enging of the "d3dGeneral.cpp"
And this is my "Meshes.cpp" file: (Which is main cpp file)
// Begining of the "Meshes.cpp" file.
#include "DXUT.h"
#include "XMesh.h"
#include "Camera.h"
#include "d3dGeneral.cpp"
...
...
//Usualy SetupMatrices is found here.
...
...
VOID Render()
{
SetupMatrices( &g_pd3dDevice );
...
...
...
}
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, int nCmdShow)
{
...
...
...
Render();
...
...
...
}
// End of the "Meshes.cpp" file
The header file named DXUT.h contains other general includes. So, when I do this I get an error:
Error 2 error C2227: left of '->SetTransform' must point to class/struct/union/generic type c:\u开发者_运维知识库sers\catt\desktop\deneme\d3dgeneral.cpp 74 MeshClass
I know what that means, but I can't findout how to avoid from it. Looks like I have a problem with pointers. Also I tryed to use PDev like this:
*PDev->SetTransform( D3DTS_PROJECTION, &matProj ); // ???
I know I don't have to use d3dDevice with reference in that function, but I also have a function Cleanup. I think I need to give refrence for it, because it have to clean the real Device itself not the copy of it 8). I hope I explained myself correctly. If you can help me that will be awsome. Thank you for giving your time...
Have you tried this:
(*PDev)->SetTransform( D3DTS_PROJECTION, &matProj );
LPDIRECT3D9DEVICE
is already a pointer. You don't need a pointer to it. Just take LPDIRECT3D9DEVICE
by value.
Of course, I personally prefer to take an IDirect3D9Device*
, as it's clearer, and in addition, I like to store the original pointer in a smart pointer.
精彩评论