4/30/2023 0 Comments Python convert mouse coordinates![]() ![]() Pressing the same in X Y or Z again will rotate its object about its corresponding local axis. Pressing X Y or Z while the operator is running will make object only rotate about the corresponding global axis. By default it rotates about the view vector self.axis = rv3d.view_ansposed().to_3x3() * z_axis This axis of rotation is used to create a rotation matrix Matrix.Rotation(angle, size, axis). Print('alpha angle:',grees(alpha_angle))Ĭontext.window_manager.modal_handler_add(self)īelow is a sample operator to emulate the rotation operator. #Print angle in degrees to help with testing. #Get rotation angle and update object rotationĪlpha_angle = math.atan2(val2_y-val1_y, val2_x-val1_x) Ob_region = view3d_utils.location_3d_to_region_2d(region, #Convert ob loc to region loc (maybe would work with screen loc #you would want to be looking in front perspective.Ĭoord = ob.location.x, ob.location.y, ob.location.z Any ideas? Another approach perhaps? import bpy, math Currently, the mouse rotation does not correctly equate to the y axis rotation. Thought it might help if I traded out the direct object 3D coordinates with those from the screen (only found region coordinates via bpy_extras.view3d_utils though). I've got everything else worked out, I just need a bit of code that takes, mouse_x, mouse_y, object_x and object_y and spits out a corresponding angle for say Y rotation of the object.ĮDIT: Though the title reads (not in bge) I'm not at all opposed to importing something from the bge module to use it if it can solve this problem (just meant that this is for use directly in Blender, not for the game engine).īelow is what I've got so far. Basically want to emulate what Blender's rotate operator does once you've locked an axis (doesn't seem like it should be to hard). Also, limiting the rotation to a single axis at a time (as the locked axis image below displays) would be fine. This stackoverflow post seems to be on the right track but I'm confused as to how I might implement the math. Trying to produce similar behavior to the standard Blender rotate operator, for a modal operator I'm building.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |