Friday 15 June 2012

c++ - Inbetweening a rotation -


I have an image (say this is a simple rectangle) on the left side of my screen, which I I can go and down. While moving it forward, I use a few simple trigonometry to simplify it so that the rectangular "digit" in the top right corner of the screen. While walking downwards, it indicates in the lower left corner of the screen.

Given that my application uses the following coordinate system: coordinate system < / P>

I use the following code to get the rotation:

  // rotation moves upwards = -tech2 (position.y, Res.x - Position.x)); // rotation rotation below = atan 2 (ridge position - position y, res.x - position.x));   

Where res is the reference point and position is our rectangle image position (upper left corner) ( atan2 () for information on).

It works just fine: it rotates more when it is away from the reference point (res). However, suppose that the bottom of the screen screen has an image. If we take it upwards, then it will rotate very suddenly I would like to 'inbit' in this rotation so that it is pushed out.

What I mean by suddenly walking: Suppose that the rectangle is not running in the frame n: so its rotation is 0 degree. I then press the up arrow, Calculates the frame in N + 1, angle is 30 degrees (for example) it is not exactly smooth at all.

Is my question clear? How can you go about this?

You can constantly change the angle on each frame for very "smooth" rotation effect, you

  target_angle = ... current_angle + = (target_angle - current_angle) can be used * smoothing_factor   

where scotting_factor Returns the rate at which current_angle should be centered on target_angle . For example, the value of 1 will be instantaneous, the value of 0.1 will probably give a smooth effect

By doing so, you may have to face the wrapping issue, which would be as wrong as going from 10 degrees to 350 degrees Ways to go the way. In this case, use

  target_angle = ... current_angle + = diff (target_angle, current_angle) * smoothing_factor   

where < Pre> diff (a, b) {return atan2 (sin (a - b), cos (a - b))}

This is taken from the good angle differential formula

No comments:

Post a Comment