Thread

Coordinates Function (Sdk)

Coordinates Function // Sdk

1  |  

johnf

Feb 8, 2004, 11:15am
Hehe

~John
-----------------------------------------------------

Public Type type_Coordinates
Xcoord As Long
Ycoord As Long
Zcoord As Long
YAWcoord As Long
End Type
Global Xcoord As Long, Ycoord As Long, Zcoord As Long, YAWcoord As Long

Public Function Coordinates(ByVal CoordString As String) As type_Coordinates

Dim Va As Variant

If InStr(CoordString, " ") = 0 Then Exit Function
Va = Split(CoordString, " ")


If UBound(Va) = 1 Then CoordString = CoordString & " 0a"
If UBound(Va) = 2 Then CoordString = CoordString & " 0"
CoordString = CoordString & " 0"

Va = Split(CoordString, " ")

Dim TMP As String
TMP = CStr(Va(0))

If VBA.Right(TMP, 1) = "n" Then
Zcoord = Val(VBA.Left(TMP, Len(TMP) - 1)) * -1000
ElseIf VBA.Right(TMP, 1) = "s" Then
Zcoord = Val(VBA.Left(TMP, Len(TMP) - 1)) * 1000
End If

TMP = CStr(Va(1))

If VBA.Right(TMP, 1) = "e" Then
Xcoord = Val(VBA.Left(TMP, Len(TMP) - 1)) * -1000
ElseIf VBA.Right(TMP, 1) = "w" Then
Xcoord = Val(VBA.Left(TMP, Len(TMP) - 1)) * 1000
End If

Ycoord = Val(Va(2)) * 1000
YAWcoord = Val(Va(3)) * 10

With Coordinates
.Xcoord = Xcoord
.Ycoord = Ycoord
.Zcoord = Zcoord
.YAWcoord = YAWcoord
End With

End Function

Public Function StringCoords(ByVal X As Variant, ByVal Y As Variant, ByVal Z
As Variant, ByVal _
YAW As Variant) As String

Z = Val(Z) / 1000
Y = Val(Y) / 1000
X = Val(X) / 1000
YAW = Val(YAW) / 10

Dim TMPx As String, TMPy As String, TMPz As String, TMPyaw As String
If Z < 0 Then TMPz = -Z & "N" Else TMPz = Z & "S"
If X > 0 Then TMPx = X & "W" Else TMPx = -X & "E"
TMPy = Format(Y, "0.00") & "A"
TMPyaw = Format(YAW, "0.00")

StringCoords = TMPz & " " & TMPx & " " & TMPy & " " & TMPyaw
StringCoords = Replace(StringCoords, ".00", "")

End Function

ep0ch

Feb 9, 2004, 3:05am
Ah good. Does this one actually work correctly? the AW SDK Functions module
makes the y axis positive all the times...but now we need a working aw
coords to nsew coords. Maybe ill write one...

-Ep0ch

[View Quote]

ep0ch

Feb 9, 2004, 4:44am
Erm...just shoot me before i reply again alright?


[View Quote]

ep0ch

Feb 9, 2004, 5:05am
This code is reversed making it go south instead of north. Replace

If VBA.Right(TMP, 1) = "n" Then
Zcoord = Val(VBA.Left(TMP, Len(TMP) - 1)) * -1000
ElseIf VBA.Right(TMP, 1) = "s" Then
Zcoord = Val(VBA.Left(TMP, Len(TMP) - 1)) * 1000
End If

with

If VBA.Right(TMP, 1) = "n" Then
Zcoord = Val(VBA.Left(TMP, Len(TMP) - 1)) * 1000
ElseIf VBA.Right(TMP, 1) = "s" Then
Zcoord = Val(VBA.Left(TMP, Len(TMP) - 1)) * -1000
End If

otherwise a great module john. Im going to use it on my bot since the
conversion module i have now is broken. Thanks!

-Ep0ch
[View Quote]

ep0ch

Feb 9, 2004, 5:11am
Also
Ycoord = Val(Va(2)) * 1000
should be
Ycoord = Val(Va(2)) * 100

And
Y = Val(Y) / 1000
should be
Y = Val(Y) / 100

All the errors i see right now

-Ep0ch

[View Quote]

ep0ch

Feb 9, 2004, 5:23am
Another correction:

If Z < 0 Then TMPz = -Z & "N" Else TMPz = Z & "S"
needs to be changed to
If Z < 0 Then TMPz = -Z & "S" Else TMPz = Z & "N"

-Ep0ch
[View Quote]

johnf

Feb 9, 2004, 2:43pm
Uhh when tested this was all OK

~John

[View Quote]

johnf

Feb 9, 2004, 2:45pm
NM - you're correct, lol!

~John

[View Quote]

johnf

Feb 9, 2004, 2:47pm
Corrected:

~John

!-----------------------------------------------------!

Public Type type_Coordinates
Xcoord As Long
Ycoord As Long
Zcoord As Long
YAWcoord As Long
End Type
Global Xcoord As Long, Ycoord As Long, Zcoord As Long, YAWcoord As Long

Public Function coordinates(ByVal CoordString As String) As type_Coordinates

Dim Va As Variant

If InStr(CoordString, " ") = 0 Then Exit Function
Va = Split(CoordString, " ")


If UBound(Va) = 1 Then CoordString = CoordString & " 0a"
If UBound(Va) = 2 Then CoordString = CoordString & " 0"
CoordString = CoordString & " 0"

Va = Split(CoordString, " ")

Dim TMP As String
TMP = CStr(Va(0))

If VBA.Right(TMP, 1) = "n" Then
Zcoord = Val(VBA.Left(TMP, Len(TMP) - 1)) * 1000
ElseIf VBA.Right(TMP, 1) = "s" Then
Zcoord = Val(VBA.Left(TMP, Len(TMP) - 1)) * -1000
End If

TMP = CStr(Va(1))

If VBA.Right(TMP, 1) = "e" Then
Xcoord = Val(VBA.Left(TMP, Len(TMP) - 1)) * -1000
ElseIf VBA.Right(TMP, 1) = "w" Then
Xcoord = Val(VBA.Left(TMP, Len(TMP) - 1)) * 1000
End If

Ycoord = Val(Va(2)) * 1000
YAWcoord = Val(Va(3)) * 10

With coordinates
.Xcoord = Xcoord
.Ycoord = Ycoord
.Zcoord = Zcoord
.YAWcoord = YAWcoord
End With

End Function

Public Function StringCoords(ByVal X As Variant, ByVal Y As Variant, ByVal Z
As Variant, ByVal _
YAW As Variant) As String

Z = Val(Z) / 1000
Y = Val(Y) / 1000
X = Val(X) / 1000
YAW = Val(YAW) / 10

Dim TMPx As String, TMPy As String, TMPz As String, TMPyaw As String
If Z > 0 Then TMPz = Z & "N" Else TMPz = -Z & "S"
If X > 0 Then TMPx = X & "W" Else TMPx = -X & "E"
TMPy = Format(Y, "0.00") & "A"
TMPyaw = Format(YAW, "0.00")

StringCoords = TMPz & " " & TMPx & " " & TMPy & " " & TMPyaw
StringCoords = Replace(StringCoords, ".00", "")

End Function

[View Quote]

brant

Feb 9, 2004, 6:41pm
That's why I removed that module from the website :) This is great that
everyone's going open source so people won't keep relying on my code alone
so heavily - when it's open source, you can fix it :) The following
function is the one that I've actually been using recently. However, your
function seems to have fewer lines, but such a function is used so
infrequently that it's probably not worth comparing the two, as long as they
work correctly.

Of course, you can't test this function, because the Location class is not
yet available (someday I'll get around to that, as soon as I'm finished with
wasting hours implementing microinstructions on 1983 MIPS machines). Still,
I'd be interested if anyone feels like comparing the two and seeing if one
has some unforseen error that could cause problems down the line :)

-Brant

-----------------------------------

Public Function coordinates(ByVal stringToProcess As String) As Location
Dim returnValue as New Location(0,0,0,0,0,0)
Dim parts(3) As String, counter As Byte, position As Double,
coordinateMeasure As Integer
Dim northWest As Boolean

returnValue.Tilt = 0.0
returnValue.Roll = 0.0 'These values are irrelevant for avatar
locations

parts = Split(stringToProcess) 'Split string by spaces

For counter = 0 To parts.GetUpperBound(0)
parts(counter) = parts(counter).ToLower()

Next

position = InStr(parts(0), "s")
northWest = (position = 0.0)
If northWest Then position = InStr(parts(0), "n")
coordinateMeasure = CDbl(Left(parts(0), position)) * 1000
returnValue.Z = IIf(northWest, -coordinateMeasure,
coordinateMeasure)

position = InStr(parts(1), "e")
northWest = (position = 0.0)
If northWest Then position = InStr(parts(1), "w")
coordinateMeasure = CDbl(Left(parts(1), position)) * 1000
returnValue.X = IIf(northWest, -coordinateMeasure,
coordinateMeasure)

If parts.GetUpperBound(0) < 2 Then
returnValue.YAW = 0.0
returnValue.Y = 0.0
coordinates = returnValue
Exit Function
End If

position = InStr(parts(2), "a")
If position = 0 Then
returnValue.YAW = CDbl(parts(2))
coordinates = returnValue
Exit Function

End If

returnValue.Y = cDbl(Left(parts(2), position)) * 1000

If parts.GetUpperBound(0) < 3 Then
returnValue.YAW = 0.0
coordinates = returnValue
Exit Function
End If

returnValue.YAW = cDbl(parts(3))
coordinates = returnValue

End Function

-----------------------------

brant

Feb 9, 2004, 9:05pm
Another thing about this code that may or may not be a problem is that it
uses the Val() function. I myself made the mistake of using that function
extensively in programs up until recently.

The problem with that function is that it won't pay attention to
internationalization. In some countries, the decimal point is replaced with
a comma, so that in those countries "975,5n 975,5e 0.5a 0" would register an
error with the Val() function.

This problem can be fixed by using conversion functions such as CInt() or
CSng().

-Brant

[View Quote]

ep0ch

Feb 9, 2004, 10:04pm
Forgot to add the StringCoords modifications
[View Quote]

johnf

Feb 10, 2004, 9:52am
Uhh, no i didn't... :-o

~John

[View Quote]

ep0ch

Feb 10, 2004, 10:10pm
You forgot my Ycoord corrections as well as

If Z < 0 Then TMPz = -Z & "N" Else TMPz = Z & "S"
to
If Z < 0 Then TMPz = -Z & "S" Else TMPz = Z & "N"

[View Quote]

strike rapier

Feb 11, 2004, 5:13pm
NB: If your going to release code.. make sure it works first >_<

- Marky R

bowen

Feb 11, 2004, 8:16pm
[View Quote] I should hope you can fix it. Marky.

ep0ch

Feb 12, 2004, 12:44am
I brought the errors to john's attention, its his choice if he includes all
of the bugfixes i posted or not.

-Ep0ch

[View Quote]

1  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn