Author Topic: ATAN2 is needed  (Read 4010 times)

MrTAToad

  • Guest
ATAN2 is needed
« on: 2009-Jan-22 »
GLBasic at the moment doesn't recognise the command...

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1786
    • View Profile
    • Homepage
Re: ATAN2 is needed
« Reply #1 on: 2009-Jan-22 »
ATAN = ATAN2

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5035
  • O Rly?
    • View Profile
Re: ATAN2 is needed
« Reply #2 on: 2009-Jan-22 »
That's right!  :good:
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

MrTAToad

  • Guest
Re: ATAN2 is needed
« Reply #3 on: 2009-Jan-22 »
Should have noticed that :)

The angle between points is correct now (up is 270 degrees) :

Code: (glbasic) [Select]
FUNCTION angleBetweenPoints:ax,ay,ex,ey
LOCAL angle

angle=ATAN(ey-ay,ex-ax)
IF angle<0.0
angle=180.0+(180.0+angle)
ENDIF

RETURN angle
ENDFUNCTION
« Last Edit: 2009-Jan-22 by MrTAToad »

Offline WPShadow

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1667
    • View Profile
    • http://lostrevenant.blogspot.com
Re: ATAN2 is needed
« Reply #4 on: 2009-Jan-29 »
is it the same with x & z?

Code: (glbasic) [Select]
angle=ATAN(ez-az,ex-ax)

To use the 2 angles together for (x, y, z) <--> (ax, ay, az)
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10732
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: ATAN2 is needed
« Reply #5 on: 2009-Jan-29 »
Yes, indeed.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5035
  • O Rly?
    • View Profile
Re: ATAN2 is needed
« Reply #6 on: 2009-Jan-29 »
thats simple :D

Code: (glbasic) [Select]
DRAWRECT 0,0,20,20, RGB(0xff, 0x00, 0x00)
DRAWRECT 0,10,10,1, RGB(0x00, 0x00, 0x00)
GRABSPRITE 1, 0,0,20,20
BLACKSCREEN


TYPE TPlayer
x%;y%
angle#
lookat_handle% = -1
ENDTYPE

GLOBAL TPlayers[] AS TPlayer

LOCAL Player1 = CreatePlayer(20,20)
LOCAL Player2 = CreatePlayer(100,100)

PlayerLookAt(Player1,Player2)

WHILE TRUE


DrawAll()
SHOWSCREEN
WEND
END



FUNCTION CreatePlayer%: x, y
LOCAL t AS TPlayer

t.x = x
t.y = y

DIMPUSH TPlayers[], t
RETURN LEN(TPlayers[])-1
ENDFUNCTION

FUNCTION PlayerLookAt: player, target
TPlayers[player].lookat_handle = target
ENDFUNCTION


FUNCTION DrawAll:
FOREACH t IN TPlayers[]
IF t.lookat_handle > -1
t.angle = 180-ATAN(TPlayers[t.lookat_handle].y - t.y,  TPlayers[t.lookat_handle].x - t.x)
ENDIF

ROTOSPRITE 1, t.x, t.y, t.angle

NEXT
ENDFUNCTION
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard