Ok jim it's run.
I look the code of Keyboard and I had a revelation.
The source code for SpaceMouse for somebody who will need it :
Code: Select all
public void pollAndProcessInput()
{
try {
if (firstTimeJNI) {
initialize();
siapp = new JNIsiapp();
siapp.SiInitialize();
siapp.SiOpenWinInit(nomFrame,"eventCallback");
siapp.SiOpen();
firstTimeJNI = false;
}
//Fonction bloquante qui attend un évenement
siapp.SiWaitForEvent();
//Si un nouvel évenement est survenu alors
if (siapp.SiIsNewDataAvail()) {
//On recupère cette evenement
siapp.SiGetEvent();
//Evenement d'appui sur la souris
if (siapp.event.type == JNIsiapp.SiEventType.SI_MOTION_EVENT)
{
// Get the current View Platform transform into a transform3D object.
vpTrans = s3d.getVueTrans();
//vpTrans = s3d.getVueTrans();
// Extract the position, quaterion, and scale from the transform3D.
//On recupère le scalaire - Le criterion - Le Vecteur de position
vpScale = vpTrans.get(vpQuat, vpPos);
double deltaTime = (double) getDeltaTime();
deltaTime *= 0.001 * Math.abs(speedFactor);
scaleRot = 0.5; scaleScale = 4.0;
scaleVel = 1.0;
/*
* Processing of rotation motion keys.
*/
udAng = lrAng = 0.0;
a.x = a.y = a.z = 0.0; /* acceleration initially 0 */
JNI_TX = siapp.event.mData[JNIsiapp.SI_TX];
JNI_TY = siapp.event.mData[JNIsiapp.SI_TY];
JNI_TZ = siapp.event.mData[JNIsiapp.SI_TZ];
JNI_RX = siapp.event.mData[JNIsiapp.SI_RX];
JNI_RY = siapp.event.mData[JNIsiapp.SI_RY];
JNI_RZ = siapp.event.mData[JNIsiapp.SI_RZ];
abs_TX = Math.abs(JNI_TX);
abs_TY = Math.abs(JNI_TY);
abs_TZ = Math.abs(JNI_TZ);
abs_RX = Math.abs(JNI_RX);
abs_RY = Math.abs(JNI_RY);
abs_RZ = Math.abs(JNI_RZ);
int maxTranslation = Math.max(abs_TX , abs_TY);
int valmaxTranslation = Math.max(maxTranslation, abs_TZ);
int maxRotation = Math.max(abs_RX , abs_RY);
int valmaxRotation = Math.max(maxRotation, abs_RZ);
//int valMax = Math.max(valmaxRotation, valmaxTranslation);
if((valmaxRotation > 1 && valmaxRotation <200> 1 && valmaxTranslation<200)){
if(valmaxTranslation == abs_TX)
//TX--
//LEFT_ARROW=4
//ALT = 2048
if(JNI_TX<0) {
leftAcc.setX(-abs_TX);
leftDrag.setX(1000);
accSpaceMouseAdd(a, leftAcc, leftDrag, scaleVel);
}
else
{
//TX++
//RIGHT_ARROW=8
rightAcc.setX(abs_TX);
rightDrag.setX(-1000);
accSpaceMouseAdd(a, rightAcc, rightDrag, scaleVel);
}
else if(valmaxTranslation == abs_TY)
if(JNI_TY<0)
{
//TY--
//PAGE_UP=64
upAcc.setY(abs_TY);
upDrag.setY(-250);
accSpaceMouseAdd(a, upAcc, upDrag, scaleVel);
}
else
{
//TY++
//PAGE_DOWN=128
downAcc.setY(-abs_TY);
downDrag.setY(250);
accSpaceMouseAdd(a, downAcc, downDrag, scaleVel);
}
else if(valmaxTranslation == abs_TZ)
if(JNI_TZ<0) {
//TZ++
//UP_ARROW=1
bwdAcc.setZ(abs_TZ);
bwdDrag.setZ(-1000);
accSpaceMouseAdd(a, bwdAcc, bwdDrag, scaleVel);
}
else{
//TZ--
//DOWN_ARROW=2
fwdAcc.setZ(-abs_TZ);
fwdDrag.setZ(1000);
accSpaceMouseAdd(a, fwdAcc, fwdDrag, scaleVel);
}
if(valmaxRotation == abs_RX && valmaxRotation!=0)
if(JNI_RX<0)
{
udAng = (double) downRotAngle;
}
else
{
udAng = (double) upRotAngle;
}
else if(valmaxRotation == abs_RY && valmaxRotation!=0)
if(JNI_RY<0)
{
lrAng = (double) rightRotAngle;
}
else
{
lrAng = (double) leftRotAngle;
}
else if(valmaxRotation == abs_RZ && valmaxRotation!=0)
if(JNI_RZ<0)
{
RzAng = (double) RotZAngLeft;
}
else
{
RzAng = (double) RotZAngRight;
}
}
pre = navVec.z + a.z * deltaTime;
if (pre < 0.0) {
if (pre + fwdDrag.z * deltaTime <0> 0.0) {
if (pre + bwdDrag.z * deltaTime > 0.0)
a.add(bwdDrag);
else
a.z -= pre/deltaTime;
}
pre = navVec.x + a.x * deltaTime;
if (pre < 0.0) {
if (pre + leftDrag.x * deltaTime <0> 0.0) {
if (pre + rightDrag.x * deltaTime > 0.0)
a.add(rightDrag);
else
a.x -= pre/deltaTime;
}
pre = navVec.y + a.y * -deltaTime;
if (pre < 0.0) {
if (pre + downDrag.y * deltaTime <0> 0.0) {
if (pre + upDrag.y * deltaTime > 0.0)
a.add(upDrag);
else
a.y -= pre/deltaTime;
}
/* Integration of acceleration to velocity */
dv.scale(deltaTime, a);
navVec.add(dv);
/* Speed limits */
if (navVec.z <scaleVel> scaleVel * bwdVMax)
navVec.z = scaleVel * bwdVMax;
if (navVec.x <scaleVel> scaleVel * rightVMax)
navVec.x = scaleVel* rightVMax;
if (navVec.y > scaleVel * upVMax)
navVec.y = scaleVel * upVMax;
if (navVec.y < scaleVel * downVMax)
navVec.y = scaleVel * downVMax;
/* Integration of velocity to distance */
dp.scale(deltaTime, navVec);
/* Scale our motion to the current avatar scale */
// 1.0 eventually needs to be a more complex value (see hs).
// r = workplace_coexistence_to_vworld_ori.scale/
// one_to_one_coexistence_to_vworld_ori.scale;
r = vpScale/1.0;
dp.scale(r, dp);
/* Rotation due to keys being down */
lrAng *= scaleRot;
udAng *= scaleRot;
RzAng *= scaleRot;
/* Scaling of angle change to delta time */
lrAng *= deltaTime;
udAng *= deltaTime;
RzAng *= deltaTime;
/* Addition to existing orientation */
// vr_quat_inverse(&workplace_coexistence_to_vworld_ori.quat, &vpQuat);
// vpQuat gotten at top of method.
vpQuat.inverse();
if(lrAng != 0.0) {
genRotQuat(lrAng, 1, lrQuat);
vpQuat.mul(lrQuat, vpQuat);
}
if(udAng != 0.0) {
genRotQuat(udAng, 0, udQuat);
vpQuat.mul(udQuat, vpQuat);
}
if(RzAng != 0.0) {
genRotQuat(RzAng, 2, rZQuat);
vpQuat.mul(rZQuat, vpQuat);
}
/* Rotation of distance vector */
vpQuat.inverse();
vpQuat.normalize(); /* Improvment over HoloSketch */
mat.set(vpQuat);
mat.transform(dp);
// add dp into current vp position.
vpPos.add(dp);
/* Final update of view platform */
// Put the transform back into the transform group.
vpTrans.set(vpQuat, vpPos, vpScale);
spaceMouseSensor.setNextSensorRead(
System.currentTimeMillis(),
vpTrans,
new int[0]
);
}
//Bouton d'évenemenent
else if (siapp.event.type == JNIsiapp.SiEventType.SI_BUTTON_EVENT)
{
setNominalPositionAndOrientation();
}
// Button event
else if (siapp.event.type == JNIsiapp.SiEventType.SI_ZERO_EVENT)
{
}else if(siapp.event.type == JNIsiapp.SiEventType.SI_KEYBOARD_EVENT){
}
}
} catch (Exception e) {
System.out.println("Exception in JNIsiappThread: "+e);
siapp.SiClose();
siapp.SiTerminate();
}
}