 |
WiiLi.org a new revolution
|
| View previous topic :: View next topic |
| Author |
Message |
Dr_Zoidberg
Joined: 29 Dec 2006 Posts: 60
Digg It |
Posted: Thu Mar 01, 2007 10:07 pm Post subject: new FPS IR script using directinput |
|
|
Hi!
This is the current beta version of my FPS IR script. It is similar to the type of fps control on the wii, where the view changes as you point towards the edge of the screen.
Tilting the wiimote doesn't affect the direction of the mouse.
edit1: jumpy mouse fixed
edit2: better smoothing and deadzone; version 0.7 beta
edit3: more improvements, directinput or desktop xy mouse switch; version 0.8 beta
edit4: better smoothing if only one dot is visible, small improvements; version 0.9 beta
edit5: deadzone fixed
edit5: higher pie.framerate, better directinput; version 1.1 beta
edit6: jumpy cursor phantom dot improved
edit7: jumpy cursor phantom dot hopefully fixed; version 1.2 beta
edit8: more glitches fixed; version 1.3 beta
edit9: small glitch improvement
edit10: 1 to 2 visible ir dots transition glitches improved; version 1.5 beta
edit11: more improvements and fixes; added nunchuk joy as wasd and nunchuk acceleration as buttons; version 1.9 beta
edit12: bug fixed
edit13: better deadzone (smoothsoftdeadzone) added; change sensitivity with up and down; version 1.95 beta
edit14: NAN bug workaround introduced
| Code: |
//FPS IR Script beta 1.95
//by Dr_Zoidberg 2007
//0 = directinput or xy = 1
if wiimote.One = true then
var.input = 1
endif
if wiimote.two = true then
var.input = 0
endif
pie.FrameRate = 125
//rotation deadzone
var.rn = 36
pie.MouseDPI = 1600
//smoothsoftdeadzone
var.deadzone = 1
//adjust sensitivty mousedpi/100 works best
If not var.scrmultchngd = 1 then
var.scrmult = 16
endif
//areas for IR pointing ----------------
//direct pointing area
var.czonex = (screen.Width/1.5)/var.scrmult
var.czoney = (screen.Height/1.5)/var.scrmult
//faster direct pointing area
var.izonex = (screen.Width/3)/var.scrmult
var.izoney = (screen.Height/3)/var.scrmult
//continous movment around inner area
//-------------------------------------
//speed factors-----------------------
var.cfactor = 1
var.ifactor = 1/16
var.0factor = 1/40
//y-axis adjustment
var.factory = 1/1.1
//acceleration adjust
var.cpower = 0.02
var.ipower = 1.2
var.0power = 0.1
//-------------------------------------
//wiimoteroll convert
if var.onedot = 0
var.cos0 = var.cos
var.sin0 = var.sin
endif
var.roll = 0 - wiimote.roll
if var.roll < 0 then
var.roll = var.roll + 360
endif
var.cos = cos(var.roll)
var.sin = -sin(var.roll)
var.0cos = var.cos - var.cos0
var.0sin = var.sin - var.sin0
var.0cos = smooth(var.0cos,2)
var.0sin = smooth(var.0sin,2)
var.cos = smooth(var.cos,25)
var.sin = smooth(var.sin,25)
var.sinpitch = sin(wiimote.Pitch)
var.sinpitch = smooth(var.sinpitch,5)
if wiimote.dot1vis or wiimote.dot2vis then
//phantomdot creation if only one dot is visible
if (not wiimote.dot1vis) or (not wiimote.dot2vis) then
if var.onedot < pie.FrameRate
var.onedot ++
endif
//compensate for pitch
var.distf = 1+((abs(var.y)^1/768-1)*((abs(var.sinpitch)^1)*(var.dist-1))/(1024-1))*sign(var.sinpitch)*sign(var.y)
var.px = var.cos*var.dist*var.distf
var.py = var.sin*var.dist*var.distf
if wiimote.dot1vis then
var.d0x = (1024/2)- wiimote.dot1x
var.d0y = (768/2) - wiimote.dot1y
var.dot2f = 2
var.dot1f = 1
else
var.d0x = (1024/2)- wiimote.dot2x
var.d0y = (768/2) - wiimote.dot2y
var.dot1f = 2
var.dot2f = 1
endif
//check which dot is which
if sqrt(sqr(var.d0x-var.d1x)+sqr(var.d0y-var.d1y))*var.dot1f > sqrt(sqr(var.d0x-var.d2x)+sqr(var.d0y-var.d2y))*var.dot2f then
var.d3x = var.d1x
var.d3y = var.d1y
var.0d3x = var.d01x
var.0d3y = var.d01y
var.0d0x = var.d02x
var.0d0y = var.d02y
else
var.d3x = var.d2x
var.d3y = var.d2y
var.0d3x = var.d02x
var.0d3y = var.d02y
var.0d0x = var.d01x
var.0d0y = var.d01y
endif
//var.roll = var.roll - var.dr
if sqrt(sqr(var.d0x+var.px-var.d3x)+sqr(var.d0y+var.py-var.d3y)) > sqrt(sqr(var.d0x-var.px-var.d3x)+sqr(var.d0y-var.py-var.d3y)) then
var.px = var.px*(-1)
var.py = var.py*(-1)
endif
if var.onedot < 3 // set to +1 0sin / 0cos smooth value
//eliminte glitches at transition form 2 to 1 ir dots visible
var.0dx = var.px - var.0d3x + var.0d0x - var.0cos*var.dist
var.0dy = var.py - var.0d3y + var.0d0y - var.0sin*var.dist
endif
var.d2x = var.d0x + var.px - var.0dx
var.d2y = var.d0y + var.py - var.0dy
var.d1x = var.d0x
var.d1y = var.d0y
else
//read IR if both dots are visible
var.onedot = 0
var.d2x = (1024/2)- wiimote.dot2x
var.d2y = (768/2) - wiimote.dot2y
var.d1x = (1024/2)- wiimote.dot1x
var.d1y = (768/2) - wiimote.dot1y
var.dist = sqrt(sqr(var.d1x-var.d2x)+sqr(var.d1y-var.d2y))
endif
var.rotc = acos((var.d1x-var.d2x)/sqrt(sqr(var.d1x-var.d2x)+sqr(var.d1y-var.d2y)))
if ((var.d1y-var.d2y)/sqrt(sqr(var.d1x-var.d2x)+sqr(var.d1y-var.d2y))) > 0 then
var.rotc = 360 - var.rotc
endif
var.rots = - asin((var.d1y-var.d2y)/sqrt(sqr(var.d1x-var.d2x)+sqr(var.d1y-var.d2y)))
if ((var.d1x-var.d2x)/sqrt(sqr(var.d1x-var.d2x)+sqr(var.d1y-var.d2y))) < 0 then
var.rots = 180 - var.rots
endif
if var.rots < 0 then
var.rots = 360 + var.rots
endif
var.rot = var.rotc/2 + var.rots/2
//rotation neutralization
if (360 -var.rn) > abs(var.rot - var.roll) > (var.rn) then
var.rot = var.rot - 180
if var.rot < 0 then
var.rot = 360 + var.rot
endif
var.d0x = var.d1x
var.d0y = var.d1y
var.d1x = var.d2x
var.d1y = var.d2y
var.d2x = var.d0x
var.d2y = var.d0y
endif
//store last dots
if var.onedot = 0
var.d01x = var.d1x
var.d01y = var.d1y
var.d02x = var.d2x
var.d02y = var.d2y
endif
//smooth movement
var.d1x = smooth(var.d1x,2)
var.d1y = smooth(var.d1y,2)
var.d2x = smooth(var.d2x,2)
var.d2y = smooth(var.d2y,2)
//store last coordinates
var.0x = var.x
var.0y = var.y
//coordinate calculation
var.y = ((var.d1y*var.d2x)-(var.d1x*var.d2y)) / (sqrt(sqr(var.d2x-var.d1x) + sqr(var.d2y-var.d1y)))/((768))*screen.height/var.scrmult
var.x = (sqr(var.d1x)-sqr(var.d2x)+sqr(var.d1y)-sqr(var.d2y)) / (2*(sqrt(sqr(var.d2x-var.d1x) + sqr(var.d2y-var.d1y))))/(1024)*screen.Width/var.scrmult
//NAN bug workaround
if var.x = NAN then
var.x = 0
var.0x = 0
endif
if var.y = NAN then
var.y = 0
var.0y = 0
endif
//softsmoothdeadzone
if abs(var.x-var.0x) < var.deadzone then
var.x = var.x - ((var.x-var.0x)*(1-((abs((var.deadzone-abs(var.x-var.0x))/var.deadzone)))^0.5))
var.x = smooth(var.x,4)
endif
if abs(var.y-var.0y) < var.deadzone then
var.y = var.y - ((var.y-var.0y)*(1-((abs((var.deadzone-abs(var.y-var.0y))/var.deadzone)))^0.5))
var.x = smooth(var.x,4)
endif
var.x = smooth(var.x,2)
var.y = smooth(var.y,2)
if var.input = 0 then
if abs(var.x) > var.czonex
var.x = var.x*abs(1+(abs(abs(var.x)-var.czonex)/abs(var.x))*var.cpower)*var.cfactor
endif
if abs(var.y) > var.czoney
var.y = var.y*abs(1+(abs(abs(var.y)-var.czoney)/abs(var.y))*var.cpower*var.factory)*var.cfactor
endif
endif
if var.input = 1 then
mouse.x = smooth(((var.x/screen.Width*var.scrmult)*1.5 + 0.5),3)
mouse.y = smooth(((var.y/screen.Height*var.scrmult)*1.2 + 0.5),3)
endif
//fps mouse movement
if var.input = 0 then
if abs(var.x) > var.izonex then
var.inputx = var.inputx + var.x*abs((abs((abs(var.x)-var.izonex)^var.ipower)/abs(abs(var.x)^var.ipower)))*var.ifactor
endif
if abs(var.y) > var.izoney then
var.inputy = var.inputy + var.y*abs((abs((abs(var.y)-var.izoney)^var.ipower)/abs(abs(var.y)^var.ipower)))*var.ifactor
endif
var.inputx = var.inputx + var.x - var.0x
var.inputy = var.inputy + var.y - var.0y
mouse.DirectInputX = var.inputx
mouse.DirectInputY = var.inputy
endif
else
//continue mouse movement if no IR visible
if var.input = 0 then
if abs(var.x) > var.izonex then
var.InputX = var.InputX + var.x*abs((abs((abs(var.x)-var.izonex)^var.ipower)/abs(abs(var.x)^var.ipower)))*var.ifactor
else
var.InputX = var.InputX + var.x*abs(1+abs(var.x)*var.0power)*var.0factor
endif
if abs(var.y) > var.izoney then
var.InputY = var.InputY + var.y*abs((abs(abs(abs(var.y)-var.izoney)^var.ipower)/abs(abs(var.y)^var.ipower)))*var.ifactor
else
var.InputY = var.InputY + var.y*abs(1+abs(var.y)*var.0power*var.factory)*var.0factor
endif
mouse.directinputX = var.inputx
mouse.directinputY = var.inputy
endif
endif
if wiimote.Up then
var.scrmultchngd = 1
var.scrmult = var.scrmult*0.99
endif
if wiimote.Down then
var.scrmultchngd = 1
var.scrmult=var.scrmult/0.99
endif
//Nunchuckpart ----------------------
var.accsens = 15
if var.acc = 0 then
if abs(wiimote.Nunchuk.RelAccY) > var.accsens
var.acc = 1
keyboard.f = true
wait 10ms
keyboard.f = false
endif
if abs(wiimote.Nunchuk.RelAccX) > var.accsens
var.acc = 1
keyboard.g = true
wait 10ms
keyboard.g = false
endif
if abs(wiimote.Nunchuk.RelAccZ) > var.accsens
var.acc = 1
keyboard.e = true
wait 10ms
keyboard.e = false
endif
else
wait 500ms
var.acc = 0
endif
var.joysens = 0.3
var.wait = 20
var.nunjoydead0 = 1.5
var.nunjoydead1 = 0.05
var.waitpowert = 2
var.waitpowerf = 0.5
mouse.RightButton = wiimote.A
mouse.leftbutton = wiimote.B
keyboard.r = wiimote.Home
mouse.WheelUp = wiimote.plus
mouse.WheelDown = wiimote.Minus
wiimote.Rumble = wiimote.b
keyboard.LeftControl = wiimote.Nunchuk.ZButton
keyboard.c = wiimote.Nunchuk.CButton
keyboard.w = wiimote.nunchuk.joyy <= -var.joysens
keyboard.a = wiimote.nunchuk.joyx <= -var.joysens
keyboard.s = wiimote.nunchuk.joyy >= var.joysens
keyboard.d = wiimote.nunchuk.joyx >= var.joysens
debug = ("dot1x: " + wiimote.dot1x+ " dot1y: " +wiimote.dot1y + " dot2x: " +wiimote.dot2x + " dot2y: " + wiimote.dot2y +" var.x: " +var.x + " var.y: " +var.y + " rot: " + var.rot +" roll: " + var.roll + " mouse: " + mouse.DirectInputPos +" batt: " +wiimote.Battery)
|
Last edited by Dr_Zoidberg on Sun Mar 11, 2007 12:05 pm; edited 4 times in total |
|
| Back to top |
|
 |
tic
Joined: 18 Feb 2007 Posts: 121
Digg It |
Posted: Wed Mar 07, 2007 8:36 pm Post subject: |
|
|
While i think that last script from zoidberg has got rid of the inverting problem, there is a new problem with it. when i move my wiimote to move the cursor to the right edge of my monitor, it gets sucked over to it and will often start moving a lot with only a small movement. im using two monitors and would need a script that could work on any number of monitors. ill have a look through the script and see if its anything obvious to change, but i have a feeling it will take a while to debug. thanx and hope you can fix it  |
|
| Back to top |
|
 |
RedruM
Joined: 07 Mar 2007 Posts: 27
Digg It |
Posted: Thu Mar 08, 2007 2:25 am Post subject: |
|
|
Hey, so far this is the best script I've tried for FPS games (since it uses DirectX), although I do have some suggestions, especially since I'm not familiar enough with the scripting language yet.
If I may, could you or someone modify or help me modify your script a bit. I have a couple of ideas I want to try out, perhaps I could learn from looking at how its done.
I want to use the nunchucks joystick's X axis as the dX mouse X axis in conjunction with the wiimotes sensors. I like the directx mouse, but I want to use different control method with the joystick so I dont need the emulated bounding box.
One other thing I would like to do is use a few special keys as macros to remap other keys when held, and another key to disable the wiimote sensors mouse emulation and/or even adjust the wiimotes sensitivity if possible.
I'm looking around to figure out how to script stuff like this currently, but if anyone could help point me out to any relevant info please let me know. Sorry to come off like the newbie I am.  |
|
| Back to top |
|
 |
tic
Joined: 18 Feb 2007 Posts: 121
Digg It |
Posted: Thu Mar 08, 2007 6:54 pm Post subject: |
|
|
| ha! i didnt relaise that it was a bounding box you had made that was making it turn by itself. i would appreciate it if you could release the same script but without the bounding box part, so that i could add it to my wiiPC program if thats alright with you. i could edit it myself if you dont want to |
|
| Back to top |
|
 |
Dr_Zoidberg
Joined: 29 Dec 2006 Posts: 60
Digg It |
Posted: Fri Mar 09, 2007 12:34 am Post subject: |
|
|
@tic: Pressing the one button on the wiimote makes the script go into mouse.x and mouse.y mode instead of directinput and doesn't use a bounding box. You could change that part under "if var.input = 1 then" to suit your needs.
@RedruM: I'll explain the details tomorrow, the short answer is:
You need to read the wiimote.nunchuk.joyx value (multiply by a factor) and then add that to mouse.directinputX. Remove the parts under where it says "if abs(var.x) > var.izonex then" to get rid of the bounding box for the x-axis.
To disable the sensor you could change the lines where it says mouse.directinputx = ... or directinputy
Adjusting the sensitivity is done by changing the variables at the beginning of the script, that can be mapped to a button. |
|
| Back to top |
|
 |
tjdavids77
Joined: 09 Mar 2007 Posts: 29
Digg It |
Posted: Fri Mar 09, 2007 1:43 am Post subject: good work |
|
|
it seems like no one else is saying but i just wanna say great job man. This is
the best fps script out. Keep up the good work |
|
| Back to top |
|
 |
RedruM
Joined: 07 Mar 2007 Posts: 27
Digg It |
Posted: Fri Mar 09, 2007 4:21 am Post subject: |
|
|
| Dr_Zoidberg wrote: | @tic: Pressing the one button on the wiimote makes the script go into mouse.x and mouse.y mode instead of directinput and doesn't use a bounding box. You could change that part under "if var.input = 1 then" to suit your needs.
@RedruM: I'll explain the details tomorrow, the short answer is:
You need to read the wiimote.nunchuk.joyx value (multiply by a factor) and then add that to mouse.directinputX. Remove the parts under where it says "if abs(var.x) > var.izonex then" to get rid of the bounding box for the x-axis.
To disable the sensor you could change the lines where it says mouse.directinputx = ... or directinputy
Adjusting the sensitivity is done by changing the variables at the beginning of the script, that can be mapped to a button. |
Ah thank you, even little bits of info like that really help me to get started. I look forward to hearing more on this. I've never programmed before, but I script like a madman in counter strike
And yes I said this is the best script yet before you did tj  |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|