This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Unigine.Curve2d Class

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).
NameDescription
CLAMP = 0The value of the start or the end key is retained. Use this option if you don't want any changes before or after the effect created by the curve.
LOOP = 1The curve is tiled. The created effect is repeated cyclically. If the values of the first and the last key are different, the transition between the curves will be abrupt.
PING_PONG = 2Every next curve section is a reflection of the previous curve section. The created effect is repeated in the forward-and-backward manner.
NUM_REPEAT_MODES = 3Number of repeat modes.

Properties

int Hash#

The Hash value calculated for the curve. Hash 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).

int NumKeys#

The Total number of key points in the curve.

Curve2d.REPEAT_MODE RepeatModeStart#

The Repeat mode for the beginning of the curve (defines behavior before the first key point), one of the REPEAT_MODE_* values. This mode shall be used for repeating the sequence defined by the key points of the curve (tiling curves).

Curve2d.REPEAT_MODE RepeatModeEnd#

The Repeat mode for the end of the curve (defines behavior after the last key point), one of the REPEAT_MODE_* values. This mode shall 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 ( Curve2d curve ) #

Constructor. Initializes the curve by copying the specified source curve.

Arguments

  • Curve2d curve - Source curve.

void Clear ( ) #

Clears the curve removing all key points and tangents.

void Copy ( Curve2d curve ) #

Copies all the data (all key points and tangents) from the specified source curve.

Arguments

  • Curve2d curve - Source curve.

int AddKey ( 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

  • vec2 point - Coordinates of the new key point to be added.

Return value

Number of the added key point.

int AddKey ( vec2 point, vec2 left_tangent, 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

  • vec2 point - Coordinates of the new key point to be added.
  • vec2 left_tangent - Coordinates of the left tangent at the key point.
  • 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 MoveKey ( int index, 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

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, 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.
  • vec2 point - New coordinates to be set for the specified point.

void SetKeyLeftTangent ( int index, 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.
  • vec2 point - New coordinates of the left tangent at the specified key point to be set.

void SetKeyRightTangent ( int index, 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.
  • vec2 point - New coordinates of the right tangent at the specified key point to be set.

vec2 GetKeyPoint ( int index ) #

Returns the coordinates of the key point with the specified number.

Arguments

Return value

Current coordinates of the specified key point.

vec2 GetKeyLeftTangent ( int index ) #

Returns the current coordinates for the left tangent at the specified key point of the curve.

Arguments

Return value

Current coordinates of the left tangent at the specified key point.

vec2 GetKeyRightTangent ( int index ) #

Returns the current coordinates for the right tangent at the specified key point of the curve.

Arguments

Return value

Current coordinates of the right tangent at the specified key point.

bool SaveState ( Stream stream ) #

Saves data of the curve to a binary stream.

Example using saveState() and restoreState() methods:

Source code (C#)
// initialize a node and set its state
Curve2d curve = new Curve2d();
curve.AddKey(new vec2(1, 0));
curve.AddKey(new vec2(2, 1));
curve.AddKey(new vec2(4, 3));

// save state
Blob blob_state = new Blob();
curve.SaveState(blob_state);

// change the node state
curve.RemoveKey(1);

// restore state
blob_state.SeekSet(0);	// returning the carriage to the start of the blob
curve.RestoreState(blob_state);

Arguments

  • Stream stream - Stream to which the curve data will be saved.

Return value

true if the curve data is saved successfully; otherwise, false.

bool RestoreState ( Stream stream ) #

Restores curve data from a binary stream.

Example using saveState() and restoreState() methods:

Source code (C#)
// initialize a node and set its state
Curve2d curve = new Curve2d();
curve.AddKey(new vec2(1, 0));
curve.AddKey(new vec2(2, 1));
curve.AddKey(new vec2(4, 3));

// save state
Blob blob_state = new Blob();
curve.SaveState(blob_state);

// change the node state
curve.RemoveKey(1);

// restore state
blob_state.SeekSet(0);	// returning the carriage to the start of the blob
curve.RestoreState(blob_state);

Arguments

  • Stream stream - Stream in which the saved curve parameter data is stored.

Return value

true if the curve data is restored successfully; otherwise, false.

bool Save ( Json json ) #

Saves data of the curve to the specified instance of the Json class.

Arguments

  • Json json - Json class instance to which the curve data will be saved.

Return value

true if the curve data is successfully saved to the specified Json class instance; otherwise, false.

bool Load ( Json json ) #

Loads curve data from the specified instance of the Json class.

Arguments

Return value

true if the curve data is successfully loaded from the specified Json class instance; otherwise, false.

bool Save ( Xml xml ) #

Saves data of the curve to the specified instance of the Xml class.

Arguments

  • Xml xml - Xml class instance to which the curve data will be saved.

Return value

true if the curve data is successfully saved to the specified Xml class instance; otherwise, false.

bool Load ( Xml xml ) #

Loads curve data from the specified instance of the Xml class.

Arguments

  • Xml xml - Xml class instance in which the curve data is stored.

Return value

true if the curve data is successfully loaded from the specified Xml class instance; otherwise, false.

IntPtr AddChangedCallback ( ChangedDelegate func ) #

Adds a callback function to be called on changing the curve. The signature of the changed callback function must be as follows:
Source code (C#)
void changed_callback_function_name();

You can set a callback function as follows:

Source code (C#)
AddChangedCallback(() => changed_callback_function_name());

Example: Setting a changed callback function for a curve:

Source code (C#)
class SomeClass
{
	// curve for which a changed callback function is to be set
	Unigine.Curve2d curve;

	/*...*/

	// callback function
	private void on_change()
	{
		// insert your code handling curve changing here
	}

	private void RegisterCallback()
	{
		// setting the on_change() function to handle curve changing
		curve.AddChangedCallback(() => on_change());
	}
	
	/*...*/
}

Arguments

  • ChangedDelegate func - Callback function with the following signature: void ChangedDelegate()

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 ( IntPtr id ) #

Removes the specified callback from the list of changed callbacks.

Arguments

  • IntPtr 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 ) #

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: 2022-12-14
Build: ()