
type state = (env, stack, code)

type base_value = 
  | Int
  | Real
  | String
  | Bool
type value = 
  | BaseValue of base_value
  | Closure of closure
  | Array of array
  | Point
  | Object
  | Light

type closure = env * code
type array   = value list

type env = (string * value) list
type stack = value list
type code = list tokengroup

DONE

transit: state -> state

  | (t, alpha, BaseValue i:: c) -> (t, i::alpha, c)

  | (t, v::alpha, Binder x:: c) -> ((x,v)::t, alpha, c)
  | (t, alpha, x::c) -> (t, t x::alpha, c)

  | (t, alpha, {c'}::c) -> (t, (c'::t)::alpha, c)
  | (t, (t',c')::alpha, apply::c) ->
      let (t'', beta, []) = transit_etoile (t', alpha, c') in
      (t, beta, c)

  | 
....


eval: code * value list -> (value list) = fun (c, vs)
 let (t, newvs, []) = transit_etoile ([], vs, c) in
 newvs

(* no recursion, but func can pass their name as argument to do it *)
(* pad: kind of forth, reverse ops syntax (rpl) 
   => apply/0 and binder/1 => not apply x::c but only apply::c
   the notation { } = function and (t',c') = in fact a closure
   /x must just mean assign to x the value in the stack (which can be closure)

  pad: from here, we just program a kind of forth, no notion of ray tracing
*)

(*
ray tracer:  

world view |/_ 0 is at the right down nead us ("left handed")

object = (surface  object obj  in the GML syntax (forth again), surface = function
sphere
cube 
cylinder

then
code
plane

transfo = 
translate
scale
uscale
rotatex
rotatey
rotatez

 TODO can do this as in SOE, lazy calculus of pixel in it

all are affine transfo, just need a matrix , A * OpMatrix -> B
(TODO need 4*4 matrix why not 3*3 ?? dont remember)


illumination model, Wow equation
introduce light object =
light
pointlight
spotlight

GML use procedural texturing ??
 surface fonction : object face = int -> texture coordinate 1 -> texture coordinate 2

constructive solid geometry
 union
 then intersect and difference (tier 3)

render : amb -> lights -> obj -> depth -> fov -> wid -> ht -> file
eye view is fixed !! at 0,0,-1




format
 join  (map (^ " ") ["P6",(string_of_int width),(string_of_int height),"255"]))
 (red,green,blue) in row order
 comment #
 
spec:
 prog take stdin -> status (but generate files)
 if error, status must be > 0, if cool then 0

 must catch  bad format in input error, run-time type erros,
  must check bound access
 can handle too /0 and overflow of integer

README (brief descr, pl, number of tiers done, misc)
tier1 = evaluator/parserlexer/generation for planes/sphere dirctional light
 all GML operators exepct cone, cube, cylinder, difference, intersect, pointlight, spotlight
tier2 = + cone/cube/cylinder pointlight (more primitive solid and additional lighting)
tier3 = + difference/intersect spotlight (add constructive solid geomertr and additionnal lightings)

*)




------------------------------------------------
try interpretor simple:
pad: there is one thing, the program (the input)
 and the execution of this (the code, which have notion of closure, ...)
type code != type value !!


in value we have object point (create by special function point)
 light (create by special function pointlight/.... ...)


we are sure that sin cant be redefined cos it is in lexer
 and sin will not be an identifier but an operator 


--
we have object and a surface fonction
 object define some points
 object can be translated/rotated/.. => when calculate a point
  we will apply first the transfo !!

C kd ks n are surface property 

depth

surface fonction: face -> coord1 -> coord2 -> (surface color = C (3 float),
 float1 = kd, float2 = ks, float3 = n


------------
ray tracing:
 launch x ray from eye viewpoint (x is determined by width*height of screen
   a ray per pixel) the distance of screen from the viewpoint determine the angle
   that the ray take (if focal is far, then low angle)
 then calcul the first solid that intersect with this ray 
  (=> must parcourir tous les objets de la scene pour voir si obj intersect with the vector
    intersection calculus !! and take the nearest object
   (can do optimisation by making hierarchie of object (TOapprofondir)
 calcul the color of this point 
  color is function of
   texture of the solid at this point
   contribution of the different light from the scene by launching a ray
     from the intersection point toward the light, if object between, then no contribution
     for this light (=> again intersection calculus)
     shadow ray (shadow = ombre cos another object can hide a light)
   launch a ray in a direction orthogonal au vecteur incident sur la surface and
   calculate the color/illumination of the solid that intersect this ray
   (here is the recursive process !!)

as the process is recursive, we limit the depth (depth = number of ray cast
  per pixel, doom = kind of ray tracing of depth 1 (we dont calculate
  contribution of light of the other solid on this solid)


for our pb we have a fix eye view point(0,0,-1), and fix direction (XY plane)
we have width*height pixel  over a wid*hei plane in world space !!
 that is we must round (car on peut vouloir petite ou grande focale)
 hei is ratio in function of width*height


rappel:
-----------------
tan = sin/cos sin=opp/hyp cos=adj/hyp

then with fov, \/   then 1/2 fov = |/
 width = 2 * opp, tan 1/2 fov = opp/hyp = opp/1 (1 cos we are at a distance of 1 from xy plane)
 => width = 2 * opp = 2 tan 1/2 fov

delta = width of a pixel = width/number of pixel = tan 1/2 fov / number_of_pixel_width
if upper left corner = (x,y,0) (x = - 1/2 width, y = 1/2 height)
then direction if jts pixel in ith row =
(x+(j+0.5)*delta, y-(i+0.5)*delta,1) we have 0.5 cos we consider
 the center of the pixel

ex:
 fov = 90, screen = 100*100 pixel => 
 width = 2 tan 45 = 2
 delta = 2/100 = 1/50
 upper left = (-1,1,0)
 first pixel j=0,i=0   = (-1 + (0.5)*1/50, 1 - (0.5)*1/50, 1)


geometry
--------------
from task.ps

plane: normal and distance suffit
ray = R0 + Rd (point and direction)
 and R(t) = R0 + tRd  t mean the distance from R0 
 if found tinteresection, then the point is tar R0+ tRd
sphere = center * radius

what are those unit vector ??










-------------------------
pb scale/...
-----------------
to calcul intersection, dont 
 transforme obj by transfo, transfo the ray by
  the transfo of an obj (careful must normalise each time the transfo 
  cos matrix * dont preserve length) 