Solved

a moving function based on 3 (euler) angles

Posted on 2004-08-28
2
211 Views
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));
}
0
Comment
Question by:DaFou
2 Comments
 
LVL 84

Accepted Solution

by:
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;
0
 
LVL 2

Author Comment

by:DaFou
ID: 11961690
Hehe somehow it works. TYVM.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A short film showing how OnPage and Connectwise integration works.

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now