Jump to content
  • Advertisement
Sign in to follow this  
REspawn

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!