• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

arbitrary-axis billboarding in 3d

GM Version: Game Maker Studio.
Target Platform: I've only windows to test on, so windows.
Download link: https://app.box.com/s/ln6lxtula8qn89zaqwmlpk0ewp7lfy6b
Project File: ArbitraryAxisLaserBeam.gmz for Game Maker Studio, 12kb
Note: The project makes use of a shader for drawing some point sprite billboards.

Here's a gyfcat demonstration of the laser beam drawn between two crosshairs:
https://gfycat.com/SinfulCommonGraywolf


Summary:

arbitrary-axis billboarding in 3d

think of a laser beam, which always tries to rotate around its length to face as much toward the camera as it can

And in this example, that is exactly what I am doing.

This example just shows you how to get a laser "beam" object to face toward the camera.
It doesn't show you how to do any fancy effects with the laser beam, only how to rotate it.

EDIT:

Hugely cleaned up the code in the project linked above. It should be a lot easier to wrap your mind around now.
 
Last edited:

chance

predictably random
Forum Staff
Moderator
This is an interesting example. For similar applications in 3D, I usually just define a line in parametric form -- i.e.

x(t) = a1 + t*a2
y(t) = b1 + t*b2
z(t) = c1 + t*c2

where (a,b,c) and (a1,b1,c1) are the endpoints of the line. Then I can draw a "tube" around the line as the points move in space. And I can increment "t" step-by-step to get a projectile effect moving from one point to the other.

There's some similarity with your approach. The downside with my approach is that the vertex list must be entirely updated each step, instead of just transforming the tube with a translation and rotation. I haven't checked the speed, but my approach is probably slower.

By the way, it would be useful if you combined your code into a Studio file (.gmz), and posted that for users to download. Having a downloadable file isn't required anymore, but I still recommend it. Especially when you have complex code in several events. Just a suggestion.
 
Okay, download link added. Also, the y axis was flipped on the laser model, because the way I had it, when d3d_set_culling was turned on, the laser model was facing backwards! The opening post has been corrected in that regard.

The download link also includes examples of...

Rotating a camera in any direction relative to its current orientation.

Repairing a rotation matrix after floating point errors have accumulated due to repeated multiplication.

Point sprite billboarding using a shader. (making a sprite always face the camera and always orient the same way on the screen).
 
Hugely cleaned up the code in the project linked to in the OP. Also, the project now just draws regular sprites instead of d3d models. The matrix which is used to rotate the laser beam to face the camera is located inside the script "scr_billboard_the_laser".
 
I

Ikki_

Guest
Hi, is there any chance you'd update the project for GMS2? Or maybe point out what may be wrong with the billboard shader? Thanks in advance!
 
M

Misty

Guest
My method is to have one drawing object and do a for loop to get the point and direction of every billboard object. And there is a transformed d3d_model_wall that draws the billboard. My method is faster than most but still slow for games who want a standard level of particles. More than a few dozen particles would lag the game, mainly because of using so many transform matrices. Would your method be faster than mine?
 
Top