本文整理汇总了Java中com.bulletphysics.collision.shapes.ConvexShape.localGetSupportingVertex方法的典型用法代码示例。如果您正苦于以下问题:Java ConvexShape.localGetSupportingVertex方法的具体用法?Java ConvexShape.localGetSupportingVertex怎么用?Java ConvexShape.localGetSupportingVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.bulletphysics.collision.shapes.ConvexShape
的用法示例。
在下文中一共展示了ConvexShape.localGetSupportingVertex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processCollision
import com.bulletphysics.collision.shapes.ConvexShape; //导入方法依赖的package包/类
@Override
public void processCollision (CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo,
ManifoldResult resultOut) {
if (manifoldPtr == null) {
return;
}
Stack stack = Stack.enter();
Transform tmpTrans = stack.allocTransform();
CollisionObject convexObj = isSwapped ? body1 : body0;
CollisionObject planeObj = isSwapped ? body0 : body1;
ConvexShape convexShape = (ConvexShape)convexObj.getCollisionShape();
StaticPlaneShape planeShape = (StaticPlaneShape)planeObj.getCollisionShape();
boolean hasCollision = false;
Vector3 planeNormal = planeShape.getPlaneNormal(stack.allocVector3());
float planeConstant = planeShape.getPlaneConstant();
Transform planeInConvex = stack.allocTransform();
convexObj.getWorldTransform(planeInConvex);
planeInConvex.inverse();
planeInConvex.mul(planeObj.getWorldTransform(tmpTrans));
Transform convexInPlaneTrans = stack.allocTransform();
convexInPlaneTrans.inverse(planeObj.getWorldTransform(tmpTrans));
convexInPlaneTrans.mul(convexObj.getWorldTransform(tmpTrans));
Vector3 tmp = stack.allocVector3();
tmp.set(planeNormal).scl(-1);
tmp.mul(planeInConvex.basis);
Vector3 vtx = convexShape.localGetSupportingVertex(tmp, stack.allocVector3());
Vector3 vtxInPlane = stack.alloc(vtx);
convexInPlaneTrans.transform(vtxInPlane);
float distance = (planeNormal.dot(vtxInPlane) - planeConstant);
Vector3 vtxInPlaneProjected = stack.allocVector3();
tmp.set(planeNormal).scl(distance);
vtxInPlaneProjected.set(vtxInPlane).sub(tmp);
Vector3 vtxInPlaneWorld = stack.alloc(vtxInPlaneProjected);
planeObj.getWorldTransform(tmpTrans).transform(vtxInPlaneWorld);
hasCollision = distance < manifoldPtr.getContactBreakingThreshold();
resultOut.setPersistentManifold(manifoldPtr);
if (hasCollision) {
// report a contact. internally this will be kept persistent, and contact reduction is done
Vector3 normalOnSurfaceB = stack.alloc(planeNormal);
normalOnSurfaceB.mul(planeObj.getWorldTransform(tmpTrans).basis);
Vector3 pOnB = stack.alloc(vtxInPlaneWorld);
resultOut.addContactPoint(normalOnSurfaceB, pOnB, distance);
}
if (ownManifold) {
if (manifoldPtr.getNumContacts() != 0) {
resultOut.refreshContactPoints();
}
}
stack.leave();
}
示例2: processCollision
import com.bulletphysics.collision.shapes.ConvexShape; //导入方法依赖的package包/类
@Override
public void processCollision(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
if (manifoldPtr == null) {
return;
}
Transform tmpTrans = Stack.alloc(Transform.class);
CollisionObject convexObj = isSwapped ? body1 : body0;
CollisionObject planeObj = isSwapped ? body0 : body1;
ConvexShape convexShape = (ConvexShape) convexObj.getCollisionShape();
StaticPlaneShape planeShape = (StaticPlaneShape) planeObj.getCollisionShape();
boolean hasCollision = false;
Vector3f planeNormal = planeShape.getPlaneNormal(Stack.alloc(Vector3f.class));
float planeConstant = planeShape.getPlaneConstant();
Transform planeInConvex = Stack.alloc(Transform.class);
convexObj.getWorldTransform(planeInConvex);
planeInConvex.inverse();
planeInConvex.mul(planeObj.getWorldTransform(tmpTrans));
Transform convexInPlaneTrans = Stack.alloc(Transform.class);
convexInPlaneTrans.inverse(planeObj.getWorldTransform(tmpTrans));
convexInPlaneTrans.mul(convexObj.getWorldTransform(tmpTrans));
Vector3f tmp = Stack.alloc(Vector3f.class);
tmp.negate(planeNormal);
planeInConvex.basis.transform(tmp);
Vector3f vtx = convexShape.localGetSupportingVertex(tmp, Stack.alloc(Vector3f.class));
Vector3f vtxInPlane = Stack.alloc(vtx);
convexInPlaneTrans.transform(vtxInPlane);
float distance = (planeNormal.dot(vtxInPlane) - planeConstant);
Vector3f vtxInPlaneProjected = Stack.alloc(Vector3f.class);
tmp.scale(distance, planeNormal);
vtxInPlaneProjected.sub(vtxInPlane, tmp);
Vector3f vtxInPlaneWorld = Stack.alloc(vtxInPlaneProjected);
planeObj.getWorldTransform(tmpTrans).transform(vtxInPlaneWorld);
hasCollision = distance < manifoldPtr.getContactBreakingThreshold();
resultOut.setPersistentManifold(manifoldPtr);
if (hasCollision) {
// report a contact. internally this will be kept persistent, and contact reduction is done
Vector3f normalOnSurfaceB = Stack.alloc(planeNormal);
planeObj.getWorldTransform(tmpTrans).basis.transform(normalOnSurfaceB);
Vector3f pOnB = Stack.alloc(vtxInPlaneWorld);
resultOut.addContactPoint(normalOnSurfaceB, pOnB, distance);
}
if (ownManifold) {
if (manifoldPtr.getNumContacts() != 0) {
resultOut.refreshContactPoints();
}
}
}