Tuesday 15 February 2011

android - AndEngine Smooth Rotation along Path -


I am portraying a path and transferring a phantom with it. Now I want to see the phantom in every direction along the way. With this code I can just set the direction (non smooth). GetTargetAngle returns a new rotation angle.

  float angedge = getTargetAngle (sprite.getX), sprite.getY (), target x [pWaypointIndex + 1], target y [pWaypointIndex + 1]); Sprite.setRotation (angleDeg);   

Now I can smooth it, except the IM at the turn of -179 to 179 degrees, where it changes with the long path rather than the small and makes the jump:

  sprite.unregisterEntityModifier (rotMod); RotMod = New rotation modifier (0.5 F, current angle deg, anglegeng); Sprite.registerEntityModifier (rotMod);   

When I had more than 180 degrees Celsius in the whole joint of both angles, I tried to add / add 360 degrees to the current angle of the phantom. By jumping from -179 to 179 degrees to jump from 181 to 179, but it does not work.

  if (Math.Ebs ((float) anglegang) + Math. Float) current angle degree 180) {if (current angle deg <0) {currentAngleDeg + = 360.0f; } And {current Angledge- = 360.0F; }   

getTargetAngle:

  public float getTargetAngle (float RTX, float start, flap target x, float logic y) {float dX = targetX - startX; Float DJ = Target - - Start; Float angle rd = (float) monastery TAT2 (DY, DX); Float anglede = (float) monastery. Two grade (conrad); Return angle degree; The problem is that rotation is always relative to the axis orientation of the scene. The angle provided by the function getTargetAngle () should be in relation to the current rotation of the phantom.  

Please try the following,

Remove the add / subbing 360 ° code, then replace your getTargetAngle () function with the following,

  public Float getTargetAngle (float startX, float start, float start angle, flatty lexx, float logic y) {float dX = targetX - startX; Float DJ = Target - - Start; // The coordinates of the route were rotated almost with the // // in relation to the center of the sprat, so that phantom is pointing at 0 degree float cathode = Math (float) Math.cos (Math.toRadiians (-startAngle)). ; Float sin = (float) Math.sin (Math., Tudian (Steinenzell)); Float RotateddX = ((DX * cos) - (DY * sin); Float RotateddY = ((DX * sin) + (DI * cos)); // Now the angle between direction of direction is found, the phantom is pointing and // pathpoint float angle red = (float) Math.atan2 (RotateddY, RotateddX); Float anglede = (float) monastery. Two grade (conrad); Return angle degree; }   

Then when you reach the route,

  sprite.unregisterEntityModifier (rotMod); Float angleDeg = getTargetAngle (sprite.getX), sprite.getY (), sprite.getRotation (), target x [pWaypointIndex + 1], target y [pWaypointIndex + 1]); RotMod = New Rotation Modifier (0.5 F, Spread Gate Rotation ()), Spread Gate Rotation () + Angledge); Sprite.registerEntityModifier (rotMod);   

Note that the rotation modifier adds return value to the current sprite rotation from getTargetAngle () - it is now an angle in relation to the current angle.

Rotation is always in the direction of the angle & lt; = 180 ° Degree either clockwise or towards anticolv.

No comments:

Post a Comment