Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Making sure a plane always faces camera?

Started by lsdogsdnbgj May 7, 2013 at 10:18 PM 0 replies 1.7k views
Original Post
lsdogsdnbgj
lsdogsdnbgj

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.

belfegor
belfegor

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;

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.