Created
October 14, 2009 19:02
-
-
Save abuiles/210319 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed case class Sphere (center:Vector3d , radius: Double) extends Geometry | |
{ | |
def intersect (r:Ray, h:Hit, range:Range,material:Color3f): Option [(Hit,Range)]= | |
{ | |
var v = new Vector3d ( r.origin.x - center.x , r.origin.y - center.y,r.origin.z - center.z); | |
var discriminant = pow (v.dot (r.direction),2.0) - (pow (v.dot(v),2) - pow (radius,2)); | |
if (discriminant >= 0 ) | |
{ | |
//var t1 = -(v.dot(r.direction)) + sqrt (discriminant); | |
var t = -(v.dot(r.direction)) - sqrt (discriminat); | |
if (t >= range.minT && t < range.maxT ) | |
{ | |
var h = new Hit (t,material); | |
range.maxT = t; | |
return Some (h,range); | |
} | |
return None; | |
} | |
else | |
return None; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment