Keeping an object on a 2d plane ?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Keeping an object on a 2d plane ?

Postby greg2fs » Wed Jul 01, 2009 3:01 pm

Hello, I am trying to kepp an object on a plane, witch seemed easy to me but I have problems to do that.
I use a matrix (rotation+translation) representing the position of the plane, this plane will move but for now I just put it on a fixed position an orientation.
I did something like that:
NewtonJoint* joint=NewtonConstraintCreateUserJoint(nWorld, 6, customcallback, objectbody, NULL);

Then in my callback I first calculate 3 points on my object with the same position in x ( A, B, C)
I next calculate the position of these points in the plane space, I modify their x position to 0 and recalculate their new position in the object space (I get newA, newB, newC)
To finish I add 3 linearrow , (one for each points) like that:
NewtonUserJointAddLinearRow (Joint, &A.x, &newA.x, &dir.x);

But my object stay on its "starting 2d plane" whatever position I take for my plane.

Is this method correct ?

THanks
Image
greg2fs
 
Posts: 32
Joined: Sat May 24, 2008 12:36 pm

Re: Keeping an object on a 2d plane ?

Postby Gianluca » Fri Jul 03, 2009 11:09 am

No !!!
But your method is not far from the solution :-)

Good idea to use a UserJoint ...
... but you need only a one LinearRow !!
In fact, the LinearRow constrain the position of your object along an axis ... and you need only to block movement along the normal of the plane

Lets A the position of your object ... then,
create newA as the project of A onto the plane
and then add the LinearRow:
NewtonUserJointAddLinearRow( Joint, &A.x, &newA.x, &plane_normal )
and newton will move the object along the normal of the plane until it reach the position newA that corrispond to a position on your plane.

That's it.
Gianluca
 
Posts: 53
Joined: Fri Nov 11, 2005 4:37 am
Location: Rome - Italy

Re: Keeping an object on a 2d plane ?

Postby greg2fs » Fri Jul 03, 2009 12:59 pm

OK, but won't it be able to rotate on the 3 axis this way ?
Image
greg2fs
 
Posts: 32
Joined: Sat May 24, 2008 12:36 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron