Calculating Relative Height and Angle

Started by
3 comments, last by JohnnyCode 9 years, 8 months ago

Hey there. I'm new here, but already need help with XNA/Monogame (well it's more Math and Phyics in fact).

Im writing a little game for fun and came to some problems regarding calculations.

First a little overview:

The Game is like a little Flight Simulator, with one significant change: The Planet should be a Sphere.

For Pitch and Roll I used Quaternion-Calc (through tutorial, because I'm not that much into Quaternions),

so the ship can Roll and Pitch around its own axis.

I wanted to add some physics into the game, namly upforce and downforce.

For that I want to calculate the relative height first to make the downforce and upforce decrease when going higher till zero.

Question A:

How do I determine the relative Height to the surface?

The Planet is just a Sphere in this state, and I want to make the height over Sea-Level, so there

won't be a Problem when adding Terrain.

My thoughts for a Solution to A:

Could I just calculate the Distance of the Ship to every point of the Planet and pick the one with the

smallest distance? Or would that be a waste of time?

Another approach was to just calc the distance from Point(0,0,0) and subtract the radius of the planet.

Would be much easier then, I think.

I'll go on:

The upforce should not be affected by Roll-Angle but by the Pitch-Angle.

If the Ship goes up on 90° the downforce would be zero, so to say.

Question B:

How do I determine the relative Pitch to Surface?

As I'm not used to Quaternions I just tried out.

When using rotation (quaternion) there is no matter what (rotation.X, rotation.Y, rotation.Z, rotation.Y),

it won't give me the right Angle.

As the Rotation is calculated by pitch-angle (rad) and roll-angle (rad) i tried to use the cos(pitch-angle)

which will work fine as long as the surface is not a sphere and the ship wont roll.

My thoghts for a Solution to B:

My theoretical approach was to use the radius of the planet and building a Tangent on the Sphere on the

nearest position of the ship to the surface in the direction the ship is flying ( or is nearest to when flying upwards).

So to say, the Tangent has the direction that is 90° off to the direction the Wing-Tip goes to.

With this Tangent I could calculate the angle between it and the ships direction.

Question C:

How can I manage it to let the Plane fall to the surface if Downforce is higher than Upforce and both are not Zero?

My thoughts for a Solution on C:

Maybe I could use the Vector between the nearest point on the Sphere to the Ship, normalize it and devide it by a

value that depends on the downforce in regarde of height. Meaning the Normalized Vector will be "unnormalized"

so it gets bigger when getting nearer to the surface.

I won't use air-Resistance as a variable to determine the falling speed so this won't be a Problem.

then i could cange the Position-Vector of the ship to get closer to the surface by the rate of the calculated Vector.

I would appreaciate if anyone has a better solution to this problems or would comment on my approaches so I can

learn from it!

Thank you!

Edit:

Ah I forgot a point in regards of Gravitation:

I don't want to have this hard Physics in the game so I decided to

make a radius in where the Gravitation starts to play.

So to say: if the ship collides with the atmosphere, the gravitation starts to go up.

This makes it a lot easier when having more than 1 planet.

Advertisement

For question A -- distance to surface:

I'd probably just do distance between plane and center of the planet it flies around. Then subtract the radius of the planet.

Hello to all my stalkers.

A) distance to surface = distance to center - radius (as Lactose! said).
B) Compute the dot product of the vector from center to craft and the forward vector and convert to an angle using the inverse cosine function, then take Pi/2 - that angle.
C) You don't need to do anything special: Compute gravity, lift, drag, thrust and any other forces acting on the plane, add them together to compute the total force and let integration do the work.

As a general comment, it looks like your math skills might not be up to snuff. Perhaps you could reduce the scope of the project? Have you tried to make a flight simulator where the land is a rectangle? That might be a good stepping stone between where you are and where you want to be.

Ah well, actually I study computer-science and have a avarage math-background.

I just got confused about the Quaternion-Calc (and never made that more on Vector-Algebra than needed since XNA/Monogame - Start)

You just valdidated Point A.

Your Answer to point C is what I thought of. Just wanted to see if I could calc the Downforce-Vector like that to add it to the rest, so it would move appropiate.

Well on Point C, I'll try your approach. Just came up with the tangent as an work around.

Could I just calculate the Distance of the Ship to every point of the Planet and pick the one with the

If you consider the planet to be round and not influence the vessel in vacuum space, then yes, you will exhibit only against gravitational atraction, safe from molecular reactions. for sure

This topic is closed to new replies.

Advertisement