Y = (float)Math.Sin(Geometry.D

Z = (float)Math.Cos(Geometry.D

shipPos.X += speed * X;

shipPos.Y += speed * Y;

shipPos.Z += speed * Z;

Solved

Posted on 2004-08-28

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));

}

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.D

shipPos.Y += 0.0f;

shipPos.Z += -speed * (float)Math.Cos(Geometry.D

// direction 2, let it pitch doesn't combine with above 3 lines

shipPos.X += 0.0f;

shipPos.Y += speed * (float)Math.Sin(Geometry.D

shipPos.Z += -speed * (float)Math.Cos(Geometry.D

// maybe let it roll also

//shipPos.X += -speed * (float)Math.Cos(Geometry.D

//shipPos.Y += 0.0f;

//shipPos.Z += -speed * (float)Math.Sin(Geometry.D

}

2 Comments

Y = (float)Math.Sin(Geometry.D

Z = (float)Math.Cos(Geometry.D

shipPos.X += speed * X;

shipPos.Y += speed * Y;

shipPos.Z += speed * Z;

Question has a verified solution.

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

Title | # Comments | Views | Activity |
---|---|---|---|

Titan GTX SLI mode with Multiple monitors | 2 | 533 | |

How to make 2D games with custom graphics? | 3 | 297 | |

Help me install PYgame on Python 3.3.3 IDLE | 6 | 525 | |

What are your thoughts on this build? Gaming computer | 16 | 114 |

A short film showing how OnPage and Connectwise integration works.

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

Connect with top rated Experts

**19** Experts available now in Live!