ATAN2 is needed

Previous topic - Next topic

MrTAToad

GLBasic at the moment doesn't recognise the command...

Moru


Schranz0r

That's right!  :good:
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

MrTAToad

#3
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

WPShadow

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

Kitty Hello


Schranz0r

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 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard