# xna flight simulator

• (2 Pages)
• 1
• 2

## 16 Replies - 4397 Views - Last Post: 27 September 2012 - 03:25 PM

### #16 BBeck

• Here to help.

Reputation: 713
• Posts: 1,672
• Joined: 24-April 12

## Re: xna flight simulator

Posted 25 April 2012 - 03:25 PM

abdcom, on 30 March 2012 - 10:11 PM, said:

ButchDean, on 30 March 2012 - 07:32 AM, said:

I will resist the urge to split hairs on those answers, but here goes. If you are aware of Newtonian Dynamics what is it about XNA's Vector3 type would be unsuitable for representing, say, velocity?

Thank you for your patience ... I do not speak English so I find some difficulty in writing and expressions.
For your question, I thought that all xna vectors starting from the (0,0,0) but the force is not the case. It starts from the position of the object.
So I want to create a new vector's class that consists of a start point and end point and the angles formed with axes, but I want to make sure the issue of xna vectors before I begin. I am having a another problem with the vectors and determine the direction of it. I wanted to know how to draw floor of the airport and make it infinite (but these issues had another question)

I speak a few foreign languages, so I know what you mean.

XNA was not built for complex physics simulations. It may not have a lot built in for a physics simulation. And it definately does not have all the capabilities of writing a program in C++ using DirectX.

But, it IS very powerful. My knowledge of physics is limited to beginning college physics and I do not know calculus. But vectors are really trigonometry, so I do know a lot about vectors.

XNA does not represent vectors as two points. It is correct to say that XNA vectors always have their root at 0,0 or 0,0,0. That "might" cause a problem for what you are doing. I am not certain.

However, working with the idea of plane velocity and relating it to vectors in XNA I can say a few things. I do not believe there is anything built into XNA for two point vectors, but that probably "shouldn't" matter. A vector is just a direction tied to an amount.

So, let's talk about a specific example. Let's say that we have a plane flying along a certain vector. You could say that it's direction and velocity are represented by one vector. You might have another vector for drag that is perfectly opposed to the velocity vector and that's going to be subtracted. And you may have an acceleration vectory which (in a simple simulation) might be perfectly aligned with the velocity vector and added to it at specific periods in time. The important thing to understand is that none of this makes any difference the position of the plane. You are just adding and subtracting vectors and will get a valid answer.

Now say you want to apply a vector representing a crosswind to the plane's flight path. Now position matters. So here's how I would handle it in XNA. I would have two pieces of data that XNA calls "vectors". The first vector would be a real vector that represents all the forces I just mentioned and their combined result. That vector would have it's origin at 0,0,0. XNA (and game programmers in general) likes to pretend that co-ordinates are "vectors". (You can come up with a contrived argument to suggest they are but it's definately contrived.) So, I would have a second "vector" storing the position of the plane. Now this second vector isn't a vector at all because I do not care what direction it is pointing in but only where the tip is because it's storing the 3D coordinate of my plane's position.

The position of my crosswind does not matter either, because I just need to add it to my velocity/flight path vector and it will tell me the new velocity/flight path after being affected by the crosswind. This gives me the plane's vector, but I don't know the position of the plane using this vector and so I cannot move the plane to it's new position. But if I have the plane's position stored as a seperate coordinate (in what XNA calls a vector) I can add my vector to that coordinate and us it just like it were a two point vector.

So, XNA may not be ready to be a scientific tool, but I believe you could build a flight simulator at least as accurate as Microsoft Flight Simulator with it.

XNA has a lot of built in ability to handle it's single point vectors in both 2 dimensions and 3 dimension. It knows how to do a dot product and a cross product. It also has the ability to load vectors into matrices and some built in functions for matrix algebra. You can easily rotate, scale, or transform any vector in XNA using the built in matix algebra functions. I "think" it also supports quaternions as well. (Quaternions are basically 4D vectors for anyone not familiar with the term that's reading this and they are considered important for rotating 3D objects in order to avoid Gimble Lock.)

### #17 StanArio

Reputation: 0
• Posts: 1
• Joined: 27-September 12

## Re: xna flight simulator

Posted 27 September 2012 - 03:25 PM

The xna framework already includes the Vector3 structure which should work for all of the calculations that you want to perform but be warned the vector to matrix formulas in xna don't do well when your vector approaches <0,0,1> and for xna this is fine when working with first person shooter games but for a flight simulator you probably will want to deal with this limitation.
Now for not having a start point for the vectors be somewhere other than (0,0,0) can be overcome by adding your position vector to any directional force vector that you have so for example the tangentVector adjusted by the positionVector would look like
```outVector = positionVector + tangentVector;
```
and would accomplish the same thing as moving the base of the vector

This post has been edited by Kilorn: 27 September 2012 - 03:47 PM
Reason for edit:: Removed long, unnecessary quote.