












open Compatibility;;
open Types;;
open Default;;
open Constants;;
open Exceptions;;
open Basic_types;;
open Font;;
open Fonts;;
open Colors;;
open Vrml_objects_pre;;
open Calc_3D;;
open Vrml_objects_post;;
open Positionables;;
open Geometrics;;
open Geometric_properties;;
open Map;;
open Complex_geometrics;;
open Map_complex;;
open Lights;;
open Map_light;;
open Sound;;
open Frame_manipulations;;
open Specials;;
open World;;
open Translate;;
open Animations;;

(* initialize_object : animation -> animation = <fun> *)

let initialize_object animation =
let rec initialize movie animation =
match movie with 
  [] -> animation
| a::b -> initialize b (setf_animation_target animation
(match a with 
  Rotation (_,((x,y,z),a)::b) -> set_rotation animation.target x y z a
| Translation (_,(x,y,z)::b) -> set_position animation.target x y z
| _ -> animation.target)
)                    
in initialize animation.movie animation ;;

(* compute_trajectory : (float -> 'a) -> int -> float list * 'a list = <fun> *)
let compute_trajectory traject precision =
let rec compute actual =
let fraction = (float_of_int actual) /. (float_of_int precision) in
if actual = precision then ([1.0],[traject 1.0])
else match (compute (actual + 1)) with
     (key,key_value) -> (fraction::key,(traject fraction)::key_value)
in compute 0 ;;

(* circle_y : float -> float -> float * float * float = <fun> *)
let circle_y r fraction =
(r *. sin (fraction *. 2.0 *. pi), 0.0 , r *. cos (fraction *. 2.0 *. pi));;

(*  *)
let circle_z r fraction =
(r *. cos (fraction *. 2.0 *. pi), r *. sin (fraction *. 2.0 *. pi), 0.0);;

(*  ellipse : float -> float -> float -> float * float * float = <fun> *)
let ellipse r1 r2 fraction = 
(r1 *. sin (fraction *. 2.0 *. pi), 0.0 , r2 *. cos (fraction *. 2.0 *. pi));;


(* new_extrusion_bis : vect2D list -> vect3D list -> rotation -> 
   vrml_object = <fun> *)
let new_extrusion_bis cross_section spine orientation scale =
 let d = default_extrusion
   in
       new_complete_extrusion d.extrusion_begin_cap d.extrusion_ccw
                              d.extrusion_convex cross_section
                              d.extrusion_end_cap orientation
                              scale d.extrusion_solid spine
;;



(*  *)
let revolution_orientation n precision fraction =
if (fraction = 0.0 ) then ((0.,0.,1.),0.) else ((0.,0.,1.) , (float_of_int n) *. 2.0 *. pi /. (float_of_int precision )) ;;

(* compute_3DShape : (float -> 'a) -> int -> 'a list = <fun> *)
let compute_values precision traject =
match compute_trajectory traject precision with
 (key,key_list) -> key_list ;;

(* compute_2DShape_y : (float -> 'a * 'b * 'c) -> int -> 
   ('a * 'b) list = <fun  *)
let compute_2DShape_y precision traject =
let extract (x,y,z) = (x,z) in
map extract (compute_values precision traject);;

let identity fraction = (1.,1.,1.) ;;

(* compute_revolution_extrusion : vect2D list -> float -> int -> 
   vrml_object = <fun> *)
let compute_revolution_extrusion shape r precision =
let spine = compute_values precision (circle_z r) in
let scale = compute_2DShape_y precision identity
in let orientation = compute_values  precision (revolution_orientation 1 precision )
in new_extrusion_bis shape spine orientation scale;;



let couronne = compute_revolution_extrusion (compute_2DShape_y 10 (circle_y 0.5)) 4.0 20;;

let couronne = map_color (couronne) blue ;;

let mon_world =
    { info       = [] ;
      title      = "" ;
      tree       = couronne ;
      specials   = [] ;
      animations = []  }
;;









