Hi, I am trying to add xy-limits on the default mouse control so that my models won’t go out of the display region, i.e. drive the camera around xy axis within a preset x and y ranges. Is there a way to add limits to default control or do I have to build a custom camera control and add calculations using xy coordinates of mouse?
Also, i found that core base still tracks and store mouse position after base.disabledmouse(), so the cam pos does not stay still but move far away after base.enabledmouse() is called again. Is there a way to override or stop this behavior?
base.enabledmouse() # move camera around
# and then continue dragging the mouse around
# camera stays fixed
# camera suddenly jumps to far away
The problem is that this function doesn’t have an exact name. This is actually a camera node, or rather an update function. This has nothing to do with the mouse. You need to do an additional check in the body of your function to update X Y or not.
Note that there are two different built-in camera controllers available: a “trackball” controller (the default) and a “drive” controller.
What seems to work is to take the (inverse) transformation of base.camera and apply its position and orientation to base.mouseInterfaceNode (which is apparently used by the built-in camera control system) just before re-enabling the built-in controller. For some reason that transformation needs to be inverted when in trackball mode, but not when in drive mode.
Here is some code that should hopefully do what you want:
from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
environment = loader.loadModel("../samples/Roaming-Ralph/models/world")
# uncomment the following line to go into drive mode
# don't invert the camera transformation when in drive mode
xform = self.camera.get_transform().get_inverse()
pos = xform.get_pos()
hpr = xform.get_hpr()
app = MyApp()
Press D to disable built-in camera control, E to re-enable it.