restrict to rotation about 1 axis in constraint

restrict to rotation about 1 axis in constraint

Hi, I'm trying to create a constraint which limits rotation to be about the Z axis, any rotation going on around any other axis should be nuked. The documentation for this is all but extensive though, save for 2 occurences in the demos, where no restriction is made and just identity used, and a 1 line comment in the documentation, one is pretty much on his own. Perhaps it's my math which is failing me.

Anyway, I'm using the constraint construction kit and use the root fixed havok rigid body as the second body. I know that I should use some combination of setAngularBasisA and setAngularBasisB, but these accepts 3x3 matrices. I thought a matrix consisting of only 0s and a 1 on the element furthest to the bottom right would do the trick, but without luck. Would really appreciate some help on this one :)

9 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

Found a section which I had missed in the documentation under constraints which filled in the missing info! Anyway, now I'm having a different problem where the constraint seems to create friction. Even if I use setAngularFriction( 2, 0 ). Will toy around some and see if I can find a cause :)

Hi Sairon,
What kind of gameplay element are you trying to construct with the 1D constraint?
Marc

Hi, thank for the quick response!

Since it's a 2.5D game we want some things to be constrained to the 2D plane defined by X and Y. I have the position constrained nicely, and the rotation is also working sweet now, except for the friction part.

I've created a small example which demostrates the problem:

hkpConstraintConstructionKit kit;
kit.begin(this);

// Set up bodies
kit.setPivotA( pObj->getCenterOfMassLocal() );
kit.setAngularBasisA( hkRotation::getIdentity() );

kit.setPivotB( pObj->getCenterOfMassInWorld() );
kit.setAngularBasisB( hkRotation::getIdentity() );

// Constrain angular motion
//kit.constrainToAngularDof(2);

// Constrain linear motion
kit.constrainAllLinearDof();

kit.end();

// Add constraint to world
pWorld->createAndAddConstraintInstance(pObj, pWorld->getFixedRigidBody(), this)->removeReference();

If I after creating the constraint take pObj and set angular damping to 0 and angular velocity to, lets say 0, 0, 30.0f. Then the object rotates for like a few frames, after which some magic friction eats up the angular velocity. Is this a known problem or is it most likely an error on my side?

Okay, those tabs didn't go to good, I'll make another try :P

hkpConstraintConstructionKit kit;
kit.begin(this);

// Set up bodies
kit.setPivotA( pObj->getCenterOfMassLocal() );
kit.setAngularBasisA( hkRotation::getIdentity() );

kit.setPivotB( pObj->getCenterOfMassInWorld() );
kit.setAngularBasisB( hkRotation::getIdentity() );

// Constrain linear motion
kit.constrainAllLinearDof();

kit.end();

// Add constraint to world
pWorld->createAndAddConstraintInstance(pObj, pWorld->getFixedRigidBody(), this)->removeReference();

Gah, it seems to work fine if I implement it in the samples framework, sorry for the confusion :P

Hmm, I've been wrestling with this a bit more, but I can't seem to find what the error stems from. After about ~20 time steps something weird happens though, the angular velocity gets changed by hkRigidMotionUtilApplyAccumulators(). I can't get much info here since I naturaly don't have the source, but it gets called by hkpConstraintSolverSetup::solve(). If I look at hkRigidMotionUtilApplyAccumulators third paramater, which is of type hkpVelocityAccumulator*, I can see that it contains the new unwanted angular velocity:

m_angularVel {x=-3.3113036e-008 y=1.8995229e-007 z=30.000000 ...} hkVector4

The Z rotation is correct, but the X and Y rotation displayed here shouldn't even be possible since the constraint only allows rotation around Z. Further more if I take a look at this data, there's linear velocity which gets applied ( which also shouldn't be possible, since I've removed all linear motion with the constraint ). The next couple of time steps after this point continues to alter both the linear velocity as well the angular velocity until it stabilizes at an angular velocity of 0,0,0 and linear velocity of 0,0,0. When it has stabilized angular velocity stays at 0,0,0 for the reminder of the simulation.

Hi Sairon,

In addition to your constraint, you could try adjusting the inertia tensors and see if it helps. I've run into similar problems before where constraints are violated and giving them a little help with inertia tensor tweaking usually helps :-)

Thread where I've put some code to do this before:
http://software.intel.com/en-us/forums//topic/59488

Daniel

发表评论

登录添加评论。还不是成员?立即加入