void OrbitCamera::Init(const vec3f& p, const vec3f& t) { const vec3f v = (t - p); const vec3f w = v.norm3D(); const float d = v.len3D(); // acosf() takes values in [-1.0, 1.0] const float e = RAD2DEG(acosf(v.len2D() / d)); const float r = RAD2DEG(acosf(w.dot2D(XVECf))); // when v is parallel to world z-axis, dot // with x-axis will be 0 and rotation then // is ambiguous (can be +90 or -90): check // the sign of v.z to determine if we are // looking down +z or -z distance = cDistance = d; elevation = cElevation = e; rotation = cRotation = (v.z > 0.0f)? 180.0f + r: 180.0f - r; cen = t; active = false; }