Basic Question; projection?

Started by
1 comment, last by kieren_j 24 years, 1 month ago
Please keep in mind this is one of my first attempts at Direct3D.... Here is my init code for D3D (basically): It works, but I''m just putting it in to provde more info.:

	/*
	 * Get Direct3D object
	 */
	lpdd->QueryInterface(IID_IDirect3D7, (LPVOID *)&lpd3d);

	/*
	 * Create a Direct3D device
	 */
	if (D3D_OK != lpd3d->CreateDevice(IID_IDirect3DHALDevice, lpBuffer, &lpDevice))
	{
		if (D3D_OK != lpd3d->CreateDevice(IID_IDirect3DMMXDevice, lpBuffer, &lpDevice))
		{
			lpd3d->CreateDevice(IID_IDirect3DRGBDevice, lpBuffer, &lpDevice);
			DebugEvent("Using RGB device");
		}
		else
			DebugEvent("Using MMX device");
	}
	else
		DebugEvent("Using HAL device");
					
	/*
	 * Set up a viewport
	 */
	ZeroMemory(&Viewdata, sizeof(Viewdata));
	Viewdata.dwWidth = 800;
	Viewdata.dwHeight = 600;
	Viewdata.dvMinZ = D3DVALUE(-10.0);
	Viewdata.dvMaxZ = D3DVALUE(25.0);

	/*
	 * Create the viewport
	 */
	lpDevice->SetViewport(&Viewdata);
 
Anyway, that part works fine - I copied/converted it to DX7 from the "Tile Engine in D3D" article. I also tried using some of the code from this article to render a triangle. However, when I try to introduce the "sz" property of the D3DTLVERTEX structures, I find that they have no visible effect on the screen. I know some basic 3D things, and I think that this is because I need to set up a projection matrix (and I assume this isn''t done in the tile-rendering demos) ? I think that to set up a projection matrix you use IDirect3DDevice7::SetTransform, but I am unsure. Another question for me is how to set up a projection matrix? Thanks for reading
Advertisement
The sz property of D3DTLVERTEX specifies the screenspace z coordinate of the vertex. In effect it is what is written to the z-buffer, you will not see a difference if you change this unless you have two or more triangles that overlap.

The T in D3DTLVERTEX tells means that the vertex is already transformed and DirectX won''t change it. If you want to render projected triangles, you should use D3DVERTEX or D3DLVERTEX.

To set up your projection matrix you can use one of these to build the projection matrix, and then call SetTransform() with it.

D3DXMatrixPerspective()
D3DXMatrixPerspectiveFov()

There are more functions available in D3DX but those are the most commonly used projection matrices.
thx, ill try that

This topic is closed to new replies.

Advertisement