Original Post
Hello, I have a problem with my camera class.Whenever I get close to an object it is clipped by the camera.I tried setting the near clipping plane to 0.0f and turning clipping off when rendering , but it does not work.Here is the the code that I use for the camera and projection matrix (it's from the directx 7.0 sdk): [Edited by - Muhammad Haggag on December 12, 2005 3:16:05 PM]
void __fastcall TCamera::SetCamera(void)
{
D3DMATRIX CameraMatrix;
D3DVECTOR View=Substract(LookAtPoint,EyePoint),Up,Right,DefaultYUp,DefaultZUp;
float Length,dot_product;
DefaultYUp.x=0.0f;DefaultZUp.x=0.0f;
DefaultYUp.y=1.0f;DefaultZUp.y=0.0f;
DefaultYUp.z=0.0f;DefaultZUp.z=1.0f;
Length=Magnitude(View);
if(Length <1e-6f) return;
View=Normalize(View,Length);
dot_product=DotProduct(UpVector,View);
Up=Substract(UpVector,Scale(View,dot_product));
if(1e-6f>(Length=Magnitude(Up)))
{
Up=Substract(DefaultYUp,Scale(View,View.y));
if(1e-6f>(Length=Magnitude(Up)));
{
Up=Substract(DefaultZUp,Scale(View,View.z));
if(1e-6f>(Length=Magnitude(Up))) return;
}
}
Up=Normalize(Up,Length);
Right=CrossProduct(Up,View);
CameraMatrix._11=Right.x; CameraMatrix._12=Up.x; CameraMatrix._13=View.x;
CameraMatrix._21=Right.y; CameraMatrix._22=Up.y; CameraMatrix._23=View.y;
CameraMatrix._31=Right.z; CameraMatrix._32=Up.z; CameraMatrix._33=View.z;
CameraMatrix._41=-DotProduct(EyePoint,Right);
CameraMatrix._42=-DotProduct(EyePoint,Up);
CameraMatrix._43=-DotProduct(EyePoint,View);
CameraMatrix._14=0;
CameraMatrix._24=0;
CameraMatrix._34=0;
CameraMatrix._44=1;
D3DDevice->SetTransform(D3DTS_VIEW,&CameraMatrix);
};
void __fastcall TCamera::SetProjectionMatrix(void)
{
D3DMATRIX ProjectionMatrix;
float H,W,Q;
W=(float)(1/tan(HFOV*0.5));
H=(float)(1/tan(VFOV*0.5));
Q=FarPlane/(FarPlane - NearPlane);
ProjectionMatrix._12=ProjectionMatrix._13=ProjectionMatrix._14=0;
ProjectionMatrix._21=ProjectionMatrix._23=ProjectionMatrix._24=0;
ProjectionMatrix._31=ProjectionMatrix._32=ProjectionMatrix._34=0;
ProjectionMatrix._41=ProjectionMatrix._42=ProjectionMatrix._43=0;
ProjectionMatrix._11=W;
ProjectionMatrix._22=H;
ProjectionMatrix._33=Q;
ProjectionMatrix._43=-Q*NearPlane;
ProjectionMatrix._34=1;
D3DDevice->SetTransform(D3DTS_PROJECTION,&ProjectionMatrix);
};