Restricting position (to a plane).

HexDump

11-02-2008 15:42:04

Hi all,

Well, After adding 2 joints to restrict rotations around Y and Z axis, now I need to limit position of my objects to 2D. I have been reading newton documentation, and I can´t find how to do it. It seems I should be building acustom joint, but as the the doc says it should be done by someone with a good physics knoledge (not my case). So, I´m a bit stuck. If anyone could help here I would be really greatefull.

Thnaks in advance,
HexDump.

nullsquared

11-02-2008 16:58:55

Hi all,

Well, After adding 2 joints to restrict rotations around Y and Z axis, now I need to limit position of my objects to 2D. I have been reading newton documentation, and I can´t find how to do it. It seems I should be building acustom joint, but as the the doc says it should be done by someone with a good physics knoledge (not my case). So, I´m a bit stuck. If anyone could help here I would be really greatefull.

Thnaks in advance,
HexDump.

Hm. Have you tried simply constraining the object's position and velocity to a plane?

// psuedo code
Ogre::Vector3 planeNormal(0, 0, 1); // Z-plane, like a 2D side scroller
// that is, in the above example, it won't move on the Z axis, only on XY

Ogre::Vector3 validCoords(Ogre::Vector3(1, 1, 1) - planeNormal);
body->setPosition(body->getPosition() * validCoords);
body->setVelocity(body->getVelocity() * validCoords);

(sorry 'bout the psuedo code, I don't use OgreNewt)

HexDump

12-02-2008 21:19:15

I know there's a better way for that, and it is creating a custom joint. By the way when using physics is not a good thing to set position/orientation by hand. Physics should do it all, so, the joint solution is the best one, but can´t see how to do it.


Thanks in advance,
HexDump.

nullsquared

13-02-2008 20:30:12

I know there's a better way for that, and it is creating a custom joint. By the way when using physics is not a good thing to set position/orientation by hand. Physics should do it all, so, the joint solution is the best one, but can´t see how to do it.


Thanks in advance,
HexDump.

Have you actually tried it to know that it doesn't work well enough? There's nothing wrong with direct control of positions/velocities if ... well, it works. A joint might be the "proper" way of doing it, but you might as well see if an easier way works well enough, first.

HexDump

14-02-2008 21:56:44

Yes, I´m not saying your answer doesn´t do the job, sorry if I was a bit rough. But I was looking for do in it using constraints (joints).

Thanks for the answers,
HexDump.

nullsquared

15-02-2008 10:54:53

Yes, I´m not saying your answer doesn´t do the job, sorry if I was a bit rough. But I was looking for do in it using constraints (joints).

Thanks for the answers,
HexDump.

Suit yourself. I'm just saying that using joints doesn't make the simulation better - it's just a different way of achieving whatever you want (usually more convenient).

HexDump

15-02-2008 17:51:22

The problem with your aproach, is that I need to "patch" position vector for every entity in my game after physics has done its work... I don´t think it is a good way to do it, anyway, it will work.

If anyone could bring some light here I would be really greatefull.

By the way, I have been playing with the CustomJoint class, and I don´t even undertand how to create something like the "UpJoint" that seems to be the easies joint I could create, and the way newton does it is hidden, because it is not an open engine.

Thanks in advance,
HexDump.

nullsquared

17-02-2008 16:14:43

The problem with your aproach, is that I need to "patch" position vector for every entity in my game after physics has done its work... I don´t think it is a good way to do it, anyway, it will work.

If anyone could bring some light here I would be really greatefull.

By the way, I have been playing with the CustomJoint class, and I don´t even undertand how to create something like the "UpJoint" that seems to be the easies joint I could create, and the way newton does it is hidden, because it is not an open engine.

Thanks in advance,
HexDump.

Just do it in each object's force and torque callback. If the object isn't getting this callback, then it's not moving and thus doesn't need its position and velocity "restricted".

Also, the CustomUpVector is open source - look in the custom joints for the source file.

HexDump

17-02-2008 21:04:21

Yes, that's right, I could Apply it to in the applyforce thing.

The CustomUpVector is opensource yes, I noticed it last friday, anyway, I just don´t understand what is it doing there. I can intuitively see what it is doing, but I don´t know if I could add anohter restriction for another pin at the same time (I mean something like "composing" joints teh same way we do with matrices).

Thanks for the help, and if you can help me undestranding the UpVector thing let me know :).

Thanks in advance,
Hexdump.