Math is hard
This commit is contained in:
parent
c8b1a82229
commit
7a32dab579
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"renderer1/hrend"
|
"renderer1/hrend"
|
||||||
"runtime/pprof" // For performance profiling (unnecessary)
|
"runtime/pprof" // For performance profiling (unnecessary)
|
||||||
@ -23,7 +24,8 @@ const (
|
|||||||
FOV = 90.0
|
FOV = 90.0
|
||||||
ZOffset = 1.5
|
ZOffset = 1.5
|
||||||
Movement = 1.0
|
Movement = 1.0
|
||||||
Rotation = 1.0
|
Rotation = 0.25
|
||||||
|
LookLock = math.Pi / 32
|
||||||
Fps = 60
|
Fps = 60
|
||||||
ObjectFile = "../head.obj"
|
ObjectFile = "../head.obj"
|
||||||
TextureFile = "../head.jpg"
|
TextureFile = "../head.jpg"
|
||||||
@ -82,6 +84,7 @@ func main() {
|
|||||||
defer rl.CloseWindow()
|
defer rl.CloseWindow()
|
||||||
|
|
||||||
rl.SetTargetFPS(Fps)
|
rl.SetTargetFPS(Fps)
|
||||||
|
rl.DisableCursor()
|
||||||
|
|
||||||
fb := NewRaylibBuffer(Width, Height)
|
fb := NewRaylibBuffer(Width, Height)
|
||||||
defer rl.UnloadTexture(fb.Texture)
|
defer rl.UnloadTexture(fb.Texture)
|
||||||
@ -115,9 +118,10 @@ func main() {
|
|||||||
camtrans := hrend.Vec3f{X: 0, Y: 0, Z: ZOffset}
|
camtrans := hrend.Vec3f{X: 0, Y: 0, Z: ZOffset}
|
||||||
camup := hrend.Vec3f{X: 0, Y: 1, Z: 0}
|
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}
|
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??
|
// in all three directions... I think??
|
||||||
//yrot := float32(0.0)
|
//yrot := float32(0.0)
|
||||||
@ -125,39 +129,56 @@ func main() {
|
|||||||
//var camrotation, camtrans hrend.Mat44f
|
//var camrotation, camtrans hrend.Mat44f
|
||||||
//camrotation.SetIdentity()
|
//camrotation.SetIdentity()
|
||||||
//var camrotx, camroty, camrotz hrend.Mat44f
|
//var camrotx, camroty, camrotz hrend.Mat44f
|
||||||
|
//var camrotx, camroty hrend.Mat44f
|
||||||
var camera hrend.Mat44f
|
var camera hrend.Mat44f
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
|
|
||||||
start := time.Now()
|
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) {
|
if rl.IsKeyDown(rl.KeyD) {
|
||||||
camtrans.X += Movement / Fps
|
newcamtrans.X += Movement / Fps
|
||||||
}
|
}
|
||||||
if rl.IsKeyDown(rl.KeyA) {
|
if rl.IsKeyDown(rl.KeyA) {
|
||||||
camtrans.X -= Movement / Fps
|
newcamtrans.X -= Movement / Fps
|
||||||
}
|
}
|
||||||
// Moving forward moves in the negative z direction, since we FACE
|
// Moving forward moves in the negative z direction, since we FACE
|
||||||
// the -z axis
|
// the -z axis
|
||||||
if rl.IsKeyDown(rl.KeyW) {
|
if rl.IsKeyDown(rl.KeyW) {
|
||||||
camtrans.Z -= Movement / Fps
|
newcamtrans.Z -= Movement / Fps
|
||||||
}
|
}
|
||||||
if rl.IsKeyDown(rl.KeyS) {
|
if rl.IsKeyDown(rl.KeyS) {
|
||||||
camtrans.Z += Movement / Fps
|
newcamtrans.Z += Movement / Fps
|
||||||
}
|
}
|
||||||
if rl.IsKeyDown(rl.KeySpace) {
|
if rl.IsKeyDown(rl.KeySpace) {
|
||||||
camtrans.Y += Movement / Fps
|
newcamtrans.Y += Movement / Fps
|
||||||
}
|
}
|
||||||
if rl.IsKeyDown(rl.KeyLeftShift) {
|
if rl.IsKeyDown(rl.KeyLeftShift) {
|
||||||
camtrans.Y -= Movement / Fps
|
newcamtrans.Y -= Movement / Fps
|
||||||
}
|
}
|
||||||
|
|
||||||
mouse := rl.GetMouseDelta()
|
lookvec.Z = float32(-math.Sin(float64(pitch)) * math.Cos(float64(yaw)))
|
||||||
mouse.X *= 1 / Fps
|
lookvec.X = float32(math.Sin(float64(pitch)) * math.Sin(float64(yaw)))
|
||||||
mouse.Y *= 1 / Fps
|
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)
|
//camrotz.SetRotationZ(zrot)
|
||||||
//camrotation = *camrotation.Multiply(
|
//camrotation = *camrotation.Multiply(
|
||||||
// This might (thought not currently)
|
// This might (thought not currently)
|
||||||
|
Loading…
Reference in New Issue
Block a user