Solved

a moving function based on 3 (euler) angles

Posted on 2004-08-28
2
210 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
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.
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

10 Experts available now in Live!

Get 1:1 Help Now