Remove screen matrix transform, use normal math
This commit is contained in:
parent
4474f3e1bc
commit
45d931c89e
@ -149,6 +149,13 @@ func (m *Mat44f) SetViewport(tl Vec3f, br Vec3f) { //width, height, depth int) {
|
|||||||
//m.Set(2, 3, (br.Z+tl.Z)/2)
|
//m.Set(2, 3, (br.Z+tl.Z)/2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert the point to a viewport point
|
||||||
|
func (v *Vec3f) ViewportSelf(width, height int) {
|
||||||
|
v.X = (v.X + 1) / 2 * float32(width)
|
||||||
|
v.Y = (1 - (v.Y+1)/2) * float32(height)
|
||||||
|
// Don't touch Z
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Mat44f) SetViewportSimple(width, height, depth int) {
|
func (m *Mat44f) SetViewportSimple(width, height, depth int) {
|
||||||
var tl Vec3f // All zero
|
var tl Vec3f // All zero
|
||||||
br := Vec3f{
|
br := Vec3f{
|
||||||
|
@ -210,9 +210,9 @@ func main() {
|
|||||||
objects[len(objects)-1].Pos.Z -= 2
|
objects[len(objects)-1].Pos.Z -= 2
|
||||||
|
|
||||||
// These don't really change
|
// These don't really change
|
||||||
var projection, viewport hrend.Mat44f
|
var projection hrend.Mat44f //, viewport hrend.Mat44f
|
||||||
projection.SetProjection(float32(*fov), float32(Width)/float32(Height), NearClip, FarClip)
|
projection.SetProjection(float32(*fov), float32(Width)/float32(Height), NearClip, FarClip)
|
||||||
viewport.SetViewportSimple(int(Width), int(Height), 1) //65535)
|
//viewport.SetViewportSimple(int(Width), int(Height), 1) //65535)
|
||||||
|
|
||||||
var camera hrend.Mat44f
|
var camera hrend.Mat44f
|
||||||
var newcamtrans hrend.Vec3f
|
var newcamtrans hrend.Vec3f
|
||||||
@ -234,7 +234,7 @@ func main() {
|
|||||||
camtrans = *camtrans.Add(&newcamtrans)
|
camtrans = *camtrans.Add(&newcamtrans)
|
||||||
_ = camera.SetCamera(&camtrans, yaw, pitch, &camup)
|
_ = camera.SetCamera(&camtrans, yaw, pitch, &camup)
|
||||||
screenmat := camera.Inverse().Multiply(&projection)
|
screenmat := camera.Inverse().Multiply(&projection)
|
||||||
screenmat = screenmat.Multiply(&viewport)
|
//screenmat = screenmat.Multiply(&viewport)
|
||||||
|
|
||||||
rb.ResetZBuffer()
|
rb.ResetZBuffer()
|
||||||
for y := range Height {
|
for y := range Height {
|
||||||
@ -253,7 +253,6 @@ func main() {
|
|||||||
modelmat.SetLookAt(&o.Pos, o.Pos.Add(&o.LookVec), &camup)
|
modelmat.SetLookAt(&o.Pos, o.Pos.Add(&o.LookVec), &camup)
|
||||||
modelmat.ScaleSelf(o.Scale)
|
modelmat.ScaleSelf(o.Scale)
|
||||||
matrix3d := modelmat.Multiply(screenmat)
|
matrix3d := modelmat.Multiply(screenmat)
|
||||||
//matrix3d.ScaleSelf(o.Scale)
|
|
||||||
for _, f := range o.Model.Faces {
|
for _, f := range o.Model.Faces {
|
||||||
for i := range 3 {
|
for i := range 3 {
|
||||||
sc[i] = f[i]
|
sc[i] = f[i]
|
||||||
@ -264,6 +263,10 @@ func main() {
|
|||||||
log.Print(o.Model.Faces[0][0].Pos, o.Model.Faces[0][1].Pos, o.Model.Faces[0][2].Pos)
|
log.Print(o.Model.Faces[0][0].Pos, o.Model.Faces[0][1].Pos, o.Model.Faces[0][2].Pos)
|
||||||
log.Print(sc[0].Pos, sc[1].Pos, sc[2].Pos)
|
log.Print(sc[0].Pos, sc[1].Pos, sc[2].Pos)
|
||||||
log.Print(matrix3d)
|
log.Print(matrix3d)
|
||||||
|
for i := range 3 {
|
||||||
|
// Perspective divide (?) and screen coord
|
||||||
|
sc[i].Pos.ViewportSelf(*width, *height)
|
||||||
|
}
|
||||||
//log.Print(sc[0].Pos, sc[1].Pos, sc[2].Pos, matrix3d)
|
//log.Print(sc[0].Pos, sc[1].Pos, sc[2].Pos, matrix3d)
|
||||||
if o.Lighting {
|
if o.Lighting {
|
||||||
l1 := f[2].Pos.Sub(&f[0].Pos)
|
l1 := f[2].Pos.Sub(&f[0].Pos)
|
||||||
|
Loading…
Reference in New Issue
Block a user