Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Development > Archive::Database/World Building

Archive::Database/World Building Archive area for General Discussion's posts that were moved here after an inactivity period of 90 days.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #11  
Old 06-07-2003, 06:48 AM
Lurker_005
Demi-God
 
Join Date: Jan 2002
Location: Tourist town USA
Posts: 1,671
Default

Forgot, heading is actually a float value

Since I was working in VBScript and it neglected a DecToFloat function here is what I made...

Code:
Function DecToFloat(heading)
	Dim headbin, headtmp, binexptmp, binexp, headfloat, i
			'			Convert to decimal representation of first 16 bits of a float
			headtmp=CSng(heading)
			i=512
			headbin=""
			' get whole part of number into bin-string
			Do While i >=1
				If headtmp >= i Then
					headbin=headbin & "1"
					headtmp=headtmp-i
				Else
					headbin=headbin & "0"
				End If
				i=i/2
			Loop
			
'			MsgBox headtmp & ", " & headbin     
			' add fractional part of number to the string 
			If headtmp <> 0 Then
				headbin=headbin & "."
				i=2
				Do While i <=256
					If headtmp >= 1/i Then
						headbin=headbin & "1"
						headtmp=headtmp-1/i
					Else
						headbin=headbin & "0"
					End If
					i=i*2
				Loop
			End If
'			MsgBox headbin & ", " & headtmp      
			
			' Treat the bin number as a regular number and set to 1.xxx format
			headbin=CDbl(headbin)
				i=0
			If headbin >=1 Then
				Do While headbin > 2
					headbin=headbin/10
					i=i+1
				Loop
			ElseIf headbin > 0 Then
				' already in 1.xxx or smaller
				Do While headbin <1
					headbin=headbin*10
					i=i+1
				Loop
			End If
			' make headtmp a bin-string of the F part of the float
			headtmp=""
			binexptmp=i+127
			headbin=headbin-1
'			MsgBox headbin & ", " & binexptmp      
			i=-1
			Do While i > -8
				If headbin>=10^i Then
					headtmp=headtmp & "1"
					headbin=headbin-10^i
				Else
					headtmp=headtmp & "0"
				End If
				i=i-1
			Loop
'			MsgBox headbin & ", " & headtmp      
			
			' turn binexptmp into the exp in bin-string format
			i=128
			binexp=""
			Do While i >=1
				If binexptmp >= i Then
					binexp=binexp & "1"
					binexptmp=binexptmp-i
				Else
					binexp=binexp & "0"
				End If
				i=i/2
			Loop
			
			headfloat=CDbl(binexp & headtmp) ' concentrate E and F together s is always 0 so dosen't matter
'			MsgBox "0 " & binexp & ", " & headtmp & vbCRLF & headfloat     
			'convert the bin number to a decimal for EQEmu
			i=14
			heading=0
			Do While i >=0
				If headfloat >= 10^i Then
					heading=heading+2^i
					headfloat=headfloat-10^i
				End If
				i=i-1
			Loop
			

	DecToFloat=heading
End Function
__________________
Please read the forum rules and look at reacent messages before posting.
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 04:23 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3