diff --git a/renderer1/main.go b/renderer1/main.go index aca0d95..168ae8b 100644 --- a/renderer1/main.go +++ b/renderer1/main.go @@ -5,6 +5,7 @@ import ( "fmt" "image" "log" + "math" "os" "renderer1/hrend" "runtime/pprof" // For performance profiling (unnecessary) @@ -23,7 +24,8 @@ const ( FOV = 90.0 ZOffset = 1.5 Movement = 1.0 - Rotation = 1.0 + Rotation = 0.25 + LookLock = math.Pi / 32 Fps = 60 ObjectFile = "../head.obj" TextureFile = "../head.jpg" @@ -82,6 +84,7 @@ func main() { defer rl.CloseWindow() rl.SetTargetFPS(Fps) + rl.DisableCursor() fb := NewRaylibBuffer(Width, Height) defer rl.UnloadTexture(fb.Texture) @@ -115,9 +118,10 @@ func main() { camtrans := hrend.Vec3f{X: 0, Y: 0, Z: ZOffset} camup := hrend.Vec3f{X: 0, Y: 1, Z: 0} - //xrot := float32(0.0) - //zrot := float32(0.0) lookvec := hrend.Vec3f{X: 0, Y: 0, Z: -1} + // In our system, 0 degree yaw is facing -Z, into the scene + yaw := float32(0) + pitch := float32(math.Pi / 2) // Start looking flat // in all three directions... I think?? //yrot := float32(0.0) @@ -125,39 +129,56 @@ func main() { //var camrotation, camtrans hrend.Mat44f //camrotation.SetIdentity() //var camrotx, camroty, camrotz hrend.Mat44f + //var camrotx, camroty hrend.Mat44f var camera hrend.Mat44f for !rl.WindowShouldClose() { start := time.Now() + mouse := rl.GetMouseDelta() + + pitch += Rotation * mouse.Y / Fps + yaw += Rotation * mouse.X / Fps + + // Need a clamp function or something + if pitch < LookLock { + pitch = LookLock + } else if pitch > math.Pi-LookLock { + pitch = math.Pi - LookLock + } + + newcamtrans := hrend.Vec3f{X: 0, Y: 0, Z: 0} if rl.IsKeyDown(rl.KeyD) { - camtrans.X += Movement / Fps + newcamtrans.X += Movement / Fps } if rl.IsKeyDown(rl.KeyA) { - camtrans.X -= Movement / Fps + newcamtrans.X -= Movement / Fps } // Moving forward moves in the negative z direction, since we FACE // the -z axis if rl.IsKeyDown(rl.KeyW) { - camtrans.Z -= Movement / Fps + newcamtrans.Z -= Movement / Fps } if rl.IsKeyDown(rl.KeyS) { - camtrans.Z += Movement / Fps + newcamtrans.Z += Movement / Fps } if rl.IsKeyDown(rl.KeySpace) { - camtrans.Y += Movement / Fps + newcamtrans.Y += Movement / Fps } if rl.IsKeyDown(rl.KeyLeftShift) { - camtrans.Y -= Movement / Fps + newcamtrans.Y -= Movement / Fps } - mouse := rl.GetMouseDelta() - mouse.X *= 1 / Fps - mouse.Y *= 1 / Fps + lookvec.Z = float32(-math.Sin(float64(pitch)) * math.Cos(float64(yaw))) + lookvec.X = float32(math.Sin(float64(pitch)) * math.Sin(float64(yaw))) + lookvec.Y = float32(math.Cos(float64(pitch))) + //camrotx.SetRotationX(rotvec.X) + //camroty.SetRotationY(rotvec.Y) + + //lookvec := camroty.Multiply(&camrotx).MultiplyPoint3(baselook) + camtrans = *camtrans.Add(&newcamtrans) - //camrotx.SetRotationX(xrot) - //camroty.SetRotationY(yrot) //camrotz.SetRotationZ(zrot) //camrotation = *camrotation.Multiply( // This might (thought not currently)