Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. double xc0 = ((x0 - 0.5) - xCam) * 2;
  2. double yc0 = ((y0 - 0.5) - yCam) * 2;
  3. double xx0 = xc0 * rCos - yc0 * rSin;
  4. double u0 = ((-height1 - 0.5) - zCam1) * 2;
  5. double l0 = ((+0.5 - height1) - zCam1) * 2;
  6. double zz0 = yc0 * rCos + xc0 * rSin;
  7. double xc1 = ((x1 - 0.5) - xCam) * 2;
  8. double yc1 = ((y1 - 0.5) - yCam) * 2;
  9. double xx1 = xc1 * rCos - yc1 * rSin;
  10. double u1 = ((-height1 - 0.5) - zCam1) * 2;
  11. double l1 = ((+0.5 - height1) - zCam1) * 2;
  12. double zz1 = yc1 * rCos + xc1 * rSin;
  13.  
  14. xt0 *= size * 2;
  15. xt1 *= size * 2;
  16.  
  17. double zClip = 0.2;
  18.  
  19. if (zz0 < zClip && zz1 < zClip)
  20. return;
  21.  
  22. if (zz0 < zClip) {
  23. double p = (zClip - zz0) / (zz1 - zz0);
  24. zz0 = zz0 + (zz1 - zz0) * p;
  25. xx0 = xx0 + (xx1 - xx0) * p;
  26. xt0 = xt0 + (xt1 - xt0) * p;
  27. }
  28.  
  29. if (zz1 < zClip) {
  30. double p = (zClip - zz0) / (zz1 - zz0);
  31. zz1 = zz0 + (zz1 - zz0) * p;
  32. xx1 = xx0 + (xx1 - xx0) * p;
  33. xt1 = xt0 + (xt1 - xt0) * p;
  34. }
  35.  
  36. double xPixel0 = xCenter - (xx0 / zz0 * fov);
  37. double xPixel1 = xCenter - (xx1 / zz1 * fov);
  38.  
  39. if (xPixel0 >= xPixel1)
  40. return;
  41. int xp0 = (int) Math.ceil(xPixel0);
  42. int xp1 = (int) Math.ceil(xPixel1);
  43. if (xp0 < 0)
  44. xp0 = 0;
  45. if (xp1 > width)
  46. xp1 = width;
  47.  
  48. double yPixel00 = (u0 / zz0 * fov + yCenter);
  49. double yPixel01 = (l0 / zz0 * fov + yCenter);
  50. double yPixel10 = (u1 / zz1 * fov + yCenter);
  51. double yPixel11 = (l1 / zz1 * fov + yCenter);
  52.  
  53. double iz0 = 1 / zz0;
  54. double iz1 = 1 / zz1;
  55.  
  56. double iza = iz1 - iz0;
  57.  
  58. double ixt0 = xt0 * iz0;
  59. double ixta = xt1 * iz1 - ixt0;
  60. double iw = 1 / (xPixel1 - xPixel0);
  61.  
  62. for (int x = xp0; x < xp1; x++) {
  63. double pr = (x - xPixel0) * iw;
  64. double iz = iz0 + iza * pr;
  65.  
  66. int xTex = (int) ((ixt0 + ixta * pr) / iz);
  67.  
  68. double yPixel0 = yPixel00 + (yPixel10 - yPixel00) * pr - 0.5;
  69. double yPixel1 = yPixel01 + (yPixel11 - yPixel01) * pr;
  70.  
  71. int yp0 = (int) Math.ceil(yPixel0);
  72. int yp1 = (int) Math.ceil(yPixel1);
  73. if (yp0 < 0)
  74. yp0 = 0;
  75. if (yp1 > height)
  76. yp1 = height;
  77.  
  78. double ih = 1 / (yPixel1 - yPixel0);
  79. for (int y = yp0; y < yp1; y++) {
  80. double pry = (y - yPixel0) * ih;
  81. int yTex = (int) (size * 2 * pry);
  82.  
  83. if (zBufferWall[x] > iz)
  84. continue;
  85.  
  86. zBufferWall[x] = iz;
  87.  
  88. int color = Art.walls.pixels[((xTex) + (tex % size) * size * 2)
  89. + (yTex + tex / size * size * 2) * sheetSize];
  90.  
  91. if (color != 0xffff00ff) {
  92. pixels[x + y * width] = color;
  93. zBuffer[x + y * width] = 1 / iz * 4;
  94. }
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement