Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Makes rectangle
- let mkRectangle tex bl tl br =
- let z = Point.getZ bl
- let width = Vector.magnitude (Point.distance bl br)
- let height = Vector.magnitude (Point.distance bl tl)
- let u = Point.direction bl br
- let v = Point.direction bl tl
- let w = Vector.normalise(Vector.crossProduct u v)
- let ux = Vector.getX u
- let uy = Vector.getY u
- let uz = Vector.getZ u
- let vx = Vector.getX v
- let vy = Vector.getY v
- let vz = Vector.getZ v
- let wx = Vector.getX w
- let wy = Vector.getY w
- let wz = Vector.getZ w
- let blx = Point.getX bl
- let bly = Point.getY bl
- let blz = Point.getZ bl
- let o = mkTransformation (Matrix.Matrix(array2D [|[|ux;vx;wx;0.0|];[|uy;vy;wy;0.0|];[|uz;vz;wz;0.0|];[|0.0;0.0;0.0;1.0|]|]))
- let inverseo = mkTransformation (Matrix.Matrix(array2D [|[|ux;uy;uz;0.0|];[|vx;vy;vz;0.0|];[|wx;wy;wz;0.0|];[|0.0;0.0;0.0;1.0|]|]))
- let translate = translate blx bly blz
- let rect = { new Shape
- with member this.Texture = tex
- member this.Inside = None
- member this.BoundingBox =
- let lp = bl
- let hp = mkPoint (Point.getX bl + width) (Point.getY bl + height) (Point.getZ bl)
- mkBoundingBox lp hp
- member this.TransformedBoundingBox = this.BoundingBox
- member this.Hit (ray:Ray) =
- let ox = Point.getX (Ray.getPoint ray)
- let oy = Point.getY (Ray.getPoint ray)
- let oz = Point.getZ (Ray.getPoint ray)
- let dx = Vector.getX (Ray.getVector ray)
- let dy = Vector.getY (Ray.getVector ray)
- let dz = Vector.getZ (Ray.getVector ray)
- if dz = 0.0 then
- None
- else
- let t = (0.0 - oz)/dz
- let px = ox + t * dx
- let py = oy + t * dy
- let normal = mkVector 0.0 0.0 1.0
- if (px >= 0.0 && px <= width) then
- if (py >= 0.0 && py <= height) then
- let u = px/width
- let v = py/height
- if u < 0.0 || u > 1.0 then printfn "%A" "u"
- printfn "%A" u
- if v < 0.0 || v > 1.0 then printfn "%A" "v"
- printfn "%A" v
- Some (mkHit t normal (Texture.getMaterial tex u v))
- else None
- else None
- }
- let ortho = mkTransformed rect (o,inverseo)
- mkTransformed ortho translate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement