java - 如何在 Java 中定位广告牌精灵?
问题描述
我正在尝试使用它们的 和坐标、相机的位置和相机的弧度旋转来定位广告x
牌y
精灵z
。
我正在寻找类似于 Wolfenstein 3D 中实体的效果。
这是我到目前为止所拥有的:
public void render(Graphics g) {
double xx = x-camera.x;
double yy = y-camera.y;
double zz = z-camera.z;
xx = rotate2d(xx, zz, camera.rot)[0];
zz = rotate2d(xx, zz, camera.rot)[1];
double f = 200/zz;
xx *= f;
yy *= f;
xx += game.width/2;
yy += game.height/2;
if(xx >= 0 && xx <= game.width)
g.drawImage(image, (int) xx, (int) yy, null);
}
private double[] rotate2d(double x, double y, double rad) {
double s = Math.sin(rad);
double c = Math.cos(rad);
double[] pos = new double[2];
pos[0] = x*c-y*s;
pos[1] = y*c+x*s;
return pos;
}
精灵似乎围绕屏幕边缘倾斜,并且在一定的旋转时它们将完全不正确地定位。
相机的旋转以弧度为单位,game.width 和 height 指的是框架的宽度和高度。
谢谢。
解决方案
推荐阅读
- python - Python write() 方法和 close() 函数不适用于最新版本的 Visual Studio Code。代码适用于 Python 3.8.5 Shell
- php - 在本地网络上访问 WSL2 (Ubuntu 20.04) 内的 Apache 上的 PHP 网站
- stacked-chart - 堆叠折线图 y 轴在快速查看中显示总数的百分比
- excel - 将数据库复制到另一个工作表并自动对其进行排序
- javascript - 在 css / html 中重置模糊属性
- node.js - Git, Heroku, node Js [remote denied] master -> master (pre-receive hook denied)
- mysql - 优化具有数百万行的大型 SELECT/JOIN 查询
- c++ - 在多个进程之间共享单个 boost C++ 语言环境对象
- reactjs - ER:无效的挂钩调用。钩子只能在函数组件的主体内部调用。这可能由于以下原因之一而发生:
- mysql - MySQL工作台没有从csv导入所有行