Getting the Wiimote Pointer Oriented

One of the things the Wiimote doesn’t know by default is whether or not it’s upside down. This presents a mild problem when using the Wiimote Library and you want to rotate the pointer most every Wii game does.

The trick is realizing that the Wiimote is calculating the angle based on the two outer points. To know if you’re upside down you simply check to see which point is to the left of the other. You then invert the angle if the points are flipped.

The angle given by the Wiimote is from -1 to 1 so you subtract the angle from 2 when the remote is upside down. You multiply the given angle by 90 degrees to get the 0-360 degree angle.

In Wii-Land the x axis is pointing into the screen so we use the x axis rotation to determine how to rotate the pointer on the screen.

You can see in the code below that the x pos is flipped. That’s because 1024 is the left side of the screen and 0 is the right side of the screen according to the Wiimote. I flip that as well to simplify things.

This is all part of the work I’ve been doing with software rendering. I finally got a wireless Wii sensor bar to use with my computer so I can start making games that make use of the Wiimote and other Wii controllers.


if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found)
{
remote.rot_x = accel.X;
remote.rot_y = accel.Y;
remote.rot_z = accel.Z;

if (ws.IRState.IRSensors[0].Position.X < ws.IRState.IRSensors[1].Position.X)
remote.rot_x = 2.0f - remote.rot_x;

remote.pos_x = 1.0f - (float)ws.IRState.RawMidpoint.X / 1024.0f;
remote.pos_y = (float)ws.IRState.RawMidpoint.Y / 768.0f;
}

Leave a comment

You must be logged in to post a comment.

ss_blog_claim=70b9168863fc97c91e6d88b40542a327 ss_blog_claim=70b9168863fc97c91e6d88b40542a327