Sign in to follow this  

RC Airplane orientation

Recommended Posts

So there's this RC airplane flying around. The camera is fixed and the user just flies the RC airplane around by moving it's position in 3D. What I have is the plane's position history (xyz pairs). How can I make it so that the airplane banks left when it turns left , pitches up when gaining altitude etc?

thanks in advance


Share this post

Link to post
Share on other sites
Any solution to this problem will (probably) necessarily be ad hoc (since there's no 'real physics' involved), but here's a couple of suggestions.

First of all, you can compute the absolute pitch and yaw for the plane from the vector from the previous position to the current position (provided the difference vector has sufficient magnitude). This should give the basic orientation for the plane at any given time, although there will be no rolling/banking.

Once you've computed the 'base' orientation using a from-scratch Euler-angle construction (using the pitch and yaw angles), I think you could then roll the plane locally about its forward vector to create a 'banking' effect.

All you need then is the angle to bank by. One way to compute this angle would be as follows (pseudocode):

[code]vector3 v1 = position[i - 1] - position[i - 2];
vector3 v2 = position[i] - position[i - 1];
// project_to_ground_plane() would zero out the element corresponding to the world 'up' vector.
v1 = project_to_ground_plane(v1);
v2 = project_to_ground_plane(v2);
float roll_angle = signed_angle_with_respect_to_ground_plane(v1, v2) * roll_factor;[/code]
Note that this code assumes v1 and v2 both have non-negligible magnitude after being projected.

Obviously this skips over some details, and it's somewhat speculative as well (I haven't tried this exact method myself).

Share this post

Link to post
Share on other sites
The game would probably be a lot more fun if it did involve Physics. In that case, the state of the plane at a given time has both the position (x,y,z) and the attitude (either as (roll, pitch, yaw), a quaternion or a rotation matrix).

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this