quat::quat(const vec3 &from,const vec3 &to) { float len=sqrtf(from.length_sq() * to.length_sq()); if(len<0.0001f) { w=1.0f; return; } w=sqrtf(0.5f*(1.0f + from.dot(to)/len)); v=vec3::cross(from,to)/(len*2.0f*w); }
inline bool line_sphere_intersect(const vec3 &start, const vec3 &end, const vec3 &sp_center, const float sp_radius) { const vec3 diff = end - start; const float len = nya_math::clamp(diff.dot(sp_center - start) / diff.length_sq(), 0.0f, 1.0f); const vec3 inter_pt = start + len * diff; return (inter_pt - sp_center).length_sq() <= sp_radius * sp_radius; }