Unigine::Curve2d Class
Header: | #include <UnigineCurve2d.h> |
This class represents an interface enabling you to create and manage 2D curves. These curves are used, for example, to control behavior of various parameters of particle systems (how they change over time).
Curve2d Class
Enums
REPEAT_MODE#
Mode to be used for repeating the sequence defined by the key points of the curve (tiling curves).Members
Curve2d ( ) #
Constructor. Creates a new 2d curve instance.Curve2d ( const Ptr<Curve2d> & curve ) #
Constructor. Initializes the curve by copying the specified source curve.Arguments
- const Ptr<Curve2d> & curve - Source curve.
void clear ( ) #
Clears the curve removing all key points and tangents.void copy ( const Ptr<Curve2d> & curve ) #
Copies all the data (all key points and tangents) from the specified source curve.Arguments
- const Ptr<Curve2d> & curve - Source curve.
int getHash ( ) const#
Returns a hash value calculated for the curve. This value is used for performance optimization and helps define if the curve really needs to be updated, or nothing has changed in its parameters (repeat mode, key points, and tangents are all the same).Return value
Hash value calculated for the curve.int getNumKeys ( ) const#
Returns the current total number of key points in the curve .Return value
Total number of key points in the curve.int addKey ( const Math::vec2 & point ) #
Adds a new key point with the specified coordinates to the curve. Upon completion on this operation the CHANGED callback is fired.Arguments
- const Math::vec2 & point - Coordinates of the new key point to be added.
Return value
Number of the added key point.int addKey ( const Math::vec2 & point, const Math::vec2 & left_tangent, const Math::vec2 & right_tangent ) #
Adds a new key point with the specified coordinates and tangents to the curve. Upon completion on this operation the CHANGED callback is fired.Arguments
- const Math::vec2 & point - Coordinates of the new key point to be added.
- const Math::vec2 & left_tangent - Coordinates of the left tangent at the key point.
- const Math::vec2 & right_tangent - Coordinates of the right tangent at the key point.
Return value
Number of the added key point.void removeKey ( int index ) #
Removes the key point with the specified number from the curve. Upon completion on this operation the CHANGED callback is fired.Arguments
- int index - Key point number, in the range from 0 to the total number of key points in the curve.
int moveKey ( int index, const Math::vec2 & point ) #
Moves the key point with the specified number to a new position (preserving the tangents). Upon completion on this operation the CHANGED callback is fired. The index of key point will be updated automatically. This method can be used to implement dragging of keys on the curve. In case of moving multiple keys it is recommended to use the setKeyPoint() method to set new values for keys and then sort them all at once via the sortKeys() method to save performance.Arguments
- int index - Key point number, in the range from 0 to the total number of key points in the curve.
- const Math::vec2 & point
void sortKeys ( ) #
Sorts all key points ov the curve by time (X axis) in the ascending order. Upon completion on this operation the CHANGED callback is fired.void setKeyPoint ( int index, const Math::vec2 & point ) #
Sets new coordinates for the specified key point (tangents are unaffected). Upon completion on this operation the CHANGED callback is fired. This method unlike the moveKey() does not update the index of the key point automatically. It can be used to implement dragging of multiple keys to set new values for them along with subsequent sorting all keys at once via the sortKeys() method to save performance.Arguments
- int index - Key point number, in the range from 0 to the total number of key points in the curve.
- const Math::vec2 & point - New coordinates to be set for the specified point.
void setKeyLeftTangent ( int index, const Math::vec2 & point ) #
Sets new coordinates for the left tangent at the specified key point of the curve. Upon completion on this operation the CHANGED callback is fired.Arguments
- int index - Key point number, in the range from 0 to the total number of key points in the curve.
- const Math::vec2 & point - New coordinates of the left tangent at the specified key point to be set.
void setKeyRightTangent ( int index, const Math::vec2 & point ) #
Sets new coordinates for the right tangent at the specified key point of the curve. Upon completion on this operation the CHANGED callback is fired.Arguments
- int index - Key point number, in the range from 0 to the total number of key points in the curve.
- const Math::vec2 & point - New coordinates of the right tangent at the specified key point to be set.
Math::vec2 getKeyPoint ( int index ) #
Returns the coordinates of the key point with the specified number.Arguments
- int index - Key point number, in the range from 0 to the total number of key points in the curve.
Return value
Current coordinates of the specified key point.Math::vec2 getKeyLeftTangent ( int index ) #
Returns the current coordinates for the left tangent at the specified key point of the curve.Arguments
- int index - Key point number, in the range from 0 to the total number of key points in the curve.
Return value
Current coordinates of the left tangent at the specified key point.Math::vec2 getKeyRightTangent ( int index ) #
Returns the current coordinates for the right tangent at the specified key point of the curve.Arguments
- int index - Key point number, in the range from 0 to the total number of key points in the curve.
Return value
Current coordinates of the right tangent at the specified key point.int saveState ( const Ptr<Stream> & stream ) const#
Saves data of the curve to a binary stream.Example using saveState() and restoreState() methods:
// initialize a node and set its state
Curve2dPtr curve = Curve2d::create();
curve->addKey(vec2(1, 0));
curve->addKey(vec2(2, 1));
curve->addKey(vec2(4, 3));
// save state
BlobPtr blob_state = Blob::create();
curve->saveState(blob_state);
// change state
curve->removeKey(1);
// restore state
blob_state->seekSet(0); // returning the carriage to the start of the blob
curve->restoreState(blob_state);
Arguments
Return value
true if the curve data is saved successfully; otherwise, false.bool restoreState ( const Ptr<Stream> & stream ) #
Restores curve data from a binary stream.Example using saveState() and restoreState() methods:
// initialize a node and set its state
Curve2dPtr curve = Curve2d::create();
curve->addKey(vec2(1, 0));
curve->addKey(vec2(2, 1));
curve->addKey(vec2(4, 3));
// save state
BlobPtr blob_state = Blob::create();
curve->saveState(blob_state);
// change state
curve->removeKey(1);
// restore state
blob_state->seekSet(0); // returning the carriage to the start of the blob
curve->restoreState(blob_state);
Arguments
Return value
true if the curve data is restored successfully; otherwise, false.bool save ( const Ptr<Xml> & xml ) const#
Saves data of the curve to the specified instance of the Xml class.Arguments
Return value
true if the curve data is successfully saved to the specified Xml class instance; otherwise, false.bool load ( const Ptr<Xml> & xml ) #
Loads curve data from the specified instance of the Xml class.Arguments
Return value
true if the curve data is successfully loaded from the specified Xml class instance; otherwise, false.void setRepeatModeStart ( Curve2d::REPEAT_MODE start ) #
Sets the mode for the beginning of the curve to be used for repeating the sequence defined by the key points of the curve (tiling curves).Arguments
- Curve2d::REPEAT_MODE start - Repeat mode for the beginning of the curve (defines behavior before the first key point), one of the REPEAT_MODE_* values.
Curve2d::REPEAT_MODE getRepeatModeStart ( ) const#
Returns the current mode for the beginning of the curve used for repeating the sequence defined by the key points of the curve (tiling curves).Return value
Current repeat mode for the beginning of the curve (defines behavior before the first key point), one of the REPEAT_MODE_* values.void setRepeatModeEnd ( Curve2d::REPEAT_MODE end ) #
Sets the mode for the end of the curve to be used for repeating the sequence defined by the key points of the curve (tiling curves).Arguments
- Curve2d::REPEAT_MODE end - Repeat mode for the end of the curve (defines behavior after the last key point), one of the REPEAT_MODE_* values.
Curve2d::REPEAT_MODE getRepeatModeEnd ( ) const#
Returns the current mode for the end of the curve used for repeating the sequence defined by the key points of the curve (tiling curves).Return value
Current repeat mode for the end of the curve (defines behavior after the last key point), one of the REPEAT_MODE_* values.void * addChangedCallback ( Unigine::CallbackBase * func ) #
Adds a callback function to be called on changing the curve. The signature of the changed callback function must be as follows:void changed_callback_function_name();
You can set a callback function as follows:
addChangedCallback(MakeCallback(changed_callback_function_name));
Example: Setting a changed callback function for a curve:
class SomeClass {
/*...*/
// curve for which a changed callback function is to be set
Unigine::Curve2d curve;
/*...*/
};
/*...*/
// callback function
void SomeClass::on_change()
{
// insert your code handling curve changing here
}
void SomeClass::registerCallback()
{
// setting the on_change() function to handle curve changing
curve->addChangedCallback(MakeCallback(this, &SomeClass::on_change));
}
Arguments
- Unigine::CallbackBase * func - Callback pointer.
Return value
ID of the last added changed callback, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.bool removeChangedCallback ( void * id ) #
Removes the specified callback from the list of changed callbacks.Arguments
- void * id - Changed callback ID obtained when adding it.
Return value
True if the changed callback with the given ID was removed successfully; otherwise false.void clearChangedCallbacks ( ) #
Clears all added changed callbacks.float evaluate ( float time ) const#
Returns the evaluated value of the curve at the specified point in time.Arguments
- float time - The time within the curve you want to evaluate (horizontal axis in the curve graph).
Return value
The value of the curve, at the specified point in time.Last update:
13.12.2021
Помогите сделать статью лучше
Была ли эта статья полезной?
(или выберите слово/фразу и нажмите Ctrl+Enter