Image space to world space
I would like to cast a ray correspond to the image points. I am not sure if this code is correct. But it does not give me correct result.
Ray PinholeCamera::shootRay(const Vector2 &uv) const
{
std::vector<cv::Point2f> op;
op.push_back({uv.x, uv.y});
std::vector<cv::Point2f> p;
cv::undistortPoints(op, p, cameraMatrix, dist);
auto viewspace = normalize(Vector3(p[0].x, p[0].y, 1.f));
Vector3 dir = Vector3(invView*Vector4(viewspace, 0.f));
return Ray(camPos, dir);
}
add a comment