I am trying to get familiar with the modal operators in blender and want to create some kind of custom trackball rotation. When I set the rotation euler values to the mouse_x and mouse_y event values, blender adds the absolute mouse position to the rotation values. Is there a possibility to start with 0 when I click the operator button?

def execute(self, context):
    bpy.data.objects["Cube"].rotation_euler[0] = math.radians(self.value_z)
    bpy.data.objects["Cube"].rotation_euler[2] = math.radians(self.value_x)
    return {'FINISHED'}

def modal(self, context, event):
    if event.type == 'MOUSEMOVE':  # Apply
        self.value_x = event.mouse_region_x
        self.value_z = event.mouse_region_y
  • 1
    $\begingroup$ Just store the last ones and subtract them. See: Text Editor > Templates > Python > Operator Modal View 3D $\endgroup$
    – X Y
    Commented Apr 5 at 9:48
  • $\begingroup$ Thank you it worked :) $\endgroup$ Commented Apr 5 at 14:37


You must log in to answer this question.

Browse other questions tagged .