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()

Panda3D 鼠标控制示例:隐藏光标,启用禁用鼠标控制

原文地址: https://www.cveoy.top/t/topic/pgV5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录