I like using BitmapMuzzleFlames for displaying a particle in any direction I want. I wanted to make an indicator for units loading/unloading cargo with a bunch of arrows going in/out of the base of the unit. However muzzleflames that are turned upwards display really buggy behaviour, basically scaling with the rotation so they disappear when pointing straight up and stretch badly.
The problem lies in the source itself:
Code: Select all
float3 sidedir = dir.cross(float3(0,1,0));
float3 updir = dir.cross(sidedir);
va->AddVertexTC(pos+updir*isize,sideTexture->xstart,sideTexture->ystart,col);
va->AddVertexTC(pos+updir*isize+dir*ilength,sideTexture->xend,sideTexture->ystart,col); va->AddVertexTC(pos-updir*isize+dir*ilength,sideTexture->xend,sideTexture->yend,col);
va->AddVertexTC(pos-updir*isize,sideTexture->xstart,sideTexture->yend,col);
The cross product of dir and (0,1,0) = straight up is obviously fine for when dir lies in or close to the horizontal plane, hence why noone noticed. If sidedir and updir would be normalized I think the problem would be sort of solved for all angles except straight up. Perhaps some random vector would work better instead of (0,1,0).
A more complete solution would have to use a rotation matrix of the actual orientation of the muzzleflame rather then just a single vector.