Near/far clipping

Started by
8 comments, last by Funkodysse 22 years, 2 months ago
Hi. i would like to know how to set near/far clipping. could anyone be so kind and tell me Edited by - Funkodysse on January 31, 2002 10:31:12 AM
Advertisement
hello hello.
i hope u havent forgot me
could you be more specific? in general, in d3d7/8, you set up the near/far clipping plane values when you set up the projection matrix
Most likely you use D3DXMatrixPerspectiveFovLH or a similar function to set up the projection matrix (both 7 and 8)

two of the paramiters set the veiw plane, check it out in the SDK!

DX8.

i tried this but not work.

D3DVIEWPORT8 Viewport;
Viewport.X=0;
Viewport.Y=0;
Viewport.Width=800;
Viewport.Height=600;
Viewport.MinZ=-1000.0f; //near clipping
Viewport.MaxZ=1000.0f; //far clipping
g_pDevice->SetViewport(&Viewport);
No no no, MinZ and MaxZ are the depth buffer values, not the near/far clipping planes.
D3DXMatrixPerspectiveFovRH( &ProjectionMatrix,                            FOV * 0.5f,                            float(Viewport.Width) / float(Viewport.Height),                            NearDistance,                            FarDistance ); 

Near may be 0.125, Far may be 1000, for example. Both must be greater than zero.

~CGameProgrammer( );

~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
D3DVIEWPORT8 Viewport;
Viewport.X=0;
Viewport.Y=0;
Viewport.Width=800;
Viewport.Height=600;
Viewport.MinZ=-1000.0f;
Viewport.MaxZ=1000.0f;
g_pDevice->SetViewport(&Viewport);
D3DXMatrixLookAtLH(&g_ViewMatrix,&D3DXVECTOR3(0.0f,0.0f,-5.0f), &D3DXVECTOR3(0.0f,0.0f,0.0f), &D3DXVECTOR3(0.0f,1.0f,0.0f));
g_pDevice->SetTransform(D3DTS_VIEW,&g_ViewMatrix);
D3DXMatrixPerspectiveFovLH( &g_matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
g_pDevice->SetTransform( D3DTS_PROJECTION, &g_matProj );
D3DXMatrixPerspectiveFovRH( &g_matProj,0.5f,float(Viewport.Width) / float(Viewport.Height),-1000, -300); //far,near



It aint worked
This is your error:

Viewport.MinZ=-1000.0f;
Viewport.MaxZ=1000.0f;

MinZ and MaxZ must be between 0 and 1 (being a percentage of your far clip distance in D3DXPerspectiveFovLH).

Neil

WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
hi.

i removed the viewport and D3DXMatrixPerspectiveFovRH and just changed the D3DXMatrixPerspectiveFovLH( &g_matProj, D3DX_PI/4, 1.0f, 0.1f, 500.0f ); to this.

and it worked..

thanks anyway.
Yeah, I just wrote the RH function because I use right-handed math. Never mix left-handed and right-handed functions.

~CGameProgrammer( );

~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.

This topic is closed to new replies.

Advertisement