我已经坚持了大约一个星期,我在整个互联网上搜索,试图找到如何使用剪切创建 2d 立方体效果的解决方案,我尝试了许多方程,这是我一周内得到的最接近的方程,我相信这纯粹是数学,但我无法弄清楚。它适用于多人游戏,这是 Youtube 上的一段视频,讲述了我目前拥有的剪毛视频。
https://www.youtube.com/watch?v=J0qP7T0k6xk
这是我的代码:
public void addWall(Graphics2D g2d, ImageIcon img, int objX, int objY, int dir) {
//objX = objX/16;
objX = objX*32;
//objY = objY/16;
objY = (objY+4)*32;
int OffsetX = screen.width;
int OffsetY = screen.height*0;
if(dir == 1) {
//g2d.drawImage(img.getImage(), (((2*objX)+OffsetX)-(player.x*2)), (((2*objY)+OffsetY)-(player.y*2)) ,32*SCALE, ((32*SCALE)*-2)-(player.y-objY), null);
} else if(dir == 0) {
g2d.drawImage(img.getImage(), (((2*objX)+OffsetX)-(player.x*2)), (((2*objY)+OffsetY-(32*SCALE))-(player.y*2)) ,32*SCALE, ((32*SCALE)*-2)-(player.y-objY), null);
}
double skewX = (((player.x-objX)*2)*.100)*.1;
double skewY = 0;
//int x = (skewX < 0) ? -skewX*(32) : 0;
AffineTransform reset = g2d.getTransform();
AffineTransform at = AffineTransform.getTranslateInstance((-skewX*100) , 0);
at.shear(skewX, skewY);
//g2d.translate((((2*objX)+OffsetX)-(player.x*2)), (((2*objY)+OffsetY)-(player.y*2)));
// g2d.scale(SCALE, (((SCALE)*-2)-(player.y-objY)));
g2d.setTransform(at);
g2d.drawImage(img.getImage(), (((2*objX)+OffsetX)-(player.x*2)), (((2*objY)+OffsetY)-(player.y*2)) ,32*SCALE, ((32*SCALE)*-2)-(player.y-objY), null);
g2d.setTransform(reset);
//g2d.dispose();
}
public void addRoof(Graphics2D g2d, ImageIcon img, int objX, int objY) {
//objX = objX/16;
objX = objX*32;
//objY = objY/16;
objY = (objY+2)*32;
int shadowY = (objY+3)*32;
int OffsetX = screen.width;
int OffsetY = screen.height*0;
/* SHADOW */
/* SHADOW */
ImageIcon shadow = new ImageIcon("./res/shadowPixel.png");
g2d.drawImage(shadow.getImage(), (2*objX+OffsetX)-(player.x*2), (2*objY+(32*SCALE)+OffsetY)-(player.y*2), 32*SCALE, 32*SCALE, null);
/* SHADOW */
/* SHADOW */
g2d.drawImage(img.getImage(), (3*objX+OffsetX)-(player.x*3), (3*objY+OffsetY)-(player.y*3), 32*SCALE, 32*SCALE, null);
}