[Gambas-user] translating planar coordinates relative to point's angle

Kevin Fishburne kevinfishburne at ...1887...
Mon Mar 14 08:18:20 CET 2011


On 03/14/2011 02:13 AM, Kevin Fishburne wrote:
> I'm trying to move a point with an angle/direction/vector relative to
> its angle. Let's say I have these variables:
>
> Dim a as Single ' Point's angle in degrees.
> Dim x as Single ' Point's x coordinate.
> Dim y as Single ' Point's y coordinate.
> Dim xvel as Single ' Point's right/left velocity (+/-).
> Dim yvel as Single ' Point's backward/forward velocity (+/-).
>
> What's a good algorithm to figure out the new values of x and y when
> adjusted by xvel and yvel relative to a?

After more research I got a little closer, trying this:

' Move player relative to player's orientation.
worldx = worldx + ((Interface.stick_leftx / 131072) * Cos(Rad(orientation)))
worldy = worldy + ((Interface.stick_lefty / 131072) * Sin(Rad(orientation)))

It lets me move horizontally but not vertically unless I rotate the 
player. What am I doing wrong here?

FYI, the Interface.stick_left variables are divided by 131072 so that 
they are compressed from the range +/- 32768 to +/- 0.25, the maximum 
movement speed for testing. I feel I'm so very close, yet so very far.

-- 
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...1887...
phone: (770) 853-6271





More information about the User mailing list