| |
|
|
Sven Bader | Hello!
really a Basisfunktion in the Spieleentwicklung: ArcTan2 or atan2 (php/js). herewith can itself the Winkel between two Points, detect circa so z.B. a opponent in direction player look or walk To let.
I have me something gewundert, I no correspondence in Profan found have, evtl. have I it only overlooking?
its letztendlich The ArcTan function with of/ one quadrants-request. it would me forward, if The function whom lane in Profane or The math.inc find would.
In of/ one second function, I name tappt im dunkeln Arctan4, take so did i yet The Berechnung the Vektoren and the Conversion of Bogenmaß in strain ex.
as Abfallprodukt has the code yet Profan-Icons as OpenGL Textur.
Download
Windowtitle "ArcTan2, ArcTan4 and Icon Texturen"
windowstyle 1+4+8+16
window (%maxx * 0.5 - 200), (%maxy * 0.5 - 150) - 400,300'kompatible spelling
Declare tex&, hPic&, zrot!, oglX&, oglY&
oGL("init",%hWnd,1,1,1,0)
oGL("posmode",1)
'Texture from Icons
Mcls 32,32
startpaint -1
DrawIcon "GESICHT", 0,0
endpaint
hPic&=create("HPIC",0,"&MEMBMP")
tex&=ogl("getTextureBmp",hPic&,1)
DeleteObject hPic&
'from math.inc
Proc wheel2Deg
Parameters Angle!
Return (180 / Pi()) * Angle!
ENDPROC
Proc ArcTan2
'Winkel from position form
'If Objekt 1 To Objekt 2 look should, is the Winkel this:
'ArcTan2(x1 - x2, y1 - y2)
'around the Bogenmaß in strain umzuwandeln can ArcTan2 uses go
Parameters x!, y!
Declare result!
if (y! > 0.0)
result! = ArcTan(x!/y!)
elseif (y! < 0.0) & (x! >= 0.0)
result! = ArcTan(x!/y!) + Pi()
elseif (y! < 0.0) & (x! < 0.0)
result! = ArcTan(x!/y!) - Pi()
elseif (y! = 0.0) & (x! > 0.0)
result! = Pi() / 2.0
elseif (y! = 0.0) & (x! < 0.0)
result! = 0.0 - (Pi() / 2.0 )
elseif (y! = 0.0) & (x! = 0.0)
'no stood off, no direction, can with want abgefangen go
result! = -1000
endif
Return result!
ENDPROC
Proc ArcTan4
'ArcTan4: an Neuschöpfung -) everything in a inklusive performance Tweaks
'The Vektoren must not self accounts go, it go
'just two spots transfer, the Result is already in strain
Parameters x1!, y1!, x2!, y2!
Declare result!, x!, y!
x! = x1! - x2!
y! = y1! - y2!
if (y! > 0.0)
result! = ArcTan(x!/y!) * 57.2957795131
elseif (y! < 0.0) & (x! >= 0.0)
result! = (ArcTan(x!/y!) + 3.1415926535897932) * 57.2957795131
elseif (y! < 0.0) & (x! < 0.0)
result! = (ArcTan(x!/y!) - 3.1415926535897932) * 57.2957795131
elseif (y! = 0.0) & (x! > 0.0)
result! = 1.57079632679 * 57.2957795131
elseif (y! = 0.0) & (x! < 0.0)
result! = -1.57079632679 * 57.2957795131
elseif (y! = 0.0) & (x! = 0.0)
'no stood off, no direction, can with want abgefangen go
result! = -1000
endif
Return result!
ENDPROC
While isKey(27) = 0
sleep 10
oGL("clear")
oGL("move",0,0,-2)
'Mittelpunkt the Gesichts
oGL("2D", 0, 0, -2, oglX&, oglY&)
'the face (oglX&, oglY&) schaut to Mausposition (%mousex, %mousey)
'zRot! = wheel2deg(ArcTan2(%mousex - oglX&, %mousey - oglY&))
'or
zRot! =ArcTan4(%mousex, %mousey, oglX&, oglY&)
oGL("rotate",0,0,zRot!)
oGL("texture",1,1)
oGL("quad",1,1)
oGL("show")
EndWhile
|
|
|
| |
|
|
|
p.specht
| without Berücksichtigung of oGL there were time one Snippet moreover: [...] |
|
|
| XProfan 11Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'... | 08/11/21 ▲ |
|
|
|
|
Sven Bader | After atan and arctan have I sought, to "arcus" not your Posting is even right new.
i'd Yes a C++ DLL of these Things make but erfahrungsgemäß cost the DLL appeal so plenty Time How one by the faster process won had. |
|
|
| |
|
|