0

I'm not even sure what code to share, but maybe someone's been in a similar situation or has a good suggestion.

I'm basically rendering a sphere in the middle of the screen (placed at (0, 0, 0)) and it looks fine. However, if I choose to render the same sphere further away from the origin, it gets an egg shape. I think the egg shape is in the direction of the translation. Here's the code that sets up the model matrix:

Matrix.setIdentityM(mModelMatrix, 0);
Matrix.scaleM(mModelMatrix, 0, 0.15f, 0.15f, 0.15f);
Matrix.translateM(mModelMatrix, 0, 0, 0, distance);

When distance = 0, the sphere shows up normally, however if distance = -1.5f, then the sphere is sort of stretched on the z axis. Any suggestions for fixing this behavior?

async
  • 745
  • 1
  • 7
  • 23

1 Answers1

0

Scaling is based off the origin. Therefore you want to make sure to scale your object before translating it. Otherwise your scaling will be done as if the centre of the object is still (0.f, 0.f, 0.f).

  • Thanks for the tip, but the effect is still there. – async Dec 20 '13 at 14:32
  • What happens if you translate the sphere but don't scale it, does the distortion still appear? –  Dec 20 '13 at 14:55
  • Nope, still there. I'm thinking whether this effect has anything to do with the sphere. This is part of a Solar System and I have just noticed that when I render Saturn and rotate it such that the camera is facing one of the poles, the rings have a subtle umbrella-effect. So if my camera is looking from above at the North Pole, the rings look like the top of an umbrella. It becomes more obvious when I scale them up. I think something happens to all pixels when you render them further from the origin. – async Dec 20 '13 at 15:06
  • 1
    Try setting the aspect ratio to a lower value, usually between 45 to 90 degrees. –  Dec 20 '13 at 15:09
  • How would I change that? At the moment I'm setting my projection matrix in the standard way: Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far); where left = -width/height, right = width/height and bottom=-1, top=1, near=1, far = 10 – async Dec 20 '13 at 15:20
  • 1
  • 1
    That fixed it. I appreciate your support, mate. Have a great day! – async Dec 21 '13 at 12:57