Hey! I managed to find the info I needed! Here's my camera class (which also now includes ease-in/ease-out function too!):
Code:class CamObjTween {
Vec3D loc, cp1, cp2, offset;
CamObjTween(Vec3D _start, Vec3D _offset) {
loc = new Vec3D(_start);
offset = new Vec3D(_offset);
}
// Update location using bezier curves only
void Update(float _interpol, Vec3D[] _list) {
this.Update(_interpol, _list, 0, 0);
}
// Update location using bezier curves and easing
void Update(float _interpol, Vec3D[] _list, float easeIn, float easeOut) {
Vec3D l1 = _list[1].add(offset);
Vec3D l2 = _list[2].add(offset);
if (easeIn != 0 || easeOut != 0) _interpol = this.Ease(_interpol, easeIn, easeOut);
loc.x = bezierPoint(l1.x, cp1.x, cp2.x, l2.x, _interpol);
loc.y = bezierPoint(l1.y, cp1.y, cp2.y, l2.y, _interpol);
loc.z = bezierPoint(l1.z, cp1.z, cp2.z, l2.z, _interpol);
}
// Update location using easing only
void Update(float _interpol, Vec3D _target, float easeIn, float easeOut) {
_target.addSelf(offset);
loc = loc.interpolateTo(_target, this.Ease(_interpol, easeIn, easeOut));
}
// Set an offset (useful for camera eye)
void SetOffset(Vec3D _offset) {
offset = _offset;
}
// Function that sets the control points (use when new target added)
// Smoothing can be from 0.0 to 1.5, with 1.0 optimum
void SetCurve(Vec3D[] _list, float smoothing) {
cp1 = this.GetControlPoint(_list[0], _list[1], _list[2], smoothing);
cp2 = this.GetControlPoint(_list[3], _list[2], _list[1], smoothing);
}
// Function to find control points for bezier curves
// Thanks to efg's computer lab: http://www.efg2.com/Lab/Graphics/Jean-YvesQueinecBezierCurves.htm :
// "Geometrical control points construction" section
Vec3D GetControlPoint(Vec3D p1, Vec3D p2, Vec3D p3, float smoothing) {
Vec3D middle = p2.interpolateTo(p3, 0.5);
Vec3D p4 = p2.sub(p1).limit(middle.magnitude()).scale(smoothing).scale(0.5).add(p2);
Vec3D _cp = middle.interpolateTo(p4, 0.5);
return _cp;
}
// Easing function
// Thanks to "Computer animation: algorithms and techniques" by
// Rick Parent, p87-89 "Sinusodial Pieces for Acceleration and Deceleration"
float Ease(float t, float k1, float k2) {
float t1, t2;
float f, s;
f = k1*2/PI + k2 - k1 + (1.0-k2)*2/PI;
if (t < k1) {
s = k1*(2/PI)*(sin((t/k1)*PI/2-PI/2)+1);
} else if (t < k2) {
s = (2*k1/PI + t-k1);
} else {
s = 2*k1/PI + k2-k1 + ((1-k2)*(2/PI))*sin(((t-k2)/(1.0-k2))*PI/2);
}
return (s/f);
}
}