首页 > 解决方案 > 如何在 Java 中定位广告牌精灵?

问题描述

我正在尝试使用它们的 和坐标、相机的位置和相机的弧度旋转来定位广告xy精灵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 指的是框架的宽度和高度。

谢谢。

标签: java3dgame-enginebillboard.js

解决方案


推荐阅读