2012-06-22 50 views
0

這裏是我的問題:我在android中製作遊戲池遊戲,我想讓相機在桌子中心周圍自由旋轉。問題是,當我停止移動時,看起來glulookat會重置,因爲我只能看到同樣的事情。如果有人知道如何解決此問題的方法或另一種方式做我watn做我會非常感激glulookat「重置」移動後(使用android)

這是我的渲染器類:

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); 

,這裏是我的onTouch方法我活動類:

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; 
} 

回答

0

當你做數學題,你使用mMoveXmMoveY。看起來應該是添加到其他更持久的x/y變量中。

喜歡的東西:

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

仍然不完全一樣的東西,還是要謝謝你,我覺得問題是,不知我的gluLookAt參數重新設置自己因此總是回來到初始位置(0,0,0) 。不管怎麼說,還是要謝謝你 – ThargtG