Really dumb functions
This commit is contained in:
parent
ccc2823c83
commit
362ed0802c
@ -158,6 +158,22 @@ func (m *Mat44f) SetRotationZ(radang float32) {
|
|||||||
m[2] = -m[4]
|
m[2] = -m[4]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: need roll too
|
||||||
|
func (m *Mat44f) SetModel(loc *Vec3f, yaw float32, pitch float32, scale float32, up *Vec3f) Vec3f {
|
||||||
|
// Use sphere equation to compute lookat vector through the two
|
||||||
|
// player-controled angles (pitch and yaw)
|
||||||
|
lookvec := Vec3f{
|
||||||
|
Z: float32(-math.Sin(float64(pitch)) * math.Cos(float64(yaw))),
|
||||||
|
X: float32(math.Sin(float64(pitch)) * math.Sin(float64(yaw))),
|
||||||
|
Y: float32(math.Cos(float64(pitch))),
|
||||||
|
}
|
||||||
|
m.SetLookAt(loc, loc.Add(&lookvec), up)
|
||||||
|
m.Set(0, 0, m.Get(0, 0)*scale)
|
||||||
|
m.Set(1, 1, m.Get(1, 1)*scale)
|
||||||
|
m.Set(2, 2, m.Get(2, 2)*scale)
|
||||||
|
return lookvec
|
||||||
|
}
|
||||||
|
|
||||||
// Note: use {0,1,0} for up for normal use
|
// Note: use {0,1,0} for up for normal use
|
||||||
func (m *Mat44f) SetLookAt(from *Vec3f, to *Vec3f, up *Vec3f) {
|
func (m *Mat44f) SetLookAt(from *Vec3f, to *Vec3f, up *Vec3f) {
|
||||||
forward := from.Sub(to).Normalize()
|
forward := from.Sub(to).Normalize()
|
||||||
|
@ -94,12 +94,6 @@ func main() {
|
|||||||
rb := hrend.NewRenderbuffer(fb, Width, Height)
|
rb := hrend.NewRenderbuffer(fb, Width, Height)
|
||||||
o, texture := loadDefault()
|
o, texture := loadDefault()
|
||||||
|
|
||||||
// light := hrend.Vec3f{
|
|
||||||
// X: 0,
|
|
||||||
// Y: 0,
|
|
||||||
// Z: -1,
|
|
||||||
// }
|
|
||||||
|
|
||||||
var thing hrend.Vec2i
|
var thing hrend.Vec2i
|
||||||
log.Print(thing)
|
log.Print(thing)
|
||||||
|
|
||||||
@ -118,19 +112,11 @@ 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}
|
||||||
|
|
||||||
lookvec := hrend.Vec3f{X: 0, Y: 0, Z: -1}
|
|
||||||
// In our system, 0 degree yaw is facing -Z, into the scene
|
// In our system, 0 degree yaw is facing -Z, into the scene
|
||||||
yaw := float32(0)
|
yaw := float32(0)
|
||||||
pitch := float32(math.Pi / 2) // Start looking flat
|
pitch := float32(math.Pi / 2) // Start looking flat
|
||||||
|
|
||||||
// in all three directions... I think??
|
var camera, moverot hrend.Mat44f
|
||||||
//yrot := float32(0.0)
|
|
||||||
|
|
||||||
//var camrotation, camtrans hrend.Mat44f
|
|
||||||
//camrotation.SetIdentity()
|
|
||||||
//var camrotx, camroty, camrotz hrend.Mat44f
|
|
||||||
//var camrotx, camroty hrend.Mat44f
|
|
||||||
var camera hrend.Mat44f
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
|
|
||||||
@ -156,7 +142,7 @@ func main() {
|
|||||||
newcamtrans.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 (the camera does anyway)
|
||||||
if rl.IsKeyDown(rl.KeyW) {
|
if rl.IsKeyDown(rl.KeyW) {
|
||||||
newcamtrans.Z -= Movement / Fps
|
newcamtrans.Z -= Movement / Fps
|
||||||
}
|
}
|
||||||
@ -170,23 +156,14 @@ func main() {
|
|||||||
newcamtrans.Y -= Movement / Fps
|
newcamtrans.Y -= Movement / Fps
|
||||||
}
|
}
|
||||||
|
|
||||||
lookvec.Z = float32(-math.Sin(float64(pitch)) * math.Cos(float64(yaw)))
|
// translate the new camera movement based on the yaw
|
||||||
lookvec.X = float32(math.Sin(float64(pitch)) * math.Sin(float64(yaw)))
|
moverot.SetRotationY(-yaw)
|
||||||
lookvec.Y = float32(math.Cos(float64(pitch)))
|
newcamtrans = moverot.MultiplyPoint3(newcamtrans)
|
||||||
//camrotx.SetRotationX(rotvec.X)
|
|
||||||
//camroty.SetRotationY(rotvec.Y)
|
|
||||||
|
|
||||||
//lookvec := camroty.Multiply(&camrotx).MultiplyPoint3(baselook)
|
|
||||||
camtrans = *camtrans.Add(&newcamtrans)
|
camtrans = *camtrans.Add(&newcamtrans)
|
||||||
|
|
||||||
//camrotz.SetRotationZ(zrot)
|
// The camera is really just a model
|
||||||
//camrotation = *camrotation.Multiply(
|
lookvec := camera.SetModel(&camtrans, yaw, pitch, 1.0, &camup)
|
||||||
// This might (thought not currently)
|
|
||||||
//camtrans.SetTranslation(xofs, yofs, zofs)
|
|
||||||
|
|
||||||
camera.SetLookAt(&camtrans, camtrans.Add(&lookvec), &camup)
|
|
||||||
|
|
||||||
//screenmat := camrotx.Multiply(&camroty).Multiply(&camrotz).Multiply(&camtrans).Inverse().Multiply(&projection)
|
|
||||||
screenmat := camera.Inverse().Multiply(&projection)
|
screenmat := camera.Inverse().Multiply(&projection)
|
||||||
screenmat = screenmat.Multiply(&viewport)
|
screenmat = screenmat.Multiply(&viewport)
|
||||||
|
|
||||||
@ -195,19 +172,15 @@ func main() {
|
|||||||
fb.Data[i].G = 0
|
fb.Data[i].G = 0
|
||||||
fb.Data[i].B = 0
|
fb.Data[i].B = 0
|
||||||
}
|
}
|
||||||
//rl.ImageDrawRectangle(fb.Image, 0, 0, Width, Height, rl.Black)
|
|
||||||
//rl.ImageClearBackground(fb.Image, rl.Black)
|
|
||||||
|
|
||||||
var sc [3]hrend.Vertex
|
var sc [3]hrend.Vertex
|
||||||
rb.ResetZBuffer()
|
rb.ResetZBuffer()
|
||||||
for _, f := range o.Faces {
|
for _, f := range o.Faces {
|
||||||
// Precompute perspective for vertices to save time. Notice Z
|
// Precompute perspective for vertices to save time. Notice Z
|
||||||
// is not considered: is this orthographic projection? Yeah probably...
|
// is not considered: is this orthographic projection? Yeah probably...
|
||||||
//var fpt [3]hrend.Vec3f
|
|
||||||
for i := range 3 { // Triangles, bro
|
for i := range 3 { // Triangles, bro
|
||||||
sc[i] = f[i]
|
sc[i] = f[i]
|
||||||
sc[i].Pos = screenmat.MultiplyPoint3(f[i].Pos)
|
sc[i].Pos = screenmat.MultiplyPoint3(f[i].Pos)
|
||||||
//fpt[i] = worldToCamera.MultiplyPoint3(f[i].Pos)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
l1 := f[2].Pos.Sub(&f[0].Pos)
|
l1 := f[2].Pos.Sub(&f[0].Pos)
|
||||||
@ -217,7 +190,6 @@ func main() {
|
|||||||
if intensity < 0 {
|
if intensity < 0 {
|
||||||
intensity = 0
|
intensity = 0
|
||||||
}
|
}
|
||||||
//intensity := float32(1.0)
|
|
||||||
hrend.TriangleTextured(&rb, texture, intensity, sc[0], sc[1], sc[2])
|
hrend.TriangleTextured(&rb, texture, intensity, sc[0], sc[1], sc[2])
|
||||||
//hrend.TriangleFlat(&rb, hrend.Col2Uint(byte(255*intensity), byte(255*intensity), byte(255*intensity)), sc[0].Pos, sc[1].Pos, sc[2].Pos)
|
//hrend.TriangleFlat(&rb, hrend.Col2Uint(byte(255*intensity), byte(255*intensity), byte(255*intensity)), sc[0].Pos, sc[1].Pos, sc[2].Pos)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user