1
OKこのアルゴリズムでは、ボールとユーザーがiPadの画面上に描く線との衝突を検出する必要があります。コードはかなりシンプルです:動くボールとラインとの衝突
for (int i = 1; i < currentPlatform; i++) {
float x1 = xStart[i] -xBall;
float y1 = yStart[i] - yBall;
float x2 = xEnd[i] - xBall;
float y2 = yEnd[i] - yBall;
float dx = x2 - x1;
float dy = y2 - y1;
float dr = sqrtf(powf(dx, 2) + powf(dy, 2));
float D = x1*y2 - x2*y1;
float delta = powf((ball.frame.size.height/2), 2)*powf(dr, 2) - powf(D, 2);
NSLog(@"%f", delta);
if (delta >= 0) {
iDir = (((ballVelocity*(sin(angle[i])))*-1)*kRestitution);//*sin(angle[i]));
jDir = (((ballVelocity*(cos(angle[i]))))*kRestitution*cos(angle[i]));
}
}
問題は、ボールが検出されない線を通過することです!そして、デルタが印刷されたコンソールでは、4trillionのような狂った答えが出ます!誰も私がこの衝突の検出に間違っている何かを見ていますか?
これは最善の方法ではないかもしれませんが、他に何も問題がなければ試してみてはいかがですか? – Jordan