Public Group

# 3D Billboarding Woes

This topic is 2557 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi,

I'm making a 3d particle system and am getting a bit confused by my billboarding math.
So far I've got this:

 Vector3f vec = cGraphicsManager::Instance().GetCamera()->GetPosition() - mParticles.mPosition; vec .Normalise(); float angle = atan2(vec .z, vec .x); angle = cMathLookUps::Instance().RadiansToDegrees(angle); glRotatef(-angle + 90, 0, 1, 0); 

This works for a 2D rotation towards the camera but then I get confused after that. I've read various websites which have confused me further. For example lighthouse3d's tutorial - http://www.lighthouse3d.com/opengl/billboarding/index.php?billSphe

Is there not a simple way of just adding to my existing code which makes sense to me to tilt the image as well as rotate it. It seems like I should just be able to do the calculation I've already done again somehow to calculate the rotation around the other axis.

Cheers.

##### Share on other sites
it's just a matter of taking the distance on the X/Z plane that you've generated your Y-axis angle from and doing an atan2 with that and the vec.y

 Vector3f vec = cGraphicsManager::Instance().GetCamera()->GetPosition() - mParticles.mPosition; float angle_x, angle_y, xzdist; vec .Normalise(); xzdist = sqrt(vec.x * vec.x + vec.z * vec.z); angle_x = cMathLookUps::Instance().RadiansToDegrees(atan2(vec.y, xzdist)); angle_y = cMathLookUps::Instance().RadiansToDegrees(atan2(vec.z, vec.x)); glRotatef(-angle_y + 90, 0, 1, 0); glRotatef(angle_x, 1, 0, 0); 

there might be a better way that doesn't use sqrt, somehow extracting out the vec.y from the vec itself to get the length of XZ, especially since you're already calling a sqrt from inside the Normalize, and having many particles will definitely slow it down after a point.. You might also need to invert and add/sub 90 degrees from angle_x.. and I can't remember if you rotate X first or last, you might need to mess with that too.

but that's basically the jist of it.

##### Share on other sites
This would be much more efficiently done in your vertex shader rather than on the CPU. Stick "billboarding vertex shader" into Google for lots of useful hints and techniques.

##### Share on other sites
Thanks for the replies,

Thats worked radioteeth, thanks. I know its not the most optimal method but since it works for now I'm happy.

And mhagain I know, thats the next step, I'm in the process at the moment of teaching myself shader programming but I'm trying not to just copy and paste things off websites and trying to really learn the theory behind it so its quite a slow process.

Cheers
x

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002294
×