티스토리 뷰

<충돌 처리>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// 윗면 체크
            y                 = circle.getY();
            dist             = (float)Math.sqrt(y*y);
            if (dist < circle.getR())
            {
                circle.setY(circle.getR());
                circle.setAY(circle.getAY() * -1);
            }
            
            // 아랫면 체크
            y                = circle.getY() - cGameManager.getInstance().getGameView().getHeight();
            dist            = (float)Math.sqrt(y*y);
            if (dist < circle.getR())
            {
                circle.setY(cGameManager.getInstance().getGameView().getHeight()-circle.getR());
                circle.setAY(circle.getAY() * -1);
            }
            
            // 왼쪽면 체크
            x                = circle.getX();
            dist            = (float)Math.sqrt(x*x);
            if (dist < circle.getR())
            {
                circle.setX(circle.getR());
                circle.setAX(circle.getAX() * -1);
            }
            
            // 오른면 체크
            x                = circle.getX() - cGameManager.getInstance().getGameView().getWidth();
            dist            = (float)Math.sqrt(x*x);
            if (dist < circle.getR())
            {
                circle.setX(cGameManager.getInstance().getGameView().getWidth() - circle.getR());
                circle.setAX(circle.getAX() * -1);
            }
cs


  • 윗변과 밑변은 y축을 가지고 체크를 해주면 되기 때문에, x값은 0으로 배제를 한 상태
    • 위쪽 변을 체크할 때.
    • 밑변을 체크할 때


  • 왼쪽변과 오른쪽변을 체크할때는 마찬가지로 y축 값은 배제하고 x축을 가지고만 충돌 체크를 해준다.
    • 왼쪽 변을 체크할 때.
    • 오른쪽변을 체크할 때

<정반사>


  • 정반사는 입사각과 반사각의 크기가 같은것을 말한다.
  • 따라서, x축 변화량과 y축 변화량인 mAX, mAY를 역으로 바꿔주면 된다.
  • 위의 코드에서는 setAX와 setAX를 통해 mAX와 mAY를 역으로 바꿔준다.


'Programming > 수학&물리' 카테고리의 다른 글

사각형과 원의 충돌체크  (0) 2015.12.10
공튀기기  (0) 2015.12.02
sin, cos, tan  (0) 2015.12.02
두 원의 충돌(원과 점의 충돌)  (0) 2015.11.21
점과 직선사의 거리  (0) 2015.11.21
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함