I want to draw a circle into the 3d view in the direction of the current view rotation.
I have 2 vectors (center, mouse_pos), so I have two points in 3d space, so I have the radius - fine.
This is my code so far and the painted result:
segments = 32
mul = (1.0 / (segments - 1)) * (pi * 2)
self._vertices = [(sin(i * mul) + self._center[0],
cos(i * mul) + self._center[1], 0) for i in range(segments)]
With this the circle is painted like I have a "top perspective". I also have a method to get the current view direction:
def get_view_direction(context):
rv3d = context.space_data.region_3d
view_rot = rv3d.view_rotation
dir = view_rot @ mathutils.Vector((0,0,-1))
return dir.normalized()
My question is now how to let the segments of the circle take the rotation of the view into account? Any ideas?
EDIT: First part solved:
rv3d = context.space_data.region_3d
view_rot = rv3d.view_rotation
segments = 32
mul = (1.0 / (segments - 1)) * (pi * 2)
points = [(sin(i * mul), cos(i * mul), 0) for i in range(segments)]
for point in points:
vertex = view_rot @ mathutils.Vector(point)
self._vertices.append(vertex)
What's left now is to take the radius and center into acount, and I want to move it along the view direction, but I already have a method for this:
def get_view_direction(context):
rv3d = context.space_data.region_3d
view_rot = rv3d.view_rotation
dir = view_rot @ mathutils.Vector((0,0,-1))
return dir.normalized()
So I guess I can add the direction multiplied by a scalar to each vector?