2012-06-22 3 views
0

voici mon problème: je fais un jeu de billard dans android et je veux faire tourner la caméra librement autour du centre de la table. La chose est que quand j'arrête mon mouvement, il semble que le glulookat se réinitialise parce que je ne vois que la même chose encore et encore. Si quelqu'un connaît un moyen sur la façon de résoudre ce ou d'une autre façon de faire ce que je watn à faire, je serais vraiment appréciéglulookat "réinitialise" après le mouvement (avec android)

Voici ma classe renderer:

public void onDrawFrame(GL10 gl) { 


    // Redraw background color 
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 

    // Set GL_MODELVIEW transformation mode 
    gl.glMatrixMode(GL10.GL_MODELVIEW); 

    gl.glLoadIdentity(); // reset the matrix to its default state 



    // Screen position to angle conversion 
    theta = (float) ((360.0/screenHeight)*mMoveY*3.0); //3.0 rotations possible 
    phi = (float) ((360.0/screenWidth)*mMoveX*3.0); 

    // Spherical to Cartesian conversion. 
    // Degrees to radians conversion factor 0.0174532 
    eyeX = (float) (r * Math.sin(theta/**0.0174532*/) * Math.sin(phi/**0.0174532*/)); 
    eyeY = (float) (r * Math.cos(theta/**0.0174532*/)); 
    eyeZ = (float) (r * Math.sin(theta/**0.0174532*/) * Math.cos(phi/**0.0174532*/)); 

    // Reduce theta slightly to obtain another point on the same longitude line on the sphere. 

    eyeXtemp = (float) (r * Math.sin(theta/**0.0174532*/-dt) * Math.sin(phi/**0.0174532*/)); 
    eyeYtemp = (float) (r * Math.cos(theta/**0.0174532*/-dt)); 
    eyeZtemp = (float) (r * Math.sin(theta/**0.0174532*/-dt) * Math.cos(phi/**0.0174532*/)); 

    // Connect these two points to obtain the camera's up vector. 
    upX=eyeXtemp-eyeX; 
    upY=eyeYtemp-eyeY; 
    upZ=eyeZtemp-eyeZ; 

    // Set the view point 
    GLU.gluLookAt(gl,  eyeX, eyeY, eyeZ,  0,0,0,  upX, upY, upZ); 

et voici ma méthode de OnTouch dans mon classe d'activité:

public boolean onTouchEvent(MotionEvent e) { 

    float x = e.getX(); 
    float y = e.getY(); 

    switch (e.getAction()) { 
    case MotionEvent.ACTION_MOVE: 

     float dx = x - mPreviousX; 
     float dy = y - mPreviousY; 

     // reverse direction of rotation above the mid-line 
     /*if (y > getHeight()/2) { 
      dx = dx * -1 ; 
     } 

     // reverse direction of rotation to left of the mid-line 
     if (x < getWidth()/2) { 
      dy = dy * -1 ; 
     }*/ 

     mRenderer.mMoveX = dx * TOUCH_SCALE_FACTOR/100; 
     mRenderer.mMoveY = dy * TOUCH_SCALE_FACTOR/100; 

     requestRender(); 
    } 

    mPreviousX = x; 
    mPreviousY = y; 
    return true; 
} 

Répondre

0

Lorsque vous faites le calcul, vous utilisez mMoveX et mMoveY. Il semble que vous deviez ajouter à d'autres variables x/y plus persistantes.

Quelque chose comme:

mCamX += mMoveX; 
mCamY += mMoveY; 
theta = (float) ((360.0/screenHeight)*mCamY*3.0); //3.0 rotations possible 
phi = (float) ((360.0/screenWidth)*mCamX*3.0); 
+0

ne fonctionne toujours exactement la même chose, merci quand même, je pense que le problème est que venir en quelque sorte mes paramètres gluLookAt se réinitialisent donc toujours à la position initiale (0,0,0) . Merci quand même – ThargtG

Questions connexes