static void transform(ref float[] dst, float[] mat, float[] vec)
{
double[] tmp = new double[4];
double invW;
int i;
for (i = 0; i < 4; i++)
{
tmp[i] = mat[i * 4 + 0] * vec[0] +
mat[i * 4 + 1] * vec[1] +
mat[i * 4 + 2] * vec[2] +
mat[i * 4 + 3] * vec[3];
}
invW = 1 / tmp[3];
/* Apply perspective divide and copy to dst (so dst can vec). */
for (i = 0; i < 3; i++)
dst[i] = (float)(tmp[i] * tmp[3]);
dst[3] = 1;
}