CCurve Manual

About

A CCurve represents an animation curve that stores and interpolates animation keys. A CCurve is stored in a CTrack object.

CCurve objects are an instance of CSbase.

// This code loops through all tracks and all keys of the given object.
CTrack* track = activeObject->GetFirstCTrack();
while (track)
{
CCurve* const curve = track->GetCurve();
if (curve == nullptr)
continue;
const Int32 keyCount = curve->GetKeyCount();
for (Int32 i = 0; i < keyCount; ++i)
{
CKey* const key = curve->GetKey(i);
if (key)
{
// do something with the key
ApplicationOutput("Found a key!");
}
}
track = track->GetNext();
}

Access

CCurve objects cannot be created on their own. They are created with a CTrack that contains the CCurve object.

Keys

Access Keys

The CCurve objects stores the animation keys and provides access to these:

// This example searches for a key left from the given time.
const BaseTime time = doc->GetTime();
CKey* const leftKey = curve->FindKey(time, nullptr, FINDANIM::LEFT);
if (leftKey)
{
// move this key to the current time
leftKey->SetTime(curve, time);
}

Add Keys

A CCurve object can create and receive keys:

// This example creates keys along the timeline.
const Int32 fps = doc->GetFps();
const Int32 min = doc->GetMinTime().GetFrame(fps);
const Int32 max = doc->GetMaxTime().GetFrame(fps);
const Int32 range = max - min;
const Int32 step = range / 10;
const BaseTime stepTime = BaseTime(step, fps);
BaseTime keyTime = doc->GetMinTime();
for (Int32 i = 0; i <= 10; ++i)
{
if (curve->AddKey(keyTime, nullptr) == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
keyTime = keyTime + stepTime;
}

See also CKey Allocation/Deallocation.

Handle Keys

A CCurve object can be used to manipulate its keys:

// This example creates a new key and sets the default values.
Int32 index;
CKey* const newKey = curve->AddKey(time, &index);
if (newKey == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
track->FillKey(doc, obj, newKey);
curve->SetKeyDefault(doc, index);

Unmuted Keys

A key can be muted so it is ignored.

// This example searches for the first unmuted key.
const CKey* const key = curve->FindNextUnmuted(0);
if (key)
{
const Float time = key->GetTime().Get();
ApplicationOutput("Found unmuted key at " + String::FloatToString(time));
}

See also CKey Bits.

Animation

The interpolation between the keys defines the dynamics of an animation. This interpolation is refined with the tangents.

  • CCurve::CalcHermite(): Calculates the Hermite spline between two sets of key values.
  • CCurve::CalcSoftTangents(): Calculates the soft tangents (i.e. auto interpolation) around the key of the given index.
  • CCurve::GetTangents(): Computes the tangents of a key, taking into account all options like zero slope, link slope etc.
  • CCurve::GetValue(): Returns the value calculated at the given time, taking into account things like time curves.
// This example samples the curve.
BaseTime time(0.0);
const BaseTime step(0.1);
for (Int32 i = 0; i < 10; ++i)
{
const Float value = curve->GetValue(time);
time = time + step;
}

Time

A CCurve is confined by a first and a last key:

// This example sets the loop time dimensions based on the start
// and end time of the given curve.
const BaseTime start = curve->GetStartTime();
const BaseTime end = curve->GetEndTime();
doc->SetLoopMinTime(start);

Further Reading