我已经坚持了大约一个星期,我已经在互联网上搜索试图找到如何使用剪切创建二维立方体效果的解决方案,我已经尝试了数字方程式,这是我得到的最接近的在一个星期内,我认为这纯粹是数学,但我无法理解。这是一个多人游戏,这是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);
}