Jump to content


Photo

need smoothing algorithm


  • Please log in to reply
6 replies to this topic

#1 Bart

Bart

  • Network Admins
  • 8,524 posts
  • Location:The Netherlands
  • Division:Revora
  • Job:Network Leader

Posted 17 April 2008 - 10:56 PM

i've connected a wiimote to my pc and i'm trying to script it to use it as a mouse. i do this by simply taking the roll value of the wiimote and translating it to a mouse x

mouse.x = (wiimote.roll + 60) / 120; // results in number between 0 and 1

however, the roll value is quite shaky, so the mouse starts shaking too. i'm looking for an algorithm which can smooth this movement (detect when movement is real and when it's shaking).

anyone know?
bartvh | Join me, make your signature small!
Einstein: "We can’t solve problems by using the same kind of thinking we used when we created them."

#2 Banshee

Banshee

    One Vision, One Purpose!

  • Network Admins
  • 9,045 posts
  • Location:Rio De Janeiro, RJ, Brazil.
  • Projects:PPM, PPM: Final Dawn, OS SHP Builder, OS Palette Editor, OS W3D Viewer, VXLSE III, etc...
  •  Retired Network Leader
  • Division:Revora
  • Job:Maintenance Admin

Posted 18 April 2008 - 05:37 PM

I have no clue on how to program with Wii, but I have some knowledge on computer graphics and smooth effects on it.

So, I suggest you to try something like this:

new.x = (new.x + old.x) / 2;
new.y = (new.y + old.y) / 2;
Project Perfect Mod

Command & Conquer Mods, Mods Support, Public Researchs, Map Archives, Tutorials, Tools, A Friendly Community and much more. Check it out now!

Posted Image

#3 Mastermind

Mastermind

    Server Technician

  • Undead
  • 7,014 posts
  • Location:Cambridge, MA
  • Projects:MasterNews 3
  •  The Man Behind the Curtain

Posted 18 April 2008 - 05:40 PM

Yeah, a really simple smoothing algorithm is just a rolling average. The more points you use the smoother you get, but the more data you throw away. You're going to have to deal with some level of inaccuracy pretty much no matter what though.
Posted Image

Well, when it comes to writing an expository essay about counter-insurgent tactics, I'm of the old school. First you tell them how you're going to kill them. Then you kill them. Then you tell them how you just killed them.

Too cute! | Server Status: If you can read this, it's up |

#4 Bart

Bart

  • Network Admins
  • 8,524 posts
  • Location:The Netherlands
  • Division:Revora
  • Job:Network Leader

Posted 18 April 2008 - 07:40 PM

i found out the scripting platform (glovepie) has a built-in smoothing function, but it doesn't do exactly what i want. sure, it removes the shaking, but also makes the cursor a lot less responsive.

i'm not going to spend more time on this, but to get this done a more sophisticated algorithm would be needed
bartvh | Join me, make your signature small!
Einstein: "We can’t solve problems by using the same kind of thinking we used when we created them."

#5 Banshee

Banshee

    One Vision, One Purpose!

  • Network Admins
  • 9,045 posts
  • Location:Rio De Janeiro, RJ, Brazil.
  • Projects:PPM, PPM: Final Dawn, OS SHP Builder, OS Palette Editor, OS W3D Viewer, VXLSE III, etc...
  •  Retired Network Leader
  • Division:Revora
  • Job:Maintenance Admin

Posted 19 April 2008 - 02:17 AM

Ok, so I have an idea.

Make sure you can store the current coordinates and the last two. So, in my sample here, I'll use new, old and older.. but you'll need to adapt it to the way Wii works.

if ((abs(new.x - old.x) == abs(old.x - older.x)) && (abs(new.y - old.y) == abs(old.y - older.y)))
{
  mouse.x = new.x;
  mouse.y = new.y;
}
else
{
  mouse.x = old.x;
  mouse.y = old.y;
}
older.x = old.x;
older.y = old.y;
old.x = new.x;
old.y = new.y;

I believe this should counter the shaking, although the response would be a bit suspicious on the initial move.
Project Perfect Mod

Command & Conquer Mods, Mods Support, Public Researchs, Map Archives, Tutorials, Tools, A Friendly Community and much more. Check it out now!

Posted Image

#6 Mastermind

Mastermind

    Server Technician

  • Undead
  • 7,014 posts
  • Location:Cambridge, MA
  • Projects:MasterNews 3
  •  The Man Behind the Curtain

Posted 19 April 2008 - 06:03 AM

Another way would be to just toss out any data that is less than a certain amount different from the last reading, which would smooth the shake as well. There are a lot of ways to approach this, and it really depends on what you need the smoothing to do.
Posted Image

Well, when it comes to writing an expository essay about counter-insurgent tactics, I'm of the old school. First you tell them how you're going to kill them. Then you kill them. Then you tell them how you just killed them.

Too cute! | Server Status: If you can read this, it's up |

#7 duke_Qa

duke_Qa

    I've had this avatar since... 2003?

  • Network Staff
  • 3,837 posts
  • Location:Norway
  • Division:Revora
  • Job:Artist

Posted 29 April 2008 - 07:28 PM

i would probably add a ignore-smooth function once there is a great deal of movement involved aswell. should make for more precise aiming. give it half a second Delay before the smoothing kicks back in again... Attack should be more or less instant, but not so instant that you never get to use the smoothing function :wink_new:

"I give you private information on corporations for free and I'm a villain. Mark Zuckerberg gives your private information to corporations for money and he's 'Man of the Year.'" - Assange





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users