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

LWJGL中实现相机看向指定坐标功能技术求助

游戏相机看向指定世界坐标的实现求助

我正在尝试编写代码,实现游戏中相机看向世界指定坐标的功能,之前的尝试效果不佳,以下是我目前的实现代码(思路有可取之处,但实际效果不好):

public void lookAtCoordinate(Vector3f target) {
    double xSide = target.x - position.x;
    double ySide = target.y - position.y;
    double zSide = target.z - position.z;
    setRotation((float) Math.toDegrees(Math.acos(xSide / ySide)), (float) -Math.toDegrees(Math.acos(xSide / zSide)), 0);
    //setRotation(target.x - position.x, target.y - position.x, 0;
}

请求技术帮助。游戏控制代码如下:

Game.newKeybind(GLFW_KEY_S, () -> { Game.cameraInc.z = 1; });
Game.newKeybind(GLFW_KEY_W, () -> { Game.cameraInc.z = -1; });
Game.newKeybind(GLFW_KEY_D, () -> { Game.cameraInc.x = 1; });
Game.newKeybind(GLFW_KEY_A, () -> { Game.cameraInc.x = -1; });
Game.newKeybind(GLFW_KEY_SPACE, () -> { Game.cameraInc.y = 1; });
Game.newKeybind(GLFW_KEY_LEFT_SHIFT, () -> { Game.cameraInc.y = -1; });

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 07:57:31