diff --git a/engine/game.go b/engine/game.go index 7d7abed..869eb8b 100755 --- a/engine/game.go +++ b/engine/game.go @@ -41,7 +41,6 @@ func Run(g Game, w *Window, rend renderer.Render, ui nmageimgui.ImguiInfo) { for isRunning { - //PERF: Cache these width, height = w.SDLWin.GetSize() fbWidth, fbHeight = w.SDLWin.GLGetDrawableSize() diff --git a/go.mod b/go.mod index e9213b6..7e44b32 100755 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 require ( github.com/bloeys/assimp-go v0.4.4 - github.com/bloeys/gglm v0.49.0 + github.com/bloeys/gglm v0.50.0 ) require ( @@ -16,4 +16,7 @@ require ( github.com/mandykoh/prism v0.35.1 ) -require github.com/mandykoh/go-parallel v0.1.0 // indirect +require ( + github.com/mandykoh/go-parallel v0.1.0 // indirect + golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect +) diff --git a/go.sum b/go.sum index da1d88b..de27e1d 100755 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/AllenDang/cimgui-go v0.0.0-20230720025235-f2ff398a66b2 h1:3HA/5qD8Rim github.com/AllenDang/cimgui-go v0.0.0-20230720025235-f2ff398a66b2/go.mod h1:iNfbIyOBN8k3XScMxULbrwYbPsXEAUD0Jb6UwrspQb8= github.com/bloeys/assimp-go v0.4.4 h1:Yn5e/RpE0Oes0YMBy8O7KkwAO4R/RpgrZPJCt08dVIU= github.com/bloeys/assimp-go v0.4.4/go.mod h1:my3yRxT7CfOztmvi+0svmwbaqw0KFrxaHxncoyaEIP0= -github.com/bloeys/gglm v0.49.0 h1:YtbyHpszYhjnxw7KVV0LaCdBktRMqfGx/i37EMomxsE= -github.com/bloeys/gglm v0.49.0/go.mod h1:qwJQ0WzV191wAMwlGicbfbChbKoSedMk7gFFX6GnyOk= +github.com/bloeys/gglm v0.50.0 h1:DlGLp9z8KMNx+hNR6PjnPmC0HjDRC19QwAKL1iwhOxs= +github.com/bloeys/gglm v0.50.0/go.mod h1:5s2U/NiOrtJyrSup1j8wK+QOBmGIO03ub0LHMvuNSK8= github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 h1:zDw5v7qm4yH7N8C8uWd+8Ii9rROdgWxQuGoJ9WDXxfk= github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw= github.com/mandykoh/go-parallel v0.1.0 h1:7vJMNMC4dsbgZdkAb2A8tV5ENY1v7VxIO1wzQWZoT8k= @@ -15,6 +15,8 @@ github.com/veandco/go-sdl2 v0.4.35/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofe github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI= golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= diff --git a/main.go b/main.go index c3cd5d4..4f09df7 100755 --- a/main.go +++ b/main.go @@ -200,8 +200,8 @@ var ( frameTimesMsIndex int = 0 frameTimesMs []float32 = make([]float32, 0, FRAME_TIME_MS_SAMPLES) - camSpeed float32 = 15 - mouseSensitivity float32 = 0.5 + camMoveSpeed float32 = 15 + camRotSpeed float32 = 0.5 window engine.Window @@ -412,9 +412,10 @@ func (g *Game) handleWindowEvents(e sdl.Event) { g.WinWidth = e.Data1 g.WinHeight = e.Data2 - cam.AspectRatio = float32(g.WinWidth) / float32(g.WinHeight) + cam.AspectRatio = float32(g.WinWidth) / float32(g.WinHeight) cam.Update() + updateAllProjViewMats(cam.ProjMat, cam.ViewMat) } } @@ -886,7 +887,7 @@ func (g *Game) showDebugWindow() { // Ambient light imgui.Text("Ambient Light") - if imgui.DragFloat3("Ambient Color", &ambientColor.Data) { + if imgui.ColorEdit3("Ambient Color", &ambientColor.Data) { whiteMat.SetUnifVec3("ambientColor", &ambientColor) containerMat.SetUnifVec3("ambientColor", &ambientColor) groundMat.SetUnifVec3("ambientColor", &ambientColor) @@ -907,14 +908,14 @@ func (g *Game) showDebugWindow() { palleteMat.SetUnifVec3("dirLight.dir", &dirLight.Dir) } - if imgui.DragFloat3("Diffuse Color", &dirLight.DiffuseColor.Data) { + if imgui.ColorEdit3("Diffuse Color", &dirLight.DiffuseColor.Data) { whiteMat.SetUnifVec3("dirLight.diffuseColor", &dirLight.DiffuseColor) containerMat.SetUnifVec3("dirLight.diffuseColor", &dirLight.DiffuseColor) groundMat.SetUnifVec3("dirLight.diffuseColor", &dirLight.DiffuseColor) palleteMat.SetUnifVec3("dirLight.diffuseColor", &dirLight.DiffuseColor) } - if imgui.DragFloat3("Specular Color", &dirLight.SpecularColor.Data) { + if imgui.ColorEdit3("Specular Color", &dirLight.SpecularColor.Data) { whiteMat.SetUnifVec3("dirLight.specularColor", &dirLight.SpecularColor) containerMat.SetUnifVec3("dirLight.specularColor", &dirLight.SpecularColor) groundMat.SetUnifVec3("dirLight.specularColor", &dirLight.SpecularColor) @@ -962,14 +963,14 @@ func (g *Game) showDebugWindow() { palleteMat.SetUnifVec3(indexString+".pos", &pl.Pos) } - if imgui.DragFloat3("Diffuse Color", &pl.DiffuseColor.Data) { + if imgui.ColorEdit3("Diffuse Color", &pl.DiffuseColor.Data) { whiteMat.SetUnifVec3(indexString+".diffuseColor", &pl.DiffuseColor) containerMat.SetUnifVec3(indexString+".diffuseColor", &pl.DiffuseColor) groundMat.SetUnifVec3(indexString+".diffuseColor", &pl.DiffuseColor) palleteMat.SetUnifVec3(indexString+".diffuseColor", &pl.DiffuseColor) } - if imgui.DragFloat3("Specular Color", &pl.SpecularColor.Data) { + if imgui.ColorEdit3("Specular Color", &pl.SpecularColor.Data) { whiteMat.SetUnifVec3(indexString+".specularColor", &pl.SpecularColor) containerMat.SetUnifVec3(indexString+".specularColor", &pl.SpecularColor) groundMat.SetUnifVec3(indexString+".specularColor", &pl.SpecularColor) @@ -1012,34 +1013,39 @@ func (g *Game) showDebugWindow() { palleteMat.SetUnifVec3(indexString+".dir", &l.Dir) } - if imgui.DragFloat3("Diffuse Color", &l.DiffuseColor.Data) { + if imgui.ColorEdit3("Diffuse Color", &l.DiffuseColor.Data) { whiteMat.SetUnifVec3(indexString+".diffuseColor", &l.DiffuseColor) containerMat.SetUnifVec3(indexString+".diffuseColor", &l.DiffuseColor) groundMat.SetUnifVec3(indexString+".diffuseColor", &l.DiffuseColor) palleteMat.SetUnifVec3(indexString+".diffuseColor", &l.DiffuseColor) } - if imgui.DragFloat3("Specular Color", &l.SpecularColor.Data) { + if imgui.ColorEdit3("Specular Color", &l.SpecularColor.Data) { whiteMat.SetUnifVec3(indexString+".specularColor", &l.SpecularColor) containerMat.SetUnifVec3(indexString+".specularColor", &l.SpecularColor) groundMat.SetUnifVec3(indexString+".specularColor", &l.SpecularColor) palleteMat.SetUnifVec3(indexString+".specularColor", &l.SpecularColor) } - if imgui.DragFloat("Inner Cutoff Radians", &l.InnerCutoffRad) { + if imgui.DragFloatRange2V( + "Cutoff Radians", + &l.InnerCutoffRad, + &l.OuterCutoffRad, + 0.1, + 0, + 0, + "%.3f", + "%.3f", + imgui.SliderFlagsNone, + ) { cos := l.InnerCutoffCos() - whiteMat.SetUnifFloat32(indexString+".innerCutoff", cos) containerMat.SetUnifFloat32(indexString+".innerCutoff", cos) groundMat.SetUnifFloat32(indexString+".innerCutoff", cos) palleteMat.SetUnifFloat32(indexString+".innerCutoff", cos) - } - - if imgui.DragFloat("Outer Cutoff Radians", &l.OuterCutoffRad) { - - cos := l.OuterCutoffCos() + cos = l.OuterCutoffCos() whiteMat.SetUnifFloat32(indexString+".outerCutoff", cos) containerMat.SetUnifFloat32(indexString+".outerCutoff", cos) groundMat.SetUnifFloat32(indexString+".outerCutoff", cos) @@ -1084,11 +1090,15 @@ func (g *Game) updateCameraLookAround() { return } + const MAX_MOUSE_MOVE = 300 + mouseX = gglm.Clamp(mouseX, -MAX_MOUSE_MOVE, MAX_MOUSE_MOVE) + mouseY = gglm.Clamp(mouseY, -MAX_MOUSE_MOVE, MAX_MOUSE_MOVE) + // Yaw - yaw += float32(mouseX) * mouseSensitivity * timing.DT() + yaw += float32(mouseX) * camRotSpeed * timing.DT() // Pitch - pitch += float32(-mouseY) * mouseSensitivity * timing.DT() + pitch += float32(-mouseY) * camRotSpeed * timing.DT() if pitch > 1.5 { pitch = 1.5 } @@ -1097,7 +1107,6 @@ func (g *Game) updateCameraLookAround() { pitch = -1.5 } - // Update cam forward cam.UpdateRotation(pitch, yaw) updateAllProjViewMats(cam.ProjMat, cam.ViewMat) @@ -1114,21 +1123,21 @@ func (g *Game) updateCameraPos() { // Forward and backward if input.KeyDown(sdl.K_w) { - cam.Pos.Add(cam.Forward.Clone().Scale(camSpeed * camSpeedScale * timing.DT())) + cam.Pos.Add(cam.Forward.Clone().Scale(camMoveSpeed * camSpeedScale * timing.DT())) update = true } else if input.KeyDown(sdl.K_s) { - cam.Pos.Add(cam.Forward.Clone().Scale(-camSpeed * camSpeedScale * timing.DT())) + cam.Pos.Add(cam.Forward.Clone().Scale(-camMoveSpeed * camSpeedScale * timing.DT())) update = true } // Left and right if input.KeyDown(sdl.K_d) { cross := gglm.Cross(&cam.Forward, &cam.WorldUp) - cam.Pos.Add(cross.Normalize().Scale(camSpeed * camSpeedScale * timing.DT())) + cam.Pos.Add(cross.Normalize().Scale(camMoveSpeed * camSpeedScale * timing.DT())) update = true } else if input.KeyDown(sdl.K_a) { cross := gglm.Cross(&cam.Forward, &cam.WorldUp) - cam.Pos.Add(cross.Normalize().Scale(-camSpeed * camSpeedScale * timing.DT())) + cam.Pos.Add(cross.Normalize().Scale(-camMoveSpeed * camSpeedScale * timing.DT())) update = true }