# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### Code Snippets / [DBP] - Optimized Arbitrary Axis Aligned Billboarding.

Message
Posted: 12th Jan 2016 21:09 Edited at: 23rd Jan 2016 06:38
I recently wrote some billboarding code for a project and it worked so well I decided to port it to DBPro.

 Attached Laser Beam Image.
[Edit2] Fixed bug with matrix memory allocation; it appears MAKE MEMORY() does not ensure the memory is initialized with zeros...

#### Attachments

Login to view attachments
Posted: 20th Jan 2016 07:48
Didn't DBP have a point object command that would do all this?

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Posted: 21st Jan 2016 06:42 Edited at: 21st Jan 2016 06:45
Not quite, Point object() uses XY rotation to point an object's local z-axis towards some point in space. The result of that operation does not define a Z-rotation angle because all values would be equally correct. Unfortunately, this means Point Object() is useless for anything other than point-sprite effects or global-axis oriented billboards (X or Y).

My example shows how to construct a world transformation matrix which aligns an object to an arbitrary axis (as defined by the laser's end-points), then rotates the object about that axis in an attempt to face towards a second point (the camera). The matrix also applies the proper scaling needed to achieve the desired beam width and length. I suppose it could be thought of as being Point Object() on steroids which attempts to align two of an object's local axis with two separate points in space.

In this example I've applied the world matrix directly to an object, but the matrix is also suitable for transforming vertexdata.
Posted: 23rd Jan 2016 06:36
Updated example to fix Make Memory() error, seems matrix memory was not initialized with zeros sometimes leading to improper transformations.
Posted: 11th Feb 2016 06:03
very cool man, this will be handy