250 likes | 387 Views
3D Flight Simulator for CE. Balaban Nir Lander Shiran Supervisor: Futerman Yan. The Problem. Building a 3D Flight Simulator for iPaq computers based on Direct3D. Performance optimization – the iPaq is not a powerful graphic machine because lack of proper hardware,
E N D
3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan
The Problem • Building a 3D Flight Simulator for iPaq computers based on Direct3D. • Performance optimization – the iPaq is not a powerful graphic machine because lack of proper hardware, therefore, the application must be efficient. iPaq H3975
Project Goals • Checking the performances of the iPaq computer • Picture quality • Speed • Memory • Optimize the above • Acquaintance with the Direct3D Windows CE environment
Solution Overview • Building a 3D surface in the Direct3D environment (referred as “scene”). • The user view-port will be through a “camera” that will be moved around the scene. • A timer will schedule the movement of the plane.
Solution Overview (2) • Each quantum a few actions will be taken: • Checking for user keyboard interrupts. • Moving the plane forward. • Rendering the new scene seen. • Checking whether or not a crash happened.
The Direct3D Enviroment The Direct3D enables the developer to a build a 3D object easily. Direct3D doesn’t require some special hardware but it is "device independent", means it works the same way with any hardware given. Because of this property we found it best to use Direct3D for this project.
The Direct3D Environment (2) The Direct3D environment is made of a group of 3D object in a 3D world, which we call a “scene”, a camera which represents the point of view for the scene. The 3D objects are made of vertices in the 3D World that build a solid model by connecting the vertices with triangles shape.
The Direct3D Environment (3) The Direct3D handles most of the mathematical and algorithmical requirements for building a 3D scene. Some of them are listed below: • Z-Buffer • Shading • Clipping and Transformation • Projections • Etc…
Solution The application consists of 3 main parts: • 3D terrain object • Plane movement controller object • Managing the objects
z x Solution – 3D Terrain Like any 3D object in Direct3D, our terrain consists of vertices. The vertices are placed uniformly in the XZ plane:
Solution – 3D Terrain (2) Every 3 vertices are connects to form a triangle.
y Solution – 3D Terrain (3) Each vertex has its own height (Y value) and a feeling of mountains is formed. The heights are chosen with a mathemetical formula. the vertices are samples of the mathematical mountains.
Solution – 3D Terrain (4) In order to achieve an infinite terrain, we created it cyclically so when the plane gets to the edge of the cycle it just “hops” to the other edge. Every terrain cycle is divided to 4 parts in order to create a richer terrain.
Solution – Plane movement controller In order to create a feeling of flying, the camera moves along the terrain according to the user requests. For that, an object that control the plane movement is required.
Solution – Plane movement controller (2) The object handles 3 main missions: • Saving the plane location and direction, and updating them. • Calculating where to place the camera each quantum, according to plane position, direction and speed. • Cyclic movement – when the plane gets to the edge, the object is responsible to move it to the other edge.
Solution – Managing the objects At first the objects must be built and given some parameters: • Creating the vertices. • Coloring each vertex by its height. • Pre Mathematical calculation. • Initializing the plane position at start.
אתחול המשטח מחלקת המשטח מחלקת היגוי המטוס אתחול משתני המטוס האם נלחץ מקש ? כן לא קידום משתני המטוס האם התרסקנו? האם נלחץ 'Q'? לא כן כן לא שינוי משתני מצב ציור המשטח render יציאה Solution – Managing the objects(2) After Initializing the objects the application waits for messages, from the user or the timer, and acting accordingly.
Coping with Windows CE One should keep in mind when he transits Windows applications to Windows CE about some facts: • The Pocket PC is not a powerful machine and “heavy” effects (like texture, lighting…) might not work properly. • There are function that exits in Direct3D for PC and doesn’t in Direct3D windows CE edition. Therefore, one must check every function he adds to the application.
Coping with Windows CE (2) • There are some functions that does exist on Windows CE, but for different reasons, the parameters were changed slightly. • Not like PC computers, the pocket PC has other kind of hardware. There is no keyboard, and the presentation on the screen is different (full screen mode…)
Optimizations As mentioned before, the greatest challenge is to optimize the application, so that it will run as fast as it can. In order to do that some actions had been taken: • Lighting – Adding lights to the scene result much calculations in real-time. To save these calculations, the lighting algorithms were disables, and each vertex got its own color in the initialization.
Optimizations (2) • As mentioned, the resolution of the vertices building the mountain effects its shape and the duration of the rendering time. There is a trade-off between these two elements. As higher the resolution, the slower the application. There we must optimize the resolution so the speed will be reasonable and the terrain will look properly.
Optimizations (3) The resolution in he application is represented by the variable DIF, which is the distance (in Direct3D units) between two vertices.
Optimizations (4) • Shading – In Direct3D there are two possible shading modes: Flat and Gouraud. • Flat Shading –Color each polygon with constant shades • and intensities according to the polygon’s • normal. This is the most simple and fast shading because there are no calculations to make.
Optimizations (5) • Gouraud Shading – Compute exact shading and intensity values for the vertices of each polygon, • using exact normals at vertices. • Interpolate (in image space) colors, for • interior pixels of polygon. • This is the most “expensive” way of shading but the results are much better.
Optimizations (6) • Clipping – The fewer vertices we render, the faster the render is. Therefore distant vertices, that the user can slightly notice should be cut off the scene.