text
stringlengths 0
15.7k
| source
stringlengths 6
112
|
---|---|
on v3length(self)
|
raytracer.applescript
|
v3lengthSq(self) ^ 0.5 -- x ^ 0.5 calculates sqrt(x)
|
raytracer.applescript
|
on v3unit(v)
|
raytracer.applescript
|
v3divScalar(v, v3length(v))
|
raytracer.applescript
|
on v3dot(u, v)
|
raytracer.applescript
|
(x of u) * (x of v) + (y of u) * (y of v) + (z of u) * (z of v)
|
raytracer.applescript
|
on v3cross(self, other)
|
raytracer.applescript
|
set res to v3(0,0,0)
|
raytracer.applescript
|
set x of res to y of self * z of other - z of self * y of other
|
raytracer.applescript
|
set y of res to z of self * x of other - x of self * z of other
|
raytracer.applescript
|
set z of res to x of self * y of other - y of self * x of other
|
raytracer.applescript
|
res
|
raytracer.applescript
|
on v3origin()
|
raytracer.applescript
|
v3(0,0,0)
|
raytracer.applescript
|
on v3clone(other)
|
raytracer.applescript
|
v3(x of other, y of other, z of other)
|
raytracer.applescript
|
on v3isEmpty(self)
|
raytracer.applescript
|
x of self = 0 and y of self = 0 and z of self = 0
|
raytracer.applescript
|
on v3print(self)
|
raytracer.applescript
|
log ("" & x in self & " " & y in self & " " & z in self)
|
raytracer.applescript
|
on v3copyFrom(self, other)
|
raytracer.applescript
|
set x of self to x of other
|
raytracer.applescript
|
set y of self to y of other
|
raytracer.applescript
|
set z of self to z of other
|
raytracer.applescript
|
on v3randomInRange(min, max)
|
raytracer.applescript
|
set rng to max - min
|
raytracer.applescript
|
return v3(random number * rng + min, random number * rng + min, random number * rng + min)
|
raytracer.applescript
|
on randomInRange(min, max)
|
raytracer.applescript
|
return random number * rng + min
|
raytracer.applescript
|
on min(a, b)
|
raytracer.applescript
|
if a < b
|
raytracer.applescript
|
on max(a, b)
|
raytracer.applescript
|
if a > b
|
raytracer.applescript
|
on v3nearZero(self)
|
raytracer.applescript
|
set s to 1e-8
|
raytracer.applescript
|
return (abs(x of self) < s) or (abs(y of self) < s) or (abs(z of self) < s)
|
raytracer.applescript
|
on randomInUnitSphere()
|
raytracer.applescript
|
set p to v3randomInRange(-1,1)
|
raytracer.applescript
|
if v3lengthSq(p) < 1
|
raytracer.applescript
|
return p
|
raytracer.applescript
|
on randomUnitVector()
|
raytracer.applescript
|
v3unit(randomInUnitSphere())
|
raytracer.applescript
|
on randomInHemisphere(normal)
|
raytracer.applescript
|
set inUnitSphere to randomInUnitSphere()
|
raytracer.applescript
|
if (v3dot(inUnitSphere, normal) > 0.0) -- In the same hemisphere as the normal
|
raytracer.applescript
|
return inUnitSphere
|
raytracer.applescript
|
return v3mulScalar(inUnitSphere, -1.0)
|
raytracer.applescript
|
on clamp(x, min, max)
|
raytracer.applescript
|
if (x < min)
|
raytracer.applescript
|
return min
|
raytracer.applescript
|
if (x > max)
|
raytracer.applescript
|
return max
|
raytracer.applescript
|
on makeRay(origin, direction)
|
raytracer.applescript
|
{origin:origin, direction:direction}
|
raytracer.applescript
|
on rayAt(r, t)
|
raytracer.applescript
|
v3add((origin of r), v3mulScalar((direction of r), t))
|
raytracer.applescript
|
on v3ToColor(v)
|
raytracer.applescript
|
makeColor(x of v, y of v, z of v)
|
raytracer.applescript
|
on correctColor(c)
|
raytracer.applescript
|
set red of c to clamp(sqrt(red of c), 0.0, 0.999)
|
raytracer.applescript
|
set green of c to clamp(sqrt(green of c), 0.0, 0.999)
|
raytracer.applescript
|
set blue of c to clamp(sqrt(blue of c), 0.0, 0.999)
|
raytracer.applescript
|
c
|
raytracer.applescript
|
on makeHitRecord()
|
raytracer.applescript
|
{t: 0, p: v3origin(), normal: v3origin(), frontFace: true, material: null}
|
raytracer.applescript
|
on hitRecordCopyFrom(self, other)
|
raytracer.applescript
|
set t of self to t of other
|
raytracer.applescript
|
v3copyFrom(p of self, p of other)
|
raytracer.applescript
|
v3copyFrom(normal of self, normal of other)
|
raytracer.applescript
|
set frontFace of self to frontFace of other
|
raytracer.applescript
|
set material of self to material of other
|
raytracer.applescript
|
on hitRecordSetFaceNormal(self, r, outwardNormal)
|
raytracer.applescript
|
set frontFace of self to v3dot((direction of r), outwardNormal) < 0
|
raytracer.applescript
|
if frontFace of self
|
raytracer.applescript
|
set normal of self to outwardNormal
|
raytracer.applescript
|
set normal of self to -outwardNormal
|
raytracer.applescript
|
script spherePrototype
|
raytracer.applescript
|
on hit(r,tMin,tMax,rec)
|
raytracer.applescript
|
set oc to v3sub((origin of r), my sphereCenter)
|
raytracer.applescript
|
set a to v3lengthSq(direction of r)
|
raytracer.applescript
|
set halfB to v3dot(oc, (direction of r))
|
raytracer.applescript
|
set c to v3lengthSq(oc) - my sphereRadius*my sphereRadius
|
raytracer.applescript
|
set discriminant to halfB*halfB - a*c
|
raytracer.applescript
|
if (discriminant < 0)
|
raytracer.applescript
|
set sqrtd to sqrt(discriminant)
|
raytracer.applescript
|
set root to (-halfB - sqrtd) / a
|
raytracer.applescript
|
if (root < tMin or tMax < root)
|
raytracer.applescript
|
root = (-halfB + sqrtd) / a
|
raytracer.applescript
|
set t of rec to root
|
raytracer.applescript
|
set p of rec to rayAt(r, t of rec)
|
raytracer.applescript
|
set normal of rec to v3divScalar(v3sub(p of rec, my sphereCenter), my sphereRadius)
|
raytracer.applescript
|
set outwardNormal to v3divScalar(v3sub(p of rec, my sphereCenter), my sphereRadius)
|
raytracer.applescript
|
hitRecordSetFaceNormal(rec, r, outwardNormal)
|
raytracer.applescript
|
set material of rec to my material
|
raytracer.applescript
|
end hit
|
raytracer.applescript
|
on newSphere(_sphereCenter, _sphereRadius, _material)
|
raytracer.applescript
|
script sphere
|
raytracer.applescript
|
property parent: spherePrototype
|
raytracer.applescript
|
property sphereCenter: _sphereCenter
|
raytracer.applescript
|
property sphereRadius: _sphereRadius
|
raytracer.applescript
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.