' '
def material(color)
{
  Materials.uniform( [ "ambient": color * 0.1,
                       "diffuse": color * 0.8,
                       "specular": Colors.white(),
                       "specular_exponent": 100,
                       "reflectivity": 0.5 ] )
}

def scene_at(now)
{
  var camera = Cameras.perspective( [ "eye": pos(0,0,10),
                                      "look_at": pos(0,0,0) ] )

  var x_anim = Animations.animate(-3, 3, seconds(5))
  var quad_in = Animations.ease(x_anim, Easing.cubic_in());
  var quad_out = Animations.ease(x_anim, Easing.cubic_out());
  var quad_inout = Animations.ease(x_anim, Easing.cubic_inout());

  var root = union( [ translate(vec(quad_in[now], 3, 0), decorate( material(Colors.red()), sphere())),
                      translate(vec(quad_out[now], 0, 0), decorate( material(Colors.green()), sphere())),
                      translate(vec(quad_inout[now], -3, 0), decorate( material(Colors.blue()), sphere())) ] )

  var lights = [ Lights.omnidirectional( pos(0,5,5), Colors.white() ) ]


  create_scene(camera, root, lights)
}


var raytracer   = Raytracers.v6()
var renderer    = Renderers.standard( [ "width": 500,
                                        "height": 500,
                                        "sampler": Samplers.multijittered(2),
                                        "ray_tracer": raytracer ] )

pipeline( scene_animation(scene_at, seconds(5)),
          [ Pipeline.animation(30),
            Pipeline.renderer(renderer),
            Pipeline.studio() ] )

1. Implementation

Create files math/functions/easing/quadratic-function.cpp/.h and implement quadratic_in, quadratic_out and quadratic_inout as described in here. Use linear-easing-function.h/.cpp as a guide.

Don’t forget to add a binding for the scripting language. In scripting/math-module, update the EasingLibrary structure and add an extra BIND to add_easing.

Do the same for the cubic easing function. Put the implementation in separate files math/functions/easing/cubic-function.cpp/.h.

Do the same for the quintic easing function. Put the implementation in separate files math/functions/easing/quintic-function.cpp/.h.

2. Evaluation

Render the scene below:

def scene_at(now)
{
  var camera = Cameras.perspective( [ "eye": pos(0,0,20),
                                      "look_at": pos(0,0,0) ] )

  var primitives = []

  {
    var x_anim = Animations.animate(-5, 0, seconds(5))
    var x1 = Animations.ease(x_anim, Easing.quadratic_in())[now];
    var x2 = Animations.ease(x_anim, Easing.cubic_in())[now];
    var x3 = Animations.ease(x_anim, Easing.quintic_in())[now];

    primitives.push_back(translate(vec(x1, 3, 0), sphere()))
    primitives.push_back(translate(vec(x2, 0, 0), sphere()))
    primitives.push_back(translate(vec(x3, -3, 0), sphere()))
  }

  {
    var x_anim = Animations.animate(-2.5, 2.5, seconds(5))
    var x1 = Animations.ease(x_anim, Easing.quadratic_inout())[now];
    var x2 = Animations.ease(x_anim, Easing.cubic_inout())[now];
    var x3 = Animations.ease(x_anim, Easing.quintic_inout())[now];

    primitives.push_back(translate(vec(x1, 3, 0), sphere()))
    primitives.push_back(translate(vec(x2, 0, 0), sphere()))
    primitives.push_back(translate(vec(x3, -3, 0), sphere()))
  }

  {
    var x_anim = Animations.animate(0, 5, seconds(5))
    var x1 = Animations.ease(x_anim, Easing.quadratic_out())[now];
    var x2 = Animations.ease(x_anim, Easing.cubic_out())[now];
    var x3 = Animations.ease(x_anim, Easing.quintic_out())[now];

    primitives.push_back(translate(vec(x1, 3, 0), sphere()))
    primitives.push_back(translate(vec(x2, 0, 0), sphere()))
    primitives.push_back(translate(vec(x3, -3, 0), sphere()))
  }

  var root = union( primitives )

  var lights = [ ]

  create_scene(camera, root, lights)
}

var raytracer   = Raytracers.v0()
var renderer    = Renderers.standard( [ "width": 500,
                                        "height": 500,
                                        "sampler": Samplers.single(),
                                        "ray_tracer": raytracer ] )

pipeline( scene_animation(scene_at, seconds(5)),
          [ Pipeline.animation(30),
            Pipeline.renderer(renderer),
            Pipeline.studio() ] )