Using OCaml to visualize Radiohead's HoC music video (part 3)

Posted in: ocaml , visualization , opengl
*Update 10/2009:* The project is currently hosted at GitHub. *Update 01/2009:* Created a new file and some documentation. A while ago Radiohead published their House of Cards video data in form of CSV files. Each CSV file contains information about the 3D position of the points for each frame. I wrote a couple of previous posts that covered how to render and save that data with OpenGL and OCaml and also how to customize camera movement in OpenGL. This post shows how to customize particle animations for Radiohead's House of Cards video. A proof of concept for camera movement + particle animation is shown in this youtube video: If you want to generate the video, you have to download Radiohead's HoC music video data here. Also, you can download the source code for this project here. This small project is organized in a way that is easy to add new features, camera animations and particle transformations in order to easily code new videos with different effects using the HoC data. Radiohead's HoC data is a set of CSV files. Those files are rendered in OpenGL with OCaml and then saved in bmp or jpeg files to be merged into a video using ffmpeg. If you want to know more about this you should probably read part 1 of this "trilogy". The Camera Model class allows you to make custom camera movements that can be handled and defined in a Timeline object in the file. If you like to know more about this, you can read part 2 of this "trilogy". This last post shows how to customize particle interpolation and movement by using the Particle Model class, the ParticleTrans module and the Timeline object.

Particle Model

The particle_model class handles particle animations. Somewhat like the camera class, particle_model stores the initial frame and the last frame along with some extra information about the timing of the animation. The particle_model then performs an interpolation from the initial_frame to the last_frame, rendering the state of the transformation in the draw function. A possible interface for the particle model could be something like this:
class particle_model :
    (* starting frame *)
    val mutable start_frame : VertexType.depth_vertex list
    (* ending frame *)
    val mutable last_frame : VertexType.depth_vertex list
    (* currently loaded frame *)
    val mutable loaded_frame : VertexType.depth_vertex list
    (* if setted to true, it will load a new frame for each
    step of the animation *)
    val mutable refresh_frames : bool
    (* same as the camera_model -check that post *)
    val mutable time : float
    val mutable total_frames : float
    val mutable transition : Transition.trans * Transition.ease
    (* extend start_frame or last_frame in order to
    have same number of points *)
    method balance : unit
    (* equivalent to the camera methods *)
    method step : unit
    method draw : float -> unit
    (* set the type of the animation you want
    to perform *)
    method set_animation :
      float ->
      bool * bool *
      (ParticleTrans.transformation * float *
       (Transition.trans * Transition.ease)) ->
Particle animations have a special type, that ressembles the camera model transition type. This type is defined as follows:
type animation_op =
    ParticleTrans.transformation * float *
    (Transition.trans * Transition.ease)
Just to make a comparison, the camera model transition type is:
type camera_op_list = (camera_op list) * float * (trans * ease)
This type can be divided into three main parts:

Putting it all together

The timeline object (described in the previous post) holds information about the camera and particle transformations beeing applied at each stage of the animation. This class-less object is defined in the file and looks like this:
let timeline =
  object (self)
    val mutable frame = 0.
    val camera_timeline = [
    (* operations defined in the
    camera model post *)

    val particle_timeline = [
      (* frame number,  (invert, refresh frames, instruction) *)
      (1., (true, true, (Random, 120., (Elastic, EaseOut))));
      (420., (false, false, (Random, 50., (Quad, EaseOut))));
      (471., (false, true, (Idle, 80., (Quad, EaseIn))))

    method get_frame = frame

    method tick =
      frame <- frame +. 1.;

    method update_camera =
        let camera_anim = List.assoc frame camera_timeline in
          cam#set_animations camera_anim;
          | Not_found -> ()

    method update_animation =
        let anim = List.assoc frame particle_timeline in
          part#set_animation frame anim;
          | Not_found -> ()
The particle_timeline and camera_timeline variables hold the transformations to be performed at different stages of the animation.

Download and Use

You can download the project here. You can compile the project by typing:
ocamlc -g str.cma -I +camlimages ci_core.cma ci_jpeg.cma ci_bmp.cma
-I +lablGL lablglut.cma lablgl.cma -o main
Any comment about the Video or the OpenGL/OCaml implementation is very welcome!
blog comments powered by Disqus