Application Research of PhysX Engine in Virtual Environment
Application Research of PhysX Engine in Virtual Environment
Abstract engine with OGRE graphic engine, and at the end will
give an example of the virtual scene with PhysX engine.
PhysX is a powerful commercial physics engine,
with which the virtual environment has more realistic 2. PhysX physics engine
sensation for users. This paper research on the PhysX
physics engine, and designs a main framework with PhysX is a powerful cross-platform physics engine,
OGRE graphic engine. The core parts of process have which made by NVIDIA corporation, can simulate
been analyzed in details. Finally, avirtual scene with real-time physics effects by hardware acceleration.
physical characteristics is given. The research has PhysX engine can calculate the interaction between
established the foundation of the virtual environment, rigid bodies accurately, can implement variety type of
and will promote the applications of the PhysX engine. joints which connected rigid bodies, can simulate cloth,
fluids, vehicles, force fields, soft bodies and other
1. Introduction physical effects. By massive parallel processors PhysX
engine is optimized for hardware acceleration, thus
With the development of science and technology, offloading the physical calculations from the CPU, the
virtual reality has been attracted many attention [1-2]. engine provides an exponential increase in physics
Most of virtual reality systems build the three processing power. PhysX engine is a powerful
dimensions applications based on graphic engine in middleware physics engine that avoids developers
current [3-4]. Using graphics engine we can display writing their own code to handle the complex physics
beautiful 3D geometric models, we can control the interactions, which present vivid, immersive physical
positions and orientations of the objects, we can detect environment for users.
the collisions of objects’ boundary [5-8]. However, The architecture of PhysX engine is shown in Figure
only using graphic engines bring about the lack of 1, which solid lines denote affiliations and dotted lines
interaction between objects, objects hardly motion in denote references. All the scenes are simulated in a
the real world way, and the motion scenes lack of virtual environment, in which each scene simulated
realism, thus it’s necessary to introduce physics engine. independently, the objects in a scene does not affect
Physics engine uses the physical motion laws, calculate other scene’s objects usually. A scene consists of actors,
the positions, orientations and collisions in real time, so joints, materials, and the others. PhysX rigid bodies are
that the interaction between objects and the virtual called actors, which are the protagonists of the
scenes get more enhanced [9-11]. There are excellent simulation, constructed from collision shapes. There
physics engines include PhysX, Havok, ODE, Newton, are basic shapes you can use: box, sphere, capsule,
etc., in which the PhysX is a cross-platform convex mesh, triangle mesh and plane. Pushing shapes
commercial physics engine, and using for free. PhysX onto the actor and assigning the actor a density, the
can simulate rigid bodies, soft bodies, fluids, cloths and mass and the inertia tensor of the actor will be
many other spectral effects [12-16]. computed automatically. Materials are the physical
How to apply PhysX engine in a virtual substance objects are made of, which define the interior
environment and integrate with the graphics engine, properties of the actors: restitution, and the surface
and how to maintaining accurate physics simulation properties: friction.
capabilities and powerful graphics rendering Joints are connections between rigid bodies. There
capabilities are problems, this paper will investigate the are basic joints you can use: fixed joint, revolute joint,
PhysX engine, design and implement bonding PhysX spherical joint, prismatic joint, cylindrical joint, 6 DOF
588
listener updating scenes view, the PhysX engine starts such as pActor-> userData = pNode, the OGRE scene
to calculate the simulation in the same time. For the node pNode and the PhysX actor pActor will set the
reason of the PhysX engine simulation thread corresponding relationship, that is, the object on pNode
independent, the physics simulation and graphics view will associate with pActor.
displaying process at the same time. According to the
results of the physical calculation, update the positions / / Create the SDK and PhysX Scene, set the simulation environment
and velocities of the actors, and update the OGRE 3D / * Create PhysX environment, set simulation parameters * /
gPhysicsSDK=NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
graphics display, then the program loop go to next step
gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01);
until shutting down.
/* Define the gravity, create PhysX scene */
NxSceneDesc sceneDesc;
sceneDesc.gravity = NxVec3(0.0,-9.8,0.0);
gScene = gPhysicsSDK->createScene(sceneDesc);
Figure 3. A typical code of PhysX engine
initialization
589
Then combined with the OGRE graphic rendering
// translate the position and orientation of PhysX actors to OGRE engine, we design a framework to integrate PhysX
objects engine to virtual scene, and obtain the program
NxU32 nb=gScene->getNbActors();//Get the number of actors
implementation of the main framework. Base on the
NxActor** actors=gScene->getActors();//Get the pointer of actors list
study an example of virtual scene using PhysX engine
while(nb--) // Traverse the actors
{
was given.
NxActor* actor=*actors++; //Get pointer of the actor PhysX is a powerful physics engine. How to use the
if(!actor->isDynamic()) continue; // If be static actor, skip fluids, soft bodies and joints in virtual environment is
if(actor->isSleeping()) continue; // If the actor sleep, skip an important aspect of future work.
if(!actor->userData) continue; // If no associated object, skip
Ogre::SceneNode*node=(Ogre::SceneNode*)actor->userData; //Get References
the pointer of scene node associated with the actor
NxMat34 nm=actor->getGlobalPose();//Obtain the pose of the actor
[1] Gibber M, Kaye R, Fried M, Virtual Simulation in the
node->_setDerivedPosition(Vector3(pos.x,pos.y,pos.z)); //Assign the
Surgical World, Otolaryngologic Clinics of North America,
position to the scene node
2009, 42 (5): 891-900.
node-
[2] Yan Yanyun, Shi Guanglin, Virtual Simulation Method
>_setDerivedOrientation(Quaternion(quat.w,quat.x,quat.y,quat.z))
Based On Multi-Software Platform And Its Applications,
; //Assign the orientation to the scene node
Computer Simulation, 2006, (03): 180-182. (In Chinese)
}
[3] Long Yuguo, Zhao Hongwu, The Research of Virtual
Figure 5. Translate the PhysX results to OGRE Simulation Training System for Portal Crane, Computer
update Simulation, 2003, 20 (5): 120-122. (In Chinese)
[4] Dai Tangyun, Wang Zeming and XuShouheng, Research
5. Example of Creating and Fetching 3D Models of Virtual Reality Based
on OpenGL, IEEE/ICMA2006, 2006: 1991-1995.
[5] Gregory Junker, Pro OGRE 3D Programming, Apress,
We present an example about how to use PhysX 2006.
engine in virtual environment. The three-dimensional [6] Li Gang, Su Lijun and Zhang Junling, Study on the
scene includes all the types of actors. As shown in OGRE Technology Used in the Three-dimensional
Figure 6 the ground, the wall and the cylinder are static Emulational Scene, Ship Electronic Engineering, 2009, 29
actors, which can’t move. The balls are dynamic actors (3): 92-95. (In Chinese)
which can roll to any place and the box is a kinematic [7] Sampaio P, de Freitas R and Cardoso G. OGRE-
actor. Users can control the box pushing the balls, thus Multimedia: An API for the Design of Multimedia and
the balls will be rolling and colliding with each other. Virtual Reality Applications, Springer, 2008: 465-472.
[8] Shu Chang, Liang Yinglun and Wang Dawei, Research on
an Equipment Visual Emluator Based on 3Dmax and OGRE,
Command Control & Simulation, 2009, 31 (005): 78-80. (In
Chinese)
[9] You Ren, Chen Dingfang, Research on Physical
Simulation and Application of Physical Engine in Virtual
Environment, Journal of Hubei University of Technology,
2008, 23 (002): 7-9. (In Chinese)
[10] Wang Shujun, Research of Physics Engine Key
Techniques in 3D Game Engine, Tianjin University, 2007.
(In Chinese)
[11] Joselli M, Clua E, Montenegro A, et al. A new Physics
Engine with Automatic Process Distribution between CPU-
GPU, ACM, 2008: 149-156.
[12] Wei Lixin, On the Physics Engine to Use the PhysX
SDK, Computer Knowledge and Technology, 2009, 5 (20):
Figure 6. An example of three-dimensional 5561-5562. (In Chinese)
scene with PhysX engine [13] Gao Song, Chen Xianqiao and Yang Ju, Design and
Realization of Vehicle Driving Simulation System Based on
OGRE and ODE, Computer and Communications, 2006, 24
6. Conclusions (001): 101-104. (In Chinese)
[14] Maciel A, Halic T, Lu Z, et al. Using the PhysX Engine
The paper has introduced a professional physics for Physics-based Virtual Surgery with Force Feedback. The
engine: PhysX, and studied how the engine uses in International Journal of Medical Robotics and Computer
virtual environment. Firstly we investigate the Assisted Surgery, 2009, 5 (3): 341-353.
architecture of the engine and three types of actors.
590
[15] Ouyang Huiqin, Chen Fumin, Research and [16] Su Xinxin, Li Xueqing and Qi Bin, Research and
implementation of binding of physics engine and graphic implementation of cloth simulation algorithm based on
rendering engine, Computer Engineering and Design, 2008, PhysX physics engine, Journal of Computer Applications,
29 (021): 5580-5582. (In Chinese) 2009, 29 (12): 3445-3448. (In Chinese)
591