November 25, 2020, 05:37:20 AM

Author Topic: [bb] Rumble Beta 1a part 1/5 by Mikorians [ 1+ years ago ]  (Read 602 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Rumble Beta 1a part 1/5 by Mikorians [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : Rumble Beta 1a part 1/5
Author : Mikorians
Posted : 1+ years ago

Description : A force feedback rumble library by Todd Riggins aka: Pepsi.
I have included the .dll file and a slight modification to include a polar coordinate axis usage example as he requested.
This has been done since the links to it keep going dead.


Code :
Code: BlitzBasic
  1. ; DirectX7 Rumble Dll - BY: Todd Riggins aka: Pepsi - FREEWARE
  2. ; Demo #3 - Dynamic FFB Effect! Left mouse button in box area to change effect!
  3. ; Updated for polar coordinates by Mikorians - 2014
  4.  
  5. Global swidth=800
  6. Global sheight=600
  7. Graphics swidth,sheight,0,2
  8. SetBuffer BackBuffer()
  9.  
  10. ; Init DLL
  11. di7=SystemProperty$("DirectInput7")
  12. hwnd=SystemProperty$("AppHWND")
  13. DX7RUMBLE_INIT%(hwnd, di7, 1)
  14.  
  15. ; Get Number of Game Devices
  16. Global totalgamedevices=TOTAL_GAMEDEVICES%()
  17.  
  18. For j=0 To (totalgamedevices-1)
  19.         FFB_AUTOCENTER%(j,0)
  20. Next
  21.  
  22. Global customeffect1=CREATE_EFFECT%()
  23. SET_EFFECT_SAMPLEPERIOD(customeffect1,0)
  24. SET_EFFECT_AXES(customeffect1,2,1,0,0)
  25. SET_EFFECT_DURATION(customeffect1,0,1)
  26. SET_EFFECT_GAIN(customeffect1,10000)
  27. SET_EFFECT_CONSTANTFORCE(customeffect1,0,0)
  28. For j=0 To (totalgamedevices-1)
  29.                 If FFB_AVAIL%(j)
  30.                         If ATTACH_EFFECT%(j,customeffect1)=0
  31.                                 ;;RuntimeError "Failed: Effect unable to attach to game device!"
  32.                         Else
  33.                
  34.                         ; HAS_EFFECT_SUPPORT and HAS_DYNAMIC_EFFECT_SUPPORT will write there results in the
  35.                         ; DX7Rumble_debug.txt file if you have the last parameter set to true of the DX7RUMBLE_INIT command.
  36.                         For i=0 To 6
  37.                                 HAS_EFFECT_SUPPORT%(j,customeffect1,i)
  38.                         Next           
  39.                         For i=0 To 6
  40.                                 HAS_DYNAMIC_EFFECT_SUPPORT%(j,customeffect1,i)
  41.                         Next           
  42.                 EndIf
  43.         EndIf
  44. Next
  45.  
  46.  
  47. ; Variables applied to change ffb during runtime
  48. Global gXForce=0
  49. Global gYForce=0
  50.  
  51. MoveMouse swidth/2,sheight/2
  52.  
  53. ; Red dot will move to mouse position inside the box area
  54. ; Further away from the center of the box, the stronger the FFB effect!
  55. Global dotx=swidth/2
  56. Global doty=sheight/2
  57.  
  58.  
  59. Global magnitude=0
  60. PLAY_EFFECT%(customeffect1) ; Constant force magnitude is set to zero so playing the initial effect here you wont feel anything.
  61. ; the gXForce,gYForce vars will change during runtime, then will update the magnitude of the constant force, then will
  62. ; get updated by the UPDATE_EFFECT command where then you will feel the FFB " rumble " change.
  63.  
  64. ;Blitz3d Blue
  65. ClsColor 34,85,119
  66. While Not KeyDown(1)
  67.  
  68.         ; Poll for Game Device(s) updated info
  69.         DX7RUMBLE_POLL()
  70.         Cls
  71.        
  72.         ; Crosshair marks the center
  73.         Color 0,0,0
  74.         Line swidth/2-25+1,sheight/2+1,swidth/2+25+1,sheight/2+1
  75.         Line swidth/2+1,sheight/2-25+1,swidth/2+1,sheight/2+25+1
  76.         Color 255,255,255
  77.         Line swidth/2-25,sheight/2,swidth/2+25,sheight/2
  78.         Line swidth/2,sheight/2-25,swidth/2,sheight/2+25
  79.         ; Draw Box (boundry to keep dot in)
  80.         Color 0,0,0
  81.         Rect swidth/2-100+1,sheight/2-100+1,200,200,0
  82.         Color 0,255,255
  83.         Rect swidth/2-100,sheight/2-100,200,200,0
  84.         ; Draw Dot
  85.         Color 0,0,0
  86.         Oval dotx+2-6,doty+2-6,12,12,1
  87.         Color 255,0,0
  88.         Oval dotx-6,doty-6,12,12,1
  89.        
  90.        
  91.         ; Text Info
  92.         Color 0,255,0  
  93.         Text 0,0,"; DirectX7 Rumble Dll - BY: Todd Riggins aka: Pepsi - FREEWARE"
  94.         Text 0,15,"; Demo #3 - Dynamic FFB Effect! Left mouse button in box area to change effect! Press Escape to Exit!"
  95.        
  96.         Color 255,255,255      
  97.         For j=0 To (totalgamedevices-1)
  98.                 ; Print Game Device Name on Screen
  99.                 Text 0,45+(j*60),"("+Str$(j)+") "+GAMEDEVICE_NAME$(j)
  100.                
  101.                 ; Dynamically change effect during runtime!
  102.                 If FFB_AVAIL%(j)
  103.                         Text 0,60+(j*60),"Force FeedBack IS Available - magnitude="+Str$(magnitude*100)
  104.                         SetJoyForcesXY()
  105.                 Else
  106.                         Text 0,60+(j*60),"Force FeedBack NOT Available"
  107.                         Text 0,75+(j*60),"No Effect Will Play!"
  108.                 EndIf
  109.         Next
  110.        
  111.         Flip
  112. Wend
  113.  
  114. STOP_EFFECT%(customeffect1)
  115. ; Release Dll's Aquired Memory!
  116. DX7RUMBLE_RELEASE()
  117. End
  118.  
  119.  
  120. ; Apply updated forces
  121. Function SetJoyForcesXY()
  122.         ; Get changed values
  123.         If MouseX()>swidth/2-100
  124.                 If MouseX()<swidth/2+100
  125.                         If MouseY()>sheight/2-100
  126.                                 If MouseY()<sheight/2+100
  127.                                         If MouseDown(1)
  128.                                                 dotx=MouseX()
  129.                                                 doty=MouseY()
  130.                                                 gXForce=dotx-swidth/2
  131.                                                 gYForce=doty-sheight/2
  132.  
  133.         ; Modifying an effect is like creating a new one, but here
  134.         ; you only need to specify the parameters you are modifying...
  135.         CLEAR_EFFECT(customeffect1) ; ie: zero it out
  136.        
  137.         ;If you need an adapter for your Microsoft Sidewinder or
  138.         ;Microsoft Force Feedback 15pin to USB, search on Google
  139.         ;for Teensy-based adapters, there are now purchasable,
  140.         ;fully-assembled and tested units available (no drivers
  141.         ;required) from:
  142.         ;https://docs.google.com/forms/d/1D4Kc8dtIO80csKkV4HTwlzH7I3SAGXPGtU17d6zaDcg/viewform
  143.         ;Reference:http://code.google.com/p/adapt-ffb-joy/wiki/HowToBuild
  144.         ;(May not work with Windows 8)
  145.        
  146.         ;Cartesian Coordinates Example:
  147.         ;SET_EFFECT_AXES(customeffect1,2,1,gXForce,gYForce)
  148.         ;Polar Coordinates Example
  149.         Ang=Rec2Pol(dotx,doty,swidth*.5,sheight*.5)*100
  150.         SET_EFFECT_AXES(customeffect1,2,0,Ang,0)
  151.         magnitude=Sqr((gXForce*gXForce)+(gYForce*gYForce))
  152.         If magnitude>100 Then magnitude=100
  153.         If magnitude<10 Then magnitude=0
  154.         SET_EFFECT_CONSTANTFORCE(customeffect1,0,magnitude*100)
  155.         UPDATE_EFFECT%(customeffect1,1,0,1,0,0,0,0,0)
  156.                                                
  157.                                         EndIf
  158.                                 EndIf
  159.                         EndIf
  160.                 EndIf
  161.         EndIf
  162. End Function
  163.  
  164. Function Rec2Pol#(X1#,Y1#,X2#,Y2#)
  165. C# = 3.141592654 / 180
  166. OX# = X2# - X1#: OY# = Y2# - Y1#:R# = Sqr((OX# ^ 2) + (OY# ^ 2))
  167. If Sgn(OX#)=0 And Sgn(OY#)=0 Then Ret#=0:Goto XitR
  168. If OX<0 And OY<0 Then QT=180
  169. If OX<0 And OY>0 Then QT=180
  170. If OX=0 And OY>0 Then Ret#=0:Goto XitR
  171. If OX>0 And OY=0 Then Ret#=90:Goto XitR
  172. If OX=0 And OY<0 Then Ret#=180:Goto XitR
  173. If OX<0 And OY=0 Then Ret#=270:Goto XitR
  174. Ret# = 90-ATan((OY / R#) / (OX# / R#))+QT
  175. .XitR
  176. Return Ret#
  177. End Function
  178.  
  179. TO OBTAIN THE ENTIRE ARCHIVE INCLUDING THE .DLL FILE, YOU'LL NEED TO USE THIS PROGRAM
  180. TO EXTRACT THE RELEVANT RAR FILE.
  181.  
  182. ;HEXREAD
  183. o=0:fl=0:ck%=0:pre_ck%=0:mck%=0
  184. MyPath$="."
  185. NM$="rarfile.hex"
  186. FileIn=ReadFile(NM$)
  187. NM$=ReadLine(FileIn)
  188. FileOut=WriteFile(MyPath$+NM$)
  189. ck%=ReadLine(FileIn)
  190. While Not Eof(FileIn)
  191. ReadIn$=ReadLine(FileIn)
  192. If ReadIn$<>"" Then
  193. o=0:For t=1 To Len(ReadIn$) Step 2
  194. Nib1$=Mid$(ReadIn$,t+0,1)
  195. Nib2$=Mid$(ReadIn$,t+1,1)
  196. N1=Instr("0123456789ABCDEF",Nib1$)-1
  197. N2=Instr("0123456789ABCDEF",Nib2$)-1
  198. Byt=(N1*16)+N2
  199. pre_ck%=pre_ck%+(Byt*(256^o)) ;Build 8 byte value
  200. o=o+1:If o>3 Then o=0:mck%=mck%+pre_ck%:pre_ck%=0 ;Checksumming
  201. WriteByte(FileOut,Byt)
  202. Next
  203. End If
  204. Wend
  205. CloseFile(FileOut)
  206. CloseFile(FileIn)
  207. If mck%<>ck% Then RuntimeError "Warning: Checksums did not match!"


Comments :


degac(Posted 1+ years ago)

 Question: do you know there are many free service to host files?Dropbox, Mega, Box and so on...


RGR(Posted 1+ years ago)

 Do you really believe that the way you provide these programms is accepted by many users? I usualy try every new entry in the code archives ... if I see your bulk of Hexnumbers, look into the code and see that its not an easy load and run thing I just ignore it ... maybe I am the only one. But I doubt that.In my view this way of providing software and objects(?) spoils the code archive ...Don't get me wrong. Your intention and effort is great ... its just the wrong way to do it ...


RustyKristi(Posted 1+ years ago)

 I think this is a good idea and another way of preserving great code. I was spending my time browsing the archives for the last few days and apparently some of the links with zip/rar archives are already broken and have not been updated or brought back for archiving. The main intention here is making sure his or other author's code will be available the same as the server hosting this site.Kudos to you Mikorians and thank you for this resource!Rusty


GW(Posted 1+ years ago)

 I agree, the Code archives are loaded with broken links resulting in useless posts.  This method isn't ideal, but its better than broken links and vanishing authors.


Rick Nasher(Posted 1+ years ago)

 So true. There are loads of broken links here. Those file hosting sites are never permanent enough, so I think this is a good compromise. A pity BRL doesn't provide a space for uploading files such as dll's and rights free media, but I can understand as the security/monitoring can be quite a hassle of course.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal