Jump to content

Path with orientation from points


photo

Recommended Posts

Posted

I have simple path data from some application - just list of xyz coordinates:

(0, 0, 0)
(100, 0, 50)
(100, 100, 100)
(0, 100, 50)
(0, 0, 0)

I want to use this data to create Unigine::Path and then use this path in Unigine::WorldTransformPath to animate object - transform it along this path.
I'm adding this points to Unigine::Path using setFramePosition and setFrameTime.

I saw that Unigine::WorldTransformPath have method setOrientation that should keep my object correctly oriented during transformation animation along path, but it seems like it's not working for me - object is always oriented in one direction.

How can I correct object orientation? Do I need to somehow calculate rotation in every path frame (setFrameRotation) and this will be used to object orientation?

Posted
Unigine::Vector<Unigine::Math::vec3> points;
//...adding a lot of vec3 from my other app

Unigine::PathPtr path = Unigine::Path::create( );
for ( int pI = 0; pI < points.size( ); ++pI )
{
  const int frame = path->addFrame( );
  path->setFramePosition( frame, points[pI] );
  path->setFrameTime( frame, 1.0 * (float)pI );
}

Unigine::String pathFile = "myPath.path";
path->save( pathFile );

Unigine::NodeReferencePtr fbxReference = Unigine::NodeReference::create( "myFbx.fbx" );
  
Unigine::WorldTransformPathPtr worldTransformPath = Unigine::WorldTransformPath::create( pathFile );
worldTransformPath->setLoop( 1 );
worldTransformPath->setOrientation( 1 );
worldTransformPath->setRadius( 100 );
worldTransformPath->addChild( fbxReference->getNode( ) );
worldTransformPath->play( );
worldTransformPath->release( );
Unigine::Editor::get( )->addNode( worldTransformPath->getNode( ) );

I'm currently using Unigine 2.7.2.1.

Posted

Hi!

The Orientation parameter has default value 1.

If it's settled to 1, the transformation of intermediate frame between two frames is calculated via full matrices from these frames.

If == 0, only the position from frames is taken for an intermediate frame, scale and rotation are taken from node transformation.

You should use setFrameRotation or setFrameTransform for each frame.

Posted

Hello,
Do you have any hints for how to calculate this transformations having only list of vec3 coordinates?

Posted

Use vector between two points as Axis for basis.

Example. Don't forget calculate special case when axis_y and Vec3::UP are collinear.

Vec3 start_p, end_p;
auto axis_y = (end_p - start_p).normalize();
auto axis_z (Vec3::UP);
auto axis_x (cross(axis_y, axis_z));
Mat4 transform(axis_x, axis_y, axis_z, start_p);

 

  • Like 1
×
×
  • Create New...