Hi guys, in general, I decided to write chess.
I want to choose just one click a shape on the second mouse click selects the cell to which it will go.
I used the code from the Mouse Picking.
I chose one shape to another variable is assigned its
CurrentTarget = target;
then choose a cage on board and put a figure on its location (on the axis + Y)
He stopped on the fact that I can not choose their shape a second time. That is when I want to choose a figure that has already walked it moves the previous figure but not the one that is needed.
Please tell me how to do so that you can select an object much time and store it in memory to move it to another position the selected object.
thanks in advance
Not possible to answer the question as globally as you ask it. Completely dependent on your code and what you do. What you describe isn’t a general behavior of jME3 but flaws in your own code.
Ok.
I select the object:
[java]
private AnalogListener analogListener = new AnalogListener() {
private Geometry target;
private ControlFigurs Control = new ControlFigurs();
public void onAnalog(String name, float value, float tpf) {
if (isRunning) {
if (name.equals(“pick target”)) {
CollisionResults results = new CollisionResults();
Vector2f click2d = inputManager.getCursorPosition();
Vector3f click3d = cam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f);
Vector3f dir = cam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 1f).subtractLocal(click3d);
Ray ray = new Ray(click3d, dir);
rootNode.collideWith(ray, results);
for (int i = 0; i < results.size(); i++) {
float dist = results.getCollision(i).getDistance();
Vector3f pt = results.getCollision(i).getContactPoint();
String target1 = results.getCollision(i).getGeometry().getName();
System.out.println(“Selection #” + 0 + ": " + target1 + " at " + pt + ", " + dist);
}
if (results.size() > 0) {
target = results.getClosestCollision().getGeometry();
Control.Control(target, figurs);
}
}
}
}
};
[/java]
ControlFigurs it is my class where i check the name of figur and save it.
figurs - arrey of all figurs on the board.
[java]
public class ControlFigurs extends Application {
Boolean isRunning = true;
private Geometry CurrentTarget;
private String Name;
private Spatial get;
protected final Quaternion tmp_inverseWorldRotation = new Quaternion();
public ControlFigurs(){
}
public void Control(Geometry target, Spatial[][] figurs){
Name = target.getName();
if ((“Rook”.equals(Name)) || (“Pawn”.equals(Name)) || (“Elephant”.equals(Name)) ||
(“King”.equals(Name)) || (“Queen”.equals(Name)) || (“Horse”.equals(Name))) {
if ((target.getLocalTranslation().x>(-1f)) &&
(target.getLocalTranslation().z>:(-7f)) && (target.getLocalTranslation().z<=7)){
if ((target.getLocalTranslation().x<13f) && (target.getLocalTranslation().z<8)){
if (target.getLocalTranslation().z>:(-7f)){
CurrentTarget=target;
}
}
else if ((“Pawn”.equals(Name))){
}
}
}
if ((“submesh0”.equals(Name))) {
Transform asd= CurrentTarget.getWorldTransform();
asd.setTranslation(CurrentTarget.getLocalTranslation());
Vector3f qwe=CurrentTarget.getLocalTranslation();
qwe.set(target.getWorldTranslation().x-1f, 0f,target.getWorldTranslation().z-1f);
CurrentTarget.getWorldTranslation().set(qwe);
}
}[/java]
submesh0 - it is geometry where mast stay selected figur.
That’s all.
Please help me. Thanks
and yet, all the pieces are loaded into a scene like this
[java]
private void loadFigures(){
White=new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
Black=new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
White.setColor("Color", ColorRGBA.Magenta);
Black.setTexture("ColorMap", assetManager.loadTexture("Textures/dirt.jpg"));
for (i=0;i<8;i++){
Spatial Pawn=assetManager.loadModel("Models/Pawn.j3o");
Pawn pawn = new Pawn(Pawn,White);
pawn.setLocalTranslation(-1f, 0f, 5f-i3);
figurs[1] = pawn.NodePawn();
rootNode.attachChild(figurs[1]);
}
for (i=0;i<8;i++){
Spatial pawn=assetManager.loadModel("Models/Pawn.j3o");
pawn.setLocalTranslation(14f, 0f, 5f-i3);
pawn.setMaterial(Black);
figurs[0] = pawn;
rootNode.attachChild(pawn);
}
[/java]
P.S.
Please forgive me for bad code.
What do u mean about “save”? Ask good questions!
Not all from this forum can read minds like normen :P.
I think what he means is that once he selects a target, e.g. the line “CurrentTarget = target” is executed, it is not possible to select another target.
Ah yes.
I want to keep the selected object and then select another object and put in its place that has been kept.
CurrentTarget = target; this I try keep the fist selected object.
Then i select other (second) object and if it is “submesh0”, I put the first object to the place of the second object.
Problem: I choose the first object moves it to another location. Choose the second object is moving it. I want to again choose the first object and move it again, but moved to second. :o