commit 9f41cd151bdb38a4c2f457014764e744ccb36f2d
parent e98182433ed2b1ed8837709822e058bd44df9867
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sun, 10 Nov 2024 15:56:19 +0900
scale light
Diffstat:
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/cmd/sample/main.go b/cmd/sample/main.go
@@ -153,7 +153,8 @@ type App struct{
func (app App) Update() error {
lightModel := tofu.Rotate(float32(glfw.GetTime()), tofu.Vec3{0, 1.41421356/2, 1.41421356/2}).
- Mul(tofu.Translate(tofu.Vec3{3, 0, 0}))
+ 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}).
MulVec(tofu.Vec4{3, 0, 0, 0}).Vec3()
diff --git a/math.go b/math.go
@@ -84,6 +84,15 @@ func (m Mat4) MulVec(v Vec4) Vec4 {
}
}
+func Scale(r float32) Mat4 {
+ return Mat4{
+ r, 0, 0, 0,
+ 0, r, 0, 0,
+ 0, 0, r, 0,
+ 0, 0, 0, 1,
+ }
+}
+
func Translate(v Vec3) Mat4 {
var n Mat4
n[0] = 1
diff --git a/object.go b/object.go
@@ -2,7 +2,6 @@ package tofu
import (
"image/color"
- "log"
"github.com/go-gl/gl/v3.3-core/gl"
)
@@ -76,14 +75,12 @@ func newVAO(obj *Object) *VAO {
vao := &VAO{id: id, vbo: newBuffer(), ebo: newBuffer()}
vao.bind()
data := obj.data()
- log.Println(data)
vao.setData(data)
vao.setAttribute(UniformVertex, 3, objectStride, 0)
vao.setAttribute(UniformColor, 3, objectStride, 3)
vao.setAttribute(UniformTexCoords, 2, objectStride, 6)
vao.setAttribute(UniformNormal, 3, objectStride, 8)
fdata := obj.faceData()
- log.Println(fdata)
vao.setFaces(fdata)
return vao
}