1
C / C++ /C# / Re: Help with understanding demo source
« on: July 07, 2016 »
Thanks for your help. I've got a lot of reading to do!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Vector3 getCubeKeyframe(int key)
{
const Vector3 keyframes[] = {
Vector3(0, 0, 0),
Vector3(60, 0, 0),
Vector3(120, 0, 0),
Vector3(120, 60, 0),
Vector3(120, 120, 0),
Vector3(60, 120, 0),
Vector3(0, 120, 0),
Vector3(0, 120, 60),
Vector3(0, 120, 120),
Vector3(0, 60, 120),
Vector3(0, 0, 120),
Vector3(0, 0, 60),
Vector3(0, 0, 0),
Vector3(0, 0, -60),
Vector3(0, 0, -120),
Vector3(60, 0, -120),
Vector3(120, 0, -120),
Vector3(120,-60, -120),
Vector3(120,-120,-120),
Vector3(60, -120,-120),
Vector3(0, -120,-120),
Vector3(0, -120,-60),
Vector3(0, -120, 0),
Vector3(0, -60, 0)
};
return keyframes[key % ARRAY_SIZE(keyframes)] * 0.5
+ keyframes[(key - 1) % ARRAY_SIZE(keyframes)] * 0.25
+ keyframes[(key + 1) % ARRAY_SIZE(keyframes)] * 0.25;
}
Vector3 getCubePos(float cam_time)
{
int k0 = int(floor(cam_time) - 1);
int k1 = k0 + 1;
int k2 = k1 + 1;
int k3 = k2 + 1;
Vector3 samples[4] = {
getCubeKeyframe(k0), getCubeKeyframe(k1), getCubeKeyframe(k2), getCubeKeyframe(k3)
};
Vector3 tangents[2] = {
(samples[2] - samples[0]) / 2.0,
(samples[3] - samples[1]) / 2.0
};
float t = cam_time - floor(cam_time);
float t2 = t * t;
float t3 = t2 * t;
float w[4] = {
// 2t^3 - 3t^2 + 1
2.0f * t3 - 3.0f * t2 + 1.0f,
// t^3 - 2t^2 + t
1.0f * t3 - 2.0f * t2 + t,
// -2t^3 + 3t^2
w[2] = -2.0f * t3 + 3.0f * t2,
// t^3 - t^2
w[3] = 1.0f * t3 - 1.0f * t2
};
return samples[1] * w[0] +
tangents[0] * w[1] +
samples[2] * w[2] +
tangents[1] * w[3];
}


It's the kind of thing I always wanted to make back in the DOS days when I had no skill. I first saw this lissajous effect in Cronologia by cascada.

