2
\$\begingroup\$

enter image description hereWhy isn't the rendered shape a parabola?

@Override
public void render () {
    Gdx.gl.glClearColor(1, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    renderer.begin(ShapeRenderer.ShapeType.Filled);
    position.x += 1;
    position.y = position.x * position.x ;
    renderer.circle(position.x,position.y,radius);
    renderer.end();
}
\$\endgroup\$
  • 2
    \$\begingroup\$ It's difficult to convey the motion of the circle with a still screenshot. Have you considered recording a video or an animated gif with something like LICEcap? \$\endgroup\$ – DMGregory Jul 8 '17 at 17:10
  • \$\begingroup\$ Why isn't the rendered shape a parabola? You only render a circle... \$\endgroup\$ – Cedric Martens Jul 8 '17 at 17:23
  • \$\begingroup\$ you're clearing your buffer every step. \$\endgroup\$ – Sidar Jul 8 '17 at 17:59
  • \$\begingroup\$ If you've solved your problem, please consider describing your solution in an answer, and marking it accepted. This helps give the question some closure, so the system won't keep bumping it to attract new answers. \$\endgroup\$ – DMGregory Jul 9 '17 at 2:39
2
\$\begingroup\$

Your function acts like the y = x^2 function:

enter image description here

As you can see, it acts the same for positive and negative arguments, but it's mirrored through the Y axis. To achieve a parabola, you need to give it a range like (-5,5) or (-100,100). What you probably did is you set the x to 0 or 1.

In order to achieve what you want, you should write:

float xOffset = 100;

@Override
public void render () {
    Gdx.gl.glClearColor(1, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    renderer.begin(ShapeRenderer.ShapeType.Filled);
    float newX = ++position.x;
    position.x = xOffset + newX;
    position.y = newX * newX;
    renderer.circle(position.x,position.y,radius);
    renderer.end();
}

The xOffset will move your entire circle by x pixels right.

\$\endgroup\$
  • \$\begingroup\$ the circle seems to go vertically upwards. Maybe because my eye cant catch it ? the next pixel on the x axis is very close to the previous and the y is increasing very fast so it goes off the screen . please comment \$\endgroup\$ – satyam singhal Jul 8 '17 at 16:26
  • \$\begingroup\$ Please, provide a screenshot. \$\endgroup\$ – Jacob Jul 8 '17 at 16:27
  • 1
    \$\begingroup\$ Keep in mind that, without a small scaling factor on the y, it quickly outspeeds x. By the time the object has moved 5 pixels sideways, it's crossed 30 vertically. After 10 pixels sideways it's travelled 110 vertically. That's sharp enough to look straight vertical in a quick motion, and it doubles that height again four pixels later. If your eye can't catch it, have you tried applying a small multiplier (eg. 0.01) to your y movement to slow it down and see what it's doing more clearly? \$\endgroup\$ – DMGregory Jul 8 '17 at 17:17
  • \$\begingroup\$ @DMGregory I scaled it down and it seems to work now ,thanks :) \$\endgroup\$ – satyam singhal Jul 8 '17 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.