본문 바로가기
LibGdx

libgdx-collision handling 2 (collision, bullet engine)

by ses jeon 2019. 11. 18.

=============== Continue from previous chapter ====================
Let's add a dynamic world for crash testing.
If you don't have enough knowledge, read xoppa's blog too.

=============== 이전 장에서 이어집니다 ====================

충돌 테스트를 위한 dynamic world를 추가하겠습니다.

관련 지식이 부족하다면, 역시 xoppa의 블로그를 읽어주세요.

https://xoppa.github.io/blog/using-the-libgdx-3d-physics-bullet-wrapper-part1/

 

Using the libGDX 3D physics Bullet wrapper - part1 | blog.xoppa.com

Many 3D games require some sort of collision detection between 3D objects. Sometimes it's possible to do this with some basic math and bounding boxes and...

xoppa.github.io

Let's create an automation class by gathering the dynamic world settings.

dynamic 월드 설정을 모아서 자동화 클래스를 만들겠습니다.

Number 1 is the dynamic world setting. There are many parts to dispose twice. Collect it.

1번은 dynamic 월드 세팅입니다. 2번 dispose해야될 부분이 많습니다. 모아줍니다.

And add world in mainPage as above and add each collision body.

Next, let's modify the motion state. When you use motion state, you control the actual movement in getWorldTransform, setWorldTransform of motion state. Go to PrimitiveModel.

그리고 위처럼 mainPage에서 world를 추가하고, 각 collision body를 추가합니다.

 

다음으로 motion state를 수정해봅니다. motion state를 사용하면 motion state의 getWorldTransform, setWorldTransform에서 실제 이동을 컨트롤합니다. PrimitiveModel로 갑니다.

No. 1, if there is a bouding line, it should be done when changing location information. This is the link.
2 brings the changes in the motion state into the transform.
3 Change the Primitive model itself, and change the bouding line if there is one.

1번, 만약 bouding line이 있다면 위치정보변경시 같이 해주어야한다. 이때 링크이다.

2는 motion state의 변경 내용을 transform으로 가져온다.

3 Primitive 모델 자신을 변경하고, bouding line이 있다면 같이 변경한다.

Reflect it like this:

Go back to mainPage and set the location. Before that, use the Callback filter. The callback filter extracts only the callbacks that need to be notified of conflicts. Let's drop the sphere and use the cube like ground. You can see that sphere is a moving model using CF_CUSTOM_MATERIAL_CALLBACK.

다음처럼 반영시킵니다.

 

다시 mainPage로 돌아와서 위치설정을 해줍니다. 그러기 전에 Callback 필터를 사용합니다. callback필터는 충돌을 알려주는 callback을 필요한 것만 뽑아서 해줍니다. sphere는 떨어뜨리고, cube는 ground처럼 사용하겠습니다. sphere는 CF_CUSTOM_MATERIAL_CALLBACK을 써서 움직이는 모델임을 알수 있습니다.

And in PrimitiveModel, the box model is set to non-moving ground by giving mass = 0.

그리고 PrimitiveModel에서 box model은 mass=0 를 주어서 움직이지 않는 ground로 설정합니다.

The preparation stage is as follows.

Now let's give gravity and run the dynamic world.

다음처럼 준비단계가 다 되었습니다.

 

이제 중력을 주고, dynamic world를 실행시키겠습니다.

Running screen

실행화면

core.zip
0.01MB

========== Next Post =========================

========== 다음 포스트에 이어집니다 =========================

 

 

 

 

 

댓글