Billboarding???

Darc

Regular
Joined
Apr 18, 2003
Messages
89
can someone help me out with this, I've never done it before and I can not make sense of Microsofts beautiful "SDK Samples".
 
Billboarding is a simple square that show an image as texture and not a 3D poligon to save resource. To give the orientation to the square I used a function that I've created

Function getAngolo(ByVal o As Vector3, ByVal c As Vector3) As Single
Dim ax As Single
Dim ay As Single
ax = c.X - o.X
ay = c.Z - o.Z

If ay < 0 Then
getAngolo = Math.Atan(ax / ay) / rad + 180
End If

If ay > 0 Then
If ax > 0 Then
getAngolo = Math.Atan(ax / ay) / rad
Else
getAngolo = 360 + Math.Atan(ax / ay) / rad
End If
End If

If ay = 0 Then
If ax > 0 Then getAngolo = 0 Else getAngolo = 180
End If

End Function

It get position of the camera and of the object and return the angle Y that the square must have (use trasformation matrix).

The image is a simply alphablend operation with two texture: the image and a mask.

You can find an example on my website but is commented in Italian. http:\\robydx.altervista.org

directX9/direct3D/billboarding. It was edited with VB.Net 2002
 
thanx, it looks great, but I somehow managed to decipher the Microsoft SDK code and got this:

Visual Basic:
            Dim vDir As Vector3 = Vector3.Subtract(CCamera.CameraView, CCamera.CameraPosition)

            If vDir.X > 0.0F Then
                billboardMatrix = Matrix.RotationY(CSng(-Math.Atan((vDir.Z / vDir.X)) + Math.PI / 2))
            Else
                billboardMatrix = Matrix.RotationY(CSng(-Math.Atan((vDir.Z / vDir.X)) - Math.PI / 2))
            End If
            billboardMatrix.M41 = object.X
            billboardMatrix.M42 = object.Y
            billboardMatrix.M43 = object.Z
            d3dDevice.Transform.World = billboardMatrix

it works pretty well, just a matter of speed I guess
 
Back
Top