Use mouse to control camera view in opengl window

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
cdm
Posts: 2
Joined: Fri Jul 20, 2018 11:15 pm

Use mouse to control camera view in opengl window

Post by cdm » Fri Jul 20, 2018 11:24 pm

Hi all,
I'm new to pybullet. I was wondering if it is possible to control the 3D view of the opengl window using the mouse? I can only zoom in and out, but not other operations as rotating the view.
I mean just moving the 3D view as you can do with most viewers.
Does this require code or there is some trick with the mouse that I haven't discovered? (Using python3 in ubuntu 16.04).
Thanks.

cmoses
Posts: 1
Joined: Wed Sep 19, 2018 2:16 pm

Re: Use mouse to control camera view in opengl window

Post by cmoses » Wed Sep 19, 2018 2:17 pm

I'm not sure how to do it through mouse control, but you can use the pybullet.resetDebugVisualizerCamera() function explained in the API to change the camera view.

richardbloemenkamp
Posts: 7
Joined: Tue Sep 18, 2018 7:50 pm

Re: Use mouse to control camera view in opengl window

Post by richardbloemenkamp » Fri Sep 28, 2018 5:41 pm

I think most of us have found the same issue and then turned to programmatically work around it. I think it will be improved in a future version.
Hope the example below helps you a bit further.

Example of moving the camera around programmatically with the keys (not the mouse sorry) while staying directed towards object called 'dog'

Code: Select all

while (1):
    cubePos, cubeOrn = p.getBasePositionAndOrientation(dog)
    p.resetDebugVisualizerCamera( cameraDistance=cdist, cameraYaw=cyaw, cameraPitch=cpitch, cameraTargetPosition=cubePos)

    keys = p.getKeyboardEvents()
    #Keys to change camera
    if keys.get(100):  #D
        cyaw+=1
    if keys.get(97):   #A
        cyaw-=1
    if keys.get(99):   #C
        cpitch+=1
    if keys.get(102):  #F
        cpitch-=1
    if keys.get(122):  #Z
        cdist+=.01
    if keys.get(120):  #X
        cdist-=.01

User avatar
Erwin Coumans
Site Admin
Posts: 4126
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Use mouse to control camera view in opengl window

Post by Erwin Coumans » Sun Sep 30, 2018 12:31 pm

Try holding the CONTROL or ALT key + left or middle or left mouse button to rotate, pan or zoom the camera, while dragging the mouse.

richardbloemenkamp
Posts: 7
Joined: Tue Sep 18, 2018 7:50 pm

Re: Use mouse to control camera view in opengl window

Post by richardbloemenkamp » Mon Oct 01, 2018 6:00 pm

Yes that works great! I definitely thought I had tried that before without result but apparently not.

Post Reply