Implementation/port of Lode Vandevenne´s Raycaster behaving weirdly
Posted: Wed Mar 29, 2023 8:59 pm
I recently posted about having issues with a raycaster, to which i got very helpful answers and even a fully implemented raycaster. After looking at the website (https://lodev.org/cgtutor/raycasting.html) which Bigfoot showed me i tried implementing the dda algorithm which this site covers, but now i have almost the exact same issues as before, the rays being casted in the wrong direction and being kindof cluttered, which shouldnt happen. I suspect one of the issue lies in how i tried to "translate " these lines of c++ into lua :
there are probably even more mistakes which is why i´ll attach a .love
I hope its not against the rules for me to post about such a similar issue twice.
Edit:
i found a mistake in line 162 where i had to replace the second lineheight with the screenheight, so know i can see some rendering, but the other issues remain
Edit2: i fixed all the actual drawing code:
I think one of the issues is how i rotate the camera plane, as the world looks skewed just like in the example on the website, i´ll try fixing that, but i still have no clue why the rays spread like that
Edit 3:
I have found and fixed one more issue, my rotation code
Code: Select all
double deltaDistX = (rayDirX == 0) ? 1e30 : std::abs(1 / rayDirX);
double deltaDistY = (rayDirY == 0) ? 1e30 : std::abs(1 / rayDirY);
|
\/
if rayDirx == 0 then
deltaDistX = 1e30
else
deltaDistX = math.abs(1 / rayDirx)
end
if rayDiry == 0 then
deltaDistY = 1e30
else
deltaDistY = math.abs(1 / rayDiry)
end
I hope its not against the rules for me to post about such a similar issue twice.
Edit:
i found a mistake in line 162 where i had to replace the second lineheight with the screenheight, so know i can see some rendering, but the other issues remain
Edit2: i fixed all the actual drawing code:
I think one of the issues is how i rotate the camera plane, as the world looks skewed just like in the example on the website, i´ll try fixing that, but i still have no clue why the rays spread like that
Code: Select all
if side == 0 then perpWallDist = (sideDistX - deltaDistX)
else perpWallDist = (sideDistY - deltaDistY) end
local lineheight = math.floor(wall_height / perpWallDist)
local drawStart = math.floor(-lineheight / 2 + screen_height / 2)
if drawStart < 0 then drawStart = 0 end
local drawEnd = math.floor(screen_height / 2 + lineheight / 2 )
if drawEnd > screen_height then drawEnd = screen_height - 1 end
love.graphics.setColor(1, 0, 0,1 )
love.graphics.line(x, drawStart, x, drawEnd)
I have found and fixed one more issue, my rotation code
Code: Select all
if love.keyboard.isScancodeDown("d") then
--both camera direction and camera plane must be rotated
local oldDirX = self.delX
self.delX = self.delX * math.cos(-self.rotation_speed) - self.delY * math.sin(-self.rotation_speed)
self.delY = oldDirX * math.sin(-self.rotation_speed) + self.delY * math.cos(-self.rotation_speed)
local oldPlaneX = self.planeX
self.planeX = self.planeX * math.cos(-self.rotation_speed) - self.planeY * math.sin(-self.rotation_speed)
self.planeY = oldPlaneX * math.sin(-self.rotation_speed) + self.planeY * math.cos(-self.rotation_speed)
end
if love.keyboard.isScancodeDown("a") then
--both camera direction and camera plane must be rotated
local oldDirX = self.delX
self.delX = self.delX * math.cos(self.rotation_speed) - self.delY * math.sin(self.rotation_speed)
self.delY = oldDirX * math.sin(self.rotation_speed) + self.delY * math.cos(self.rotation_speed)
local oldPlaneX = self.planeX
self.planeX = self.planeX * math.cos(self.rotation_speed) - self.planeY * math.sin(self.rotation_speed)
self.planeY = oldPlaneX * math.sin(self.rotation_speed) + self.planeY * math.cos(self.rotation_speed)
end