Position after rotation around custom pivot

Software: Away3D 4.x

Avatar
Sonoma, Newbie
Posted: 22 November 2014 09:54 AM   Total Posts: 1

Hello everyone!

I’m currently working on a basic truck / trailer animation with Away3D 4.5.1 where I need the trailer’s coupling position to be aligned with the truck’s coupling position. Furthermore the trailer should rotate around it’s coupling position.

This is what I currently do:

[Initialization]
1. Create a container with a cube mesh and a coupling mesh for the truck and the trailer.
2. Calculate the distance between the truck’s and trailer’s coupling.
3. Set the trailer’s pivot position to the local position of the coupling mesh.

mTrailer.pivotPoint mTrailerCouplingMesh.position;
   
// Calculate desired coupling distance
mCouplingDist Vector3D.distancetruckCouplingMesh.positionmTrailerCouplingMesh.position ); 

[Position & Rotation Update]
1. Set the truck’s position and rotation.
2. Set the trailer’s rotation to the truck’s rotation and position the trailer behind the truck using the truck’s back vector and the coupling distance calculated during initialization.

mTrailer.mTruck.mTruck.backVector.mCouplingDist;   
mTrailer.mTruck.mTruck.backVector.mCouplingDist;
mTrailer.rotationY mTruck.rotationY

This works fine for any truck position if the truck’s rotation is zero. But as soon as I change the truck’s rotation the coupling alignment doesn’t work anymore. Also, if I don’t change the trailer’s pivot point at all and keep it at (0,0,0) the alignment works.

I attached some screenshots to illustrate the problem.

It seems that I have to add some kind off additional offset depending on the rotation angle? But I can’t really figure out the math at the moment. :-(

The source of the test project can be found in the attachment of the post.
You can also check out test project here: http://sonoma.lima-city.de/TruckTrailerCoupling/

Cheers,
Sonoma

 

 

File Attachments
TruckTrailerCoupling.zip  (File Size: 332KB - Downloads: 344)
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X