void Camera::pan(float x, float y) { float up[4] = {0.f, (m_phi < M_PI)?1.f:-1.f, 0.f, 0.f}; float fwd[4] = {m_o[0] - m_eye[0], m_o[1] - m_eye[1], m_o[2] - m_eye[2], 0.f}; vec3fNormalize(fwd, vec3fNorm(fwd)); float side[4]; vec3fCross(fwd, up, side); vec3fNormalize(side, vec3fNorm(side)); vec3fCross(side, fwd, up); m_o[0] += up[0] * y * m_radius * 2; m_o[1] += up[1] * y * m_radius * 2; m_o[2] += up[2] * y * m_radius * 2; m_o[0] -= side[0] * x * m_radius * 2; m_o[1] -= side[1] * x * m_radius * 2; m_o[2] -= side[2] * x * m_radius * 2; }
void Camera::centerOn(float center[4], float halfDists[4]) { vec4fCopy(m_o, center); m_radius = vec3fNorm(halfDists) * 2.f; if (m_far < m_radius) { m_far = 1.5 * m_radius; setPerspective(m_near, m_far, m_fov, m_ratio); } }
void Camera::zoom(float factor) { m_radius += factor * m_radius ; if (m_radius < 0.1) { m_radius = 10.f; float fwd[4] = {m_o[0] - m_eye[0], m_o[1] - m_eye[1], m_o[2] - m_eye[2], 0.f}; vec3fNormalize(fwd, vec3fNorm(fwd)); vec3fScale(fwd, m_radius); vec3fAdd(m_eye, fwd, m_o); } }
float vec3fAng(vec3f_t* a, vec3f_t* b) { vec3f_t an = vec3fNorm(a); vec3f_t bn = vec3fNorm(b); return acosf(vec3fDot(&an, &bn)); }