Newton Plugin for Unity 3D

Share with us how are you using the powerrrr of the force

Moderator: Alain

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Wed Apr 27, 2016 12:47 am

not to derail, the topic, but just to give a little incentive, please sync to latest Newton and play the monster truck demo. Tell me what you thing.

I believe this almost ready, the one last thing the Lateral dynamics stability, which I will add tomorrow. and that will be the Vehicle for 3.14

Maybe some tweaks and customization request here and there but I believe this is it.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Kaos » Wed Apr 27, 2016 3:24 am

Monser Truck works great!

It also doesent seem to have that fly and spin bug anymore as i toppeld over and nothing bad happend.

I have made some observations and have at least one question ;D

The rpm isnt changing when you get in full turn at high speed. I think its somewhat inherented from the low friction setup in the demo which is too low maybe.
But it may also be that the tires have no weight or too little?
On a monster truck is suspect there are much greater forces at play when it comes to tires than on a normal car.

Its nearly always at full rpm even from 50 to 120kmh all on the second gear. That s somewhat unbelievable.



Is it possible to give steering to the backwheels?
Monster trucks have sometimes a setup where this are moveable too. And with an adjustable degree of some sorts so its not always exactly the mirrored of the front wheels.

And a bit special was a toy car monstertruck i once had that could then didnt mirror the wheels steering instead it used the same so the car would move sideways.

Also it had a winch :D But this isnt part of the vehicle physics setup and could be done via rope stuff. Not that i had this in mind for what i wanna do but for the hardcore offroad sim fans that could be nice.

Advanced suspension setup is something one can then do by themselvs or as demo do this in unity i suspect its easier/faster to setup this visually than in your current demo scene. But thats just standard joint stuff.

And the rest is just setup stuff... it could swing a bit more for my taste ;D
And its abit too stable ..
you can make a full turn at top speed without topling or heavy drifting. But i admit that is partly a visual and sound things without hearing slipping and seeing dirt fly its harder to get a feeling for that kind of thing. But i watched quite a few monster truck shows when i was little and i saw them flip at corners and having trouble with staying on gas in corners.

watch that from minute 1.00
https://www.youtube.com/watch?v=bqHixJVRiGw
Ther you can see a topple while trying to turn and staying on gas ;D

But i know that is always to somewhat influenced then with a center of mass and its better to have a stable base than the other way around ;D

Im curious how easy or comfortable it will be to set this whole thing up in unity later.
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Sweenie » Wed Apr 27, 2016 3:37 am

Oh man, that looks great.

So here is the roadmap for the plugin.

* Creating and destroying worlds.
* IN WITH THE VEHICLES!!!
* Add the rest, single rigid bodies and joints can be added later, who needs them? :mrgreen:

Haha, no, seriously can't wait to start playing with vehicles in Unity(again).
My old setup was a quick'n'dirty solution.

By the way, regarding vehicle setup.
Can the current vehicle handle more than 4 wheels?
Or rather more than 2 axles?

It seems the Engine Controller expects a front and rear axle.

Also, would it be possible with the current setup to create 2 or 3-wheel vehicles?
Like a motorcycle or a trike?
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Wed Apr 27, 2016 5:39 am

Kaos wrote:The rpm isn't changing when you get in full turn at high speed. I think its somewhat inherited from the low friction setup in the demo which is too low maybe.
But it may also be that the tires have no weight or too little?
On a monster truck is suspect there are much greater forces at play when it comes to tires than on a normal car.

yes the parameters are the same of the viper, so the engine is too powerful for the vehicle weight
although monsters truck are a weird thing, for example in real Monster the tire are about twice as heavy that the vehicle, and the engine has ridicules power. all that can be accommodated, with this vehicle model. 8)

Kaos wrote:Its nearly always at full rpm even from 50 to 120kmh all on the second gear. That s somewhat unbelievable.

yes because eth engine are that of a super car, so is driving like body weight like a toy, if you drive a car in first gear is actually behave like that.

Kaos wrote: Is it possible to give steering to the backwheels?
Monster trucks have sometimes a setup where this are moveable too. And with an adjustable degree of some sorts so its not always exactly the mirrored of the front wheels.

yes all wheels can be configure to have steering angle. I will add that later, so far I have only hard coded vehicle definition

Kaos wrote:Also it had a winch :D But this isnt part of the vehicle physics setup and could be done via rope stuff. Not that i had this in mind for what i wanna do but for the hardcore offroad sim fans that could be nice.

ha that the beauty of this vehicle mode, it is a ordinary set of connected bodies, any thing can be added to the vehicle doors, winches, hoods, if it can be done with joint an bodies, it can be added as an accessory. I will add some demos in the heavy vehicles.

Kaos wrote:Advanced suspension setup is something one can then do by themselvs or as demo do this in unity i suspect its easier/faster to setup this visually than in your current demo scene. But that just standard joint stuff.

yes that planned, in fact is necessary for a sport car, but that all planned later.

Kaos wrote:you can make a full turn at top speed without topling or heavy drifting. But i admit that is partly a visual and sound things without hearing slipping and seeing dirt fly its harder to get a feeling for that kind of thing. But i watched quite a few monster truck shows when i was little and i saw them flip at corners and having trouble with staying on gas in corners.
But i know that is always to somewhat influenced then with a center of mass and its better to have a stable base than the other way around ;D

yes I know, Monster truck drive like bad video game physics. the hard part is how to make then behave like vehicle that do not topple so easy. Later I will adjust the data so that is does a lithe more that that. I am very surprise that comes even close to a real life truck with those settings. :D
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Wed Apr 27, 2016 5:48 am

Sweenie wrote:By the way, regarding vehicle setup.
Can the current vehicle handle more than 4 wheels?
Or rather more than 2 axles?
It seems the Engine Controller expects a front and rear axle.

it can have any number of axels, jus that that demo build four wheel cars.
the weekend I will complete the demo that show a Tank with 18 wheels,
and a military transport with 8 wheels, all plug when a 8 way differential

Sweenie wrote:Also, would it be possible with the current setup to create 2 or 3-wheel vehicles?
Like a motorcycle or a trike?

Oh yes motorcycle are in the plan, also three wheels vehicles.

Keep those observation coming guys that what makes the engine better.
now back to the Plug in.

Yes Sweenie I see your excitement, and I guess that not that we can add anything to the wrapper we can actually skip things.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Kaos » Wed Apr 27, 2016 7:06 am

Ive read about making motorcycles in games and one way is to make them with hidden supporting wheels. Like a bike for kids so it wont fall over.

Otherwise many bike games completly faking the whole thing or partly and just using animations and a kinematic controller.

A Truly correct model would actual need an driver to keep it stable under 5km/h and from then on the bike should stablelize itself or around that. But i dont have a bike license so im no expert.

So this could work right out of the box physx peeps use the 4 wheels car and setting the wheels up that to fit a bike with 2 support wheels.
The only thing that has to change is that only one wheel is powered in the setup.
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Wed Apr 27, 2016 7:55 am

there will be not fake wheel in the bike. I will al come out of the emerging physic behavior.
bike are actually very stable, because bike try to preserve angular momentum.

if If the engine you take a chamfered cylinder and you role it over you will see that it want to role around hit axis of symmetry.
the fate the more stable but it does not have to be that fast.

now think of two chamfered cylinders connect by a hinge to a body. as long as that angular momentum of the tire is larger that the acquire angular momentum that the added to the body by the gravity try to topple it, the bike is stable. so there is a minimum velocity that the bike need to be stable, but is very low.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Sweenie » Wed Apr 27, 2016 9:44 am

I'm having a hard time with the swig-generated code.

Everything that returns a pointer is wrapped into classes.

For example
In Newton.h, NewtonBody is just a forward declarated class. The C-interface has no idea what it contains and it doesn't need to.

The Swig generated code newton_wrap.cxx generates this...
Code: Select all
SWIGEXPORT void * SWIGSTDCALL CSharp_NewtonCreateDynamicBody(void * jarg1, void * jarg2, float * jarg3) {
  void * jresult ;
  NewtonWorld *arg1 = (NewtonWorld *) (NewtonWorld *)0 ;
  NewtonCollision *arg2 = (NewtonCollision *) (NewtonCollision *)0 ;
  float *arg3 = (float *) (float *)0 ;
  NewtonBody *result = 0 ;
 
  arg1 = (NewtonWorld *)jarg1;
  arg2 = (NewtonCollision *)jarg2;
  arg3 = jarg3;
  result = (NewtonBody *)NewtonCreateDynamicBody((NewtonWorld const *)arg1,(NewtonCollision const *)arg2,(float const *)arg3);
  jresult = (void *)result;
  return jresult;
}

I don't know why it clear the parameters, it overwrites them anyway :roll:

Now in newton_wrap.cs it creates this...

Code: Select all
public class SWIGTYPE_p_NewtonBody {
  private global::System.Runtime.InteropServices.HandleRef swigCPtr;

  internal SWIGTYPE_p_NewtonBody(global::System.IntPtr cPtr, bool futureUse) {
    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
  }

  protected SWIGTYPE_p_NewtonBody() {
    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
  }

  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SWIGTYPE_p_NewtonBody obj) {
    return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
  }
}


It just creates a class containing the ptr to NewtonBody.
This is wasteful and not necessary. It's just an expensive wrapping that cause garbage collection.

Finally it creates this dll import
Code: Select all
[global::System.Runtime.InteropServices.DllImport("NewtonWrapper", EntryPoint="CSharp_NewtonCreateDynamicBody")]
  public static extern SWIGTYPE_p_NewtonBody NewtonCreateDynamicBody(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, float * jarg3);


All we really need is to return a simple IntPtr which basically is C# version of a void *

Also, Swig generates classes for dMatrix, dQuaternion etc. We can't really use those in C#. We can but it would be inefficient calling the dll whenever we want to create a Matrix and as a Unity user I wouldn't want to user Vectors and Matrices other than those Unity uses.

Small classes like Vector, Quaternion, Matrix should really be a struct in .Net instead of a class.
These are used a lot where performance is needed and if they are classes they would end up in the garbage collector instead of being deallocated immediately when going out of scope(as value types does in .Net)

When C# passes a matrix to Newton like it does in NewtonBodyCreateDynamicBody, Newton wants a float *.
C# can't just pass a pointer to it's Matrix but instead you have to use something called marshalling.

This is how you must do it...(Matrix4x4 here is Unitys 4x4 matrix which is a struct)
Code: Select all
        Matrix4x4 mat = Matrix4x4.identity;
        IntPtr ptrmat = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Matrix4x4)));
        Marshal.StructureToPtr(mat, ptrmat, false);
        NewtonWrapper.NewtonCreateDynamicBody(m_world, m_collider, ptrmat);
        Marshal.FreeHGlobal(ptrmat);


You see, first we must allocate unmanaged memory the size of the struct.
Get a ptr to it.
Then copy the contents(memcopy) to the unmanaged buffer.
Then we pass that to Newton
After Newton returns the newly created body we have to free the buffer.

This is slow but that is the only allowed way to do it.
Since I know Newton's and Unity's matrix has identical members I can instead declare the dllimport like this...

Code: Select all
[code][global::System.Runtime.InteropServices.DllImport("NewtonWrapper", EntryPoint="CSharp_NewtonCreateDynamicBody")]
  public static extern SWIGTYPE_p_NewtonBody NewtonCreateDynamicBody(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, ref Matrix4x4 matrix);[/code]


This will still cause the memory copy to happen but Pinvoke does it for me instead so I just need to write
Code: Select all
        Matrix4x4 mat = Matrix4x4.identity;
        NewtonWrapper.NewtonCreateDynamicBody(m_world, m_collider, ref mat);


Which is alot easier.

Now I said this is the only allowed way to pass classes and structure via Pinvoke.
That isn't really true.

There is a compile option in .NET.

"Allow unsafe code"
Enabling this allows you to use pointers in C#(won't work in VB.NET).

Now you can actually call declare the dllimport like this...

Code: Select all
[code][global::System.Runtime.InteropServices.DllImport("NewtonWrapper", EntryPoint="CSharp_NewtonCreateDynamicBody")]
  public static extern SWIGTYPE_p_NewtonBody NewtonCreateDynamicBody(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, float *matrix);[/code]


And call it like this from C#

Code: Select all
        Matrix4x4 mat = Matrix4x4.identity;
        NewtonWrapper.NewtonCreateDynamicBody(m_world, m_collider, &(Matrix4x4)mat);

(Not sure about the casting above, but something like that...

This would ignore marshalling and work just like c and c++, with no extra memory copying which would make things faster.

This requires the functions to be declarated with the unsafe keyword and this will be tricky with swig.

I peeked a little at the Bullet C# wrapper and they went with a custom wrapping tool as well and use the unsafe method.

Julio, would you be very upset if I tried coding my own wrapping tool for this?
It would be specialized just for Newton and this Plugin project, but it would make things so much easier for me.

I would try to make it so that we could rerun it anytime Newton.h changes with as little manual intervention as possible.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Kaos » Wed Apr 27, 2016 10:09 am

The only problem with the unsafe flag is that the webplayer and i suppose the html5 versions wont work. Browser wont allow that.

EDit: that doesent meant im agaisnt it just to complete the facts.
The browser stuff isnt really up to that now anyway.. but the day may come in 5 - 10 years..
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

Re: Newton Plugin for Unity 3D

Postby Sweenie » Wed Apr 27, 2016 11:17 am

In our case it doesn't matter. Our wrapper makes pinvokes to a native dll, the webplayer doesn't allow that even if we don't use unsafe sections. Only pure .NET code is allowed with the webplayer.

[EDIT]
Unless we port Newton Dynamics to C#, are you up for that Julio? :lol:
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Wed Apr 27, 2016 11:43 am

I has a difficult time underhanging how swig mean to interface with c#. but the I saw you were suscesfull hooking the Malloc and Free.

Before we throw the swig out let us do some more research, to see how we can interface with the the call back.

this is what I think, but is just an expeculation.

I believe we need to write and C++ file that glue the delegate to the swig generated code.
the we add the header file to the Newton.I and the CS code use the header file to do the interface to swig.

I do not know how is done but I remember that I did some similar when I was doing the Python to connect to Newton. I have to use some swig directive to make swig produce code that I could uses.
Het the idea is to generate code that make swig produce a CH object that has the interface to the Delegate and we use that code not the Swig generated code.
The problem here is that I do not know delegate work in C#
but I am sure there have to be a way.

Sweenie wrote:Unless we port Newton Dynamics to C#, are you up for that Julio? :lol:

and how do we do that, I believe that will make very slow. I can no see the solver been efficient enough on a manage language. That I believe is a much harder task.
I think is better to set back and give some time, and learn who swig is meant to be use.
It gives us a lot for free. plus is also offer future support but just simple compiling the new code.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Wed Apr 27, 2016 11:51 am

In my part I will spend the week day try to learn more about C# because I am a fish out of water here. and that part of the major problem.

But I say let us rest for a least a week until we know that there are some limitations that we can no overcome. Believe I glue Newton to callback in GameStudion back when Game studio was using scripts, I do no see how we can not do it for C# using this tool.
It is our ignorance that I talking now.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Sweenie » Wed Apr 27, 2016 1:08 pm

and how do we do that, I believe that will make very slow. I can no see the solver been efficient enough on a manage language. That I believe is a much harder task.
I think is better to set back and give some time, and learn who swig is meant to be use.
It gives us a lot for free. plus is also offer future support but just simple compiling the new code.


No no, I was just joking. We are not gonna port Newton to C# :mrgreen:

But don't underestimate .NET, it's evolving fast. And with the new open source .NET Core that runs on Linux and Mac it's growing even larger than it already is. :D

You probably already heard of this but DigitalRune Engine is written purely in C#, even the physics engine.

Regarding Swig.

I read a little what other people say about using Swig for wrapping to C#.

Several people say don't bother using swig for wrapping C code, it's easier to just create the Pinvoke calls manually.(DLLImport)
I just want Swig to output something like this...
Code: Select all
        internal delegate void NewtonBodyIteratorDelegate(IntPtr body, IntPtr userData);
        internal delegate void NewtonCollisionIteratorDelegate(IntPtr userData, int vertexCount, IntPtr faceArray, int faceId);
        internal delegate void NewtonApplyForceAndTorqueDelegate(IntPtr body, float timestep, int threadIndex);
        internal delegate void NewtonSetTransformDelegate(IntPtr body, ref Matrix4x4 matrix, int threadIndex);

        // World
        [DllImportAttribute("Newton", EntryPoint = "NewtonCreate", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr NewtonCreate();

        [DllImportAttribute("Newton", EntryPoint = "NewtonDestroy", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
        public static extern void NewtonDestroy(IntPtr newtonWorld);

        [DllImportAttribute("Newton", EntryPoint = "NewtonUpdate", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
        public static extern void NewtonDestroyAllBodies(IntPtr newtonWorld);

        [DllImportAttribute("Newton", EntryPoint = "NewtonUpdate", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
        public static extern void NewtonUpdate(IntPtr newtonWorld,float timestep);

        [DllImportAttribute("Newton", EntryPoint = "NewtonWorldGetFirstBody", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr NewtonWorldGetFirstBody(IntPtr newtonWorld);

        [DllImportAttribute("Newton", EntryPoint = "NewtonWorldGetNextBody", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr NewtonWorldGetNextBody(IntPtr newtonWorld, IntPtr body);




Swig seems to be mostly intended for wrapping C++ Classes.

Maybe we shouldn't use Swig against Newton.h but against NewtonClass.h ?
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Newton Plugin for Unity 3D

Postby Julio Jerez » Wed Apr 27, 2016 1:28 pm

I read a little what other people say about using Swig for wrapping to C#.
Swig seems to be mostly intended for wrapping C++ Classes.
Several people say don't bother using swig for wrapping C code, it's easier to just create the Pinvoke calls manually. Maybe we shouldn't use Swig against Newton.h but against NewtonClass.h ?


It seem swig does not generates use friendly interface for C and is even more difficult when using function pointer.
The c++ solution was what I was trying to say before.

the C Newton Class could be used as a starting point. we can just copy that class or make a new one and we add function and virtual functions to interface to Newton.h
That class will resolve all the callback business and will only have to deal with the Csharp generate by swing from cpp classes only.
take a look at file: dNewton\dNewton.h
that will clean it up more, than I can explain.

we can copy from that project or we can even just use as it, we will probale have to do some changes. because is a while I do no use it, but that was the core interface for the opens Cen graphs and Ogre plugin, But recommend we make a new one for the project.

Let us not do any programing for the next few days, until we read more, until we collect more information, but yes I agree the interface to for swig to C is too low level for my taste.

I can stat the ball rolling by station making the NewtonSDK.cpp the NetwonBody.cpp and NetwonCollsion.cpp
and start the newton_wrap.cxx again and consider that previous a false started.

what do you think?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Plugin for Unity 3D

Postby Kaos » Wed Apr 27, 2016 1:38 pm

Julio Jerez wrote:I has a difficult time underhanging how swig mean to interface with c#. but the I saw you were suscesfull hooking the Malloc and Free.

Before we throw the swig out let us do some more research, to see how we can interface with the the call back.

this is what I think, but is just an expeculation.

I believe we need to write and C++ file that glue the delegate to the swig generated code.
the we add the header file to the Newton.I and the CS code use the header file to do the interface to swig.

I do not know how is done but I remember that I did some similar when I was doing the Python to connect to Newton. I have to use some swig directive to make swig produce code that I could uses.
Het the idea is to generate code that make swig produce a CH object that has the interface to the Delegate and we use that code not the Swig generated code.
The problem here is that I do not know delegate work in C#
but I am sure there have to be a way.

Sweenie wrote:Unless we port Newton Dynamics to C#, are you up for that Julio? :lol:

and how do we do that, I believe that will make very slow. I can no see the solver been efficient enough on a manage language. That I believe is a much harder task.
I think is better to set back and give some time, and learn who swig is meant to be use.
It gives us a lot for free. plus is also offer future support but just simple compiling the new code.


Yeah i had even suspected to see some assembler in and physics engine just for speed. And i think that question was meant as a joke anyway but c# is also not as bad as it was.. in some minds its like 10 times slower and thats not the case. But id ont wanna talk albout that.

I were more thinking that it may make sense to put some what now is on the c# side on the c++ side ..
Code: Select all
        public Quaternion GetRotation()
        {
            Matrix4x4 mat = Matrix4x4.identity;
            NewtonAPI.NewtonBodyGetMatrix(pBody, ref mat);
            Quaternion q = new Quaternion();
            q.w = Mathf.Sqrt(Mathf.Max(0, 1 + mat[0, 0] + mat[1, 1] + mat[2, 2])) / 2;
            q.x = Mathf.Sqrt(Mathf.Max(0, 1 + mat[0, 0] - mat[1, 1] - mat[2, 2])) / 2;
            q.y = Mathf.Sqrt(Mathf.Max(0, 1 - mat[0, 0] + mat[1, 1] - mat[2, 2])) / 2;
            q.z = Mathf.Sqrt(Mathf.Max(0, 1 - mat[0, 0] - mat[1, 1] + mat[2, 2])) / 2;
            q.x *= Mathf.Sign(q.x * (mat[2, 1] - mat[1, 2]));
            q.y *= Mathf.Sign(q.y * (mat[0, 2] - mat[2, 0]));
            q.z *= Mathf.Sign(q.z * (mat[1, 0] - mat[0, 1]));
            return q;
        }


This for example will be optimized by the compiler where it will use bit operators and whatnot to try to dont do the divides and other things that would be expensive.

But this kind of optimization is done by the compiler but this could also be done in a thread in c++ without taking any resources out of the unity thread. And Unity has only 1 main thread and dont believe making a coroutine for this makes sense.

ok thats one of my crazy ideas but...

couldnt one use one cycle for collisions and stuff and then change all those types and stuff for unity and then send them in a somewhat packaged way to saved calls and the user wont mind if the physics engine is even a frame ahead of things visual, if that would be the case.

I hadnt said anything because that is more work for julio i think and its not newtons problem that c# / unity uses other stuff. And i may be completly on the wrong path here, but if you want optimize i thought not about to put more into c#, i would put more into c++. And then try to minimize communication between the two and the transforming of data on c# side.

Like julio mentioned with his proxy idea. Like having one wolrd completly in c++ and then shoving all this data to unity to present it. instead of actually using all the calls from unity itself.

Of course this is not good for all problems but maybe for the main course. Its a bit like having a multiplayer game where you do all the things on the server and doesent trust the client.
Kaos
 
Posts: 38
Joined: Mon Apr 18, 2016 11:24 pm

PreviousNext

Return to User Gallery

Who is online

Users browsing this forum: No registered users and 10 guests