hi everybody,
I have written a Custom Input Handler which essentially switches between various action modes depending upon
which button is active.
Essentially the problem is that this is not getting switched on…
ChessBoardhandler.java
public class ChessBoardHandler extends InputHandler {
private ChessGameBoard game = null;
private AbsoluteMouse mouse = null;
private Node rootNode = null;
private DisplaySystem display = null;
private ChessBoardPick pick = null;
private ChessBoardRotateAction mouseRotate =null;
public ChessBoardHandler() {
super();
game = ChessGameBoard.getCurrentGame();
rootNode = game.getRenderer().getBoardRootNode();
display = DisplaySystem.getDisplaySystem();
initCursor();
//Now the movements
pick = new ChessBoardPick(mouse);
mouseRotate = new ChessBoardRotateAction(mouse,rootNode);
}
private void initCursor() {
MouseInput.get().setCursorVisible(false);
mouse = new AbsoluteMouse("Mouse Input", display.getWidth(), display.getHeight());
mouse.registerWithInputHandler(this);
AlphaState alpha = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
alpha.setBlendEnabled(false);
alpha.setSrcFunction(AlphaState.SB_SRC_ALPHA);
alpha.setDstFunction(AlphaState.DB_ONE);
alpha.setTestEnabled(true);
alpha.setTestFunction(AlphaState.TF_GREATER);
alpha.setEnabled(true);
mouse.setRenderState(SkinManager.getDefaultManager().getTextureInfo(SkinEnum.Tex_DefaultCursor).getTextureState(Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR));
mouse.setRenderState(alpha);
mouse.setLocalScale(new Vector3f(1, 1, 1));
mouse.setLocalTranslation(new Vector3f(display.getWidth() / 2, display.getHeight() / 2, 0.0F));
rootNode.attachChild(mouse);
}
public void ActivateBoardRotationMode() {
this.removeAllActions();
this.addAction(mouseRotate);
}
public void ActivateZoomMode() {
}
public void ActivateTranslateMode() {
}
public void ActivatePickMode() {
this.removeAllActions();
this.addAction(pick);
// setActionSpeed(100f);
}
}
and below is the mouseinput action which should get activated
public class ChessBoardPick extends MouseInputAction {
private float shotTime = 0;
private ChessGameBoard game = null;
private DisplaySystem display;
private PickResults results;
public ChessBoardPick(AbsoluteMouse mouse) {
this.mouse = mouse;
this.game = ChessGameBoard.getCurrentGame();
display = DisplaySystem.getDisplaySystem();
results = new BoundingPickResults();
}
public void performAction(InputActionEvent inputActionEvent) {
shotTime += inputActionEvent.getTime();
// MouseInput.get().isButtonDown(0)
if( shotTime > 0.1f) {
Vector2f screenPos = new Vector2f();
// Get the position that the mouse is pointing to
screenPos.set(mouse.getHotSpotPosition().x, mouse.getHotSpotPosition().y);
// Get the world location of that X,Y value
Vector3f worldCoords = display.getWorldCoordinates(screenPos, 0);
Vector3f worldCoords2 = display.getWorldCoordinates(screenPos, 1);
// Create a ray starting from the camera, and going in the direction of the mouse's location
Ray mouseRay = new Ray(worldCoords, worldCoords2.subtractLocal(worldCoords).normalizeLocal());
// Does the mouse's ray intersect the box's world bounds?
results.setCheckDistance(true);
game.getRenderer().getBoardRootNode().findPick(mouseRay, results);
if (results.getNumber() > 0) {
if (results.getPickData(0).getTargetMesh().getParentGeom() instanceof SimpleGameBoardRendererCell) {
if (MouseInput.get().isButtonDown(0)) {
game.GamePositionActive(((SimpleGameBoardRendererCell) results.getPickData(0).getTargetMesh().getParentGeom()).getPos());
} else {
game.GamePositionHover(((SimpleGameBoardRendererCell) results.getPickData(0).getTargetMesh().getParentGeom()).getPos());
}
}
}
results.clear();
shotTime = 0f;
}
}
}
I have tested the ChessBoardPick class individually and it works perfectly when it is individually used on a InputHandler class
Can you pls tell me what is wrong????
also on a side note ... is this the best method of doing this ...?
Regds
AgentX