feat(main): floor and ceiling cast
This commit is contained in:
parent
40342a6d35
commit
9f19df48db
44
main.go
44
main.go
@ -110,8 +110,48 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
for i := range pixels {
|
||||
pixels[i] = 0x00000000 // Set background to black
|
||||
// Floorcasting logic
|
||||
for y := 0; y < screenHeight; y += screenScale {
|
||||
rayDirX0 := dirX - planeX
|
||||
rayDirY0 := dirY - planeY
|
||||
rayDirX1 := dirX + planeX
|
||||
rayDirY1 := dirY + planeY
|
||||
|
||||
p := y - screenHeight/2
|
||||
if p == 0 {
|
||||
continue // avoid division by zero
|
||||
}
|
||||
|
||||
posZ := 0.5 * float64(screenHeight)
|
||||
rowDistance := posZ / float64(p)
|
||||
|
||||
floorStepX := rowDistance * (rayDirX1 - rayDirX0) / float64(screenWidth)
|
||||
floorStepY := rowDistance * (rayDirY1 - rayDirY0) / float64(screenWidth)
|
||||
|
||||
floorX := posX + rowDistance*rayDirX0
|
||||
floorY := posY + rowDistance*rayDirY0
|
||||
|
||||
for x := 0; x < screenWidth; x++ {
|
||||
cellX := int(floorX)
|
||||
cellY := int(floorY)
|
||||
|
||||
tx := int(float64(texWidth)*(floorX-float64(cellX))) & (texWidth - 1)
|
||||
ty := int(float64(texHeight)*(floorY-float64(cellY))) & (texHeight - 1)
|
||||
|
||||
floorX += floorStepX
|
||||
floorY += floorStepY
|
||||
|
||||
floorTexture := 3
|
||||
ceilingTexture := 6
|
||||
|
||||
var color uint32 = textures[floorTexture][texWidth*ty+tx]
|
||||
color = (color >> 1) & 0x7F7F7F // darken
|
||||
pixels[y*screenWidth+x] = color
|
||||
|
||||
color = textures[ceilingTexture][texWidth*ty+tx]
|
||||
color = (color >> 1) & 0x7F7F7F
|
||||
pixels[(screenHeight-y-1)*screenWidth+x] = color
|
||||
}
|
||||
}
|
||||
|
||||
// Raycasting logic
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user