This topic is now archived and is closed to further replies.


how to align a billboard along any axis?

Recommended Posts

sflare    122
just what the subject is i mean like the way trees are done (Y-only) but along any axis given by some vector not just the y-axis

Share this post

Link to post
Share on other sites
streampark    122
try this link, download the billboard demo...

it''s all to do with this section :-

// Update the view position

Angle = (float)timeGetTime() / 2000.0f;
D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3((float)cos(Angle) * 200.0f, 200.0f, (float)sin(Angle) * 200.0f), &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
g_pD3DDevice->SetTransform(D3DTS_VIEW, &matView);

see the 200.0f there ^, set that to the height of the tree you want to render (or have all trees relative to 0.0f). - WayOut Engine v00.2
''That''s it man, game over man, game over'' - Aliens

Share this post

Link to post
Share on other sites
sflare    122
the could that you showed is just used for setting the camera
and that example rotates billboards around all axis
when you look at the trees from the top they look like trees that are on the ground

what i''m looking for is like what the directx sdk billboard example does but along any axis not only y

Share this post

Link to post
Share on other sites
krez    443
i''m pretty low on the 3D foodchain, but...
for billboarding, the sprite (surface, polygon, whatever it is called) is rotated on all 3 axes to face the camera. you just have to find that section of the code, and cut out the x & z rotation parts...

--- krez (

Share this post

Link to post
Share on other sites
S1CA    1418
Best way IMO (if you need them in world space rather than screen space) is generate the vertices for the billboards in realtime.

The rotation (top 3x3) part of the VIEW matrix has a very useful property when it comes to generating "spherical" billboards, it can be viewed as a set of 3 vectors known as "a basis".

Each of these vectors points in the direction of each major axis of the coordinate system represented by the camera.

I''ll call those vectors bx, by and bz. Imagine you have a debug function to draw a vector into your 3D screen as a line, something like:

dbgDrawVector( Vector& start_position, Vector& direction )
Vector end_position; // end point of line

// work out the end position of the line
// ** the line is 40 units long @ **
end_position.x = start_position.x + (direction.x * 40.0f);
end_position.y = start_position.y + (direction.y * 40.0f);
end_position.z = start_position.z + (direction.z * 40.0f);

draw3DLine( start_position, end );

Now extract our 3 vectors from your view matrix (either the first 3 rows or first 3 columns depending on how your matrix is stored) and display each vector with the above function:

Vector start(0,0,0);
dbgDrawVector( start, bx );
dbgDrawVector( start, by );
dbgDrawVector( start, bz );

If you put that into your code and move the camera about you''ll notice something magical happening!! - however you rotate your camera, the "bx" line will ALWAYS stay parallel with the bottom of your screen, and the "by" line will ALWAYS stay parallel with the side of your screen and the "bz" line will ALWAYS point into the screen. [this magic happens to be what you want].

That''s all the hints I''m going to give for the moment - no complete code, just the building blocks and BIG hints - its useful to work this stuff out for yourself rather than have everything made for you .

Simon O''''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites