commit c1541bec81d065f1e5bb576a675cda2fdd121a4f
parent eb86b4639c4b06a71b404489bff845b687b26b36
Author: Matsuda Kenji <info@mtkn.jp>
Date: Tue, 12 Nov 2024 07:26:16 +0900
remove glfw dependency from cmd/sample
Diffstat:
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/cmd/sample/main.go b/cmd/sample/main.go
@@ -6,9 +6,9 @@ import (
"math"
"path/filepath"
"runtime"
+ "time"
"github.com/go-gl/gl/v3.3-core/gl"
- "github.com/go-gl/glfw/v3.3/glfw"
"git.mtkn.jp/tofu"
)
@@ -61,7 +61,6 @@ func processInput(app *App) {
}
}
-
func watchCursor(app *App) {
const sensitivity = 0.005
firstTime := true
@@ -138,30 +137,28 @@ var object = tofu.Object{
var alpha float32 = 0.2
type App struct {
- program *tofu.Program
- lightProgram *tofu.Program
- lightCol tofu.Vec3
- objCol tofu.Vec3
-
- cursorChan chan tofu.Cursor
- cur tofu.Cursor
-
- keyChan chan struct{}
-
- camera *tofu.Camera
-
- termination bool
+ program *tofu.Program
+ lightProgram *tofu.Program
+ lightCol tofu.Vec3
+ objCol tofu.Vec3
+ cursorChan chan tofu.Cursor
+ cur tofu.Cursor
+ keyChan chan struct{}
+ camera *tofu.Camera
+ termination bool
+ startedAt time.Time
}
func (app *App) Update() error {
+ now := float32(time.Since(app.startedAt).Seconds())
processInput(app)
if app.termination {
return tofu.Termination
}
- lightModel := tofu.Rotate(float32(glfw.GetTime()), tofu.Vec3{0, 1.41421356 / 2, 1.41421356 / 2}).
+ lightModel := tofu.Rotate(now, tofu.Vec3{0, 1.41421356 / 2, 1.41421356 / 2}).
Mul(tofu.Translate(tofu.Vec3{3, 0, 0})).
Mul(tofu.Scale(0.1))
- lightPos := tofu.Rotate(float32(glfw.GetTime()), tofu.Vec3{0, 1.41421356 / 2, 1.41421356 / 2}).
+ lightPos := tofu.Rotate(now, tofu.Vec3{0, 1.41421356 / 2, 1.41421356 / 2}).
MulVec(tofu.Vec4{3, 0, 0, 0}).Vec3()
view := camera.View()
@@ -173,7 +170,7 @@ func (app *App) Update() error {
app.program.SetVec3("lightCol", app.lightCol)
app.program.SetVec3("camPos", camera.Pos)
model := tofu.Translate(tofu.Vec3{0, 0, 0}).
- Mul(tofu.Rotate(float32(glfw.GetTime()), tofu.Vec3{math.Sqrt2 / 2, -math.Sqrt2 / 2, 0}))
+ Mul(tofu.Rotate(now, tofu.Vec3{math.Sqrt2 / 2, -math.Sqrt2 / 2, 0}))
app.program.SetMat4("model", model)
app.program.SetVec3("objCol", app.objCol)
@@ -198,6 +195,7 @@ func main() {
app.lightCol = tofu.Vec3{1, 1, 1}
app.objCol = tofu.Vec3{1.0, 0.5, 0.32}
app.cursorChan = make(chan tofu.Cursor)
+ app.startedAt = time.Now()
go watchCursor(app)
tofu.SetWindowSize(winW, winH)
tofu.Init()