0
겹치는 원 끌고 두 Circle
의 제 드래그하고 고정 제는, I는 중복없이 제 주위 첫번째 (드래그으로 )를 회전 할방지, 난이 제목에 언급 된 바와 같이
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class Collision extends Application{
private Pane root = new Pane();
private Scene scene;
private Circle CA = new Circle(20);
private Circle CB = new Circle(20);
private double xOffset = 0;
private double yOffset = 0;
@Override
public void start(Stage stage) throws Exception{
initCircles();
scene = new Scene(root,500,500);
stage.setScene(scene);
stage.show();
}
private void initCircles(){
CA.setCenterX(100);
CA.setCenterY(100);
CA.setFill(Color.rgb(255, 0, 0,0.2));
CA.setStroke(Color.BLACK);
CB.setCenterX(250);
CB.setCenterY(200);
CB.setFill(Color.rgb(255, 0, 0,0.2));
CB.setStroke(Color.BLACK);
CA.setOnMousePressed(evt->{
xOffset = CA.getCenterX() - evt.getSceneX();
yOffset = CA.getCenterY() - evt.getSceneY();
});
CA.setOnMouseDragged(evt->{
//get Scene coordinate from MouseEvent
drag(evt.getSceneX(),evt.getSceneY());
});
root.getChildren().addAll(CA,CB);
}
private void drag(double x, double y){
/* calculate the distance between
* the center of the first and the second circle
*/
double distance = Math.sqrt (Math.pow(CA.getCenterX() - CB.getCenterX(),2) + Math.pow(CA.getCenterY() - CB.getCenterY(),2));
if (!(distance < (CA.getRadius() + CB.getRadius()))){
CA.setCenterX(x + xOffset);
CA.setCenterY(y + yOffset);
}else{
/**************THE PROBLEM :Condition to drag************/
CA.setCenterX(CA.getCenterX() - (CB.getCenterX()-CA.getCenterX()));
CA.setCenterY(CA.getCenterY() - (CB.getCenterY()-CA.getCenterY()));
/*What condition must be established for the
* circle to behave correctly
*/
/********************************************************/
}
}
public static void main(String[] args) {
launch(args);
}
}
: 그들하지만 내 Circle
내가 오류가 드래그 상태에서 오는 확신하지만 난 그것을 해결하는 방법을 모른다, 이상한 반응, 그게 내가 당신의 도움이 필요한 이유, 여기에 최소 및 테스트 가능한 코드입니다 간략한 개요는 다음과 같습니다.
참고 : 내 방어를위한 , 내가 검색 및 내 여러 피사체가 가까운 찾았지만있는 더 정확한 또는 정확한 솔루션, 사이가 없다 :
-The circle remains blocked at the time of the collision
-Two circle that push each other
을 -JavaScript, Difficult to understand and convert to java
도움 주셔서 감사합니다.
정확히 내가 원했던 것, 감사합니다! –