Software Design for Pluggable Real Time Physics Middleware
Total Page:16
File Type:pdf, Size:1020Kb
2005:270 CIV MASTER'S THESIS AgentPhysics Software Design for Pluggable Real Time Physics Middleware Johan Göransson Luleå University of Technology MSc Programmes in Engineering Department of Computer Science and Electrical Engineering Division of Computer Science 2005:270 CIV - ISSN: 1402-1617 - ISRN: LTU-EX--05/270--SE AgentPhysics Software Design for Pluggable Real Time Physics Middleware Johan GÄoransson Department of Computer Science and Electrical Engineering, LuleºaUniversity of Technology, [email protected] October 27, 2005 Abstract This master's thesis proposes a software design for a real time physics appli- cation programming interface with support for pluggable physics middleware. Pluggable means that the actual implementation of the simulation is indepen- dent and interchangeable, separated from the user interface of the API. This is done by dividing the API in three layers: wrapper, peer, and implementation. An evaluation of Open Dynamics Engine as a viable middleware for simulating rigid body physics is also given based on a number of test applications. The method used in this thesis consists of an iterative software design based on a literature study of rigid body physics, simulation and software design, as well as reviewing related work. The conclusion is that although the goals set for the design were ful¯lled, it is unlikely that AgentPhysics will be used other than as a higher level API on top of ODE, and only ODE. This is due to a number of reasons such as middleware speci¯c tools and code containers are di±cult to support, clash- ing programming paradigms produces an error prone implementation layer and middleware developers are reluctant to port their engines to Java. The evalu- ation of ODE shows that ODE has decent features, performance and stability, and that ODE is good enough for small scale game development. Preface This thesis is the ¯nal requisite for my master degree in computer sience from LuleºaUniversity of Technology. It was carried out in the spring of 2005 at Agency9 in Luleºa. I would like to thank Tomas and Khashayar at Agency9 for their help and support as well as making these months a fun time in general. I would also like to thank my examiner Mikael Drugge for guidance in writing this thesis. 2 Table of Contents 1 Introduction 5 1.1 Background . 5 1.1.1 Middleware . 5 1.2 Purpose . 7 1.3 Goals . 7 1.3.1 Intuitive, Flexible and Extendable . 7 1.3.2 Switchable Middleware Layer . 7 1.3.3 Evaluate ODE . 7 1.4 Demarcations . 7 1.5 Methodology . 8 2 Theory 9 2.1 Rigid Body Physics . 9 2.1.1 Constant Properties . 9 2.1.2 Degree of Freedom . 9 2.1.3 Kinematics . 10 2.1.4 Dynamics . 10 2.2 Design Aspects of a Physics API . 11 2.2.1 Position . 11 2.2.2 Orientation . 11 2.2.3 Constraints . 12 2.2.4 Collisions . 12 2.2.5 Friction . 13 2.2.6 Ordinary Di®erential Equation Solvers . 13 2.3 Architecture of Open Dynamics Engine . 14 2.3.1 Rigid Body Simulation . 14 2.3.2 Collision Detection . 14 2.3.3 Joint Constraints . 15 2.3.4 Friction . 15 2.4 Related Work . 15 2.4.1 Collada . 15 2.4.2 Open Dynamics Framework . 15 2.4.3 Open Physics Abstraction Layer . 16 3 Design Speci¯cation 17 3.1 Design Patterns . 17 3.1.1 Creational Patterns . 17 3.1.2 Structural Patterns . 18 3 3.2 Design Outline . 18 3.2.1 Peer Layer . 19 3.2.2 Implementation Layer . 19 3.2.3 Wrapper Layer . 19 3.3 Packages . 20 3.3.1 Peer . 21 3.3.2 Listeners . 23 3.3.3 Volume . 25 3.3.4 Physics . 25 3.3.5 Graphics . 25 3.3.6 Containers . 26 3.3.7 ODE Peer Implementation . 27 4 Discussion 30 4.1 AgentPhysics . 30 4.1.1 Usability . 30 4.1.2 Issues . 31 4.2 Evaluation of ODE . 32 4.2.1 Features . 32 4.2.2 Issues . 33 4.2.3 Result . 34 4.3 Conclusions . 34 4.4 Further Work . 35 A Demo Applications 38 A.1 Multiple Collision Volumes . 38 A.2 Multiple Materials . 38 A.3 Joints . 38 A.4 Simultaneous Simulations . 38 A.5 Dynamics . 39 A.6 Simple Ragdoll . 39 A.7 Ragdoll Drop . 39 A.8 Animated Ragdolls . 39 A.9 Vehicle Simulation . 39 B Class Diagrams 40 B.1 Typical Application . 40 B.2 A9WorldPeer . 40 B.3 A9StaticBodyPeer . 40 B.4 A9Joint and Extending Interfaces . 40 B.5 Listerners . 40 B.6 Material . 40 B.7 Graphics . 40 B.8 Container . 40 4 Chapter 1 Introduction 1.1 Background In the past couple of years, real time physics has become the new buzzword in game development. Hardware accelerated 3D-graphics, which now is com- monplace, has freed the processor from processing costly graphics algorithms, making real time physics calculations possible instead. Usage of realtime physics in games has up until now been sparse, apart from vehicle simulation. In today's games, physics has evolved to the point where almost every object in the game world can be manipulated by the player, and react in a realistic way according to force applied, surface friction and elasticity. Vehicles have become more ad- vanced than ever, and character death animations have become obsolete with the usage of ragdolls, which means characters a®ected by physics, interacting with the surroundings in a realistic manner. Animation and physics can be used in combination as well, creating realistic e®ects when the character is hit by a bullet or recoil e®ects when the character ¯res his weapon. Even water and cloth is simulated in a realistic fashion, allowing the game developers to create a more life-like and intuitive game. Gameplay is evolving from where the player is trying to ¯nd a trigger to overcome some obstacle, to the player stacking objects or combining objects to build something to overcome the obstacle. With life-like physics, the player can use his real world experience to solve problems, since the game behaves as expected in the real world. The bestselling title Half-Life 2 is renowned because of the clever usage of real time physics, which allows the player to solve problems in a very intuitive way. Game physics is simpli¯ed by utilizing the concept of Rigid bodies, which is an idealized representation of an object, and Articulated Rigid bodies, which are constrained rigid bodies. 1.1.1 Middleware Middleware is the term for an application programming interface (API) devel- oped for one purpose only. For instance, the API could be intended only for graphics or only for physics. A developer can develop the modules needed for the game from scratch or use middleware for any number of modules. The bene- ¯t of using middleware is of course cutting development time, but also allowing the developers to focus on game content instead of technical issues with the 5 graphics module for instance. The drawbacks can include di±culties in ¯nding middleware well suited for a particular game and licensing cost. High standard middleware is usually expensive to license, but development time costs as well. Havok Physics and Animation Havok is perhaps the most well known middleware physics API. It is available for current and next generation game platforms. Havok physics in combination with Havok Animation enables the developer to mix physics simulation with an- imations. Havok also ships with a framework for developing vehicle simulations. Currently, over 120 titles including Half-Life 2 and Halo 2, are using Havok. Novodex/Ageia PhysX Engine Novodex is a multithreaded object oriented physics API, with an ANSI C++ programming interface, available for Windows and consoles. Novodex is the ¯rst physics engine supporting the new Physics Processor Unit (PPU) from AGEIA, which allows hardware accelerated calculations. Little is known about the PPU at this time of writing, but the PPU is believed to have the same impact on games and gameplay as the ¯rst 3D-accelerated graphics cards had on graphics. Epic Games are using Novodex for Unreal 3 and their next generation games, as well as other major developers such as Sega and Ubisoft. Novodex was acquired by Ageia and is now known as Ageia PhysX Engine. Meqon Game Dynamics Meqon Game Dynamics is also multi platform, with a C++ interface. It features both rigid body physics as well as vehicle dynamics, liquid surfaces and particle systems. Duke Nukem Forever, which is a highly anticipated game, is among the users of Meqon Game Dynamics. Meqon also has a product suited for industrial physics simulations, where accuracy and stability is crucial. Meqon was however acquired by Ageia in September 2005, and the future of Meqon Game Dynamics is unknown. Open Dynamics Engine Open dynamics engine (ODE) is a non commercial open source physics engine written by Russell Smith. It has a native C interface as well as a C++ interface. An open source Java bind using the Java Native Interface (JNI) to communicate to the native code base is also available, with a one-to-one interface to the native C. ODE has most of the same features as the commercial ones, but it is not as stable and easy to use as the commercial ones, and lacks support other than its quite small web community. A more exhaustive description of ODE follows in chapter 2. AgentFX Agency9 is a middleware developer with AgentFX as their main product. AgentFX is a high performance 3D-graphics engine developed entirely in Java, suitable for any real-time 3D application.