Aligning Quads to Camera : What's Best?
Blitz3D Forums/Blitz3D Programming/Aligning Quads to Camera : What's Best?
| ||
When the camera is stationary, I have no problem writing a simple single surface particle system. In fact, ATB already uses it for the firework effects. But I'm less sure of the best ( fastest ) way of aligning to the camera. TFormPoint? Also : do any of the available particle systems ( free or not ) use single surfaces? I've seen Gosse's particle system and Eole's (sp?) but I didn't think either was single surface. |
| ||
Mines is sort of free :) It's not complete, but works as is. It uses two surfaces, one for the fire, and one surface for other particles that don't animate. So the fire can be adjusted, but needs the image to work. I can give you a copy if you want? The aligning part is: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 Messy and longwinded, but the speed doesn't seem to get affected too much. I will be using TForm commands when i get the chance :) |
| ||
Erm, maybe I'm not understanding properly, so if I'm way off in left field smack me. But couldn't you just parent the mesh to the camera? o_O |
| ||
It's single surface, meaning triangle out of the mesh represent particles. Each quad will probably facing different directions, so they must all be rotated independantly. *RossC slaps POedBoy around a bit with a large trout* :D |
| ||
I would like to get a look at your particle system if you don't mind, Ross. You're doing things very differently from how I do them ( I don't use VertexCoords at all, I free the surface and recreate it ) so I'm having a little trouble understanding it as it stands. If that's ok, you can email it to sybixsus@... Thanks. |
| ||
Mail sent :) |
| ||
Got it. Thanks very much. |
| ||
It's single surface, meaning triangle out of the mesh represent particles. Each quad will probably facing different directions, so they must all be rotated independantly. -_- I've already got a single surface thing goin. And all the quads are rotated individually. AND....*drumroll*..... I can use the entity commands(parenting in this case) to align the mesh to the camera. Regardless of being individual faces, they still belong to the same mesh. /me trouts Ross C repeatedly |
| ||
@ poedBoy, would you mind share with us how you do this? |
| ||
Theres an early demo of my 2d-in-3d on blitzcoder.com http://www.blitzcoder.com/cgi-bin/showcase/showcase_showentry.pl?id=poedboy12222003051440&comments=no -BUT- ^that^ version does not use what I was talking about, as far as parenting the mesh to the camera. I had started working on a newer demo, which will most likely be a real playable( tho fairly simple) game. So heres some relevant tidbits to the parenting issue from the newer demo... ........... ........... ........... ;======================================================================================================= ;MAIN ;======================================================================================================= AppTitle "Renaissance Demo 2b" ;RenaissanceSplash() ;setup graphics------------------------- SuperGraphics(640,480,0) AmbientLight 255,255,255 FadeColor(0,0,0) ;create surface for sprite layer SpriteSurface.Surface=NewSurface.Surface(2,2,256,TEX_COLOR%+TEX_ALPHA%) ;create surface for HUD layer HUDSurface.Surface=NewSurface.Surface(1,1,256,TEX_COLOR%+TEX_ALPHA%) ;load in media-------------------------- TestFrameset.frameset=LoadFrameset("Images\demo.frameset",SpriteSurface.Surface,1,0) PlanetFrameset.frameset=LoadFrameset("Images\planet.frameset",SpriteSurface.Surface,0,0) HUDFrameset.frameset=LoadFrameset("Images\Interface.frameset",HUDSurface.Surface,0,0) ;setup bobs----------------------------- Ship.Frame=GetFrameByIndex.Frame(TestFrameset.Frameset,0) ............ ............ ............ EntityParent HUDSurface\Mesh%,GFX_Camera%;<==RIGHT THERE I PARENT THE MESH TO THE CAMERA ............ ............ ............ ;start main loop------------------------ SetFramerate(60) Repeat ............. ............. ............. ;THE HUD WILL ALWAYS ALIGN TO THE CAMERA NOW PositionEntity GFX_Camera%,Player\X#,-Player\Y#,EntityZ(GFX_Camera%) If rotlock%=1 Then RotateEntity GFX_Camera%,0,0,-Player\Angle# ............. ............. ............. RenderGraphics() Flip GFX_FlipMode% UpdateFramerate() Until KeyHit(Key_F12) And yes, in that case presented, I'm using 2 surfaces- one for the HUD, one for the "sprites". Hopefully I'll find the time soon to knock out this newer demo. |
| ||
;<==RIGHT THERE I PARENT THE MESH TO THE CAMERA Thanks that was what was needed. Now I can move on with my coding for this. |
| ||
Just did some tests, and parenting the mesh to the camera doesn't work for a free look game type like a fps, as far as I can tell. when moving around the sprites you can get to view them from the side, they don't face the camera anymore. |
| ||
Yeah, i was wondering that... |