diff --git a/renderer2/generation.go b/renderer2/generation.go index 168bb11..2dbfe9a 100644 --- a/renderer2/generation.go +++ b/renderer2/generation.go @@ -3,7 +3,7 @@ package main import ( "image" "image/color" - "renderer1/hrend" + "renderer2/hrend" ) func Checkerboard(cols []color.Color, size int) image.Image { @@ -33,13 +33,14 @@ func FlatTerrain(size int) *hrend.ObjModel { result.Vertices = append(result.Vertices, hrend.Vec3f{X: float32(x), Y: 0, Z: float32(z)}) } } + width := size + size + 1 // Faces are slightly different; we generate two for every "cell" inside the vertices - for z := 0; z < size*2; z++ { - for x := 0; x < size*2; x++ { - topleft := x + z*size*2 - topright := x + 1 + z*size*2 - bottomleft := x + (z+1)*size*2 - bottomright := x + 1 + (z+1)*size*2 + for z := 0; z < width-1; z++ { + for x := 0; x < width-1; x++ { + topleft := x + z*width + topright := x + 1 + z*width + bottomleft := x + (z+1)*width + bottomright := x + 1 + (z+1)*width // remember to wind counter-clockwise result.Faces = append(result.Faces, hrend.Facef{ hrend.Vertex{Pos: result.Vertices[topleft], Tex: result.VTexture[0]}, diff --git a/renderer2/go.mod b/renderer2/go.mod index 693692a..cb01c63 100644 --- a/renderer2/go.mod +++ b/renderer2/go.mod @@ -1,4 +1,4 @@ -module renderer1 +module renderer2 go 1.22.5 diff --git a/renderer2/main.go b/renderer2/main.go index c2170fb..32dcae8 100644 --- a/renderer2/main.go +++ b/renderer2/main.go @@ -8,7 +8,7 @@ import ( "log" "math" "os" - "renderer1/hrend" + "renderer2/hrend" "runtime/pprof" // For performance profiling (unnecessary) "time" @@ -20,13 +20,9 @@ import ( const ( NearClip = 0.01 FarClip = 100 - FOV = 90.0 - ZOffset = 1.5 - YOffset = 0.5 Movement = 1.0 Rotation = 0.25 LookLock = math.Pi / 32 - Fps = 60 //ObjectFile = "../head.obj" //TextureFile = "../head.jpg" ) @@ -59,9 +55,14 @@ func must(err error) { // However flag works... idk var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") var width = flag.Int("width", 640, "width of window or frame") -var height = flag.Int("width", 480, "height of window or frame") +var height = flag.Int("height", 480, "height of window or frame") var renderout = flag.String("renderout", "", "If set, rendering is done to a file instead of realtime") var renderinput = flag.String("renderinput", "", "If not realtime, the inputs are taken from here.") +var xofs = flag.Float64("xofs", 0, "starting x-offset") +var zofs = flag.Float64("zofs", 0, "starting z-offset") +var yofs = flag.Float64("yofs", 0.5, "starting y-offset") +var fov = flag.Float64("fov", 90, "the horizontal fov") +var fps = flag.Int("fps", 60, "fps to run (realtime only)") // var renderconfig = flag.String("renderconfig", "", "if set, rendering is written out") @@ -72,6 +73,7 @@ func IsRealtime() bool { // Do next inputs, whether they come from raylib or a file func CameraInput(yaw, pitch float32) (float32, float32, hrend.Vec3f) { + Fps := float32(*fps) mouse := rl.GetMouseDelta() pitch += Rotation * mouse.Y / Fps yaw += Rotation * mouse.X / Fps @@ -104,7 +106,7 @@ func CameraInput(yaw, pitch float32) (float32, float32, hrend.Vec3f) { moverot.SetRotationY(-yaw) newcamtrans = moverot.MultiplyPoint3(newcamtrans) - return pitch, yaw, newcamtrans + return yaw, pitch, newcamtrans } func main() { @@ -131,7 +133,7 @@ func main() { if IsRealtime() { rl.InitWindow(int32(Width), int32(Height), "Simple renderer with raylib") defer rl.CloseWindow() - rl.SetTargetFPS(Fps) + rl.SetTargetFPS(int32(*fps)) rl.DisableCursor() rfb := NewRaylibBuffer(Width, Height) defer rl.UnloadTexture(rfb.Texture) @@ -152,18 +154,18 @@ func main() { rb := hrend.NewRenderbuffer(fb, Width, Height) // Generate world - wtexraw := Checkerboard([]color.Color{color.RGBA{R: 255, G: 0, B: 0, A: 255}, color.RGBA{R: 0, G: 0, B: 255, A: 255}}, 32) + wtexraw := Checkerboard([]color.Color{color.RGBA{R: 0, G: 255, B: 0, A: 255}, color.RGBA{R: 50, G: 150, B: 0, A: 255}}, 32) wtex := hrend.NewTexture(wtexraw, 1) world := FlatTerrain(10) // These don't really change var projection, viewport hrend.Mat44f - projection.SetProjection(float32(FOV), float32(Width)/float32(Height), NearClip, FarClip) + projection.SetProjection(float32(*fov), float32(Width)/float32(Height), NearClip, FarClip) viewport.SetViewportSimple(int(Width), int(Height), 1) //65535) var camera hrend.Mat44f var newcamtrans hrend.Vec3f - camtrans := hrend.Vec3f{X: 0, Y: YOffset, Z: ZOffset} + camtrans := hrend.Vec3f{X: float32(*xofs), Y: float32(*yofs), Z: float32(*zofs)} camup := hrend.Vec3f{X: 0, Y: 1, Z: 0} // In our system, 0 degree yaw is facing -Z, into the scene