I’m using the simplest way of rendering.
Get the center position of billbaords,
count distance from eyes, than sort results, and draw them in inversed order (nearest -> last).
Everything is OK, untill billboard size isn’t too big.
Here’s an example:
------- Plane 1
---------------------------------- Plane 2
()
Viewer
It can happen that center of 1 will be nearer than 2, (fe. viewer much more far on the left) and in the result it won’t be rendered properly (before 2)!!!
Is there any simple way to do with it?
[This message has been edited by UnBc_Corwin (edited 01-19-2001).]
Originally posted by XBCT:
[b]Hi!
How do you calculate the distance from your viewer to a billboard?
Greets, XBTC!
[/b]
Distance from center to Viewer is: (there is only one way to do it
d = sqrt((xc-xv)^2 + (yc-yv)^2 + (zc-zv)^2))
where:
xc,yc,zc - center
xv,yv,zv - viewer
Didn’t we just cover this already? Look in the history its there.
Anyway, you need to use the plane equation
Ax+By+Cz+D = DistFromPlane
you get A, B and C from the modelview matrix directly and you use your x,y,z from your billboards, and D you calculate. Really just read my posts in the board history, the rest of the people here aren’t helping as they probably haven’t even done it themself.
That’s not a very nice thing to say Theo. Those of us that are responding clearly have done it. If we don’t tell them to do it the way Theo does it, that does not make us wrong. And if UnBc_Corwin did not understand our responses I would think he would ask for further clarification. I think you honestly owe some people an apology.
I will look up for more stuff in history (as Theo said).
But I think that I will implement that in a little different way. I don’t want to get info from modelview, because it can be not reliable reference for current camera z-axis (in my case). Instead of this I pass a pointer to a current camera through effects (such as DepthSorter) pipeline. So I get Z-Axis as inversed:
vec = lookAtPos - cameraPos
Then I have to multiply this vector by vertex (of billboard) position to get absolute z-position (am I right?).
And because I should get the nearest distance from viewer to target, I should get the maximum z-value from all vertexes of billboard, or rather BBox (8 vertices), becuase in the case of billboards I can afford to count distance for every vertex, but in the case of other “objects” I can’t (I will use the same sorter for all objects).
Theo, if you only had had some linear algebra… It really helps to see that we aren’t saying anything different, well, just differently expressed. My equation gives the distance of the near plane if you give it a vertex on the near plane and the near plane’s normalized normal.