Page 1 of 1
Use mouse to control camera view in opengl window
Posted: Fri Jul 20, 2018 11:24 pm
by cdm
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.
Re: Use mouse to control camera view in opengl window
Posted: Wed Sep 19, 2018 2:17 pm
by cmoses
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.
Re: Use mouse to control camera view in opengl window
Posted: Fri Sep 28, 2018 5:41 pm
by richardbloemenkamp
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
Re: Use mouse to control camera view in opengl window
Posted: Sun Sep 30, 2018 12:31 pm
by Erwin Coumans
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.
Re: Use mouse to control camera view in opengl window
Posted: Mon Oct 01, 2018 6:00 pm
by richardbloemenkamp
Yes that works great! I definitely thought I had tried that before without result but apparently not.