taultunleashed logoNeed help with math function : VGExtreme General Discussion
newtopic  postreply
 [ 3 posts ] 
blue large dot

Need help with math function : VGExtreme General Discussion

Posted: April 6th, 2007, 6:48 pm
 
slam666

Total Posts: 1184
Location: Quebec, Canada
Joined: April 21st, 2005, 7:30 am
slam666's Reps: 1
User avatar
Moderator
premium
Hi,

I need some help with a math function to calculate the angle to a point (x,y)

Here is my function from EQ2 but it does not seem to work in VG. Any help will be appreciated.
If I call CalcTargetAngle(x, y) I get an angle but its not right.

Thanks.

==============================
Function CalculateAngle(dx, dy, dis)
Dim tmpFloat

'objDebug.Print "In CalculateAngle(" & dx & ", " & dy & ", " & dis & ")", 2
if dis=0 then
'objDebug.Print "***WARNING: dis=0 - can't calculate angle", 0
CalculateAngle=0
exit Function
end if

tmpFloat = ArcSin(Abs(dx) / Abs(dis))

if (dx >= 0) and (dy >= 0) then
' Do nothing to tmpFloat
end if
if (dx >= 0) and (dy < 0) then
tmpFloat = PI - tmpFloat
end if
if (dx < 0) and (dy < 0) then
tmpFloat = PI + tmpFloat
end if
if (dx <0>= 0) then
tmpFloat = (2 * PI) - tmpFloat
end if

CalculateAngle = Round(tmpFloat * (180 / PI))
end Function
===============================
Function CalcTargetAngle(x, y)
Dim dx, dy, dis

dx = (-x) - (-getPlayerX())
dy = (-y) - (-getPlayerY())

dis = Sqr(dx*dx + dy*dy)
'dis = Round(Sqr(dx*dx + dy*dy))

' Return Angle
CalcTargetAngle=CalculateAngle(dx, dy, dis)
end Function

_________________
Slam666

Author of EQ2Ultrabot, NOW WITH CRAFTING!!!
Read this before asking for help


Reply with quote
Posted: April 6th, 2007, 7:54 pm
 
gheezer
gheezer's Reps:
User avatar
It looks like you need to add a 90 degree offset to the result. Also, this function returns the absolute angle, not the relative angle if thats what your looking for.

This is what I use to calculate absolute angle:

(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
Function CalcAbsAngleToXY(x, y)
    Dim mh
    Dim dx, dy
    Dim lAngle

    dx = CDbl(x - getPlayerX)
    dy = CDbl(y - getPlayerY)
 
    If dx = 0 Then
        If dy = 0 Then
            mh = 0
        ElseIf dy > 0 Then
            mh = PI/2.0
        Else
            mh = PI*3.0/2.0
        End If
    ElseIf dy = 0 Then
        If dx < 0 Then
            mh = 0
        Else
            mh = PI
        End If
    Else
        If dx < 0 Then
            mh = atn(dy/dx) + PI
        ElseIf dy < 0 Then
            mh = atn(dy/dx) + 2.0*PI
        Else
            mh = atn(dy/dx)
        End If           
    End If

    mh = ((mh * 180.0 / PI) + 90) Mod 360

    CalcAbsAngleToXY = mh
End Function


Reply with quote
Posted: April 7th, 2007, 5:52 am
 
slam666

Total Posts: 1184
Location: Quebec, Canada
Joined: April 21st, 2005, 7:30 am
slam666's Reps: 1
User avatar
Moderator
premium
Gheezer (!empty($user->lang['WROTE'])) ? $user->lang['WROTE'] : ucwords(strtolower(str_replace('_', ' ', 'WROTE'))):
It looks like you need to add a 90 degree offset to the result. Also, this function returns the absolute angle, not the relative angle if thats what your looking for.

This is what I use to calculate absolute angle:

(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
Function CalcAbsAngleToXY(x, y)
    Dim mh
    Dim dx, dy
    Dim lAngle

    dx = CDbl(x - getPlayerX)
    dy = CDbl(y - getPlayerY)
 
    If dx = 0 Then
        If dy = 0 Then
            mh = 0
        ElseIf dy > 0 Then
            mh = PI/2.0
        Else
            mh = PI*3.0/2.0
        End If
    ElseIf dy = 0 Then
        If dx < 0 Then
            mh = 0
        Else
            mh = PI
        End If
    Else
        If dx < 0 Then
            mh = atn(dy/dx) + PI
        ElseIf dy < 0 Then
            mh = atn(dy/dx) + 2.0*PI
        Else
            mh = atn(dy/dx)
        End If           
    End If

    mh = ((mh * 180.0 / PI) + 90) Mod 360

    CalcAbsAngleToXY = mh
End Function


Thanks Gheezer, work like a charm.

_________________
Slam666

Author of EQ2Ultrabot, NOW WITH CRAFTING!!!
Read this before asking for help


Reply with quote
Want Advertisements After The Last Post Removed? Create A Free Account!

blue large dot Who is online
Users browsing this forum: No registered users and 37 guests

cron
Popular Sections
SWTOR Cheats
Guild Wars 2 Cheats
Guild Wars 2 Hacks
Guild Wars 2 Bots
Diablo 3 Cheats
Guild Wars 2 Mods

Popular Sections
WoW Cataclysm Cheats & Exploits
WoW Cataclysm Hacks & Bots
Star Wars The Old Republic Cheats
SWTOR Mods
Torchlight 2 Cheats
SWTOR Space Mission Bots
Site Nav and RSS
RSS Feed of VGExtreme General Discussion RSS Feed 
Sitemap of VGExtreme General Discussion Sitemap 
SitemapIndex SitemapIndex
RSS Feed RSS Feed
Channel list Channel list
left bottom corner Site and Contents Copyright 2001-2012 All Rights Reserved TaultUnleashed.com bottom corner
top left
top right
createaccount
Username:   Password:   Remember Me?