Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

thanx, it looks great, but I somehow managed to decipher the Microsoft SDK code and got this:

 

           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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...