-
Notifications
You must be signed in to change notification settings - Fork 3
Camera centering
This is a brief overview of how we center the camera (focusing on near/far planes).
Because the part rotates, we can't just use the vertices' current positions but need to include wherever they might rotate to. Since we only rotate around the Z axis, we draw a circle around said Z axis and check for extremums of distance to the camera plane.
In particular, with c
the camera position, n
the camera direction (normal to camera plane) and v
the vertex we're considering, we check for the projection of v - c
on the normal n
. We derive the general equation for all vertices at height v_z
and solve for the local maximum and minimum.
The general expression as function of theta
is:
Spelling it out that gives:
where v_z
is the correct height and r
is the radius:
Deriving d
wrt theta
and setting d(d)/dtheta
to zero to find the extrema we get
(there are 2 solutions, arctan(...)
and arctan(...) + pi
Injecting in the original equation:
expanding and noting that cos(x + pi) = -cos(x)
and same for sine:
Using a couple of shortcuts for sin(atan)
and cos(atan)
from here (which both yield the same denominator), for the +/-
part we get
And since the normal n
is normalized we have n_x^2 + n_y^2 + n_z^2 = 1
and finally:
Lots of room for error but code seems to work