I’m trying to create a camera handler that will enable the camera to zoom, pan, and orbit.
My current setup uses camera to control panning and orbiting and base.cam to control zooming. camera is at (0,0,0) with hpr set to (0,-45,0). base.cam is at (0,-50,0) with hpr set to (0,0,0).
Since base.cam’s hpr doesn’t change, I assume that it’s always directed towards camera. Zooming works fine until I change camera’s hpr. Then, when I change camera’s position and try to decrease base.cam’s y value, I find that it doesn’t always move towards camera.
I’ve taken a look at Zhao’s RTS cam, which does what I want, but don’t understand why my method doesn’t work:
This is what I have:
#Default settings base.disableMouse() def resetCamera(): base.cam.setPos(0, -50, 0) camera.setHpr(0, -45, 0) #Zooming def zoomIn(): base.cam.setPos(base.cam, 0, -5, 0) def zoomOut(): base.cam.setPos(base.cam, 0, 5, 0) #Panning def startPan(x,y): task = taskMgr.add(panTask, 'panTask') task.x = x task.y = y def panTask(task): camera.setPos(camera, task.x, 0, task.y) return task.cont def endPan(): taskMgr.remove('panTask') #Orbiting def startDrag(): global gMx,gMy task = taskMgr.add(dragTask, 'dragTask') task.mx,task.my = base.mouseWatcherNode.getMouse() def dragTask(task): mx,my = base.mouseWatcherNode.getMouse() if (mx,my != task.mx,task.my): camera.setHpr(camera, 180 * (task.mx - mx), -180 * (task.my - my), 0) task.mx = mx task.my = my return task.cont def endDrag(): taskMgr.remove('dragTask')
Zooming, panning, and orbiting work on their own, but not in conjunction with each other.