Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3508 Members - Latest Member: PienueDut

26. May 2012, 09:35:19 am
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Animation along a curve
Pages: [1]
Print
Author Topic: Animation along a curve  (Read 605 times)
kluks
Just dropped in

Offline Offline

Posts: 3


View Profile Email
« on: 04. December 2008, 03:20:54 pm »

Hi all. I just started experimenting with Xith3D. I want to a group of objects (a bunch of spheres at the moment) along a curve (circle would be ok for the moment). Could you point me to some examples or explain what classes should I use.

I could use TransformationDirectives and modify x,y,z speeds every few frames but this looks like a very cumbersome solution.

Regards,
Krzysztof
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 04. December 2008, 05:36:24 pm »

Hi Krzysztof. Welcome to Xith3D Smiley.

I suggest to use org.openmali.curves.BezierCurve to compute the positions at a timepoint. Is applying them to the scenegraph a problem for you?

Marvin
Logged
kluks
Just dropped in

Offline Offline

Posts: 3


View Profile Email
« Reply #2 on: 05. December 2008, 08:58:05 am »

Thanks for your reply Marvin.

I could use some help with applying computed positions to my scenegraph. I created BezierCurve2 object and I can compute points on it with getPoint() method in prepareNextFrame(). But how do I actually use them to transform scenegraph? Do I need to use DistanceInterpolator?
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #3 on: 05. December 2008, 11:08:14 am »

No you don't have to further interpolate the translation, since it already is interpolated by BezierCurve2.

All you need to do is to get the right TransformGroup "tg" and do the following with it:
Code:
Point3f p = your_interpolated_point_on_the_bezier_curve;
tg.getTransform().setTranslation( p );
tg.updateTransform();

That's all so far. Maybe you also want to adjust the rotation, so that the shape isn't always facing in the same absolute direction. This can be done by e.g. this code:
Code:
Point3f p0 = you_center_fix_point;

...

Vector3f v = Vector3f.fromPool();
v.sub( p0, p );
float angle = v.angle( Vector3f.POSITIVE_X_AXIS );
Matrix3f rot = Matrix3f.fromPool();
MatrixUtils.getRotationMatrix( 0f, 0f, 1f, angle, rot );
tg.getTransform().setRotation( rot );
tg.getTransform().setTranslation( p );
tg.updateTransform();

Matrix3f.toPool( rot );
Vector3f.toPool( v );

Marvin
Logged
kluks
Just dropped in

Offline Offline

Posts: 3


View Profile Email
« Reply #4 on: 05. December 2008, 12:25:56 pm »

It works, thanks!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic