Thursday, July 14, 2022
HomeGame Developmentjava - Floorcasting not scrolling in raycaster?

java – Floorcasting not scrolling in raycaster?


I am at present engaged on a raycaster in Java, and to date, I’ve the ground appropriately textured. The issue, nonetheless, is that the ground would not scroll. In different phrases, once I transfer the digicam within the projection, the ground stays the identical, but the partitions transfer as anticipated. I am actually unsure what I am doing improper. I took nearly all of the code from this reference. Word that I took some liberties when pasting the code in that I used some pseudocode.

I attempted making use of a participant offset to the tileX and tileY variables, e.g., tileX += participant.x, and all I bought was a flooring that scrolls far too rapidly and incorrectly.

for each ray:
   ... // different stuff referring to the partitions above right here.
   int begin = (int)(wallY + wallHeight + 1);
   double directionCos = cos(rad(ray.getAngle()));
   double directionSin = sin(rad(ray.getAngle()));
   int textureDim = 16;
   for (int y = begin; y < screenHeight; y++) {
       double distance = screenHeight / (2.f * y - screenHeight);
       distance /= cos(rad(participant.getAngle()) - rad(ray.getAngle()));
       // The supply I grabbed the code from truly appends the participant's x and y to the tileX and tileY variables, however this fully messes up the textures when I attempt to.
       double tileX = distance * directionCos;
       double tileY = distance * directionSin;

       int textureX = Math.floorMod((int)(tileX * textureDim), textureDim);
       int textureY = Math.floorMod((int)(tileY * textureDim), textureDim);
       int rgb = floorTexture.getRGB(textureX, textureY);
       projectionFloor.setRGB((int)wallX, y, rgb);
  }

Beneath is a picture of the ground.
This is what the floor currently looks like

Beneath is an animation visualizing the issue.
Animation of what's wrong

Beneath is an animation visualizing what occurs if I attempt to apply a participant place offset (it’s not simple to inform, however the scrolling is way sooner than it ought to be and scrolls within the improper course more often than not):
enter image description here

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments