本文整理汇总了Java中com.bulletphysics.collision.narrowphase.ManifoldPoint.getPositionWorldOnB方法的典型用法代码示例。如果您正苦于以下问题:Java ManifoldPoint.getPositionWorldOnB方法的具体用法?Java ManifoldPoint.getPositionWorldOnB怎么用?Java ManifoldPoint.getPositionWorldOnB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.bulletphysics.collision.narrowphase.ManifoldPoint
的用法示例。
在下文中一共展示了ManifoldPoint.getPositionWorldOnB方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveSingleCollision
import com.bulletphysics.collision.narrowphase.ManifoldPoint; //导入方法依赖的package包/类
/** Response between two dynamic objects with friction. */
public static float resolveSingleCollision (RigidBody body1, RigidBody body2, ManifoldPoint contactPoint,
ContactSolverInfo solverInfo) {
Stack stack = Stack.enter();
Vector3 tmpVec = stack.allocVector3();
Vector3 pos1_ = contactPoint.getPositionWorldOnA(stack.allocVector3());
Vector3 pos2_ = contactPoint.getPositionWorldOnB(stack.allocVector3());
Vector3 normal = contactPoint.normalWorldOnB;
// constant over all iterations
Vector3 rel_pos1 = stack.allocVector3();
rel_pos1.set(pos1_).sub(body1.getCenterOfMassPosition(tmpVec));
Vector3 rel_pos2 = stack.allocVector3();
rel_pos2.set(pos2_).sub(body2.getCenterOfMassPosition(tmpVec));
Vector3 vel1 = body1.getVelocityInLocalPoint(rel_pos1, stack.allocVector3());
Vector3 vel2 = body2.getVelocityInLocalPoint(rel_pos2, stack.allocVector3());
Vector3 vel = stack.allocVector3();
vel.set(vel1).sub(vel2);
float rel_vel;
rel_vel = normal.dot(vel);
float Kfps = 1f / solverInfo.timeStep;
// btScalar damping = solverInfo.m_damping ;
float Kerp = solverInfo.erp;
float Kcor = Kerp * Kfps;
ConstraintPersistentData cpd = (ConstraintPersistentData)contactPoint.userPersistentData;
assert (cpd != null);
float distance = cpd.penetration;
float positionalError = Kcor * -distance;
float velocityError = cpd.restitution - rel_vel; // * damping;
float penetrationImpulse = positionalError * cpd.jacDiagABInv;
float velocityImpulse = velocityError * cpd.jacDiagABInv;
float normalImpulse = penetrationImpulse + velocityImpulse;
// See Erin Catto's GDC 2006 paper: Clamp the accumulated impulse
float oldNormalImpulse = cpd.appliedImpulse;
float sum = oldNormalImpulse + normalImpulse;
cpd.appliedImpulse = 0f > sum ? 0f : sum;
normalImpulse = cpd.appliedImpulse - oldNormalImpulse;
// #ifdef USE_INTERNAL_APPLY_IMPULSE
Vector3 tmp = stack.allocVector3();
if (body1.getInvMass() != 0f) {
tmp.set(contactPoint.normalWorldOnB).scl(body1.getInvMass());
body1.internalApplyImpulse(tmp, cpd.angularComponentA, normalImpulse);
}
if (body2.getInvMass() != 0f) {
tmp.set(contactPoint.normalWorldOnB).scl(body2.getInvMass());
body2.internalApplyImpulse(tmp, cpd.angularComponentB, -normalImpulse);
}
// #else //USE_INTERNAL_APPLY_IMPULSE
// body1.applyImpulse(normal*(normalImpulse), rel_pos1);
// body2.applyImpulse(-normal*(normalImpulse), rel_pos2);
// #endif //USE_INTERNAL_APPLY_IMPULSE
stack.leave();
return normalImpulse;
}
示例2: resolveSingleCollision
import com.bulletphysics.collision.narrowphase.ManifoldPoint; //导入方法依赖的package包/类
/**
* Response between two dynamic objects with friction.
*/
public static float resolveSingleCollision(
RigidBody body1,
RigidBody body2,
ManifoldPoint contactPoint,
ContactSolverInfo solverInfo) {
Vector3f tmpVec = Stack.alloc(Vector3f.class);
Vector3f pos1_ = contactPoint.getPositionWorldOnA(Stack.alloc(Vector3f.class));
Vector3f pos2_ = contactPoint.getPositionWorldOnB(Stack.alloc(Vector3f.class));
Vector3f normal = contactPoint.normalWorldOnB;
// constant over all iterations
Vector3f rel_pos1 = Stack.alloc(Vector3f.class);
rel_pos1.sub(pos1_, body1.getCenterOfMassPosition(tmpVec));
Vector3f rel_pos2 = Stack.alloc(Vector3f.class);
rel_pos2.sub(pos2_, body2.getCenterOfMassPosition(tmpVec));
Vector3f vel1 = body1.getVelocityInLocalPoint(rel_pos1, Stack.alloc(Vector3f.class));
Vector3f vel2 = body2.getVelocityInLocalPoint(rel_pos2, Stack.alloc(Vector3f.class));
Vector3f vel = Stack.alloc(Vector3f.class);
vel.sub(vel1, vel2);
float rel_vel;
rel_vel = normal.dot(vel);
float Kfps = 1f / solverInfo.timeStep;
// btScalar damping = solverInfo.m_damping ;
float Kerp = solverInfo.erp;
float Kcor = Kerp * Kfps;
ConstraintPersistentData cpd = (ConstraintPersistentData) contactPoint.userPersistentData;
assert (cpd != null);
float distance = cpd.penetration;
float positionalError = Kcor * -distance;
float velocityError = cpd.restitution - rel_vel; // * damping;
float penetrationImpulse = positionalError * cpd.jacDiagABInv;
float velocityImpulse = velocityError * cpd.jacDiagABInv;
float normalImpulse = penetrationImpulse + velocityImpulse;
// See Erin Catto's GDC 2006 paper: Clamp the accumulated impulse
float oldNormalImpulse = cpd.appliedImpulse;
float sum = oldNormalImpulse + normalImpulse;
cpd.appliedImpulse = 0f > sum ? 0f : sum;
normalImpulse = cpd.appliedImpulse - oldNormalImpulse;
//#ifdef USE_INTERNAL_APPLY_IMPULSE
Vector3f tmp = Stack.alloc(Vector3f.class);
if (body1.getInvMass() != 0f) {
tmp.scale(body1.getInvMass(), contactPoint.normalWorldOnB);
body1.internalApplyImpulse(tmp, cpd.angularComponentA, normalImpulse);
}
if (body2.getInvMass() != 0f) {
tmp.scale(body2.getInvMass(), contactPoint.normalWorldOnB);
body2.internalApplyImpulse(tmp, cpd.angularComponentB, -normalImpulse);
}
//#else //USE_INTERNAL_APPLY_IMPULSE
// body1.applyImpulse(normal*(normalImpulse), rel_pos1);
// body2.applyImpulse(-normal*(normalImpulse), rel_pos2);
//#endif //USE_INTERNAL_APPLY_IMPULSE
return normalImpulse;
}