Game Development Community

Billboarding a Square Polygon

by Case Western (#0004) · in Technical Issues · 12/05/2005 (4:11 pm) · 4 replies

I'm having trouble billboarding a square polygon in Torque. I am using the following algorithm (better described here):

1) Extract the current modelview matrix
2) Extract the right vector from the modelview matrix by making the right vector the 1st row of the matrix
3) Extract the up vector from the modelview matrix by making the up vector the 2nd row of the matrix
4) Using the center point of the quad, I find each of the corners in the following way:
bottom-left = center + (-up + -right) * (half of the width)
bottom-right = center + (-up + right) * (half of the width)
top-right = center + (up + right) * (half of the width)
top-left = center + (up - right) * (half of the width)

This method causes all of the quads to rotate to face the camera, but they are all facing upward, as shown in this shot:
vorlon.cwru.edu/~mrl12/EECS396L/Flat0_1.jpgwhen they should actually look like this:
vorlon.cwru.edu/~mrl12/EECS396L/Flat3_1.jpgI think this may be because Torque's coordinate system is oriented such that +z is up, but I can't figure out how to compensate for this.

Also, when I tilt the camera downward, the squares are rotated upward:
vorlon.cwru.edu/~mrl12/EECS396L/Flat1_1.jpgand when I tilt the camera upward, the squares are rotated downward:
vorlon.cwru.edu/~mrl12/EECS396L/Flat2_1.jpg
Any help is greatly appreciated, thanks.
Mike

#1
12/05/2005 (4:39 pm)
I personall prefix all Billboard dts objects with BB: and make sure the front is point correctly acording to the pivot point. That seems to work for me. Check the [url=http://fosters.realmwarsgame.com/maxdts/]dts[url] docs for details
#2
12/05/2005 (4:59 pm)
Thanks Anthony,

I actually am not using a billboard dts object; I'm rendering these squares manually with glVertex() calls near the end of the render function for fluids (see this post for why I am doing this). Thus, I unfortunately can't take advantage of making the squares actual billboard dts objects by setting the billboard flag, etc.
#3
12/05/2005 (5:59 pm)
I figured it out!

So my hunch was correct about this problem having to do with Torque's coordinate system having +z be upward instead of +y. Knowing this, in step 3 of the above algorithm in the first post, I tried using the 3rd row of the modelview matrix instead of the 2nd one as the up vector. This worked like a charm.
#4
12/05/2005 (6:27 pm)
Awesome to hear you worked it out...and a side comment: excellent presentation of the question! Sometimes it can be very hard to get well-presented questions without asking repeatedly, and the graphics were even better, so keep it up!