3D Virtual Viewer with integrated Newton Physics Engine PROJECT REPORT ALAIN VINIOT DE LARA Professor C. Sun CS 491B Spring 2007 1. Abstract O n e o f t h e m o s t e x c i t i n g f i e l d i n c o m p u t e r s c i e n c e i s V i r t u a l R e a l i t y, i t provide the user with visual experience, made from virtual environment simulated with the computer. There has been increasing interest in the potential social impact of new technologies, specially virtual reality w h i c h w i l l l e a d t o s o m e c h a n g e s i n h u m a n l i f e a n d a c t i v i t y. Modern artist have been interested in this technology to create imaginative worlds in virtual space. The immersive capability of VR is starting to change the way people use the computer and manipulate digital information. 2 . Introduction Virtual Reality and 3D Video Games are exciting fields in computer science, commercial 3D video game products are the most profitable, m a n y p e o p l e e n j o y p l a yi n g v i d e o g a m e s . T h e f i r s t p e r s o n s h o o t e r e v e r produced, Wolfenstein3D was an instant hit and its progeny DOOM is recognized as the notorious pioneer for its use of immersive 3D graphics. B u t g e t t i n g t o m a k e a 3 D v i d e o g a m e i s a n o t h e r s t o r y, t h e r e q u i r e m e n t s t o produce these products are very demanding, the computer scientist that work in video game production are considered elites in computer science. The engineer that wants pursue a career in this field must master many s u b j e c t s s u c h a s m a t h e m a t i c s , p h ys i c s , c o m p u t e r g r a p h i c s . I t r e q u i r e s talent, ambition, experience, the skill level are often so high t hat only few talented people can get involved. For early video games, a single programmer could handle almost all the tasks needed to develop a game. However modern video game production involves a wide variety of skills and support staff. The productio n team has at least one lead designer, several programmers, many artists, sound engineers, level designers and testers. Imaginative and creative minds are required for this type of job. Every elements is critical to the success of the product, the work of the programmer is the most important. Developing computer game is a team effort, and each member is expected to have high skills in their field, competion is intense, so people have to keep up with the latest techniques and trends. Most modern 3D video games all use sophisticated 3D engines such as OpenGL and DirectX to render the virtual environment, more advanced ones are using physics engines to simulate Newtonian physics, such as m a s s , v e l o c i t y, c o n s e r v a t i o n o f m o m e n t u m , f r i c t i o n a n d e l a s t i c i t y. T h e r e a r e t w o t yp e s o f P h ys i c s e n g i n e , h i g h p r e c i s i o n a n d r e a l - t i m e , t h e l a s t o n e i s t a k i n g t h e f a s t a p p r o a c h , b y s i m p l i f yi n g c a l c u l a t i o n a n d l o w e r i n g t h e p r e c i s i o n t o i m p r o v e t h e r a t e o f g a m e p l a y. M a n y t yp e s o f r u n t i m e p h ys i c s e n g i n e e x i s t , a r e d i f f e r e n t i n q u a l i t y a n d p e r f o r m a n c e , I c h o o s e t h e N e w t o n P h ys i c s e n g i n e , b e c a u s e i t i s f r e e to use, one of the most accurate, can handle higher to mass ratios and simulation is very robust. There are some instability in the engine, an experienced programmer must know to fine tune the engine to avoid being in the "unstable zone". D u e t o p h ys i c a l i n t e r a c t i o n b e t w e e n p h ys i c s o b j e c t a n d t h e e n v i r o n m e n t , I c a n n o t u s e a p h ys i c s o b j e c t t o s i m u l a t e t h e p l a ye r c o l l i s i o n detection, because it will cause jittering for the view, so I implemented m y o w n t e c h n i q u e f o r c o l l i s i o n d e t e c t i o n . T h e r e s t o f t h e p h ys i c a l interactions are provided by the Newton engine. The general idea for this project is improve the speed of production, I u s e m y o w n 3 D e d i t o r t h a t c a n e d i t p o l yg o n s , a t t a c h t e x t u r e s , i n s e r t p h ys i c s o b j e c t s t h a t c a n b e s a v e d a n d l o a d e d l a t e r . T h i s e d i t o r c a n l o a d 3D mesh objects from some other file formats, so that, if the editor cannot edit some complicated shapes, it can rely on another program to do s o . A n u p g r a d e t o t h e 3 D e d i t o r w a s a p p l i e d t o s a v e P h ys i c s O b j e c t s , t h e viewer program is reading from a file and render the result. The editor is much more complicated than the project itself, if we upgrade the editor further, we will need less programming, w e will only need to be proficient in using the editor to produce video games, it’s equivalent of u s i n g a w e b p a g e e d i t o r i n s t e a d o f t yp i n g i n H T M L d i r e c t l y. T h i s e d i t o r i s still a work in progress. 3 . Techno log ica l Ba ckground 3 .1 B o r l a n d D e l p h i Borland Delphi is one of the first development tool to be known as RAD (Rapid Application Development), the interface is similar to Visual Basic with better performance, its predecessor was Turbo Pascal which was the fastest compiler in the pre -windows era. Delphi most popular use is the development of desktop and enterprise database application for Windows. I t i s b a s e d o n a w e l l d e s i g n e d l a n g u a g e , h i g h l e v e l a n d s t r o n g l y t yp e d with low level escapes for experts. It can compile to a single execu table, s i m p l i f yi n g d i s t r i b u t i o n a n d r e d u c i n g D L L v e r s i o n i n g i s s u e s . M a n y v i s u a l components library and third party components are available with source code, it can optimize compiling and use assembler code. Multiple platform native code from the same source code is provided s u c h a s C r o s s K yl i x . 3 .2 N e w t o n G a me Dy n a mi c s N e w t o n G a m e D y n a m i c s i s a f r e e , b u t c l o s e d s o u r c e p h ys i c s e n g i n e f o r realistically simulating rigid bodies in games and other real -time a p p l i c a t i o n s . I n c o n t r a s t t o m o s t o t h e r r e a l - t i m e p h ys i c s e n g i n e s i t g o e s for accuracy over speed. Its solver is deterministic and not based on traditional LCP or iterative methods. The advantages are that it can handle higher mass ratios (up to 400:1) and the simulation is very robust and easy to tune. The disadvantage is that it is a bit s l o w e r t h a n p h ys i c s e n g i n e s w i t h a n i t e r a t i v e s o l v e r . Newton Game Dynamics gets used in a lot of non -commercial, commercial and academic projects. It is a popular choice in the Irr licht and OGRE communities. T h e N e w t o n G a m e D yn a m i c s S D K L i c e n s e a l l o w s d e v e l o p e r s t o f r e e l y incorporate the engine into personal projects or commercial products so long as credit is given and the engine is distributed solely as part of a c o m p i l e d s o f t w a r e p r o g r a m t h a t i s i t s e l f n o t a p h ys i c s e n g i n e . N e w t o n G a m e D yn a m i c s i s a c t i v e l y d e v e l o p e d b y J u l i o J e r e z w h o f r e q u e n t s t h e forums on the official website. Currently a new version which will take advantage of multi -core cpus and gpus is in the works. Features: - easy to use C-API - available for windows, osx, linux - plethora of convex collision shapes - compound collision shapes - continuous collision mode - hinge, ball, slider, corkscrew,... and custom joints - powerful custom constraint/joint API - special vehicle container - special ragdoll container - also usable as a stand -alone collision detection library 3 .3 S e l f Ma d e 3 D E d i t o r The 3D editor was coded entirely by myself, although I use some extra library such as for loading textures, OpenGL/DirectX headers. The editor is still a work in progress. It is easy to create almost any shapes , we can p o s i t i o n , r o t a t e p o l y g o n s b y g r o u p s o r i n d i v i d u a l l y. T h e s a m e c a n b e s a i d about cameras, lights, translator, rotators. The features of the 3D editor are the described below: - p o l yg o n / v e r t e x e d i t i n g ( t r a n s l a t i o n a n d r o t a t i o n ) -Texturing by plane projection, cylindrical and spherical. -Skeletal animation with polygons - S u b d i v i s i o n w i t h B u t t e r f l y, L o o p a n d C a t m u l l - C l a r k m e t h o d . -Loading 3DS file -Rotating/Translating with scrollbar or mouse trackball -Transparent polygon editing/ degree of transparency - M a n u a l s h a d i n g o f v e r t e x a n d p o l yg o n s -Mirroring, Point Extrusion. -2D to 3D tools: Pivot, Path, 3D terrain editing,Extrude Tool. - C o l o r i n g v e r t e x o r p o l yg o n s -Filtered selection -Wire-frame or Gouraud shading view -Triangulation -Bicubic Spline and Bezier 3D Patch -Sizeable window view and focal lens adjustment. -Calculate Shadow and generate lightmaps files. -Pre-calculate before saving collision vectors and scalars. - P h ys i c s o b j e c t e d i t i n g , w e c a n s i z e t h e m i n t h e X , Y , Z d i r e c t i o n . 4 . System Ov erview T h e 3 D v i e w e r i s c a p a b l e o f g e n e r a t i n g 3 D P h ys i c s o b j e c t s o r l o a d from file, it depends on the 3D editor to produce the meshes. It can process collision detection by switching a menu item, the mass o f the 3D p h ys i c s o b j e c t s a r e h a r d c o d e d . I choose to give a specified mass so that the engine behave with s t a b i l i t y. R e n d e r i n g i s d o n e b y u s i n g O p e n G L , i t r e n d e r o p a q u e n o n l i g h t e d p o l yg o n a n d t r a n s p a r e n c y i s n o t s u p p o r t e d e v e n t h o u g h t h e e d i t o r a l l o w t o s p e c i f y l i g h t i n g a n d t r a n s p a r e n c y, d u e t o t i m e c o n s t r a i n t n o t a l l wanted features were finished. 5 . Desig n a nd Implementa tion. 5 .1 D e s c r i p t i on o f d e s i g n a n d i mp l e me n t a t i o n . I n t h i s p r o j e c t , I a d d e d p h ys i c s o b j e c t r e n d e r i n g w i t h w i r e - f r a m e b o x i n t h e 3 D e d i t o r , t h e p h ys i c s o b j e c t c a n b e s i z e d i n t h e X , Y a n d Z b y adjusting the 3 vectors of the matrix object. The data needed to store those object is just a matrix: Point of origin, X -vector, Y-vector and Zvector. We can see the 3 scales on the Top Caption of the editor when we p u s h s o m e d e f i n e d k e ys t o a d j u s t t h e s c a l e s ( s e e s c r e e n s h o t s e c t i o n ) . W e c a n t r a n s l a t e o r r o t a t e t h e p h ys i c s o b j e c t w i t h t h e m o u s e l i k e t h e p o l yg o n s . T h e w o r k c o d i n g p h ys i c s b o x e s a r e t o a l l o w o p e r a t i o n o n t h e objects like are selecting, deselecting, moving, rotating, scaling, d i s p l a yi n g a n d s a v i n g . Saving the Physics object is done by appending the number and array t o t h e f i l e . P o l y g o n s a n d o t h e r t yp e s o f o b j e c t s a r e s a v e d i n t h e s a m e manner. W e c a n p l a c e t h e P h ys i c s B o x e s a r b i t r a r i l y, w h e n l o a d e d t o t h e v i e w e r p r o g r a m , t h e b o x e s w i l l f a l l d o w n d u e t o t h e f o r c e o f g r a v i t y. I f t h e b o x i s p o s i t i o n e d n e a r a f l o o r p o l yg o n , i t w i l l n o t f a l l d o w n , i t w i l l s t a y immobile until we choose to go toward it or throw a physics object. T h e p r o g r a m h a s s e v e r a l p h ys i c s n o d e s , t h e f i r s t n o d e i s t h e environment which has zero mass, the second is the viewer who is also a p h ys i c s o b j e c t b u t w e d i s a b l e d i n t e r a c t i o n w i t h t h e e n v i r o n m e n t t o b e replaced by self-made collisio n detection, the loaded physics boxes are a l l i n d i v i d u a l n o d e s . T h e p l a ye r c a n g e n e r a t e p h ys i c s n o d e s b y p u s h i n g t h e s p a c e b a r , t o t h r o w p h ys i c s o b j e c t s . T h e p h ys i c s i n t e r a c t i o n s o f t h e p l a ye r a r e w i t h t h e l o a d e d a n d g e n e r a t e d p h ys i c s n o d e s o n l y. P h ys i c s B o x d a t a s t r u c t u r e i n D e l p h i TYPE PHYSBOX=Record O x , O y, O z : D o u b l e ; // Center of Box XVecX,XVecY,XVecZ, YVecX,YVecY,YVecZ, ZVecX,ZVecY,ZVecZ:double; // Orthonornal Vectors ScalX,ScalY,ScalZ: double; // Scales of the vectors texture_ID:longint; // Texture ID OpjX,OpjY:double; // 2D projection of Center Point end; 5 .2 S c r e e n s h o t s f r o m 3 D e d i t o r . View inside 3D editor of the scene ren dered on next slide 5 .3 Na t u r a l Co l l i s i o n d e t e c t i o n . T h e c o l l i s i o n d e t e c t i o n b e t w e e n t h e p l a ye r a n d t h e e n v i r o n m e n t d o e s n o t d e p e n d o n t h e N e w t o n P h ys i c s E n g i n e , i t w a s s e l f r e s e a r c h e d a n d d e s i g n e d . T h e p r o c e s s i n v o l v e s f i l t e r i n g b y d i s t a n c e t h e p o l yg o n s t h a t a r e t o o f a r t o t h e p l a ye r , s o t h a t w e w o n ' t p r o c e s s a l l p o l yg o n s o f t h e environment, once filtered in, we perform the collision detection. We c a t e g o r i z e 3 t yp e s o f p o l yg o n s w a l l , c e i l i n g a n d f l o o r . C e i l i n g a n d F l o o r a r e a l m o s t e q u i v a l e n t . I n a l l c a s e s w e u s e t h e s c a l a r v e c t o r o f t h e p o l yg o n w h i c h h a s b e e n p r e - c a l c u l a t e d t o i m p r o v e s p e e d . I f t h e p l a ye r ' s p o s i t i o n a n d t h e s c a l a r c a l c u l a t e d d o t p r o d u c t s a r e a l l p o s i t i v e , t h e n t h e p l a ye r i s i n t h e p r o x i m i t y o f t h e p o l y g o n s . O n c e e s t a b l i s h e d t h a t t h e p o l yg o n s a r e n e a r t h e p l a ye r , t h e s p e e d v e c t o r o f t h e p l a ye r i s c h e c k e d i f i t i s c r o s s i n g t h r u t h e p o l yg o n , w e t h e n p r o j e c t t h e s p e e d v e c t o r o n t o t h e c o l l i s i o n vector to get its length, we then scale down the speed vector to adjust so t h a t i t w i l l " t o u c h " e x a c t l y t h e p l a n e o f t h e p o l yg o n , w e c a l c u l a t e t h e reflected vector, and add it to the resulting scaled down vector to get he adjusted position. This effect is consistent with many observed commercial video games. 6 . System eva lua t io n 6 .1 N ew t o n E v a l u a t i o n The viewer performed as expected, we had to adjust the mass and gravity of the engine to run it under stable condition, the Newton Engine is not free from bugs. I observed some strange behavior from the engine under some conditions: -Object passing through wall if its mass is too heavy or speed is too high. -If mass of object is too heav y the force of gravit y takes over the force of friction, we see emergent phenomenon predicted in the documentation, like as "explosion". - I f b y m i s t a k e w e p l a c e 3 D p h ys i c s o b j e c t s c r o s s i n g i n s i d e a n o t h e r , the objects will bounce off as wanting to separate from the other. - T h e e n g i n e s l o w s d o w n i f t h e r e a r e t o o m a n y p h ys i c s o b j e c t s . 6 .2 S e l f ma d e c o l l i s i o n d e t e c t io n . I f t h e p o l yg o n s a r e w e l l e d i t e d w e s h o u l d n o t h a v e a n y p r o b l e m s w i t h collision detection, sometime if there is a "hole" between polygons, large e n o u g h , t h e p l a ye r c a n " p a s s t h r o u g h t h e w a l l s " . T h e s p e e d o f d e t e c t i n g collision is efficient and fast, it uses at least 1/500 of a second (2 ms) to process collision detection at every move. 7 . Conclusio n a nd Future wo rk Through my activity on this project, I advanced my knowledge and u n d e r s t a n d i n g o f u s i n g a p h ys i c s e n g i n e l i k e N e w t o n . I t p r o v i d e d m e w i t h the opportunity to implement a difficult matter which is collision detection. Although it only covered a small portion of the skill needed to i m p l e m e n t a V i d e o G a m e , I p r o g r e s s e d f r o m h yp o t h e s i s t o d i r e c t immersion by working on this project which gave me a view of this exciting field. I wanted to implement many features that the 3D editor allowed, such a s t r a n s p a r e n c y, l i g h t i n g , s h a d o w i n g . I t ' s p o s s i b l e t o u p g r a d e t h e e d i t o r further to support arbitrary shaped objects, not only box -like. I will continue to improve the 3D editor and Viewer on my own outside the class project and time constraints. 8 References [ 1 ] N e w t o n D yn a m i c s E n g i n e < h t t p : / / w w w . n e w t o n d yn a m i c s . c o m > [2] Game engine <http://en.wikipedia.org/wiki/Game_engine > [ 3 ] P h ys i c s p r o c e s s i n g u n i t < h t t p : / / e n . w i k i p e d i a . o r g / w i k i / P h ys i c s _ p r o c e s s i n g _ u n i t > [4] Rigid Body Dynamics - Chris Hecker's Website < h t t p : / / c h r i s h e c k e r . c o m / R i g i d _ B o d y_ D yn a m i c s > [ 5 ] A d r i a n B o e i n g ' s p h ys i c s e n g i n e l i s t < h t t p : / / w w w . a d r i a n b o e i n g . c o m / l i n k s . h t m l # p h ys i c s >
© Copyright 2025 Paperzz