From de255063b234871021da004d32964e25d549d3e4 Mon Sep 17 00:00:00 2001 From: tslil clingman <> Date: Wed, 1 Sep 2021 15:48:09 -0400 Subject: Scale the projection plane to the screen correctly Also bumped up the textures to 32x32 --- src/main.zig | 5 +---- src/raycast.zig | 8 ++++++-- src/renderConstants.zig | 8 +++++--- 3 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main.zig b/src/main.zig index 64da425..aef559f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -28,9 +28,6 @@ usingnamespace @import("raycast.zig"); usingnamespace @import("renderConstants.zig"); usingnamespace @import("map.zig"); -const screenWidth = 1280; -const screenHeight = 960; - // TODO: is there anyway i can say fn renderWall : RenderWallFunction? fn renderWall( window: sf.graphics.RenderWindow, @@ -116,7 +113,7 @@ pub fn main() !void { var backSprite = try sf.Sprite.createFromTexture(backTexture); defer backSprite.destroy(); - backSprite.setScale(.{ .x = 4.0 * @intToFloat(f32, screenWidth) / backTextureWidth, .y = @intToFloat(f32, screenHeight) / (2 * backTextureHeight) }); + backSprite.setScale(.{ .x = 4.0 * screenWidth / backTextureWidth, .y = screenHeight / (2 * backTextureHeight) }); // Load brick texture! var wallTexture = try sf.Texture.createFromFile("walls.png"); diff --git a/src/raycast.zig b/src/raycast.zig index 6acc16b..608bb10 100644 --- a/src/raycast.zig +++ b/src/raycast.zig @@ -84,11 +84,15 @@ pub const Player = struct { pub fn renderMapUsing( self: Player, window: RenderWindow, - sprite: Sprite, + wallSprite: Sprite, map: Map, // the abstract the rendering call renderWall: RenderWallFunction, ) void { + self.renderWalls(window, wallSprite, map, renderWall); + } + + fn renderWalls(self: Player, window: RenderWindow, wallSprite: Sprite, map: Map, renderWall: RenderWallFunction) void { const floor = std.math.floor; var col: i32 = 0; @@ -183,7 +187,7 @@ pub const Player = struct { // textures, in this case clockwise if ((horizontal_hit and sinra < 0) or (!horizontal_hit and cosra > 0)) texfrac = 1 - texfrac; - renderWall(window, sprite, col, top, total_length, draw_frac, texfrac, cell.wall_texture); + renderWall(window, wallSprite, col, top, total_length, draw_frac, texfrac, cell.wall_texture); highest_point = top; } diff --git a/src/renderConstants.zig b/src/renderConstants.zig index aa477ee..2dbadee 100644 --- a/src/renderConstants.zig +++ b/src/renderConstants.zig @@ -14,11 +14,13 @@ // // You should have received a copy of the GNU General Public License // along with this program. If not, see . +pub const screenWidth: f32 = 1024; +pub const screenHeight: f32 = 768; pub const planeWidth = 320; pub const planeHeight = 240; -pub const backTextureWidth: f32 = 1280.0; -pub const backTextureHeight: f32 = 240.0; +pub const backTextureWidth: f32 = 1280; +pub const backTextureHeight: f32 = 240; -pub const wallTextureDim: f32 = 16.0; +pub const wallTextureDim: f32 = 32.0; -- cgit v1.3.1