I was toying around with creating custom geometry in Panda3d engine. And next code works 100% correct.
class FooBarTriangle(ShowBase):
def __init__(self):
super(self).__init__()
self.disable_mouse()
self.set_frame_rate_meter(True)
self.accept("escape", sys.exit)
self.accept("space", lambda: print(self.camera.get_pos()))
self.camera.set_pos(0, 0, 10)
self.camera.look_at(0, 0, 0)
self._add_light()
self._add_triangle()
def _add_light(self):
# Adds a point light
pass
def _add_triangle(self):
# Adds a single triangle in a certain place
pass
Mysterious things happen when I remove base.disableMouse()
from my code. I expect my camera to be movable and appear in the (0, 0, 10) position, looking at (0, 0, 0). But, instead, camera is in the position (0, 0, 0) and I don't know where does it look.
Why does it happen?
This happens, because Panda3D has a default camera control in place (the default camera driver), if you don't call disableMouse()
, Panda3D will not move your camera through calls to camera.set_pos(x, y, z)
, but only allow movement through the specified controls as can be read up here and here in the manual.
You either have to write your own camera controller if you wish to be able to place your camera anywhere other than (0, 0, 0)
through code or just use the controls indicated on the links above to move around the scene.