태그 : Physics

Integrating Physics with the game engine

오늘자 Sweng-Gamedev mailing list에 "물리 시스템의 게임 엔진에의 통합"과 관련한 답변으로 Jon Watte씨가 올린 글입니다.

물리 시스템은 대부분 Havoc, PhysX 등의 외부 미들웨어를 통합하는 방식을 취하고 있는데, 이 경우에도 참고하면 많은 도움이 되는 내용입니다.

아래 내용만으로는 부족하다면 Nebula2의 Mangalore 부분에서 ODE 물리 엔진을 어떻게 통합하고 있는지 아래 내용을 코드와 함께 보기 바랍니다. 쉽게 이해하는데 도움이 됩니다. 반대로 Nebula에서 물리 엔진이나 기타 시스템의 통합을 *왜*이러한 방법으로 하는지가 궁금하셨던 분들에게도 나름의 답이 될 수 있겠군요.

어느 정도 감을 잡았다면 Nebula3의 Raknet 네트워크 시스템의 통합도 같이 살펴 보길 권합니다. 방법은 거의 동일합니다.

그리고 아래 내용의 세 번째 항목에서 언급한 데이터와 관련한 내용, 사실 이 내용은 통합과는 직접적인 관련이 없을지 몰라도 외부 물리 시스템 사용시 제일 중요한 내용이라고 봅니다. 최근에는 PhysX 쪽도 3dsmax 2010용 플러그인(베타)이 나왔더군요. 시스템의 사용은 그리 어렵지 않지만 데이터를 생산하는 적절한 방법이 함께 고려되지 않으면 반쪽짜리 해결책이 되거나 사용하지 않으니만 못할 수 도 있기 때문입니다.


Integrating Physics with the game engine

I am not making a physics engine, just implementing 'as-much' physics as
required for my game


Once you start doing proxy-against-concave-mesh, and
multiple-contact-constraints, the difference will start to diminish.
Especially the "handle multiple contacts" part ends up more or less leading
you to actually write a physics engine. If you want physics without writing
a physics engine, use either an open source physics engine (Bullet, ODE) or
a "free for PC" commercial physics engine (NVIDIA PhysX, Havok Physics).

Regarding structure, I find that each subsystem should have its own data
structures, optimized for that subsystem. Thus, you may have a RigidBody
with some BodyCollisionShapes on it. Separately, you have an AnimatableMesh
with some Materials and Animations on it. You may also have a SoundSource
with some PlayingCues, and one or more SpecialEffects, and maybe even an
InputListener. Each of those are for a separate subsystem (physics,
animation, sound, scene graph, input in these cases).

The "game object" as such is the union of all these sub-components. There
are a few ways of doing that union:

1) Each subsystem allow *you* to define the ID of each subsystem object. You
say "create a rigid body, and call it '3'." A game entity is then just the
ID, and it's created as a collective hallucination of all the subsystems
that happen to have an object with that ID.

2) There's a bit struct with a pointer to every kind of component: struct
Entity { RigidBody *body; AnimatedMesh *animated; ... }; An entity comes to
life with NULL everywhere, and you populate it as appropriate.

3) You build an abstraction for "being a component" and for "containing
components." The entity is then a container for components. You write
component wrappers for each of rigid body, animated mesh, sound source, etc.
The entity is then created as a component container with whatever components
in it that you need. If you want editor support for arbitrary component
packages, for a fancy designer-built world, then this approach, plus XML
serialization, will get you there. The container will generally contain a
message bus, reflection support, etc.

The main problem you have to solve is how to get data from "here" to
"there." For example, the physics object collides with a wall, and thus
needs to adjust the animation to not penetrate an arm. Or the graphics scene
graph node moves, and you need the sound emitter to move as well. Generally,
this kind of data ends up in the "entity" component, so the "pure" ID
approach is not too common. However, if each of the subsystems can accept
some kind of "pull" input for common data like position, and the
authoritative source of that information can "push" it, then it can still be
done reliably and without pain.

Sincerely,

jw

by kimsama | 2009/12/17 14:16 | Development | 트랙백 | 덧글(0)

Physx의 불안한 미래?

AMD 그래픽 제품 그룹의 기술 마케팅 디렉터인 고프리 쳉(Godfrey Cheng)이 Bit-Tech와의 인터뷰에서 PhysX에 사망선고(?)를 했네요.

AMD says Physx will Die: 원문은 여기에서

Mirror's Edge PC delay down to PhysX 원문의 핵심은 아래로 nVidia의 GPU에서의 물리 기능을 사용하면 nVidia 칩에서만 돌아간다는 이야기입니다. 원문에서는 유사한 예로 과거 "FarCry"의 HDR이나 "Compan of Heroes"의 DX10 포팅을 이야기하고 있습니다.

(...)
Of course the let down is that those with ATI graphics will miss out,as PhysX acceleration on the GPU is still very much an Nvidia exclusiveproperty despite rumours of third party developers porting the API to ATI hardware persisting, although nothing concrete has yet materialised.
(...)

위의 기사 내용을 보니 과거 Novodex에서 Physx에 참여했던 Pierre Terdiman씨가 자신의 블로그에서 NVidia Physx 2.8.1의 발표에 대해서 포스팅한 내용이 떠오릅니다. (혹시 공격 사이트라는 경고가 나올 수도 있는데 무시하시길 -_-)

현재 Physx를 사용하고 있거나 혹은 예정인 경우에는 혼돈스러운 내용일 수도 있겠습니다. 물론 물리 계산에 하드웨어 가속을 이용하지 않는다면야 크게 신경 쓸 내용이 아닐 수도 있겠습니다만 앞으로의 트렌드를 본다면 너무 과감한(?) 결단이겠죠.

Physx 물리 엔진의 대안으로는 Bullet Physics Engine을 고려해 볼 수 있지만 물리 엔진을 대체하는 것만으로는 같은 일이 벌어지지 말라는 법이 없으므로 역시 불안합니다. 그래서 미들웨어 사용시에는 반드시 해당 도메인를 잘 파악한 다음 유연한 인터페이스를  설계하는 것이 중요합니다.(쉽게 이야기하면 래퍼 클래스를 작성하는 일입니다.)

물리 엔진의 경우 PAL과 같은 추상 레이어를 사용하는 것도 좋습니다. 아니면 Nebula3의 물리 엔진 레이어를 참고해서 필요한 추상 레이어를 작성하는 것도 좋습니다. (Nebula3의 물리 추상 레이어는 잘 작성되어 있다고 평가 받고 있는 것 중의 하나입니다. 현재 사용하고 있는 물리 엔진은 ODE입니다.)

이렇게 하면 사용하고 있는 미들웨어를 교체해야 하는 일이 발생하더라도 전체 애플리케이션이 경천동지할 일이 벌어지지는 않습니다. 전체를 엎어야 하는 것이 아니라 물리 엔진 래퍼 아래서만 변경하면 되니까 말입니다.

핵심은 인터페이스가 되는 래퍼 클래스를 만드는 일입니다. 네, 이미 알다시피 잘 만드는 일이 어렵습니다. 그러니까 여기서 이야기하고 싶은 핵심은 무작정 만들기 보다는 기존에 다른 곳에서 작성한 것이나 사용하고 있는 예가 있다면 충분히 살펴 보고 작성하라는 것입니다. ^^

by kimsama | 2009/01/04 15:07 | Development | 트랙백 | 덧글(8)

◀ 이전 페이지다음 페이지 ▶