This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Raycasting troubles

oajfh johnson
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all, first post here (I hope this all displays correctly).
I program a little in Java here and there (made a few very basic games), and recently thought I should start writing my own raycasting engine.

My code is based off the Permadi tutorial (my code may not be very well-written, I hope no one cringes too much). Wall size is 128 pixels.

Anyhow, I seem to have a problem rendering my walls properly. My level is square-shaped, with blocks along the edges.

Currently, the size of the walls seems to be a little strange : it is the same ratio no matter what direction one looks in, no matter where one happens to be (walls at the other end of the map seem to be the same size as ones a dozen pixels away).
What's more, some walls are jagged whereas some others are smooth. Lastly, the size of the wall doesn't quite change smoothly with distance.

Source code enclosed is simplified and therefore mostly unoptimised (little bit shifting, nor any precaslculated values) in order to help understanding.

Angles are in degrees (360 >angles >=0).

554 is the distance to the proj plane, for a FOV of 60 degrees. Screen size is 640*400.

In my Render class, I have these methods :

The render method has this piece of code :

Here's the raycasting (which I put in a separate class) :

Finally, here's the level data :
This method returns the block corresponding to the coordinates (usually intersection coordinates)

Here's the level :

That 's the layout. -1 for walls. Width and depth are set to 8.

I hope that wasn't too much of a mouthful, but I've been stuck at this point for the last couple of days, even after rewriting part of the above.
If the full source code needs to be posted, just tell me.
Any help on this would be greatly appreciated.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic