bool YawPitchRollToUpDirection(float yaw, float pitch, float roll, vec3& up, vec3& dir) { float cos_yaw = cos(yaw); float cos_pitch = cos(pitch); float cos_roll = cos(roll); float sin_yaw = sin(yaw); float sin_pitch = sin(pitch); float sin_roll = sin(roll); dir.Set(sin_yaw * cos_pitch, sin_pitch, cos_pitch * -cos_yaw); up.Set(-cos_yaw * sin_roll - sin_yaw * sin_pitch * cos_roll, cos_pitch * cos_roll, -sin_yaw * sin_roll - sin_pitch * cos_roll * -cos_yaw); up.Normalize(); dir.Normalize(); return true; }
// Generates a look-at matrix mat4 Lookat(vec3 target, vec3 camera, vec3 up) { vec3 forward = (target - camera).Normalize(); vec3 upNorm = up.Normalize(); vec3 side = forward.Cross(upNorm); vec3 upNew = side.Cross(forward); mat4 result; result[0] = vec4(side[0], side[1], side[2], 0.0f); result[1] = vec4(upNew[0], upNew[1], upNew[2], 0.0f); result[2] = vec4(forward[0], forward[1], forward[2], 0.0f); result[3] = vec4(-camera[0], -camera[1], -camera[2], 1.0f); return result; }
void getCuTransformParams(cu_param ¶_trans, paramfile ¶ms, vec3 &campos, vec3 &lookat, vec3 &sky) { int xres = params.find<int>("xres", 800), yres = params.find<int>("yres", xres); double fov = params.find<double>("fov", 45); //in degrees double fovfct = tan(fov * 0.5 * degr2rad); float64 xfac = 0.0, dist = 0.0; sky.Normalize(); vec3 zaxis = (lookat - campos).Norm(); vec3 xaxis = crossprod(sky, zaxis).Norm(); vec3 yaxis = crossprod(zaxis, xaxis); TRANSFORM trans; trans.Make_General_Transform(TRANSMAT(xaxis.x, xaxis.y, xaxis.z, yaxis.x, yaxis.y, yaxis.z, zaxis.x, zaxis.y, zaxis.z, 0, 0, 0)); trans.Invert(); TRANSFORM trans2; trans2.Make_Translation_Transform(-campos); trans2.Add_Transform(trans); trans = trans2; bool projection = params.find<bool>("projection", true); if (!projection) { float64 dist = (campos - lookat).Length(); float64 xfac = 1. / (fovfct * dist); cout << " Field of fiew: " << 1. / xfac * 2. << endl; } float minrad_pix = params.find<float>("minrad_pix", 1.); //retrieve the parameters for transformation for (int i = 0; i < 12; i++) para_trans.p[i] = trans.Matrix().p[i]; para_trans.projection = projection; para_trans.xres = xres; para_trans.yres = yres; para_trans.fovfct = fovfct; para_trans.dist = dist; para_trans.xfac = xfac; para_trans.minrad_pix = minrad_pix; }
vec3 Normalize(vec3 v) { v.Normalize(); return v; }