[Gambas-user] angle interpolation algorithm troubles

Randall Morgan rmorgan62 at ...626...
Fri Feb 17 07:11:25 CET 2012


Try a little conditional:

if abs(a1 - a2) > 180 then rotate counter clockwise
else rotate clockwise

I think this will work try it and see...



On Thu, Feb 16, 2012 at 9:08 PM, Kevin Fishburne <
kevinfishburne at ...1887...> wrote:

> Apparently I'm too much of a dummy to figure this out. I have two
> singles representing orientation in degrees, let's say Angle1 and
> Angle2. I need to continually increment one (let's say Angle1) until
> it's close to the value of the other (Angle2), but in the direction of
> the shortest distance between the two angles.
>
> So if Angle1 = 10 and Angle2 = 350, Angle1 should be repeatedly
> decremented, wrapping around the upper limit of 360 (10, 5, 0, 355,
> 350). If Angle1 was 350 and Angle2 was 20, Angle1 would be incremented
> like 350, 355, 0, 5, 10, 15, 20. I have a crude function to wrap a
> number which may be of use:
>
> Public Function Wrap_Single(Minimum As Single, Maximum As Single, Value
> As Single) As Single
>
>   ' Constrain value to specified range.
>
>   ' General declarations.
>   Dim Spread As Single = Maximum - Minimum + 1  ' Range between minimum
> and maximum values.
>
>   ' Wrap if value is too large.
>   If Value > Maximum Then
>     Do
>       Value = Value - Spread
>     Loop Until Value <= Maximum
>   Endif
>
>   ' Wrap if value is too small.
>   If Value < Minimum Then
>     Do
>       Value = Value + Spread
>     Loop Until Value >= Minimum
>   Endif
>
>   ' Return wrapped value.
>   Return Value
>
> End
>
> This is my current code, which works except the Distance variable isn't
> doing its job:
>
> ' Check if camera orientation is locked to client player orientation.
> If Camera.Locked Then
>   ' Check if difference in orientations exceeds interpolation threshold.
>   Distance = Abs(Camera.Orientation -
> Client.Player[Client.Number].Orientation)
>   If Distance >= 5.625 Then
>     ' Move camera orientation closer to player orientation (interpolate).
>     If Camera.Orientation - Client.Player[Client.Number].Orientation <
> Client.Player[Client.Number].Orientation - Camera.Orientation Then
>       Camera.Orientation = Convert.Wrap_Single(0, 359,
> Camera.Orientation + 0.1 * Distance)
>     Else
>       Camera.Orientation = Convert.Wrap_Single(0, 359,
> Camera.Orientation - 0.1 * Distance)
>     Endif
>   Endif
> Endif
>
> My instinct tells me I'm almost there but am missing one critical thing.
> If someone smarter than myself instantly sees my mistake please let me
> know. :)
>
> --
> Kevin Fishburne
> Eight Virtues
> www: http://sales.eightvirtues.com
> e-mail: sales at ...1887...
> phone: (770) 853-6271
>
>
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



-- 
If you ask me if it can be done. The answer is YES, it can always be done.
The correct questions however are... What will it cost, and how long will
it take?



More information about the User mailing list