Panda3D 鼠标控制程序 - 隐藏光标,自由移动相机
from panda3d.core import WindowProperties from direct.showbase.ShowBase import ShowBase
class MyApp(ShowBase): def init(self): ShowBase.init(self)
# 隐藏鼠标光标
props = WindowProperties()
props.setCursorHidden(True)
self.win.requestProperties(props)
# 设置鼠标控制
self.accept('mouse1', self.toggleMouseControl)
self.mouseControlEnabled = False
def toggleMouseControl(self):
self.mouseControlEnabled = not self.mouseControlEnabled
props = WindowProperties()
props.setPointerHidden(self.mouseControlEnabled)
self.win.requestProperties(props)
def update(self):
if self.mouseControlEnabled:
# 获取鼠标移动的相对位置
md = self.win.getPointer(0)
x = md.getX()
y = md.getY()
# 计算相机的旋转角度
self.camera.setH(self.camera.getH() - x * 0.2)
self.camera.setP(self.camera.getP() - y * 0.2)
# 继续更新场景
return task.cont
app = MyApp() app.run()
原文地址: http://www.cveoy.top/t/topic/phcS 著作权归作者所有。请勿转载和采集!