小编Jac*_*ack的帖子

Ray Casting具有不同的高度尺寸

我有一个java项目谁制作了"windows'迷宫"并使用光线投射算法.这是一个截图:

迷宫用射线铸造

就像你可以看到所有的墙都有相同的高度.我想做同样的事,但身高不同

private void castRay(int xOnScreen,double angle,double direction) {
    R rx = castRayInX(angle,direction);
    R ry = castRayInY(angle,direction);
    // In case of out-of-space rays
    if (rx.getDistance()==Double.MAX_VALUE && ry.getDistance()==Double.MAX_VALUE) {
        graphics.setColor(BACKGROUND);
        graphics.drawLine(xOnScreen,0,xOnScreen,this.image.getHeight());
        return;
    }
    double distance = rx.getDistance();
    double normal = rx.getNormal();
    Color c = rx.getColor();
    double coef = Math.cos((angle+direction+Math.PI)-normal);
    Plot collision = rx.getPlot();

    if (ry.getDistance()<rx.getDistance()) {
        distance = ry.getDistance();
        normal = ry.getNormal();
        c = ry.getColor();
        coef = Math.cos((angle+direction+Math.PI)-normal);
        collision = ry.getPlot();
    }

    coef = Math.abs(coef);
    int factor = map.length*SQUARE_SIZE;
    double d …
Run Code Online (Sandbox Code Playgroud)

java math graphics 2d-3d-conversion raycasting

6
推荐指数
1
解决办法
2422
查看次数

继承类C++

我想像这样调用父构造函数:

Character::Character(int x, int y, int h, int s, int a, char dir) : health(h), strength(s), armor(a), direction(dir){
    if(direction == 'N') {
        Visual('^', x, y);
    } else if(direction == 'S') {
        Visual('v', x, y);
    } else if(direction == 'W') {
        Visual('<', x, y);
    } else if(direction == 'E') {
        Visual('>', x, y);
    }
}
Run Code Online (Sandbox Code Playgroud)

但它不能很好地工作,因为它调用父项的默认构造函数 private

class Visual {
    private:
        Visual();
        Visual(const Visual &);
    protected:
        Position coordinate;
        char chara;
    public:
        Visual(char c, int x, int y);
};
Run Code Online (Sandbox Code Playgroud)

c++ inheritance

5
推荐指数
1
解决办法
69
查看次数

标签 统计

2d-3d-conversion ×1

c++ ×1

graphics ×1

inheritance ×1

java ×1

math ×1

raycasting ×1