# Rotating a planet around a ships axis

I have a planet rotating around its own axis (like regular planets, and Pluto) and a spaceship that can fly around in space. The idea is to lock the player (ship) in a deadzone "above" the planet and when he moves to an edge, the planet begin to rotate in the direction that the ship is traveling. I.E. not rotate the player or camera, but instead rotate the planet.

The problem is I need to rotate the planet (in THOSE cases) around the ship's axis and not its own. So I need some way to create the rotation matrix for the planet using the ship's right and Up vector.

I don't want to use the CreateAxisFromAngle method because I don't want to automate the rotation (assuming that is how the function works, correct me if I'm wrong). I want to rotate the planet while the player is moving in a direction and stop rotating when they stop moving.

I also am not very comfortable with Quaternions. So if that is the solution (which I fear it is), please lay it out to me like you would a child, cause I am quaternions retarded. General math is fine though.

-
Could you explain what you want to do a little better. maybe a sketch. – Steve H Jan 6 '12 at 0:35
... and pluto Nice. But yes, you need to explain: What's moving to an edge? You are actually changing the rotation of the planets when a ship is traveling nearby? A sketch or similar aspect in another game would help a lot. – Byte56 Jan 6 '12 at 0:46
Why do you need the planet to rotate? Why not just move the ship around the planet? – annonymously Jan 6 '12 at 3:07
I'm trying to not rotate the camera and player, and only deal with the planet. No exact reason why, but that's what we're trying to do. (It's a class project type of thing). – Nicholas Jan 6 '12 at 3:31
If you think about the planet in 2D space. The top of the circle (planet) is showing at the bottom of the viewport, and the ship is let's say 20px higher than the exact center of the planet. When the player moves past let's say 10px to the left or right of the center of the screen, I want the planet to start rotating in the direction that the player is moving. That's the concept of what I'm trying to do, but of course in 3D space. Hope that helps a little more. – Nicholas Jan 6 '12 at 3:34

Only rotating the planet is probably going to look strange, since any background objects (moons, other ships) and star field are not going to move as they should.

Attempting to only rotate the planet will make things very complicated. For example, say the player approaches a planet, orbits half way around then flies off directly away from the planet. If you only rotated the planet in that situation (instead of player and camera) the player would fly away to the same place they flew in. Or they go to a planet at the south pole, fly to the equator and leave. Now the planet is sideways relative to the rest of the solar system.

What about some kind of orbit function. Where the player flies into this "dead zone" you mentioned, then their controls change into "orbit mode". When in orbit mode, the player is at a locked altitude from the planet and their controls act as if they were stuck to a invisible sphere surrounding the planet.

-
That is actually exactly what I'm doing, but I guess I didn't explain it well enough. Sorry about that. As for background objects looking odd, there are none. It's just the ship and the planet on screen. – Nicholas Jan 6 '12 at 19:26
Well, not exactly. You're attempting to rotate the planet to simulate the effect of the ship traveling around it, instead of just moving the ship around it. – Byte56 Jan 6 '12 at 19:36
By locking the player to this invisible sphere that is slightly bigger than the planet, and then turning the planet, wouldn't that accomplish the same effect? – Nicholas Jan 6 '12 at 20:04
You lock the player on the invisible sphere, then turn the sphere, not the planet. – Byte56 Jan 6 '12 at 20:05
Which would technically be turning the player then right? That's what I'm trying not to do. And again, no REAL reason why I want to move the planet instead of the player, but that's the avenue I'm trying to take. I kind of also like the idea of only having to rotate one model on screen, and not both. Thanks for all your help so far btw, much appreciated. – Nicholas Jan 6 '12 at 20:17

Please just simplify everything. Player is moving on angle, radius of planet. If angle is <> value, start rotating both planet and player. Since you are rotating around a fixed point, you can make it a looping xy space ( rotation, height ) problem instead of complicated 3d problem.

-