public override void Cast(Ray ray, CastResult cr) { double t = (D-Normal.X*ray.X0-Normal.Y*ray.Y0-Normal.Z*ray.Z0)/(Normal.X*ray.DX+Normal.Y*ray.DY+Normal.Z*ray.DZ); if(t > 0.0d) { cr.Copy(t, Normal, 0.0d, 0.0d); } else { cr.SetNull(); } }
public override void Cast(Ray ray, CastResult cr) { double x0 = ray.X0-Center.X; double y0 = ray.Y0-Center.Y; double z0 = ray.Z0-Center.Z; double dx = ray.DX; double dy = ray.DY; double dz = ray.DZ; double b_2 = dx*x0+dy*y0+dz*z0; double c = x0*x0+y0*y0+z0*z0-Radius*Radius; double D_4 = b_2*b_2-c; D_4 = Math.Sqrt(D_4); double t = Maths.MinGeqZero(-D_4-b_2, D_4-b_2); double normx = Rinv*(x0+t*dx); double normy = Rinv*(y0+t*dy); double normz = Rinv*(z0+t*dz); double phi = Math.Atan2(normx, -normz); double tu = 0.5d*phi/Math.PI+0.5d; double tv = 0.5d-Math.Asin(normy)/Math.PI; cr.Copy(t, normx, normy, normz, tu, tv, 0.0d, new Point3(-normz, normy, normx), new Point3(-normy, normx, normz)); }
public override void Cast (Ray ray, CastResult cr) { double j = ray.X0-p0.X; double k = ray.Y0-p0.Y; double l = ray.Z0-p0.Z; double dx01 = p1.X-p0.X; double dy01 = p1.Y-p0.Y; double dz01 = p1.Z-p0.Z; double dx02 = p2.X-p0.X; double dy02 = p2.Y-p0.Y; double dz02 = p2.Z-p0.Z; double M = 1.0d/(dx01*(ray.DY*dz02-dy02*ray.DZ)+dx02*(dy01*ray.DZ-ray.DY*dz01)+ray.DX*(dy02*dz01-dy01*dz02)); double beta = (dx02*(ray.DZ*k-ray.DY*l)+ray.DX*(dy02*l-dz02*k)+(ray.DY*dz02-dy02*ray.DZ)*j)*M; double gamma = -(dx01*(ray.DZ*k-ray.DY*l)+ray.DX*(dy01*l-dz01*k)+(ray.DY*dz01-dy01*ray.DZ)*j)*M; double t = -(dx01*(dz02*k-dy02*l)+dx02*(dy01*l-dz01*k)+(dy02*dz01-dy01*dz02)*j)*M; double alpha = 1.0d-beta-gamma; cr.Copy(t, alpha*n0.X+beta*n1.X+gamma*n2.X, alpha*n0.Y+beta*n1.Y+gamma*n2.Y, alpha*n0.Z+beta*n1.Z+gamma*n2.Z, alpha*t0.X+beta*t1.X+gamma*t2.X, alpha*t0.Y+beta*t1.Y+gamma*t2.Y, alpha*t0.Z+beta*t1.Z+gamma*t2.Z, this.bumpx, this.bumpy); cr.NormalizeNormal(); }
public void Copy(CastResult cr) { this.T = cr.T; this.Normal.SetValues(cr.Normal); this.TU.SetValues(cr.TU); }
public void ADSAtAndBump(CastResult cr, Point3 raydir, out Color ambient, out Color diffuse, out Color specular, out Color reflectance, out Color refraction) { Point3 tu = cr.TU; this.Bump(tu, cr.Normal, cr.BumpX, cr.BumpY); double cos = -Point3.CosAngleNorm(raydir, cr.Normal); ambient = this.Ambient; diffuse = this.Diffuse; specular = this.Specular; Color tex = this.Texture(tu); ambient *= tex; diffuse *= tex; specular *= tex; double fres = this.ReflectanceGetter(cos); double ta = Math.Max(0.0d, this.ReflectanceThreshold*fres-this.Transparent); reflectance = Color.FromFrac(ta); tex = this.Reflection(tu); specular *= tex; reflectance *= tex; refraction = Color.FromFrac(this.Transparent); }
public abstract void Cast(Ray ray, CastResult cr);