Origin changed event

I have two component and I need to keep their movement in sync. I know I can get their position changing event by TranslationRotationService, but how can I identify whether the origin of them has changed?

Could you tell a bit more about the case? Are you changing origin of components?

Python has OnSimulationUpdate event in vcScript that is perfect for monitoring any or many component location (PositionMatrix) during simulation run. So, by monitor one component you can set the location of another comp in the event handler by setting its otherComp.PositionMatrix and calling otherComp.update() to update the location.

I believe in .NET you could utilize IRenderService.OnRequestRender event for similar monitoring and location updating.

Yes, I reset the origin of component A and after moving component B by
B.TransformationInWorld = A.TransformationInWorld;
I found they are not at the same position.

I just did a quick test and it seems to work.

_app = IoC.Get<IApplication>();
_app.LayoutLoaded += _app_LayoutLoaded;
compA = null;

   private void _app_LayoutLoaded(object sender, LayoutLoadedEventArgs e)
   {
        if (_app.World.Components.Count == 1)
        {
           compA = e.Components[0];
           compA.TransformationChanged += CompA_TransformationChanged;
         }
    }

    private void CompA_TransformationChanged(object sender, EventArgs e)
    {
         var compB = _app.World.Components.Last();
         compB.TransformationInWorld = compA.TransformationInWorld;
     }

 

 

Just to add a note here:

It is different thing to change/manipulate the origin (coordinate system) of a component and to locate/move the component within another coordinate system (e.g. World). In this case you’re not manipulating the origin of the component :wink:

do this test

_app = IoC.Get<IApplication>();
_app.LayoutLoaded += _app_LayoutLoaded;
compA = null;

   private void _app_LayoutLoaded(object sender, LayoutLoadedEventArgs e)
   {
        if (_app.World.Components.Count == 1)
        {
           compA = e.Components[0];
           compA.TransformationChanged += CompA_TransformationChanged;
         }
    }

    private void CompA_TransformationChanged(object sender, EventArgs e)
    {
         var compB = _app.World.Components.Last();
         compB.TransformationInWorld = compA.TransformationInWorld;
     }