Private Sub SetupBillboard(ByVal vxbf As VertexBuffer, ByVal D9 As Device)
Dim vs() As CustomVertex.PositionColoredTextured
Dim N As Single = 3.0F
Dim A As Array = vxbf.Lock(0, LockFlags.None)
Const BBX As Single = 40.0F, BBY As Single = 40.0F, BBZ As Single = 3.0F
'It returns a vanilla array...
vs = DirectCast(A, CustomVertex.PositionColoredTextured())
vs(0) = New CustomVertex.PositionColoredTextured(0.0F, -N, 2.0F * N, &HFFFFFFFF, 0.0F, 0.0F)
vs(1) = New CustomVertex.PositionColoredTextured(0.0F, N, 2.0F * N, &HFFFFFFFF, 1.0F, 0.0F)
vs(2) = New CustomVertex.PositionColoredTextured(0.0F, -N, 0.0F, &HFFFFFFFF, 0.0F, 1.0F)
vs(3) = New CustomVertex.PositionColoredTextured(0.0F, N, 0.0F, &HFFFFFFFF, 1.0F, 1.0F)
Mx = Matrix.Identity
Mx.Multiply(Matrix.RotationY(Convert.ToSingle(Math.Asin(BBZ / GetDistance(New Vector3(BBX, BBY, BBZ), Camera)))))
Mx.Multiply(Matrix.RotationZ(Convert.ToSingle(Math.Atan2(Camera.Y - BBY, Camera.X - BBX))))
Mx.Multiply(Matrix.Translation(BBX, BBY, BBZ))
vxbf.Unlock()
End Sub |