Billboards… [Archive] – OpenGL Discussion and Help Forums

Sorry to nag you guys with this question as you may find it trivial but I have failed over and over again while trying to get my billboards going and I really really need them to do nefty special effects as it seems that they are used so often in great games for different tasks (particule systems, trees, lights etc) After calling glLookAt and glPerspective I want to be able to draw spherical and cylindrical billboards. I want these to drawn at a given spot. By that I mean after some calls to gltranslate and glrotate I want to be able to do math equations giving me the theta needed to turn my 2 triangles so that it is flat to the camera. I have looked in the message board alot of time and over the internet and I have not found what I was looking for. There was some code but it seemed that it didn't fit my needs. I have tried other things such as multiplying [0 0 1] and [1 0 0] by the modelview then using the same atan2 thing with the view direction only to fail again and again. I do all my billboards in eye-space so no turning is necessary. (Well, at least the billboards don't need turning, everything else does to line up with my eye-space.) The problem with Nate's Miller example is that his camera is fix. If you call gluLookAt(something) you will see that his billboard donesn't face the camera but only a fixed point in the modelview. While this is fun to do a simple effect it doesn't work in a game where I want a billboard to be scaled appropriatly depending to the distance to the eye and to always face the moving camera. does my object need to point at the coordinates of the camera in modelview or does the paremeter of the projection matrix have to be taken into account. I don't know and am mistified quite frankly! Try to transform the world coordinates of the point(s) where you want your billboard(s) to be to window coordinates with gluProject. Then change the projection matrix to an orthogonal projection and display your billboard(s) in 2D, facing the camera. You'll have to scale the billboard(s) manually depending on the Z window coordinate of its position. If you look somewhere, you'll have an right-axis-vector and an up-axis-vector. The billboard simply has to lay on a plane that is parallel to the plane of these two axises. So you can get the coordinates of the vertices of a billboard quad through linear combination of these vectors and the place-vector where the billboard should be positioned. Uhmmm, another try, get the vector that moves the billboard to the viewpoint. That vector is orthogonal (is the normal) to the plane where the billboard should lay on. [B]The problem with Nate's Miller example is that his camera is fix. If you call gluLookAt(something) you will see that his billboard donesn't face the camera but only a fixed point in the modelview. While this is fun to do a simple effect it doesn't work in a game where I want a billboard to be scaled appropriatly depending to the distance to the eye and to always face the moving camera. First, reset the camera to be at position 0,0,0, facing in the -z axis direction ( This is usually you're starting mode, so a PopMatrix and a PushMatrix should do the trick). Second, rotate according to the direction of the camera in the following order: z axis, x axis, y axis. Now, translate using the position of the particle minus the position of the camera. Finally, rotate again using the direction of the camera, but this time with the values and the order reversed: -y axis, -x axis, -z axis. Now, you draw the particle along the x axis, facing positive z, centered at 0,0,0. oops, on the glTranslatef and the second set of rotations, it's supposed to be camera, not cam. I changed it from my original code to be easier to read. Doh! Well, I'm sure you guys figured that out anyway. Here is the code I got working for the cylindrical billboards. Any comments (other then my functions and data names are a bit whacky) ? The billboard will always face the camera, regardless of your direction. I assume that's what you mean by spherical, so yes, it's spherical. By cylindrical, do you mean that it will face you on certain angles, but will act like a regular polygon on others ( what many games do to produce grass, vines, wires, etc )? If so, then I'm not completely sure how to do it. I haven't experimented with that effect yet, but I might in the future. By the way, if you try my method and it acts funky, try putting the -axis rotations first, and the regular rotations last. This isn't somehting that should come up or anything, just something to keep in mind. Source.


Яндекс.Метрика Рейтинг@Mail.ru Free Web Counter
page counter
Last Modified: November 28, 2015 @ 12:00 am