Java3D : SpaceMouseDevice : Object Mode and Camera Mode

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

lololem
Posts: 37
Joined: Sat Mar 24, 2007 10:25 am

Post by lololem »

For the moment i have that :

Code: Select all

VecteurTranslation.add(new Vector3d((siapp.event.mData[JNIsiapp.SI_TX] * sensitivity),
                                     (siapp.event.mData[JNIsiapp.SI_TY] * sensitivity),
                                     -(siapp.event.mData[JNIsiapp.SI_TZ] * sensitivity))); 
                                  
                                    rX.rotX(siapp.event.mData[JNIsiapp.SI_RX] *angularRate);
                                    rY.rotY(siapp.event.mData[JNIsiapp.SI_RY] *angularRate);
                                    rZ.rotZ(siapp.event.mData[JNIsiapp.SI_RZ] *angularRate);
                                    
                                    MatriceRotation.mul( rY, MatriceRotation  );
                                    MatriceRotation.mul( rZ, MatriceRotation  );
                                    MatriceRotation.mul( rX, MatriceRotation  );
                                    
                                   Point3d targetPos = new Point3d(
                                             VecteurTranslation.x,
                                             VecteurTranslation.y,
                                             VecteurTranslation.z);
        
                                    Point3d camPos = new Point3d(
                                             ?
                                             ,?
                                             ,?);
                                    
                                    Vector3d VectDirection = new Vector3d(
                                             ?
                                             ,?
                                             ,?);
                                    vueTransform.lookAt(camPos,targetPos,VectDirection);
                                     
                                    vueTransform.invert();  
lololem
Posts: 37
Joined: Sat Mar 24, 2007 10:25 am

Post by lololem »

I may have given you a Java version of that. If not, it converts to Java easily.
I wouldn't say no !!!
lololem
Posts: 37
Joined: Sat Mar 24, 2007 10:25 am

Post by lololem »

i find the code of function lookat

it's that :

Code: Select all

public final void lookAt(Tuple3f eye, Tuple3f center, Tuple3f up) {

         /* Make rotation matrix */

         /* Z vector */
         Vector3f z = new Vector3f();
         z.x = eye.x - center.x;
         z.y = eye.y - center.y;
         z.z = eye.z - center.z;

         z.normalize();

         Vector3f y = new Vector3f(up);

         /* X vector = Y cross Z */
         Vector3f x = new Vector3f();
         x.cross(y,z);
         y.cross(z,x);

        x.normalize();
        y.normalize();

        matrix.setIdentity();

        matrix.m00 = x.x;
        matrix.m01 = x.y;
        matrix.m02 = x.z;

        matrix.m10 = y.x;
        matrix.m11 = y.y;
        matrix.m12 = y.z;

        matrix.m20 = z.x;
        matrix.m21 = z.y;
        matrix.m22 = z.z;


        //matrix.negate();
        Vector3f negEye = new Vector3f(eye);
        negEye.negate();

        Matrix4f translate = new Matrix4f();
        translate.setIdentity();
        translate.setTranslation(negEye);
        matrix.mul(matrix,translate);

        matrix.invert();
        // this put it into opengl mode, was screwing things up
//        matrix.transpose();

        setChanged(true);
    }
lololem
Posts: 37
Joined: Sat Mar 24, 2007 10:25 am

Post by lololem »

Sorry i do a mistake

is that :

Point3d camPos = new Point3d(
VecteurTranslation.x
,VecteurTranslation.y
,VecteurTranslation.z);

Point3d targetPos = new Point3d(
0,
0,
0);

and not the inverse.


There is not more than a vector of direction
jwick
Moderator
Moderator
Posts: 3341
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

You need to think about what you are trying to do. Remember the Tinker Toys. One coordinate system is the target, one is the camera. If you want to spin the camera around the target, don't move the target.

Get one degree of freedom at a time working. Start with no rotations and just get the translations working the way you want. 1 DOF at a time.

You don't need ArbitraryAxisToMatrix if you just use the small delta values Rx,Ry,Rz and accumulate them into MatriceRotation (as you are doing).

1 D O F at a time. Baby steps...
lololem
Posts: 37
Joined: Sat Mar 24, 2007 10:25 am

Post by lololem »

I do that no ?

I try like that with no rotation for the moment, just in the direction in the right (0,1,0)

Code: Select all

 
              rX.rotX(siapp.event.mData[JNIsiapp.SI_RX] *angularRate);
              rY.rotY(siapp.event.mData[JNIsiapp.SI_RY] *angularRate);
              rZ.rotZ(siapp.event.mData[JNIsiapp.SI_RZ] *angularRate);
                                   
                                    MatriceRotation.mul( rX, MatriceRotation  );
                                    MatriceRotation.mul( rY, MatriceRotation  );
                                    MatriceRotation.mul( rZ, MatriceRotation  );
                                   
                                    double x = VecteurTranslation.x;
                                    double y = VecteurTranslation.y;
                                    double z = VecteurTranslation.z;
                                    
                                    
                                   Point3d camPos = new Point3d(
                                             x
                                             ,y
                                             ,z);
                                    
                                    Point3d targetPos = new Point3d(
                                             0,
                                             0,
                                             0);
        
                                   Vector3d VectDirection = new Vector3d(
                                            0
                                             ,1
                                             ,0);

                            vueTransform.lookAt(camPos,targetPos,VectDirection);
                            vueTransform.invert(); 


It's run, you move correcty but you turn on the right

Now, i don't understand how to transform my rotation matrix to vector direction for adapt to my function ?
jwick
Moderator
Moderator
Posts: 3341
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

Think about what you are doing here. You are telling the camera position to move, apparently using all 3 translation DOFs :(, but not moving the target position. It is still looking at the center. Sooooo, if you push the camera to the right...it will still be looking at the same target position (the center). This will look like the object is rotating to the left.

Remember the table example.

Is this what you are seeing?
lololem
Posts: 37
Joined: Sat Mar 24, 2007 10:25 am

Post by lololem »

yes it's that,

Now how i adapt my three DOF Rotation ?

I have to change the target position?
jwick
Moderator
Moderator
Posts: 3341
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

I'm going to insist that you get translations working correctly first!

Think about what you need to do to get translations working correctly. If you didn't move the target point, you just rotated about it when you moved the camera. So, try moving the target in the same direction of the camera by the same amount. They will track together.

Let me know when you have this working correctly for all 3 translation DOFs.
lololem
Posts: 37
Joined: Sat Mar 24, 2007 10:25 am

Post by lololem »

Ok i think i understand what you want but i don't know how do that.

You explain me that the important it's the vector (direction) and it's stipulate by my Position Camera and my Origine of my vector, when i change my origine my vectors is recalculate and give it to me an impression of rotation.

Ok but you say me test translation by translation - I must determinate what ?

Sorry for my little comprehension... :( i am feeling stupid

Actualy when i give in this configuration :

Code: Select all

 double x = VecteurTranslation.x;
 double y = VecteurTranslation.y;
 double z = VecteurTranslation.z;

Point3d camPos = new Point3d(
                                             x
                                             ,y
                                             ,z);
                                    
                                    Point3d targetPos = new Point3d(
                                             -5,
                                             -5,
                                             -5);
        
                                   Vector3d VectDirection = new Vector3d(
                                            0
                                             ,1
                                             ,0);
when i push, you go straigt on, when il translate in right, you translate in right, but you are in front of my cube (with no rotation)

face :
Image

push :
Image

translate :
Image
jwick
Moderator
Moderator
Posts: 3341
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

#1 Don't trust any code you are given. lookAt may not work correctly. From what you describe, it isn't working correctly or you aren't using it the way it is meant to be used. Break everything down to 1 DOF at a time. I suggest you don't use any rotations for now. Just get panning and zooming working. You should have to adjust the targetPos and the cameraPos together to get what you show in the last picture.

Finally, after you set the view data, get it back from the viewing code and print it out. Verify that those numbers are being used unmangled. Verify that they make sense. Sometimes library code will modify your input data and not use it the way you are requesting if it doesn't fit the model the developer of the library had in mind.

Look at the numbers. They don't lie.
lololem
Posts: 37
Joined: Sat Mar 24, 2007 10:25 am

Post by lololem »

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();
		}
	}
lololem
Posts: 37
Joined: Sat Mar 24, 2007 10:25 am

Post by lololem »

Tchao Jim

I think that all it's ok now ;)
Post Reply