c++ - Optimizing a pinhole camera rendering system -


I am creating software registrars for school, and instead of using traditional matrix calculations, I am using an unusual rendering method. I <<>
"post-text" itemprop = "text">

This one is based. I have some points in the 3D space, and I change them by taking the distance between the 2D screen and the camera between normal and normalizing it

  Vec3 ray_to_camera = (A_Point-plane_pos). Normal ( );  

This gives me directional direction towards the camera. Then I change the direction of the ray on the direction of the ray by placing the original of the camera and an airliner with a plane to a ray.

  Vec3 plane_pos = m_Position + (m_Direction * m_ScreenDistance); Float dot = ray work GettoutProduct (MDIRAction); If (dot & lieutenant; 0) {float time = (-mc screendistance - plane_poz.getototproduct (MDIRaction)) / dot; // If time is smaller than 0 then either parallel to the plane or if (time> = 0) {// actual realization point is getting a_Point - = (m_Direction * (a_Point - plane_pos) .GETDotProduct (m_Direction))); // Cutting the plane origin from the point of intersection // // puts points at the original point (0, 0, 0) Vec3 sub = a_Point - plane_pos; // Calculation of axes Directional vector of the camera // This new z axis is approximate. X = sub.GetDotProduct (m_Axis [0]); Projected.y = sub.GetDotProduct (M_Xis [1]); }}  

It works wonders, but I am thinking: can the algorithm be made faster? Right now, for every triangle in the scene, I have to calculate three Normals

Float length = 1 / sqrtf (GetSquaredLength ()); X * = Length; Y * = length; Z * = Length;

Even a fast reciprocal square root approximation ( 1 / sqrt (x) ) is also being demanded.

My questions are as follows:
Is there a good way to estimate the three norms?
What is this rendering technique called?
Can the three top points be approximate using the general of the center? (V0 + v1 + v2) / 3)

Thanks in advance.

"PS You will make a fully functional software registrar in the next seven weeks with the help of a specialist in this field. I extend my education :)

Edit Do:

  Vec2 estimate; // is behind the camera Vec3 plane_pos = m_Position + (m_Direction * m_ScreenDistance); Float scale = m_ScreenDistance / (m_Position - plane_pos) .GetSquaredLength ( ); / / -100 due to square length instead of length / / (which would include a square root) Projected .x = a_Point.GetDotPr Oduct (M_exis [0]) .x * scale * -100; Projected.y = a_Point.GetDotProduct (M_Xis [1]). Y * scale * -100; Returning project;  

This gives the right result, although the model is now independent of the camera position. (

It is very short and fast!

It is difficult to understand what your code is doing, because it operates very meaningless! However, if I understand what you are saying then you are: / P>

  • Finding vector

    pin From Ole to point

  • it normal to
  • An "image plane with normalized vector" (Pinhol, Nach!
  • To create dot products on results of "axis" vectors to find X and Y screen coordinates

If the above description represents your intentions, then generalization should be futile - you should not do it at all! Removing generalization gives you poor results, maybe you are doing something different from your plan ... in other words, it was likely that you feel confused with me, and that the generalization step The "fixing" that feels great in your test cases, even if it is still not doing enough, what you want.

The overall problem, I think, is that your code is widely used as an ovenender: you are writing all your high-level vector algebra because the code can be executed in the internal loop. The way to optimize this is to work all the vector algebra on paper, the simplest expression is possible for its internal loop, and for this, precomput all the necessary constants at the time of the camera setup. Pinhole camera specs will only be input to the camera setup routine.

Unfortunately, unless I miss my guess, it should reduce your pinhole camera into traditional, boring old matrix calculations. (Ray tracing cool makes non-standard camera accessories easy - but whatever you describe should be completely standard ...)


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -