localhost
localhost

Reputation: 113

Objects are shaking during rendering in Android GLES 1.0.

I have a little bit of trouble with fixing bug in my game engine.

My problem is that I see elements of my hud shaking when I am moving my camera in the scene. Bug only appears when my camera is moved by finger slide. When I change it position in update method everything seems to be fine.

Render method (called from onDrawFrame() in main activity):

public void drawScene(GL10 gl)
{
    // Clear scene
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    // Move left top corner of camera to specified point
    gl.glTranslatef(-camera.getX(), screenManager.getScreenHeight() - camera.getY(), 0f);
    // Render all objects from the scene
    root.renderObjects(gl);
    // Fixed position for HUD elements
    gl.glTranslatef(camera.getX(), -screenManager.getScreenHeight() + camera.getY(), 0.0f);
    // Render hud to the screen
    hud.renderObjects(gl);
    // Get back to camera position
    gl.glTranslatef(-camera.getX(), screenManager.getScreenHeight() - camera.getY(), 0.0f);
    // Reset the matrix
    gl.glLoadIdentity();
}

Moving method (called from onTouchEvent in main activity):

public void onPointerMove(TouchPointer pointer, TouchPointer historicalPointer)
{
    Point p = new Point(pointer.getRawTouchPoint());
    p.subtract(historicalPointer.getRawTouchPoint());
    camera.moveBy(p);
}

I think this is the code that matters. But I don't see anything that I could change. If anyone got any idea please share ;)

Upvotes: 0

Views: 287

Answers (1)

PiotrK
PiotrK

Reputation: 4453

Personally I would change drawScene to

public void drawScene(GL10 gl)
{
    // Clear scene
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    // Move left top corner of camera to specified point
    gl.glTranslatef(-camera.getX(), screenManager.getScreenHeight() - camera.getY(), 0f);
    // Render all objects from the scene
    root.renderObjects(gl);
    // Fixed position for HUD elements
    gl.glLoadIdentity();
    // Render hud to the screen
    hud.renderObjects(gl);
    gl.glLoadIdentity();
}

See if it helped. The problem may be in changing camera position during renderObject (for example from external thread), or even float not being enough precise.

Upvotes: 1

Related Questions