Moving Models Blues

Hi im developing a chess game and im trying to move a piece model, lets say a king to a square on the board.

Each square is a seperate model as is each piece so i figured i could just get the ceter point of the square and transate the king to it. simple!

But im getting some strange effects the king is moving but not to the center point of the square, it seems to be offset by a lot for some reason here is the code i’m using



public void movePiece(Node sourcePiece, Node targetSquare){

    Transform3D translate = new Transform3D();
    Vector3f move = new Vector3f    (targetSquare.getVworldBounds().getCenter());
                translate.setTranslation(move);

    sourcePiece.getTransformGroup().setTransform(translate);

}

The models im using are .ase exported from 3dmax and im loading them with an ase loader as supllied with the convert coords to xith3D option true.

all help is greatly appriciated as this is for a college project which needs to be finished fairly soon. thanks

in 3D Max - make sure your pivot point is exactly where you want it in the model.

Use the getNamedNodesMap method of AseFile which offsets the geometry by it’s pivot point.

Alternativly move your object in MAX so that (0,0,0) is your pivot point and use getModel()

Cheers,

Will

The model board model is centered fine ts when im trying to move the pieces after the model loads that i have probs.

If i click on a piece say a knight and click on a square say two squares ahead. the knight model moves to a position off the board. if i then click on a knight piece (which is in the same starting location) and click three squares ahead, the knight moves to on square ahead of the original knight off board position.

This would suggest that the coords for the board are off center in some way but every piece seems to have a different idea off where the board is. strange.

i am using the old method of loading the models e.g. getting them as a Hashtable so ill remedy that prob first thanks for the reply :slight_smile:

I am just curious if you have tested your getCenter method? I would suggest creating a sphere and import that as a model. Then move it around to see if it still has the problem.

This would allow you to see whether it is the moving method, or possibly the model. I hope this might help you.
What is the code that gets your center of each square?

All sorted, it was the fact i was using the depricated getNamedNodes() method instead of getNamedNodesMap(). the coords of each shape were all offset.

Thanks all :slight_smile: