static void half_diff_coords_to_std_coords( double _ThetaHalf, double _PhiHalf, double _ThetaDiff, double _PhiDiff,
ref Vector3 _In, ref Vector3 _Out )
{
double SinTheta_half = Math.Sin( _ThetaHalf );
Half.Set( Math.Cos( _PhiHalf ) * SinTheta_half, Math.Sin( _PhiHalf ) * SinTheta_half, Math.Cos( _ThetaHalf ) );
// Build the 2 vectors representing the frame in which we can use the diff angles
Vector3 OrthoX;
Half.Cross( ref Normal, out OrthoX );
if ( OrthoX.LengthSq() < 1e-6 )
OrthoX.Set( 1, 0, 0 );
else
OrthoX.Normalize();
Vector3 OrthoY;
Half.Cross( ref OrthoX, out OrthoY );
// Rotate using diff angles to retrieve incoming direction
Half.Rotate( ref OrthoX, -_ThetaDiff, out Temp );
Temp.Rotate( ref Half, _PhiDiff, out _In );
// ...or by mirroring in "Half tangent space"
double MirrorX = -_In.Dot( ref OrthoX );
double MirrorY = -_In.Dot( ref OrthoY );
double z = _In.Dot( ref Half );
_Out.Set(
MirrorX*OrthoX.x + MirrorY*OrthoY.x + z*Half.x,
MirrorX*OrthoX.y + MirrorY*OrthoY.y + z*Half.y,
MirrorX*OrthoX.z + MirrorY*OrthoY.z + z*Half.z
);
// if ( _In.z < -0.5 || _Out.z < -0.5 )
// throw new Exception( "RHA MAIS MERDE!" );
}