ID:2010352
 
I'd like to animate an object 180 degrees around but I want other objects on top of that object to move with it as if glued into place.

I'm reading through the jt_vectors library and my brain is oozing out of my ears a little bit. I figured I better check and see if there is an easier way to achieve this effect. I'm worried I won't be able to figure it out on my own.


All you need to do to get objects to orbit around another is matrix transformations using translations of polar coordinates (x,y).

It's crude, but this is what I came up with to test it.

OrbitingOrbit()
var/obj/O = new(src.loc)
O.icon = 'Light.dmi'
O.color = rgb(200, 20, 30) // red ball
var/matrix/m = new
var/dist = 16
var/angleinc = 0
var/obj/S = new(src.loc)
S.icon = 'Light.dmi'
S.color = rgb(30, 20, 200) // blue ball
var/matrix/ms = new
var/dists = 30
var/angleincs = 0
spawn()
while(1)
angleinc += 10 // here to the next comment tranforms both the red and blue ball
m.Translate(dist * cos(angleinc), dist * sin(angleinc))
O.transform = m
S.transform = m
if(angleinc == 360)
angleinc = 0
angleincs += 30 // here and below transforms the blue ball
ms = S.transform // this is the important part; you need to translate off its previous tranformation
ms.Translate(dists * cos(angleincs), dists * sin(angleincs))
S.transform = ms
if(angleincs == 360)
angleincs = 0
sleep(world.tick_lag)


Essentially all you need to do is translate the main object, translate all oribiting objects by the same amount, and then apply the orbiting object's transformation to its previous transformation.

This is what happens with this code.

Image and video hosting by TinyPic
In response to Reformist
Reformist wrote:
All you need to do to get objects to orbit around another is matrix transformations using translations of polar coordinates (x,y).

It's crude, but this is what I came up with to test it.

> OrbitingOrbit()
> var/obj/O = new(src.loc)
> O.icon = 'Light.dmi'
> O.color = rgb(200, 20, 30) // red ball
> var/matrix/m = new
> var/dist = 16
> var/angleinc = 0
> var/obj/S = new(src.loc)
> S.icon = 'Light.dmi'
> S.color = rgb(30, 20, 200) // blue ball
> var/matrix/ms = new
> var/dists = 30
> var/angleincs = 0
> spawn()
> while(1)
> angleinc += 10 // here to the next comment tranforms both the red and blue ball
> m.Translate(dist * cos(angleinc), dist * sin(angleinc))
> O.transform = m
> S.transform = m
> if(angleinc == 360)
> angleinc = 0
> angleincs += 30 // here and below transforms the blue ball
> ms = S.transform // this is the important part; you need to translate off its previous tranformation
> ms.Translate(dists * cos(angleincs), dists * sin(angleincs))
> S.transform = ms
> if(angleincs == 360)
> angleincs = 0
> sleep(world.tick_lag)
>

Essentially all you need to do is translate the main object, translate all oribiting objects by the same amount, and then apply the orbiting object's transformation to its previous transformation.

This is what happens with this code.

Image and video hosting by TinyPic

This comes real close to what I need. Thank you for sharing it. The center will spin in place so I was able to simplify the code a bit. The following code has the satellite orbiting but relative to itself instead of my other object.

var/matrix/m = new
var/dist = get_dist(locate(27, 15, 1), c) * 32
m.Translate(dist * cos(angleinc), dist * sin(angleinc))
c.transform = m


How can I specify my other object as the center?
I need to switch it over to pixel movement to retain other transforms. This seems to be working fine although I still need to define a center.

var/matrix/m = new
var/dist = get_dist(locate(27, 15, c.z), c) * 32
c.pixel_x = dist * cos(angle)
c.pixel_y = dist * sin(angle)
So the main object isn't going to move at all? If that's the case, then I suggest getting two of Kaiochao's libraries:

Absolute Positions: http://www.byond.com/developer/Kaiochao/absolutepositions

Map Info: http://www.byond.com/developer/Kaiochao/mapinfo

Absolute positions requires map info.

Absolute Positions will give you access to Cx() and Cy(), which return the absolute coordinates of an atom's center. You could use this to get the center of the atom you want your satellite to orbit around.
Kaio actually has a good post about this:
http://www.byond.com/forum/?post=1554647#comment9775199