tags:

views:

156

answers:

1
+1  Q: 

WPF 3D Billboards

In a 3D scene we often need to apply labels (little textelements or icons) next to 3D object that is moving around (rotation, translation) in the scene. These labels should always face the camera but still move with the object. This technique I believe is called billboard.

An additional cool feature would be if the label would stay always at the same size - no matter how far away the associated object is. So the label seems to live in 2D screenspace and not in the 3D scenegraph.

Does anyone figures out a clever way how to do this in WPF?

A: 

For billboarding you need to make sure that the face normal is pointing towards the camera. The algorithm is that the dot product between the face normal and the view direction should be -1 (minus one).

I have some old C code that does this, but it's probably not particularly useful.

For keeping the object the same size you'd need to work out the screen size and then apply a transform to keep it the constant size you desired.

However, if you want the object to appear as though it's in 2D space, why not draw it in a 2D overlay? This will solve both the billboarding and scaling problem at the same time. You work out the screen location of your label and then use the 2D drawing functions.

ChrisF
I can draw it in 2D overlay, but how would I determine the position of the label? When the associated 3D object moves, the label needs to move with it. I guess it invloves calculating the projection matrix or something.
bitbonk
I am more or less aware of the math behind all this and if I try really hards I might even be able to calculate the correct matrix I would need to transform it to the view. But I really hoped I wouldn't have to do this myself:) Also I am not quite sure how I incorporate all this into a WPF Viewport3D scene.
bitbonk
Yes you need to get involved with the projection matrices. I haven't done 3D with WPF so I wouldn't like so say what methods and/or properties you need.
ChrisF
Either way (doing the billboarding or 2D labels) involves some fairly hairy maths.
ChrisF
Unfortunately a search for "WPF billboard" turned up your question as the second hit!
ChrisF