gpt4 book ai didi

java - 计算 block /人脸相机/光标在 3d block 世界中具有焦点

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:53:18 25 4
gpt4 key购买 nike

一直在用我的世界克隆游戏自学 3D 编程。我有一个无限 map ,以 16x16x64 block 的形式加载。

当玩家(摄像机)四处走动时,摄像机的中心(游戏光标)指向一个方 block 。我正在尝试弄清楚如何确定用户指向哪个 block 。

我有一个带有 3d 坐标、偏航、俯仰的相机,所以我知道用户正在看哪里。

我已经尝试找到位于从该原点绘制的“直线”上的坐标,但这并没有说明当相机指向 block 的边缘/角落时,系统将不知道。

我试过在网上寻找示例,但我没有找到任何有用的东西,一些示例,但它们非常错误且记录不完整。

我怎样才能正确地将相机的中心位置转换成它正在注视的方 block /面?

最佳答案

"I've tried finding coordinates that would be on a "line" drawn from that origin point but that doesn't account for when the camera points at the edges/corners of a block, the system won't know." .. "How can I properly convert where the center of the camera is looking into which block/face it's looking at?"

OpenGL 程序进行鼠标拾取的两种常见方式是颜色拾取光线转换。听起来您正在尝试遍历您的 block 网格以获得有点不寻常的位置,或者想要做一些类似光线转换的事情。

光线转换从相机 -> 通过鼠标 -> 到屏幕上的平面 -> 将屏幕空间映射到世界空间 -> 与场景碰撞

"I've tried looking for examples online but I'm not finding anything useful, a few examples but they're extremely buggy and poorly documented."

这里有一些光线转换教程的链接 one with maths and diagrams , one with some code examples , and another .

请注意,如果您找到任何较旧的 OpenGL 教程,它们可能会提到“选择模式”“名称堆栈”,这确实是旧的,不要使用它 - OpenGL wiki .

关于java - 计算 block /人脸相机/光标在 3d block 世界中具有焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20304682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com