I made a simple code to get the ball's bouncing position, but I definitely missed something because I get the following:
Here is the code to get the x and y positions:
public Vector2f[] draw() { float x = 0, y = height; // height - float value from class constructor; ArrayList<Vector2f> graphic = new ArrayList<Vector2f>(); for(;;){ Vector2f a = new Vector2f(x, y); graphic.add(a); ySpeed -= 10; y += ySpeed*Math.cos(angle); x += xSpeed*Math.sin(angle); if(y <= 0){ // float coef = -10 * y / ySpeed; // ySpeed = ((ySpeed + coef) * (-1) ) * bouncyness; ySpeed = (ySpeed * (-1)) * bouncyness; System.out.println(ySpeed + " " + y); y = 0; } if(x > Main.width) break; } Vector2f[] graphicArray = new Vector2f[graphic.size()]; for (int i = 0; i < graphic.size(); i++) { graphicArray[i] = graphic.get(i); } return graphicArray; }
y , X . ,, max height, , height.,y 0, ( , ).height 10 10, .
y
height
10
if ( y <= 0) if ( y<= 10 ) y = 0.( ), y = Math.abs(y)
if ( y <= 0)
if ( y<= 10 )
y = 0
y = Math.abs(y)
angle
, .
x += v + acc * ∆time * ∆time * 0.5; v += acc * ∆time;
y = -y, y < 0.
y = -y
∆time - 1, acc - -10, .
∆time
1
acc
-10
Source: https://habr.com/ru/post/1570281/More articles:Opencv laser line recognition - opencvbandpass FIR filter - c ++SHA256 gives 44 output lengths instead of 64 lengths - c #how can I insert a frame at a specific index into a video using ffmpeg or opencv - javaHow to add image to Highcharts Title and subtitles - javascriptonclick on link should open unclosed tabs - javascriptC # - Services, how to set initial parameters - windowsManaging Connections Deploying the Azure Cloud Service - azureDo I need to write my own proxy processing code for OkHttp on Android? - androidWhy does Spark send a spark-submit script to ignore `-num-executors`? - yarnAll Articles