# View and projection matrix for view frustum

This topic is 4253 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, im converting over to c++ and directx from c# and dx and I have a quick question... In my c# view frustum i built the planes using a matrix product of the Device.Transform.View and Device.Transform.Projection matrix's. The problem with the new c++ version is i had to use a vector4 instead of a 3, so im using the .w of the vector4 as the radius to get it to work, but even at that the frustum is very confined. Anyone point me in the right direction, if you need more code please let me know. Cheers. Original C#
Matrix viewProjection = parentDevice.Transform.View * parentDevice.Transform.Projection;


And heres my c++ version...
device->GetTransform(D3DTS_VIEW, &transMatrix);
device->GetTransform(D3DTS_PROJECTION, &projMatrix);
D3DXMatrixMultiply(&viewProjection, &transMatrix, &projMatrix);


and then my check for inside the view frustum... Original C#
public bool insideFrustum(Vector3 position, float radius)
{
for (int i = 0; i < 6; i++){
if (m_frustum.Dot(position) + radius < 0)
{
// Outside the frustum, reject it!
return false;
}
}
return true;
}


and the new c++ one...
bool insideFrustum(D3DXVECTOR4 position)
{
for(int i=0; i<6; i++)
if(D3DXPlaneDot(&viewFrustum, &position) + position.w < 0)
return false; //its outside in the cold

return true;
}



##### Share on other sites
Does that mean that you multiply a plane (a, b, c, d) and a vector (x, y, z, w)
and w != 1.0?
The return value of the D3DXPlaneDot function is a*x + b*y + c*z + d*w.
Try to keep w = 1.0 and have a different variable for the radius.

##### Share on other sites
Just use D3DXPlaneDotCoord and a D3DXVECTOR3.

##### Share on other sites
That did it keeping the w value at 1.0.

Cheers guys.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633654
• Total Posts
3013168
×