Jump to content
  • Advertisement
Sign in to follow this  
george7378

Making sure a plane always faces camera?

This topic is 2046 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 everyone,

 

I am having a problem with a plane object that I can't sort out. I have defined my plane in-game using a custom vertex format. It consists of four vertices as follows:

 

//Format: {x,y,z,nx,ny,nz,tu,tv}
        {0, -0.128, 0.0339, 1, 0, 0, 0, 0},

        {0, -0.128, -0.0452, 1, 0, 0, 1, 0},

        {0, -0.564, 0.0339, 1, 0, 0, 0, 1},

        {0, -0.564, -0.0452, 1, 0, 0, 1, 1},

 

I want to build a transformation matrix which will ensure that this object is always facing the camera (i.e. the plane is always perpendicular to the camera's look direction). Basically, it's a billboard. I can't figure out how to make it so that the predefined plane always faces the camera though - can anyone suggest how I'd transform these vertices to always face me?

 

Thanks.

Share this post


Link to post
Share on other sites
Advertisement

Try this:

I will set yz as xy and normal z(-1), because it is easier for me and i always make billboards this way

 

EDIT: Forgat that need to adjust vertices position

float halfWidth = 0.7f; //set your values
float halfHeight = 0.9f;
{-halfWidth, halfHeight, 0, 0, 0, -1, 0, 0}, // top left

{halfWidth, halfHeight, 0, 0, 0, -1, 1, 0}, // top right

{halfWidth, -halfHeight, 0, 0,  0, -1, 0, 1}, // bottom right

{-halfWidth, -halfHeight, 0, 0, 0, -1, 1, 1}, // bottom left

And set your indices to get correct triangle winding

 

Then you take inverse of view matrix and adjust position:

 

D3DXVECTOR3 billPos(...);
D3DXMATRIX billWorldMat;
D3DXMatrixInverse(&billWorldMat, 0, &camera->View);
billWorldMat._41 = billPos.x;
billWorldMat._42 = billPos.y;
billWorldMat._43 = billPos.z;
Edited by belfegor

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!