Not precise positioning in Android (OpenGL ES 2.0)

OnDrawFrame I am calling Matrix.setLookAtM, Matrix.multiplyMM, Matrix.translateM, Matrix.scaleM a lot because I need to render different objects in 2D. I have created two objects - circle (How to draw basic circle in OpenGL ES 2.0 Android - Stack Overflow) and line. I render many of them by changing their position, color and scale. There might be some more extra work in GLRenderer class to calculate correct position after receiving information from network. The problem is that shake effect appears as other objects moves a little bit upside and down when I’m trying to translate one object’s position by 1f each second and to lock view on it (trying to move).

Device might be running on 30 FPS.

DDMS information:
[ATTACH=CONFIG]84[/ATTACH]

I have managed to capture the screenshots of the actual problem:
[ATTACH=CONFIG]85[/ATTACH][ATTACH=CONFIG]86[/ATTACH]

As you can see in this example only the light blue bubble with border moves with the grid. The problem is that that the orange bubble with border moves randomly up and down (same happens with other axis - it depends on where the player is moving) when I’m changing light blue bubble position. While idling nothing happens. The difference of the orange bubble position on Y axis is about 0.03f-0.05f when this happens. After this happens it moves back to it’s real position. So this happens only for a very short moment and about 5-10 times a second.
In this case the coordinates of circles with borders were around -2f both X and Y.

P.S. Multisampling anti-lasing is 4x, problem persists with depth size 16 and 24.

This is how I draw circles:


        float camera = -3.01f
        for (float[] cp : buffer.cp) {
	    	int colour = Float.valueOf(cp[0]).intValue()*6;

	    	int i = 0;
	       	for (int i = 0; i < cp[1]; i += 3) {
	       		Matrix.setLookAtM(mViewMatrix, 0, cp[2+i], cp[3+i], zoom, cp[2+i], cp[3+i], 0f, 0f, 1f, 0f);
		        Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);
		        Matrix.scaleM(mMVPMatrix, 0, cp[4+i], cp[4+i], 1f);
		        Matrix.translateM(mMVPMatrix, 0, 0f, 0f, camera);
		        mCircle.setColor(GameUtils.colours[colour], GameUtils.colours[colour+1], GameUtils.colours[colour+2], 1f);
		        mCircle.draw(mMVPMatrix);
		        
		        Matrix.scaleM(mMVPMatrix, 0, 0.85f, 0.85f, 1f);
		        mCircle.setColor(GameUtils.colours[colour+3], GameUtils.colours[colour+4], GameUtils.colours[colour+5], 1f);
		        mCircle.draw(mMVPMatrix);
	       	}
	    }

cp[2+i] - final X coordinate
cp[3+i] - final Y coordinate
cp[4+i] - final object scale compared to zoom value

public void onSurfaceChanged(GL10 unused, int width, int height) {
        GLES20.glViewport(0, 0, width, height);
        
        this.width = width;
        this.height = height;
        ratio = (float) width / height;
        ratioInv = (float) Math.pow(ratio, -1);
        
        // This projection matrix is applied to object coordinates in the onDrawFrame() method
        Matrix.frustumM(mProjectionMatrix, 0, -ratio, ratio, -1, 1, 3, 50);
    }

I have tried to change Far value and set zoom variable to -10f or -20f but it didn’t helped.

temp[2] = (playerPart.getPosX()-buffer.diffX);
temp[3] = -(playerPart.getPosY()-buffer.diffY);
temp[4] = GameUtils.PLAYER_SIZE;

This is how I calculate circle position. Buffer.diffX and buffer.diffY are the main player’s coordinates (temp = cp).

After some research I found that there were problem with Android application optimization. The delay was not related to OpenGL ES 2.0.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.