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.

Author
Message
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
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.




[Edit] 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
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
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
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
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.
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
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.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 11th Feb 2016 06:03
very cool man, this will be handy

Login to post a reply

Server time is: 2024-04-19 17:38:27
Your offset time is: 2024-04-19 17:38:27