Saturday, August 10, 2019

opengl - How do I implement camera axis aligned billboards?


I am trying to make an axis-aligned billboard with Pyglet. I have looked at several tutorials, but they only show me how to get the up, right, and look vectors. So far this is what I have:


target = cam.pos
look = norm(target - billboard.pos)


right = norm(Vector3(0,1,0) * look)
up = look * right

gluLookAt(
look.x, look.y, look.z,
self.pos.x, self.pos.y, self.pos.z,
up.x, up.y, up.z
)


This does nothing for me visibly. Any idea what I'm doing wrong?



Answer



I tried out billboards a while back. I just created a quad that faced the camera. Using the position I want the object at and the up and right vectors (normalized) of the camera, you can set the four corners of the quad like so:


a = position - ((right + up) * scale);
b = position + ((right - up) * scale);
c = position + ((right + up) * scale);
d = position - ((right - up) * scale);

Where a, b, c and d define the corners, use them clockwise or counter-clockwise depending on the winding order of your graphics library.


The right can be derived from the cross product or the look and the up vectors.



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...