ln icon indicating copy to clipboard operation
ln copied to clipboard

Orthographic Errors

Open scisci opened this issue 7 years ago • 5 comments

Hi, I'm trying to do some tests using an orthographic matrix, but I seem to be getting some errors in the ray intersection. I don't know if I've set something up wrong.

eye := ln.Vector{-3, 4, 3}   // camera position
center := ln.Vector{0, 0, 0} // camera looks at
up := ln.Vector{0, 1, 0}     // up direction
znear := 0.1 // near z plane
zfar := 10.0 // far z plane
step := 0.01 // how finely to chop the paths for visibility testing
matrix := ln.LookAt(eye, center, up).Orthographic(-1, 1, -1, 1, znear, zfar)
paths := scene.RenderWithMatrix(matrix, eye, width, height, step)

As you can see, edges are clipped before they go behind objects.

screen shot 2018-01-07 at 4 32 53 am

scisci avatar Jan 07 '18 09:01 scisci

Ah, it looks like my code assumes a perspective projection!

If you change Scene.Visible to this, it works. This code assumes that the eye is looking at the origin though. (center := ln.Vector{0,0,0})

func (s *Scene) Visible(eye, point Vector) bool {
	v := eye
	r := Ray{point, v.Normalize()}
	hit := s.Intersect(r)
	return !hit.Ok()
}

fogleman avatar Jan 07 '18 22:01 fogleman

Obviously this is a hacky fix, but hope it helps.

fogleman avatar Jan 07 '18 22:01 fogleman

Thanks for the fix, really appreciate it!

scisci avatar Jan 07 '18 22:01 scisci

Just so I understand, is this how this works?

  • Shoot a ray from the point we are testing towards the camera
  • If it hits anything between the point and camera, then its hidden

In the Orthographic case, the camera is more like a plane that is infinitely far away

?

scisci avatar Jan 07 '18 22:01 scisci

Exactly.

fogleman avatar Jan 07 '18 22:01 fogleman