# 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.

## 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 on other sites

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

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633703
• Total Posts
3013455
×