Public Group

# Rotation in space

This topic is 4961 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi everyone! This is probably to be considered a newbee question. I've done a lot of work on a 3d RPG now but one thing eludes me: There is a space sim part to the game and I want it to be so that instead of moving the camera in space, I want to move everything else (planets, ships, etc). This is so that there can be a ship interior model in the middle with windows and stuff and instead of moving everything in the ship (consoles, crew, camera, etc) I want to move the stuff outside. This is fine for simple forward motion, etc but when it comes to turning, the issue is more complex. When you turn the ship along a specific axis, then the planets and stuff should move along that axis in a circular orbit and this is the catch! I have not been able to find a good way of doing this. I've read articles and downloaded sample code but I still can't get it to work right. Does anyone have any suggestions? By the way, I'm coding in Visual Basic but I reckon I can understand examples in other languages too. It's the math that bothers me. Thanx for any advice.

##### Share on other sites
Quote:
 Original post by SweeneyHi everyone!This is probably to be considered a newbee question. I've done a lot of work on a 3d RPG now but one thing eludes me: There is a space sim part to the game and I want it to be so that instead of moving the camera in space, I want to move everything else (planets, ships, etc). This is so that there can be a ship interior model in the middle with windows and stuff and instead of moving everything in the ship (consoles, crew, camera, etc) I want to move the stuff outside. This is fine for simple forward motion, etc but when it comes to turning, the issue is more complex. When you turn the ship along a specific axis, then the planets and stuff should move along that axis in a circular orbit and this is the catch! I have not been able to find a good way of doing this. I've read articles and downloaded sample code but I still can't get it to work right. Does anyone have any suggestions? By the way, I'm coding in Visual Basic but I reckon I can understand examples in other languages too. It's the math that bothers me.Thanx for any advice.

No no no. You don't want to do this. I assure you that it is far easier to move both the camera and the space ship.

If you still want to do this, then what you have to do is rather simple: let M be the transformation matrix and S the ship position in space. For every vertex V oustide the ship (I hope there isn't too many...), do:
Vresult = (M * (V - S)) + S// or ((V - S) * M) + S, depending on your matrix type

To simplify, and to put it the right way:
1) translate the world to have the origin of the world == the position of the ship
3) translate back the world

HTH,

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015462
×