ras maxim
Member
Hello. I am trying to implement a simple raycasting algorythm in Game Maker Studio 1.4 following the tutorials by Permadi and Lode Vandevenne and I need some help.
Project file: Download
Compiled executable: Download
Things I want to improve:
Project file: Download
Compiled executable: Download
Things I want to improve:
- Division by zero bug. When checking for intersections with horizontal walls, we use the following formula (taken from here):
Code:first wall x coordinate = wall size / tangent of ray angle
Is there another way to find the first coordinate? Please help me to fix this.
- Correct floor drawing. I can't seem to find the right way to get the exact floor intersection coordinates. Lode Vandevenne gives the following code depending what wall is being cheked, east, west, south or north:
Code://4 different wall directions possible if(side == 0 && rayDirX > 0) { floorXWall = mapX; floorYWall = mapY + wallX; } else if(side == 0 && rayDirX < 0) { floorXWall = mapX + 1.0; floorYWall = mapY + wallX; } else if(side == 1 && rayDirY > 0) { floorXWall = mapX + wallX; floorYWall = mapY; } else { floorXWall = mapX + wallX; floorYWall = mapY + 1.0; }
It doesn't work for me, probably because I use pixel coordinates and lodev's tutorial uses grid coordinates (e.g. the first wall in the row is 0.0, 0.0 and the next one is 1.0, 0.0 and not 64.0, 0.0). For the current moment I just use wall coordinates for this, and it gives "scrolling floors" effect. This is not the way to go.
I can't figure out how to adapt these formulas for my pixel coordinates. If you know how to do it, please tell me.
- Performance. It runs about 8 fps and 22 fps with YoYo Complier. I tried using surface buffers instead of draw_sprite, it frees another 3-4 frames. But the main time is taken by the floor drawing loop calculations. Even if I comment out the actual drawing part it is 14 fps and 36 fps with YoYo Complier.
If you have suggestions how to optimize the code, please post them.