You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在CMU图形库中无外部导入实现立方体渲染的技术求助

3D方块游戏渲染与移动问题

项目进展

  • 已在学校平台实现可在任意位置放置方块的类
  • 基于玩家视角的俯仰角(pitch)和偏航角(yaw)做简易渲染,能显示方块每个面的中心点(仿Minecraft按面渲染以方便面剔除)

核心问题

  • 不知道如何将面的中心点转换为可渲染的方形面
  • 移动时点的位置不符合预期,有时出现类似360度相机的局部异常效果
  • 不确定玩家移动方向是否正确,试错过程过于繁琐

可用渲染资源

平台提供多种2D形状渲染类,包括矩形、圆形,核心可用Polygon类——传入点列表即可渲染图形内部。目标是利用已渲染的点和距离渲染方块侧面,但毫无思路。

渲染代码参考

def render(self,target):
        if self.top==True:
            
            tPitch, tYaw, dist= self.angleTo3d(target,"top")
            yaw = tYaw+target.yaw
            if yaw>360:
                yaw-=360
            pitch = 180*(tPitch/math.pi)+target.pitch
            if pitch>360:
                pitch-=360
            renderGroup.add(Circle(200+((yaw-180)/90)*200,600+((pitch-180)/90)*200,2))
            renderGroup.add(Polygon())
            print(pitch,yaw)
        if self.left==True:
            
            tPitch, tYaw, dist= self.angleTo3d(target,"left")
            yaw = tYaw+target.yaw
            if yaw>360:
                yaw-=360
            pitch = 180*(tPitch/math.pi)+target.pitch
            if pitch>360:
                pitch-=360
            renderGroup.add(Circle(200+((yaw-180)/90)*200,600+(((pitch-180)/90)*200),2))
        if self.front==True:
            
            tPitch, tYaw, dist= self.angleTo3d(target,"front")
            yaw = tYaw+target.yaw
            if yaw>360:
                yaw-=360
            pitch = 180*(tPitch/math.pi)+target.pitch
            if pitch>360:
                pitch-=360
            renderGroup.add(Circle(200+((yaw-180)/90)*200,600+((pitch-180)/90)*200,2))
        if self.bottom==True:
            
            tPitch, tYaw, dist= self.angleTo3d(target,"bottom")
            yaw = tYaw+target.yaw
            if yaw>360:
                yaw-=360
            pitch = 180*(tPitch/math.pi)+target.pitch
            if pitch>360:
                pitch-=360
            renderGroup.add(Circle(200+((yaw-180)/90)*200,600+((pitch-180)/90)*200,2))
        if self.right==True:
            
            tPitch, tYaw, dist= self.angleTo3d(target,"right")
            yaw = tYaw+target.yaw
            if yaw>360:
                yaw-=360
            pitch = 180*(tPitch/math.pi)+target.pitch
            if pitch>360:
                pitch-=360
            renderGroup.add(Circle(200+((yaw-180)/90)*200,600+((pitch-180)/90)*200,2))
        if self.back==True:
            
            tPitch, tYaw, dist= self.angleTo3d(target,"back")
            yaw = tYaw+target.yaw
            if yaw>360:
                yaw-=360
            pitch = 180*(tPitch/math.pi)+target.pitch
            if pitch>360:
                pitch-=360
            renderGroup.add(Circle(200+((yaw-180)/90)*200,600+((pitch-180)/90)*200,2))

补充说明

  • renderGroup.add是学校平台提供的渲染库方法
  • 无法且不想使用多数外部库

内容的提问来源于stack exchange,提问作者guywhocode

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.01 15:47:27