I want to bring a vertex to the zero position for a certain axis (x or Y), the vertex is on a special plane (not an object, a stored viewplane) so I tried to use the stored view matrix, set it to 0 for an axis and then tried to rotate it back.
rot_mat = self._view_context._view_mat # This is stored from Region3d.view_matrix.
v = rot_mat @ vec_center
if axis == "X":
v = Vector((-v[0],0,0)) # Difference in X location
elif axis == "Y":
v = Vector((0,-v[1],0)) # Difference in Y location
vec_center += rot_mat.inverted() @ v
It works, but not, if the view is panned. How can I take the translation of the viewport into acount as well?