ln
ln copied to clipboard
Orthographic Errors
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.
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()
}
Obviously this is a hacky fix, but hope it helps.
Thanks for the fix, really appreciate it!
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
?
Exactly.