ssp - billboard effect - how ?

Blitz3D Forums/Blitz3D Beginners Area/ssp - billboard effect - how ?

cywhale(Posted 2003) [#1]
Hello.
Im developing a single surface particle system using pure triangles.
Moving and rotating(relative to world/x,y,z-own axis) triangles within a surface/mesh works great, no problems there.

But how can i create that billboarding effect like sprite-billboarding?

i have the coordinates

;origin/center of tri
tris\x0
tris\y0
tris\z0

;first vertex
tris\x1
tris\y1
tris\z1

;second vertex
tris\x2
tris\y2
tris\z2

;last vertex
tris\x3
tris\y3
tris\z3

+camera coordinates.

Surfed the blitzbasic.com community + some others for two days now, but couldn´t find a hint, in some other particle systems the authors use tformvector(), didn´t work for me.

Help would be really appreciated.

MfG
Cy


Ross C(Posted 2003) [#2]
Hey, i made a single surface particle system. Mines uses quads tho. I used sin and cos to rotate each quad and have modes i use to set bill board effect, always face camera, face camera but don't roll with camera. How are you going about rotating each particle?

Btw i don't use tform commands,as i don't quite grasp how they work but it my system works none the less :)


cywhale(Posted 2003) [#3]
I´m using sin/cos,too to rotate the tri around the mesh 0,0,0 or the tri´s center (moving tri to mesh 0,0,0, rotating, moving back to tri-original 0,0,0.

But i have massive problems with billboarding.

Can you poste the algorithm? *hope*


Ross C(Posted 2003) [#4]
Well, Bill Boarding basically for me was to rotate it to the right rotations , then leave it there. Or do you mean something else? I'm at college right now so i can't post any of my code. Can you explain what you mean by bill boarding then, if it's not rotating the tri to an angle then never rotating it again?


cywhale(Posted 2003) [#5]
I mean that the tris of the mesh should always face the camera, even if i´m moving/rotating the camera around.

Effect just like theBB3D-sprites.


Ross C(Posted 2003) [#6]
Right, get you now. As i say i'm at college but the only way, using sin and cos, it would work for me, was to rotate in stages.

Firstly i would rotate about the z axis first. Then i would rotate around the y axis, using the new co-ords generated by the first rotation. Then finally i would rotate it about the x axis, using the rotated co-ords from the previous rotations. I'll post some code to help you when i get home. Should be about 5 hours time, if you can hold on that long.

It took me a while, and alot of paper, to figure it out. It's strange cause it needs to be rotated in a certain sequence or it won't work :D


cywhale(Posted 2003) [#7]
Seem you had the same problems like me now, but figured it out. The help would be appreciated, doesn´t matter if i´m waiting some hours, i´m trying to solve ths problem for two days now...;)


Ross C(Posted 2003) [#8]
ok , np. speak to you later :)


Ross C(Posted 2003) [#9]
Hey, hears what i do to keep the quads facing the camera. It's is very unoptimised, but still runs quickly :)

VertexCoords(fire_surface,fire\pindex+0,fire\x+Sin(fire\ang)*fire\size,fire\y+Cos(fire\ang)*fire\size,fire\z)

VertexCoords(fire_surface,fire\pindex+1,fire\x+Sin(fire\ang+90)*fire\size,fire\y+Cos(fire\ang+90)*fire\size,fire\z)

VertexCoords(fire_surface,fire\pindex+2,fire\x+Sin(fire\ang-90)*fire\size,fire\y+Cos(fire\ang-90)*fire\size,fire\z)

VertexCoords(fire_surface,fire\pindex+3,fire\x+Sin(fire\ang+180)*fire\size,fire\y+Cos(fire\ang+180)*fire\size,fire\z)


Ok, this first bit, sets the vertex co-ordinates for the z rotation, basically the spin the quad has.

Vertexcoords (SURFACE, INDEX of vertex,
Now thats the surface of the mesh. and the index of the vertex. The next bit is the x,y,z co-ords of the quad.

fire\x the x co-ord of the quad + Sin(fire\angle)*fire\size

The fire\angle is the angle of the z rotation. The fire\size is the size of the quad. Now in the other three you'll see i've added +180,+90 or -90 to the fire\angle bit.
This is because each vertex is 90 degs apart from each other.

	
fire_xdist(0)=Sin(fire\ang)*fire\size
fire_xdist(1)=Sin(fire\ang+90)*fire\size
fire_xdist(2)=Sin(fire\ang-90)*fire\size
fire_xdist(3)=Sin(fire\ang+180)*fire\size
				
fire_ycoord(0)=Cos(fire\ang)*fire\size
fire_ycoord(1)=Cos(fire\ang+90)*fire\size
fire_ycoord(2)=Cos(fire\ang-90)*fire\size
fire_ycoord(3)=Cos(fire\ang+180)*fire\size				


Now this peice of code gets the distances between the centre of the quad and the vertex point and stores them in an array.

		
For loop=0 To 3
	VertexCoords(fire_surface,fire\pindex+loop	,fire_xdist(loop),	fire\y+fire_ycoord(loop)*Cos(cam_rot_x)	,fire\z+Sin(cam_rot_x)*fire_ycoord(loop)  )
Next			


This part performs the rotation on the X Axis. This must be done before the Y Axis is rotated, or it won't work right. I'll explain that more if you want.

fire_zdist(0)=Sin(cam_rot_x)*fire_ycoord(0)
fire_zdist(1)=Sin(cam_rot_x)*fire_ycoord(1)
fire_zdist(2)=Sin(cam_rot_x)*fire_ycoord(2)
fire_zdist(3)=Sin(cam_rot_x)*fire_ycoord(3)						

fire_ycoord(0)=fire_ycoord(0)*Cos(cam_rot_x)
fire_ycoord(1)=fire_ycoord(1)*Cos(cam_rot_x)
fire_ycoord(2)=fire_ycoord(2)*Cos(cam_rot_x)
fire_ycoord(3)=fire_ycoord(3)*Cos(cam_rot_x)


This bit again stores the updated distances of the vertexs and such for usage in the next rotation stage. The reason i'm using arrays for all of this is i don't want to keep calling VertexX, VertexY and VertexZ, because i've heard with large meshes, this can take time.

For loop=0 To 3
	VertexCoords(fire_surface,fire\pindex+loop	,fire\x+ (fire_xdist(loop)*Sin(cam_rot_y)) - (fire_zdist(loop)*Cos(cam_rot_y)),	fire\y+fire_ycoord(loop)	,fire\z+(fire_zdist(loop)*Sin(cam_rot_y)) - (fire_xdist(loop)*-Cos(cam_rot_y))  )
Next


This part performs the last rotation on the Y Axis, by using the updated values in the array.

Weeeeshh, hope that helps some. If you want a demo, plz post back. :) It's tough and i'm glad i could help someone out with this :)

Here's the whole algorithim for it

				VertexCoords(fire_surface,fire\pindex+0,fire\x+Sin(fire\ang)*fire\size,fire\y+Cos(fire\ang)*fire\size,fire\z)
				VertexCoords(fire_surface,fire\pindex+1,fire\x+Sin(fire\ang+90)*fire\size,fire\y+Cos(fire\ang+90)*fire\size,fire\z)
				VertexCoords(fire_surface,fire\pindex+2,fire\x+Sin(fire\ang-90)*fire\size,fire\y+Cos(fire\ang-90)*fire\size,fire\z)
				VertexCoords(fire_surface,fire\pindex+3,fire\x+Sin(fire\ang+180)*fire\size,fire\y+Cos(fire\ang+180)*fire\size,fire\z)
				
				fire_xdist(0)=Sin(fire\ang)*fire\size
				fire_xdist(1)=Sin(fire\ang+90)*fire\size
				fire_xdist(2)=Sin(fire\ang-90)*fire\size
				fire_xdist(3)=Sin(fire\ang+180)*fire\size
				
				fire_ycoord(0)=Cos(fire\ang)*fire\size
				fire_ycoord(1)=Cos(fire\ang+90)*fire\size
				fire_ycoord(2)=Cos(fire\ang-90)*fire\size
				fire_ycoord(3)=Cos(fire\ang+180)*fire\size				
				
				For loop=0 To 3
						VertexCoords(fire_surface,fire\pindex+loop	,fire_xdist(loop),	fire\y+fire_ycoord(loop)*Cos(cam_rot_x)	,fire\z+Sin(cam_rot_x)*fire_ycoord(loop)  )
				Next				
				
				fire_zdist(0)=Sin(cam_rot_x)*fire_ycoord(0)
				fire_zdist(1)=Sin(cam_rot_x)*fire_ycoord(1)
				fire_zdist(2)=Sin(cam_rot_x)*fire_ycoord(2)
				fire_zdist(3)=Sin(cam_rot_x)*fire_ycoord(3)						

				fire_ycoord(0)=fire_ycoord(0)*Cos(cam_rot_x)
				fire_ycoord(1)=fire_ycoord(1)*Cos(cam_rot_x)
				fire_ycoord(2)=fire_ycoord(2)*Cos(cam_rot_x)
				fire_ycoord(3)=fire_ycoord(3)*Cos(cam_rot_x)

				For loop=0 To 3
						VertexCoords(fire_surface,fire\pindex+loop	,fire\x+ (fire_xdist(loop)*Sin(cam_rot_y)) - (fire_zdist(loop)*Cos(cam_rot_y)),	fire\y+fire_ycoord(loop)	,fire\z+(fire_zdist(loop)*Sin(cam_rot_y)) - (fire_xdist(loop)*-Cos(cam_rot_y))  )
				Next



cywhale(Posted 2003) [#10]
Thx - maybe i´ll try to convert it...
but i developed just this afternoon a working function using
yaw/pitch-functions of BB ;) after 48+ hours...

thx


Ross C(Posted 2003) [#11]
Oh, are you rotating a triangle, then recording the vertex co-ords, then positioning you triangle using that?

Also, it's better to use quads apprently, because of fill rates. Say if you want a square texture using a triangle, you have to scale it up, alot more than a quad. But, good luck with it. :)


Ross C(Posted 2003) [#12]
In fact, hehe, i sthere any chance i could see it ?


Wiebo(Posted 2003) [#13]
I place a pivot at the billboard position, align it to the camera, and position the vertices in pivot space.


cywhale(Posted 2003) [#14]
Thx to all - maybe i finally found a solution - without SIN/COS/Rotations, simply using TFormVector and Pos. of Camera...

If it works, i´ll soon post the triangle-billboard-function, along with some useful links/therory...

Screenshot (Athlon900, Win98SE, Particles NOT animated, just billboarding...):



Warren(Posted 2003) [#15]
Please do post the code. I would love to see your solution.