- Home /
Other
Projecting point into plane made by camera frame
I am working on a heads up display project, where I want to create a 2D outline of certain objects in the world on the viewer's screen.
Say an object is located at point p. Where Q is the plane that is normal to the camera's forward direction, I project p into Q. Then I obtain a vector v from the camera's position to the projected point, and v should lie in the plane Q.Then I split up v into v1 and v2, which are the UP and RIGHT basis of the camera, so that I can get coordinates of the projected point with respect to a screen gui.
Currently my approach does not seem to work in most cases. I can get it to work in 1 direction where I can rotate and the a bit and it tracks, but then when I rotate everything 90 degrees the approach stops working. As pass an objected, I would expect it's vector v2 to increase significantly with respect to transform.right, but it stops increasing way too early. I left the below code of what I am working with.
Vector3 point = ptr.position;
Vector3 projected_point = Vector3.ProjectOnPlane(point, transform.forward) + Vector3.Dot(transform.position, transform.forward) * transform.forward;
Vector3 v = projected_point - transform.position;
Vector3 v2 = Vector3.project(v, transform.right);
Does anyone know if my math has an error, or is this the wrong approach for what I am doing?
Thanks.
Follow this Question
Related Questions
Projecting a point on plane 1 Answer
How to find coordinate 1 Answer
Vector3.Project() not working as expected? 0 Answers
Slow WorldToScreenPoint () 0 Answers
How do I pinpoint GPS coordinates with Conic Projection 0 Answers