[Solved and working] Wii Balance Board?

well, this depends on what you want to do with the values.



If you want to use them for the movent of a character or the cursor, then use the double values you get from the balanceboard directly for the translation of the character/cursor.

So get the values from the balanceboard during your update(), with e.g. BalanceBoardController.getXValue()!

The value you get should be something between 0 to1 or -1 to 1.

And with this values you can alter the translation/rotation of your character/cursor.

So add the value to the current character/cursor position within the update() as well.

private void update(float fps){
float balboardValueX = (float)BBController.getXValue();

cursor.getLocalTranslation().x += balboardValueX();
}




If you want to use the 4 senible areas of the balanceboard as simple buttons, you have to define a threshold on how much pessure a keystroke should be fired. Therefore check the values you got against the threshold

private void update(float fps){
float balboardValueX = (float)BBController.getXValue();

if(balboardValueX >= 0.5f){
doSomething.whatShouldHappen()
}
}



hope this helps


*edit*
Well ... i see, during i was posting this answer you got the solution ;)
Fine you figured it out.
Keep on!

Hi .:emp…imm0|82:. ,



thanks for your reply. Made me think of more ideas: What I did now was the rotation/translation. Next step would be the e 4 sensible areas of the balanceboard.





I thought about this:



double massRightTop
double LeftTop
double massRightBottom
double massLeftButtom



This means I have the Mass in each area. After that I would have to divide it with the totalmass and put it somehow in relation with the other ones.
And then bind it with the keys UP, LEFT; DOWN; RIGHT

I looked at your code but I am not sure how to use it.

Maybe we can do it step by step with the 4 double values for each area *g* ;)


Thanks again.... RapidM

Thanx for the contrib :slight_smile:



(I edited a section that was outside the 'code' tags, it might have caused ppl issues when copy and pasting :))

Wuhuhuhu it's finished and working as a real controller (up,down,left,right,upleft,upright,downleft,downright) :wink:



Here is the working code:



WiiRemoteProxa.java  (put it somewhere and import it in all the files)

This class is used to make a connection to the bb and calculate the sensors


package com.jme.input.controls.binding;

import gamecontrols.WiiRemoteProxy;

import com.jme.input.controls.Binding;

public class BalanceBoardBinding implements Binding {
   
   public static final int AXIS_X = 1;
    public static final int AXIS_Y = 2;
   
   private      WiiRemoteProxy         balanceBoard;

    private static final long serialVersionUID = 1L;
    private int axis;
   
    public BalanceBoardBinding(WiiRemoteProxy balanceBoard, int axis) {
        this.balanceBoard = balanceBoard;
        this.axis = axis;
    }
   
   
   public float getValue() {
      float value = 0.0f;
      if(axis == AXIS_X){
      value = (float) balanceBoard.getHorizontal();
      }else {
         value = (float) balanceBoard.getVertical();
      }
      //System.out.println("BB:val: " + value);
        return value;
   }
   
   public String getName() {
        return "BB:X" + axis;
   }

}



BalanceBoardBindingKeys.java
Used to get the values for the controller

package com.jme.input.controls.binding;

import gamecontrols.WiiRemoteProxy;

import com.jme.input.controls.Binding;

public class BalanceBoardBindingKeys implements Binding {
   
   public static final int AXIS_LEFT = 1;
    public static final int AXIS_DOWN = 4;
    public static final int AXIS_RIGHT = 2;
    public static final int AXIS_UP = 3;
   
   private      WiiRemoteProxy         balanceBoard;

    private static final long serialVersionUID = 1L;
    private int axis;
   
    public BalanceBoardBindingKeys(WiiRemoteProxy balanceBoard, int axis) {
        this.balanceBoard = balanceBoard;
        this.axis = axis;
    }
   
   
   public float getValue() {
      float value = 0.0f;
      if(axis == AXIS_LEFT){
      value = (-1)* (float) balanceBoard.getHorizontal();
      }
      if(axis == AXIS_RIGHT){
         value = (float) balanceBoard.getHorizontal();
         }
      if(axis == AXIS_UP){
         value = (-1)*(float) balanceBoard.getVertical();
         }
      if(axis == AXIS_DOWN) {
         value = (float) balanceBoard.getVertical();
      }
      //System.out.println("BB:val: " + value);
        return value;
   }
   
   public String getName() {
        return "BB:X" + axis;
   }

}



CubeController.java
Used to Controll this test application (cube from the tutorials)

package gamecontrols;
 
import com.jme.input.controls.GameControl;
import com.jme.input.controls.GameControlManager;
import com.jme.input.controls.binding.BalanceBoardBindingKeys;
import com.jme.input.controls.binding.KeyboardBinding;
import com.jme.input.controls.binding.MouseButtonBinding;
import com.jme.scene.Controller;
import com.jme.scene.Node;
import static gamecontrols.CubeController.CubeAction.*;
import static com.jme.input.KeyInput.*;
import static com.jme.input.controls.binding.MouseButtonBinding.*;
import com.jme.input.controls.binding.BalanceBoardBinding;
import gamecontrols.WiiRemoteProxy;
 
public class CubeController extends Controller{
   
   public      WiiRemoteProxy         balanceBoard;
   private static final long serialVersionUID = 1L;
   enum CubeAction {LEFT, RIGHT, UP, DOWN, EXIT, X_AXIS, Y_AXIS};
 
    private final static float SPEED = 2F;
    private final Node node;
    private final GameControlManager manager;
    private float x_axis = 0F;
    private float y_axis = 0F;
   
    public CubeController(Node node) {
        this.node = node;
        this.manager = new GameControlManager();
       
        //create all actions
        for (CubeAction action : CubeAction.values()) {
            manager.addControl(action.name());
        }
                      
        //bind keys
        bindKey(EXIT, KEY_X);
        bindKey(UP, KEY_UP);
        bindKey(DOWN, KEY_DOWN);
        bindKey(LEFT, KEY_LEFT);
        bindKey(RIGHT, KEY_RIGHT);
 
        //bind mouse buttons
        bindMouseButton(LEFT, LEFT_BUTTON);
        bindMouseButton(RIGHT, RIGHT_BUTTON);
               
        balanceBoard = new WiiRemoteProxy();
        //BalanceBoard binding
           bindBalanceBoardKeys(RIGHT, BalanceBoardBindingKeys.AXIS_RIGHT);
           bindBalanceBoardKeys(DOWN, BalanceBoardBindingKeys.AXIS_DOWN);
           bindBalanceBoardKeys(LEFT, BalanceBoardBindingKeys.AXIS_LEFT);
           bindBalanceBoardKeys(UP, BalanceBoardBindingKeys.AXIS_UP);
    }
    
    private void bindKey(CubeAction action, int... keys) {
        final GameControl control = manager.getControl(action.name());
        for (int key : keys) {
          control.addBinding(new KeyboardBinding(key));
        }
    }
   
    private void bindBalanceBoardAxis(CubeAction action, int axis){
        final GameControl control = manager.getControl(action.name());
        control.addBinding(new BalanceBoardBinding(balanceBoard, axis));
    }
   
    private void bindBalanceBoardKeys(CubeAction action, int axis){
       final GameControl control = manager.getControl(action.name());
        control.addBinding(new BalanceBoardBindingKeys(balanceBoard, axis));
    }
    
    private void bindMouseButton(CubeAction action, int mouseButton) {
        final GameControl control = manager.getControl(action.name());
        control.addBinding(new MouseButtonBinding(mouseButton));
    }
 
  
    private float value(CubeAction action) {
        return manager.getControl(action.name()).getValue();
    }
 
    @Override
    public void update(float time) {
        if (value(EXIT) > 0) {
            System.exit(0); //OK, this is just a demo...
        }
        else{      
        x_axis += SPEED * time * (value(RIGHT) - value(LEFT));
        y_axis += SPEED * time * (value(UP) - value(DOWN));
       
   
        node.getLocalTranslation().set(x_axis, y_axis, 0);
        }
    }

}



CubeGameState.java
makes a Cube and puts a texture on it (see tutorials from jME2)

package gamecontrols;
 
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.light.PointLight;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.LightState;
import com.jme.scene.state.MaterialState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jmex.game.state.BasicGameState;
 
/**
 *
 * @author Gronau
 */
public class CubeGameState extends BasicGameState {
 
    private static String texture = "jmetest/data/images/Monkey.jpg";
   public      WiiRemoteProxy         remote;

   
    public CubeGameState() {
        super("cubeGameState");
        final Box box = new Box("MonkeyBox", new Vector3f(0, 0, 0), 5, 5, 5);
 
        //Material: gray
        final MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
        ms.setEmissive(new ColorRGBA(0.5f, 0.5f, 0.5f, 1));
        box.setRenderState(ms);
 
        //Texture: the Monkey
        final TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
        final Texture t = TextureManager.loadTexture(
                BasicGameState.class.getClassLoader().getResource(texture),
                Texture.MinificationFilter.BilinearNoMipMaps,
                Texture.MagnificationFilter.Bilinear);
        ts.setTexture(t);
        box.setRenderState(ts);
        box.setModelBound(new BoundingBox());
        box.updateModelBound();
        Node boxNode = new Node("MonkeyBoxNode");
        boxNode.attachChild(box);
        getRootNode().attachChild(boxNode);
 
        //Spot on!
        final PointLight light = new PointLight();
        light.setDiffuse(new ColorRGBA(0.75f, 0.75f, 0.75f, 0.75f));
        light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
        light.setLocation(new Vector3f(100, 100, 100));
        light.setEnabled(true);
 
        final LightState lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
        lightState.setEnabled(true);
        lightState.attach(light);
        getRootNode().setRenderState(lightState);
 
        getRootNode().updateRenderState();
        //Oh, and don't forget the controller...
        getRootNode().addController(new CubeController(boxNode));
    }
}



Main.java
The Main Class to start the whole application. Important that you press the SYNCH in the bb before you run the Main.java!!! Be aware to close the bb_connection (with the power button on the balanceboard) before you close the window of the Main application!!!  If you dont do that, you wiill have problems with the bluetooth stack on the next start!!!

package gamecontrols;

import com.jmex.game.StandardGame;
import com.jmex.game.state.GameState;
import com.jmex.game.state.GameStateManager;

public class Main{
   private static StandardGame standardGame;
   
   public static void main(String[]args){
      System.setProperty("bluecove.jsr82.psm_minimum_off", "true");
      
      standardGame = new StandardGame("GameControl", StandardGame.GameType.GRAPHICAL, null);
      standardGame.start();
      
      GameState cubeState = new CubeGameState();      

        GameStateManager.getInstance().attachChild(cubeState);
        cubeState.setActive(true);      
   }
}




Maybe someone can use this code for his bb-game.

THANKS again for all the good help on the board!

RapidM