Using Movers & Rotators and Finding Target Angles
Posted: Tue Feb 17, 2015 7:15 am
Hi, I'm animating a MobileMesh model using EntityMover and EntityRotator classes. The objective is the model should rotate and move to a known position. ConstantLinearSpeedCurve and ConstantAngularSpeedCurve are used as input paths to EntityMover and EntityRotator objects respectively. Since I have only the initial (current) and target position & angle of the model, LinearInterpolationCurve3D and QuaternionSlerpCurve objects with only two control points are used as inputs to ConstantLinearSpeedCurve and ConstantAngularSpeedCurve. First control point at time=0 is set to current position & orientation and another control point at time=1 is set to target position and orientation. Both PreLoop and PostLoop are set to Clamp.
With this setup, translation (movement) and rotation animations are working correctly, but not consistently. Can you please help on the following questions.
1) Wondering whether EntityMover and EntityRotator classes are the right choice for the above mentioned objective. Also, the animation is already working with only two control points but should we give few intermediate positions and angles as inputs to position and rotation paths?
2) How to find whether mover and rotator has finished moving and rotating the model to target? Currently, Vector3.Distance and Quaternion.GetRelativeRotation methods are used in PositionUpdated event in order to check whether the model has reached the target location and angle. Not sure whether this is correct and whether this is the only possible solution for this.
3) The mover and rotator seems to work fine only for first time; the consecutive attempts to move/rotate the same model is not working - the model keeps flickering at the same location. It appears like it is trying to move to the 2nd target position from 1st target position but something is trying to hold it back to the 1st target position, so it keeps flickering to and fro at same position (between 1st and 2nd target positions) with quick random animations. A dictionary is maintained to store multiple movers and rotators and each mover/rotator is removed from the dictionary once it has reached the target. The flickering issue happens both with and without the dictionary. Without dictionary, same mover/rotator object is reused (but each time new instance is created). Time step variable (used in Path.Evaluate) is reset to 0 while creating the mover/rotator object. The same issue happens even with or without removing the mover/rotator from space after it has reached the target.
4) Another question (however not related to mover/rotator) is... how to find the target quaternion for a model when it needs to be aligned perpendicular to a line in 3D space. If there are two Vector3 points that might form a straight line in 3D space and the model need to be aligned perpendicular to that straight line, the question is how to find the quaternion to be applied to the model so that the model is parallel to a plane that is perpendicular to the line connecting the two points. I can see the method Quaternion.GetQuaternionBetweenNormalizedVectors and its usage in BEPUphysicsDemos, but some valuable inputs on this problem would be very helpful. ** EDIT ** Since perpendicular is always 90 degree, quaternion can be easily created using Quaternion.CreateFromAxisAngle or Quaternion.CreateFromYawPitchRoll, but still 90 degree is applicable for one axis only if I'm correct and still need to find values for x, z and w components of quaternion if y is set to 90 degree... maybe I'm missing something basic here.
With this setup, translation (movement) and rotation animations are working correctly, but not consistently. Can you please help on the following questions.
1) Wondering whether EntityMover and EntityRotator classes are the right choice for the above mentioned objective. Also, the animation is already working with only two control points but should we give few intermediate positions and angles as inputs to position and rotation paths?
2) How to find whether mover and rotator has finished moving and rotating the model to target? Currently, Vector3.Distance and Quaternion.GetRelativeRotation methods are used in PositionUpdated event in order to check whether the model has reached the target location and angle. Not sure whether this is correct and whether this is the only possible solution for this.
3) The mover and rotator seems to work fine only for first time; the consecutive attempts to move/rotate the same model is not working - the model keeps flickering at the same location. It appears like it is trying to move to the 2nd target position from 1st target position but something is trying to hold it back to the 1st target position, so it keeps flickering to and fro at same position (between 1st and 2nd target positions) with quick random animations. A dictionary is maintained to store multiple movers and rotators and each mover/rotator is removed from the dictionary once it has reached the target. The flickering issue happens both with and without the dictionary. Without dictionary, same mover/rotator object is reused (but each time new instance is created). Time step variable (used in Path.Evaluate) is reset to 0 while creating the mover/rotator object. The same issue happens even with or without removing the mover/rotator from space after it has reached the target.
4) Another question (however not related to mover/rotator) is... how to find the target quaternion for a model when it needs to be aligned perpendicular to a line in 3D space. If there are two Vector3 points that might form a straight line in 3D space and the model need to be aligned perpendicular to that straight line, the question is how to find the quaternion to be applied to the model so that the model is parallel to a plane that is perpendicular to the line connecting the two points. I can see the method Quaternion.GetQuaternionBetweenNormalizedVectors and its usage in BEPUphysicsDemos, but some valuable inputs on this problem would be very helpful. ** EDIT ** Since perpendicular is always 90 degree, quaternion can be easily created using Quaternion.CreateFromAxisAngle or Quaternion.CreateFromYawPitchRoll, but still 90 degree is applicable for one axis only if I'm correct and still need to find values for x, z and w components of quaternion if y is set to 90 degree... maybe I'm missing something basic here.