RotMatPR_tr=transpose(RotMatPR);//RotMatPR works fine if pitch =0 or roll=0 but if say pitch=35 and roll=60 the rotation is all wrong. transpose(RotMatPR) however works perfectly.
vec2deltaxy=lightFull.xy*0.95*(alt_agl+vertex.z+gear_clearance)/lightFull.z;//This is the 'actual' location, taking into a account the full 3-D structure of the aircraft
vec2deltazeroxy=lightFull.xy*0.95*(alt_agl+gear_clearance)/lightFull.z;//Instead of using the exact z value of this particularly point to determine the distance of the shadow & reposition & shrink it appropriately, we'll just use the origin (0,0,0) of the model instead. This avoids a problem below, where varying vertex.z in deltaxy and then using deltaxy to calculate dist caused the shadow to sort of slant upwards, thanks to the varying z values used
floatdist=sqrt(deltazeroxy.x*deltazeroxy.x+deltazeroxy.y*deltazeroxy.y+alt_agl*alt_agl);//could use function 'distance' instead, might be better?
//The code below to shrink the shadow while keeping it 75 m. away has some issues that need to be fixed. Making the shadow shrink at x^2 rate partly to cover up this problem until it can be solved . . .
//The problem is that the aircraft isn't flat/parallel to the ground any more, but it appears to be at an angle to the ground.
//The various shrinkages perhaps mess with the angles somehow, meaning that when the animations apply the roll & pitch corrections they just don't quite work as they should
pos.z=(-0.9*75)*alt_agl/dist+0.05*vertex.z;//if the shadow is more than about 75 meters from the aircraft it disappears so we are going to just keep it right at 75 m. & make it smaller to simulate greater distance.
//(-0.9*75) is the same factor for altitude we were using above when dist=75. *alt_agl/dist keeps it at the right height proportionally to simulate the location at a further distance, while actually just keeping it at 75 m. distance.
//pos.z = 0.05 * vertex.z ; //if the shadow is more than about 75 meters from the aircraft it disappears so we are going to just keep it right at 75 m. & make it smaller to simulate greater distance.
//shrink the size FIRST, THEN move where it needs to be. If you shrink later you're also shrinking the deltaxy distance moved, which doesn't work well
pos.xy=75/dist*pos.xy;//shrinking the size of the shadow to simulate further distance. Should be linear shrinkage but doing it ^2 for now to help ucover up the issues in code above.
pos.xy-=75*deltaxy/dist;// Similarly to above, * deltaxy/dist; keeps it at the right XY position proportionally to simulate the location at a further distance, while actually just keeping it at 75 m. distance.