1
0
Fork 0
go-raytracer/render/minimap.go
2025-06-08 15:51:07 +02:00

36 lines
1.1 KiB
Go

package render
import (
"github.com/pnx/go-raytracer/graphics"
"github.com/pnx/go-raytracer/math"
"github.com/pnx/go-raytracer/world"
)
func DrawMiniMap(ctx *graphics.Context, camera math.Transform, level *world.Level) {
const tileSize = 32
const scale = float64(tileSize) / float64(world.TileSize)
// offset := math.Vec2i32{X: 25, Y: 25}
// size := math.Vec2i32{X: 200, Y: 100}
ctx.DrawRect(0, 0, int32(level.W*tileSize)+3, int32(level.H*tileSize)+3, math.Color{})
for y := range level.H {
for x := range level.W {
if level.Wall(x, y) {
ctx.DrawRect(int32(x*tileSize), int32(y*tileSize), tileSize, tileSize, math.Color{R: 255, G: 255, B: 255, A: 255})
}
}
}
// Camera Position
cPos := camera.Position.Get().Scale(scale)
ctx.DrawRect(int32(cPos.X-2), int32(cPos.Y-2), 4, 4, math.Color{R: 255, G: 0, B: 255, A: 255})
// Rays
for x := range ctx.Width() {
hit := CastRay(camera, level, int(x), int(ctx.Width()))
end := camera.Position.Get().AddVec(hit.Pos.Scale(world.TileSize)).Scale(scale)
ctx.DrawLine(int32(cPos.X), int32(cPos.Y), int32(end.X), int32(end.Y), math.Color{R: 150, G: 150, B: 0, A: 255})
}
}