# How to maximum height and body to move in projectile motion( on Canvas)

**Really.anybody Know't this question's Answer? **

I asked this question before, but I think I worded it badly and thus did not get any response. I am trying to use an projectile motion in my game. It works. But Canvas coordinate system to Left Top corner to calculate. So projectile point is inverted. I don't know how to maximum height and body to move in point. please help me. Thank you!

Here is my code:

public class strak extends View {

public float x;
public float y;
private Controller controller;
private ProjectileEquation projectileEquation;
public int trajectoryPointCount = 20;
public float timeSeparation = 1/3f;

float x1, x2, y1, y2;
private Bitmap bmp;

public static class ProjectileEquation {

public float gravity;
public Vector2 startVelocity = new Vector2();
public Vector2 startPoint = new Vector2();

public float getX(float t) {
return startPoint.x + t * startVelocity.x;
}

public float getY(float t) {

return 0.5f * gravity * t * t + startVelocity.y * t + startPoint.y;
}
}

public static class Controller {
public float power = 10f;
public float angle = 0f;
}

public strak(Context context) {
super(context);
this.controller = new Controller();
this.projectileEquation = new ProjectileEquation();
this.projectileEquation.gravity = 10f;
Log.i("BitmapFactory", "Create!");
bmp = BitmapFactory.decodeResource(getResources(),R.drawable.boll);
yyyyyy();
}

private void yyyyyy() {
projectileEquation.startVelocity.set( controller.power,0f);
projectileEquation.startVelocity.rotate(controller.angle);
}

@Override
public boolean onTouchEvent(MotionEvent ev) {

x2 = ev.getX();
y2 = ev.getY();

invalidate();

long startTime = System.nanoTime();
float deltaTime = (System.nanoTime() - startTime) / 1000.000f;
startTime = System.nanoTime();

if((y1 < y2 )&& (x1 < x2)){

controller.angle-= .2* deltaTime;
controller.power-= .2* deltaTime;
Log.i("LOG_TAG,", "Right to Down Cros");
}
if((y1 > y2 )&& (x1 > x2)){
controller.angle+= .2* deltaTime;
controller.power+= .2* deltaTime;
Log.i("LOG_TAG,", "Down to Right Cros");
}
if((y1 > y2 )&& (x1 < x2)){
controller.angle+= .2* deltaTime;
controller.power+= .2* deltaTime;
Log.i("LOG_TAG,", "Down to Left Cros");
}
if((y1 < y2 )&& (x1 > x2)){
controller.angle-= .2* deltaTime;
controller.power-= .2* deltaTime;
Log.i("LOG_TAG,", "Left to  Down Cros");
}
switch (ev.getAction()) {

case MotionEvent.ACTION_DOWN:

case MotionEvent.ACTION_MOVE:
Log.i("LOG_TAG,", "ACTION_MOVE:");
x1 = ev.getX();
y1 = ev.getY();
}
return true;
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
yyyyyy();
float t = 0f;
x = getWidth() / 2;
y = getHeight()/2;
float timeSeparation = this.timeSeparation;

for (int i = 0; i < trajectoryPointCount; i++) {
float x = this.x + projectileEquation.getX(t);
float y = this.y + projectileEquation.getY(t);

canvas.drawBitmap(bmp, x, y, null);
t += timeSeparation;
}
}
}

• No one answers because we don't understand what you need, and your code is quite unclean, so no one wants to take a plunge and understand what you're trying to achieve. – Alexandre Vaillancourt Jul 13 '16 at 15:35
• fast sorry sar. I want a parabola on my Canvas. but Canvas calculate coordinate system to Left Top corner.so I want Draw Left Bottom. – user82700 Jul 14 '16 at 2:43
• yToDaw = canvas.height - computedY? – Alexandre Vaillancourt Jul 14 '16 at 3:03
• Yes sar.Right... – user82700 Jul 14 '16 at 3:11
• but .how to do set – user82700 Jul 14 '16 at 3:18

float y = -(this.y + projectileEquation.getY(t));