본문 바로가기
LibGdx

libgdx-collision handling 3 (collision, bullet engine)

by ses jeon 2019. 11. 18.

================ Continue from previous chapter ====================
If you don't have enough knowledge, read xoppa's blog too.

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

관련 지식이 부족하다면, 역시 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

Now let's handle the crash event.

이번에는 충돌 이벤트를 처리해보겠습니다.

Override and add ContactListener as follows:

다음처럼 ContactListener를 재정의하고 추가합니다.

And set the userValue of the cube and sphere as follows: You can then identify the object by this userValue in the contact listener above.

Let's print

그리고 다음처럼 cube와 sphere의 userValue를 설정합니다. 그러면 위의 contact listener에서 이 userValue로 물체를 구분할수있습니다.

 

출력을 해봅니다

userValue is printed.

Add an IntMap to get the PrimitiveModel that the userValue points to. IntMap is a Map whose key is integer and has Object.

userValue가 출력되네요.

 

userValue로 그 값이 가리키는 PrimitiveModel을 가져오기 위해서 IntMap 하나를 추가합니다. IntMap는 key가 integer형이고 Object를 가지는 Map입니다.

In the event of a collision, we will change the color of the sphere and print the collision position.

충돌시, sphere의 색상을 변경하고, 충돌위치를 출력해보도록 하겠습니다.

Output screen

출력화면

core.zip
0.01MB

Finally, dispose.

마지막으로 dispose를 해봅니다.

1. Dispose the PrimitiveModel. In the previous post, the shapes of the PrimitiveModel were called links to each collsion fragment model used to create a rigid body. Dispose at this time. Dispose the collsion body and finally dispose your model.
2. modelInstance simply disposes the model.
3. Dispose the wset and contactListener.

1. PrimitiveModel을 dispose합니다. 이전 포스트에서 PrimitiveModel의 shapes는 rigid body를 만들때 사용되는 각 collsion 조각 모델들을 모은 링크라고 했습니다. 이때 dispose합니다. 그리고 collsion body를 dispose, 마지막으로 자신의 model을 dispose합니다.

2. modelInstance는 해당 model을 dispose하면 됩니다.

3. wset과 contactListener를 dispose합니다.

 

 

 

 

 

 

댓글