1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
public void setDrone(double phi, double theta, double psi, double x, double y, double z) {
// On sauve les positions demandées
this.x = (float)x;
this.y = (float)y;
this.z = (float)z;
this.phi = phi;
this.theta = theta;
this.psi = psi;
// On recupere la position de l'avion
objTrans.getTransform(transfoShape);
// on applique Euler
transfoShape.setEuler(new Vector3d(Math.toRadians(-phi), Math.toRadians(psi), Math.toRadians(theta)));
// on le translate
transfoShape.setTranslation(new Vector3d(x, z, -y));
// Transfo 3D de l'avion
objTrans.setTransform(transfoShape);
// positionnement de la camera
setCamera(cameraMode);
}
/**
* Position la camera en fonction du mode
* @param mode
*/
public void setCamera(int mode) {
cameraMode = mode;
if (mode==CAMERA_FIXED) return;
// On recupere le TG de la camera
TransformGroup view=universe.getViewingPlatform().getViewPlatformTransform();
Transform3D trans=new Transform3D();
view.getTransform(trans);
Vector3f currentPosition = new Vector3f();
// get camera position
trans.get(currentPosition);
// get camera rotation
Quat4d rotation = new Quat4d();
trans.get( rotation );
if (mode == CAMERA_FOLLOWS) {
// La camera suit l'avion : OK
trans.lookAt(new Point3d(x+2, z+2, -y-2), new Point3d(x, z, -y), new Vector3d(0,1,0));
} else if (mode == CAMERA_POINTS) {
// Camera fixe en position mais suit l'avion : OK
trans.lookAt(new Point3d(2, 0.1, -2), new Point3d(x, z, -y), new Vector3d(0,1,0));
} else if (mode == CAMERA_PILOT) {
// La camera est dans l'avion et subie les mouvement de l'avion
trans.lookAt(new Point3d(x, z+0.5, -y-0.5), new Point3d(x, z+0.1, -y), new Vector3d(0,1,0));
trans.setEuler(new Vector3d(Math.toRadians(-phi), Math.toRadians(psi), Math.toRadians(theta)));
}
trans.invert();
view.setTransform(trans);
} |
Partager