void RayCaster::Compute(const Matrix<3,4>& camera, const Vec4& plane) { Mat4 M; M.slice<0, 0, 3, 4> () = camera; M.slice<3, 0, 1, 4> () = plane.as_row(); svd.compute(M); double du = 1. / (camera[2] * atretina(svd.backsub(makeVector(1,0,1,0)))); double dv = 1. / (camera[2] * atretina(svd.backsub(makeVector(0,1,1,0)))); double dw = 1. / (camera[2] * atretina(svd.backsub(makeVector(0,0,1,0)))); depth_eqn = makeVector(du-dw, dv-dw, dw); }
// Intersect a ray from pixel Vec4 IntersectRay(const Vec3& pixel, const Matrix<3, 4>& camera, const Vec4& plane) { // Solve for x: // x*w = 0 { w is the plane normal } // C*x = y { C is the camera matrix, y is its image position } // // x is the solution to Mx=b with: // // M = [ C11 C12 C13 C14 ] // [ C21 C22 C23 C24 ] // [ C31 C32 C33 C34 ] // [ w1 w2 w3 w4 ] // // b = [ y1 y2 y3 0 ] Mat4 M; M.slice<0, 0, 3, 4> () = camera; M.slice<3, 0, 1, 4> () = plane.as_row(); Vec4 b = Zeros; b.slice<0, 3> () = pixel; return SVD<4>(M).backsub(b); }