Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 pseudo-billboarding question
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Chango
Neophyte

5 Posts

Posted - Aug 13 2006 :  5:33:40 PM  Show Profile  Reply with Quote
Hello,

In my current programming efforts, having done several 2d games in the past, I am attempting to create a very basic 3d engine. It can already do a lot of things such as loading and manipulating .x files in 3d space, .x file animation, simple lighting, and it has a simple point sprite based particle system. However, I am having some trouble implementing a solution for using billboards.

What I want to do is have a rectangle out in 3d space that always directly faces the camera and orients itself so that whatever texture is on there will always face 'up' in relation to the view of the camera. I already have the code to create and draw the rectangle; I'm just having trouble finding the correct math functions to orient the rectangle to the camera's view.

For example, right now the code in my angle finding Sub looks more or less like this:

a = CameraRotation
b = CameraVerticalPitch
Object.Direction.x = b
Object.Direction.y = -a
'Object.Direction.Z = ?

This causes the rectangle to rotate correctly around the world's 'Y' axis, and interestingly rotates it correctly around the world's 'X' axis as long as the camera is directly lined up with the 'Z' axis (when it’s at the default start position of [0,0,40]). However, when the camera moves out of alignment with the 'Z' axis, and has a vertical pitch that isn’t zero, the object keeps rotating around the world's 'X' axis. This, of course, produces unacceptable results.

I think the answer lies in how to rotate the rectangle around the worlds 'Z' axis. I've already tried 'Object.Direction.Z = b * Sin(a)' and gotten results that were close in that the rectangle will face the camera, but still have it rotating around in an odd way.

I've already gone through the billboarding tutorial from directx4vb and found that it doesn’t really contain the solution to my problem. Unfortunately, one of the Subs it uses contains the equivalent of the line 'temp = (vN.x / (r * Sin(Object.Direction.x))).' Unfortunately, if the rectangle object has a direction of zero, it causes a crash (because as you all obviously know, one can't divide by zero).

If anyone has any ideas or suggestions, I would be very appreciative.

Thanks,

Chango

Almar
Moderator

Netherlands
192 Posts

Posted - Aug 18 2006 :  1:52:49 PM  Show Profile  Visit Almar's Homepage  Send Almar an ICQ Message  Reply with Quote
I think you can just transform (multiply) your vertices using the inverse view matrix, and have it work pretty well? That's what I use in my game.

http://www.flipcode.com/cgi-bin/fcarticles.cgi?show=63904

Go to Top of Page

Chango
Neophyte

5 Posts

Posted - Aug 21 2006 :  11:21:34 PM  Show Profile  Reply with Quote
That sounds interesting. Do you know how I might code such a thing in VB? Or more specifically, how would I find the inverse of my view matrix in VB?

I coded something similar to the example in the link you provided, only I used the regular view matrix instead of the inverse. It provided interesting results, but unfortunately is still incorrect. (the quad seemed to rotate around the camera's position instead of staying stationary)

Thanks.
Go to Top of Page

Almar
Moderator

Netherlands
192 Posts

Posted - Aug 25 2006 :  4:43:13 PM  Show Profile  Visit Almar's Homepage  Send Almar an ICQ Message  Reply with Quote
Just use the D3DXMatrixInverse /Inverte or so function I think. Or, I believe you can multiply your matrix with an inversion matrix, but you'll have to look that up on google. :)
Go to Top of Page

Chango
Neophyte

5 Posts

Posted - Sep 10 2006 :  7:55:56 PM  Show Profile  Reply with Quote
Success! I have finally gotten my billboards to work properly.

Thank you for all your help.

-Chango
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.11 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.