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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

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

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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

617 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