entity: physics rewrite

This commit is contained in:
2022-02-01 23:48:39 +08:00
parent 25872b257d
commit 37ee76e9fc
9 changed files with 201 additions and 256 deletions

View File

@@ -3,6 +3,7 @@ package game
import (
"fmt"
"log"
"math"
"os"
"runtime"
@@ -52,7 +53,8 @@ func (g *Game) imgui() {
if imgui.BeginV("Player", nil, imgui.WindowFlagsAlwaysAutoResize) {
pos := g.player.Position()
vel := g.player.Speed()
imgui.Text(fmt.Sprintf("Pos: (%.5f, %.5f, %.5f), Vel: (%.5f, %.5f, %.5f)", pos[0], pos[1], pos[2], vel[0], vel[1], vel[2]))
igwrap.Text("Pos: (%.5f, %.5f, %.5f), Vel: (%.5f, %.5f, %.5f)", pos[0], pos[1], pos[2], vel[0], vel[1], vel[2])
igwrap.Text("VelXZ=%.5f, VelXYZ=%.5f", math.Sqrt(vel[0]*vel[0]+vel[2]*vel[2]), vel.Length())
}
imgui.End()

View File

@@ -166,6 +166,7 @@ func (g *Game) Init(win *glfw.Window) {
igwrap.MouseScrollCallback(xpos, ypos)
}
})
}
const airAccel = 0.1
@@ -234,7 +235,7 @@ func (g *Game) Update(win *glfw.Window, delta time.Duration) {
io.ViewPos = g.player.EyePosition()
io.ViewDir = itype.Vec3d(mgl64.Rotate3DY(float64(g.rotY.Radians())).Mul3(mgl64.Rotate3DZ(float64(itype.Degrees(g.rotZ)))).Mul3x1(mgl64.Vec3{1, 0, 0}))
render.Framewire.PushBox(g.player.WorldHitbox().ToFloat32(), color.White)
render.Framewire.PushBox(g.player.WorldHitbox()[0].ToFloat32(), color.White)
if g.player.Position()[1] < -100 {
g.player.SetPosition(itype.Vec3d{18, 80, 18})