Using OCaml to visualize Radiohead's HoC music video (part 3)
*Update 10/2009:* The project is currently hosted at GitHub.
*Update 01/2009:* Created a new hoc3.zip 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 main.ml 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.
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:
classparticle_model:object(* starting frame *)valmutablestart_frame:VertexType.depth_vertexlist(* ending frame *)valmutablelast_frame:VertexType.depth_vertexlist(* currently loaded frame *)valmutableloaded_frame:VertexType.depth_vertexlist(* if setted to true, it will load a new frame for each step of the animation *)valmutablerefresh_frames:bool(* same as the camera_model -check that post *)valmutabletime:floatvalmutabletotal_frames:floatvalmutabletransition:Transition.trans*Transition.ease(* extend start_frame or last_frame in order to have same number of points *)methodbalance:unit(* equivalent to the camera methods *)methodstep:unitmethoddraw:float->unit(* set the type of the animation you want to perform *)methodset_animation:float->bool*bool*(ParticleTrans.transformation*float*(Transition.trans*Transition.ease))->unitend
Particle animations have a special type, that ressembles the camera model transition type.
This type is defined as follows:
The float value is the total number of frames the animation will use.
The (trans \* ease) value allows you to customize different type of transitions, from Linear, None to Quad, EaseInOut. More information about this is in the camera_model post.
ParticleTrans.transformation is a function that applies a transformation to a frame. You can define custom functions in that module and then apply them to the visualization.
I only defined a couple of functions, but you can define any other animation you like. You just have to define a function that receives a frame as input and returns a frame as output.
The interface for ParticleTrans is:
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 main.ml file and looks like this:
lettimeline=object(self)valmutableframe=0.valcamera_timeline=[(* operations defined in the camera model post *)]valparticle_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))))]methodget_frame=framemethodtick=frame<-frame+.1.;self#update_camera;self#update_animationmethodupdate_camera=tryletcamera_anim=List.assocframecamera_timelineincam#set_animationscamera_anim;with|Not_found->()methodupdate_animation=tryletanim=List.assocframeparticle_timelineinpart#set_animationframeanim;with|Not_found->()end
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: