(*
  Copyright (C) 2010 Florent Monnier

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation the
  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  sell copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  The Software is provided "as is", without warranty of any kind, express or
  implied, including but not limited to the warranties of merchantability,
  fitness for a particular purpose and noninfringement. In no event shall
  the authors or copyright holders be liable for any claim, damages or other
  liability, whether in an action of contract, tort or otherwise, arising
  from, out of or in connection with the software or the use or other dealings
  in the Software.
*)
(** A module to manage OpenGL matrices. *)

(** matrices handling by opengl is now deprecated,
    programmers are now supposed to handle matrices themselves,
    so here is a module to do so *)

type t = float array

val get_identity: unit -> t

val pi: float
val deg_to_rad: float
val rad_to_deg: float

val copy: t -> t

(** {3 projection matrices} *)

val perspective_projection:
  fov:float -> ratio:float -> near:float -> far:float -> t
(** replaces [gluPerspective] *)

val ortho_projection: left:float -> right:float ->
  bottom:float -> top:float -> near:float -> far:float -> t
(** replaces [glOrtho] *)

val frustum:
  left:float -> right:float ->
  bottom:float -> top:float ->
  near:float -> far:float -> t
(** replaces [glFrustum] *)


(** {3 transformation matrices} *)

val translation_matrix: float * float * float -> t
val scale_matrix: float * float * float -> t

val x_rotation_matrix: angle:float -> t
val y_rotation_matrix: angle:float -> t
val z_rotation_matrix: angle:float -> t

(** the following:
{[
  let scale = Ogl_matrix.scale_matrix (0.1, 0.1, 0.1)
  and rot   = Ogl_matrix.x_rotation_matrix 20.0
  and trans = Ogl_matrix.translation_matrix (3.0, 4.0, 5.0)
  in
  let m = Ogl_matrix.get_identity() in
  let m = Ogl_matrix.mult_matrix m scale in
  let m = Ogl_matrix.mult_matrix m rot in
  let m = Ogl_matrix.mult_matrix m trans in
  (m)
]}
  is equivalent to:
{[
  glScale 0.1 0.1 0.1;
  glRotate (20.0) 1.0 0.0 0.0;
  glTranslate 3.0 4.0 5.0;
]}
*)

val rotation_matrix_of_axis :
  axis:float * float * float -> angle:float -> t

val mult_matrix: m1:t -> m2:t -> t

val matrix_translate: matrix:t -> float * float * float -> unit
(** imperative, modifies the matrix parameter *)


val look_at:
  eye:float * float * float ->
  center:float * float * float ->
  up_vector:float * float * float -> t
(** replaces [gluLookAt] *)

val unproject: win_x:float -> win_y:float -> win_z:float ->
  model:float array -> proj:float array -> viewport:int array ->
  float * float * float
(** replaces [gluUnProject] *)


(** {3 Low Functional Transformations} *)

(** functional, returns a matrix from the input matrix with the transformation *)

val translate_mat: m:t -> float * float * float -> t
val scale_mat: m:t -> float * float * float -> t

val x_rotate_mat: m:t -> float -> t
val y_rotate_mat: m:t -> float -> t
val z_rotate_mat: m:t -> float -> t

val rotate_mat: m:t -> float -> float * float * float -> t

(** {3 High Functional Transformations} *)

val translate: t -> float * float * float -> (t -> 'a) -> 'a
val scale: t -> float * float * float -> (t -> 'a) -> 'a
val rotate_x: t -> float -> (t -> 'a) -> 'a
val rotate_y: t -> float -> (t -> 'a) -> 'a
val rotate_z: t -> float -> (t -> 'a) -> 'a
val rotate: t -> float -> float * float * float -> (t -> 'a) -> 'a

(** {3 Vectors} *)

val normalise_vector: float * float * float -> float * float * float

(**/**)
val print_mat: t -> unit (* XXX DEBUG *)