English
Source / code snippets

ArcTan2, atan2 "In direction schauen" (+Icons as OpenGL Textures)

 

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


9 kB
Bezeichnung:ArcTan2 OpenGL
Hochgeladen:08/11/21
Downloadcounter63
Download
99 kB
Bezeichnung:Programm als EXE
Hochgeladen:08/11/21
Downloadcounter67
Download
 
08/11/21  
 




p.specht

without Berücksichtigung of oGL there were time one Snippet moreover: [...] 
 
XProfan 11
Computer: 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.
 
08/11/21  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

2.498 Views

Untitledvor 0 min.
H.Brill06/04/24
Sven Bader08/05/23
Ernst05/29/22
p.specht11/18/21
More...

Themeninformationen

this Topic has 2 subscriber:

Sven Bader (2x)
p.specht (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie