Sin and cos suspension ball to callback Activity

if (getDistance(x, mStartX, y, mStartY) < moveRange) {
updateViewPosition();
} else {
//斜率
float k = (y - mStartY) / (x - mStartX);
double rx;
double ry;
rx = Math.sqrt(moveRange * moveRange / (k * k + 1));
if ((x - mStartX) < 0) {
rx = -rx;
}
ry = k * rx;
wmParams.x = (int) (rx + 700);
wmParams.y = (int) (ry + 1900);
//回调sin,cos
listener.onSpeakListener(ry / radius, rx / radius);
wm.updateViewLayout(this, wmParams); //刷新显示
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
. 17
18 is
the Activity reception parameters

customeMovebutton.setOnSpeakListener(new CustomeMovebutton.OnSpeakListener() {
@Override
public void onSpeakListener(double sin, double cos) {
speedLat = -speed * sin;
speedLon = speed * cos;
}
});
————————————————

Guess you like

Origin www.cnblogs.com/liyanyan665/p/11414340.html