/*
This was Modified based on "PipoXYZ's 2Dof, 2Leds, Flight- and RaceScript."
Modifications:
1. "smooth()" was added;
2. var.Angle is initialized by 1200 instead of 200;
3. Beep when Pitch over 90 degree (at the edge of pitch in LockON)
4. Changed keys for sensitive and centerView
Keys:
NumPad- = Less Sensitive
NumPad+ = More Sensitive
NumPad5 = Set CenterView
Joystick2.button4 pressed = set var.Angle to 3000
Compatible with these games:
http://www.naturalpoint.com/trac ... nced-games-all.html
Emulates Yaw/Pitch
Setup:
Place your Wiimote near your monitor facing your head.
Wear two IR-leds on your head facing the Wiimote.
The leds can be attached to glasses, headphones, caps or something else.
*/
if starting then
wait 200 ms
PIE.FrameRate = 100Hz
if Wiimote.dot2vis = true then
var.XOffset = (Wiimote.Dot1x + Wiimote.Dot2x) / 2
var.YOffset = (Wiimote.Dot1y + Wiimote.Dot2y) / 2
else
var.XOffset = Wiimote.Dot1x
var.YOffset = Wiimote.Dot1y
endif
var.Angle = 1200
endif
//Sensitivity
if pressed(NumPadMinus) and var.Angle < 1200 then
var.Angle = var.Angle + 50
say (var.Angle)
else
var.Angle = var.Angle
endif
if pressed(NumPadPlus) and var.Angle > 50 then
var.Angle = var.Angle - 50
say (var.Angle)
else
var.Angle = var.Angle
endif
if Joystick2.button4 <> true and var.Angle > 1200 then
var.Angle = 1200
endif
if Joystick2.button4 then //if Joystick1.button14 then
var.Angle = 3000
endif
//Maprange
var.MinIRX = var.XOffset - var.Angle
var.MaxIRX = var.XOffset + var.Angle
var.MinIRY = var.YOffset - var.Angle
var.MaxIRY = var.YOffset + var.Angle
//Center View
if pressed(NumPad5) then
if Wiimote.dot2vis = true then
var.XOffset = (Wiimote.Dot1x + Wiimote.Dot2x) / 2
var.YOffset = (Wiimote.Dot1y + Wiimote.Dot2y) / 2
else
var.XOffset = Wiimote.Dot1x - var.TempX
var.YOffset = Wiimote.Dot1y - var.TempY
endif
say "居中"
endif
//Mapset
if Wiimote.dot2vis = true then
var.TempDot2x = Wiimote.Dot2x
var.TempDot1x = Wiimote.Dot1x
var.TempDot2y = Wiimote.Dot2y
var.TempDot1y = Wiimote.Dot1y
var.X = (Wiimote.Dot1x + Wiimote.Dot2x) / 2
var.Y = (Wiimote.Dot1y + Wiimote.Dot2y) / 2
if var.TempDot1x < var.TempDot2x then
var.TempX = (Wiimote.Dot2x - Wiimote.Dot1x) / 2
else
var.TempX = (Wiimote.Dot1x - Wiimote.Dot2x) / 2
endif
if var.TempDot1y < var.TempDot2y then
var.TempY = (Wiimote.Dot2y - Wiimote.Dot1y) / 2
else
var.TempY = (Wiimote.Dot1y - Wiimote.Dot2y) / 2
endif
else
if var.TempDot1x < var.TempDot2x then
var.X = Wiimote.Dot1x + var.TempX
else
var.X = Wiimote.Dot1x - var.TempX
endif
if var.TempDot1y < var.TempDot2y then
var.Y = Wiimote.Dot1y + var.TempY
else
var.Y = Wiimote.Dot1y - var.TempY
endif
endif
//smoothing
var.TrackIRYawOld = var.FakeTrackIRYaw
var.TrackIRPitchOld = var.FakeTrackIRPitch
var.FakeTrackIRYaw = ensureMapRange(var.X, var.MaxIRX, var.MinIRX , -360, 360)
var.FakeTrackIRPitch = ensureMapRange(var.Y, var.MinIRY, var.MaxIRY , -360, 360)
var.DiffX = max(var.TrackIRYawOld,var.FakeTrackIRYaw) - min(var.TrackIRYawOld,var.FakeTrackIRYaw)
if var.DiffX < 10 then
FakeTrackIR.Yaw = smooth(var.FakeTrackIRYaw,30)
//FakeTrackIR.Yaw = smooth(smooth(var.FakeTrackIRYaw,30),30)
//FakeTrackIR.Yaw = kalman(smooth(var.FakeTrackIRYaw,30),0.4,0.04)
//FakeTrackIR.Yaw = smooth(kalman(var.FakeTrackIRYaw,0.4,0.03),30)
endif
var.DiffY = max(var.TrackIRPitchOld,var.FakeTrackIRPitch) - min(var.TrackIRPitchOld,var.FakeTrackIRPitch)
if var.DiffY < 10 then
FakeTrackIR.Pitch = 1.5 * smooth(var.FakeTrackIRPitch,30)
//FakeTrackIR.Pitch = smooth(smooth(var.FakeTrackIRPitch,30),30)
//FakeTrackIR.Pitch = kalman(smooth(var.FakeTrackIRPitch,30),0.4,0.04)
//FakeTrackIR.Pitch = smooth(kalman(var.FakeTrackIRPitch,0.4,0.03),30)
endif
if FakeTrackIR.Pitch > 90 then
Beep(5000,6)
endif
以下是最新的单LED方案,也是一个速度优化版;
更新:
1、单LED,简化计算量;
2、删除注释,优化速度;
3、数字键盘的“8”和“2”分别是Zoom in 和 Zoom out;
4、NumPad5 = Set CenterView;
5、NumPad- = Less Sensitive;
6、NumPad+ = More Sensitive;
7、NumPad5 = Set CenterView;
8、Joystick2.button4 pressed = Freeze Aspect and Zoom in;
以下内容拷贝到GlovePIE中执行:
if starting then
wait 200 ms
PIE.FrameRate = 100Hz
var.XOffset = Wiimote.Dot1x
var.YOffset = Wiimote.Dot1y
var.Angle = 1800
var.Zoom = -0.4
endif
//Sensitivity
if pressed(NumPadMinus) and var.Angle < 1800 then
var.Angle = var.Angle + 100
say (var.Angle)
else
var.Angle = var.Angle
endif
if pressed(NumPadPlus) and var.Angle > 100 then
var.Angle = var.Angle - 100
say (var.Angle)
else
var.Angle = var.Angle
endif
//Zoom and Freeze
if pressed(NumPad8) and var.Zoom < 0.5 then var.Zoom = var.Zoom + 0.05
if pressed(NumPad2) and var.Zoom > -0.4 then var.Zoom = var.Zoom - 0.05
if Joystick2.button4 then
FakeTrackIR.z = 0.3 //这是当Joystick2.button4按下情况下的z轴值,可以根据自己需要调整
else
FakeTrackIR.z = var.Zoom //这是当Joystick2.button4放开情况下的z轴值,可以根据自己需要调整
//Maprange
var.MinIRX = var.XOffset - var.Angle
var.MaxIRX = var.XOffset + var.Angle
var.MinIRY = var.YOffset - var.Angle
var.MaxIRY = var.YOffset + var.Angle
//Center View
if pressed(NumPad5) then
var.XOffset = Wiimote.Dot1x
var.YOffset = Wiimote.Dot1y
say "校准居中"
endif
//Mapset
var.TempDot1x = Wiimote.Dot1x
var.TempDot1y = Wiimote.Dot1y
var.X = Wiimote.Dot1x
var.Y = Wiimote.Dot1y
var.TempX = Wiimote.Dot1x
var.TempY = Wiimote.Dot1y
//smoothing
var.TrackIRYawOld = var.FakeTrackIRYaw
var.TrackIRPitchOld = var.FakeTrackIRPitch
var.FakeTrackIRYaw = ensureMapRange(var.X, var.MaxIRX, var.MinIRX , -360, 360)
var.FakeTrackIRPitch = ensureMapRange(var.Y, var.MinIRY, var.MaxIRY , -360, 360)
FakeTrackIR.Yaw = smooth(var.FakeTrackIRYaw,30)
//FakeTrackIR.Yaw = kalman(smooth(var.FakeTrackIRYaw,30),0.4,0.04)
FakeTrackIR.Pitch = 1.5 * smooth(var.FakeTrackIRPitch,30)
//FakeTrackIR.Pitch = kalman(smooth(var.FakeTrackIRPitch,30),0.4,0.04)
if FakeTrackIR.Pitch > 90 then Beep(5000,6)
debug = var.Angle + ' Battery=' + Wiimote.Battery + ' Yaw=' + FakeTrackIR.Yaw + ' Pitch=' + FakeTrackIR.Pitch + ' Zoom=' +var.Zoom
endif //endif for "if Joystick2.button4 then"
[ 本帖最后由 Akar 于 2008-10-10 22:25 编辑 ] |