Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: matt on Sun 08/03/2009 09:27:41

Title: Complex maths
Post by: matt on Sun 08/03/2009 09:27:41
Hi all. I am currently making a game and I need to figure out a point from a start xy, a distance and an angle. Would anyone know how to do this.
cheers
Matt
Title: Re: Complex maths
Post by: Gilbert on Sun 08/03/2009 09:35:07
Assuming that the angle is anticlockwise from positive x-axis and you are using the normal cartesean coordinates (if it's computer screen coordinates the y has to be negated), the formulae are:
x=startx+dist*cos(angle)
y=starty+dist*sin(angle)
Title: Re: Complex maths
Post by: paolo on Tue 10/03/2009 13:00:00
Quote from: Gilbet V7000a on Sun 08/03/2009 09:35:07
(if it's computer screen coordinates the y has to be negated)

If you're working in screen coordinates, the above formulae require the angle to be measured clockwise; if you are measuring the angle anticlockwise, then you need these instead:

x = startx + dist * cos(angle)
y = starty - dist * sin(angle)

Additionally, you might need to convert the angle from degrees to radians (I don't remember whether AGS trigonometric functions work in radians or degrees). Look up "cos" or "sin" in the AGS manual to see if this is necessary. If so, then I think it explains there how to do the conversion.
Title: Re: Complex maths
Post by: Dualnames on Fri 13/03/2009 12:44:51
Probably might need an Abs function as well. I recall doing something similar and the scripting an Abs function came in really handy.
Title: Re: Complex maths
Post by: DoorKnobHandle on Fri 13/03/2009 14:53:37
Well, abs is really nothing more than:


float Math_Abs ( float value )
{
      if ( value < 0.0f )
            return -value;
      return value;
}


So it's very easy to work around which is probably the reason why it doesn't have much priority.

EDIT: Sorry, misunderstood your post there. :) (I could've sworn I was in the AGS next version feature suggestion thread).
Title: Re: Complex maths
Post by: Dualnames on Fri 13/03/2009 15:15:06
No harm done. Show off!!! :D :D :D