This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Rendering
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Version Control
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
Animations-Related Classes
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
VR-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Unigine::NodePivot Class

Header: #include <UnigineNodes.h>
Inherits from: Node

This class adds a pivot node that can serve as a pivot point for its children and allows for easy control over their transformation. It has two matrices: one sets the basis of rotation (the pivot point transformation matrix), and another one describes local transformation for child nodes relative to the pivot point.

Notice
It has virtually zero influence on performance and shares all common options that other nodes have.

Creating a Pivot Node#

To create a pivot node, perform as follows:

  • Create an instance of the NodePivot class.
  • Add child nodes to the pivot node.
Source code (C++)
#include "AppWorldLogic.h"
#include <UnigineNodes.h>
#include <UnigineEditor.h>
#include <UnigineMesh.h>
#include <UnigineObjects.h>

using namespace Unigine;
using namespace Math;

int AppWorldLogic::init() {

	// create a mesh
	MeshPtr mesh = Mesh::create();
	mesh->addBoxSurface("box_0", vec3(1.0f));
	// create a node (e.g. an instance of the ObjectMeshStatic class)
	ObjectMeshStaticPtr object = ObjectMeshStatic::create(mesh);
	object->setMaterialParameterFloat4("albedo_color", vec4(1.0f, 0.0f, 0.0f, 1.0f), 0);

	// create a pivot node
	NodePivotPtr pivot = NodePivot::create();

	// add the static mesh to the pivot node as a child
	pivot->addWorldChild(object);

	return 1;
}

Editing a Pivot Node#

Editing the pivot node includes changing its pivot and local transformation matrices. The example below performs as follows:

  1. Create a first node and set its transformation.
  2. Create a first pivot node and add the previously created node to it as a child.
  3. Perform the same for the second pivot node and its child node.
  4. Change pivot point transformation of the second pivot node.
  5. In the main loop, on the engine update, change local transformations of the child nodes.

In the result, child nodes will have different trajectories of movement, as the pivot nodes have different pivot point transformations.

Source code (C++)
#include "AppWorldLogic.h"
#include <UnigineNodes.h>
#include <UnigineEditor.h>
#include <UnigineMesh.h>
#include <UnigineObjects.h>
#include <UnigineGame.h>
#include <UnigineLog.h>

using namespace Unigine;
using namespace Math;

NodePivotPtr pivot_0;
NodePivotPtr pivot_1;

int AppWorldLogic::init() {

	// create a mesh
	MeshPtr mesh = Mesh::create();
	mesh->addBoxSurface("box_0", vec3(0.7f));
	
	// create a 1st node (e.g. an instance of the ObjectMeshStatic class)
	ObjectMeshStaticPtr object_0 = ObjectMeshStatic::create(mesh);

	// change material albedo color
	object_0->setMaterialParameterFloat4("albedo_color", vec4(1.0f, 0.0f, 0.0f, 1.0f), 0);
	// set node transformation
	object_0->setWorldPosition(object_0->getWorldPosition() + Vec3(2.0));
	
	// create a 1st pivot node
	pivot_0 = NodePivot::create();

	// set pivot node transformation
	pivot_0->setWorldTransform(object_0->getWorldTransform() * translate(Vec3(-1.0, 0.0, 0.0)));
	// add the 1st created node as a child to the pivot node
	pivot_0->addWorldChild(object_0);

	// create a 2nd node
	ObjectMeshStaticPtr object_1 = ObjectMeshStatic::create(mesh);
	// change material albedo color
	object_1->setMaterialParameterFloat4("albedo_color", vec4(0.0f, 1.0f, 0.0f, 1.0f), 0);
	// set node transformation
	object_1->setWorldTransform(object_1->getWorldTransform() * translate(Vec3(1.0, 0.0, 0.0)));
	
	// create a 2nd pivot node
	pivot_1 = NodePivot::create();

	// set pivot node transformation
	pivot_1->setWorldPosition(pivot_0->getWorldPosition() + Vec3(1.0));
	// add the 2nd created node as a child to the pivot node
	pivot_1->addWorldChild(object_1);


	// change the pivot point transformation of the 2nd pivot node
	mat4 transform = pivot_1->getPivotTransform();
	transform.setRotateX(45.0f);
	pivot_1->setPivotTransform(pivot_1->getPivotTransform() * transform);
	
	return 1;
}

int AppWorldLogic::update() {

	float ifps = Game::getIFps();
	float angle = ifps * 45.0f;

	// set local transformation for the child nodes of the 1st pivot node
	mat4 transform_0 = pivot_0->getLocalTransform();
	transform_0.setRotateZ(angle);
	pivot_0->setLocalTransform(pivot_0->getLocalTransform() * transform_0);
	
	// set local transformation for the child nodes of the 2nd pivot node
	mat4 transform_1 = pivot_1->getLocalTransform();
	transform_1.setRotateZ(angle);
	pivot_1->setLocalTransform(pivot_1->getLocalTransform() * transform_1);
	
	return 1;
}

To get position, rotation and scale components of transformation, use the decomposeTransform() method:

Source code (C++)
vec3 translate,scale;
quat rotate;
Unigine::Math::decomposeTransform(pivot->getPivotTransform(),translate,rotate,scale);

See Also#

  • Article on the Pivot node

NodePivot Class

Members


static NodePivotPtr create ( ) #

Creates a pivot node (with the pivot and local transformation matrices equal to mat4_identity).

void setLocalTransform ( const Math::mat4 & transform ) #

Sets a matrix that controls local transformations of child nodes.

Arguments

  • const Math::mat4 & transform - Local transformation matrix.

Math::mat4 getLocalTransform ( ) #

Returns the current matrix used to control local transformations of the child nodes.

Return value

Local transformation matrix.

void setPivotTransform ( const Math::mat4 & transform ) #

Sets a matrix that controls the basis of rotation of the child nodes (the pivot point transformation matrix).

Arguments

  • const Math::mat4 & transform - Pivot transformation matrix.

Math::mat4 getPivotTransform ( ) #

Returns the current transformation matrix used to control the basis of rotation of the child nodes (the pivot point transformation matrix).

Return value

Local transformation matrix.

static int type ( ) #

Returns the type of the node.

Return value

NodePivot type identifier.
Last update: 2023-07-11
Build: ()