0% found this document useful (0 votes)
12 views5 pages

Application Research of PhysX Engine in Virtual Environment

Uploaded by

Pierre Lam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

Application Research of PhysX Engine in Virtual Environment

Uploaded by

Pierre Lam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Application Research of PhysX Engine in Virtual Environment

Niu Hongpan, Gao Yong, Hou Zhongming


Architectural Engineering Research Institute of General Logistics Department, Xi'an, Shaanxi,
710032, China
[email protected]

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

978-1-4244-5858-5/10/$26.00 ©2010 IEEE 587 ICALIP2010


joint, and others. Joints can have limits, springs, motors, shut down the engine. If you want the simulation more
and can be made to break under certain forces. In realistic, you should set gravity, friction coefficient, air
addition, PhysX can create fluids, cloths, particles and resistance and the likes according to the real world.
others in scenes, which describe the real world as well.
3. Graphics engine
In this paper we use OGRE engine to render virtual
scenes. OGRE (Object-Oriented Graphics Rendering
Engine) is a typical graphics rendering engine, which
provides a general solution for graphics rendering.
OGRE engine is written in C++ and easily used to
build 3D scenes. The engine abstracts all the details of
using the underlying system libraries like Direct3D and
OpenGL, and provides an interface based on real world
Figure 1. Architecture diagram of the PhysX
objects. Developers can use a small amount of codes to
build a complete virtual environment that will help to
Actors have three basic types: static actors, dynamic
develop complex 3D scenes.
actors and kinematic actors. The differences between
OGRE engine uses extensible application
three types of actors are shown in Table 1. Static actors
framework, with high efficiency and high configurable
are fixed in the world reference frame, which primary
render state management, supports efficient plug-in
used for collision detection, must have shapes assigned
architecture, using flexible mesh data format, and has
and no body property assigned. Static actors are frozen
clean design and full documentation of all engine class.
in the scene, thus once the static actors created do not
It is worth to mention that OGRE is an open source
do anything with it. The body property is used for rigid
engine and using MIT License that means you do not
actor’s simulation, including mass and inertia tensor.
need to pay license fees. OGRE engine has extensive
Dynamic actors must have body property, which are
applied perspective in 3D simulations and games.
normal rigid bodies that move under physical laws and
constraints, such as vehicles, moveable boxes. A
kinematic actor is a spectral kind of dynamic actor, for 4. Application
that must be moved by users control and does not move
in response to forces. It’s worth to mention that Using graphics engine you can create colorful three-
kinematic actors only collide with dynamic actors but dimensional virtual environment. Once you introduce
not with static actors. PhysX engine into your scene, the objects of the scene
will have bodies, will have weights, will react to the
Table 1. Comparison of three types of actors environment around them, thus the whole virtual world
Static Dynamic Kinematic will be alive.
Actor Actor Actor
Shapes Yes Optional Yes
4.1. Main framework
Bodies No Yes Yes
Introducing PhysX physics engine into graphics
Moveable No Yes Yes
engine, the main framework adopts the program loop
Collision detection Yes Yes Yes
of OGRE engine, which consist of initialization, input
Force acceptable No Yes No
processing and graphics update, and then add relevant
parts of the PhysX engine into the main flow as shown
When using PhysX engine to do simulation, firstly in Figure 2.
you need to create a PhysX simulation environment Firstly, you should initialize the OGRE engine,
and set environmental parameters, then create a scene create object, terrain, lights, and others need to display.
under the gravity acceleration and simulation type Complete all preparation before rendering. Next step is
description. The materials consist of restitution and initializing PhysX engine and setting parameters of
friction that should be set according to your needs. physical environment. According to the OGRE scenes
Developers should set the positions and velocity create static, dynamic and kinematic actors, and
parameters of the actors, then the PhysX engine begin associate the PhysX actors with OGRE objects. Then
to do calculation. After one time-step of the physics set the positions, velocities, forces and other state
loop, fetching the new position and velocity parameters parameters, complete all preparations before the
of the actors, processing user inputs, resetting the scene, physical simulation. While creating OGRE frame
and then run next time-step of the physics loop until

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

PhysX engine uses the function NxScene::


simulate(NxReal elapsedTime) to do the calculation,
which elapsedTime is the simulation time step. A fixed
step size can be used, such as gScene-> simulate
(1.0f/60.0f) means use 1 / 60 second fixed time step. A
variable step also allow to use, such as gScene->
simulate(evt.timeSinceLastFrame) means that use a
time interval between each frame. The simulation
function is usually run before frameStarted() function.
Fetch results using NxScene:: fetchResults() function,
PhysX engine uses state buffer mechanism, thus
asynchronous API is used by the code as shown in
Figure 2. Main flow of using PhysX engine with Figure 4. The approach can expand the scale and
OGRE graphics engine quality of physics content while providing better and
more consistent frame rate.
4.2. Implementation
// This code is used for simulation, and fetch results
According to the main framework by the previous /* fetch results until calculation complete */
section, the parts of initializing the PhysX engine, while(!gScene->fetchResults(NX_RIGID_BODY_FINISHED,
false));
calculating, obtaining the results should be
/* Set the time step, and started the PhysX simulation */
implemented in OGRE framework. gScene->simulate(evt.timeSinceLastFrame);
The preparation for simulation of PhysX engine gScene->flushStream();
should be put in the OGRE program CreateScene() Figure 4. Simulation and fetch the results
function, including initializing the simulation
environment, creating scenes, creating actors, and After fetching the results, the position information
associating with the OGRE objects. PhysX engine of the actors need to translate to OGRE objects. First
usually use NxCreatePhysicsSDK() function to create a find the actors who need to pass parameters, thus static
physical environment, use setParameter() to set the actors and dynamic actors in sleep do not need to pass
environment. Because the engine using numerical parameters. Then obtain the corresponding OGRE
algorithm, the actors always intrude each other when scene nodes, and translate the positions and
collisions occur, the skin thickness orientations of the PhysX actors to OGRE scene nodes,
(NX_SKIN_WIDTH) should be controlled, and the as shown in Figure 5. It’s should be attention that the
default value is 0.025. Create a scene need to set relationship between the world coordinates and local
gravity. PhysX coordinate system uses right-handed coordinates. If the PhysX actors use world coordinates,
coordinate system as OGRE coordinate, which y-axis the OGRE should use the world coordinates as well.
points to the vertical upward direction, thus the general When you want to shunt down the system, you must
acceleration of gravity set (0, -9.8, 0). Figure 3 shows a release the PhysX resources. The method is using
typical physics environment setting. PhysX actors releaseScene() and NxReleasePhysicsSDK() functions
associate OGRE objects using NxActor:: userData, to release the physics scenes and physics environment.

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

You might also like