3d flight simulator for ce balaban nir lander shiran supervisor: futerman yan

25
3D Flight Simulator 3D Flight Simulator for CE for CE Balaban Nir Balaban Nir Lander Shiran Lander Shiran Supervisor: Futerman Yan Supervisor: Futerman Yan

Post on 19-Dec-2015

226 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

3D Flight Simulator for CE3D Flight Simulator for CE

Balaban NirBalaban NirLander ShiranLander Shiran

Supervisor: Futerman YanSupervisor: Futerman Yan

Page 2: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

The ProblemThe 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

Page 3: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Project GoalsProject Goals

• Checking the performances of the iPaq computer

• Picture quality• Speed• Memory

• Optimize the above

• Acquaintance with the Direct3D Windows CE environment

Page 4: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Solution OverviewSolution Overview

1. Building a 3D surface in the Direct3D environment (referred as “scene”).

2. The user view-port will be through a “camera” that will be moved around the scene.

3. A timer will schedule the movement of the plane.

Page 5: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Solution Overview (2)Solution Overview (2)

4. Each quantum a few actions will be taken:

1. Checking for user keyboard interrupts.

2. Moving the plane forward.

3. Rendering the new scene seen.

4. Checking whether or not a crash happened.

Page 6: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

The Direct3D EnviromentThe 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.

Page 7: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

The Direct3D Environment (2)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.

Page 8: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

The Direct3D Environment (3)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…

Page 9: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

SolutionSolution

The application consists of 3 main parts:

1. 3D terrain object

2. Plane movement controller object

3. Managing the objects

Page 10: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Solution – 3D TerrainSolution – 3D Terrain

Like any 3D object in Direct3D, our terrain consists of vertices. The vertices are placed uniformly in the XZ plane:

z

x

Page 11: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Solution – 3D Terrain (2)Solution – 3D Terrain (2)

Every 3 vertices are connects to form a triangle.

Page 12: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Solution – 3D Terrain (3)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

yvertices are samples of the mathematical mountains.

Page 13: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Solution – 3D Terrain (4)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.

Page 14: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Solution – Plane movement Solution – Plane movement controllercontroller

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.

Page 15: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Solution – Plane movement Solution – Plane movement controller (2)controller (2)

The object handles 3 main missions:1. Saving the plane location and direction,

and updating them.2. Calculating where to place the camera

each quantum, according to plane position, direction and speed.

3. Cyclic movement – when the plane gets to the edge, the object is responsible to move it to the other edge.

Page 16: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Solution – Managing the objects 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.

Page 17: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Solution – Managing the objects(2) Solution – Managing the objects(2)

After Initializing the objects the application waits for messages, from the user or the timer, and acting accordingly.

אתחול המשטח

אתחול משתני המטוס

מחלקת המשטח

מחלקת היגוי המטוס

האם נלחץ מקש ?

האם התרסקנו

?

קידום משתני המטוס

יציאה

האם נלחץ

'Q?'

ציור המשטח

render

שינוי משתני

מצב

כן

כן לכןא

לא

לא

Page 18: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Coping with Windows CECoping with Windows CE

One should keep in mind when he transitsWindows applications to Windows CE aboutsome facts:1. The Pocket PC is not a powerful machine and

“heavy” effects (like texture, lighting…) might not work properly.

2. 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.

Page 19: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Coping with Windows CE (2)Coping with Windows CE (2)

3. There are some functions that does exist on Windows CE, but for different reasons, the parameters were changed slightly.

4. 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…)

Page 20: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

OptimizationsOptimizations

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:

1. 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.

Page 21: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Optimizations (2)Optimizations (2)

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.

Page 22: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Optimizations (3)Optimizations (3)

The resolution in he application is represented by the variable DIF, which is the distance (in Direct3D units) between two vertices.

Render Rate vs. DIF

0

500

1000

1500

2000

2500

3000

3500

4000

0 5 10 15 20 25

DIF

Re

nd

er

Tim

e (

ms

ec

)

Page 23: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Optimizations (4)Optimizations (4)

3. Shading – In Direct3D there are two possible shading modes: Flat and Gouraud.

•Flat Shading –Color each polygon with constant shadesand intensities according to the polygon’snormal. This is the most simple and fast shading because there are no calculations to make.

Page 24: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Optimizations (5)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, forinterior pixels of polygon.This is the most “expensive” way of shading but the results are much better.

Page 25: 3D Flight Simulator for CE Balaban Nir Lander Shiran Supervisor: Futerman Yan

Optimizations (6)Optimizations (6)

4.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.