3d math question

Blitz3D Forums/Blitz3D Programming/3d math question

Craig H. Nisbet(Posted 2005) [#1]
I need to make a single surface partical system. How do I costruct the points into quads and force them to face the camera? I'm going to check the archives now. Anyone have some code for this?


Matty(Posted 2005) [#2]
Hi Craig, I've written my own code for handling quads, based on an idea that Dark Half had a while ago. I use it in my gauntlet remake and is in the file QuadFunctions.bb which is included in the small zip below:

http://home.swiftdsl.com.au/~gezeder/lloyd/Code.zip

Basically when you create your quads, parent the mesh they are a part of to the camera. You will also need to use the tform commands to assign the position of each vertex in your quad such that they are aligned 'facing' relative to the camera.

Anyway have a look in the quadfunctions.bb file, it should not be too hard to follow.


DH(Posted 2005) [#3]
Nice to see I made a contribution in some respects.

Let me guess though:

Create a camera,
Create a mesh, parent it to the camera,

For each quad, you create a pivot in global space and refference them to each other in some fashion.

In each update, you check the global position of the pivot, then tform that point to the camera mesh, and move the quad (translate) to that location (locally)?

Sound about right?

Super fast with no need for any messy rotation code!


Matty(Posted 2005) [#4]
Dark Half - pretty similar, except I don't use a pivot I simply use the tformpoint commands to convert the particle/quad's x,y,z location (stored in a type) to the location in the camera's space. I actually use those functions, quadfunctions.bb, in pretty much every project I do now in which I need to use quads/billboards or sprites. It's only when I get really lazy that I revert to sprites, or when the performance hit is not going to be noticeable.


DH(Posted 2005) [#5]
Well, the only reason I used pivots, is so that the end user could reposition something as a normal blitz entity and have that single command affect the particle/billboard/tree branch/etc in real time. Rather than making a function call to my lib that gives the new position. Any entity-to-entity functions would work with blitz nativly (one could assign a collision radius to the pivot and do collisions with a folliage system, thus when the player walks past a tree, or grass, the collision system would move the branch or grass, and the particle/foliage would merely pick up from the pivots).

Granted though, your solution is by far better performance-wise. Simplicity is always a plus!


(tu) sinu(Posted 2005) [#6]
Both ways are good depending on what you need them for.
Having pivots does hit performance but gives more power, i can get about 3000 snow particles in a 3d world running at over 300fps without pivots but get about 60fps with pivots. The upside is the pivots can collide with stuff and react.