我想用Java制作3D射线脚轮游戏。我已经制作了地板和天花板,但是当我尝试制作墙时,右侧的墙几乎是无限的。我什至看过一些教程,但仍然找不到导致墙几乎无限的问题。
render.floor(game);
render.renderWall(0, 0.5, 5, 5, 0);
render.renderDistanceLimiter();
draw(render, 0, 0);
--------------------------------------------------------------------
public void renderWall(double xLeft, double xRight, double zDistLeft, double zDistRight, double yHeight){
double xcLeft = ((xLeft) - right) * 2;
double zcLeft = ((zDistLeft) - forward) * 2;
double xcRight = ((xRight) - right) * 2;
double zcRight = ((zDistRight) - forward) * 2;
double rotLeftSideX = xcLeft * cos - zcLeft * sin;
double yCornerTL = ((-yHeight) - (-up * 0.05)) * 2;
double yCornerBL = ((0.5 - yHeight) - (-up * 0.05)) * 2;
double rotLeftSideZ = zcLeft * cos + xcLeft * sin;
double rotRightSideX = xcRight * cos - zcRight * sin;
double yCornerTR = ((-yHeight) - (-up * 0.05)) * 2;
double yCornerBR = ((0.5 - yHeight) - (-up * 0.05)) * 2;
double rotRightSideZ = zcRight * cos * xcRight * sin;
double xPixelLeft = (rotLeftSideX / rotLeftSideZ * height + width / 2);
double xPixelRight = (rotRightSideX / rotRightSideZ * height + width / 2);
if(xPixelLeft >= xPixelRight){
return;
}
int xPixelLeftInt = (int) xPixelLeft;
int xPixelRightInt = (int) xPixelRight;
if(xPixelLeftInt < 0){
xPixelLeftInt = 0;
}
if(xPixelRightInt > width){
xPixelRightInt = width;
}
double yPixelLeftTop = (int) (yCornerTL / rotLeftSideZ * height + height / 2);
double yPixelLeftBottom = (int) (yCornerBL / rotLeftSideZ * height + height / 2);
double yPixelRightTop = (int) (yCornerTR / rotRightSideZ * height + height / 2);
double yPixelRightBottom = (int) (yCornerBR / rotRightSideZ * height + height / 2);
for(int x = xPixelLeftInt; x < xPixelRightInt; x++){
System.out.println(xPixelRightInt);
double pixelRot = (x - xPixelLeft) / (xPixelRight - xPixelLeft);
double yPixelTop = yPixelLeftTop + (yPixelRightTop - yPixelLeftTop) * pixelRot;
double yPixelBottom = yPixelLeftBottom + (yPixelRightBottom - yPixelLeftBottom) * pixelRot;
int yPixelTopInt = (int) (yPixelTop);
int yPixelBottomInt = (int) (yPixelBottom);
if(yPixelTopInt < 0){
yPixelTopInt = 0;
}
else if(yPixelTopInt > height){
yPixelTopInt = height;
}
for(int y = yPixelTopInt; y < yPixelBottomInt; y++){
pixels[x + y * width] = 0x1B91E0;
zBuffer[x + y * width] = 0;
}
}
}
有人知道为什么右边的墙几乎是无限的吗?
墙毛刺: