chrono icon indicating copy to clipboard operation
chrono copied to clipboard

How to extend TorqueFunctor in C#

Open AFIDclan opened this issue 4 years ago • 1 comments

I'm attempting to implement a ChLinkRotSpringCB in C#, but I'm having troubles extending the TorqueFunctor class to have a custom torque function. In python, I can just use def __call__ to make a class a functor, and in C++ it's: virtual double operator(). But in C# the only way to make a class callable is to extend DynamicObject and override the TryInvoke function (as described here). This of course won't work because ChLinkRotSpringCB needs a TorqueFunctor type class. Am I missing something? How would I create my own ChLinkRotSpringCB joint in C#?

AFIDclan avatar Apr 12 '21 17:04 AFIDclan

I just pushed a set of changes (to the develop branch) which should allow you to define and use such a functor object in C#.

Having said that, I don't have a way to test this (I'm only using these C# wrappers in a Chrono-Unity interface which does not require this particular functionality). So please let me know if the changes I made worked.

In fact, would you be interested in contributing a few stand-alone C# Chrono demos? I suspect you also use the C# wrappers in Unity (correct?), but maybe you have already looked into generating some stand-alone tests? If you're interested in helping with these, I could also wrap the Chrono::Irrlicht module (like we already do for our Python interface).

rserban avatar Dec 06 '21 16:12 rserban