function selectPiece(pos, initSet, contr){
        if(!contr){
            if(initSet){
                var boardPos = worldToInitBoard(pos);
                var myBoard = initBoard;
            }else{
                var boardPos = worldToBoard(pos);
                var myBoard = board;
            }
        }else{
            var boardPos = pos;
            var myBoard = initBoard;
        }
        if(myBoard[boardPos[0]][boardPos[1]] === 0 || myBoard[boardPos[0]][boardPos[1]] === 'x' || myBoard[boardPos[0]][boardPos[1]] === 1){
            selectedPiece = null;
            return false;
        }
        selectedPiece = {};
        selectedPiece.boardPos = boardPos;
        selectedPiece.obj = myBoard[boardPos[0]][boardPos[1]].pieceMesh;
        selectedPiece.origPosition = selectedPiece.obj.position.clone();
        selectedPiece.pieceObj =  myBoard[boardPos[0]][boardPos[1]].piece;
        selectedPiece.origPos = JSON.parse(JSON.stringify(selectedPiece.pieceObj.pos))
        selectedPiece.origOrient = JSON.parse(JSON.stringify(selectedPiece.pieceObj.orientation));
        return true;
    }
/**
     * Updates selectedPiece with the objects related to the object in the position given.
     * @param {Array} pos The coordinates of the piece chosen.
     * selectedPiece{
            boardPos: actual coordinates in board array
            obj: THREE.Mesh object of the piece at board[boardPos]
            objPiece: piece at board[boardPos] 
            origPosition: original obj position
            origPos: original piece pos attribute
            origOrient: original piece orientation
        }
     * return {boolean}.
     */
Updates selectedPiece with the objects related to the object in the position given.
@param {Array} pos The coordinates of the piece chosen.
Updates selectedPiece with the objects related to the object in the position given . @param { Array } pos The coordinates of the piece chosen .
function selectPiece(pos, initSet, contr){
        if(!contr){
            if(initSet){
                var boardPos = worldToInitBoard(pos);
                var myBoard = initBoard;
            }else{
                var boardPos = worldToBoard(pos);
                var myBoard = board;
            }
        }else{
            var boardPos = pos;
            var myBoard = initBoard;
        }
        if(myBoard[boardPos[0]][boardPos[1]] === 0 || myBoard[boardPos[0]][boardPos[1]] === 'x' || myBoard[boardPos[0]][boardPos[1]] === 1){
            selectedPiece = null;
            return false;
        }
        selectedPiece = {};
        selectedPiece.boardPos = boardPos;
        selectedPiece.obj = myBoard[boardPos[0]][boardPos[1]].pieceMesh;
        selectedPiece.origPosition = selectedPiece.obj.position.clone();
        selectedPiece.pieceObj =  myBoard[boardPos[0]][boardPos[1]].piece;
        selectedPiece.origPos = JSON.parse(JSON.stringify(selectedPiece.pieceObj.pos))
        selectedPiece.origOrient = JSON.parse(JSON.stringify(selectedPiece.pieceObj.orientation));
        return true;
    }
function selectPiece ( pos , initSet , contr ) { if ( ! contr ) { if ( initSet ) { var boardPos = worldToInitBoard ( pos ) ; var myBoard = initBoard ; } else { var boardPos = worldToBoard ( pos ) ; var myBoard = board ; } } else { var boardPos = pos ; var myBoard = initBoard ; } if ( myBoard [ boardPos [ 0 ] ] [ boardPos [ 1 ] ] === 0 || myBoard [ boardPos [ 0 ] ] [ boardPos [ 1 ] ] === 'x' || myBoard [ boardPos [ 0 ] ] [ boardPos [ 1 ] ] === 1 ) { selectedPiece = null ; return false ; } selectedPiece = { } ; selectedPiece . boardPos = boardPos ; selectedPiece . obj = myBoard [ boardPos [ 0 ] ] [ boardPos [ 1 ] ] . pieceMesh ; selectedPiece . origPosition = selectedPiece . obj . position . clone ( ) ; selectedPiece . pieceObj = myBoard [ boardPos [ 0 ] ] [ boardPos [ 1 ] ] . piece ; selectedPiece . origPos = JSON . parse ( JSON . stringify ( selectedPiece . pieceObj . pos ) ) selectedPiece . origOrient = JSON . parse ( JSON . stringify ( selectedPiece . pieceObj . orientation ) ) ; return true ; }
Updates selectedPiece with the objects related to the object in the position given.
Updates selectedPiece with the objects related to the object in the position given .