a moving function based on 3 (euler) angles

Posted on 2004-08-28
Last Modified: 2013-12-26
I'm still writing a program with a spaceship that moves freely through empty space.

The following function is supposed to handle the movements. The 3 lines of code seem to move the ship in
the right direction, but I want to know how to combine them so my ship can move right in all 3 (or at least 2)
directions. Hoping this function works in the first place.

// there is a ship that has a ('input')direction and a ('output')position
// the direction is noted by 3 angles ranging from 0=< angle <360, position by a vector shipPos.X, Y, Z
private void Move(float speed)
                // direction 1, let it yaw doesn't combine with 3 lines below direction 2
      shipPos.X += -speed * (float)Math.Sin(Geometry.DegreeToRadian(yaw));
      shipPos.Y += 0.0f;
      shipPos.Z += -speed * (float)Math.Cos(Geometry.DegreeToRadian(yaw));
      // direction 2, let it pitch doesn't combine with above 3 lines      
      shipPos.X += 0.0f;
      shipPos.Y += speed * (float)Math.Sin(Geometry.DegreeToRadian(pitch));
      shipPos.Z += -speed * (float)Math.Cos(Geometry.DegreeToRadian(pitch));
      // maybe let it roll also            
      //shipPos.X += -speed * (float)Math.Cos(Geometry.DegreeToRadian(roll));
      //shipPos.Y += 0.0f;
      //shipPos.Z += -speed * (float)Math.Sin(Geometry.DegreeToRadian(roll));
Question by:DaFou
LVL 84

Accepted Solution

ozo earned 500 total points
ID: 11949107
X =  -(float)Math.Sin(Geometry.DegreeToRadian(yaw))*(float)Math.Cos(Geometry.DegreeToRadian(pitch));
Y =  (float)Math.Sin(Geometry.DegreeToRadian(pitch));
Z =  (float)Math.Cos(Geometry.DegreeToRadian(yaw))*(float)Math.Cos(Geometry.DegreeToRadian(pitch));
shipPos.X += speed * X;
shipPos.Y += speed * Y;
shipPos.Z += speed * Z;

Author Comment

ID: 11961690
Hehe somehow it works. TYVM.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
THREE.js rotating cylinders and fittings 5 851
python UDP how do I specify an IP destination? 3 472
Python chess DS needs help 2 163
Any good game free GIF sites? 2 129
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question