Unity plugin progress?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Unity plugin progress?

Postby Sweenie » Mon Feb 20, 2017 2:04 pm

Hmm, dNewtonBody could easily store a reference to a NewtonBody but the problem is dNewton class is generated by swig.
Does swig have any way of "injecting" code into a generated class?
I thought maybe swig could add a private variable NewtonBody m_owner and two functions, SetOwner and GetOwner, or something like that.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Julio Jerez » Mon Feb 20, 2017 2:11 pm

probably not, but we can add a function that save the NewtonBody.
I thought maybe swig could add a private variable NewtonBody m_owner and two functions, SetOwner and GetOwner, or something like that

I tried that a whiel back and fail, I will try again maybe now I know a little more about c#
I try to added with strong type, but now I know the the argument has to be void*
I see if I can get it going now.


BTW I am now making the first work mini game emulation this tutorial.
https://unity3d.com/learn/tutorials/pro ... list=17141
I now have the ball that can be driven with the keyboard, next I will attach he camera and keep goint.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Sweenie » Mon Feb 20, 2017 2:21 pm

Hmm, just tried this and it seems it might work.

Added this to newton.i

Code: Select all
%typemap(cscode) dNewtonBody %{
  public void SetOwner(NewtonBody owner) {
    m_owner = owner;
  }
  public NewtonBody GetOwner() {
    return m_owner;
  }

  NewtonBody m_owner;   
%}


This should allow us to set a NewtonBody reference in the dNewtonBody class.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Julio Jerez » Mon Feb 20, 2017 2:36 pm

awesome, did you check it in?

maybe that the way to have strong type, I and using the void, but as the project become more elaborated, that can become a source for big problems

I now has the ball rolling and the camera following it, but for it to look good It needs a material with texture, how do we do that?

I found that making practical lithe game is a better way to focus the project than adding functionality that people may never use.

The plugin is almost that the point that can almost be usable.
after adding Ray cast and convex cast we can probably announce over the unity forum, maybe we can get some user to give a try and provide feeback.
In fact it is quite easy to add functionality, so user can customize it for their own usage.

BTW I added a 2d plane joint that allows to make 2d side scrollers games, as I understand those are quiet popular with Unity.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Sweenie » Mon Feb 20, 2017 2:50 pm

Ok, I added a checkered texture to the ball, makes it easier to see it rotate. I've checked it in.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Julio Jerez » Mon Feb 20, 2017 2:54 pm

Ok I saw it, but I am afraid I ruing it, because we edited the same files.

can you do it again and check it in please?
I will not do anything until you commit it.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Sweenie » Mon Feb 20, 2017 3:02 pm

haha, no worries.

My material was still there. I only had to drag the BallMaterial onto the ball. :)
Checked in now.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Julio Jerez » Mon Feb 20, 2017 3:10 pm

nice!!, I added some tweaks.

if you play you will see that the ball skids, whi make look cartoony, but we can clerally see that we nee to control the velocity.

so now we nee to add interface to read body velocity and angular velocity so that we can apply a torque with a viscous friction, this way the ball will have high acceleration and will skid, and will reach a terminal speed.
Our ball is already more interesting that the Unity tutorial. :shock:
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Mon Feb 20, 2017 3:16 pm

wow, is so awesome to be able to authoring a demo is a few minute with the full power of the engine. :mrgreen:
it would takes me almost day to put together a demo like that in the sandbox demos.

After we are further along I will start a series of exercises and experiment gear to our smart player.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Sweenie » Mon Feb 20, 2017 3:22 pm

I agree, it's awesome.

I noticed that if I change the y-scale to 0.5 so the sphere becomes flattened, it "stands" up when rotating fast. Is this the gyro force causing this?
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Sweenie » Mon Feb 20, 2017 3:41 pm

I think we need to store the GameObjects in NewtonWorld.
Because i believe these call slows down the update.

GameObject[] objectList = gameObject.scene.GetRootGameObjects();

The same for this call

NewtonBodyScript[] rigidBodyScripts = root.GetComponents<NewtonBodyScript>();

If you open the profiler window in Unity you can see that alot of GC allocation is going on.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Unity plugin progress?

Postby Julio Jerez » Mon Feb 20, 2017 4:00 pm

Sweenie wrote:I noticed that if I change the y-scale to 0.5 so the sphere becomes flattened, it "stands" up when rotating fast. Is this the gyro force causing this?

Yep, isn't that cool?
The ball acts just like a bike wheel which is what we expect. Oh I love my job :shock: :o 8) :twisted: :D :mrgreen:
believe or not that's called the intermediate axis theorem also the Racket tennis theorem.
Which mean the most stable axis of rotation Is the one with the largest inertia, the second axis of rotation is the one with the smallest inertial,
It is the Gyro baby!! https://www.youtube.com/watch?v=XALe27bnUm8

I bet you a dollar that none of the so called "commercial or popular" engines can't reproduce these kind of behaviors that comes out natural in newton. The run fast but ....
Now you can clearly see why bicycles and motorcycles tend to stat upright. :D

I is so cool like that, that I think we should check it in that way.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Mon Feb 20, 2017 4:05 pm

Sweenie wrote:I think we need to store the GameObjects in NewtonWorld.
Because i believe these call slows down the update.
GameObject[] objectList = gameObject.scene.GetRootGameObjects();

who slow can it be? let us play with for a while, and if we nee to make a local array, we will. but for flexibility let us continue adding functionality and the we focus on optimization.

now we need to add the Kinematics bodies, so that we can add collision shapes that can act as triggers.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Julio Jerez » Mon Feb 20, 2017 4:41 pm

yes, you are correct I can see a regular spike, and it all seem to be on game.Update generated by garbage collection.
but there is no reason to panic yet, this scene is so simple that anything that take few micro send more that the rest, is enough to show as an abnormally expensive.
Let us wait until we have more representative scene before we came back to this again.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unity plugin progress?

Postby Sweenie » Mon Feb 20, 2017 4:48 pm

I had to test the tennis racket theorem so i've added a tennis racket scene :)
Well, it reminds of a tennis racket anyway... :lol:
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 9 guests

cron